mirror of
https://github.com/home-assistant/core.git
synced 2026-02-15 07:36:16 +00:00
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>
This commit is contained in:
34
homeassistant/components/liebherr/diagnostics.py
Normal file
34
homeassistant/components/liebherr/diagnostics.py
Normal file
@@ -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()
|
||||
},
|
||||
}
|
||||
@@ -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.
|
||||
|
||||
47
tests/components/liebherr/snapshots/test_diagnostics.ambr
Normal file
47
tests/components/liebherr/snapshots/test_diagnostics.ambr
Normal file
@@ -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',
|
||||
}),
|
||||
}),
|
||||
}),
|
||||
}),
|
||||
})
|
||||
# ---
|
||||
25
tests/components/liebherr/test_diagnostics.py
Normal file
25
tests/components/liebherr/test_diagnostics.py
Normal file
@@ -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
|
||||
)
|
||||
Reference in New Issue
Block a user