mirror of
https://github.com/home-assistant/core.git
synced 2025-07-18 18:57:06 +00:00
Add diagnostics for nws (#117587)
* add diagnostics * remove hassfezt exception
This commit is contained in:
parent
5635bcce86
commit
9aa7d3057b
32
homeassistant/components/nws/diagnostics.py
Normal file
32
homeassistant/components/nws/diagnostics.py
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
"""Diagnostics support for NWS."""
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from typing import Any
|
||||||
|
|
||||||
|
from pynws import SimpleNWS
|
||||||
|
|
||||||
|
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
|
||||||
|
from homeassistant.core import HomeAssistant
|
||||||
|
|
||||||
|
from .const import CONF_STATION, DOMAIN
|
||||||
|
|
||||||
|
CONFIG_TO_REDACT = {CONF_API_KEY, CONF_LATITUDE, CONF_LONGITUDE, CONF_STATION}
|
||||||
|
OBSERVATION_TO_REDACT = {"station"}
|
||||||
|
|
||||||
|
|
||||||
|
async def async_get_config_entry_diagnostics(
|
||||||
|
hass: HomeAssistant,
|
||||||
|
config_entry: ConfigEntry,
|
||||||
|
) -> dict[str, Any]:
|
||||||
|
"""Return diagnostics for a config entry."""
|
||||||
|
nws_data: SimpleNWS = hass.data[DOMAIN][config_entry.entry_id].api
|
||||||
|
|
||||||
|
return {
|
||||||
|
"info": async_redact_data(config_entry.data, CONFIG_TO_REDACT),
|
||||||
|
"observation": async_redact_data(nws_data.observation, OBSERVATION_TO_REDACT),
|
||||||
|
"forecast": nws_data.forecast,
|
||||||
|
"forecast_hourly": nws_data.forecast_hourly,
|
||||||
|
}
|
@ -124,7 +124,6 @@ NO_DIAGNOSTICS = [
|
|||||||
"hyperion",
|
"hyperion",
|
||||||
"modbus",
|
"modbus",
|
||||||
"nightscout",
|
"nightscout",
|
||||||
"nws",
|
|
||||||
"point",
|
"point",
|
||||||
"pvpc_hourly_pricing",
|
"pvpc_hourly_pricing",
|
||||||
"risco",
|
"risco",
|
||||||
|
88
tests/components/nws/snapshots/test_diagnostics.ambr
Normal file
88
tests/components/nws/snapshots/test_diagnostics.ambr
Normal file
@ -0,0 +1,88 @@
|
|||||||
|
# serializer version: 1
|
||||||
|
# name: test_entry_diagnostics
|
||||||
|
dict({
|
||||||
|
'forecast': list([
|
||||||
|
dict({
|
||||||
|
'detailedForecast': 'A detailed forecast.',
|
||||||
|
'dewpoint': 4,
|
||||||
|
'iconTime': 'night',
|
||||||
|
'iconWeather': list([
|
||||||
|
list([
|
||||||
|
'lightning-rainy',
|
||||||
|
40,
|
||||||
|
]),
|
||||||
|
list([
|
||||||
|
'lightning-rainy',
|
||||||
|
90,
|
||||||
|
]),
|
||||||
|
]),
|
||||||
|
'isDaytime': False,
|
||||||
|
'name': 'Tonight',
|
||||||
|
'number': 1,
|
||||||
|
'probabilityOfPrecipitation': 89,
|
||||||
|
'relativeHumidity': 75,
|
||||||
|
'startTime': '2019-08-12T20:00:00-04:00',
|
||||||
|
'temperature': 10,
|
||||||
|
'timestamp': '2019-08-12T23:53:00+00:00',
|
||||||
|
'windBearing': 180,
|
||||||
|
'windSpeedAvg': 10,
|
||||||
|
}),
|
||||||
|
]),
|
||||||
|
'forecast_hourly': list([
|
||||||
|
dict({
|
||||||
|
'detailedForecast': 'A detailed forecast.',
|
||||||
|
'dewpoint': 4,
|
||||||
|
'iconTime': 'night',
|
||||||
|
'iconWeather': list([
|
||||||
|
list([
|
||||||
|
'lightning-rainy',
|
||||||
|
40,
|
||||||
|
]),
|
||||||
|
list([
|
||||||
|
'lightning-rainy',
|
||||||
|
90,
|
||||||
|
]),
|
||||||
|
]),
|
||||||
|
'isDaytime': False,
|
||||||
|
'name': 'Tonight',
|
||||||
|
'number': 1,
|
||||||
|
'probabilityOfPrecipitation': 89,
|
||||||
|
'relativeHumidity': 75,
|
||||||
|
'startTime': '2019-08-12T20:00:00-04:00',
|
||||||
|
'temperature': 10,
|
||||||
|
'timestamp': '2019-08-12T23:53:00+00:00',
|
||||||
|
'windBearing': 180,
|
||||||
|
'windSpeedAvg': 10,
|
||||||
|
}),
|
||||||
|
]),
|
||||||
|
'info': dict({
|
||||||
|
'api_key': '**REDACTED**',
|
||||||
|
'latitude': '**REDACTED**',
|
||||||
|
'longitude': '**REDACTED**',
|
||||||
|
'station': '**REDACTED**',
|
||||||
|
}),
|
||||||
|
'observation': dict({
|
||||||
|
'barometricPressure': 100000,
|
||||||
|
'dewpoint': 5,
|
||||||
|
'heatIndex': 15,
|
||||||
|
'iconTime': 'day',
|
||||||
|
'iconWeather': list([
|
||||||
|
list([
|
||||||
|
'Fair/clear',
|
||||||
|
None,
|
||||||
|
]),
|
||||||
|
]),
|
||||||
|
'relativeHumidity': 10,
|
||||||
|
'seaLevelPressure': 100000,
|
||||||
|
'station': '**REDACTED**',
|
||||||
|
'temperature': 10,
|
||||||
|
'textDescription': 'A long description',
|
||||||
|
'timestamp': '2019-08-12T23:53:00+00:00',
|
||||||
|
'visibility': 10000,
|
||||||
|
'windChill': 5,
|
||||||
|
'windDirection': 180,
|
||||||
|
'windGust': 20,
|
||||||
|
'windSpeed': 10,
|
||||||
|
}),
|
||||||
|
})
|
||||||
|
# ---
|
33
tests/components/nws/test_diagnostics.py
Normal file
33
tests/components/nws/test_diagnostics.py
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
"""Test NWS diagnostics."""
|
||||||
|
|
||||||
|
from syrupy import SnapshotAssertion
|
||||||
|
|
||||||
|
from homeassistant.components import nws
|
||||||
|
from homeassistant.core import HomeAssistant
|
||||||
|
|
||||||
|
from .const import NWS_CONFIG
|
||||||
|
|
||||||
|
from tests.common import MockConfigEntry
|
||||||
|
from tests.components.diagnostics import get_diagnostics_for_config_entry
|
||||||
|
from tests.typing import ClientSessionGenerator
|
||||||
|
|
||||||
|
|
||||||
|
async def test_entry_diagnostics(
|
||||||
|
hass: HomeAssistant,
|
||||||
|
hass_client: ClientSessionGenerator,
|
||||||
|
snapshot: SnapshotAssertion,
|
||||||
|
mock_simple_nws,
|
||||||
|
) -> None:
|
||||||
|
"""Test config entry diagnostics."""
|
||||||
|
|
||||||
|
entry = MockConfigEntry(
|
||||||
|
domain=nws.DOMAIN,
|
||||||
|
data=NWS_CONFIG,
|
||||||
|
)
|
||||||
|
entry.add_to_hass(hass)
|
||||||
|
await hass.config_entries.async_setup(entry.entry_id)
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
|
result = await get_diagnostics_for_config_entry(hass, hass_client, entry)
|
||||||
|
|
||||||
|
assert result == snapshot
|
Loading…
x
Reference in New Issue
Block a user