Add diagnostics to deCONZ integration (#64585)
This commit is contained in:
parent
3d99e23399
commit
11de453848
2 changed files with 93 additions and 0 deletions
39
homeassistant/components/deconz/diagnostics.py
Normal file
39
homeassistant/components/deconz/diagnostics.py
Normal file
|
@ -0,0 +1,39 @@
|
|||
"""Diagnostics support for deCONZ."""
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Any
|
||||
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.system_info import async_get_system_info
|
||||
|
||||
from .gateway import get_gateway_from_config_entry
|
||||
|
||||
|
||||
async def async_get_config_entry_diagnostics(
|
||||
hass: HomeAssistant, config_entry: ConfigEntry
|
||||
) -> dict[str, Any]:
|
||||
"""Return diagnostics for a config entry."""
|
||||
gateway = get_gateway_from_config_entry(hass, config_entry)
|
||||
diag: dict[str, Any] = {}
|
||||
|
||||
diag["home_assistant"] = await async_get_system_info(hass)
|
||||
diag["config_entry"] = dict(config_entry.data)
|
||||
diag["deconz_config"] = gateway.api.config.raw
|
||||
diag["websocket_state"] = gateway.api.websocket.state
|
||||
diag["deconz_ids"] = gateway.deconz_ids
|
||||
diag["entities"] = gateway.entities
|
||||
diag["events"] = {
|
||||
event.serial: {
|
||||
"event_id": event.event_id,
|
||||
"event_type": type(event).__name__,
|
||||
}
|
||||
for event in gateway.events
|
||||
}
|
||||
diag["alarm_systems"] = {k: v.raw for k, v in gateway.api.alarmsystems.items()}
|
||||
diag["groups"] = {k: v.raw for k, v in gateway.api.groups.items()}
|
||||
diag["lights"] = {k: v.raw for k, v in gateway.api.lights.items()}
|
||||
diag["scenes"] = {k: v.raw for k, v in gateway.api.scenes.items()}
|
||||
diag["sensors"] = {k: v.raw for k, v in gateway.api.sensors.items()}
|
||||
|
||||
return diag
|
54
tests/components/deconz/test_diagnostics.py
Normal file
54
tests/components/deconz/test_diagnostics.py
Normal file
|
@ -0,0 +1,54 @@
|
|||
"""Test deCONZ diagnostics."""
|
||||
|
||||
from unittest.mock import patch
|
||||
|
||||
from pydeconz.websocket import STATE_RUNNING
|
||||
|
||||
from homeassistant.const import Platform
|
||||
|
||||
from .test_gateway import DECONZ_CONFIG, setup_deconz_integration
|
||||
|
||||
from tests.components.diagnostics import get_diagnostics_for_config_entry
|
||||
|
||||
|
||||
async def test_entry_diagnostics(
|
||||
hass, hass_client, aioclient_mock, mock_deconz_websocket
|
||||
):
|
||||
"""Test config entry diagnostics."""
|
||||
config_entry = await setup_deconz_integration(hass, aioclient_mock)
|
||||
|
||||
await mock_deconz_websocket(state=STATE_RUNNING)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
with patch(
|
||||
"homeassistant.helpers.system_info.async_get_system_info",
|
||||
return_value={"get_system_info": "fake data"},
|
||||
):
|
||||
assert await get_diagnostics_for_config_entry(
|
||||
hass, hass_client, config_entry
|
||||
) == {
|
||||
"home_assistant": {"get_system_info": "fake data"},
|
||||
"config_entry": dict(config_entry.data),
|
||||
"deconz_config": DECONZ_CONFIG,
|
||||
"websocket_state": STATE_RUNNING,
|
||||
"deconz_ids": {},
|
||||
"entities": {
|
||||
str(Platform.ALARM_CONTROL_PANEL): [],
|
||||
str(Platform.BINARY_SENSOR): [],
|
||||
str(Platform.CLIMATE): [],
|
||||
str(Platform.COVER): [],
|
||||
str(Platform.FAN): [],
|
||||
str(Platform.LIGHT): [],
|
||||
str(Platform.LOCK): [],
|
||||
str(Platform.NUMBER): [],
|
||||
str(Platform.SENSOR): [],
|
||||
str(Platform.SIREN): [],
|
||||
str(Platform.SWITCH): [],
|
||||
},
|
||||
"events": {},
|
||||
"alarm_systems": {},
|
||||
"groups": {},
|
||||
"lights": {},
|
||||
"scenes": {},
|
||||
"sensors": {},
|
||||
}
|
Loading…
Add table
Reference in a new issue