mirror of
https://github.com/home-assistant/core.git
synced 2026-05-08 17:49:37 +01:00
Fix demo cover set position action (#154641)
This commit is contained in:
@@ -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."""
|
||||
|
||||
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user