mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 11:17:21 +00:00
Add diagnostics platform to IMGW-PIB integration (#116551)
* Add diagnostics * Add tests --------- Co-authored-by: Maciej Bieniek <478555+bieniu@users.noreply.github.com>
This commit is contained in:
parent
c5cac8fed4
commit
ae6a497cd1
22
homeassistant/components/imgw_pib/diagnostics.py
Normal file
22
homeassistant/components/imgw_pib/diagnostics.py
Normal file
@ -0,0 +1,22 @@
|
||||
"""Diagnostics support for IMGW-PIB."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from dataclasses import asdict
|
||||
from typing import Any
|
||||
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
from . import ImgwPibConfigEntry
|
||||
|
||||
|
||||
async def async_get_config_entry_diagnostics(
|
||||
hass: HomeAssistant, entry: ImgwPibConfigEntry
|
||||
) -> dict[str, Any]:
|
||||
"""Return diagnostics for a config entry."""
|
||||
coordinator = entry.runtime_data.coordinator
|
||||
|
||||
return {
|
||||
"config_entry_data": entry.as_dict(),
|
||||
"hydrological_data": asdict(coordinator.data),
|
||||
}
|
50
tests/components/imgw_pib/snapshots/test_diagnostics.ambr
Normal file
50
tests/components/imgw_pib/snapshots/test_diagnostics.ambr
Normal file
@ -0,0 +1,50 @@
|
||||
# serializer version: 1
|
||||
# name: test_entry_diagnostics
|
||||
dict({
|
||||
'config_entry_data': dict({
|
||||
'data': dict({
|
||||
'station_id': '123',
|
||||
}),
|
||||
'disabled_by': None,
|
||||
'domain': 'imgw_pib',
|
||||
'minor_version': 1,
|
||||
'options': dict({
|
||||
}),
|
||||
'pref_disable_new_entities': False,
|
||||
'pref_disable_polling': False,
|
||||
'source': 'user',
|
||||
'title': 'River Name (Station Name)',
|
||||
'unique_id': '123',
|
||||
'version': 1,
|
||||
}),
|
||||
'hydrological_data': dict({
|
||||
'flood_alarm': False,
|
||||
'flood_alarm_level': dict({
|
||||
'name': 'Flood Alarm Level',
|
||||
'unit': None,
|
||||
'value': 630.0,
|
||||
}),
|
||||
'flood_warning': False,
|
||||
'flood_warning_level': dict({
|
||||
'name': 'Flood Warning Level',
|
||||
'unit': None,
|
||||
'value': 590.0,
|
||||
}),
|
||||
'river': 'River Name',
|
||||
'station': 'Station Name',
|
||||
'station_id': '123',
|
||||
'water_level': dict({
|
||||
'name': 'Water Level',
|
||||
'unit': None,
|
||||
'value': 526.0,
|
||||
}),
|
||||
'water_level_measurement_date': '2024-04-27T10:00:00+00:00',
|
||||
'water_temperature': dict({
|
||||
'name': 'Water Temperature',
|
||||
'unit': None,
|
||||
'value': 10.8,
|
||||
}),
|
||||
'water_temperature_measurement_date': '2024-04-27T10:10:00+00:00',
|
||||
}),
|
||||
})
|
||||
# ---
|
31
tests/components/imgw_pib/test_diagnostics.py
Normal file
31
tests/components/imgw_pib/test_diagnostics.py
Normal file
@ -0,0 +1,31 @@
|
||||
"""Test the IMGW-PIB diagnostics platform."""
|
||||
|
||||
from unittest.mock import AsyncMock
|
||||
|
||||
from syrupy import SnapshotAssertion
|
||||
from syrupy.filters import props
|
||||
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
from . import init_integration
|
||||
|
||||
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,
|
||||
mock_config_entry: MockConfigEntry,
|
||||
mock_imgw_pib_client: AsyncMock,
|
||||
) -> None:
|
||||
"""Test config entry diagnostics."""
|
||||
await init_integration(hass, mock_config_entry)
|
||||
|
||||
result = await get_diagnostics_for_config_entry(
|
||||
hass, hass_client, mock_config_entry
|
||||
)
|
||||
|
||||
assert result == snapshot(exclude=props("entry_id"))
|
Loading…
x
Reference in New Issue
Block a user