Skip to content

Commit b5457a5

Browse files
authored
Fix demo cover set position action (home-assistant#154641)
1 parent e4b5e35 commit b5457a5

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

homeassistant/components/demo/cover.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ async def async_close_cover(self, **kwargs: Any) -> None:
139139
self.async_write_ha_state()
140140
return
141141

142+
self._is_opening = False
142143
self._is_closing = True
143144
self._listen_cover()
144145
self._requested_closing = True
@@ -162,6 +163,7 @@ async def async_open_cover(self, **kwargs: Any) -> None:
162163
return
163164

164165
self._is_opening = True
166+
self._is_closing = False
165167
self._listen_cover()
166168
self._requested_closing = False
167169
self.async_write_ha_state()
@@ -181,10 +183,14 @@ async def async_set_cover_position(self, **kwargs: Any) -> None:
181183
if self._position == position:
182184
return
183185

186+
self._is_closing = position < (self._position or 0)
187+
self._is_opening = not self._is_closing
188+
184189
self._listen_cover()
185190
self._requested_closing = (
186191
self._position is not None and position < self._position
187192
)
193+
self.async_write_ha_state()
188194

189195
async def async_set_cover_tilt_position(self, **kwargs: Any) -> None:
190196
"""Move the cover til to a specific position."""

tests/components/demo/test_cover.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,19 +154,44 @@ async def test_set_cover_position(hass: HomeAssistant) -> None:
154154
"""Test moving the cover to a specific position."""
155155
state = hass.states.get(ENTITY_COVER)
156156
assert state.attributes[ATTR_CURRENT_POSITION] == 70
157+
158+
# close to 10%
157159
await hass.services.async_call(
158160
COVER_DOMAIN,
159161
SERVICE_SET_COVER_POSITION,
160162
{ATTR_ENTITY_ID: ENTITY_COVER, ATTR_POSITION: 10},
161163
blocking=True,
162164
)
165+
state = hass.states.get(ENTITY_COVER)
166+
assert state.state == CoverState.CLOSING
167+
163168
for _ in range(6):
164169
future = dt_util.utcnow() + timedelta(seconds=1)
165170
async_fire_time_changed(hass, future)
166171
await hass.async_block_till_done()
167172

168173
state = hass.states.get(ENTITY_COVER)
169174
assert state.attributes[ATTR_CURRENT_POSITION] == 10
175+
assert state.state == CoverState.OPEN
176+
177+
# open to 80%
178+
await hass.services.async_call(
179+
COVER_DOMAIN,
180+
SERVICE_SET_COVER_POSITION,
181+
{ATTR_ENTITY_ID: ENTITY_COVER, ATTR_POSITION: 80},
182+
blocking=True,
183+
)
184+
state = hass.states.get(ENTITY_COVER)
185+
assert state.state == CoverState.OPENING
186+
187+
for _ in range(7):
188+
future = dt_util.utcnow() + timedelta(seconds=1)
189+
async_fire_time_changed(hass, future)
190+
await hass.async_block_till_done()
191+
192+
state = hass.states.get(ENTITY_COVER)
193+
assert state.attributes[ATTR_CURRENT_POSITION] == 80
194+
assert state.state == CoverState.OPEN
170195

171196

172197
async def test_stop_cover(hass: HomeAssistant) -> None:

0 commit comments

Comments
 (0)