Add diagnostics to Ridwell (#64863)
This commit is contained in:
parent
2471ddaec6
commit
149cd8e319
3 changed files with 60 additions and 1 deletions
24
homeassistant/components/ridwell/diagnostics.py
Normal file
24
homeassistant/components/ridwell/diagnostics.py
Normal file
|
@ -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()],
|
||||
}
|
|
@ -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)],
|
||||
|
|
35
tests/components/ridwell/test_diagnostics.py
Normal file
35
tests/components/ridwell/test_diagnostics.py
Normal file
|
@ -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": "<class 'datetime.date'>",
|
||||
"isoformat": "2022-01-24",
|
||||
},
|
||||
"pickups": [
|
||||
{
|
||||
"name": "Plastic Film",
|
||||
"offer_id": "offer_123",
|
||||
"priority": 1,
|
||||
"product_id": "product_123",
|
||||
"quantity": 1,
|
||||
"category": {
|
||||
"__type": "<enum 'PickupCategory'>",
|
||||
"repr": "<PickupCategory.STANDARD: 'standard'>",
|
||||
},
|
||||
}
|
||||
],
|
||||
"state": {
|
||||
"__type": "<enum 'EventState'>",
|
||||
"repr": "<EventState.INITIALIZED: 'initialized'>",
|
||||
},
|
||||
}
|
||||
]
|
||||
}
|
Loading…
Add table
Reference in a new issue