appd - Time of Day controller working

This commit is contained in:
2018-12-28 22:37:47 +01:00
parent a070dc679f
commit a3374b3ac2
6 changed files with 135 additions and 46 deletions

View File

@@ -71,13 +71,11 @@ class Entity:
self._attributes = d['attributes']
def push(self):
self._hass.set_state(self._entity, state=self._state, attributes=self._attributes)
if self._state != self._laststate:
old = self._laststate
new = self._state
self._laststate = new
self.set_state(old, new)
self._callback(old, new)
self.set_state(self._laststate, self._state)
self._laststate = self._state
self._callback(self._laststate, self._state)
self._hass.set_state(self._entity, state=self._state, attributes=self._attributes)
def set_state(self, old, new):
pass
@@ -114,6 +112,12 @@ class LightEntity(Entity):
class SwitchEntity(Entity):
def set_state(self, old, new):
if new == True:
self._state = "on"
if new == False:
self._state = "off"
def service_callback(self, data):
if data['service'] == 'turn_on':
self._state = "on"

View File

@@ -25,16 +25,16 @@ class Timers(base.Base):
def cancel_timer(self, name, *args, **kwargs):
if type(name) is str:
if name in self._timers:
return super().cancel_timer(self._timers[name])
return super(Timers, self).cancel_timer(self._timers[name])
else:
return super().cancel_timer(*args, **kwargs)
return super(Timers, self).cancel_timer(*args, **kwargs)
def _override(self, f):
setattr(self, f'_{f}', getattr(self, f))
def fn(name, *args, **kwargs):
if type(name) is str:
if name in self._timers:
super().cancel_timer(self._timers[name])
super(Timers, self).cancel_timer(self._timers[name])
self._timers[name] = getattr(self, f'_{f}')(*args, **kwargs)
return self._timers[name]
else: