diff --git a/homeassistant/components/ridwell/diagnostics.py b/homeassistant/components/ridwell/diagnostics.py new file mode 100644 index 00000000000..fce89a639ad --- /dev/null +++ b/homeassistant/components/ridwell/diagnostics.py @@ -0,0 +1,24 @@ +"""Diagnostics support for Ridwell.""" +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 DATA_COORDINATOR, 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][ + DATA_COORDINATOR + ] + + return { + "data": [dataclasses.asdict(event) for event in coordinator.data.values()], + } diff --git a/tests/components/ridwell/conftest.py b/tests/components/ridwell/conftest.py index 35b4ddded4e..221ce5be8d2 100644 --- a/tests/components/ridwell/conftest.py +++ b/tests/components/ridwell/conftest.py @@ -27,7 +27,7 @@ def account_fixture(): }, async_get_next_pickup_event=AsyncMock( return_value=RidwellPickupEvent( - AsyncMock(), + None, "event_123", date(2022, 1, 24), [RidwellPickup("Plastic Film", "offer_123", 1, "product_123", 1)], diff --git a/tests/components/ridwell/test_diagnostics.py b/tests/components/ridwell/test_diagnostics.py new file mode 100644 index 00000000000..8427fa13e11 --- /dev/null +++ b/tests/components/ridwell/test_diagnostics.py @@ -0,0 +1,35 @@ +"""Test Ridwell diagnostics.""" +from tests.components.diagnostics import get_diagnostics_for_config_entry + + +async def test_entry_diagnostics(hass, config_entry, hass_client, setup_ridwell): + """Test config entry diagnostics.""" + assert await get_diagnostics_for_config_entry(hass, hass_client, config_entry) == { + "data": [ + { + "_async_request": None, + "event_id": "event_123", + "pickup_date": { + "__type": "", + "isoformat": "2022-01-24", + }, + "pickups": [ + { + "name": "Plastic Film", + "offer_id": "offer_123", + "priority": 1, + "product_id": "product_123", + "quantity": 1, + "category": { + "__type": "", + "repr": "", + }, + } + ], + "state": { + "__type": "", + "repr": "", + }, + } + ] + }