mirror of
https://github.com/home-assistant/core.git
synced 2025-07-21 12:17:07 +00:00
Add custom integrations to analytics (#48753)
This commit is contained in:
parent
89f2f458d2
commit
191c01a611
@ -8,7 +8,7 @@ import async_timeout
|
||||
from homeassistant.components import hassio
|
||||
from homeassistant.components.api import ATTR_INSTALLATION_TYPE
|
||||
from homeassistant.components.automation.const import DOMAIN as AUTOMATION_DOMAIN
|
||||
from homeassistant.const import __version__ as HA_VERSION
|
||||
from homeassistant.const import ATTR_DOMAIN, __version__ as HA_VERSION
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
||||
from homeassistant.helpers.storage import Store
|
||||
@ -23,6 +23,7 @@ from .const import (
|
||||
ATTR_AUTO_UPDATE,
|
||||
ATTR_AUTOMATION_COUNT,
|
||||
ATTR_BASE,
|
||||
ATTR_CUSTOM_INTEGRATIONS,
|
||||
ATTR_DIAGNOSTICS,
|
||||
ATTR_HEALTHY,
|
||||
ATTR_INTEGRATION_COUNT,
|
||||
@ -131,6 +132,7 @@ class Analytics:
|
||||
|
||||
system_info = await async_get_system_info(self.hass)
|
||||
integrations = []
|
||||
custom_integrations = []
|
||||
addons = []
|
||||
payload: dict = {
|
||||
ATTR_UUID: self.uuid,
|
||||
@ -162,7 +164,16 @@ class Analytics:
|
||||
if isinstance(integration, BaseException):
|
||||
raise integration
|
||||
|
||||
if integration.disabled or not integration.is_built_in:
|
||||
if integration.disabled:
|
||||
continue
|
||||
|
||||
if not integration.is_built_in:
|
||||
custom_integrations.append(
|
||||
{
|
||||
ATTR_DOMAIN: integration.domain,
|
||||
ATTR_VERSION: integration.version,
|
||||
}
|
||||
)
|
||||
continue
|
||||
|
||||
integrations.append(integration.domain)
|
||||
@ -186,6 +197,7 @@ class Analytics:
|
||||
|
||||
if self.preferences.get(ATTR_USAGE, False):
|
||||
payload[ATTR_INTEGRATIONS] = integrations
|
||||
payload[ATTR_CUSTOM_INTEGRATIONS] = custom_integrations
|
||||
if supervisor_info is not None:
|
||||
payload[ATTR_ADDONS] = addons
|
||||
|
||||
|
@ -18,6 +18,7 @@ ATTR_ADDONS = "addons"
|
||||
ATTR_AUTO_UPDATE = "auto_update"
|
||||
ATTR_AUTOMATION_COUNT = "automation_count"
|
||||
ATTR_BASE = "base"
|
||||
ATTR_CUSTOM_INTEGRATIONS = "custom_integrations"
|
||||
ATTR_DIAGNOSTICS = "diagnostics"
|
||||
ATTR_HEALTHY = "healthy"
|
||||
ATTR_INSTALLATION_TYPE = "installation_type"
|
||||
|
@ -14,8 +14,9 @@ from homeassistant.components.analytics.const import (
|
||||
ATTR_USAGE,
|
||||
)
|
||||
from homeassistant.components.api import ATTR_UUID
|
||||
from homeassistant.const import __version__ as HA_VERSION
|
||||
from homeassistant.const import ATTR_DOMAIN, __version__ as HA_VERSION
|
||||
from homeassistant.loader import IntegrationNotFound
|
||||
from homeassistant.setup import async_setup_component
|
||||
|
||||
MOCK_UUID = "abcdefg"
|
||||
|
||||
@ -319,3 +320,16 @@ async def test_reusing_uuid(hass, aioclient_mock):
|
||||
await analytics.send_analytics()
|
||||
|
||||
assert analytics.uuid == "NOT_MOCK_UUID"
|
||||
|
||||
|
||||
async def test_custom_integrations(hass, aioclient_mock):
|
||||
"""Test sending custom integrations."""
|
||||
aioclient_mock.post(ANALYTICS_ENDPOINT_URL, status=200)
|
||||
analytics = Analytics(hass)
|
||||
assert await async_setup_component(hass, "test_package", {"test_package": {}})
|
||||
await analytics.save_preferences({ATTR_BASE: True, ATTR_USAGE: True})
|
||||
|
||||
await analytics.send_analytics()
|
||||
|
||||
payload = aioclient_mock.mock_calls[0][2]
|
||||
assert payload["custom_integrations"][0][ATTR_DOMAIN] == "test_package"
|
||||
|
Loading…
x
Reference in New Issue
Block a user