Merge pull request #433 from stefan-jonasson/fix_telldus_libary_cleanup

Telldus libary version update + added callback cleanup
This commit is contained in:
Stefan Jonasson 2015-09-23 12:15:31 +02:00
commit 34e5ecb8ab
4 changed files with 30 additions and 21 deletions

View file

@ -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)

View file

@ -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

View file

@ -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)

View file

@ -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