Add OS version and board type to analytics (#49725)

This commit is contained in:
Joakim Sørensen 2021-04-28 19:13:09 +02:00 committed by GitHub
parent 311e0e4185
commit 296dc9303f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 23 additions and 1 deletions

View File

@ -24,12 +24,14 @@ from .const import (
ATTR_AUTO_UPDATE,
ATTR_AUTOMATION_COUNT,
ATTR_BASE,
ATTR_BOARD,
ATTR_CUSTOM_INTEGRATIONS,
ATTR_DIAGNOSTICS,
ATTR_HEALTHY,
ATTR_INTEGRATION_COUNT,
ATTR_INTEGRATIONS,
ATTR_ONBOARDED,
ATTR_OPERATING_SYSTEM,
ATTR_PREFERENCES,
ATTR_PROTECTED,
ATTR_SLUG,
@ -127,6 +129,7 @@ class Analytics:
async def send_analytics(self, _=None) -> None:
"""Send analytics."""
supervisor_info = None
operating_system_info = {}
if not self.onboarded or not self.preferences.get(ATTR_BASE, False):
LOGGER.debug("Nothing to submit")
@ -138,6 +141,7 @@ class Analytics:
if self.supervisor:
supervisor_info = hassio.get_supervisor_info(self.hass)
operating_system_info = hassio.get_os_info(self.hass)
system_info = await async_get_system_info(self.hass)
integrations = []
@ -155,6 +159,12 @@ class Analytics:
ATTR_SUPPORTED: supervisor_info[ATTR_SUPPORTED],
}
if operating_system_info.get(ATTR_BOARD) is not None:
payload[ATTR_OPERATING_SYSTEM] = {
ATTR_BOARD: operating_system_info[ATTR_BOARD],
ATTR_VERSION: operating_system_info[ATTR_VERSION],
}
if self.preferences.get(ATTR_USAGE, False) or self.preferences.get(
ATTR_STATISTICS, False
):

View File

@ -19,6 +19,7 @@ ATTR_ADDONS = "addons"
ATTR_AUTO_UPDATE = "auto_update"
ATTR_AUTOMATION_COUNT = "automation_count"
ATTR_BASE = "base"
ATTR_BOARD = "board"
ATTR_CUSTOM_INTEGRATIONS = "custom_integrations"
ATTR_DIAGNOSTICS = "diagnostics"
ATTR_HEALTHY = "healthy"
@ -26,6 +27,7 @@ ATTR_INSTALLATION_TYPE = "installation_type"
ATTR_INTEGRATION_COUNT = "integration_count"
ATTR_INTEGRATIONS = "integrations"
ATTR_ONBOARDED = "onboarded"
ATTR_OPERATING_SYSTEM = "operating_system"
ATTR_PREFERENCES = "preferences"
ATTR_PROTECTED = "protected"
ATTR_SLUG = "slug"

View File

@ -133,6 +133,9 @@ async def test_send_base_with_supervisor(hass, caplog, aioclient_mock):
with patch(
"homeassistant.components.hassio.get_supervisor_info",
side_effect=Mock(return_value={"supported": True, "healthy": True}),
), patch(
"homeassistant.components.hassio.get_os_info",
side_effect=Mock(return_value={"board": "blue", "version": "123"}),
), patch(
"homeassistant.components.hassio.get_info",
side_effect=Mock(return_value={}),
@ -154,7 +157,8 @@ async def test_send_base_with_supervisor(hass, caplog, aioclient_mock):
assert f"'uuid': '{MOCK_UUID}'" in caplog.text
assert f"'version': '{MOCK_VERSION}'" in caplog.text
assert "'supervisor': {'healthy': True, 'supported': True}}" in caplog.text
assert "'supervisor': {'healthy': True, 'supported': True}" in caplog.text
assert "'operating_system': {'board': 'blue', 'version': '123'}" in caplog.text
assert "'installation_type':" in caplog.text
assert "'integration_count':" not in caplog.text
assert "'integrations':" not in caplog.text
@ -196,6 +200,9 @@ async def test_send_usage_with_supervisor(hass, caplog, aioclient_mock):
"addons": [{"slug": "test_addon"}],
}
),
), patch(
"homeassistant.components.hassio.get_os_info",
side_effect=Mock(return_value={}),
), patch(
"homeassistant.components.hassio.get_info",
side_effect=Mock(return_value={}),
@ -299,6 +306,9 @@ async def test_send_statistics_with_supervisor(hass, caplog, aioclient_mock):
"addons": [{"slug": "test_addon"}],
}
),
), patch(
"homeassistant.components.hassio.get_os_info",
side_effect=Mock(return_value={}),
), patch(
"homeassistant.components.hassio.get_info",
side_effect=Mock(return_value={}),