Skip to content

Commit 801bd9e

Browse files
authored
fix(cover): hotfix for 2025.1 update and handle boolean actions state (#490)
* Auto configure current position for garage * hotfix for latest update, commands not working. * isupper check fix. * handle is_closed for cover. * handle states better
1 parent 3a63542 commit 801bd9e

File tree

2 files changed

+22
-20
lines changed

2 files changed

+22
-20
lines changed

custom_components/localtuya/core/ha_entities/covers.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -90,22 +90,22 @@ def localtuya_cover(cmd_set, position_mode=None, inverted=False, timed=25):
9090
LocalTuyaEntity(
9191
id=DPCode.SWITCH_1,
9292
name="Door",
93-
custom_configs=localtuya_cover("open_close_stop", "None", True),
94-
current_state=DPCode.DOORCONTACT_STATE,
93+
custom_configs=localtuya_cover("open_close_stop", "none", True),
94+
current_position_dp=DPCode.DOORCONTACT_STATE,
9595
device_class=CoverDeviceClass.GARAGE,
9696
),
9797
LocalTuyaEntity(
9898
id=DPCode.SWITCH_2,
9999
name="Door 2",
100-
custom_configs=localtuya_cover("open_close_stop", "None", True),
101-
current_state=DPCode.DOORCONTACT_STATE_2,
100+
custom_configs=localtuya_cover("open_close_stop", "none", True),
101+
current_position_dp=DPCode.DOORCONTACT_STATE_2,
102102
device_class=CoverDeviceClass.GARAGE,
103103
),
104104
LocalTuyaEntity(
105105
id=DPCode.SWITCH_3,
106106
name="Door 3",
107-
custom_configs=localtuya_cover("open_close_stop", "None", True),
108-
current_state=DPCode.DOORCONTACT_STATE_3,
107+
custom_configs=localtuya_cover("open_close_stop", "none", True),
108+
current_position_dp=DPCode.DOORCONTACT_STATE_3,
109109
device_class=CoverDeviceClass.GARAGE,
110110
),
111111
),

custom_components/localtuya/cover.py

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -120,10 +120,10 @@ def supported_features(self):
120120
def _current_state(self) -> str:
121121
"""Return the current state of the cover."""
122122
state = self._current_state_action
123-
curr_pos = self.current_cover_position
123+
curr_pos = self._current_cover_position
124124
# Reset STATE when cover is fully closed or fully opened.
125-
if (state == STATE_CLOSING and curr_pos == 0) or (
126-
state == STATE_OPENING and curr_pos == 100
125+
if state == STATE_STOPPED or (
126+
state in (STATE_CLOSING, STATE_OPENING) and curr_pos in (0, 100)
127127
):
128128
self._current_state_action = STATE_STOPPED
129129
# in case cover moving by set position cmd.
@@ -147,20 +147,20 @@ def current_cover_position(self):
147147
@property
148148
def is_opening(self):
149149
"""Return if cover is opening."""
150-
state = self._current_state
151-
return state == STATE_SET_OPENING or state == STATE_OPENING
150+
return self._current_state in (STATE_OPENING, STATE_SET_OPENING)
152151

153152
@property
154153
def is_closing(self):
155154
"""Return if cover is closing."""
156-
state = self._current_state
157-
return state == STATE_SET_CLOSING or state == STATE_CLOSING
155+
return self._current_state in (STATE_CLOSING, STATE_SET_CLOSING)
158156

159157
@property
160158
def is_closed(self):
161159
"""Return if the cover is closed or not."""
162160
if isinstance(self._open_cmd, bool):
163-
return self._state == self._close_cmd
161+
return self._current_cover_position == 0 and (
162+
self._current_state == STATE_STOPPED
163+
)
164164
if self._config[CONF_POSITIONING_MODE] == MODE_NONE:
165165
return None
166166
return self.current_cover_position == 0 and self._current_state == STATE_STOPPED
@@ -268,7 +268,7 @@ def connection_made(self):
268268
super().connection_made()
269269

270270
match self.dp_value(self._dp_id):
271-
case str() as i if i.upper():
271+
case str() as i if i.isupper():
272272
self._open_cmd = self._open_cmd.upper()
273273
self._close_cmd = self._close_cmd.upper()
274274
self._stop_cmd = self._stop_cmd.upper()
@@ -283,10 +283,14 @@ def status_updated(self):
283283

284284
if self.has_config(CONF_CURRENT_POSITION_DP):
285285
curr_pos = self.dp_value(CONF_CURRENT_POSITION_DP)
286+
if isinstance(curr_pos, bool):
287+
curr_pos = 0 if curr_pos else 100
288+
elif isinstance(curr_pos, str):
289+
curr_pos = 0 if curr_pos in ("fully_close") else 100
286290
if self._position_inverted:
287-
self._current_cover_position = 100 - curr_pos
288-
else:
289-
self._current_cover_position = curr_pos
291+
curr_pos = 100 - curr_pos
292+
293+
self._current_cover_position = curr_pos
290294
if (
291295
self._config[CONF_POSITIONING_MODE] == MODE_TIME_BASED
292296
and self._state != self._previous_state
@@ -320,8 +324,6 @@ def status_updated(self):
320324
def update_state(self, action, position=None):
321325
"""Update cover current states."""
322326
state = self._current_state_action
323-
if isinstance(self._open_cmd, bool):
324-
return
325327
# using Commands.
326328
if position is None:
327329
self._current_state_action = action

0 commit comments

Comments
 (0)