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
10 changes: 10 additions & 0 deletions homeassistant/components/analytics/analytics.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,14 @@
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,
Expand Down Expand Up @@ -127,6 +129,7 @@ async def save_preferences(self, preferences: dict) -> None:
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")
Expand All @@ -138,6 +141,7 @@ async def send_analytics(self, _=None) -> None:

if self.supervisor:
supervisor_info = hassio.get_supervisor_info(self.hass)
operating_system_info = hassio.get_os_info(self.hass)
Comment thread
MartinHjelmare marked this conversation as resolved.

system_info = await async_get_system_info(self.hass)
integrations = []
Expand All @@ -155,6 +159,12 @@ async def send_analytics(self, _=None) -> None:
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
):
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 @@ -19,13 +19,15 @@
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"
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"
Expand Down
12 changes: 11 additions & 1 deletion tests/components/analytics/test_analytics.py
Original file line number Diff line number Diff line change
Expand Up @@ -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={}),
Expand All @@ -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
Expand Down Expand Up @@ -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={}),
Expand Down Expand Up @@ -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={}),
Expand Down