From 934ef9008607dca98b493fd2624ca1712fd3a0ad Mon Sep 17 00:00:00 2001 From: Thibaut Etienne Date: Wed, 8 Jul 2020 09:17:54 +0200 Subject: [PATCH] Remove all self._* variables --- custom_components/tahoma/cover.py | 84 +++++++++++-------------------- 1 file changed, 28 insertions(+), 56 deletions(-) diff --git a/custom_components/tahoma/cover.py b/custom_components/tahoma/cover.py index 5f7399189..9c3689c31 100644 --- a/custom_components/tahoma/cover.py +++ b/custom_components/tahoma/cover.py @@ -79,81 +79,48 @@ async def async_setup_entry(hass, entry, async_add_entities): class TahomaCover(TahomaDevice, CoverEntity): """Representation a TaHoma Cover.""" - def __init__(self, tahoma_device, controller): - """Initialize the device.""" - super().__init__(tahoma_device, controller) - - self._tilt_position = None - self._position = None - - self._lock_timer = 0 # Can be 0 and bigger - - # Can be 'LSC', 'SAAC', 'SFC', 'UPS', 'externalGateway', 'localUser', - # 'myself', 'rain', 'security', 'temperature', 'timer', 'user', 'wind' - self._lock_originator = None - def update(self): """Update method.""" if self.should_wait(): self.schedule_update_ha_state(True) return - self.controller.get_states([self.tahoma_device]) - self.update_position() - self.update_tilt_position() - self.update_lock() - - def update_position(self): - """Update position.""" - # Home Assistant: 0 is closed, 100 is fully open. - # core:ClosureState: 100 is closed, 0 is fully open. + @property + def current_cover_position(self): + """Return current position of cover.""" states = self.tahoma_device.active_states + position = None + # Set position for vertical covers if CORE_CLOSURE_STATE in states: - self._position = 100 - states.get(CORE_CLOSURE_STATE) + position = 100 - states.get(CORE_CLOSURE_STATE) # Set position for horizontal covers if CORE_DEPLOYMENT_STATE in states: - self._position = 100 - states.get(CORE_DEPLOYMENT_STATE) + position = 100 - states.get(CORE_DEPLOYMENT_STATE) # Set position for gates if CORE_PEDESTRIAN_POSITION_STATE in states: - self._position = 100 - states.get(CORE_PEDESTRIAN_POSITION_STATE) + position = 100 - states.get(CORE_PEDESTRIAN_POSITION_STATE) if CORE_TARGET_CLOSURE_STATE in states: - self._position = 100 - states.get(CORE_TARGET_CLOSURE_STATE) + position = 100 - states.get(CORE_TARGET_CLOSURE_STATE) - if self._position is not None: + if position is not None: # HorizontalAwning devices need a reversed position that can not be obtained via the API if "Horizontal" in self.tahoma_device.widget: - self._position = 100 - self._position + position = 100 - position # TODO Check if this offset is really necessary - if self._position <= 5: - self._position = 0 - if self._position >= 95: - self._position = 100 + if position <= 5: + position = 0 + if position >= 95: + position = 100 - def update_tilt_position(self): - """Update tilt position.""" - states = self.tahoma_device.active_states - # Set tilt position for slats - if CORE_SLATS_ORIENTATION_STATE in states: - self._tilt_position = 100 - states.get(CORE_SLATS_ORIENTATION_STATE) - - def update_lock(self): - """Update lock.""" - states = self.tahoma_device.active_states - self._lock_timer = states.get(CORE_PRIORITY_LOCK_TIMER_STATE, 0) - self._lock_originator = states.get(IO_PRIORITY_LOCK_ORIGINATOR_STATE) - - @property - def current_cover_position(self): - """Return current position of cover.""" - return self._position + return position @property def current_cover_tilt_position(self): @@ -161,7 +128,11 @@ def current_cover_tilt_position(self): None is unknown, 0 is closed, 100 is fully open. """ - return self._tilt_position + states = self.tahoma_device.active_states + position = None + if CORE_SLATS_ORIENTATION_STATE in states: + position = 100 - states.get(CORE_SLATS_ORIENTATION_STATE) + return position def set_cover_position(self, **kwargs): """Move the cover to a specific position.""" @@ -206,11 +177,11 @@ def is_closed(self): if "core:OpenClosedUnknownState" in states: return states.get("core:OpenClosedUnknownState") == "closed" - if self._position is not None: - return self._position == 0 + if self.current_cover_position is not None: + return self.current_cover_position == 0 - if self._tilt_position is not None: - return self._tilt_position == 0 + if self.current_cover_tilt_position is not None: + return self.current_cover_tilt_position == 0 return None @@ -244,8 +215,9 @@ def device_state_attributes(self): @property def icon(self): """Return the icon to use in the frontend, if any.""" - if self._lock_timer > 0: - if self._lock_originator == "wind": + states = self.tahoma_device.active_states + if states.get(CORE_PRIORITY_LOCK_TIMER_STATE, 0) > 0: + if states.get(IO_PRIORITY_LOCK_ORIGINATOR_STATE) == "wind": return "mdi:weather-windy" else: return "mdi:lock-alert"