From 3e44d15fc18d56a58f5b1e529191abb71ab52d4b Mon Sep 17 00:00:00 2001 From: mettolen <1007649+mettolen@users.noreply.github.com> Date: Sun, 8 Feb 2026 23:52:56 +0200 Subject: [PATCH] Add diagnostics to Liebherr integration (#162360) Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: epenet <6771947+epenet@users.noreply.github.com> --- .../components/liebherr/diagnostics.py | 34 ++++++++++++++ .../components/liebherr/quality_scale.yaml | 2 +- .../liebherr/snapshots/test_diagnostics.ambr | 47 +++++++++++++++++++ tests/components/liebherr/test_diagnostics.py | 25 ++++++++++ 4 files changed, 107 insertions(+), 1 deletion(-) create mode 100644 homeassistant/components/liebherr/diagnostics.py create mode 100644 tests/components/liebherr/snapshots/test_diagnostics.ambr create mode 100644 tests/components/liebherr/test_diagnostics.py diff --git a/homeassistant/components/liebherr/diagnostics.py b/homeassistant/components/liebherr/diagnostics.py new file mode 100644 index 00000000000..21e6ab7af4c --- /dev/null +++ b/homeassistant/components/liebherr/diagnostics.py @@ -0,0 +1,34 @@ +"""Diagnostics support for Liebherr.""" + +from __future__ import annotations + +from dataclasses import asdict +from typing import Any + +from homeassistant.const import CONF_API_KEY +from homeassistant.core import HomeAssistant + +from .coordinator import LiebherrConfigEntry + +TO_REDACT = {CONF_API_KEY} + + +async def async_get_config_entry_diagnostics( + hass: HomeAssistant, entry: LiebherrConfigEntry +) -> dict[str, Any]: + """Return diagnostics for a config entry.""" + return { + "devices": { + device_id: { + "coordinator": { + "last_update_success": coordinator.last_update_success, + "update_interval": str(coordinator.update_interval), + "last_exception": str(coordinator.last_exception) + if coordinator.last_exception + else None, + }, + "data": asdict(coordinator.data), + } + for device_id, coordinator in entry.runtime_data.items() + }, + } diff --git a/homeassistant/components/liebherr/quality_scale.yaml b/homeassistant/components/liebherr/quality_scale.yaml index 24a4d938f6f..25b6bd26116 100644 --- a/homeassistant/components/liebherr/quality_scale.yaml +++ b/homeassistant/components/liebherr/quality_scale.yaml @@ -41,7 +41,7 @@ rules: # Gold devices: done - diagnostics: todo + diagnostics: done discovery-update-info: status: exempt comment: Cloud API does not require updating entry data from network discovery. diff --git a/tests/components/liebherr/snapshots/test_diagnostics.ambr b/tests/components/liebherr/snapshots/test_diagnostics.ambr new file mode 100644 index 00000000000..54db49bd365 --- /dev/null +++ b/tests/components/liebherr/snapshots/test_diagnostics.ambr @@ -0,0 +1,47 @@ +# serializer version: 1 +# name: test_diagnostics + dict({ + 'devices': dict({ + 'test_device_id': dict({ + 'coordinator': dict({ + 'last_exception': None, + 'last_update_success': True, + 'update_interval': '0:01:00', + }), + 'data': dict({ + 'controls': list([ + dict({ + 'max': 8, + 'min': 2, + 'name': 'Fridge', + 'target': 4, + 'type': 'fridge', + 'unit': '°C', + 'value': 5, + 'zone_id': 1, + 'zone_position': 'top', + }), + dict({ + 'max': -16, + 'min': -24, + 'name': 'Freezer', + 'target': -18, + 'type': 'freezer', + 'unit': '°C', + 'value': -18, + 'zone_id': 2, + 'zone_position': 'bottom', + }), + ]), + 'device': dict({ + 'device_id': 'test_device_id', + 'device_name': 'CBNes1234', + 'device_type': 'COMBI', + 'image_url': None, + 'nickname': 'Test Fridge', + }), + }), + }), + }), + }) +# --- diff --git a/tests/components/liebherr/test_diagnostics.py b/tests/components/liebherr/test_diagnostics.py new file mode 100644 index 00000000000..2f4a4b568b1 --- /dev/null +++ b/tests/components/liebherr/test_diagnostics.py @@ -0,0 +1,25 @@ +"""Tests for the diagnostics data provided by the Liebherr integration.""" + +from unittest.mock import MagicMock + +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_liebherr_client: MagicMock, + init_integration: MockConfigEntry, + snapshot: SnapshotAssertion, +) -> None: + """Test diagnostics.""" + assert ( + await get_diagnostics_for_config_entry(hass, hass_client, init_integration) + == snapshot + )