From e578fdabe69bf44317b9c44b309d064a5a3fff2e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20Lov=C3=A9n?= Date: Fri, 28 Dec 2018 23:19:23 +0100 Subject: [PATCH] appd - Make TOD controller fire events on change --- appdaemon/apps/timeofday.py | 17 +++++++++++++++-- appdaemon/apps/timeofday.yaml | 2 ++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/appdaemon/apps/timeofday.py b/appdaemon/apps/timeofday.py index dea3037..900a454 100644 --- a/appdaemon/apps/timeofday.py +++ b/appdaemon/apps/timeofday.py @@ -33,11 +33,17 @@ class TimeOfDay(Timers, Entities): self.update(None, None, {'trigger': 'init'}) - def update(self, old, new, kwarg): + def update(self, old=None, new=None, kwarg=None): + if kwarg is None: + kwarg = old trigger = kwarg.get('trigger', None) - if kwarg.get('entity', None) in ['tod', 'dark']: + if kwarg.get('entity', None) == 'tod': + self.fire_event('TOD_TOD', old = old, new = new) + return + if kwarg.get('entity', None) == 'dark': + self.fire_event('TOD_DARK', old = old, new = new) return self.log(f"TOD - updated by {trigger}") @@ -101,3 +107,10 @@ class TimeOfDay(Timers, Entities): self.e['dark'].push() self.e['tod'].state = tod self.e['tod'].push() + + @property + def tod(self): + return self.e['tod'].state + @property + def dark(self): + return self.e['dark'].state diff --git a/appdaemon/apps/timeofday.yaml b/appdaemon/apps/timeofday.yaml index 5a4dcec..a232562 100644 --- a/appdaemon/apps/timeofday.yaml +++ b/appdaemon/apps/timeofday.yaml @@ -3,6 +3,8 @@ timeofday: class: TimeOfDay global_dependencies: - base + - entities + - timers morning: name: input_datetime.tod_morning