From 19c7f663ca6ee4e5f4ce75dda577805db29ce85d Mon Sep 17 00:00:00 2001 From: konsulten Date: Wed, 25 Feb 2026 18:51:51 +0100 Subject: [PATCH] Add diagnostic to systemnexa2 integration (#164090) --- .../components/systemnexa2/diagnostics.py | 40 +++++++++++++++++++ .../components/systemnexa2/quality_scale.yaml | 2 +- .../snapshots/test_diagnostics.ambr | 33 +++++++++++++++ .../systemnexa2/test_diagnostics.py | 29 ++++++++++++++ 4 files changed, 103 insertions(+), 1 deletion(-) create mode 100644 homeassistant/components/systemnexa2/diagnostics.py create mode 100644 tests/components/systemnexa2/snapshots/test_diagnostics.ambr create mode 100644 tests/components/systemnexa2/test_diagnostics.py diff --git a/homeassistant/components/systemnexa2/diagnostics.py b/homeassistant/components/systemnexa2/diagnostics.py new file mode 100644 index 00000000000..10c1e0d7836 --- /dev/null +++ b/homeassistant/components/systemnexa2/diagnostics.py @@ -0,0 +1,40 @@ +"""Diagnostics support for System Nexa 2.""" + +from __future__ import annotations + +from dataclasses import asdict +from typing import Any + +from homeassistant.components.diagnostics import async_redact_data +from homeassistant.const import CONF_DEVICE_ID, CONF_HOST +from homeassistant.core import HomeAssistant + +from .coordinator import SystemNexa2ConfigEntry + +TO_REDACT = { + CONF_HOST, + CONF_DEVICE_ID, + "unique_id", + "wifi_ssid", +} + + +async def async_get_config_entry_diagnostics( + hass: HomeAssistant, entry: SystemNexa2ConfigEntry +) -> dict[str, Any]: + """Return diagnostics for a config entry.""" + coordinator = entry.runtime_data + + return { + "config_entry": async_redact_data(dict(entry.data), TO_REDACT), + "device_info": async_redact_data(asdict(coordinator.data.info_data), TO_REDACT), + "coordinator_available": coordinator.last_update_success, + "state": coordinator.data.state, + "settings": { + name: { + "name": setting.name, + "enabled": setting.is_enabled(), + } + for name, setting in coordinator.data.on_off_settings.items() + }, + } diff --git a/homeassistant/components/systemnexa2/quality_scale.yaml b/homeassistant/components/systemnexa2/quality_scale.yaml index c70d8ddb971..fbec9bcebe5 100644 --- a/homeassistant/components/systemnexa2/quality_scale.yaml +++ b/homeassistant/components/systemnexa2/quality_scale.yaml @@ -45,7 +45,7 @@ rules: # Gold devices: done - diagnostics: todo + diagnostics: done discovery-update-info: done discovery: done docs-data-update: done diff --git a/tests/components/systemnexa2/snapshots/test_diagnostics.ambr b/tests/components/systemnexa2/snapshots/test_diagnostics.ambr new file mode 100644 index 00000000000..a83c33d1476 --- /dev/null +++ b/tests/components/systemnexa2/snapshots/test_diagnostics.ambr @@ -0,0 +1,33 @@ +# serializer version: 1 +# name: test_diagnostics[False] + dict({ + 'config_entry': dict({ + 'device_id': '**REDACTED**', + 'host': '**REDACTED**', + 'model': 'WPO-01', + 'name': 'Outdoor Smart Plug', + }), + 'coordinator_available': True, + 'device_info': dict({ + 'dimmable': False, + 'hw_version': 'Test HW Version', + 'model': 'WPO-01', + 'name': 'Outdoor Smart Plug', + 'sw_version': 'Test Model Version', + 'unique_id': '**REDACTED**', + 'wifi_dbm': -50, + 'wifi_ssid': '**REDACTED**', + }), + 'settings': dict({ + '433Mhz': dict({ + 'enabled': True, + 'name': '433Mhz', + }), + 'Cloud Access': dict({ + 'enabled': False, + 'name': 'Cloud Access', + }), + }), + 'state': 1.0, + }) +# --- diff --git a/tests/components/systemnexa2/test_diagnostics.py b/tests/components/systemnexa2/test_diagnostics.py new file mode 100644 index 00000000000..70e0b062241 --- /dev/null +++ b/tests/components/systemnexa2/test_diagnostics.py @@ -0,0 +1,29 @@ +"""Test System Nexa 2 diagnostics.""" + +from syrupy.assertion import SnapshotAssertion + +from homeassistant.core import HomeAssistant + +from tests.common import MockConfigEntry +from tests.components.diagnostics import get_diagnostics_for_config_entry +from tests.typing import ClientSessionGenerator + + +async def test_diagnostics( + hass: HomeAssistant, + hass_client: ClientSessionGenerator, + mock_config_entry: MockConfigEntry, + mock_system_nexa_2_device, + snapshot: SnapshotAssertion, +) -> None: + """Test diagnostics for config entry.""" + mock_config_entry.add_to_hass(hass) + + await hass.config_entries.async_setup(mock_config_entry.entry_id) + await hass.async_block_till_done() + + result = await get_diagnostics_for_config_entry( + hass, hass_client, mock_config_entry + ) + + assert result == snapshot