diff --git a/.gitmodules b/.gitmodules index 9817ba3..90d5562 100644 --- a/.gitmodules +++ b/.gitmodules @@ -10,3 +10,6 @@ [submodule "devdi"] path = devdi url = https://git.mount-mockery.de/smarthome/smart_devdi.git +[submodule "task"] + path = task + url = https://git.mount-mockery.de/pylib/task.git diff --git a/devices/shelly.py b/devices/shelly.py index 77da754..78b1b08 100644 --- a/devices/shelly.py +++ b/devices/shelly.py @@ -32,6 +32,7 @@ from devices.base import base import json +import task class shelly_sw1(base): @@ -49,6 +50,8 @@ class shelly_sw1(base): super().__init__(mqtt_client, topic) self["state"] = "off" # + self.__auto_off__ = None + # self.mqtt_client.add_callback(self.topic + '/relay/0/command', self.__rx_set__) def __rx_set__(self, client, userdata, message): @@ -57,10 +60,24 @@ class shelly_sw1(base): self.logger.info("Received set data for %s: %s", key, repr(data)) self.__set__(key, data) self.send_device_status(key) - if key == "relay/0" and data.lower() == "on": - self.power_on() + if key == "relay/0": + if data.lower() == "on": + self.power_on() + if self.__auto_off__ is not None: + self.__auto_off__.run() + else: + if self.__auto_off__ is not None: + self.__auto_off__.stop() def send_device_status(self, key): data = self[key] self.logger.info("Sending status for %s: %s", key, repr(data)) self.mqtt_client.send(self.topic + '/' + key, data) + + def auto_off(self, sec): + self.__auto_off__ = task.delayed(sec, self.__auto_off_func__) + + def __auto_off_func__(self): + if self.get(self.PROPERTIES[0]).lower() != 'off': + self.__set__(self.PROPERTIES[0], "off") + self.send_device_status(self.PROPERTIES[0]) diff --git a/home_emulation.py b/home_emulation.py index a010c82..96d7fba 100644 --- a/home_emulation.py +++ b/home_emulation.py @@ -78,6 +78,10 @@ if __name__ == "__main__": # FFE # ####### loc = props.LOC_FFE + # KITCHEN + roo = props.ROO_KIT + sml = ddi.get(props.STG_SHE, loc, roo, props.FUN_CIR) + sml.auto_off(600) # LIVINGROOM roo = props.ROO_LIV sml = ddi.get(props.STG_SHE, loc, roo, props.FUN_MAL) diff --git a/task b/task new file mode 160000 index 0000000..af35e83 --- /dev/null +++ b/task @@ -0,0 +1 @@ +Subproject commit af35e83d1f07fd4cb9070bdb77cf1f3bdda3a463