From cadfed23488aee2dff5b9ca51b26d2335d6e3735 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=85ke=20Strandberg?= Date: Tue, 11 Nov 2025 18:19:37 +0100 Subject: [PATCH] Add diagnostics to SENZ (#156383) --- homeassistant/components/senz/diagnostics.py | 29 ++++++++++++++ .../senz/snapshots/test_diagnostics.ambr | 40 +++++++++++++++++++ tests/components/senz/test_diagnostics.py | 36 +++++++++++++++++ 3 files changed, 105 insertions(+) create mode 100644 homeassistant/components/senz/diagnostics.py create mode 100644 tests/components/senz/snapshots/test_diagnostics.ambr create mode 100644 tests/components/senz/test_diagnostics.py diff --git a/homeassistant/components/senz/diagnostics.py b/homeassistant/components/senz/diagnostics.py new file mode 100644 index 00000000000..d9b024a3a5d --- /dev/null +++ b/homeassistant/components/senz/diagnostics.py @@ -0,0 +1,29 @@ +"""Diagnostics platform for Senz integration.""" + +from typing import Any + +from homeassistant.components.diagnostics import async_redact_data +from homeassistant.config_entries import ConfigEntry +from homeassistant.core import HomeAssistant + +from .const import DOMAIN + +TO_REDACT = [ + "access_token", + "refresh_token", +] + + +async def async_get_config_entry_diagnostics( + hass: HomeAssistant, entry: ConfigEntry +) -> dict[str, Any]: + """Return diagnostics for a config entry.""" + + raw_data = ( + [device.raw_data for device in hass.data[DOMAIN][entry.entry_id].data.values()], + ) + + return { + "entry_data": async_redact_data(entry.data, TO_REDACT), + "thermostats": raw_data, + } diff --git a/tests/components/senz/snapshots/test_diagnostics.ambr b/tests/components/senz/snapshots/test_diagnostics.ambr new file mode 100644 index 00000000000..2c925fbc317 --- /dev/null +++ b/tests/components/senz/snapshots/test_diagnostics.ambr @@ -0,0 +1,40 @@ +# serializer version: 1 +# name: test_diagnostics_config_entry + dict({ + 'entry_data': dict({ + 'auth_implementation': 'senz', + 'token': dict({ + 'access_token': '**REDACTED**', + 'expires_in': 86399, + 'refresh_token': '**REDACTED**', + 'token_type': 'Bearer', + }), + }), + 'thermostats': list([ + list([ + dict({ + 'currentTemperature': 1845, + 'errorState': None, + 'holdUntil': None, + 'isHeating': True, + 'mode': 5, + 'name': 'Test room 1', + 'online': True, + 'serialNumber': '1001', + 'setPointTemperature': 1900, + }), + dict({ + 'currentTemperature': 930, + 'errorState': None, + 'holdUntil': None, + 'isHeating': False, + 'mode': 1, + 'name': 'Test room 2', + 'online': True, + 'serialNumber': '1002', + 'setPointTemperature': 600, + }), + ]), + ]), + }) +# --- diff --git a/tests/components/senz/test_diagnostics.py b/tests/components/senz/test_diagnostics.py new file mode 100644 index 00000000000..d66ee175446 --- /dev/null +++ b/tests/components/senz/test_diagnostics.py @@ -0,0 +1,36 @@ +"""Tests for the diagnostics data provided by the senz integration.""" + +from collections.abc import Generator +from unittest.mock import MagicMock + +from syrupy.assertion import SnapshotAssertion +from syrupy.filters import paths + +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_diagnostics_config_entry( + hass: HomeAssistant, + hass_client: ClientSessionGenerator, + mock_senz_client: Generator[MagicMock], + mock_config_entry: MockConfigEntry, + snapshot: SnapshotAssertion, +) -> None: + """Test diagnostics for config entry.""" + + await setup_integration(hass, mock_config_entry) + result = await get_diagnostics_for_config_entry( + hass, hass_client, mock_config_entry + ) + + assert result == snapshot( + exclude=paths( + "entry_data.token.expires_at", + ) + )