From 115bb39c10e63b840bc09c7e6afb92a2868df133 Mon Sep 17 00:00:00 2001 From: Regev Brody Date: Wed, 29 Sep 2021 09:37:16 +0300 Subject: [PATCH] Fix cover group to handle unknown state properly (#56739) * fix cover group unknown state * fix cover grup state * fix cover group issue --- homeassistant/components/group/cover.py | 8 +++++-- tests/components/group/test_cover.py | 31 ++++++++++++++++++++++++- 2 files changed, 36 insertions(+), 3 deletions(-) diff --git a/homeassistant/components/group/cover.py b/homeassistant/components/group/cover.py index 3870ad3cca5..45d88a07f88 100644 --- a/homeassistant/components/group/cover.py +++ b/homeassistant/components/group/cover.py @@ -37,6 +37,7 @@ from homeassistant.const import ( CONF_ENTITIES, CONF_NAME, CONF_UNIQUE_ID, + STATE_CLOSED, STATE_CLOSING, STATE_OPEN, STATE_OPENING, @@ -85,7 +86,7 @@ async def async_setup_platform( class CoverGroup(GroupEntity, CoverEntity): """Representation of a CoverGroup.""" - _attr_is_closed: bool | None = False + _attr_is_closed: bool | None = None _attr_is_opening: bool | None = False _attr_is_closing: bool | None = False _attr_current_cover_position: int | None = 100 @@ -258,7 +259,7 @@ class CoverGroup(GroupEntity, CoverEntity): """Update state and attributes.""" self._attr_assumed_state = False - self._attr_is_closed = True + self._attr_is_closed = None self._attr_is_closing = False self._attr_is_opening = False for entity_id in self._entities: @@ -268,6 +269,9 @@ class CoverGroup(GroupEntity, CoverEntity): if state.state == STATE_OPEN: self._attr_is_closed = False continue + if state.state == STATE_CLOSED: + self._attr_is_closed = True + continue if state.state == STATE_CLOSING: self._attr_is_closing = True continue diff --git a/tests/components/group/test_cover.py b/tests/components/group/test_cover.py index 758bc5e0dac..9d16be9150b 100644 --- a/tests/components/group/test_cover.py +++ b/tests/components/group/test_cover.py @@ -32,6 +32,7 @@ from homeassistant.const import ( STATE_CLOSING, STATE_OPEN, STATE_OPENING, + STATE_UNKNOWN, ) from homeassistant.helpers import entity_registry as er from homeassistant.setup import async_setup_component @@ -99,7 +100,7 @@ async def setup_comp(hass, config_count): async def test_attributes(hass, setup_comp): """Test handling of state attributes.""" state = hass.states.get(COVER_GROUP) - assert state.state == STATE_CLOSED + assert state.state == STATE_UNKNOWN assert state.attributes[ATTR_FRIENDLY_NAME] == DEFAULT_NAME assert state.attributes[ATTR_ENTITY_ID] == [ DEMO_COVER, @@ -112,6 +113,34 @@ async def test_attributes(hass, setup_comp): assert ATTR_CURRENT_POSITION not in state.attributes assert ATTR_CURRENT_TILT_POSITION not in state.attributes + # Set entity as closed + hass.states.async_set(DEMO_COVER, STATE_CLOSED, {}) + await hass.async_block_till_done() + + state = hass.states.get(COVER_GROUP) + assert state.state == STATE_CLOSED + + # Set entity as opening + hass.states.async_set(DEMO_COVER, STATE_OPENING, {}) + await hass.async_block_till_done() + + state = hass.states.get(COVER_GROUP) + assert state.state == STATE_OPENING + + # Set entity as closing + hass.states.async_set(DEMO_COVER, STATE_CLOSING, {}) + await hass.async_block_till_done() + + state = hass.states.get(COVER_GROUP) + assert state.state == STATE_CLOSING + + # Set entity as unknown again + hass.states.async_set(DEMO_COVER, STATE_UNKNOWN, {}) + await hass.async_block_till_done() + + state = hass.states.get(COVER_GROUP) + assert state.state == STATE_UNKNOWN + # Add Entity that supports open / close / stop hass.states.async_set(DEMO_COVER, STATE_OPEN, {ATTR_SUPPORTED_FEATURES: 11}) await hass.async_block_till_done()