Add diagnostics platform to PEGELONLINE (#129279)

add diagnostics platform
This commit is contained in:
Michael 2024-10-27 20:36:56 +01:00 committed by GitHub
parent bc708dee30
commit 4ac23bf14c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 104 additions and 0 deletions

View File

@ -0,0 +1,21 @@
"""Diagnostics support for pegel_online."""
from __future__ import annotations
from typing import Any
from homeassistant.core import HomeAssistant
from . import PegelOnlineConfigEntry
async def async_get_config_entry_diagnostics(
hass: HomeAssistant, entry: PegelOnlineConfigEntry
) -> dict[str, Any]:
"""Return diagnostics for a config entry."""
coordinator = entry.runtime_data
return {
"entry": entry.as_dict(),
"data": coordinator.data,
}

View File

@ -0,0 +1,39 @@
# serializer version: 1
# name: test_entry_diagnostics
dict({
'data': dict({
'air_temperature': None,
'clearance_height': None,
'oxygen_level': None,
'ph_value': None,
'water_flow': dict({
'uom': 'm³/s',
'value': 88.4,
}),
'water_level': dict({
'uom': 'cm',
'value': 62,
}),
'water_speed': None,
'water_temperature': None,
}),
'entry': dict({
'data': dict({
'station': '70272185-xxxx-xxxx-xxxx-43bea330dcae',
}),
'disabled_by': None,
'discovery_keys': dict({
}),
'domain': 'pegel_online',
'minor_version': 1,
'options': dict({
}),
'pref_disable_new_entities': False,
'pref_disable_polling': False,
'source': 'user',
'title': 'Mock Title',
'unique_id': '70272185-xxxx-xxxx-xxxx-43bea330dcae',
'version': 1,
}),
})
# ---

View File

@ -0,0 +1,44 @@
"""Test pegel_online diagnostics."""
from unittest.mock import patch
from syrupy import SnapshotAssertion
from syrupy.filters import props
from homeassistant.components.pegel_online.const import CONF_STATION, DOMAIN
from homeassistant.core import HomeAssistant
from . import PegelOnlineMock
from .const import (
MOCK_CONFIG_ENTRY_DATA_DRESDEN,
MOCK_STATION_DETAILS_DRESDEN,
MOCK_STATION_MEASUREMENT_DRESDEN,
)
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,
snapshot: SnapshotAssertion,
) -> None:
"""Test config entry diagnostics."""
entry = MockConfigEntry(
domain=DOMAIN,
data=MOCK_CONFIG_ENTRY_DATA_DRESDEN,
unique_id=MOCK_CONFIG_ENTRY_DATA_DRESDEN[CONF_STATION],
)
entry.add_to_hass(hass)
with patch("homeassistant.components.pegel_online.PegelOnline") as pegelonline:
pegelonline.return_value = PegelOnlineMock(
station_details=MOCK_STATION_DETAILS_DRESDEN,
station_measurements=MOCK_STATION_MEASUREMENT_DRESDEN,
)
assert await hass.config_entries.async_setup(entry.entry_id)
await hass.async_block_till_done()
result = await get_diagnostics_for_config_entry(hass, hass_client, entry)
assert result == snapshot(exclude=props("entry_id", "created_at", "modified_at"))