From 0f904d418bb2422340f87a0395f5f3a19ce3e2ac Mon Sep 17 00:00:00 2001 From: Artur Pragacz <49985303+arturpragacz@users.noreply.github.com> Date: Wed, 24 Sep 2025 12:32:30 +0200 Subject: [PATCH] Filter out integration types in extended analytics (#152874) --- .../components/analytics/analytics.py | 3 +- tests/components/analytics/test_analytics.py | 40 ++++++++++++++++--- 2 files changed, 36 insertions(+), 7 deletions(-) diff --git a/homeassistant/components/analytics/analytics.py b/homeassistant/components/analytics/analytics.py index b527c8ab937..22e641c414a 100644 --- a/homeassistant/components/analytics/analytics.py +++ b/homeassistant/components/analytics/analytics.py @@ -546,12 +546,13 @@ async def async_devices_payload(hass: HomeAssistant) -> dict: if isinstance(integration, Integration) } - # Filter out custom integrations + # Filter out custom integrations and integrations that are not device or hub type integration_inputs = { domain: integration_info for domain, integration_info in integration_inputs.items() if (integration := integrations.get(domain)) is not None and integration.is_built_in + and integration.integration_type in ("device", "hub") } # Call integrations that implement the analytics platform diff --git a/tests/components/analytics/test_analytics.py b/tests/components/analytics/test_analytics.py index 9a63f4b29cb..4a98d9770e4 100644 --- a/tests/components/analytics/test_analytics.py +++ b/tests/components/analytics/test_analytics.py @@ -1055,6 +1055,16 @@ async def test_devices_payload_no_entities( model_id="test-model-id7", ) + # Device from an integration with a service type + mock_service_config_entry = MockConfigEntry(domain="uptime") + mock_service_config_entry.add_to_hass(hass) + device_registry.async_get_or_create( + config_entry_id=mock_service_config_entry.entry_id, + identifiers={("device", "8")}, + manufacturer="test-manufacturer8", + model_id="test-model-id8", + ) + client = await hass_client() response = await client.get("/api/analytics/devices") assert response.status == HTTPStatus.OK @@ -1173,21 +1183,29 @@ async def test_devices_payload_with_entities( original_device_class=NumberDeviceClass.TEMPERATURE, ) hass.states.async_set("number.hue_1", "2") - # Helper entity with assumed state + # Entity with assumed state entity_registry.async_get_or_create( domain="light", - platform="template", + platform="hue", + unique_id="2", + device_id=device_entry.id, + has_entity_name=True, + ) + hass.states.async_set("light.hue_2", "on", {ATTR_ASSUMED_STATE: True}) + # Entity from a different integration + entity_registry.async_get_or_create( + domain="light", + platform="roomba", unique_id="1", device_id=device_entry.id, has_entity_name=True, ) - hass.states.async_set("light.template_1", "on", {ATTR_ASSUMED_STATE: True}) # Second device entity_registry.async_get_or_create( domain="light", platform="hue", - unique_id="2", + unique_id="3", device_id=device_entry_2.id, ) @@ -1235,6 +1253,16 @@ async def test_devices_payload_with_entities( "original_device_class": "temperature", "unit_of_measurement": None, }, + { + "assumed_state": True, + "capabilities": None, + "domain": "light", + "entity_category": None, + "has_entity_name": True, + "modified_by_integration": None, + "original_device_class": None, + "unit_of_measurement": None, + }, ], "entry_type": None, "has_configuration_url": False, @@ -1281,11 +1309,11 @@ async def test_devices_payload_with_entities( }, ], }, - "template": { + "roomba": { "devices": [], "entities": [ { - "assumed_state": True, + "assumed_state": None, "capabilities": None, "domain": "light", "entity_category": None,