diff --git a/homeassistant/components/recollect_waste/diagnostics.py b/homeassistant/components/recollect_waste/diagnostics.py new file mode 100644 index 00000000000..fb19b1790f5 --- /dev/null +++ b/homeassistant/components/recollect_waste/diagnostics.py @@ -0,0 +1,23 @@ +"""Diagnostics support for ReCollect Waste.""" +from __future__ import annotations + +import dataclasses +from typing import Any + +from homeassistant.config_entries import ConfigEntry +from homeassistant.core import HomeAssistant +from homeassistant.helpers.update_coordinator import DataUpdateCoordinator + +from .const import DOMAIN + + +async def async_get_config_entry_diagnostics( + hass: HomeAssistant, entry: ConfigEntry +) -> dict[str, Any]: + """Return diagnostics for a config entry.""" + coordinator: DataUpdateCoordinator = hass.data[DOMAIN][entry.entry_id] + + return { + "entry": entry.as_dict(), + "data": [dataclasses.asdict(event) for event in coordinator.data], + } diff --git a/tests/components/recollect_waste/conftest.py b/tests/components/recollect_waste/conftest.py index 1bdf729c47b..a0d002e9d9a 100644 --- a/tests/components/recollect_waste/conftest.py +++ b/tests/components/recollect_waste/conftest.py @@ -1,6 +1,8 @@ """Define test fixtures for ReCollect Waste.""" +from datetime import date from unittest.mock import patch +from aiorecollect.client import PickupEvent, PickupType import pytest from homeassistant.components.recollect_waste.const import ( @@ -33,10 +35,16 @@ def config_fixture(hass): @pytest.fixture(name="setup_recollect_waste") async def setup_recollect_waste_fixture(hass, config): """Define a fixture to set up ReCollect Waste.""" + pickup_event = PickupEvent( + date(2022, 1, 23), [PickupType("garbage", "Trash Collection")], "The Sun" + ) + with patch( - "homeassistant.components.recollect_waste.Client.async_get_pickup_events" + "homeassistant.components.recollect_waste.Client.async_get_pickup_events", + return_value=[pickup_event], ), patch( - "homeassistant.components.recollect_waste.config_flow.Client.async_get_pickup_events" + "homeassistant.components.recollect_waste.config_flow.Client.async_get_pickup_events", + return_value=[pickup_event], ), patch( "homeassistant.components.recollect_waste.PLATFORMS", [] ): diff --git a/tests/components/recollect_waste/test_diagnostics.py b/tests/components/recollect_waste/test_diagnostics.py new file mode 100644 index 00000000000..c9c9ba5a93f --- /dev/null +++ b/tests/components/recollect_waste/test_diagnostics.py @@ -0,0 +1,23 @@ +"""Test ReCollect Waste diagnostics.""" +from tests.components.diagnostics import get_diagnostics_for_config_entry + + +async def test_entry_diagnostics( + hass, config_entry, hass_client, setup_recollect_waste +): + """Test config entry diagnostics.""" + assert await get_diagnostics_for_config_entry(hass, hass_client, config_entry) == { + "entry": config_entry.as_dict(), + "data": [ + { + "date": { + "__type": "", + "isoformat": "2022-01-23", + }, + "pickup_types": [ + {"name": "garbage", "friendly_name": "Trash Collection"} + ], + "area_name": "The Sun", + } + ], + }