1
0
mirror of https://github.com/home-assistant/core.git synced 2026-02-15 07:36:16 +00:00

Allow updates of group members

This commit is contained in:
jbouwh
2026-02-14 13:31:16 +00:00
parent 60829089b5
commit bd1d6b747f
2 changed files with 48 additions and 2 deletions

View File

@@ -466,7 +466,7 @@ def async_setup_entity_entry_helper(
class MqttAttributesMixin(Entity):
"""Mixin used for platforms that support JSON attributes."""
"""Mixin used for platforms that support JSON attributes and group entities."""
_attributes_extra_blocked: frozenset[str] = frozenset()
_attr_tpl: Callable[[ReceivePayloadType], ReceivePayloadType] | None = None
@@ -474,9 +474,10 @@ class MqttAttributesMixin(Entity):
[MessageCallbackType, set[str] | None, ReceiveMessage], None
]
_process_update_extra_state_attributes: Callable[[dict[str, Any]], None]
group: IntegrationSpecificGroup
def __init__(self, config: ConfigType) -> None:
"""Initialize the JSON attributes mixin."""
"""Initialize the JSON attributes and handle group entities."""
self._attributes_sub_state: dict[str, EntitySubscription] = {}
if CONF_GROUP in config:
self.group = IntegrationSpecificGroup(self, config[CONF_GROUP])
@@ -490,6 +491,8 @@ class MqttAttributesMixin(Entity):
def attributes_prepare_discovery_update(self, config: DiscoveryInfoType) -> None:
"""Handle updated discovery message."""
if self.group is not None and CONF_GROUP in config:
self.group.included_unique_ids = config[CONF_GROUP]
self._attributes_config = config
self._attributes_prepare_subscribe_topics()

View File

@@ -173,6 +173,7 @@ COLOR_MODES_CONFIG = {
GROUP_MEMBER_1_TOPIC = "homeassistant/light/member_1/config"
GROUP_MEMBER_2_TOPIC = "homeassistant/light/member_2/config"
GROUP_MEMBER_3_TOPIC = "homeassistant/light/member_3/config"
GROUP_TOPIC = "homeassistant/light/group/config"
GROUP_DISCOVERY_MEMBER_1_CONFIG = json.dumps(
{
@@ -192,6 +193,15 @@ GROUP_DISCOVERY_MEMBER_2_CONFIG = json.dumps(
"default_entity_id": "light.member2",
}
)
GROUP_DISCOVERY_MEMBER_3_CONFIG = json.dumps(
{
"schema": "json",
"command_topic": "test-command-topic-member3",
"unique_id": "very_unique_member3",
"name": "member3",
"default_entity_id": "light.member3",
}
)
GROUP_DISCOVERY_LIGHT_GROUP_CONFIG = json.dumps(
{
"schema": "json",
@@ -203,6 +213,17 @@ GROUP_DISCOVERY_LIGHT_GROUP_CONFIG = json.dumps(
"group": ["very_unique_member1", "very_unique_member2"],
}
)
GROUP_DISCOVERY_LIGHT_GROUP_CONFIG_EXPANDED = json.dumps(
{
"schema": "json",
"command_topic": "test-command-topic-group",
"state_topic": "test-state-topic-group",
"unique_id": "very_unique_group",
"name": "group",
"default_entity_id": "light.group",
"group": ["very_unique_member1", "very_unique_member2", "very_unique_member3"],
}
)
class JsonValidator:
@@ -1921,6 +1942,28 @@ async def test_light_group_discovery_members_before_group(
"light.member2",
]
# Now create and discover a new member
async_fire_mqtt_message(hass, GROUP_MEMBER_3_TOPIC, GROUP_DISCOVERY_MEMBER_3_CONFIG)
await hass.async_block_till_done()
# Update the group discovery
async_fire_mqtt_message(
hass, GROUP_TOPIC, GROUP_DISCOVERY_LIGHT_GROUP_CONFIG_EXPANDED
)
await hass.async_block_till_done()
assert hass.states.get("light.member1") is not None
assert hass.states.get("light.member2") is not None
assert hass.states.get("light.member3") is not None
group_state = hass.states.get("light.group")
assert group_state is not None
assert group_state.attributes.get("group_entities") == [
"light.member1",
"light.member2",
"light.member3",
]
async def test_light_group_discovery_group_before_members(
hass: HomeAssistant,