diff --git a/apps/sleep.py b/apps/sleep.py index dc7c02e..2637f94 100755 --- a/apps/sleep.py +++ b/apps/sleep.py @@ -1,21 +1,24 @@ +import json + from appdaemon.entity import Entity from appdaemon.plugins.hass.hassapi import Hass from appdaemon.plugins.mqtt.mqttapi import Mqtt -import json + class SleepSetter(Hass, Mqtt): def initialize(self): assert self.entity_exists(entity_id=self.variable), f'{self.variable} does not exist' self.variable_entity.listen_state(callback=self.handle_state) + self.setup_buttons() + self.log(f'{self.variable} can be set using {self.button}, currently {self.state}') + def setup_buttons(self): if isinstance(self.button, list): for button in self.button: self.setup_button(button) else: self.setup_button(button) - self.log(f'{self.variable} can be set using {self.button}, currently {self.state}') - def setup_button(self, name: str): topic = f'zigbee2mqtt/{name}' self.mqtt_subscribe(topic, namespace='mqtt')