From 58167fb8ecd719df6a6aca693cf9fd7735149db4 Mon Sep 17 00:00:00 2001 From: Dirk Alders Date: Thu, 28 Aug 2025 18:59:27 +0200 Subject: [PATCH] Device for stw added and cleanup --- devices.py | 242 ----------------------------------------------------- rooms.py | 3 +- topic.py | 4 +- 3 files changed, 4 insertions(+), 245 deletions(-) delete mode 100644 devices.py diff --git a/devices.py b/devices.py deleted file mode 100644 index 511c98c..0000000 --- a/devices.py +++ /dev/null @@ -1,242 +0,0 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- -# -from devdi import topic as props -from devdi.topic import get_topic -import devices -import logging - -try: - from config import APP_NAME as ROOT_LOGGER_NAME -except ImportError: - ROOT_LOGGER_NAME = 'root' -logger = logging.getLogger(ROOT_LOGGER_NAME).getChild(__name__) - - -class base(dict): - def __init__(self, mqtt_client): - super().__init__(self) - - def __dty_repr__(self, dty): - return { - props.DTY_SHY_SW1: devices.shelly_sw1, - props.DTY_HLI_SBT: devices.hue_sw_br_ct, - props.DTY_TLI_Sxx: devices.tradfri_sw, - props.DTY_TLI_SBx: devices.tradfri_sw_br, - props.DTY_TLI_SBT: devices.tradfri_sw_br_ct, - props.DTY_TIN_5xx: devices.tradfri_button, - props.DTY_LLI_SBT: devices.livarno_sw_br_ct, - props.DTY_BVL_xxx: devices.brennenstuhl_heatingvalve, - props.DTY_SPP_SW1: devices.silvercrest_powerplug, - props.DTY_SMS_xxx: devices.silvercrest_motion_sensor, - props.DTY_MPP_4xx: devices.my_powerplug, - props.DTY_MAS_xxx: devices.audio_status, - props.DTY_MRE_xxx: devices.remote, - props.DTY_MAM_THP: devices.my_ambient, - }.get(dty) - - def add(self, mqtt_client, stg, loc, roo, fun, dty, num=None): - """Method to initilise a device - - Args: - stg (numeric): Source transmittion group (see SIS_* in props) - loc (numeric): Location (see LOC_* in props) - roo (numeric): Room (see ROO_* in props) - fun (numeric): Function (see FUN_* in props) - dty (numeric): Device type (see DTP_* in props) - num (numeric): Device number in case of multiple devices - """ - def get_device(dty, mqtt_client, topic): - dev_class = self.__dty_repr__(dty) - if dev_class is None: - logger.warning('Device type %d is not yet implemented. Topic %s will not be supported.', dty, topic) - else: - return dev_class(mqtt_client, topic) - - topic = get_topic(stg, loc, roo, fun) - if num is None: - this_device = get_device(dty, mqtt_client, topic) - if this_device is None: - logger.warning('Device type %d is not yet implemented. Topic %s will not be supported.', dty, topic) - else: - self[topic] = this_device - logger.debug("Added a device type=%s, topic=%s", dty, topic) - else: - dg = [] - for i in range(1, num + 1): - device_topic = topic + '_%d' % i - dg.append(get_device(dty, mqtt_client, device_topic)) - this_device = devices.group(*dg) - self[topic] = this_device - logger.debug("Added a devicegroup type=%s, topic=%s", dty, topic + '_') - return this_device - - def get(self, stg, loc, roo, fun): - """Method to get a device - - Args: - stg (numeric): Source transmittion group (see SIS_* in props) - loc (numeric): Location (see LOC_* in props) - roo (numeric): Room (see ROO_* in props) - fun (numeric): Function (see FUN_* in props) - """ - topic = get_topic(stg, loc, roo, fun) - return self[topic] - - def get_str(self, stg, loc, roo, fun): - """Method to get a device by str version of props - - Args: - stg (str): Source transmittion group (see SIS_* in props) - loc (str): Location (see LOC_* in props) - roo (str): Room (see ROO_* in props) - fun (str): Function (see FUN_* in props) - """ - return self.get(getattr(props, stg), getattr(props, loc), getattr(props, roo), getattr(props, fun)) - - -class physical_devices(base): - """ - Class to create and store physical smarthome devices - """ - - def __init__(self, mqtt_client): - super().__init__(self) - self.__init_gfw__(mqtt_client) - self.__init_ffw__(mqtt_client) - self.__init_ffe__(mqtt_client) - self.__init_stw__(mqtt_client) - self.__init_gar__(mqtt_client) - - def __init_gfw__(self, mqtt_client): - loc = props.LOC_GFW - - # MARION - roo = props.ROO_MAR - # - self.add(mqtt_client, props.STG_SHE, loc, roo, props.FUN_MAL, props.DTY_SHY_SW1) # Shelly Main Light - self.add(mqtt_client, props.STG_ZGW, loc, roo, props.FUN_HEA, props.DTY_BVL_xxx) # Brennenstuhl Heatingvalve - self.add(mqtt_client, props.STG_ZGW, loc, roo, props.FUN_WIL, props.DTY_TLI_SBT) # Tradfri Windowlight - - # FLOOR - roo = props.ROO_FLO - # - self.add(mqtt_client, props.STG_SHE, loc, roo, props.FUN_MAL, props.DTY_SHY_SW1) # Shelly Main Light - self.add(mqtt_client, props.STG_ZGW, loc, roo, props.FUN_MAL, props.DTY_LLI_SBT, 2) # Tradfri Main Light - - # DIRK - roo = props.ROO_DIR - # - self.add(mqtt_client, props.STG_SHE, loc, roo, props.FUN_MAL, props.DTY_SHY_SW1) # Shelly Main Light - self.add(mqtt_client, props.STG_ZGW, loc, roo, props.FUN_MAL, props.DTY_TLI_SBT) # Tradfri Main Light - self.add(mqtt_client, props.STG_ZGW, loc, roo, props.FUN_INP, props.DTY_TIN_5xx) # Tradfri Input Device 5 Buttons - d = self.add(mqtt_client, props.STG_MYA, loc, roo, props.FUN_MPP, props.DTY_MPP_4xx) # My 4 port Powerplug - d.set_ch_name(d.KEY_OUTPUT_0, "amplifier") - d.set_ch_name(d.KEY_OUTPUT_1, "phono") - d.set_ch_name(d.KEY_OUTPUT_2, "cd-player") - d.set_ch_name(d.KEY_OUTPUT_3, "bluetooth") - self.add(mqtt_client, props.STG_ZGW, loc, roo, props.FUN_DEL, props.DTY_TLI_SBT) # Tradfri Desklight - self.add(mqtt_client, props.STG_ZGW, loc, roo, props.FUN_DCK, props.DTY_SPP_SW1) # Tradfri 1 port Powerplug - self.add(mqtt_client, props.STG_MYA, loc, roo, props.FUN_RCA, props.DTY_MRE_xxx) # Remote Control IR Amplifier - self.add(mqtt_client, props.STG_MYA, loc, roo, props.FUN_ASS, props.DTY_MAS_xxx) # Audio status Spotify - self.add(mqtt_client, props.STG_MYA, loc, roo, props.FUN_ASM, props.DTY_MAS_xxx) # Audio status MPD - self.add(mqtt_client, props.STG_MYA, loc, roo, props.FUN_ASB, props.DTY_MAS_xxx) # Audio status Bluetooth - self.add(mqtt_client, props.STG_ZGW, loc, roo, props.FUN_HEA, props.DTY_BVL_xxx) # Brennenstuhl Heatingvalve - self.add(mqtt_client, props.STG_MYA, loc, roo, props.FUN_AMB, props.DTY_MAM_THP) # My Ambient information - - def __init_gar__(self, mqtt_client): - loc = props.LOC_GAR - - # GARDEN - roo = props.ROO_GAR - self.add(mqtt_client, props.STG_ZGW, loc, roo, props.FUN_GAR, props.DTY_SPP_SW1) # Powerplugs Garden - self.add(mqtt_client, props.STG_ZGW, loc, roo, props.FUN_REP, props.DTY_SPP_SW1) # WiFi Garden - - def __init_ffw__(self, mqtt_client): - loc = props.LOC_FFW - # FLOOR - roo = props.ROO_FLO - # - self.add(mqtt_client, props.STG_SHE, loc, roo, props.FUN_MAL, props.DTY_SHY_SW1) # Shelly Main Light - - # JULIAN - roo = props.ROO_JUL - # - self.add(mqtt_client, props.STG_SHE, loc, roo, props.FUN_MAL, props.DTY_SHY_SW1) # Shelly Main Light - self.add(mqtt_client, props.STG_ZFW, loc, roo, props.FUN_MAL, props.DTY_TLI_SBT) # Tradfri Main Light - self.add(mqtt_client, props.STG_ZFW, loc, roo, props.FUN_HEA, props.DTY_BVL_xxx) # Brennenstuhl Heatingvalve - - # BATH - roo = props.ROO_BAT - # - self.add(mqtt_client, props.STG_SHE, loc, roo, props.FUN_MAL, props.DTY_SHY_SW1) # Shelly Main Light - self.add(mqtt_client, props.STG_ZFW, loc, roo, props.FUN_HEA, props.DTY_BVL_xxx) # Brennenstuhl Heatingvalve - - # LIVINGROOM - roo = props.ROO_LIV - # - self.add(mqtt_client, props.STG_SHE, loc, roo, props.FUN_MAL, props.DTY_SHY_SW1) # Shelly Main Light - self.add(mqtt_client, props.STG_ZFW, loc, roo, props.FUN_MAL, props.DTY_TLI_SBT) # Tradfri Main Light - self.add(mqtt_client, props.STG_ZFW, loc, roo, props.FUN_HEA, props.DTY_BVL_xxx) # Brennenstuhl Heatingvalve - - # SLEEP - roo = props.ROO_SLP - # - self.add(mqtt_client, props.STG_SHE, loc, roo, props.FUN_MAL, props.DTY_SHY_SW1) # Shelly Main Light - self.add(mqtt_client, props.STG_ZFW, loc, roo, props.FUN_MAL, props.DTY_TLI_SBx) # Tradfri Main Light - self.add(mqtt_client, props.STG_ZFW, loc, roo, props.FUN_HEA, props.DTY_BVL_xxx) # Brennenstuhl Heatingvalve - self.add(mqtt_client, props.STG_ZFW, loc, roo, props.FUN_WIL, props.DTY_TLI_SBT) # Tradfri Windowlight - - def __init_ffe__(self, mqtt_client): - loc = props.LOC_FFE - # FLOOR - roo = props.ROO_FLO - # - self.add(mqtt_client, props.STG_SHE, loc, roo, props.FUN_MAL, props.DTY_SHY_SW1) # Shelly Main Light - - # KITCHEN - roo = props.ROO_KIT - # - self.add(mqtt_client, props.STG_SHE, loc, roo, props.FUN_MAL, props.DTY_SHY_SW1) # Shelly Main Light - self.add(mqtt_client, props.STG_SHE, loc, roo, props.FUN_CIR, props.DTY_SHY_SW1) # Shelly Main Light - self.add(mqtt_client, props.STG_ZFE, loc, roo, props.FUN_MAL, props.DTY_HLI_SBT, 2) # Hue Main Light - self.add(mqtt_client, props.STG_ZFE, loc, roo, props.FUN_HEA, props.DTY_BVL_xxx) # Brennenstuhl Heatingvalve - - # DININGROOM - roo = props.ROO_DIN - # - self.add(mqtt_client, props.STG_SHE, loc, roo, props.FUN_MAL, props.DTY_SHY_SW1) # Shelly Main Light - self.add(mqtt_client, props.STG_ZFE, loc, roo, props.FUN_FLL, props.DTY_SPP_SW1) # Powerplug Floor Light - self.add(mqtt_client, props.STG_ZFE, loc, roo, props.FUN_GAR, props.DTY_SPP_SW1) # Powerplug Garland - self.add(mqtt_client, props.STG_ZFE, loc, roo, props.FUN_HEA, props.DTY_BVL_xxx) # Brennenstuhl Heatingvalve - - # SLEEP - roo = props.ROO_SLP - # - self.add(mqtt_client, props.STG_SHE, loc, roo, props.FUN_MAL, props.DTY_SHY_SW1) # Shelly Main Light - self.add(mqtt_client, props.STG_ZFE, loc, roo, props.FUN_MAL, props.DTY_TLI_SBT) # Tradfri Main Light - self.add(mqtt_client, props.STG_ZFE, loc, roo, props.FUN_INP, props.DTY_TIN_5xx) # Tradfri Input Device 5 Buttons - self.add(mqtt_client, props.STG_ZFE, loc, roo, props.FUN_BLD, props.DTY_TLI_SBx) # Tradfri Bed Light Dirk - self.add(mqtt_client, props.STG_ZFE, loc, roo, props.FUN_BLM, props.DTY_SPP_SW1) # Powerplug Bed Light Marion - self.add(mqtt_client, props.STG_ZFE, loc, roo, props.FUN_HEA, props.DTY_BVL_xxx) # Brennenstuhl Heatingvalve - self.add(mqtt_client, props.STG_ZFE, loc, roo, props.FUN_WLI, props.DTY_TLI_SBx) # Tradfri Wardobe light - - # LIVINGROOM - roo = props.ROO_LIV - # - self.add(mqtt_client, props.STG_SHE, loc, roo, props.FUN_MAL, props.DTY_SHY_SW1) # Shelly Main Light - self.add(mqtt_client, props.STG_ZFE, loc, roo, props.FUN_MAL, props.DTY_TLI_SBT) # Tradfri Main Light - self.add(mqtt_client, props.STG_ZFE, loc, roo, props.FUN_FLL, props.DTY_TLI_SBT, 6) # Tradfri Floorlamp - self.add(mqtt_client, props.STG_ZFE, loc, roo, props.FUN_XTR, props.DTY_SPP_SW1) # X-Mas Tree - self.add(mqtt_client, props.STG_ZFE, loc, roo, props.FUN_XST, props.DTY_SPP_SW1) # X-Mas Star - self.add(mqtt_client, props.STG_ZFE, loc, roo, props.FUN_HEA, props.DTY_BVL_xxx) # Brennenstuhl Heatingvalve - self.add(mqtt_client, props.STG_MYA, loc, roo, props.FUN_AMB, props.DTY_MAM_THP) # My Ambient information - - def __init_stw__(self, mqtt_client): - loc = props.LOC_STW - # FLOOR - # - self.add(mqtt_client, props.STG_SHE, loc, props.ROO_STF, props.FUN_MAL, props.DTY_SHY_SW1) # Shelly Main Light - self.add(mqtt_client, props.STG_ZFE, loc, props.ROO_STF, props.FUN_MSE, props.DTY_SMS_xxx) # Motion Sensor First Floor - self.add(mqtt_client, props.STG_ZGW, loc, props.ROO_STG, props.FUN_MSE, props.DTY_SMS_xxx) # Motion Sensor Ground Floor - diff --git a/rooms.py b/rooms.py index dcb2d81..32019e7 100644 --- a/rooms.py +++ b/rooms.py @@ -105,6 +105,7 @@ from devices import videv_sw from devices import videv_sw_br from devices import videv_sw_br_ct from devices import videv_sw_tm +from devices import videv_sw_mo from devices import videv_hea from devices import videv_pure_switch from devices import videv_multistate @@ -406,4 +407,4 @@ class stairway(base_room): self.switch_main_light = shelly_sw1(mqtt_client, get_topic(props.STG_SHE, loc, props.ROO_STF, props.FUN_MAL)) self.motion_main_light_gf = silvercrest_motion_sensor(mqtt_client, get_topic(props.STG_ZGW, loc, props.ROO_STG, props.FUN_MSE)) self.motion_main_light_ff = silvercrest_motion_sensor(mqtt_client, get_topic(props.STG_ZFE, loc, props.ROO_STF, props.FUN_MSE)) - self.videv_main_light = videv_sw(mqtt_client, get_topic(props.STG_VDE, loc, props.ROO_STF, props.FUN_MAL)) + self.videv_main_light = videv_sw_mo(mqtt_client, get_topic(props.STG_VDE, loc, props.ROO_STF, props.FUN_MAL)) diff --git a/topic.py b/topic.py index a21c581..88e9d40 100644 --- a/topic.py +++ b/topic.py @@ -235,13 +235,13 @@ def get_topic(stg, loc, roo, fun): fun_topic = FUN_TOPIC[fun] s = '/'.join([stg_topic, loc_topic, roo_topic, fun_topic]) # TODO: /!\ Changed TOPIC in VIDEV /!\ - Remove this line after changing nodered + TOPIC_STW_STAIRWAY_MAIN_LIGHT_VIDEV = "videv/stw/stairway/main_light" if stg == STG_VDE and fun == FUN_DCK: s = '/'.join([stg_topic, loc_topic, roo_topic, 'pc_dock']) if stg == STG_VDE and fun == FUN_FLL: s = '/'.join([stg_topic, loc_topic, roo_topic, 'floorlamp']) if stg == STG_VDE and roo == ROO_STF and fun == FUN_MAL: - import config # nopep8 - s = config.TOPIC_STW_STAIRWAY_MAIN_LIGHT_VIDEV + s = TOPIC_STW_STAIRWAY_MAIN_LIGHT_VIDEV if stg == STG_VDE and fun == FUN_XTR: s = '/'.join([stg_topic, loc_topic, roo_topic, 'xmas_tree']) # TODO: /!\ Changed TOPIC in VIDEV /!\ - Remove this line after changing nodered