Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions homeassistant/components/analytics/analytics.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
DOMAIN as ENERGY_DOMAIN,
is_configured as energy_is_configured,
)
from homeassistant.components.recorder import (
DOMAIN as RECORDER_DOMAIN,
get_instance as get_recorder_instance,
)
from homeassistant.const import ATTR_DOMAIN, __version__ as HA_VERSION
from homeassistant.core import HomeAssistant
from homeassistant.helpers.aiohttp_client import async_get_clientsession
Expand All @@ -40,11 +44,13 @@
ATTR_CUSTOM_INTEGRATIONS,
ATTR_DIAGNOSTICS,
ATTR_ENERGY,
ATTR_ENGINE,
ATTR_HEALTHY,
ATTR_INTEGRATION_COUNT,
ATTR_INTEGRATIONS,
ATTR_OPERATING_SYSTEM,
ATTR_PROTECTED,
ATTR_RECORDER,
ATTR_SLUG,
ATTR_STATE_COUNT,
ATTR_STATISTICS,
Expand Down Expand Up @@ -252,6 +258,15 @@ async def send_analytics(self, _: datetime | None = None) -> None:
ATTR_CONFIGURED: await energy_is_configured(self.hass)
}

if RECORDER_DOMAIN in integrations:
instance = get_recorder_instance(self.hass)
engine = instance.database_engine
if engine and engine.version is not None:
payload[ATTR_RECORDER] = {
ATTR_ENGINE: engine.dialect.value,
ATTR_VERSION: engine.version,
}

if self.preferences.get(ATTR_STATISTICS, False):
payload[ATTR_STATE_COUNT] = len(self.hass.states.async_all())
payload[ATTR_AUTOMATION_COUNT] = len(
Expand Down
2 changes: 2 additions & 0 deletions homeassistant/components/analytics/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
ATTR_CUSTOM_INTEGRATIONS = "custom_integrations"
ATTR_DIAGNOSTICS = "diagnostics"
ATTR_ENERGY = "energy"
ATTR_ENGINE = "engine"
ATTR_HEALTHY = "healthy"
ATTR_INSTALLATION_TYPE = "installation_type"
ATTR_INTEGRATION_COUNT = "integration_count"
Expand All @@ -34,6 +35,7 @@
ATTR_OPERATING_SYSTEM = "operating_system"
ATTR_PREFERENCES = "preferences"
ATTR_PROTECTED = "protected"
ATTR_RECORDER = "recorder"
ATTR_SLUG = "slug"
ATTR_STATE_COUNT = "state_count"
ATTR_STATISTICS = "statistics"
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/analytics/manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"domain": "analytics",
"name": "Analytics",
"after_dependencies": ["energy"],
"after_dependencies": ["energy", "recorder"],
"codeowners": ["@home-assistant/core", "@ludeeus"],
"dependencies": ["api", "websocket_api"],
"documentation": "https://www.home-assistant.io/integrations/analytics",
Expand Down
19 changes: 19 additions & 0 deletions tests/components/analytics/test_analytics.py
Original file line number Diff line number Diff line change
Expand Up @@ -576,3 +576,22 @@ async def test_send_usage_with_certificate(
await analytics.send_analytics()

assert "'certificate': True" in caplog.text


async def test_send_with_recorder(
recorder_mock: AsyncMock,
hass: HomeAssistant,
aioclient_mock: AiohttpClientMocker,
) -> None:
"""Test recorder information."""
aioclient_mock.post(ANALYTICS_ENDPOINT_URL, status=200)
analytics = Analytics(hass)
hass.http = Mock(ssl_certificate="/some/path/to/cert.pem")

await analytics.save_preferences({ATTR_BASE: True, ATTR_USAGE: True})

with patch("homeassistant.components.analytics.analytics.HA_VERSION", MOCK_VERSION):
await analytics.send_analytics()

postdata = aioclient_mock.mock_calls[-1][2]
assert postdata["recorder"]["engine"] == "sqlite"