stw changed to new devdi concept and cleanup

This commit is contained in:
Dirk Alders 2025-08-28 19:02:13 +02:00
parent 1d12ba59b9
commit 9c0aff5244
7 changed files with 34 additions and 163 deletions

2
devdi

@ -1 +1 @@
Subproject commit 881bc13c5a454407deeaf9f3303852e55412ac0d
Subproject commit 58167fb8ecd719df6a6aca693cf9fd7735149db4

View File

@ -47,6 +47,7 @@ from function.videv import videv_switching as videv_sw
from function.videv import videv_switch_brightness as videv_sw_br
from function.videv import videv_switch_brightness_color_temp as videv_sw_br_ct
from function.videv import videv_switching_timer as videv_sw_tm
from function.videv import videv_switching_motion as videv_sw_mo
from function.videv import videv_heating as videv_hea
from function.videv import videv_pure_switch
from function.videv import videv_multistate

View File

@ -21,10 +21,6 @@ logger = logging.getLogger(ROOT_LOGGER_NAME).getChild(__name__)
class all_functions(room_collection):
def __init__(self, mqtt_client):
# TODO: Remove this after changing to new devdi
from devdi.devices import physical_devices
pd = physical_devices(mqtt_client)
# TODO: Remove this after changing to new devdi
super().__init__(mqtt_client)
#
# Rooms
@ -32,7 +28,7 @@ class all_functions(room_collection):
# garden
self.gar = garden(self.mqtt_client)
# stairway
self.stw = stairway(self.mqtt_client, pd)
self.stw = stairway(self.mqtt_client)
# ground floor west
self.gfw = ground_floor_west(self.mqtt_client)
# first floor west
@ -62,9 +58,9 @@ class all_functions(room_collection):
self.videv_all_off = all_off(self.mqtt_client, config.TOPIC_ALL_OFF_VIDEV, self)
# ALL OFF - Long push stairway
self.stw.stairway.main_light_shelly.add_callback(self.stw.stairway.main_light_shelly.KEY_LONGPUSH_0,
True, self.stw.stairway.main_light_shelly.flash_0_mcb)
self.stw.stairway.main_light_shelly.add_callback(self.stw.stairway.main_light_shelly.KEY_LONGPUSH_0, True, self.all_off)
self.stw.stairway.switch_main_light.add_callback(self.stw.stairway.switch_main_light.KEY_LONGPUSH_0,
True, self.stw.stairway.switch_main_light.flash_0_mcb)
self.stw.stairway.switch_main_light.add_callback(self.stw.stairway.switch_main_light.KEY_LONGPUSH_0, True, self.all_off)
# FFE ALL OFF - Long push ffe_floor
self.ffe.floor.switch_main_light.add_callback(self.ffe.floor.switch_main_light.KEY_LONGPUSH_0,

View File

@ -4,11 +4,9 @@
import config
from devdi import rooms
from devdi import topic as props
from function.db import get_radiator_data, set_radiator_data
from function.modules import brightness_choose_n_action, heating_function, switched_light
from function.rooms import room, room_collection
from function.videv import videv_switching, videv_switch_brightness_color_temp, videv_heating, videv_multistate, videv_audio_player
import logging
import task
@ -18,8 +16,6 @@ except ImportError:
ROOT_LOGGER_NAME = 'root'
logger = logging.getLogger(ROOT_LOGGER_NAME).getChild(__name__)
loc = props.LOC_GFW
class ground_floor_west(room_collection):
def __init__(self, mqtt_client):

View File

@ -3,11 +3,10 @@
#
import config
from devdi import topic as props
from devdi import rooms
import logging
from function.modules import motion_sensor_light
from function.rooms import room, room_collection
from function.videv import videv_switching_motion
try:
from config import APP_NAME as ROOT_LOGGER_NAME
@ -15,40 +14,24 @@ except ImportError:
ROOT_LOGGER_NAME = 'root'
logger = logging.getLogger(ROOT_LOGGER_NAME).getChild(__name__)
loc = props.LOC_STW
class stairway(room_collection):
def __init__(self, mqtt_client, pd):
def __init__(self, mqtt_client):
super().__init__(mqtt_client)
self.stairway = stairway_stairway(mqtt_client, pd)
self.stairway = stairway_stairway(mqtt_client)
class stairway_stairway(room):
def __init__(self, mqtt_client, pd):
#
# Device initialisation
#
# http://shelly1-3494546A9364
self.main_light_shelly = pd.get(props.STG_SHE, loc, props.ROO_STF, props.FUN_MAL)
self.motion_sensor_ff = pd.get(props.STG_ZFE, loc, props.ROO_STF, props.FUN_MSE)
self.motion_sensor_gf = pd.get(props.STG_ZGW, loc, props.ROO_STG, props.FUN_MSE)
class stairway_stairway(rooms.stairway, room):
def __init__(self, mqtt_client):
super().__init__(mqtt_client)
room.__init__(self, mqtt_client)
#
# connect videv and switch
self.videv_main_light.connect_sw_device(self.switch_main_light, self.switch_main_light.KEY_OUTPUT_0)
#
# Functionality initialisation
#
self.motion_sensor_light = motion_sensor_light(
self.main_light_shelly, self.main_light_shelly.set_output_0,
self.motion_sensor_gf, self.motion_sensor_ff,
self.switch_main_light, self.switch_main_light.set_output_0,
self.motion_main_light_gf, self.motion_main_light_ff,
timer_value=config.USER_ON_TIME_STAIRWAYS
)
#
# Virtual Device Interface
#
self.main_light_videv = videv_switching_motion(
mqtt_client, config.TOPIC_STW_STAIRWAY_MAIN_LIGHT_VIDEV,
self.main_light_shelly, self.main_light_shelly.KEY_OUTPUT_0,
self.motion_sensor_light
)
self.videv_main_light.connect_mo_function(self.motion_sensor_light)

View File

@ -31,11 +31,8 @@ class videv_pure_switch(videv_base):
class videv_switching(videv_base):
KEY_STATE = 'state'
def __init__(self, mqtt_client, topic, sw_device=None, sw_key=None):
def __init__(self, mqtt_client, topic):
super().__init__(mqtt_client, topic)
# TODO: Remove the following code and the parameters from __init__
if sw_device is not None and sw_key is not None:
self.connect_sw_device(sw_device, sw_key)
def connect_sw_device(self, sw_device, sw_key):
self.add_routing(self.KEY_STATE, sw_device, sw_key)
@ -44,41 +41,34 @@ class videv_switching(videv_base):
class videv_switching_timer(videv_switching):
KEY_TIMER = 'timer'
def __init__(self, mqtt_client, topic, sw_device=None, sw_key=None, tm_device=None, tm_key=None):
super().__init__(mqtt_client, topic, sw_device, sw_key)
# TODO: Remove the following code and the parameters from __init__
if tm_device is not None and tm_key is not None:
self.connect_tm_device(tm_device, tm_key)
def __init__(self, mqtt_client, topic):
super().__init__(mqtt_client, topic)
def connect_tm_device(self, tm_device, tm_key):
self.add_display(self.KEY_TIMER, tm_device, tm_key)
class videv_switching_motion(videv_base):
class videv_switching_motion(videv_switching):
KEY_STATE = 'state'
#
KEY_TIMER = 'timer'
KEY_MOTION_SENSOR = 'motion_%d'
def __init__(self, mqtt_client, topic, sw_device, sw_key, motion_function):
self.motion_sensors = motion_function.motion_sensors
#
def __init__(self, mqtt_client, topic):
super().__init__(mqtt_client, topic)
self.add_routing(self.KEY_STATE, sw_device, sw_key)
self.add_display(self.KEY_TIMER, motion_function, motion_function.KEY_TIMER)
def connect_mo_function(self, mo_function):
self.add_display(self.KEY_TIMER, mo_function, mo_function.KEY_TIMER)
# motion sensor state
for index, motion_sensor in enumerate(self.motion_sensors):
for index, motion_sensor in enumerate(mo_function.motion_sensors):
self.add_display(self.KEY_MOTION_SENSOR % index, motion_sensor, motion_sensor.KEY_OCCUPANCY)
class videv_switch_brightness(videv_switching):
KEY_BRIGHTNESS = 'brightness'
def __init__(self, mqtt_client, topic, sw_device=None, sw_key=None, br_device=None, br_key=None):
super().__init__(mqtt_client, topic, sw_device, sw_key)
# TODO: Remove the following code and the parameters from __init__
if br_device is not None and br_key is not None:
self.connect_br_device(br_device, br_key)
def __init__(self, mqtt_client, topic):
super().__init__(mqtt_client, topic)
def connect_br_device(self, br_device, br_key):
self.add_routing(self.KEY_BRIGHTNESS, br_device, br_key)
@ -87,11 +77,8 @@ class videv_switch_brightness(videv_switching):
class videv_switch_brightness_color_temp(videv_switch_brightness):
KEY_COLOR_TEMP = 'color_temp'
def __init__(self, mqtt_client, topic, sw_device=None, sw_key=None, br_device=None, br_key=None, ct_device=None, ct_key=None):
super().__init__(mqtt_client, topic, sw_device, sw_key, br_device, br_key)
# TODO: Remove the following code and the parameters from __init__
if ct_device is not None and ct_key is not None:
self.connect_ct_device(ct_device, ct_key)
def __init__(self, mqtt_client, topic):
super().__init__(mqtt_client, topic)
def connect_ct_device(self, ct_device, ct_key):
self.add_routing(self.KEY_COLOR_TEMP, ct_device, ct_key)
@ -108,11 +95,8 @@ class videv_heating(videv_base):
#
KEY_TEMPERATURE = 'temperature'
def __init__(self, mqtt_client, topic, heating_function=None):
def __init__(self, mqtt_client, topic):
super().__init__(mqtt_client, topic)
# TODO: Remove the following code and the parameters from __init__
if heating_function is not None:
self.connect_heating_function(heating_function)
def connect_heating_function(self, heating_function):
#
@ -131,11 +115,8 @@ class videv_heating(videv_base):
class videv_multistate(videv_base):
KEY_STATE = 'state_%d'
def __init__(self, mqtt_client, topic, key_for_device=None, device=None, num_states=None, default_values=None):
def __init__(self, mqtt_client, topic):
super().__init__(mqtt_client, topic)
# TODO: Remove the following code and the parameters from __init__
if device is not None and key_for_device is not None and num_states is not None:
self.connect_br_function(device, key_for_device, num_states)
def connect_br_function(self, device, key_for_device, num_states):
self.num_states = num_states
@ -155,13 +136,9 @@ class videv_audio_player(videv_base):
KEY_TITLE = 'title'
NO_TITLE = '---'
def __init__(self, mqtt_client, topic, *args):
def __init__(self, mqtt_client, topic):
super().__init__(mqtt_client, topic)
self.__device_cnt__ = 0
#
# TODO: Remove the following code and the parameters from __init__
for device in args:
self.connect_audio_device(device)
def connect_audio_device(self, device):
self.add_display(self.KEY_ACTIVE_PLAYER % self.__device_cnt__, device, device.KEY_STATE)

View File

@ -1,87 +1,5 @@
#
# TOPICS
#
TOPIC_WARNINGS = "videv/warnings"
TOPIC_ALL_OFF_VIDEV = "videv/off"
TOPIC_ALL_SUMMER_WINTER_MODE = "videv/summer_mode"
# ground floor west
# floor
TOPIC_GFW_FLOOR_MAIN_LIGHT_VIDEV = "videv/gfw/floor/main_light"
# marion
TOPIC_GFW_MARION_MAIN_LIGHT_VIDEV = "videv/gfw/marion/main_light"
TOPIC_GFW_MARION_HEATING_VALVE_VIDEV = "videv/gfw/marion/heating_valve"
TOPIC_GFW_MARION_WINDOW_LAMP_VIDEV = "videv/gfw/marion/window_light"
# dirk
TOPIC_GFW_DIRK_MAIN_LIGHT_VIDEV = "videv/gfw/dirk/main_light"
TOPIC_GFW_DIRK_DESK_LIGHT_VIDEV = "videv/gfw/dirk/desk_light"
TOPIC_GFW_DIRK_AMPLIFIER_VIDEV = "videv/gfw/dirk/amplifier"
TOPIC_GFW_DIRK_PHONO_VIDEV = "videv/gfw/dirk/phono"
TOPIC_GFW_DIRK_CD_PLAYER_VIDEV = "videv/gfw/dirk/cd_player"
TOPIC_GFW_DIRK_BT_VIDEV = "videv/gfw/dirk/bt"
TOPIC_GFW_DIRK_PC_DOCK_VIDEV = "videv/gfw/dirk/pc_dock"
TOPIC_GFW_DIRK_ACTIVE_BRIGHTNESS_DEVICE_VIDEV = "videv/gfw/dirk/active_brightness_device"
TOPIC_GFW_DIRK_AUDIO_PLAYER_VIDEV = "videv/gfw/dirk/audio_player"
TOPIC_GFW_DIRK_HEATING_VALVE_VIDEV = "videv/gfw/dirk/heating_valve"
# garden
TOPIC_GAR_GARDEN_MODE_VIDEV = "videv/gar/garden/mode"
TOPIC_GAR_GARDEN_GARLAND_VIDEV = "videv/gar/garden/garland"
TOPIC_GAR_GARDEN_REPEATER_VIDEV = "videv/gar/garden/repeater"
# first floor west
# floor
TOPIC_FFW_FLOOR_MAIN_LIGHT_VIDEV = "videv/ffw/floor/main_light"
# julian
TOPIC_FFW_JULIAN_MAIN_LIGHT_VIDEV = "videv/ffw/julian/main_light"
TOPIC_FFW_JULIAN_HEATING_VALVE_VIDEV = "videv/ffw/julian/heating_valve"
# bath
TOPIC_FFW_BATH_MAIN_LIGHT_VIDEV = "videv/ffw/bath/main_light"
TOPIC_FFW_BATH_HEATING_VALVE_VIDEV = "videv/ffw/bath/heating_valve"
# livingroom
TOPIC_FFW_LIVINGROOM_MAIN_LIGHT_VIDEV = "videv/ffw/livingroom/main_light"
TOPIC_FFW_LIVINGROOM_HEATING_VALVE_VIDEV = "videv/ffw/livingroom/heating_valve"
# sleep
TOPIC_FFW_SLEEP_MAIN_LIGHT_VIDEV = "videv/ffw/sleep/main_light"
TOPIC_FFW_SLEEP_HEATING_VALVE_VIDEV = "videv/ffw/sleep/heating_valve"
TOPIC_FFW_SLEEP_WINDOW_LAMP_VIDEV = "videv/ffw/sleep/window_light"
# first floor east
# floor
TOPIC_FFE_FLOOR_MAIN_LIGHT_VIDEV = "videv/ffe/floor/main_light"
# kitchen
TOPIC_FFE_KITCHEN_MAIN_LIGHT_VIDEV = "videv/ffe/kitchen/main_light"
TOPIC_FFE_KITCHEN_CIRCULATION_PUMP_VIDEV = "videv/ffe/kitchen/circulation_pump"
TOPIC_FFE_KITCHEN_HEATING_VALVE_VIDEV = "videv/ffe/kitchen/heating_valve"
# diningroom
TOPIC_FFE_DININGROOM_MAIN_LIGHT_VIDEV = "videv/ffe/diningroom/main_light"
TOPIC_FFE_DININGROOM_FLOOR_LAMP_VIDEV = "videv/ffe/diningroom/floorlamp"
TOPIC_FFE_DININGROOM_GARLAND_VIDEV = "videv/ffe/diningroom/garland"
TOPIC_FFE_DININGROOM_HEATING_VALVE_VIDEV = "videv/ffe/diningroom/heating_valve"
# sleep
TOPIC_FFE_SLEEP_MAIN_LIGHT_VIDEV = "videv/ffe/sleep/main_light"
TOPIC_FFE_SLEEP_BED_LIGHT_DI_VIDEV = "videv/ffe/sleep/bed_light_di"
TOPIC_FFE_SLEEP_BED_LIGHT_MA_VIDEV = "videv/ffe/sleep/bed_light_ma"
TOPIC_FFE_SLEEP_ACTIVE_BRIGHTNESS_DEVICE_VIDEV = "videv/ffe/sleep/active_brightness_device"
TOPIC_FFE_SLEEP_HEATING_VALVE_VIDEV = "videv/ffe/sleep/heating_valve"
TOPIC_FFE_SLEEP_WARDROBE_LIGHT_VIDEV = "videv/ffe/sleep/wardrobe_light"
# livingroom
TOPIC_FFE_LIVINGROOM_MAIN_LIGHT_VIDEV = "videv/ffe/livingroom/main_light"
TOPIC_FFE_LIVINGROOM_FLOOR_LAMP_VIDEV = "videv/ffe/livingroom/floorlamp"
TOPIC_FFE_LIVINGROOM_XMAS_TREE_VIDEV = "videv/ffe/livingroom/xmas_tree"
TOPIC_FFE_LIVINGROOM_HEATING_VALVE_VIDEV = "videv/ffe/livingroom/heating_valve"
# stairway
# floor
TOPIC_STW_STAIRWAY_MAIN_LIGHT_VIDEV = "videv/stw/stairway/main_light"