Don't set assumed_state in fan groups (#99399)

This commit is contained in:
Erik Montnemery 2023-09-04 14:08:50 +02:00 committed by GitHub
parent f3d8a0eaaf
commit 6223af1899
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 6 additions and 31 deletions

View file

@ -25,7 +25,6 @@ from homeassistant.components.fan import (
)
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import (
ATTR_ASSUMED_STATE,
ATTR_ENTITY_ID,
ATTR_SUPPORTED_FEATURES,
CONF_ENTITIES,
@ -41,12 +40,7 @@ from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
from . import GroupEntity
from .util import (
attribute_equal,
most_frequent_attribute,
reduce_attribute,
states_equal,
)
from .util import attribute_equal, most_frequent_attribute, reduce_attribute
SUPPORTED_FLAGS = {
FanEntityFeature.SET_SPEED,
@ -110,7 +104,6 @@ class FanGroup(GroupEntity, FanEntity):
"""Representation of a FanGroup."""
_attr_available: bool = False
_attr_assumed_state: bool = True
def __init__(self, unique_id: str | None, name: str, entities: list[str]) -> None:
"""Initialize a FanGroup entity."""
@ -243,19 +236,16 @@ class FanGroup(GroupEntity, FanEntity):
"""Set an attribute based on most frequent supported entities attributes."""
states = self._async_states_by_support_flag(flag)
setattr(self, attr, most_frequent_attribute(states, entity_attr))
self._attr_assumed_state |= not attribute_equal(states, entity_attr)
@callback
def async_update_group_state(self) -> None:
"""Update state and attributes."""
self._attr_assumed_state = False
states = [
state
for entity_id in self._entity_ids
if (state := self.hass.states.get(entity_id)) is not None
]
self._attr_assumed_state |= not states_equal(states)
# Set group as unavailable if all members are unavailable or missing
self._attr_available = any(state.state != STATE_UNAVAILABLE for state in states)
@ -274,9 +264,6 @@ class FanGroup(GroupEntity, FanEntity):
FanEntityFeature.SET_SPEED
)
self._percentage = reduce_attribute(percentage_states, ATTR_PERCENTAGE)
self._attr_assumed_state |= not attribute_equal(
percentage_states, ATTR_PERCENTAGE
)
if (
percentage_states
and percentage_states[0].attributes.get(ATTR_PERCENTAGE_STEP)
@ -301,6 +288,3 @@ class FanGroup(GroupEntity, FanEntity):
ior, [feature for feature in SUPPORTED_FLAGS if self._fans[feature]], 0
)
)
self._attr_assumed_state |= any(
state.attributes.get(ATTR_ASSUMED_STATE) for state in states
)

View file

@ -468,7 +468,7 @@ async def test_options_flow_hides_members(
COVER_ATTRS = [{"supported_features": 0}, {}]
EVENT_ATTRS = [{"event_types": []}, {"event_type": None}]
FAN_ATTRS = [{"supported_features": 0}, {"assumed_state": True}]
FAN_ATTRS = [{"supported_features": 0}, {}]
LIGHT_ATTRS = [
{
"icon": "mdi:lightbulb-group",

View file

@ -247,11 +247,7 @@ async def test_attributes(hass: HomeAssistant, setup_comp) -> None:
assert state.attributes[ATTR_PERCENTAGE] == 50
assert ATTR_ASSUMED_STATE not in state.attributes
# Add Entity that supports
# ### Test assumed state ###
# ##########################
# Add Entity with a different speed should set assumed state
# Add Entity with a different speed should not set assumed state
hass.states.async_set(
PERCENTAGE_LIMITED_FAN_ENTITY_ID,
STATE_ON,
@ -264,7 +260,7 @@ async def test_attributes(hass: HomeAssistant, setup_comp) -> None:
state = hass.states.get(FAN_GROUP)
assert state.state == STATE_ON
assert state.attributes[ATTR_ASSUMED_STATE] is True
assert ATTR_ASSUMED_STATE not in state.attributes
assert state.attributes[ATTR_PERCENTAGE] == int((50 + 75) / 2)
@ -306,11 +302,7 @@ async def test_direction_oscillating(hass: HomeAssistant, setup_comp) -> None:
assert state.attributes[ATTR_DIRECTION] == DIRECTION_FORWARD
assert ATTR_ASSUMED_STATE not in state.attributes
# Add Entity that supports
# ### Test assumed state ###
# ##########################
# Add Entity with a different direction should set assumed state
# Add Entity with a different direction should not set assumed state
hass.states.async_set(
PERCENTAGE_FULL_FAN_ENTITY_ID,
STATE_ON,
@ -325,11 +317,10 @@ async def test_direction_oscillating(hass: HomeAssistant, setup_comp) -> None:
state = hass.states.get(FAN_GROUP)
assert state.state == STATE_ON
assert state.attributes[ATTR_ASSUMED_STATE] is True
assert ATTR_ASSUMED_STATE not in state.attributes
assert ATTR_PERCENTAGE in state.attributes
assert state.attributes[ATTR_PERCENTAGE] == 50
assert state.attributes[ATTR_OSCILLATING] is True
assert ATTR_ASSUMED_STATE in state.attributes
# Now that everything is the same, no longer assumed state