This commit is contained in:
John Lancaster
2023-11-24 21:40:18 -06:00
parent 525b519433
commit 1ce2e73f77

View File

@@ -1,21 +1,24 @@
import json
from appdaemon.entity import Entity from appdaemon.entity import Entity
from appdaemon.plugins.hass.hassapi import Hass from appdaemon.plugins.hass.hassapi import Hass
from appdaemon.plugins.mqtt.mqttapi import Mqtt from appdaemon.plugins.mqtt.mqttapi import Mqtt
import json
class SleepSetter(Hass, Mqtt): class SleepSetter(Hass, Mqtt):
def initialize(self): def initialize(self):
assert self.entity_exists(entity_id=self.variable), f'{self.variable} does not exist' assert self.entity_exists(entity_id=self.variable), f'{self.variable} does not exist'
self.variable_entity.listen_state(callback=self.handle_state) 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): if isinstance(self.button, list):
for button in self.button: for button in self.button:
self.setup_button(button) self.setup_button(button)
else: else:
self.setup_button(button) self.setup_button(button)
self.log(f'{self.variable} can be set using {self.button}, currently {self.state}')
def setup_button(self, name: str): def setup_button(self, name: str):
topic = f'zigbee2mqtt/{name}' topic = f'zigbee2mqtt/{name}'
self.mqtt_subscribe(topic, namespace='mqtt') self.mqtt_subscribe(topic, namespace='mqtt')