From c9bf0365917f5946ec9d0298fadb3cb861c8b130 Mon Sep 17 00:00:00 2001 From: Dirk Alders Date: Thu, 5 Sep 2024 07:13:59 +0200 Subject: [PATCH] Added pssibility to disable all_off functionality of output devices. Disabled all_off for ffe.sleep.wardrobe_light --- devices/base.py | 16 ++++++++++++++++ devices/mydevices.py | 6 +++--- devices/shelly.py | 8 ++++---- devices/silvercrest.py | 6 +++--- devices/tradfri.py | 6 +++--- function/first_floor_east.py | 1 + 6 files changed, 30 insertions(+), 13 deletions(-) diff --git a/devices/base.py b/devices/base.py index 61b469e..90047e8 100644 --- a/devices/base.py +++ b/devices/base.py @@ -116,3 +116,19 @@ class base(mqtt_base): self.mqtt_client.send('/'.join([self.topic, key, self.TX_TOPIC] if len(self.TX_TOPIC) > 0 else [self.topic, key]), data) else: self.logger.error("Unknown tx toptic. Set TX_TOPIC of class to a known value") + + +class base_output(base): + def __init__(self, mqtt_client, topic): + super().__init__(mqtt_client, topic) + self.__all_off_enabled__ = True + + def disable_all_off(self, state=True): + self.__all_off_enabled__ = not state + + def all_off(self): + if self.__all_off_enabled__: + try: + self.__all_off__() + except (AttributeError, TypeError) as e: + self.logger.warning("Method all_off was used, but __all_off__ method wasn't callable: %s", repr(e)) diff --git a/devices/mydevices.py b/devices/mydevices.py index 658ffac..eb8b97a 100644 --- a/devices/mydevices.py +++ b/devices/mydevices.py @@ -1,11 +1,11 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- # -from devices.base import base +from devices.base import base, base_output import logging -class powerplug(base): +class powerplug(base_output): """ Communication (MQTT) my_powerplug @@ -115,7 +115,7 @@ class powerplug(base): def set_output_all_mcb(self, device, key, data): self.set_output_all(data) - def all_off(self): + def __all_off__(self): self.set_output_all(False) diff --git a/devices/shelly.py b/devices/shelly.py index 3b937e1..12c2495 100644 --- a/devices/shelly.py +++ b/devices/shelly.py @@ -1,12 +1,12 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- # -from devices.base import base +from devices.base import base_output import logging import task -class shelly(base): +class shelly(base_output): """ Communication (MQTT) shelly @@ -52,7 +52,7 @@ class shelly(base): KEY_FIRMWARE_VERSION = "fw_ver" # TX_TOPIC = "command" - TX_TYPE = base.TX_VALUE + TX_TYPE = base_output.TX_VALUE TX_FILTER_DATA_KEYS = [KEY_OUTPUT_0, KEY_OUTPUT_1] # RX_KEYS = [KEY_OUTPUT_0, KEY_OUTPUT_1, KEY_INPUT_0, KEY_INPUT_1, KEY_LONGPUSH_0, KEY_LONGPUSH_1, KEY_OVERTEMPERATURE, KEY_TEMPERATURE, @@ -161,7 +161,7 @@ class shelly(base): self.toggle_output_1_mcb(device, key, data) self.delayed_flash_task.run() - def all_off(self): + def __all_off__(self): if self.flash_active: self.all_off_requested = True else: diff --git a/devices/silvercrest.py b/devices/silvercrest.py index 5f926a3..0aa7313 100644 --- a/devices/silvercrest.py +++ b/devices/silvercrest.py @@ -1,11 +1,11 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- # -from devices.base import base +from devices.base import base, base_output import logging -class silvercrest_powerplug(base): +class silvercrest_powerplug(base_output): """ Communication (MQTT) silvercrest_powerplug { @@ -58,7 +58,7 @@ class silvercrest_powerplug(base): def toggle_output_0_mcb(self, device, key, data): self.set_output_0(not self.output_0) - def all_off(self): + def __all_off__(self): if self.output_0: self.set_output_0(False) diff --git a/devices/tradfri.py b/devices/tradfri.py index bbef409..3b5faf1 100644 --- a/devices/tradfri.py +++ b/devices/tradfri.py @@ -1,11 +1,11 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- # -from devices.base import base +from devices.base import base, base_output import logging -class tradfri_light(base): +class tradfri_light(base_output): """ Communication (MQTT) tradfri_light { @@ -124,7 +124,7 @@ class tradfri_light(base): def set_color_temp_mcb(self, device, key, data): self.set_color_temp(data) - def all_off(self): + def __all_off__(self): if self.output_0: self.set_output_0(False) diff --git a/function/first_floor_east.py b/function/first_floor_east.py index c0ecbc4..b74ae1f 100644 --- a/function/first_floor_east.py +++ b/function/first_floor_east.py @@ -193,6 +193,7 @@ class first_floor_east_sleep(room): self.button_tradfri = pd.get(props.STG_ZFE, loc, roo, props.FUN_INP) # wardrobe light self.wardrobe_light = pd.get(props.STG_ZFE, loc, roo, props.FUN_WLI) + self.wardrobe_light.disable_all_off() # Always on - Off by light sensor super().__init__(mqtt_client, pd, vd)