From 5d1b78a29d1c9e91b4db132dbcfa18a1d840f184 Mon Sep 17 00:00:00 2001 From: "David F. Mulcahey" Date: Tue, 27 Feb 2024 06:44:26 -0500 Subject: [PATCH] Add device list to ZHA config entry diagnostics (#111549) * Add device list to ZHA config entry diagnostics * add logical type --- homeassistant/components/zha/diagnostics.py | 12 +++++++++++- tests/components/zha/test_diagnostics.py | 16 ++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/homeassistant/components/zha/diagnostics.py b/homeassistant/components/zha/diagnostics.py index ae68e6d5cca..57088818c66 100644 --- a/homeassistant/components/zha/diagnostics.py +++ b/homeassistant/components/zha/diagnostics.py @@ -28,6 +28,7 @@ from .core.const import ( UNKNOWN, ) from .core.device import ZHADevice +from .core.gateway import ZHAGateway from .core.helpers import async_get_zha_device, get_zha_data, get_zha_gateway KEYS_TO_REDACT = { @@ -63,7 +64,8 @@ async def async_get_config_entry_diagnostics( ) -> dict[str, Any]: """Return diagnostics for a config entry.""" zha_data = get_zha_data(hass) - app = get_zha_gateway(hass).application_controller + gateway: ZHAGateway = get_zha_gateway(hass) + app = gateway.application_controller energy_scan = await app.energy_scan( channels=Channels.ALL_CHANNELS, duration_exp=4, count=1 @@ -86,6 +88,14 @@ async def async_get_config_entry_diagnostics( "zigpy_zigate": version("zigpy-zigate"), "zhaquirks": version("zha-quirks"), }, + "devices": [ + { + "manufacturer": device.manufacturer, + "model": device.model, + "logical_type": device.device_type, + } + for device in gateway.devices.values() + ], }, KEYS_TO_REDACT, ) diff --git a/tests/components/zha/test_diagnostics.py b/tests/components/zha/test_diagnostics.py index 1f6a731d0fb..c91d9c1ddbc 100644 --- a/tests/components/zha/test_diagnostics.py +++ b/tests/components/zha/test_diagnostics.py @@ -27,6 +27,7 @@ CONFIG_ENTRY_DIAGNOSTICS_KEYS = [ "config_entry", "application_state", "versions", + "devices", ] @@ -83,6 +84,21 @@ async def test_diagnostics_for_config_entry( str(k): 100 * v / 255 for k, v in scan.items() } + assert isinstance(diagnostics_data["devices"], list) + assert len(diagnostics_data["devices"]) == 2 + assert diagnostics_data["devices"] == [ + { + "manufacturer": "Coordinator Manufacturer", + "model": "Coordinator Model", + "logical_type": "Coordinator", + }, + { + "manufacturer": "FakeManufacturer", + "model": "FakeModel", + "logical_type": "EndDevice", + }, + ] + async def test_diagnostics_for_device( hass: HomeAssistant,