mirror of
https://github.com/home-assistant/core.git
synced 2025-04-22 16:27:56 +00:00
Add diagnostics
platform for Airly integration (#69874)
Co-authored-by: Robert Svensson <Kane610@users.noreply.github.com>
This commit is contained in:
parent
fa28ee1f14
commit
74e9c050af
31
homeassistant/components/airly/diagnostics.py
Normal file
31
homeassistant/components/airly/diagnostics.py
Normal file
@ -0,0 +1,31 @@
|
||||
"""Diagnostics support for Airly."""
|
||||
from __future__ import annotations
|
||||
|
||||
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 AirlyDataUpdateCoordinator
|
||||
from .const import DOMAIN
|
||||
|
||||
TO_REDACT = {CONF_API_KEY, CONF_LATITUDE, CONF_LONGITUDE, CONF_UNIQUE_ID}
|
||||
|
||||
|
||||
async def async_get_config_entry_diagnostics(
|
||||
hass: HomeAssistant, config_entry: ConfigEntry
|
||||
) -> dict:
|
||||
"""Return diagnostics for a config entry."""
|
||||
coordinator: AirlyDataUpdateCoordinator = hass.data[DOMAIN][config_entry.entry_id]
|
||||
|
||||
diagnostics_data = {
|
||||
"config_entry": async_redact_data(config_entry.as_dict(), TO_REDACT),
|
||||
"coordinator_data": coordinator.data,
|
||||
}
|
||||
|
||||
return diagnostics_data
|
16
tests/components/airly/fixtures/diagnostics_data.json
Normal file
16
tests/components/airly/fixtures/diagnostics_data.json
Normal file
@ -0,0 +1,16 @@
|
||||
{
|
||||
"PM1": 9.23,
|
||||
"PM25": 13.71,
|
||||
"PM10": 18.58,
|
||||
"PRESSURE": 1000.87,
|
||||
"HUMIDITY": 92.84,
|
||||
"TEMPERATURE": 14.23,
|
||||
"PM25_LIMIT": 25.0,
|
||||
"PM25_PERCENT": 54.84,
|
||||
"PM10_LIMIT": 50.0,
|
||||
"PM10_PERCENT": 37.17,
|
||||
"CAQI": 22.85,
|
||||
"LEVEL": "very low",
|
||||
"DESCRIPTION": "Great air here today!",
|
||||
"ADVICE": "Great air!"
|
||||
}
|
37
tests/components/airly/test_diagnostics.py
Normal file
37
tests/components/airly/test_diagnostics.py
Normal file
@ -0,0 +1,37 @@
|
||||
"""Test Airly diagnostics."""
|
||||
import json
|
||||
|
||||
from homeassistant.components.diagnostics import REDACTED
|
||||
|
||||
from tests.common import load_fixture
|
||||
from tests.components.airly import init_integration
|
||||
from tests.components.diagnostics import get_diagnostics_for_config_entry
|
||||
|
||||
|
||||
async def test_entry_diagnostics(hass, aioclient_mock, hass_client):
|
||||
"""Test config entry diagnostics."""
|
||||
entry = await init_integration(hass, aioclient_mock)
|
||||
|
||||
coordinator_data = json.loads(load_fixture("diagnostics_data.json", "airly"))
|
||||
|
||||
result = await get_diagnostics_for_config_entry(hass, hass_client, entry)
|
||||
|
||||
assert result["config_entry"] == {
|
||||
"entry_id": entry.entry_id,
|
||||
"version": 1,
|
||||
"domain": "airly",
|
||||
"title": "Home",
|
||||
"data": {
|
||||
"latitude": REDACTED,
|
||||
"longitude": REDACTED,
|
||||
"name": "Home",
|
||||
"api_key": REDACTED,
|
||||
},
|
||||
"options": {},
|
||||
"pref_disable_new_entities": False,
|
||||
"pref_disable_polling": False,
|
||||
"source": "user",
|
||||
"unique_id": REDACTED,
|
||||
"disabled_by": None,
|
||||
}
|
||||
assert result["coordinator_data"] == coordinator_data
|
Loading…
x
Reference in New Issue
Block a user