From 27e35d5f345a71d0261bf6290ed5f64d0e67f305 Mon Sep 17 00:00:00 2001 From: Erik Date: Sun, 27 Dec 2015 21:49:45 +0100 Subject: [PATCH] don't poll (turns out a request for state immediately a state turn on/off request will not return the newly updated state. import constants from tellive, not tellcore --- homeassistant/components/switch/tellduslive.py | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/homeassistant/components/switch/tellduslive.py b/homeassistant/components/switch/tellduslive.py index a6b3b53f0b2..d515dcb50a2 100644 --- a/homeassistant/components/switch/tellduslive.py +++ b/homeassistant/components/switch/tellduslive.py @@ -38,7 +38,7 @@ class TelldusLiveSwitch(ToggleEntity): @property def should_poll(self): """ Tells Home Assistant to poll this entity. """ - return True + return False @property def name(self): @@ -46,25 +46,28 @@ class TelldusLiveSwitch(ToggleEntity): return self._name def update(self): - from tellcore.constants import ( - TELLSTICK_TURNON, TELLSTICK_TURNOFF) - states = {TELLSTICK_TURNON: STATE_ON, - TELLSTICK_TURNOFF: STATE_OFF} + from tellive.live import const state = tellduslive.NETWORK.get_switch_state(self._id) - self._state = states[state] + if state == const.TELLSTICK_TURNON: + self._state = STATE_ON + elif state == const.TELLSTICK_TURNOFF: + self._state = STATE_OFF + else: + self._state = STATE_UNKNOWN @property def is_on(self): """ True if switch is on. """ - self.update() return self._state == STATE_ON def turn_on(self, **kwargs): """ Turns the switch on. """ if tellduslive.NETWORK.turn_switch_on(self._id): self._state = STATE_ON + self.update_ha_state() def turn_off(self, **kwargs): """ Turns the switch off. """ if tellduslive.NETWORK.turn_switch_off(self._id): self._state = STATE_OFF + self.update_ha_state()