From e4493c3475643d4e57e815d4610fe6d1db110e2e Mon Sep 17 00:00:00 2001 From: Luca Bortolotti Date: Tue, 11 Apr 2023 19:48:01 +0200 Subject: [PATCH 1/3] Inverted cover position to match home assistant's definition --- custom_components/comelit/cover.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/custom_components/comelit/cover.py b/custom_components/comelit/cover.py index cea102f..0336d31 100644 --- a/custom_components/comelit/cover.py +++ b/custom_components/comelit/cover.py @@ -40,11 +40,11 @@ def is_closing(self): @property def current_cover_position(self): # -> int | None: - return self._position + return 100 - self._position def set_cover_position(self, position, **kwargs): _LOGGER.debug(f"Trying to SET POSITION {position} cover {self.name}! _state={self._state}") - self._hub.cover_position(self._id, position) + self._hub.cover_position(self._id, 100 - position) def open_cover(self, stopping=False, **kwargs): _LOGGER.debug(f"Trying to OPEN cover {self.name}! _state={self._state}") From 0061bab5b64f7085249a010b94e2d351314bbb47 Mon Sep 17 00:00:00 2001 From: Luca Bortolotti Date: Sat, 4 May 2024 08:35:01 +0200 Subject: [PATCH 2/3] Update all async_schedule_update_ha_state calls to their non-async counterpart. --- custom_components/comelit/climate.py | 4 ++-- custom_components/comelit/comelit_device.py | 2 +- custom_components/comelit/cover.py | 6 +++--- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/custom_components/comelit/climate.py b/custom_components/comelit/climate.py index 6fe186e..6ef818d 100644 --- a/custom_components/comelit/climate.py +++ b/custom_components/comelit/climate.py @@ -74,11 +74,11 @@ def set_temperature(self, **kwargs): if temperature is not None: self._hub.climate_set_temperature(self._id, temperature) self._state['target_temperature'] = temperature - self.async_schedule_update_ha_state() + self.schedule_update_ha_state() def set_hvac_mode(self, hvac_mode): self._hub.climate_set_state(self._id, hvac_mode == HVACMode.HEAT) - self.async_schedule_update_ha_state() + self.schedule_update_ha_state() def update(self): pass diff --git a/custom_components/comelit/comelit_device.py b/custom_components/comelit/comelit_device.py index b1c62f0..0e7155a 100644 --- a/custom_components/comelit/comelit_device.py +++ b/custom_components/comelit/comelit_device.py @@ -38,7 +38,7 @@ def update_state(self, state): old = self._state self._state = state if old != state: - self.async_schedule_update_ha_state() + self.schedule_update_ha_state() @property def state(self): diff --git a/custom_components/comelit/cover.py b/custom_components/comelit/cover.py index d546ce1..96f19cd 100644 --- a/custom_components/comelit/cover.py +++ b/custom_components/comelit/cover.py @@ -56,14 +56,14 @@ def open_cover(self, stopping=False, **kwargs): self._hub.cover_up(self._id) if not stopping: self._state == STATE_OPENING - self.async_schedule_update_ha_state() + self.schedule_update_ha_state() def close_cover(self, stopping=False, **kwargs): _LOGGER.debug(f"Trying to CLOSE cover {self.name}! _state={self._state}") self._hub.cover_down(self._id) if not stopping: self._state = STATE_CLOSING - self.async_schedule_update_ha_state() + self.schedule_update_ha_state() def update_state(self, state, position): super().update_state(state) @@ -72,7 +72,7 @@ def update_state(self, state, position): old = self._position self._position = position if old != position: - self.async_schedule_update_ha_state() + self.schedule_update_ha_state() def stop_cover(self, **kwargs): _LOGGER.debug(f"Trying to STOP cover {self.name}! is_opening={self.is_opening}, is_closing={self.is_closing}") From 3dccde486dd882223f52e732e82e5854b4926d37 Mon Sep 17 00:00:00 2001 From: Luca Bortolotti Date: Mon, 6 May 2024 08:54:31 +0200 Subject: [PATCH 3/3] Fixed position=None handling (was causing closed covers to be misreported as open) --- custom_components/comelit/cover.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/custom_components/comelit/cover.py b/custom_components/comelit/cover.py index 96f19cd..528631c 100644 --- a/custom_components/comelit/cover.py +++ b/custom_components/comelit/cover.py @@ -42,10 +42,10 @@ def is_closing(self): @property def current_cover_position(self): # -> int | None: - if self._position: # if not None: - return 100 - self._position + if self._position is None: + return None else: - return self._position + return 100 - self._position def set_cover_position(self, position, **kwargs): _LOGGER.debug(f"Trying to SET POSITION {position} cover {self.name}! _state={self._state}")