From 60b4ec688cf31c4175df41e452090a5cb968867e Mon Sep 17 00:00:00 2001 From: xZetsubou Date: Tue, 20 Aug 2024 16:30:05 +0300 Subject: [PATCH] Fix cover state stuck when inverted and set position --- custom_components/localtuya/cover.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/custom_components/localtuya/cover.py b/custom_components/localtuya/cover.py index 56477901e..2654aea49 100644 --- a/custom_components/localtuya/cover.py +++ b/custom_components/localtuya/cover.py @@ -103,6 +103,7 @@ def __init__(self, device, config_entry, switchid, **kwargs): self._current_state_action = STATE_STOPPED # Default. self._set_new_position = int | None self._stop_switch = self._config.get(CONF_STOP_SWITCH_DP, None) + self._position_inverted = self._config.get(CONF_POSITION_INVERTED) @property def supported_features(self): @@ -187,7 +188,7 @@ async def async_set_cover_position(self, **kwargs): elif self._config[CONF_POSITIONING_MODE] == MODE_SET_POSITION: converted_position = int(kwargs[ATTR_POSITION]) - if self._config.get(CONF_POSITION_INVERTED): + if self._position_inverted: converted_position = 100 - converted_position if 0 <= converted_position <= 100 and self.has_config(CONF_SET_POSITION_DP): await self._device.set_dp( @@ -195,7 +196,7 @@ async def async_set_cover_position(self, **kwargs): ) # Give it a moment, to make sure hass updated current pos. await asyncio.sleep(0.1) - self.update_state(STATE_SET_CMD, converted_position) + self.update_state(STATE_SET_CMD, int(kwargs[ATTR_POSITION])) async def async_stop_after_timeout(self, delay_sec): """Stop the cover if timeout (max movement span) occurred.""" @@ -258,7 +259,7 @@ def status_updated(self): if self.has_config(CONF_CURRENT_POSITION_DP): curr_pos = self.dp_value(CONF_CURRENT_POSITION_DP) - if self._config.get(CONF_POSITION_INVERTED): + if self._position_inverted: self._current_cover_position = 100 - curr_pos else: self._current_cover_position = curr_pos