From 4fa00811c6d243888828e67b0952b5b06f46a3d7 Mon Sep 17 00:00:00 2001 From: Dirk Alders Date: Mon, 25 Aug 2025 18:33:52 +0200 Subject: [PATCH] Added room definitions for future use. --- devices.py | 34 ++---------- topic.py | 149 +++++++++++++++++++++++++++++++---------------------- 2 files changed, 91 insertions(+), 92 deletions(-) diff --git a/devices.py b/devices.py index a2f1853..511c98c 100644 --- a/devices.py +++ b/devices.py @@ -2,7 +2,7 @@ # -*- coding: utf-8 -*- # from devdi import topic as props -from devdi.topic import topic_by_props +from devdi.topic import get_topic import devices import logging @@ -53,7 +53,7 @@ class base(dict): else: return dev_class(mqtt_client, topic) - topic = str(topic_by_props(stg, loc, roo, fun)) + topic = get_topic(stg, loc, roo, fun) if num is None: this_device = get_device(dty, mqtt_client, topic) if this_device is None: @@ -80,7 +80,7 @@ class base(dict): roo (numeric): Room (see ROO_* in props) fun (numeric): Function (see FUN_* in props) """ - topic = topic_by_props(stg, loc, roo, fun) + topic = get_topic(stg, loc, roo, fun) return self[topic] def get_str(self, stg, loc, roo, fun): @@ -240,31 +240,3 @@ class physical_devices(base): 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 - -class videv_devices(base): - """ - Class to create and store videv 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) - - def __init_gfw__(self, mqtt_client): - loc = props.LOC_GFW - # TODO: Add devices - - def __init_ffw__(self, mqtt_client): - loc = props.LOC_FFW - # TODO: Add devices - - def __init_ffe__(self, mqtt_client): - loc = props.LOC_FFE - # TODO: Add devices - - def __init_stw__(self, mqtt_client): - loc = props.LOC_STW - # TODO: Add devices diff --git a/topic.py b/topic.py index 3ca1119..b29b59f 100644 --- a/topic.py +++ b/topic.py @@ -45,6 +45,8 @@ STG_SHE = 4 """ Shellies """ STG_MYA = 5 """ My Applications """ +STG_VDE = 6 +""" Videv Devices """ # @@ -143,70 +145,95 @@ FUN_WLI = 22 """ Warddrobe light """ FUN_WIL = 23 """ Window light """ +FUN_AMP = 24 +""" Amplifier """ +FUN_CDP = 25 +""" CD Player """ +FUN_BTP = 26 +""" Bluetooth """ +FUN_PHO = 27 +""" Phono """ -class topic_by_props(UserString): - def __init__(self, stg, loc, roo, fun): - UserString.__init__(self, '/'.join([self.__stg_repr__(stg), self.__loc_repr__(loc), self.__roo_repr__(roo), self.__fun_repr__(fun)])) +STG_TOPIC = { + STG_ZGW: 'zigbee_gfw', + STG_ZFW: 'zigbee_ffw', + STG_ZFE: 'zigbee_ffe', + STG_SHE: 'shellies', + STG_MYA: 'my_apps', + STG_VDE: 'videv', +} - def __stg_repr__(self, stg): - return { - STG_ZGW: 'zigbee_gfw', - STG_ZFW: 'zigbee_ffw', - STG_ZFE: 'zigbee_ffe', - STG_SHE: 'shellies', - STG_MYA: 'my_apps', - }.get(stg) +LOC_TOPIC = { + LOC_GFE: 'gfe', + LOC_GFW: 'gfw', + LOC_FFE: 'ffe', + LOC_FFW: 'ffw', + LOC_GAR: 'gar', + LOC_STW: 'stw', +} - def __loc_repr__(self, loc): - return { - LOC_GFE: 'gfe', - LOC_GFW: 'gfw', - LOC_FFE: 'ffe', - LOC_FFW: 'ffw', - LOC_GAR: 'gar', - LOC_STW: 'stw', - }.get(loc) +ROO_TOPIC = { + ROO_DIN: 'diningroom', + ROO_KIT: 'kitchen', + ROO_LIV: 'livingroom', + ROO_FLO: 'floor', + ROO_SLP: 'sleep', + ROO_BAT: 'bath', + ROO_DIR: 'dirk', + ROO_MAR: 'marion', + ROO_JUL: 'julian', + ROO_STG: 'groundfloor', + ROO_STF: 'firstfloor', + ROO_GAR: 'garden', +} - def __roo_repr__(self, roo): - return { - ROO_DIN: 'diningroom', - ROO_KIT: 'kitchen', - ROO_LIV: 'livingroom', - ROO_FLO: 'floor', - ROO_SLP: 'sleep', - ROO_BAT: 'bath', - ROO_DIR: 'dirk', - ROO_MAR: 'marion', - ROO_JUL: 'julian', - ROO_STG: 'groundfloor', - ROO_STF: 'firstfloor', - ROO_GAR: 'garden', - }.get(roo) +FUN_TOPIC = { + FUN_MAL: 'main_light', + FUN_DEL: 'desk_light', + FUN_FLL: 'floor_light', + FUN_BLD: 'bed_light_di', + FUN_BLM: 'bed_light_ma', + FUN_HEA: 'heating_valve', + FUN_MPP: 'powerplug', + FUN_INP: 'input_device', + FUN_DCK: 'dock', + FUN_CIR: 'circulation_pump', + FUN_GAR: 'garland', + FUN_XTR: 'xmas-tree', + FUN_XST: 'xmas-star', + FUN_MSE: 'motion_sensor', + FUN_RCA: 'remote_ctrl/RAS5', + FUN_RCC: 'remote_ctrl/EUR642100', + FUN_ASS: 'audio_status_spotify', + FUN_ASM: 'audio_status_mpd', + FUN_ASB: 'audio_status_bt', + FUN_AMB: 'ambient', + FUN_REP: 'repeater', + FUN_WLI: 'wardrobe_light', + FUN_WIL: 'window_light', + FUN_AMP: 'amplifier', + FUN_CDP: 'cd_player', + FUN_BTP: 'bt', + FUN_PHO: 'phono', +} - def __fun_repr__(self, fun): - return { - FUN_MAL: 'main_light', - FUN_DEL: 'desk_light', - FUN_FLL: 'floor_light', - FUN_BLD: 'bed_light_di', - FUN_BLM: 'bed_light_ma', - FUN_HEA: 'heating_valve', - FUN_MPP: 'powerplug', - FUN_INP: 'input_device', - FUN_DCK: 'dock', - FUN_CIR: 'circulation_pump', - FUN_GAR: 'garland', - FUN_XTR: 'xmas-tree', - FUN_XST: 'xmas-star', - FUN_MSE: 'motion_sensor', - FUN_RCA: 'remote_ctrl/RAS5', - FUN_RCC: 'remote_ctrl/EUR642100', - FUN_ASS: 'audio_status_spotify', - FUN_ASM: 'audio_status_mpd', - FUN_ASB: 'audio_status_bt', - FUN_AMB: 'ambient', - FUN_REP: 'repeater', - FUN_WLI: 'wardrobe_light', - FUN_WIL: 'window_light', - }.get(fun) + +def get_topic(stg, loc, roo, fun): + stg_topic = STG_TOPIC[stg] + loc_topic = LOC_TOPIC[loc] + roo_topic = ROO_TOPIC[roo] + 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 + 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 + 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 + return s