mirror of
https://github.com/home-assistant/core.git
synced 2025-04-23 00:37:53 +00:00
parent
6c54267f57
commit
2ed30ac361
28
homeassistant/components/nam/diagnostics.py
Normal file
28
homeassistant/components/nam/diagnostics.py
Normal file
@ -0,0 +1,28 @@
|
||||
"""Diagnostics support for NAM."""
|
||||
from __future__ import annotations
|
||||
|
||||
from dataclasses import asdict
|
||||
|
||||
from homeassistant.components.diagnostics import async_redact_data
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import CONF_PASSWORD, CONF_USERNAME
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
from . import NAMDataUpdateCoordinator
|
||||
from .const import DOMAIN
|
||||
|
||||
TO_REDACT = {CONF_PASSWORD, CONF_USERNAME}
|
||||
|
||||
|
||||
async def async_get_config_entry_diagnostics(
|
||||
hass: HomeAssistant, config_entry: ConfigEntry
|
||||
) -> dict:
|
||||
"""Return diagnostics for a config entry."""
|
||||
coordinator: NAMDataUpdateCoordinator = hass.data[DOMAIN][config_entry.entry_id]
|
||||
|
||||
diagnostics_data = {
|
||||
"info": async_redact_data(config_entry.data, TO_REDACT),
|
||||
"data": asdict(coordinator.data),
|
||||
}
|
||||
|
||||
return diagnostics_data
|
24
tests/components/nam/fixtures/diagnostics_data.json
Normal file
24
tests/components/nam/fixtures/diagnostics_data.json
Normal file
@ -0,0 +1,24 @@
|
||||
{
|
||||
"bme280_humidity": 45.7,
|
||||
"bme280_pressure": 1011,
|
||||
"bme280_temperature": 7.6,
|
||||
"bmp180_pressure": 1032,
|
||||
"bmp180_temperature": 7.6,
|
||||
"bmp280_pressure": 1022,
|
||||
"bmp280_temperature": 5.6,
|
||||
"dht22_humidity": 46.2,
|
||||
"dht22_temperature": 6.3,
|
||||
"heca_humidity": 50.0,
|
||||
"heca_temperature": 8.0,
|
||||
"mhz14a_carbon_dioxide": 865,
|
||||
"sds011_p1": 19,
|
||||
"sds011_p2": 11,
|
||||
"sht3x_humidity": 34.7,
|
||||
"sht3x_temperature": 6.3,
|
||||
"signal": -72,
|
||||
"sps30_p0": 31,
|
||||
"sps30_p1": 21,
|
||||
"sps30_p2": 34,
|
||||
"sps30_p4": 25,
|
||||
"uptime": 456987
|
||||
}
|
18
tests/components/nam/test_diagnostics.py
Normal file
18
tests/components/nam/test_diagnostics.py
Normal file
@ -0,0 +1,18 @@
|
||||
"""Test NAM diagnostics."""
|
||||
import json
|
||||
|
||||
from tests.common import load_fixture
|
||||
from tests.components.diagnostics import get_diagnostics_for_config_entry
|
||||
from tests.components.nam import init_integration
|
||||
|
||||
|
||||
async def test_entry_diagnostics(hass, hass_client):
|
||||
"""Test config entry diagnostics."""
|
||||
entry = await init_integration(hass)
|
||||
|
||||
diagnostics_data = json.loads(load_fixture("diagnostics_data.json", "nam"))
|
||||
|
||||
result = await get_diagnostics_for_config_entry(hass, hass_client, entry)
|
||||
|
||||
assert result["info"] == {"host": "10.10.2.3"}
|
||||
assert result["data"] == diagnostics_data
|
Loading…
x
Reference in New Issue
Block a user