diff --git a/homeassistant/components/light/tellstick.py b/homeassistant/components/light/tellstick.py index 91c48f68e70..3f7002b5b03 100644 --- a/homeassistant/components/light/tellstick.py +++ b/homeassistant/components/light/tellstick.py @@ -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): diff --git a/homeassistant/components/switch/tellstick.py b/homeassistant/components/switch/tellstick.py index 3b510738b06..8f0150543de 100644 --- a/homeassistant/components/switch/tellstick.py +++ b/homeassistant/components/switch/tellstick.py @@ -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):