Don't set assumed_state in cover groups (#99391)
parent
e0594bffa1
commit
1c2c13c938
|
@ -17,7 +17,6 @@ from homeassistant.components.cover import (
|
|||
)
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import (
|
||||
ATTR_ASSUMED_STATE,
|
||||
ATTR_ENTITY_ID,
|
||||
ATTR_SUPPORTED_FEATURES,
|
||||
CONF_ENTITIES,
|
||||
|
@ -44,7 +43,7 @@ from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
|||
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
|
||||
|
||||
from . import GroupEntity
|
||||
from .util import attribute_equal, reduce_attribute
|
||||
from .util import reduce_attribute
|
||||
|
||||
KEY_OPEN_CLOSE = "open_close"
|
||||
KEY_STOP = "stop"
|
||||
|
@ -116,7 +115,6 @@ class CoverGroup(GroupEntity, CoverEntity):
|
|||
_attr_is_opening: bool | None = False
|
||||
_attr_is_closing: bool | None = False
|
||||
_attr_current_cover_position: int | None = 100
|
||||
_attr_assumed_state: bool = True
|
||||
|
||||
def __init__(self, unique_id: str | None, name: str, entities: list[str]) -> None:
|
||||
"""Initialize a CoverGroup entity."""
|
||||
|
@ -251,8 +249,6 @@ class CoverGroup(GroupEntity, CoverEntity):
|
|||
@callback
|
||||
def async_update_group_state(self) -> None:
|
||||
"""Update state and attributes."""
|
||||
self._attr_assumed_state = False
|
||||
|
||||
states = [
|
||||
state.state
|
||||
for entity_id in self._entity_ids
|
||||
|
@ -293,9 +289,6 @@ class CoverGroup(GroupEntity, CoverEntity):
|
|||
self._attr_current_cover_position = reduce_attribute(
|
||||
position_states, ATTR_CURRENT_POSITION
|
||||
)
|
||||
self._attr_assumed_state |= not attribute_equal(
|
||||
position_states, ATTR_CURRENT_POSITION
|
||||
)
|
||||
|
||||
tilt_covers = self._tilts[KEY_POSITION]
|
||||
all_tilt_states = [self.hass.states.get(x) for x in tilt_covers]
|
||||
|
@ -303,9 +296,6 @@ class CoverGroup(GroupEntity, CoverEntity):
|
|||
self._attr_current_cover_tilt_position = reduce_attribute(
|
||||
tilt_states, ATTR_CURRENT_TILT_POSITION
|
||||
)
|
||||
self._attr_assumed_state |= not attribute_equal(
|
||||
tilt_states, ATTR_CURRENT_TILT_POSITION
|
||||
)
|
||||
|
||||
supported_features = CoverEntityFeature(0)
|
||||
if self._covers[KEY_OPEN_CLOSE]:
|
||||
|
@ -322,11 +312,3 @@ class CoverGroup(GroupEntity, CoverEntity):
|
|||
if self._tilts[KEY_POSITION]:
|
||||
supported_features |= CoverEntityFeature.SET_TILT_POSITION
|
||||
self._attr_supported_features = supported_features
|
||||
|
||||
if not self._attr_assumed_state:
|
||||
for entity_id in self._entity_ids:
|
||||
if (state := self.hass.states.get(entity_id)) is None:
|
||||
continue
|
||||
if state and state.attributes.get(ATTR_ASSUMED_STATE):
|
||||
self._attr_assumed_state = True
|
||||
break
|
||||
|
|
|
@ -346,10 +346,10 @@ async def test_attributes(hass: HomeAssistant, setup_comp) -> None:
|
|||
assert state.attributes[ATTR_CURRENT_POSITION] == 70
|
||||
assert state.attributes[ATTR_CURRENT_TILT_POSITION] == 60
|
||||
|
||||
# ### Test assumed state ###
|
||||
# ### Test state when group members have different states ###
|
||||
# ##########################
|
||||
|
||||
# For covers - assumed state set true if position differ
|
||||
# Covers
|
||||
hass.states.async_set(
|
||||
DEMO_COVER, STATE_OPEN, {ATTR_SUPPORTED_FEATURES: 4, ATTR_CURRENT_POSITION: 100}
|
||||
)
|
||||
|
@ -357,7 +357,7 @@ async def test_attributes(hass: HomeAssistant, setup_comp) -> None:
|
|||
|
||||
state = hass.states.get(COVER_GROUP)
|
||||
assert state.state == STATE_OPEN
|
||||
assert state.attributes[ATTR_ASSUMED_STATE] is True
|
||||
assert ATTR_ASSUMED_STATE not in state.attributes
|
||||
assert state.attributes[ATTR_SUPPORTED_FEATURES] == 244
|
||||
assert state.attributes[ATTR_CURRENT_POSITION] == 85 # (70 + 100) / 2
|
||||
assert state.attributes[ATTR_CURRENT_TILT_POSITION] == 60
|
||||
|
@ -373,7 +373,7 @@ async def test_attributes(hass: HomeAssistant, setup_comp) -> None:
|
|||
assert ATTR_CURRENT_POSITION not in state.attributes
|
||||
assert state.attributes[ATTR_CURRENT_TILT_POSITION] == 60
|
||||
|
||||
# For tilts - assumed state set true if tilt position differ
|
||||
# Tilts
|
||||
hass.states.async_set(
|
||||
DEMO_TILT,
|
||||
STATE_OPEN,
|
||||
|
@ -383,7 +383,7 @@ async def test_attributes(hass: HomeAssistant, setup_comp) -> None:
|
|||
|
||||
state = hass.states.get(COVER_GROUP)
|
||||
assert state.state == STATE_OPEN
|
||||
assert state.attributes[ATTR_ASSUMED_STATE] is True
|
||||
assert ATTR_ASSUMED_STATE not in state.attributes
|
||||
assert state.attributes[ATTR_SUPPORTED_FEATURES] == 128
|
||||
assert ATTR_CURRENT_POSITION not in state.attributes
|
||||
assert state.attributes[ATTR_CURRENT_TILT_POSITION] == 80 # (60 + 100) / 2
|
||||
|
@ -399,11 +399,12 @@ async def test_attributes(hass: HomeAssistant, setup_comp) -> None:
|
|||
assert ATTR_CURRENT_POSITION not in state.attributes
|
||||
assert ATTR_CURRENT_TILT_POSITION not in state.attributes
|
||||
|
||||
# Group member has set assumed_state
|
||||
hass.states.async_set(DEMO_TILT, STATE_CLOSED, {ATTR_ASSUMED_STATE: True})
|
||||
await hass.async_block_till_done()
|
||||
|
||||
state = hass.states.get(COVER_GROUP)
|
||||
assert state.attributes[ATTR_ASSUMED_STATE] is True
|
||||
assert ATTR_ASSUMED_STATE not in state.attributes
|
||||
|
||||
# Test entity registry integration
|
||||
entity_registry = er.async_get(hass)
|
||||
|
|
Loading…
Reference in New Issue