Add diagnostics to Ridwell (#64863)

This commit is contained in:
Aaron Bach 2022-01-25 23:23:45 -07:00 committed by GitHub
parent 2471ddaec6
commit 149cd8e319
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 60 additions and 1 deletions

View 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()],
}

View file

@ -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)],

View 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'>",
},
}
]
}