diff --git a/homeassistant/components/analytics/analytics.py b/homeassistant/components/analytics/analytics.py index 178faf7ccca..9419f00e41e 100644 --- a/homeassistant/components/analytics/analytics.py +++ b/homeassistant/components/analytics/analytics.py @@ -17,6 +17,10 @@ from homeassistant.components.energy import ( 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 @@ -40,11 +44,13 @@ from .const import ( 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, @@ -252,6 +258,15 @@ class Analytics: 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( diff --git a/homeassistant/components/analytics/const.py b/homeassistant/components/analytics/const.py index 63fdf820923..fd253c32f93 100644 --- a/homeassistant/components/analytics/const.py +++ b/homeassistant/components/analytics/const.py @@ -26,6 +26,7 @@ ATTR_CONFIGURED = "configured" 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" @@ -34,6 +35,7 @@ ATTR_ONBOARDED = "onboarded" 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" diff --git a/homeassistant/components/analytics/manifest.json b/homeassistant/components/analytics/manifest.json index b14647680a4..955c4a813f4 100644 --- a/homeassistant/components/analytics/manifest.json +++ b/homeassistant/components/analytics/manifest.json @@ -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", diff --git a/tests/components/analytics/test_analytics.py b/tests/components/analytics/test_analytics.py index a2faa198b4e..bc2c1bad483 100644 --- a/tests/components/analytics/test_analytics.py +++ b/tests/components/analytics/test_analytics.py @@ -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"