Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix cover state stuck when inverted and set position #336

Merged
merged 1 commit into from
Aug 20, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading