From 946ceead96b765f6fd8b6fc3db25deb5dd6cbac6 Mon Sep 17 00:00:00 2001 From: Dirk Alders Date: Tue, 19 Aug 2025 22:32:08 +0200 Subject: [PATCH] Added Channel names for devices --- devdi | 2 +- devices/__init__.py | 7 ++++++- simulation/devices.py | 12 ++++-------- simulation/rooms.py | 29 +---------------------------- tests/__init__.py | 1 + tests/common_testcases.py | 4 ++-- 6 files changed, 15 insertions(+), 40 deletions(-) diff --git a/devdi b/devdi index 6813ec4..1afa4f7 160000 --- a/devdi +++ b/devdi @@ -1 +1 @@ -Subproject commit 6813ec40fe716cfc5bdab827769f8d88bfbc860e +Subproject commit 1afa4f73eee8ac5a5b1abda4d7b413a19e10019f diff --git a/devices/__init__.py b/devices/__init__.py index 02bbf65..2e9641f 100644 --- a/devices/__init__.py +++ b/devices/__init__.py @@ -5,9 +5,9 @@ from simulation.devices import shelly as shelly_sw1 from simulation.devices import brennenstuhl_heatingvalve from simulation.devices import my_powerplug + shelly_pro3 = None tradfri_button = None -hue_sw_br_ct = None silvercrest_button = None silvercrest_motion_sensor = None audio_status = None @@ -30,6 +30,11 @@ class tradfri_sw_br_ct(tradfri_light): super().__init__(mqtt_client, topic, enable_state=True, enable_brightness=True, enable_color_temp=True, send_on_power_on=True) +class hue_sw_br_ct(tradfri_light): + def __init__(self, mqtt_client, topic): + super().__init__(mqtt_client, topic, enable_state=True, enable_brightness=True, enable_color_temp=True, send_on_power_on=True) + + class livarno_sw_br_ct(tradfri_light): def __init__(self, mqtt_client, topic): super().__init__(mqtt_client, topic, enable_state=True, enable_brightness=True, enable_color_temp=True, send_on_power_on=False) diff --git a/simulation/devices.py b/simulation/devices.py index f0d4472..542229a 100644 --- a/simulation/devices.py +++ b/simulation/devices.py @@ -14,7 +14,7 @@ COLOR_WARNINGS = colored.fg("dark_orange_3b") COLOR_HEATING_VALVE = colored.fg("red") COLOR_REMOTE = colored.fg("green") -OUTPUT_ACTIVE = True +OUTPUT_ACTIVE = False class base_common(mqtt_base): @@ -25,12 +25,8 @@ class base_common(mqtt_base): def __init__(self, mqtt_client, topic, default_values=None): super().__init__(mqtt_client, topic, default_values) - self.names = {} self.commands = self.COMMANDS[:] - def add_channel_name(self, key, name): - self.names[key] = name - def __payload_filter__(self, payload): try: return json.loads(payload) @@ -282,7 +278,7 @@ class shelly(base): def print_formatted(self, device, key, value): if value is not None: info = (" - %ds" % self.__output_0_auto_off__) if self.__output_0_auto_off__ is not None and value else "" - channel = "(%s%s)" % (self.names.get(key, key), info) + channel = "(%s%s)" % (self.get_name(key, key), info) self.print_formatted_light(COLOR_SHELLY, value, channel) def warning_state_on(self): @@ -348,7 +344,7 @@ class my_powerplug(base): def print_formatted(self, device, key, value): if value is not None: - self.print_formatted_light(COLOR_POWERPLUG, value, "(%s)" % self.names.get(key, "State")) + self.print_formatted_light(COLOR_POWERPLUG, value, "(%s)" % self.get_name(key, "State")) class silvercrest_powerplug(base): @@ -393,7 +389,7 @@ class silvercrest_powerplug(base): def print_formatted(self, device, key, value): if value is not None: - self.print_formatted_light(COLOR_POWERPLUG, value, "(%s)" % self.names.get(key, key)) + self.print_formatted_light(COLOR_POWERPLUG, value, "(%s)" % self.get_name(key, key)) class tradfri_light(base): diff --git a/simulation/rooms.py b/simulation/rooms.py index 4520802..5b9e8ef 100644 --- a/simulation/rooms.py +++ b/simulation/rooms.py @@ -3,8 +3,6 @@ from simulation.devices import videv_light, videv_heating, videv_warnings import inspect from devdi import topic as props -# TODO: Add channel names for all devices in devdi! Move it from here to devdi. Adaption in other prjs required! - class base(object): def getmembers(self, prefix=''): @@ -47,8 +45,7 @@ class gfw_floor(base): # self.main_light = pd.get(props.STG_SHE, loc, roo, props.FUN_MAL) self.main_light.configure(input_0_func=self.main_light.INPUT_FUNC_OUT1_TRIGGER) - self.main_light.add_channel_name(self.main_light.KEY_OUTPUT_0, "Main Light") - self.main_light_zigbee = pd.get(props.STG_ZGW, loc, roo, props.FUN_MAL) # , True, True, True, False + self.main_light_zigbee = pd.get(props.STG_ZGW, loc, roo, props.FUN_MAL) self.main_light.add_callback(self.main_light.KEY_OUTPUT_0, True, self.main_light_zigbee.power_on) self.main_light.add_callback(self.main_light.KEY_OUTPUT_0, False, self.main_light_zigbee.power_off) # @@ -62,9 +59,7 @@ class gfw_marion(base): # self.main_light = pd.get(props.STG_SHE, loc, roo, props.FUN_MAL) self.main_light.configure(input_0_func=self.main_light.INPUT_FUNC_OUT1_TRIGGER) - self.main_light.add_channel_name(self.main_light.KEY_OUTPUT_0, "Main Light (gfw.marion)") self.window_light = pd.get(props.STG_ZGW, loc, roo, props.FUN_WIL) - self.main_light.add_channel_name(self.main_light.KEY_OUTPUT_0, "Window Light (gfw.marion)") self.heating_valve = pd.get(props.STG_ZGW, loc, roo, props.FUN_HEA) @@ -81,19 +76,13 @@ class gfw_dirk(base): # self.main_light = pd.get(props.STG_SHE, loc, roo, props.FUN_MAL) self.main_light.configure(input_0_func=self.main_light.INPUT_FUNC_OUT1_TRIGGER) - self.main_light.add_channel_name(self.main_light.KEY_OUTPUT_0, "Main Light (gfw.dirk)") self.main_light_zigbee = pd.get(props.STG_ZGW, loc, roo, props.FUN_MAL) self.main_light.add_callback(self.main_light.KEY_OUTPUT_0, True, self.main_light_zigbee.power_on) self.main_light.add_callback(self.main_light.KEY_OUTPUT_0, False, self.main_light_zigbee.power_off) self.desk_light = pd.get(props.STG_ZGW, loc, roo, props.FUN_DEL) - self.desk_light.add_channel_name(self.desk_light.KEY_OUTPUT_0, "Desk Light (gfw.dirk)") self.pc_dock = pd.get(props.STG_ZGW, loc, roo, props.FUN_DCK) self.my_powerplug = pd.get(props.STG_MYA, loc, roo, props.FUN_MPP) - self.my_powerplug.add_channel_name(self.my_powerplug.KEY_OUTPUT_0, "Amplifier (gfw.dirk)") - self.my_powerplug.add_channel_name(self.my_powerplug.KEY_OUTPUT_1, "Phono (gfw.dirk)") - self.my_powerplug.add_channel_name(self.my_powerplug.KEY_OUTPUT_2, "CD_Player (gfw.dirk)") - self.my_powerplug.add_channel_name(self.my_powerplug.KEY_OUTPUT_3, "Bluetooth (gfw.dirk)") self.heating_valve = pd.get(props.STG_ZGW, loc, roo, props.FUN_HEA) @@ -124,7 +113,6 @@ class ffw_julian(base): # self.main_light = pd.get(props.STG_SHE, loc, roo, props.FUN_MAL) self.main_light.configure(input_0_func=self.main_light.INPUT_FUNC_OUT1_TRIGGER) - self.main_light.add_channel_name(self.main_light.KEY_OUTPUT_0, "Main Light (ffw.julian)") self.main_light_zigbee = pd.get(props.STG_ZFW, loc, roo, props.FUN_MAL) self.main_light.add_callback(self.main_light.KEY_OUTPUT_0, True, self.main_light_zigbee.power_on) self.main_light.add_callback(self.main_light.KEY_OUTPUT_0, False, self.main_light_zigbee.power_off) @@ -140,7 +128,6 @@ class ffw_livingroom(base): # self.main_light = pd.get(props.STG_SHE, loc, roo, props.FUN_MAL) self.main_light.configure(input_0_func=self.main_light.INPUT_FUNC_OUT1_TRIGGER) - self.main_light.add_channel_name(self.main_light.KEY_OUTPUT_0, "Main Light (ffw.livingroom)") self.main_light_zigbee = pd.get(props.STG_ZFW, loc, roo, props.FUN_MAL) self.main_light.add_callback(self.main_light.KEY_OUTPUT_0, True, self.main_light_zigbee.power_on) self.main_light.add_callback(self.main_light.KEY_OUTPUT_0, False, self.main_light_zigbee.power_off) @@ -156,7 +143,6 @@ class ffw_sleep(base): # self.main_light = pd.get(props.STG_SHE, loc, roo, props.FUN_MAL) self.main_light.configure(input_0_func=self.main_light.INPUT_FUNC_OUT1_TRIGGER) - self.main_light.add_channel_name(self.main_light.KEY_OUTPUT_0, "Main Light (ffw.sleep)") self.main_light_zigbee = pd.get(props.STG_ZFW, loc, roo, props.FUN_MAL) self.main_light.add_callback(self.main_light.KEY_OUTPUT_0, True, self.main_light_zigbee.power_on) self.main_light.add_callback(self.main_light.KEY_OUTPUT_0, False, self.main_light_zigbee.power_off) @@ -182,7 +168,6 @@ class ffw_floor(base): # self.main_light = pd.get(props.STG_SHE, loc, roo, props.FUN_MAL) self.main_light.configure(input_0_func=self.main_light.INPUT_FUNC_OUT1_TRIGGER) - self.main_light.add_channel_name(self.main_light.KEY_OUTPUT_0, "Main Light (ffw.floor)") # self.videv_main_light = videv_light(mqtt_client, config.TOPIC_FFW_FLOOR_MAIN_LIGHT_VIDEV, True, False, False) @@ -203,7 +188,6 @@ class ffe_floor(base): # self.main_light = pd.get(props.STG_SHE, loc, roo, props.FUN_MAL) self.main_light.configure(input_0_func=self.main_light.INPUT_FUNC_OUT1_TRIGGER) - self.main_light.add_channel_name(self.main_light.KEY_OUTPUT_0, "Main Light (ffe.floor)") # self.videv_main_light = videv_light(mqtt_client, config.TOPIC_FFE_FLOOR_MAIN_LIGHT_VIDEV, True, False, False) @@ -216,11 +200,9 @@ class ffe_kitchen(base): # self.main_light = pd.get(props.STG_SHE, loc, roo, props.FUN_MAL) self.main_light.configure(input_0_func=self.main_light.INPUT_FUNC_OUT1_TRIGGER) - self.main_light.add_channel_name(self.main_light.KEY_OUTPUT_0, "Main Light (ffe.kitchen)") self.circulation_pump = pd.get(props.STG_SHE, loc, roo, props.FUN_CIR) self.circulation_pump.configure(input_0_func=self.main_light.INPUT_FUNC_OUT1_TRIGGER) # , output_0_auto_off=10*60) - self.circulation_pump.add_channel_name(self.circulation_pump.KEY_OUTPUT_0, "Circulation Pump (ffe.kitchen)") # self.videv_main_light = videv_light(mqtt_client, config.TOPIC_FFE_KITCHEN_MAIN_LIGHT_VIDEV, True, False, False) @@ -234,14 +216,11 @@ class ffe_diningroom(base): # self.main_light = pd.get(props.STG_SHE, loc, roo, props.FUN_MAL) self.main_light.configure(input_0_func=self.main_light.INPUT_FUNC_OUT1_TRIGGER) - self.main_light.add_channel_name(self.main_light.KEY_OUTPUT_0, "Main Light (ffe.diningroom)") self.floor_lamp = pd.get(props.STG_ZFE, loc, roo, props.FUN_FLL) - self.floor_lamp.add_channel_name(self.floor_lamp.KEY_OUTPUT_0, "Floor Lamp (ffe.diningroom)") if config.CHRISTMAS: self.garland = pd.get(props.STG_ZFE, loc, roo, props.FUN_GAR) - self.garland.add_channel_name(self.garland.KEY_OUTPUT_0, "Garland (ffe.diningroom)") # self.videv_main_light = videv_light(mqtt_client, config.TOPIC_FFE_DININGROOM_MAIN_LIGHT_VIDEV, True, False, False) @@ -257,14 +236,12 @@ class ffe_sleep(base): # self.main_light = pd.get(props.STG_SHE, loc, roo, props.FUN_MAL) self.main_light.configure(input_0_func=self.main_light.INPUT_FUNC_OUT1_TRIGGER) - self.main_light.add_channel_name(self.main_light.KEY_OUTPUT_0, "Main Light (ffe.sleep)") self.main_light_zigbee = pd.get(props.STG_ZFE, loc, roo, props.FUN_MAL) self.main_light.add_callback(self.main_light.KEY_OUTPUT_0, True, self.main_light_zigbee.power_on) self.main_light.add_callback(self.main_light.KEY_OUTPUT_0, False, self.main_light_zigbee.power_off) self.bed_light_di_zigbee = pd.get(props.STG_ZFE, loc, roo, props.FUN_BLD) self.bed_light_ma = pd.get(props.STG_ZFE, loc, roo, props.FUN_BLM) - self.bed_light_ma.add_channel_name(self.bed_light_ma.KEY_OUTPUT_0, "Bed light Marion (ffe.sleep)") self.heating_valve = pd.get(props.STG_ZFE, loc, roo, props.FUN_HEA) @@ -284,7 +261,6 @@ class ffe_livingroom(base): # self.main_light = pd.get(props.STG_SHE, loc, roo, props.FUN_MAL) self.main_light.configure(input_0_func=self.main_light.INPUT_FUNC_OUT1_TRIGGER) - self.main_light.add_channel_name(self.main_light.KEY_OUTPUT_0, "Main Light (ffe.livingroom)") self.main_light_zigbee = pd.get(props.STG_ZFE, loc, roo, props.FUN_MAL) self.main_light.add_callback(self.main_light.KEY_OUTPUT_0, True, self.main_light_zigbee.power_on) self.main_light.add_callback(self.main_light.KEY_OUTPUT_0, False, self.main_light_zigbee.power_off) @@ -293,9 +269,7 @@ class ffe_livingroom(base): if config.CHRISTMAS: self.xmas_tree = pd.get(props.STG_ZFE, loc, roo, props.FUN_XTR) - self.xmas_tree.add_channel_name(self.xmas_tree.KEY_OUTPUT_0, "Xmas-Tree (ffe.livingroom)") self.xmas_star = pd.get(props.STG_ZFE, loc, roo, props.FUN_XST) - self.xmas_star.add_channel_name(self.xmas_star.KEY_OUTPUT_0, "Xmas-Star (ffe.livingroom)") # self.videv_main_light = videv_light(mqtt_client, config.TOPIC_FFE_LIVINGROOM_MAIN_LIGHT_VIDEV, True, True, True) @@ -320,7 +294,6 @@ class stairway(base): # self.main_light = pd.get(props.STG_SHE, loc, roo, props.FUN_MAL) self.main_light.configure(input_0_func=self.main_light.INPUT_FUNC_OUT1_TRIGGER) - self.main_light.add_channel_name(self.main_light.KEY_OUTPUT_0, "Main Light (stairway)") # self.videv_main_light = videv_light(mqtt_client, config.TOPIC_STW_STAIRWAY_MAIN_LIGHT_VIDEV, True, False, False, True) diff --git a/tests/__init__.py b/tests/__init__.py index b5a1548..0e1d948 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -9,3 +9,4 @@ def add_all_testcases(ts, mc, h): gfe(ts, mc, h) gfw(ts, mc, h) stw(ts, mc, h) + # TODO: GARDEN diff --git a/tests/common_testcases.py b/tests/common_testcases.py index 2063705..8675f60 100644 --- a/tests/common_testcases.py +++ b/tests/common_testcases.py @@ -19,9 +19,9 @@ def device_follow(tLogger, master, master_key, slave, slave_key, values): # Test devices for value in values: - tLogger.debug("Setting state of %s to %s", master.names.get(master_key, master.topic), repr(value)) + tLogger.debug("Setting state of %s to %s", master.get_name(master_key, master.topic), repr(value)) master.set(master_key, value) time.sleep(DELAY_SET_GET) expectation = slave.get(slave_key) time.sleep(DELAY_SET_GET) - equivalency_chk(expectation, value, tLogger, f"Value for {slave.names.get(slave_key, slave.topic)}") + equivalency_chk(expectation, value, tLogger, f"Value for {slave.get_name(slave_key, slave.topic)}")