mirror of
https://github.com/home-assistant/core.git
synced 2025-11-09 10:59:40 +00:00
Add analytics platform to automation (#152828)
This commit is contained in:
@@ -18,6 +18,7 @@ from .analytics import (
|
|||||||
AnalyticsModifications,
|
AnalyticsModifications,
|
||||||
DeviceAnalyticsModifications,
|
DeviceAnalyticsModifications,
|
||||||
EntityAnalyticsModifications,
|
EntityAnalyticsModifications,
|
||||||
|
async_devices_payload,
|
||||||
)
|
)
|
||||||
from .const import ATTR_ONBOARDED, ATTR_PREFERENCES, DOMAIN, INTERVAL, PREFERENCE_SCHEMA
|
from .const import ATTR_ONBOARDED, ATTR_PREFERENCES, DOMAIN, INTERVAL, PREFERENCE_SCHEMA
|
||||||
from .http import AnalyticsDevicesView
|
from .http import AnalyticsDevicesView
|
||||||
@@ -27,6 +28,7 @@ __all__ = [
|
|||||||
"AnalyticsModifications",
|
"AnalyticsModifications",
|
||||||
"DeviceAnalyticsModifications",
|
"DeviceAnalyticsModifications",
|
||||||
"EntityAnalyticsModifications",
|
"EntityAnalyticsModifications",
|
||||||
|
"async_devices_payload",
|
||||||
]
|
]
|
||||||
|
|
||||||
CONFIG_SCHEMA = cv.empty_config_schema(DOMAIN)
|
CONFIG_SCHEMA = cv.empty_config_schema(DOMAIN)
|
||||||
|
|||||||
24
homeassistant/components/automation/analytics.py
Normal file
24
homeassistant/components/automation/analytics.py
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
"""Analytics platform."""
|
||||||
|
|
||||||
|
from homeassistant.components.analytics import (
|
||||||
|
AnalyticsInput,
|
||||||
|
AnalyticsModifications,
|
||||||
|
EntityAnalyticsModifications,
|
||||||
|
)
|
||||||
|
from homeassistant.core import HomeAssistant
|
||||||
|
from homeassistant.helpers import entity_registry as er
|
||||||
|
|
||||||
|
|
||||||
|
async def async_modify_analytics(
|
||||||
|
hass: HomeAssistant, analytics_input: AnalyticsInput
|
||||||
|
) -> AnalyticsModifications:
|
||||||
|
"""Modify the analytics."""
|
||||||
|
ent_reg = er.async_get(hass)
|
||||||
|
|
||||||
|
entities: dict[str, EntityAnalyticsModifications] = {}
|
||||||
|
for entity_id in analytics_input.entity_ids:
|
||||||
|
entity_entry = ent_reg.entities[entity_id]
|
||||||
|
if entity_entry.capabilities is not None:
|
||||||
|
entities[entity_id] = EntityAnalyticsModifications(capabilities=None)
|
||||||
|
|
||||||
|
return AnalyticsModifications(entities=entities)
|
||||||
41
tests/components/automation/test_analytics.py
Normal file
41
tests/components/automation/test_analytics.py
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
"""Tests for analytics platform."""
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
|
||||||
|
from homeassistant.components.analytics import async_devices_payload
|
||||||
|
from homeassistant.components.automation import DOMAIN
|
||||||
|
from homeassistant.core import HomeAssistant
|
||||||
|
from homeassistant.helpers import entity_registry as er
|
||||||
|
from homeassistant.setup import async_setup_component
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.asyncio
|
||||||
|
async def test_analytics(
|
||||||
|
hass: HomeAssistant, entity_registry: er.EntityRegistry
|
||||||
|
) -> None:
|
||||||
|
"""Test the analytics platform."""
|
||||||
|
await async_setup_component(hass, "analytics", {})
|
||||||
|
|
||||||
|
entity_registry.async_get_or_create(
|
||||||
|
domain="automation",
|
||||||
|
platform="automation",
|
||||||
|
unique_id="automation1",
|
||||||
|
suggested_object_id="automation1",
|
||||||
|
capabilities={"id": "automation1"},
|
||||||
|
)
|
||||||
|
|
||||||
|
result = await async_devices_payload(hass)
|
||||||
|
assert result["integrations"][DOMAIN]["entities"] == [
|
||||||
|
{
|
||||||
|
"assumed_state": None,
|
||||||
|
"capabilities": None,
|
||||||
|
"domain": "automation",
|
||||||
|
"entity_category": None,
|
||||||
|
"has_entity_name": False,
|
||||||
|
"modified_by_integration": [
|
||||||
|
"capabilities",
|
||||||
|
],
|
||||||
|
"original_device_class": None,
|
||||||
|
"unit_of_measurement": None,
|
||||||
|
},
|
||||||
|
]
|
||||||
Reference in New Issue
Block a user