Better listening for lights returning from unavailable

This commit is contained in:
2019-05-23 10:58:53 +02:00
parent a38914e191
commit c7282f05da
2 changed files with 14 additions and 9 deletions

View File

@@ -4,12 +4,12 @@ class OutsideLights(Entities):
def initialize(self):
super().initialize()
for l in self.args['lights']:
self.register_entity(l, l)
e = self.register_entity(l, l)
e.listen(self.found, {'entity': e})
self.listen_event(self.update, 'TOD_TOD')
self.run_in(lambda *_: self.update(None, None, None), 2)
for l in self.args['lights']:
self.listen_event(self.found, l, old="unavailable")
def update(self, event, data, kwarg):
self.state = self.get_app('timeofday').dark
@@ -21,11 +21,14 @@ class OutsideLights(Entities):
self.e[l].state = self.state
self.e[l].push()
def found(self, entity, attribute, old, new, kwargs):
def found(self, old, new, kwarg):
entity = kwarg.get('entity', None)
if not entity: return;
if old == "unavailable":
self.log(f"{entity} showed up, setting to {self.state}")
self.e[entity].state = self.state
self.e[entity].push()
self.log(f"{entity.entity_id} showed up, setting to {self.state}")
entity.state = self.state
entity.push()
class DecorativeLights(OutsideLights):
def update(self, event, data, kwarg):