From 963b34e6bdb803404e36fbadd1fd522dadd59c5c Mon Sep 17 00:00:00 2001 From: Giuseppe Lo Presti Date: Sat, 6 Jan 2018 21:17:04 +0100 Subject: [PATCH 1/5] Strip off the RTS/IO ID from the entity ID --- homeassistant/components/cover/tahoma.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/homeassistant/components/cover/tahoma.py b/homeassistant/components/cover/tahoma.py index 2f0362535cad5f..8b4c6b881de659 100644 --- a/homeassistant/components/cover/tahoma.py +++ b/homeassistant/components/cover/tahoma.py @@ -33,7 +33,13 @@ class TahomaCover(TahomaDevice, CoverDevice): def __init__(self, tahoma_device, controller): """Initialize the Tahoma device.""" super().__init__(tahoma_device, controller) - self.entity_id = ENTITY_ID_FORMAT.format(self.unique_id) + eid = ENTITY_ID_FORMAT.format(self.unique_id) + # strip off the RTS or the IO ID from the entity ID + if eid.rfind('_rts') > 0: + eid = eid[:eid.rfind('_rts')] + elif eid.rfind('_io') > 0: + eid = eid[:eid.rfind('_io')] + self.entity_id = eid def update(self): """Update method.""" From ca3871179912078d4f9be5bebcc27dd438e83c3e Mon Sep 17 00:00:00 2001 From: Giuseppe Lo Presti Date: Sat, 6 Jan 2018 21:17:59 +0100 Subject: [PATCH 2/5] Ignore exception thrown when the device does not provide an active state --- homeassistant/components/cover/tahoma.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/homeassistant/components/cover/tahoma.py b/homeassistant/components/cover/tahoma.py index 8b4c6b881de659..3d92b3f609e1db 100644 --- a/homeassistant/components/cover/tahoma.py +++ b/homeassistant/components/cover/tahoma.py @@ -52,12 +52,15 @@ def current_cover_position(self): 0 is closed, 100 is fully open. """ - position = 100 - self.tahoma_device.active_states['core:ClosureState'] - if position <= 5: - return 0 - if position >= 95: - return 100 - return position + try: + position = 100 - self.tahoma_device.active_states['core:ClosureState'] + if position <= 5: + return 0 + if position >= 95: + return 100 + return position + except KeyError: + return None def set_cover_position(self, position, **kwargs): """Move the cover to a specific position.""" From 7da2781848cd0135d601e6bc664444222461b9c3 Mon Sep 17 00:00:00 2001 From: Giuseppe Lo Presti Date: Sat, 6 Jan 2018 21:20:27 +0100 Subject: [PATCH 3/5] Send actions with a label for easier identification in the Tahoma log --- homeassistant/components/tahoma.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/homeassistant/components/tahoma.py b/homeassistant/components/tahoma.py index 129c6506ac1bfa..d373efb2589a00 100644 --- a/homeassistant/components/tahoma.py +++ b/homeassistant/components/tahoma.py @@ -117,4 +117,4 @@ def apply_action(self, cmd_name, *args): from tahoma_api import Action action = Action(self.tahoma_device.url) action.add_command(cmd_name, *args) - self.controller.apply_actions('', [action]) + self.controller.apply_actions('HomeAssistant', [action]) From 5a86b1986610cf02d45f09f9d11ee95e2c69d4db Mon Sep 17 00:00:00 2001 From: Giuseppe Lo Presti Date: Tue, 9 Jan 2018 12:08:58 +0100 Subject: [PATCH 4/5] Linting --- homeassistant/components/cover/tahoma.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/homeassistant/components/cover/tahoma.py b/homeassistant/components/cover/tahoma.py index 3d92b3f609e1db..6cbed0a56d90e0 100644 --- a/homeassistant/components/cover/tahoma.py +++ b/homeassistant/components/cover/tahoma.py @@ -53,7 +53,8 @@ def current_cover_position(self): 0 is closed, 100 is fully open. """ try: - position = 100 - self.tahoma_device.active_states['core:ClosureState'] + position = 100 - \ + self.tahoma_device.active_states['core:ClosureState'] if position <= 5: return 0 if position >= 95: From 1f0e30a14a0759c6452d7f93a6e12daeae1860af Mon Sep 17 00:00:00 2001 From: Giuseppe Lo Presti Date: Tue, 9 Jan 2018 17:23:34 +0100 Subject: [PATCH 5/5] Strip off the RTS/IO ID from the entity ID, take 2 As per suggestions, let HA do the standard initialization and assign an appropriate entity_id, instead of overriding it with the lengthy unique_id coming from the TaHoma devices. --- homeassistant/components/cover/tahoma.py | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/homeassistant/components/cover/tahoma.py b/homeassistant/components/cover/tahoma.py index 6cbed0a56d90e0..3eba3a8a1f3cbe 100644 --- a/homeassistant/components/cover/tahoma.py +++ b/homeassistant/components/cover/tahoma.py @@ -7,7 +7,7 @@ import logging from datetime import timedelta -from homeassistant.components.cover import CoverDevice, ENTITY_ID_FORMAT +from homeassistant.components.cover import CoverDevice from homeassistant.components.tahoma import ( DOMAIN as TAHOMA_DOMAIN, TahomaDevice) @@ -30,17 +30,6 @@ def setup_platform(hass, config, add_devices, discovery_info=None): class TahomaCover(TahomaDevice, CoverDevice): """Representation a Tahoma Cover.""" - def __init__(self, tahoma_device, controller): - """Initialize the Tahoma device.""" - super().__init__(tahoma_device, controller) - eid = ENTITY_ID_FORMAT.format(self.unique_id) - # strip off the RTS or the IO ID from the entity ID - if eid.rfind('_rts') > 0: - eid = eid[:eid.rfind('_rts')] - elif eid.rfind('_io') > 0: - eid = eid[:eid.rfind('_io')] - self.entity_id = eid - def update(self): """Update method.""" self.controller.get_states([self.tahoma_device])