Fix Matter device ID for non-bridged composed device (#118256)

This commit is contained in:
Marcel van der Veldt 2024-05-28 12:47:46 +02:00 committed by GitHub
parent a5f81262aa
commit 21f5ac7715
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 20 additions and 6 deletions

View file

@ -59,12 +59,12 @@ def get_device_id(
) -> str: ) -> str:
"""Return HA device_id for the given MatterEndpoint.""" """Return HA device_id for the given MatterEndpoint."""
operational_instance_id = get_operational_instance_id(server_info, endpoint.node) operational_instance_id = get_operational_instance_id(server_info, endpoint.node)
# Append endpoint ID if this endpoint is a bridged or composed device # if this is a composed device we need to get the compose parent
if endpoint.is_composed_device: # example: Philips Hue motion sensor on Hue Hub (bridged to Matter)
compose_parent = endpoint.node.get_compose_parent(endpoint.endpoint_id) if compose_parent := endpoint.node.get_compose_parent(endpoint.endpoint_id):
assert compose_parent is not None endpoint = compose_parent
postfix = str(compose_parent.endpoint_id) if endpoint.is_bridged_device:
elif endpoint.is_bridged_device: # Append endpoint ID if this endpoint is a bridged device
postfix = str(endpoint.endpoint_id) postfix = str(endpoint.endpoint_id)
else: else:
# this should be compatible with previous versions # this should be compatible with previous versions

View file

@ -172,6 +172,20 @@ async def test_node_added_subscription(
assert entity_state assert entity_state
async def test_device_registry_single_node_composed_device(
hass: HomeAssistant,
matter_client: MagicMock,
) -> None:
"""Test that a composed device within a standalone node only creates one HA device entry."""
await setup_integration_with_node_fixture(
hass,
"air-purifier",
matter_client,
)
dev_reg = dr.async_get(hass)
assert len(dev_reg.devices) == 1
async def test_get_clean_name_() -> None: async def test_get_clean_name_() -> None:
"""Test get_clean_name helper. """Test get_clean_name helper.