mirror of
https://github.com/home-assistant/core.git
synced 2025-07-16 17:57:11 +00:00
Add diagnostics for Tradfri platform (#66092)
Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
This commit is contained in:
parent
86ab500afd
commit
f8a84f0101
36
homeassistant/components/tradfri/diagnostics.py
Normal file
36
homeassistant/components/tradfri/diagnostics.py
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
"""Diagnostics support for IKEA Tradfri."""
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from typing import cast
|
||||||
|
|
||||||
|
from homeassistant.config_entries import ConfigEntry
|
||||||
|
from homeassistant.core import HomeAssistant
|
||||||
|
from homeassistant.helpers import device_registry as dr
|
||||||
|
|
||||||
|
from .const import CONF_GATEWAY_ID, COORDINATOR, COORDINATOR_LIST, DOMAIN, GROUPS_LIST
|
||||||
|
|
||||||
|
|
||||||
|
async def async_get_config_entry_diagnostics(
|
||||||
|
hass: HomeAssistant, entry: ConfigEntry
|
||||||
|
) -> dict:
|
||||||
|
"""Return diagnostics the Tradfri platform."""
|
||||||
|
entry_data = hass.data[DOMAIN][entry.entry_id]
|
||||||
|
coordinator_data = entry_data[COORDINATOR]
|
||||||
|
|
||||||
|
device_registry = dr.async_get(hass)
|
||||||
|
device = cast(
|
||||||
|
dr.DeviceEntry,
|
||||||
|
device_registry.async_get_device(
|
||||||
|
identifiers={(DOMAIN, entry.data[CONF_GATEWAY_ID])}
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
|
device_data: list = []
|
||||||
|
for coordinator in coordinator_data[COORDINATOR_LIST]:
|
||||||
|
device_data.append(coordinator.device.device_info.model_number)
|
||||||
|
|
||||||
|
return {
|
||||||
|
"gateway_version": device.sw_version,
|
||||||
|
"device_data": sorted(device_data),
|
||||||
|
"no_of_groups": len(coordinator_data[GROUPS_LIST]),
|
||||||
|
}
|
45
tests/components/tradfri/test_diagnostics.py
Normal file
45
tests/components/tradfri/test_diagnostics.py
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
"""Tests for Tradfri diagnostics."""
|
||||||
|
from unittest.mock import MagicMock, Mock
|
||||||
|
|
||||||
|
from aiohttp import ClientSession
|
||||||
|
|
||||||
|
from homeassistant.core import HomeAssistant
|
||||||
|
|
||||||
|
from .common import setup_integration
|
||||||
|
from .test_fan import mock_fan
|
||||||
|
from .test_light import mock_group
|
||||||
|
|
||||||
|
from tests.components.diagnostics import get_diagnostics_for_config_entry
|
||||||
|
|
||||||
|
|
||||||
|
async def test_diagnostics(
|
||||||
|
hass: HomeAssistant,
|
||||||
|
hass_client: ClientSession,
|
||||||
|
mock_gateway: Mock,
|
||||||
|
mock_api_factory: MagicMock,
|
||||||
|
) -> None:
|
||||||
|
"""Test diagnostics for config entry."""
|
||||||
|
mock_gateway.mock_devices.append(
|
||||||
|
# Add a fan
|
||||||
|
mock_fan(
|
||||||
|
test_state={
|
||||||
|
"fan_speed": 10,
|
||||||
|
"air_quality": 42,
|
||||||
|
"filter_lifetime_remaining": 120,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
mock_gateway.mock_groups.append(
|
||||||
|
# Add a group
|
||||||
|
mock_group(test_state={"state": True, "dimmer": 100})
|
||||||
|
)
|
||||||
|
|
||||||
|
init_integration = await setup_integration(hass)
|
||||||
|
|
||||||
|
result = await get_diagnostics_for_config_entry(hass, hass_client, init_integration)
|
||||||
|
|
||||||
|
assert isinstance(result, dict)
|
||||||
|
assert result["gateway_version"] == "1.2.1234"
|
||||||
|
assert len(result["device_data"]) == 1
|
||||||
|
assert result["no_of_groups"] == 1
|
Loading…
x
Reference in New Issue
Block a user