Add diagnostics to AirNow (#79904)
This commit is contained in:
parent
d80c0ddb5f
commit
eae96eb4c2
2 changed files with 96 additions and 0 deletions
53
homeassistant/components/airnow/diagnostics.py
Normal file
53
homeassistant/components/airnow/diagnostics.py
Normal file
|
@ -0,0 +1,53 @@
|
|||
"""Diagnostics support for AirNow."""
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Any
|
||||
|
||||
from homeassistant.components.diagnostics import async_redact_data
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import (
|
||||
CONF_API_KEY,
|
||||
CONF_LATITUDE,
|
||||
CONF_LONGITUDE,
|
||||
CONF_UNIQUE_ID,
|
||||
)
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
from . import AirNowDataUpdateCoordinator
|
||||
from .const import DOMAIN
|
||||
|
||||
ATTR_LATITUDE_CAP = "Latitude"
|
||||
ATTR_LONGITUDE_CAP = "Longitude"
|
||||
ATTR_REPORTING_AREA = "ReportingArea"
|
||||
ATTR_STATE_CODE = "StateCode"
|
||||
|
||||
CONF_TITLE = "title"
|
||||
|
||||
TO_REDACT = {
|
||||
ATTR_LATITUDE_CAP,
|
||||
ATTR_LONGITUDE_CAP,
|
||||
ATTR_REPORTING_AREA,
|
||||
ATTR_STATE_CODE,
|
||||
CONF_API_KEY,
|
||||
CONF_LATITUDE,
|
||||
CONF_LONGITUDE,
|
||||
# The config entry title has latitude/longitude:
|
||||
CONF_TITLE,
|
||||
# The config entry unique ID has latitude/longitude:
|
||||
CONF_UNIQUE_ID,
|
||||
}
|
||||
|
||||
|
||||
async def async_get_config_entry_diagnostics(
|
||||
hass: HomeAssistant, entry: ConfigEntry
|
||||
) -> dict[str, Any]:
|
||||
"""Return diagnostics for a config entry."""
|
||||
coordinator: AirNowDataUpdateCoordinator = hass.data[DOMAIN][entry.entry_id]
|
||||
|
||||
return async_redact_data(
|
||||
{
|
||||
"entry": entry.as_dict(),
|
||||
"data": coordinator.data,
|
||||
},
|
||||
TO_REDACT,
|
||||
)
|
43
tests/components/airnow/test_diagnostics.py
Normal file
43
tests/components/airnow/test_diagnostics.py
Normal file
|
@ -0,0 +1,43 @@
|
|||
"""Test AirNow diagnostics."""
|
||||
from homeassistant.components.diagnostics import REDACTED
|
||||
|
||||
from tests.components.diagnostics import get_diagnostics_for_config_entry
|
||||
|
||||
|
||||
async def test_entry_diagnostics(hass, config_entry, hass_client, setup_airnow):
|
||||
"""Test config entry diagnostics."""
|
||||
assert await get_diagnostics_for_config_entry(hass, hass_client, config_entry) == {
|
||||
"entry": {
|
||||
"entry_id": config_entry.entry_id,
|
||||
"version": 1,
|
||||
"domain": "airnow",
|
||||
"title": REDACTED,
|
||||
"data": {
|
||||
"api_key": REDACTED,
|
||||
"latitude": REDACTED,
|
||||
"longitude": REDACTED,
|
||||
"radius": 75,
|
||||
},
|
||||
"options": {},
|
||||
"pref_disable_new_entities": False,
|
||||
"pref_disable_polling": False,
|
||||
"source": "user",
|
||||
"unique_id": REDACTED,
|
||||
"disabled_by": None,
|
||||
},
|
||||
"data": {
|
||||
"O3": 0.048,
|
||||
"PM2.5": 8.9,
|
||||
"HourObserved": 15,
|
||||
"DateObserved": "2020-12-20",
|
||||
"StateCode": REDACTED,
|
||||
"ReportingArea": REDACTED,
|
||||
"Latitude": REDACTED,
|
||||
"Longitude": REDACTED,
|
||||
"PM10": 12,
|
||||
"AQI": 44,
|
||||
"Category.Number": 1,
|
||||
"Category.Name": "Good",
|
||||
"Pollutant": "O3",
|
||||
},
|
||||
}
|
Loading…
Add table
Reference in a new issue