From a0c1202ad6d61ef8f57eba2480ecbaac07d0dd25 Mon Sep 17 00:00:00 2001 From: Stefan Jonasson Date: Wed, 23 Sep 2015 08:26:40 +0200 Subject: [PATCH 01/19] Try to make the connection to the tellcore library more stable --- homeassistant/components/light/tellstick.py | 10 +++++++++- homeassistant/components/switch/tellstick.py | 12 ++++++++++-- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/homeassistant/components/light/tellstick.py b/homeassistant/components/light/tellstick.py index 19ce1a06d4a..de612ea7551 100644 --- a/homeassistant/components/light/tellstick.py +++ b/homeassistant/components/light/tellstick.py @@ -41,9 +41,17 @@ 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 + threading.Thread(target=light_device.update_ha_state, daemon=False, args=(True,)).start() light_device.update_ha_state(True) - core.register_device_event(_device_event_callback) + callback_id = core.register_device_event(_device_event_callback) + + def unload_telldus_lib(): + 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/switch/tellstick.py b/homeassistant/components/switch/tellstick.py index 96b10a0a977..c17347bd587 100644 --- a/homeassistant/components/switch/tellstick.py +++ b/homeassistant/components/switch/tellstick.py @@ -52,9 +52,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) + # Execute the update in another thread + threading.Thread(target=switch_device.update_ha_state, daemon=False).start() + break - core.register_device_event(_device_event_callback) + callback_id = core.register_device_event(_device_event_callback) + + def unload_telldus_lib(): + 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) From a9ea8972dd9ee3055f2ba680e0f6c19a02b03a9a Mon Sep 17 00:00:00 2001 From: Stefan Jonasson Date: Wed, 23 Sep 2015 08:29:57 +0200 Subject: [PATCH 02/19] Updated required tellcore version --- homeassistant/components/light/tellstick.py | 2 +- homeassistant/components/sensor/tellstick.py | 2 +- homeassistant/components/switch/tellstick.py | 2 +- requirements_all.txt | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/homeassistant/components/light/tellstick.py b/homeassistant/components/light/tellstick.py index de612ea7551..c24f5a3010f 100644 --- a/homeassistant/components/light/tellstick.py +++ b/homeassistant/components/light/tellstick.py @@ -9,7 +9,7 @@ from homeassistant.components.light import Light, ATTR_BRIGHTNESS from homeassistant.const import 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 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 c17347bd587..180019cc42e 100644 --- a/homeassistant/components/switch/tellstick.py +++ b/homeassistant/components/switch/tellstick.py @@ -17,7 +17,7 @@ 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 diff --git a/requirements_all.txt b/requirements_all.txt index 19cc04016a8..3b74c153959 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 From 7d0ff6884c1d833942e7de116b39ccb18cdd3494 Mon Sep 17 00:00:00 2001 From: Stefan Jonasson Date: Wed, 23 Sep 2015 09:32:11 +0200 Subject: [PATCH 03/19] Added the req consts --- homeassistant/components/light/tellstick.py | 4 +++- homeassistant/components/switch/tellstick.py | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/homeassistant/components/light/tellstick.py b/homeassistant/components/light/tellstick.py index c24f5a3010f..1bb60898dd3 100644 --- a/homeassistant/components/light/tellstick.py +++ b/homeassistant/components/light/tellstick.py @@ -6,7 +6,9 @@ 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_START, EVENT_HOMEASSISTANT_STOP, + ATTR_FRIENDLY_NAME) import tellcore.constants as tellcore_constants from tellcore.library import DirectCallbackDispatcher REQUIREMENTS = ['tellcore-py==1.1.2'] diff --git a/homeassistant/components/switch/tellstick.py b/homeassistant/components/switch/tellstick.py index 180019cc42e..ed8214f3e1c 100644 --- a/homeassistant/components/switch/tellstick.py +++ b/homeassistant/components/switch/tellstick.py @@ -11,7 +11,9 @@ signal_repetitions: 3 """ import logging -from homeassistant.const import ATTR_FRIENDLY_NAME +from homeassistant.const import ( + EVENT_HOMEASSISTANT_START, EVENT_HOMEASSISTANT_STOP, + ATTR_FRIENDLY_NAME) from homeassistant.helpers.entity import ToggleEntity import tellcore.constants as tellcore_constants from tellcore.library import DirectCallbackDispatcher From e90fd3d654655d0722e51fa39ccc77d9eed2375c Mon Sep 17 00:00:00 2001 From: Stefan Jonasson Date: Wed, 23 Sep 2015 09:43:16 +0200 Subject: [PATCH 04/19] Removed the check for callback_dispatcher --- homeassistant/components/light/tellstick.py | 11 +++++------ homeassistant/components/switch/tellstick.py | 8 ++++---- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/homeassistant/components/light/tellstick.py b/homeassistant/components/light/tellstick.py index 1bb60898dd3..626b7a9be33 100644 --- a/homeassistant/components/light/tellstick.py +++ b/homeassistant/components/light/tellstick.py @@ -13,7 +13,6 @@ import tellcore.constants as tellcore_constants from tellcore.library import DirectCallbackDispatcher REQUIREMENTS = ['tellcore-py==1.1.2'] - # pylint: disable=unused-argument def setup_platform(hass, config, add_devices_callback, discovery_info=None): """ Find and return Tellstick lights. """ @@ -26,11 +25,11 @@ def setup_platform(hass, config, add_devices_callback, discovery_info=None): return [] # pylint: disable=no-member - if telldus.TelldusCore.callback_dispatcher is None: - dispatcher = DirectCallbackDispatcher() - core = telldus.TelldusCore(callback_dispatcher=dispatcher) - else: - core = telldus.TelldusCore() + #if telldus.TelldusCore.callback_dispatcher is None: + #dispatcher = DirectCallbackDispatcher() + #core = telldus.TelldusCore(callback_dispatcher=dispatcher) + #else: + core = telldus.TelldusCore() switches_and_lights = core.devices() lights = [] diff --git a/homeassistant/components/switch/tellstick.py b/homeassistant/components/switch/tellstick.py index ed8214f3e1c..ea269468270 100644 --- a/homeassistant/components/switch/tellstick.py +++ b/homeassistant/components/switch/tellstick.py @@ -33,11 +33,11 @@ def setup_platform(hass, config, add_devices_callback, discovery_info=None): return # pylint: disable=no-member - if telldus.TelldusCore.callback_dispatcher is None: + #if telldus.TelldusCore.callback_dispatcher is None: dispatcher = DirectCallbackDispatcher() - core = telldus.TelldusCore(callback_dispatcher=dispatcher) - else: - core = telldus.TelldusCore() + core = telldus.TelldusCore(callback_dispatcher=dispatcher) + #else: + # core = telldus.TelldusCore() signal_repetitions = config.get('signal_repetitions', SINGAL_REPETITIONS) From 16c2827465f7151cd5e33802633846e63023f1a4 Mon Sep 17 00:00:00 2001 From: Stefan Jonasson Date: Wed, 23 Sep 2015 09:50:12 +0200 Subject: [PATCH 05/19] Removed the check for callback_dispatcher --- homeassistant/components/switch/tellstick.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/homeassistant/components/switch/tellstick.py b/homeassistant/components/switch/tellstick.py index ea269468270..7846f789250 100644 --- a/homeassistant/components/switch/tellstick.py +++ b/homeassistant/components/switch/tellstick.py @@ -34,7 +34,7 @@ def setup_platform(hass, config, add_devices_callback, discovery_info=None): # pylint: disable=no-member #if telldus.TelldusCore.callback_dispatcher is None: - dispatcher = DirectCallbackDispatcher() + dispatcher = DirectCallbackDispatcher() core = telldus.TelldusCore(callback_dispatcher=dispatcher) #else: # core = telldus.TelldusCore() From b4ca691822cd36a1138ca4e75fc3619e6fe59619 Mon Sep 17 00:00:00 2001 From: Stefan Jonasson Date: Wed, 23 Sep 2015 09:52:58 +0200 Subject: [PATCH 06/19] Removed the check for callback_dispatcher --- homeassistant/components/light/tellstick.py | 9 ++------- homeassistant/components/switch/tellstick.py | 9 ++------- 2 files changed, 4 insertions(+), 14 deletions(-) diff --git a/homeassistant/components/light/tellstick.py b/homeassistant/components/light/tellstick.py index 626b7a9be33..f8a3a105f8c 100644 --- a/homeassistant/components/light/tellstick.py +++ b/homeassistant/components/light/tellstick.py @@ -24,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 = [] @@ -48,7 +43,7 @@ def setup_platform(hass, config, add_devices_callback, discovery_info=None): callback_id = core.register_device_event(_device_event_callback) - def unload_telldus_lib(): + def unload_telldus_lib(event): if callback_id is not None: core.unregister_callback(callback_id) diff --git a/homeassistant/components/switch/tellstick.py b/homeassistant/components/switch/tellstick.py index 7846f789250..e300c9959bc 100644 --- a/homeassistant/components/switch/tellstick.py +++ b/homeassistant/components/switch/tellstick.py @@ -32,12 +32,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) @@ -60,7 +55,7 @@ def setup_platform(hass, config, add_devices_callback, discovery_info=None): callback_id = core.register_device_event(_device_event_callback) - def unload_telldus_lib(): + def unload_telldus_lib(event): if callback_id is not None: core.unregister_callback(callback_id) From 48df06d1c024a8dc350fa0382127b64d188f7c87 Mon Sep 17 00:00:00 2001 From: Stefan Jonasson Date: Wed, 23 Sep 2015 10:18:45 +0200 Subject: [PATCH 07/19] Added callback logging. --- homeassistant/components/light/tellstick.py | 2 ++ homeassistant/components/switch/tellstick.py | 2 ++ 2 files changed, 4 insertions(+) diff --git a/homeassistant/components/light/tellstick.py b/homeassistant/components/light/tellstick.py index f8a3a105f8c..fa8e5210309 100644 --- a/homeassistant/components/light/tellstick.py +++ b/homeassistant/components/light/tellstick.py @@ -35,6 +35,8 @@ def setup_platform(hass, config, add_devices_callback, discovery_info=None): def _device_event_callback(id_, method, data, cid): """ Called from the TelldusCore library to update one device """ + logging.getLogger(__name__).info( + "got TellCore callback {} {} {} {}".format(id_, method, data, cid)) for light_device in lights: if light_device.tellstick_device.id == id_: # Execute the update in another thread diff --git a/homeassistant/components/switch/tellstick.py b/homeassistant/components/switch/tellstick.py index e300c9959bc..a6d22fb4c99 100644 --- a/homeassistant/components/switch/tellstick.py +++ b/homeassistant/components/switch/tellstick.py @@ -47,6 +47,8 @@ def setup_platform(hass, config, add_devices_callback, discovery_info=None): def _device_event_callback(id_, method, data, cid): """ Called from the TelldusCore library to update one device """ + logging.getLogger(__name__).info( + "got TellCore callback {} {} {} {}".format(id_, method, data, cid)) for switch_device in switches: if switch_device.tellstick_device.id == id_: # Execute the update in another thread From b6bf398859ec36778a554f53fdd165833b5eace6 Mon Sep 17 00:00:00 2001 From: Stefan Jonasson Date: Wed, 23 Sep 2015 11:07:37 +0200 Subject: [PATCH 08/19] Added callback logging. --- homeassistant/components/light/tellstick.py | 2 ++ homeassistant/components/switch/tellstick.py | 2 ++ 2 files changed, 4 insertions(+) diff --git a/homeassistant/components/light/tellstick.py b/homeassistant/components/light/tellstick.py index fa8e5210309..15faf673451 100644 --- a/homeassistant/components/light/tellstick.py +++ b/homeassistant/components/light/tellstick.py @@ -40,6 +40,8 @@ def setup_platform(hass, config, add_devices_callback, discovery_info=None): for light_device in lights: if light_device.tellstick_device.id == id_: # Execute the update in another thread + logging.getLogger(__name__).info( + "Updating state to {}".switch_device.state()) threading.Thread(target=light_device.update_ha_state, daemon=False, args=(True,)).start() light_device.update_ha_state(True) diff --git a/homeassistant/components/switch/tellstick.py b/homeassistant/components/switch/tellstick.py index a6d22fb4c99..e82b73426cb 100644 --- a/homeassistant/components/switch/tellstick.py +++ b/homeassistant/components/switch/tellstick.py @@ -52,6 +52,8 @@ def setup_platform(hass, config, add_devices_callback, discovery_info=None): for switch_device in switches: if switch_device.tellstick_device.id == id_: # Execute the update in another thread + logging.getLogger(__name__).info( + "Updating state to {}".switch_device.state()) threading.Thread(target=switch_device.update_ha_state, daemon=False).start() break From 6afe99dcc77f2370f3f51b2b739551d36ca9851c Mon Sep 17 00:00:00 2001 From: Stefan Jonasson Date: Wed, 23 Sep 2015 11:14:47 +0200 Subject: [PATCH 09/19] Added more logging. --- homeassistant/components/switch/tellstick.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/homeassistant/components/switch/tellstick.py b/homeassistant/components/switch/tellstick.py index e82b73426cb..8afe91ca39b 100644 --- a/homeassistant/components/switch/tellstick.py +++ b/homeassistant/components/switch/tellstick.py @@ -50,6 +50,8 @@ def setup_platform(hass, config, add_devices_callback, discovery_info=None): logging.getLogger(__name__).info( "got TellCore callback {} {} {} {}".format(id_, method, data, cid)) for switch_device in switches: + logging.getLogger(__name__).info( + "checking switch {}".format(switch_device.tellstick_device.id)) if switch_device.tellstick_device.id == id_: # Execute the update in another thread logging.getLogger(__name__).info( From 62af1fcc57aad938e5f7ac370e8b9013b76eef97 Mon Sep 17 00:00:00 2001 From: Stefan Jonasson Date: Wed, 23 Sep 2015 11:19:27 +0200 Subject: [PATCH 10/19] Added more logging. --- homeassistant/components/switch/tellstick.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/homeassistant/components/switch/tellstick.py b/homeassistant/components/switch/tellstick.py index 8afe91ca39b..56b452017e8 100644 --- a/homeassistant/components/switch/tellstick.py +++ b/homeassistant/components/switch/tellstick.py @@ -55,8 +55,8 @@ def setup_platform(hass, config, add_devices_callback, discovery_info=None): if switch_device.tellstick_device.id == id_: # Execute the update in another thread logging.getLogger(__name__).info( - "Updating state to {}".switch_device.state()) - threading.Thread(target=switch_device.update_ha_state, daemon=False).start() + "Updating state to {}".fromat(switch_device.state())) + #threading.Thread(target=switch_device.update_ha_state, daemon=False).start() break callback_id = core.register_device_event(_device_event_callback) @@ -98,6 +98,8 @@ class TellstickSwitchDevice(ToggleEntity): @property def is_on(self): """ True if switch is on. """ + logging.getLogger(__name__).info( + "Returning state for {}".format(self.tellstick_device.id)) last_command = self.tellstick_device.last_sent_command( self.last_sent_command_mask) From 82a06279def2c7dec60648e1eb0930cb823a5cd4 Mon Sep 17 00:00:00 2001 From: Stefan Jonasson Date: Wed, 23 Sep 2015 11:22:32 +0200 Subject: [PATCH 11/19] Added more logging. --- homeassistant/components/switch/tellstick.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/homeassistant/components/switch/tellstick.py b/homeassistant/components/switch/tellstick.py index 56b452017e8..375f5eea61d 100644 --- a/homeassistant/components/switch/tellstick.py +++ b/homeassistant/components/switch/tellstick.py @@ -55,8 +55,8 @@ def setup_platform(hass, config, add_devices_callback, discovery_info=None): if switch_device.tellstick_device.id == id_: # Execute the update in another thread logging.getLogger(__name__).info( - "Updating state to {}".fromat(switch_device.state())) - #threading.Thread(target=switch_device.update_ha_state, daemon=False).start() + "Updating state to {}".fromat(method)) + threading.Thread(target=switch_device.update_ha_state, daemon=False).start() break callback_id = core.register_device_event(_device_event_callback) From de7a34b648badafa3cd27f99268ad8192f327611 Mon Sep 17 00:00:00 2001 From: Stefan Jonasson Date: Wed, 23 Sep 2015 11:25:08 +0200 Subject: [PATCH 12/19] Added more logging. --- homeassistant/components/switch/tellstick.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/homeassistant/components/switch/tellstick.py b/homeassistant/components/switch/tellstick.py index 375f5eea61d..77ace5b0272 100644 --- a/homeassistant/components/switch/tellstick.py +++ b/homeassistant/components/switch/tellstick.py @@ -56,7 +56,7 @@ def setup_platform(hass, config, add_devices_callback, discovery_info=None): # Execute the update in another thread logging.getLogger(__name__).info( "Updating state to {}".fromat(method)) - threading.Thread(target=switch_device.update_ha_state, daemon=False).start() + #threading.Thread(target=switch_device.update_ha_state, daemon=False).start() break callback_id = core.register_device_event(_device_event_callback) From 86270e1a374f7d462279a620c24aa4e4a3af2730 Mon Sep 17 00:00:00 2001 From: Stefan Jonasson Date: Wed, 23 Sep 2015 11:27:25 +0200 Subject: [PATCH 13/19] Added more logging. --- homeassistant/components/switch/tellstick.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/homeassistant/components/switch/tellstick.py b/homeassistant/components/switch/tellstick.py index 77ace5b0272..584cd306dd4 100644 --- a/homeassistant/components/switch/tellstick.py +++ b/homeassistant/components/switch/tellstick.py @@ -50,14 +50,11 @@ def setup_platform(hass, config, add_devices_callback, discovery_info=None): logging.getLogger(__name__).info( "got TellCore callback {} {} {} {}".format(id_, method, data, cid)) for switch_device in switches: - logging.getLogger(__name__).info( - "checking switch {}".format(switch_device.tellstick_device.id)) + logging.getLogger(__name__).info("checking switch {}: ".format(switch_device.tellstick_device.id)) if switch_device.tellstick_device.id == id_: # Execute the update in another thread - logging.getLogger(__name__).info( - "Updating state to {}".fromat(method)) + logging.getLogger(__name__).info("Updating state to: {}".fromat(method)) #threading.Thread(target=switch_device.update_ha_state, daemon=False).start() - break callback_id = core.register_device_event(_device_event_callback) From bcbb8edd59a8234e033d84f68f5ddb61aa0cf1f6 Mon Sep 17 00:00:00 2001 From: Stefan Jonasson Date: Wed, 23 Sep 2015 11:30:46 +0200 Subject: [PATCH 14/19] Added more logging. --- homeassistant/components/switch/tellstick.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/homeassistant/components/switch/tellstick.py b/homeassistant/components/switch/tellstick.py index 584cd306dd4..0666dc24454 100644 --- a/homeassistant/components/switch/tellstick.py +++ b/homeassistant/components/switch/tellstick.py @@ -53,8 +53,9 @@ def setup_platform(hass, config, add_devices_callback, discovery_info=None): logging.getLogger(__name__).info("checking switch {}: ".format(switch_device.tellstick_device.id)) if switch_device.tellstick_device.id == id_: # Execute the update in another thread - logging.getLogger(__name__).info("Updating state to: {}".fromat(method)) - #threading.Thread(target=switch_device.update_ha_state, daemon=False).start() + logging.getLogger(__name__).info("Updating state to: {}".format(method)) + threading.Thread(target=switch_device.update_ha_state, daemon=False).start() + break callback_id = core.register_device_event(_device_event_callback) From 10327795e9d527939220dd5ed95f4e7e13811994 Mon Sep 17 00:00:00 2001 From: Stefan Jonasson Date: Wed, 23 Sep 2015 11:34:20 +0200 Subject: [PATCH 15/19] Added more logging. --- homeassistant/components/switch/tellstick.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/homeassistant/components/switch/tellstick.py b/homeassistant/components/switch/tellstick.py index 0666dc24454..6c00c258bed 100644 --- a/homeassistant/components/switch/tellstick.py +++ b/homeassistant/components/switch/tellstick.py @@ -53,8 +53,8 @@ def setup_platform(hass, config, add_devices_callback, discovery_info=None): logging.getLogger(__name__).info("checking switch {}: ".format(switch_device.tellstick_device.id)) if switch_device.tellstick_device.id == id_: # Execute the update in another thread - logging.getLogger(__name__).info("Updating state to: {}".format(method)) - threading.Thread(target=switch_device.update_ha_state, daemon=False).start() + logging.getLogger(__name__).info("Updating state to: {}".format(switch_device.state)) + switch_device.update_ha_state() break callback_id = core.register_device_event(_device_event_callback) From 32449754896946372af69bd15b27b9607c1fa244 Mon Sep 17 00:00:00 2001 From: Stefan Jonasson Date: Wed, 23 Sep 2015 11:37:45 +0200 Subject: [PATCH 16/19] Removed logging. --- homeassistant/components/light/tellstick.py | 6 +----- homeassistant/components/switch/tellstick.py | 5 ----- 2 files changed, 1 insertion(+), 10 deletions(-) diff --git a/homeassistant/components/light/tellstick.py b/homeassistant/components/light/tellstick.py index 15faf673451..0791cf8120a 100644 --- a/homeassistant/components/light/tellstick.py +++ b/homeassistant/components/light/tellstick.py @@ -35,15 +35,11 @@ def setup_platform(hass, config, add_devices_callback, discovery_info=None): def _device_event_callback(id_, method, data, cid): """ Called from the TelldusCore library to update one device """ - logging.getLogger(__name__).info( - "got TellCore callback {} {} {} {}".format(id_, method, data, cid)) for light_device in lights: if light_device.tellstick_device.id == id_: # Execute the update in another thread - logging.getLogger(__name__).info( - "Updating state to {}".switch_device.state()) - threading.Thread(target=light_device.update_ha_state, daemon=False, args=(True,)).start() light_device.update_ha_state(True) + break callback_id = core.register_device_event(_device_event_callback) diff --git a/homeassistant/components/switch/tellstick.py b/homeassistant/components/switch/tellstick.py index 6c00c258bed..d01718b2c4d 100644 --- a/homeassistant/components/switch/tellstick.py +++ b/homeassistant/components/switch/tellstick.py @@ -47,13 +47,8 @@ def setup_platform(hass, config, add_devices_callback, discovery_info=None): def _device_event_callback(id_, method, data, cid): """ Called from the TelldusCore library to update one device """ - logging.getLogger(__name__).info( - "got TellCore callback {} {} {} {}".format(id_, method, data, cid)) for switch_device in switches: - logging.getLogger(__name__).info("checking switch {}: ".format(switch_device.tellstick_device.id)) if switch_device.tellstick_device.id == id_: - # Execute the update in another thread - logging.getLogger(__name__).info("Updating state to: {}".format(switch_device.state)) switch_device.update_ha_state() break From f48e65096a1216bed879701a6f234a0a69d97cff Mon Sep 17 00:00:00 2001 From: Stefan Jonasson Date: Wed, 23 Sep 2015 11:38:47 +0200 Subject: [PATCH 17/19] Removed logging. --- homeassistant/components/switch/tellstick.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/homeassistant/components/switch/tellstick.py b/homeassistant/components/switch/tellstick.py index d01718b2c4d..ab9f819501b 100644 --- a/homeassistant/components/switch/tellstick.py +++ b/homeassistant/components/switch/tellstick.py @@ -91,8 +91,6 @@ class TellstickSwitchDevice(ToggleEntity): @property def is_on(self): """ True if switch is on. """ - logging.getLogger(__name__).info( - "Returning state for {}".format(self.tellstick_device.id)) last_command = self.tellstick_device.last_sent_command( self.last_sent_command_mask) From 94db1ac142a44e4c8284d44e22d48840cd17c5ee Mon Sep 17 00:00:00 2001 From: Stefan Jonasson Date: Wed, 23 Sep 2015 11:46:55 +0200 Subject: [PATCH 18/19] Codestyle cleanup --- homeassistant/components/light/tellstick.py | 7 ++++--- homeassistant/components/switch/tellstick.py | 6 +++--- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/homeassistant/components/light/tellstick.py b/homeassistant/components/light/tellstick.py index 0791cf8120a..dd2f9a39a4e 100644 --- a/homeassistant/components/light/tellstick.py +++ b/homeassistant/components/light/tellstick.py @@ -6,13 +6,13 @@ 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 ( - EVENT_HOMEASSISTANT_START, EVENT_HOMEASSISTANT_STOP, - 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.1.2'] + # pylint: disable=unused-argument def setup_platform(hass, config, add_devices_callback, discovery_info=None): """ Find and return Tellstick lights. """ @@ -44,6 +44,7 @@ def setup_platform(hass, config, add_devices_callback, discovery_info=None): 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) diff --git a/homeassistant/components/switch/tellstick.py b/homeassistant/components/switch/tellstick.py index ab9f819501b..1a0f7097b52 100644 --- a/homeassistant/components/switch/tellstick.py +++ b/homeassistant/components/switch/tellstick.py @@ -11,9 +11,8 @@ signal_repetitions: 3 """ import logging -from homeassistant.const import ( - EVENT_HOMEASSISTANT_START, EVENT_HOMEASSISTANT_STOP, - 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 @@ -55,6 +54,7 @@ def setup_platform(hass, config, add_devices_callback, discovery_info=None): 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) From 8f95885e3a7b074b8b32f33620780008e16ebf4e Mon Sep 17 00:00:00 2001 From: Stefan Jonasson Date: Wed, 23 Sep 2015 11:47:53 +0200 Subject: [PATCH 19/19] Codestyle cleanup --- homeassistant/components/light/tellstick.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/homeassistant/components/light/tellstick.py b/homeassistant/components/light/tellstick.py index dd2f9a39a4e..819dce499e9 100644 --- a/homeassistant/components/light/tellstick.py +++ b/homeassistant/components/light/tellstick.py @@ -6,8 +6,8 @@ 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 ( EVENT_HOMEASSISTANT_STOP, - 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.1.2']