Home Assistant Unofficial Reference 2024.12.1
diagnostics.py
Go to the documentation of this file.
1 """Diagnostics support for AVM FRITZ!Box."""
2 
3 from __future__ import annotations
4 
5 from typing import Any
6 
7 from homeassistant.components.diagnostics import async_redact_data
8 from homeassistant.config_entries import ConfigEntry
9 from homeassistant.const import CONF_PASSWORD, CONF_USERNAME
10 from homeassistant.core import HomeAssistant
11 
12 from .const import DOMAIN
13 from .coordinator import AvmWrapper
14 
15 TO_REDACT = {CONF_USERNAME, CONF_PASSWORD}
16 
17 
19  hass: HomeAssistant, entry: ConfigEntry
20 ) -> dict[str, Any]:
21  """Return diagnostics for a config entry."""
22  avm_wrapper: AvmWrapper = hass.data[DOMAIN][entry.entry_id]
23 
24  return {
25  "entry": async_redact_data(entry.as_dict(), TO_REDACT),
26  "device_info": {
27  "model": avm_wrapper.model,
28  "unique_id": avm_wrapper.unique_id.replace(
29  avm_wrapper.unique_id[6:11], "XX:XX"
30  ),
31  "current_firmware": avm_wrapper.current_firmware,
32  "latest_firmware": avm_wrapper.latest_firmware,
33  "update_available": avm_wrapper.update_available,
34  "connection_type": avm_wrapper.device_conn_type,
35  "is_router": avm_wrapper.device_is_router,
36  "mesh_role": avm_wrapper.mesh_role,
37  "last_update success": avm_wrapper.last_update_success,
38  "last_exception": avm_wrapper.last_exception,
39  "discovered_services": list(avm_wrapper.connection.services),
40  "client_devices": [
41  {
42  "connected_to": device.connected_to,
43  "connection_type": device.connection_type,
44  "hostname": device.hostname,
45  "is_connected": device.is_connected,
46  "last_activity": device.last_activity,
47  "wan_access": device.wan_access,
48  }
49  for _, device in avm_wrapper.devices.items()
50  ],
51  "wan_link_properties": await avm_wrapper.async_get_wan_link_properties(),
52  },
53  }
dict async_redact_data(Mapping data, Iterable[Any] to_redact)
Definition: util.py:14
dict[str, Any] async_get_config_entry_diagnostics(HomeAssistant hass, ConfigEntry entry)
Definition: diagnostics.py:20