diff --git a/homeassistant/components/pegel_online/diagnostics.py b/homeassistant/components/pegel_online/diagnostics.py new file mode 100644 index 00000000000..b68437c5ee7 --- /dev/null +++ b/homeassistant/components/pegel_online/diagnostics.py @@ -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, + } diff --git a/tests/components/pegel_online/snapshots/test_diagnostics.ambr b/tests/components/pegel_online/snapshots/test_diagnostics.ambr new file mode 100644 index 00000000000..1e55805f867 --- /dev/null +++ b/tests/components/pegel_online/snapshots/test_diagnostics.ambr @@ -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, + }), + }) +# --- diff --git a/tests/components/pegel_online/test_diagnostics.py b/tests/components/pegel_online/test_diagnostics.py new file mode 100644 index 00000000000..220f244b751 --- /dev/null +++ b/tests/components/pegel_online/test_diagnostics.py @@ -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"))