diff --git a/homeassistant/components/google_assistant/helpers.py b/homeassistant/components/google_assistant/helpers.py index b2cda5522ee..2eeb1903c85 100644 --- a/homeassistant/components/google_assistant/helpers.py +++ b/homeassistant/components/google_assistant/helpers.py @@ -15,7 +15,7 @@ from aiohttp.web import json_response from awesomeversion import AwesomeVersion from yarl import URL -from homeassistant.components import webhook +from homeassistant.components import matter, webhook from homeassistant.const import ( ATTR_DEVICE_CLASS, ATTR_SUPPORTED_FEATURES, @@ -678,10 +678,18 @@ class GoogleEntity: elif area_entry and area_entry.name: device["roomHint"] = area_entry.name - # Add deviceInfo if not device_entry: 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) + ): + device["matterUniqueId"] = matter_info["unique_id"] + device["matterOriginalVendorId"] = matter_info["vendor_id"] + device["matterOriginalProductId"] = matter_info["product_id"] + + # Add deviceInfo device_info = {} if device_entry.manufacturer: diff --git a/homeassistant/components/google_assistant/manifest.json b/homeassistant/components/google_assistant/manifest.json index 3c7ac043441..e36f6a1ca87 100644 --- a/homeassistant/components/google_assistant/manifest.json +++ b/homeassistant/components/google_assistant/manifest.json @@ -1,7 +1,7 @@ { "domain": "google_assistant", "name": "Google Assistant", - "after_dependencies": ["camera"], + "after_dependencies": ["camera", "matter"], "codeowners": ["@home-assistant/cloud"], "dependencies": ["http"], "documentation": "https://www.home-assistant.io/integrations/google_assistant", diff --git a/tests/components/google_assistant/test_helpers.py b/tests/components/google_assistant/test_helpers.py index 57915968933..771df137278 100644 --- a/tests/components/google_assistant/test_helpers.py +++ b/tests/components/google_assistant/test_helpers.py @@ -14,14 +14,17 @@ from homeassistant.components.google_assistant.const import ( SOURCE_LOCAL, STORE_GOOGLE_LOCAL_WEBHOOK_ID, ) +from homeassistant.components.matter.models import MatterDeviceInfo from homeassistant.config import async_process_ha_core_config from homeassistant.core import HomeAssistant, State +from homeassistant.helpers import device_registry as dr, entity_registry as er from homeassistant.setup import async_setup_component from homeassistant.util import dt as dt_util from . import MockConfig from tests.common import ( + MockConfigEntry, async_capture_events, async_fire_time_changed, async_mock_service, @@ -73,6 +76,56 @@ async def test_google_entity_sync_serialize_with_local_sdk(hass: HomeAssistant) assert "customData" not in serialized +async def test_google_entity_sync_serialize_with_matter( + hass: HomeAssistant, + device_registry: dr.DeviceRegistry, + entity_registry: er.EntityRegistry, +) -> None: + """Test sync serialize attributes of a GoogleEntity that is also a Matter device.""" + entry = MockConfigEntry() + entry.add_to_hass(hass) + device = device_registry.async_get_or_create( + config_entry_id=entry.entry_id, + manufacturer="Someone", + model="Some model", + sw_version="Some Version", + connections={(dr.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")}, + ) + entity = entity_registry.async_get_or_create( + "light", + "test", + "1235", + suggested_object_id="ceiling_lights", + device_id=device.id, + ) + hass.states.async_set("light.ceiling_lights", "off") + + entity = helpers.GoogleEntity( + hass, MockConfig(hass=hass), hass.states.get("light.ceiling_lights") + ) + + serialized = entity.sync_serialize(None, "mock-uuid") + assert "matterUniqueId" not in serialized + assert "matterOriginalVendorId" not in serialized + assert "matterOriginalProductId" not in serialized + + hass.config.components.add("matter") + + with patch( + "homeassistant.components.matter.get_matter_device_info", + return_value=MatterDeviceInfo( + unique_id="mock-unique-id", + vendor_id="mock-vendor-id", + product_id="mock-product-id", + ), + ): + serialized = entity.sync_serialize("mock-user-id", "abcdef") + + assert serialized["matterUniqueId"] == "mock-unique-id" + assert serialized["matterOriginalVendorId"] == "mock-vendor-id" + assert serialized["matterOriginalProductId"] == "mock-product-id" + + async def test_config_local_sdk( hass: HomeAssistant, hass_client: ClientSessionGenerator ) -> None: