From 9b810c64d98db452dd0ed3aaba70873fa050dcc2 Mon Sep 17 00:00:00 2001 From: Klaas Schoute Date: Wed, 25 Feb 2026 00:24:33 +0100 Subject: [PATCH] Add diagnostics support for Powerfox Local integration (#163985) --- .../components/powerfox_local/diagnostics.py | 24 +++++++++++++++ .../powerfox_local/quality_scale.yaml | 2 +- .../snapshots/test_diagnostics.ambr | 10 +++++++ .../powerfox_local/test_diagnostics.py | 30 +++++++++++++++++++ 4 files changed, 65 insertions(+), 1 deletion(-) create mode 100644 homeassistant/components/powerfox_local/diagnostics.py create mode 100644 tests/components/powerfox_local/snapshots/test_diagnostics.ambr create mode 100644 tests/components/powerfox_local/test_diagnostics.py diff --git a/homeassistant/components/powerfox_local/diagnostics.py b/homeassistant/components/powerfox_local/diagnostics.py new file mode 100644 index 00000000000..7cfd196cf5a --- /dev/null +++ b/homeassistant/components/powerfox_local/diagnostics.py @@ -0,0 +1,24 @@ +"""Support for Powerfox Local diagnostics.""" + +from __future__ import annotations + +from typing import Any + +from homeassistant.core import HomeAssistant + +from .coordinator import PowerfoxLocalConfigEntry + + +async def async_get_config_entry_diagnostics( + hass: HomeAssistant, entry: PowerfoxLocalConfigEntry +) -> dict[str, Any]: + """Return diagnostics for Powerfox Local config entry.""" + coordinator = entry.runtime_data + + return { + "power": coordinator.data.power, + "energy_usage": coordinator.data.energy_usage, + "energy_usage_high_tariff": coordinator.data.energy_usage_high_tariff, + "energy_usage_low_tariff": coordinator.data.energy_usage_low_tariff, + "energy_return": coordinator.data.energy_return, + } diff --git a/homeassistant/components/powerfox_local/quality_scale.yaml b/homeassistant/components/powerfox_local/quality_scale.yaml index ce0faf0e787..df71b45d6c7 100644 --- a/homeassistant/components/powerfox_local/quality_scale.yaml +++ b/homeassistant/components/powerfox_local/quality_scale.yaml @@ -48,7 +48,7 @@ rules: # Gold devices: done - diagnostics: todo + diagnostics: done discovery-update-info: done discovery: done docs-data-update: done diff --git a/tests/components/powerfox_local/snapshots/test_diagnostics.ambr b/tests/components/powerfox_local/snapshots/test_diagnostics.ambr new file mode 100644 index 00000000000..6ee874eaaba --- /dev/null +++ b/tests/components/powerfox_local/snapshots/test_diagnostics.ambr @@ -0,0 +1,10 @@ +# serializer version: 1 +# name: test_entry_diagnostics + dict({ + 'energy_return': 111111, + 'energy_usage': 1111111, + 'energy_usage_high_tariff': 111111, + 'energy_usage_low_tariff': 111111, + 'power': 111, + }) +# --- diff --git a/tests/components/powerfox_local/test_diagnostics.py b/tests/components/powerfox_local/test_diagnostics.py new file mode 100644 index 00000000000..c20fe00723c --- /dev/null +++ b/tests/components/powerfox_local/test_diagnostics.py @@ -0,0 +1,30 @@ +"""Test for Powerfox Local diagnostics.""" + +from unittest.mock import AsyncMock + +from syrupy.assertion import SnapshotAssertion + +from homeassistant.core import HomeAssistant + +from . import setup_integration + +from tests.common import MockConfigEntry +from tests.components.diagnostics import get_diagnostics_for_config_entry +from tests.typing import ClientSessionGenerator + + +async def test_entry_diagnostics( + hass: HomeAssistant, + hass_client: ClientSessionGenerator, + mock_powerfox_local_client: AsyncMock, + mock_config_entry: MockConfigEntry, + snapshot: SnapshotAssertion, +) -> None: + """Test the Powerfox Local entry diagnostics.""" + await setup_integration(hass, mock_config_entry) + + result = await get_diagnostics_for_config_entry( + hass, hass_client, mock_config_entry + ) + + assert result == snapshot