mirror of
https://github.com/home-assistant/core.git
synced 2025-04-24 01:08:12 +00:00
Add diagnostics platform to PEGELONLINE (#129279)
add diagnostics platform
This commit is contained in:
parent
bc708dee30
commit
4ac23bf14c
21
homeassistant/components/pegel_online/diagnostics.py
Normal file
21
homeassistant/components/pegel_online/diagnostics.py
Normal 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,
|
||||
}
|
@ -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,
|
||||
}),
|
||||
})
|
||||
# ---
|
44
tests/components/pegel_online/test_diagnostics.py
Normal file
44
tests/components/pegel_online/test_diagnostics.py
Normal 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"))
|
Loading…
x
Reference in New Issue
Block a user