Add diagnostics to ReCollect Waste (#64814)
This commit is contained in:
parent
224d0d80b2
commit
620991fef8
3 changed files with 56 additions and 2 deletions
23
homeassistant/components/recollect_waste/diagnostics.py
Normal file
23
homeassistant/components/recollect_waste/diagnostics.py
Normal file
|
@ -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],
|
||||
}
|
|
@ -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", []
|
||||
):
|
||||
|
|
23
tests/components/recollect_waste/test_diagnostics.py
Normal file
23
tests/components/recollect_waste/test_diagnostics.py
Normal file
|
@ -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": "<class 'datetime.date'>",
|
||||
"isoformat": "2022-01-23",
|
||||
},
|
||||
"pickup_types": [
|
||||
{"name": "garbage", "friendly_name": "Trash Collection"}
|
||||
],
|
||||
"area_name": "The Sun",
|
||||
}
|
||||
],
|
||||
}
|
Loading…
Add table
Reference in a new issue