From 9d67d229fabae488af956f152c65fc1f48b7c31f Mon Sep 17 00:00:00 2001 From: Giuseppe Date: Sat, 13 Jan 2018 21:24:10 +0100 Subject: [PATCH] Fixes and enhancements for the Tahoma platform (#11547) * Strip off the RTS/IO ID from the entity ID * Ignore exception thrown when the device does not provide an active state * Send actions with a label for easier identification in the Tahoma log * Linting * 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 | 23 +++++++++++------------ homeassistant/components/tahoma.py | 2 +- 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/homeassistant/components/cover/tahoma.py b/homeassistant/components/cover/tahoma.py index 9968e3d6503..a4159721de7 100644 --- a/homeassistant/components/cover/tahoma.py +++ b/homeassistant/components/cover/tahoma.py @@ -7,7 +7,7 @@ https://home-assistant.io/components/cover.tahoma/ 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,11 +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) - self.entity_id = ENTITY_ID_FORMAT.format(self.unique_id) - def update(self): """Update method.""" self.controller.get_states([self.tahoma_device]) @@ -46,12 +41,16 @@ class TahomaCover(TahomaDevice, CoverDevice): 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.""" diff --git a/homeassistant/components/tahoma.py b/homeassistant/components/tahoma.py index aebe1e0d88e..040f499c115 100644 --- a/homeassistant/components/tahoma.py +++ b/homeassistant/components/tahoma.py @@ -124,4 +124,4 @@ class TahomaDevice(Entity): 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])