Skip to content

Commit

Permalink
Fix cover state stuck when inverted and set position (#336)
Browse files Browse the repository at this point in the history
  • Loading branch information
xZetsubou authored Aug 20, 2024
1 parent 42a9e35 commit 5b48d9c
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions custom_components/localtuya/cover.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -187,15 +188,15 @@ 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(
converted_position, self._config[CONF_SET_POSITION_DP]
)
# 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."""
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 5b48d9c

Please sign in to comment.