From b5457a5abd8b8b12808b544bbf6fc820ec376b65 Mon Sep 17 00:00:00 2001 From: Shay Levy Date: Thu, 16 Oct 2025 21:21:32 +0300 Subject: [PATCH] Fix demo cover set position action (#154641) --- homeassistant/components/demo/cover.py | 6 ++++++ tests/components/demo/test_cover.py | 25 +++++++++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/homeassistant/components/demo/cover.py b/homeassistant/components/demo/cover.py index ed13f24cfd7..af7b4934975 100644 --- a/homeassistant/components/demo/cover.py +++ b/homeassistant/components/demo/cover.py @@ -139,6 +139,7 @@ class DemoCover(CoverEntity): self.async_write_ha_state() return + self._is_opening = False self._is_closing = True self._listen_cover() self._requested_closing = True @@ -162,6 +163,7 @@ class DemoCover(CoverEntity): return self._is_opening = True + self._is_closing = False self._listen_cover() self._requested_closing = False self.async_write_ha_state() @@ -181,10 +183,14 @@ class DemoCover(CoverEntity): if self._position == position: return + self._is_closing = position < (self._position or 0) + self._is_opening = not self._is_closing + self._listen_cover() self._requested_closing = ( self._position is not None and position < self._position ) + self.async_write_ha_state() async def async_set_cover_tilt_position(self, **kwargs: Any) -> None: """Move the cover til to a specific position.""" diff --git a/tests/components/demo/test_cover.py b/tests/components/demo/test_cover.py index dcec921c01d..3a2e51ca6b1 100644 --- a/tests/components/demo/test_cover.py +++ b/tests/components/demo/test_cover.py @@ -154,12 +154,17 @@ async def test_set_cover_position(hass: HomeAssistant) -> None: """Test moving the cover to a specific position.""" state = hass.states.get(ENTITY_COVER) assert state.attributes[ATTR_CURRENT_POSITION] == 70 + + # close to 10% await hass.services.async_call( COVER_DOMAIN, SERVICE_SET_COVER_POSITION, {ATTR_ENTITY_ID: ENTITY_COVER, ATTR_POSITION: 10}, blocking=True, ) + state = hass.states.get(ENTITY_COVER) + assert state.state == CoverState.CLOSING + for _ in range(6): future = dt_util.utcnow() + timedelta(seconds=1) async_fire_time_changed(hass, future) @@ -167,6 +172,26 @@ async def test_set_cover_position(hass: HomeAssistant) -> None: state = hass.states.get(ENTITY_COVER) assert state.attributes[ATTR_CURRENT_POSITION] == 10 + assert state.state == CoverState.OPEN + + # open to 80% + await hass.services.async_call( + COVER_DOMAIN, + SERVICE_SET_COVER_POSITION, + {ATTR_ENTITY_ID: ENTITY_COVER, ATTR_POSITION: 80}, + blocking=True, + ) + state = hass.states.get(ENTITY_COVER) + assert state.state == CoverState.OPENING + + for _ in range(7): + future = dt_util.utcnow() + timedelta(seconds=1) + async_fire_time_changed(hass, future) + await hass.async_block_till_done() + + state = hass.states.get(ENTITY_COVER) + assert state.attributes[ATTR_CURRENT_POSITION] == 80 + assert state.state == CoverState.OPEN async def test_stop_cover(hass: HomeAssistant) -> None: