Add diagnostics support to Sensor.Community (#64636)
This commit is contained in:
parent
0af369d8f9
commit
1bf58b37e9
3 changed files with 59 additions and 1 deletions
|
@ -51,7 +51,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||
data.update(sensor_community.meta)
|
||||
return data
|
||||
|
||||
coordinator: DataUpdateCoordinator[dict[Any, Any]] = DataUpdateCoordinator(
|
||||
coordinator: DataUpdateCoordinator[dict[str, Any]] = DataUpdateCoordinator(
|
||||
hass,
|
||||
_LOGGER,
|
||||
name=f"{DOMAIN}_{sensor_community.sensor_id}",
|
||||
|
|
28
homeassistant/components/luftdaten/diagnostics.py
Normal file
28
homeassistant/components/luftdaten/diagnostics.py
Normal file
|
@ -0,0 +1,28 @@
|
|||
"""Diagnostics support for Sensor.Community."""
|
||||
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_LATITUDE, CONF_LONGITUDE
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator
|
||||
|
||||
from .const import CONF_SENSOR_ID, DOMAIN
|
||||
|
||||
TO_REDACT = {
|
||||
CONF_LATITUDE,
|
||||
CONF_LONGITUDE,
|
||||
CONF_SENSOR_ID,
|
||||
}
|
||||
|
||||
|
||||
async def async_get_config_entry_diagnostics(
|
||||
hass: HomeAssistant, entry: ConfigEntry
|
||||
) -> dict[str, Any]:
|
||||
"""Return diagnostics for a config entry."""
|
||||
coordinator: DataUpdateCoordinator[dict[str, Any]] = hass.data[DOMAIN][
|
||||
entry.entry_id
|
||||
]
|
||||
return async_redact_data(coordinator.data, TO_REDACT)
|
30
tests/components/luftdaten/test_diagnostics.py
Normal file
30
tests/components/luftdaten/test_diagnostics.py
Normal file
|
@ -0,0 +1,30 @@
|
|||
"""Tests for the diagnostics data provided by the Sensor.Community integration."""
|
||||
from aiohttp import ClientSession
|
||||
|
||||
from homeassistant.components.diagnostics import REDACTED
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
from tests.common import MockConfigEntry
|
||||
from tests.components.diagnostics import get_diagnostics_for_config_entry
|
||||
|
||||
|
||||
async def test_diagnostics(
|
||||
hass: HomeAssistant,
|
||||
hass_client: ClientSession,
|
||||
init_integration: MockConfigEntry,
|
||||
):
|
||||
"""Test diagnostics."""
|
||||
assert await get_diagnostics_for_config_entry(
|
||||
hass, hass_client, init_integration
|
||||
) == {
|
||||
"P1": 8.5,
|
||||
"P2": 4.07,
|
||||
"altitude": 123.456,
|
||||
"humidity": 34.7,
|
||||
"latitude": REDACTED,
|
||||
"longitude": REDACTED,
|
||||
"pressure": 98545.0,
|
||||
"pressure_at_sealevel": 103102.13,
|
||||
"sensor_id": REDACTED,
|
||||
"temperature": 22.3,
|
||||
}
|
Loading…
Add table
Reference in a new issue