1
mirror of https://github.com/home-assistant/core synced 2024-08-28 03:36:46 +02:00

Fix device sync to Google Assistant if Matter integration is active (#104796)

* Only get Matter device info if device is an actual Matter device

* Return None if matter device does not exist

* lint

* fix test

* adjust google assistant test
This commit is contained in:
Marcel van der Veldt 2023-11-30 16:59:26 +01:00 committed by GitHub
parent cc2c7c7be1
commit 52450291cb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 12 additions and 10 deletions

View File

@ -686,8 +686,12 @@ class GoogleEntity:
return device
# Add Matter info
if "matter" in self.hass.config.components and (
matter_info := matter.get_matter_device_info(self.hass, device_entry.id)
if (
"matter" in self.hass.config.components
and any(x for x in device_entry.identifiers if x[0] == "matter")
and (
matter_info := matter.get_matter_device_info(self.hass, device_entry.id)
)
):
device["matterUniqueId"] = matter_info["unique_id"]
device["matterOriginalVendorId"] = matter_info["vendor_id"]

View File

@ -94,7 +94,7 @@ def get_node_from_device_entry(
)
if device_id_full is None:
raise ValueError(f"Device {device.id} is not a Matter device")
return None
device_id = device_id_full.lstrip(device_id_type_prefix)
matter_client = matter.matter_client

View File

@ -89,6 +89,7 @@ async def test_google_entity_sync_serialize_with_matter(
manufacturer="Someone",
model="Some model",
sw_version="Some Version",
identifiers={("matter", "12345678")},
connections={(dr.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")},
)
entity = entity_registry.async_get_or_create(

View File

@ -60,16 +60,13 @@ async def test_get_node_from_device_entry(
assert node_from_device_entry is node
with pytest.raises(ValueError) as value_error:
await get_node_from_device_entry(hass, other_device_entry)
assert f"Device {other_device_entry.id} is not a Matter device" in str(
value_error.value
)
# test non-Matter device returns None
assert get_node_from_device_entry(hass, other_device_entry) is None
matter_client.server_info = None
# test non-initialized server raises RuntimeError
with pytest.raises(RuntimeError) as runtime_error:
node_from_device_entry = await get_node_from_device_entry(hass, device_entry)
node_from_device_entry = get_node_from_device_entry(hass, device_entry)
assert "Matter server information is not available" in str(runtime_error.value)