Add diagnostics to ReCollect Waste (#64814)

This commit is contained in:
Aaron Bach 2022-01-24 08:18:22 -07:00 committed by GitHub
parent 224d0d80b2
commit 620991fef8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 56 additions and 2 deletions

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

View file

@ -1,6 +1,8 @@
"""Define test fixtures for ReCollect Waste.""" """Define test fixtures for ReCollect Waste."""
from datetime import date
from unittest.mock import patch from unittest.mock import patch
from aiorecollect.client import PickupEvent, PickupType
import pytest import pytest
from homeassistant.components.recollect_waste.const import ( from homeassistant.components.recollect_waste.const import (
@ -33,10 +35,16 @@ def config_fixture(hass):
@pytest.fixture(name="setup_recollect_waste") @pytest.fixture(name="setup_recollect_waste")
async def setup_recollect_waste_fixture(hass, config): async def setup_recollect_waste_fixture(hass, config):
"""Define a fixture to set up ReCollect Waste.""" """Define a fixture to set up ReCollect Waste."""
pickup_event = PickupEvent(
date(2022, 1, 23), [PickupType("garbage", "Trash Collection")], "The Sun"
)
with patch( 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( ), 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( ), patch(
"homeassistant.components.recollect_waste.PLATFORMS", [] "homeassistant.components.recollect_waste.PLATFORMS", []
): ):

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