Home Assistant Unofficial Reference 2024.12.1
diagnostics.py
Go to the documentation of this file.
1 """Diagnostics support for IKEA Tradfri."""
2 
3 from __future__ import annotations
4 
5 from typing import Any, cast
6 
7 from homeassistant.config_entries import ConfigEntry
8 from homeassistant.core import HomeAssistant
9 from homeassistant.helpers import device_registry as dr
10 
11 from .const import CONF_GATEWAY_ID, COORDINATOR, COORDINATOR_LIST, DOMAIN
12 
13 
15  hass: HomeAssistant, entry: ConfigEntry
16 ) -> dict[str, Any]:
17  """Return diagnostics the Tradfri platform."""
18  entry_data = hass.data[DOMAIN][entry.entry_id]
19  coordinator_data = entry_data[COORDINATOR]
20 
21  device_registry = dr.async_get(hass)
22  device = cast(
23  dr.DeviceEntry,
24  device_registry.async_get_device(
25  identifiers={(DOMAIN, entry.data[CONF_GATEWAY_ID])}
26  ),
27  )
28 
29  device_data: list = [
30  coordinator.device.device_info.model_number
31  for coordinator in coordinator_data[COORDINATOR_LIST]
32  ]
33 
34  return {
35  "gateway_version": device.sw_version,
36  "device_data": sorted(device_data),
37  }
dict[str, Any] async_get_config_entry_diagnostics(HomeAssistant hass, ConfigEntry entry)
Definition: diagnostics.py:16