Merge pull request #414 from stefan-jonasson/telldus_callback_fix

Telldus callback fix
This commit is contained in:
Paulus Schoutsen 2015-09-20 10:25:34 -07:00
commit 81085c7467
2 changed files with 23 additions and 20 deletions

View File

@ -34,7 +34,17 @@ def setup_platform(hass, config, add_devices_callback, discovery_info=None):
for switch in switches_and_lights:
if switch.methods(tellcore_constants.TELLSTICK_DIM):
lights.append(TellstickLight(switch, core))
lights.append(TellstickLight(switch))
# pylint: disable=unused-argument
def _device_event_callback(id_, method, data, cid):
""" Called from the TelldusCore library to update one device """
for light_device in lights:
if light_device.tellstick_device.id == id_:
light_device.update_ha_state(True)
core.register_device_event(_device_event_callback)
add_devices_callback(lights)
@ -46,18 +56,10 @@ class TellstickLight(Light):
tellcore_constants.TELLSTICK_UP |
tellcore_constants.TELLSTICK_DOWN)
def __init__(self, tellstick_device, core):
def __init__(self, tellstick_device):
self.tellstick_device = tellstick_device
self.state_attr = {ATTR_FRIENDLY_NAME: tellstick_device.name}
self._brightness = 0
self.callback_id = core.register_device_event(self._device_event)
# pylint: disable=unused-argument
def _device_event(self, id_, method, data, cid):
""" Called when a state has changed . """
if self.tellstick_device.id == id_:
self.update_ha_state()
@property
def name(self):

View File

@ -46,7 +46,16 @@ def setup_platform(hass, config, add_devices_callback, discovery_info=None):
for switch in switches_and_lights:
if not switch.methods(tellcore_constants.TELLSTICK_DIM):
switches.append(
TellstickSwitchDevice(switch, signal_repetitions, core))
TellstickSwitchDevice(switch, signal_repetitions))
# pylint: disable=unused-argument
def _device_event_callback(id_, method, data, cid):
""" Called from the TelldusCore library to update one device """
for switch_device in switches:
if switch_device.tellstick_device.id == id_:
switch_device.update_ha_state(True)
core.register_device_event(_device_event_callback)
add_devices_callback(switches)
@ -56,18 +65,10 @@ class TellstickSwitchDevice(ToggleEntity):
last_sent_command_mask = (tellcore_constants.TELLSTICK_TURNON |
tellcore_constants.TELLSTICK_TURNOFF)
def __init__(self, tellstick_device, signal_repetitions, core):
def __init__(self, tellstick_device, signal_repetitions):
self.tellstick_device = tellstick_device
self.state_attr = {ATTR_FRIENDLY_NAME: tellstick_device.name}
self.signal_repetitions = signal_repetitions
self.callback_id = core.register_device_event(self._device_event)
# pylint: disable=unused-argument
def _device_event(self, id_, method, data, cid):
""" Called when a state has changed . """
if self.tellstick_device.id == id_:
self.update_ha_state()
@property
def should_poll(self):