diff --git a/homeassistant/components/imgw_pib/diagnostics.py b/homeassistant/components/imgw_pib/diagnostics.py new file mode 100644 index 00000000000..d135208115f --- /dev/null +++ b/homeassistant/components/imgw_pib/diagnostics.py @@ -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), + } diff --git a/tests/components/imgw_pib/snapshots/test_diagnostics.ambr b/tests/components/imgw_pib/snapshots/test_diagnostics.ambr new file mode 100644 index 00000000000..096e370ab02 --- /dev/null +++ b/tests/components/imgw_pib/snapshots/test_diagnostics.ambr @@ -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', + }), + }) +# --- diff --git a/tests/components/imgw_pib/test_diagnostics.py b/tests/components/imgw_pib/test_diagnostics.py new file mode 100644 index 00000000000..62dabc982c4 --- /dev/null +++ b/tests/components/imgw_pib/test_diagnostics.py @@ -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"))