diff --git a/homeassistant/components/light/tellstick.py b/homeassistant/components/light/tellstick.py index 19ce1a06d4a..819dce499e9 100644 --- a/homeassistant/components/light/tellstick.py +++ b/homeassistant/components/light/tellstick.py @@ -6,10 +6,11 @@ Support for Tellstick lights. import logging # pylint: disable=no-name-in-module, import-error from homeassistant.components.light import Light, ATTR_BRIGHTNESS -from homeassistant.const import ATTR_FRIENDLY_NAME +from homeassistant.const import (EVENT_HOMEASSISTANT_STOP, + ATTR_FRIENDLY_NAME) import tellcore.constants as tellcore_constants from tellcore.library import DirectCallbackDispatcher -REQUIREMENTS = ['tellcore-py==1.0.4'] +REQUIREMENTS = ['tellcore-py==1.1.2'] # pylint: disable=unused-argument @@ -23,12 +24,7 @@ def setup_platform(hass, config, add_devices_callback, discovery_info=None): "Failed to import tellcore") return [] - # pylint: disable=no-member - if telldus.TelldusCore.callback_dispatcher is None: - dispatcher = DirectCallbackDispatcher() - core = telldus.TelldusCore(callback_dispatcher=dispatcher) - else: - core = telldus.TelldusCore() + core = telldus.TelldusCore(callback_dispatcher=DirectCallbackDispatcher()) switches_and_lights = core.devices() lights = [] @@ -41,9 +37,18 @@ def setup_platform(hass, config, add_devices_callback, discovery_info=None): """ Called from the TelldusCore library to update one device """ for light_device in lights: if light_device.tellstick_device.id == id_: + # Execute the update in another thread light_device.update_ha_state(True) + break - core.register_device_event(_device_event_callback) + callback_id = core.register_device_event(_device_event_callback) + + def unload_telldus_lib(event): + """ Un-register the callback bindings """ + if callback_id is not None: + core.unregister_callback(callback_id) + + hass.bus.listen_once(EVENT_HOMEASSISTANT_STOP, unload_telldus_lib) add_devices_callback(lights) diff --git a/homeassistant/components/sensor/tellstick.py b/homeassistant/components/sensor/tellstick.py index 7ee0fc19a99..6ec24d18ef1 100644 --- a/homeassistant/components/sensor/tellstick.py +++ b/homeassistant/components/sensor/tellstick.py @@ -34,7 +34,7 @@ import homeassistant.util as util DatatypeDescription = namedtuple("DatatypeDescription", ['name', 'unit']) -REQUIREMENTS = ['tellcore-py==1.0.4'] +REQUIREMENTS = ['tellcore-py==1.1.2'] # pylint: disable=unused-argument diff --git a/homeassistant/components/switch/tellstick.py b/homeassistant/components/switch/tellstick.py index 96b10a0a977..1a0f7097b52 100644 --- a/homeassistant/components/switch/tellstick.py +++ b/homeassistant/components/switch/tellstick.py @@ -11,13 +11,14 @@ signal_repetitions: 3 """ import logging -from homeassistant.const import ATTR_FRIENDLY_NAME +from homeassistant.const import (EVENT_HOMEASSISTANT_STOP, + ATTR_FRIENDLY_NAME) from homeassistant.helpers.entity import ToggleEntity import tellcore.constants as tellcore_constants from tellcore.library import DirectCallbackDispatcher SINGAL_REPETITIONS = 1 -REQUIREMENTS = ['tellcore-py==1.0.4'] +REQUIREMENTS = ['tellcore-py==1.1.2'] # pylint: disable=unused-argument @@ -30,12 +31,7 @@ def setup_platform(hass, config, add_devices_callback, discovery_info=None): "Failed to import tellcore") return - # pylint: disable=no-member - if telldus.TelldusCore.callback_dispatcher is None: - dispatcher = DirectCallbackDispatcher() - core = telldus.TelldusCore(callback_dispatcher=dispatcher) - else: - core = telldus.TelldusCore() + core = telldus.TelldusCore(callback_dispatcher=DirectCallbackDispatcher()) signal_repetitions = config.get('signal_repetitions', SINGAL_REPETITIONS) @@ -52,9 +48,17 @@ def setup_platform(hass, config, add_devices_callback, discovery_info=None): """ 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) + switch_device.update_ha_state() + break - core.register_device_event(_device_event_callback) + callback_id = core.register_device_event(_device_event_callback) + + def unload_telldus_lib(event): + """ Un-register the callback bindings """ + if callback_id is not None: + core.unregister_callback(callback_id) + + hass.bus.listen_once(EVENT_HOMEASSISTANT_STOP, unload_telldus_lib) add_devices_callback(switches) diff --git a/requirements_all.txt b/requirements_all.txt index 77f725ed4f0..04c944e4447 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -22,7 +22,7 @@ pychromecast==0.6.12 pyuserinput==0.1.9 # Tellstick bindings (*.tellstick) -tellcore-py==1.0.4 +tellcore-py==1.1.2 # Nmap bindings (device_tracker.nmap) python-nmap==0.4.3