Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 5 commits into from Nov 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 6 additions & 2 deletions homeassistant/components/google_assistant/helpers.py
Expand Up @@ -686,8 +686,12 @@ def sync_serialize(self, agent_user_id, instance_uuid):
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"]
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/matter/helpers.py
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions tests/components/google_assistant/test_helpers.py
Expand Up @@ -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(
Expand Down
11 changes: 4 additions & 7 deletions tests/components/matter/test_helpers.py
Expand Up @@ -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)