mirror of
https://github.com/home-assistant/core.git
synced 2025-07-17 02:07:09 +00:00
Add diagnostics support for AEMET (#111218)
aemet: add diagnostics support Signed-off-by: Álvaro Fernández Rojas <noltari@gmail.com>
This commit is contained in:
parent
bf9c4197b9
commit
57d169582d
44
homeassistant/components/aemet/diagnostics.py
Normal file
44
homeassistant/components/aemet/diagnostics.py
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
"""Support for the AEMET OpenData diagnostics."""
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from typing import Any
|
||||||
|
|
||||||
|
from aemet_opendata.const import AOD_COORDS
|
||||||
|
|
||||||
|
from homeassistant.components.diagnostics.util 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 .const import DOMAIN, ENTRY_WEATHER_COORDINATOR
|
||||||
|
from .coordinator import WeatherUpdateCoordinator
|
||||||
|
|
||||||
|
TO_REDACT_CONFIG = [
|
||||||
|
CONF_API_KEY,
|
||||||
|
CONF_LATITUDE,
|
||||||
|
CONF_LONGITUDE,
|
||||||
|
CONF_UNIQUE_ID,
|
||||||
|
]
|
||||||
|
|
||||||
|
TO_REDACT_COORD = [
|
||||||
|
AOD_COORDS,
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
async def async_get_config_entry_diagnostics(
|
||||||
|
hass: HomeAssistant, config_entry: ConfigEntry
|
||||||
|
) -> dict[str, Any]:
|
||||||
|
"""Return diagnostics for a config entry."""
|
||||||
|
aemet_entry = hass.data[DOMAIN][config_entry.entry_id]
|
||||||
|
coordinator: WeatherUpdateCoordinator = aemet_entry[ENTRY_WEATHER_COORDINATOR]
|
||||||
|
|
||||||
|
return {
|
||||||
|
"api_data": coordinator.aemet.raw_data(),
|
||||||
|
"config_entry": async_redact_data(config_entry.as_dict(), TO_REDACT_CONFIG),
|
||||||
|
"coord_data": async_redact_data(coordinator.data, TO_REDACT_COORD),
|
||||||
|
}
|
113
tests/components/aemet/snapshots/test_diagnostics.ambr
Normal file
113
tests/components/aemet/snapshots/test_diagnostics.ambr
Normal file
@ -0,0 +1,113 @@
|
|||||||
|
# serializer version: 1
|
||||||
|
# name: test_config_entry_diagnostics
|
||||||
|
dict({
|
||||||
|
'api_data': dict({
|
||||||
|
}),
|
||||||
|
'config_entry': dict({
|
||||||
|
'data': dict({
|
||||||
|
'api_key': '**REDACTED**',
|
||||||
|
'latitude': '**REDACTED**',
|
||||||
|
'longitude': '**REDACTED**',
|
||||||
|
'name': 'AEMET',
|
||||||
|
}),
|
||||||
|
'disabled_by': None,
|
||||||
|
'domain': 'aemet',
|
||||||
|
'entry_id': '7442b231f139e813fc1939281123f220',
|
||||||
|
'minor_version': 1,
|
||||||
|
'options': dict({
|
||||||
|
}),
|
||||||
|
'pref_disable_new_entities': False,
|
||||||
|
'pref_disable_polling': False,
|
||||||
|
'source': 'user',
|
||||||
|
'title': 'Mock Title',
|
||||||
|
'unique_id': None,
|
||||||
|
'version': 1,
|
||||||
|
}),
|
||||||
|
'coord_data': dict({
|
||||||
|
'forecast': dict({
|
||||||
|
'forecast-daily': list([
|
||||||
|
]),
|
||||||
|
'forecast-hourly': list([
|
||||||
|
]),
|
||||||
|
}),
|
||||||
|
'lib': dict({
|
||||||
|
'station': dict({
|
||||||
|
'altitude': 667.0,
|
||||||
|
'coordinates': '**REDACTED**',
|
||||||
|
'datetime': '2021-01-09T13:00:00+01:00',
|
||||||
|
'dew-point': -0.7,
|
||||||
|
'distance': 12.746,
|
||||||
|
'humidity': 99.0,
|
||||||
|
'id': '3195',
|
||||||
|
'name': 'MADRID RETIRO',
|
||||||
|
'outdated': True,
|
||||||
|
'precipitation': 7.0,
|
||||||
|
'pressure': 1004.4,
|
||||||
|
'temperature': -0.7,
|
||||||
|
'temperature-max': -0.6,
|
||||||
|
'temperature-min': -1.0,
|
||||||
|
'timestamp-utc': '2021-01-09T13:00:00+01:00',
|
||||||
|
'timezone': dict({
|
||||||
|
'__type': "<class 'zoneinfo.ZoneInfo'>",
|
||||||
|
'repr': "zoneinfo.ZoneInfo(key='Europe/Madrid')",
|
||||||
|
}),
|
||||||
|
'wind-direction': 122.0,
|
||||||
|
'wind-speed': 3.2,
|
||||||
|
'wind-speed-max': 12.2,
|
||||||
|
}),
|
||||||
|
'timestamp-utc': '2024-02-23T18:00:00+00:00',
|
||||||
|
'town': dict({
|
||||||
|
'altitude': 622,
|
||||||
|
'coordinates': '**REDACTED**',
|
||||||
|
'distance': 0.0,
|
||||||
|
'forecast-daily': dict({
|
||||||
|
'forecast': list([
|
||||||
|
]),
|
||||||
|
'timestamp-local': '2021-01-09T11:54:00+00:00',
|
||||||
|
'timestamp-utc': '2021-01-09T11:54:00+00:00',
|
||||||
|
'timezone': dict({
|
||||||
|
'__type': "<class 'zoneinfo.ZoneInfo'>",
|
||||||
|
'repr': "zoneinfo.ZoneInfo(key='Europe/Madrid')",
|
||||||
|
}),
|
||||||
|
}),
|
||||||
|
'forecast-hourly': dict({
|
||||||
|
'forecast': list([
|
||||||
|
]),
|
||||||
|
'timestamp-local': '2021-01-09T11:47:45+00:00',
|
||||||
|
'timestamp-utc': '2021-01-09T11:47:45+00:00',
|
||||||
|
'timezone': dict({
|
||||||
|
'__type': "<class 'zoneinfo.ZoneInfo'>",
|
||||||
|
'repr': "zoneinfo.ZoneInfo(key='Europe/Madrid')",
|
||||||
|
}),
|
||||||
|
}),
|
||||||
|
'id': 'id28065',
|
||||||
|
'name': 'Getafe',
|
||||||
|
'residents': 173057,
|
||||||
|
'timezone': dict({
|
||||||
|
'__type': "<class 'zoneinfo.ZoneInfo'>",
|
||||||
|
'repr': "zoneinfo.ZoneInfo(key='Europe/Madrid')",
|
||||||
|
}),
|
||||||
|
}),
|
||||||
|
'weather': dict({
|
||||||
|
'condition': None,
|
||||||
|
'dew-point': None,
|
||||||
|
'feel-temperature': None,
|
||||||
|
'humidity': None,
|
||||||
|
'precipitation': None,
|
||||||
|
'precipitation-probability': None,
|
||||||
|
'pressure': None,
|
||||||
|
'rain': None,
|
||||||
|
'rain-probability': None,
|
||||||
|
'snow': None,
|
||||||
|
'snow-probability': None,
|
||||||
|
'storm-probability': None,
|
||||||
|
'temperature': None,
|
||||||
|
'uv-index': None,
|
||||||
|
'wind-direction': None,
|
||||||
|
'wind-speed': None,
|
||||||
|
'wind-speed-max': None,
|
||||||
|
}),
|
||||||
|
}),
|
||||||
|
}),
|
||||||
|
})
|
||||||
|
# ---
|
32
tests/components/aemet/test_diagnostics.py
Normal file
32
tests/components/aemet/test_diagnostics.py
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
"""Define tests for the AEMET OpenData diagnostics."""
|
||||||
|
|
||||||
|
from unittest.mock import patch
|
||||||
|
|
||||||
|
from syrupy import SnapshotAssertion
|
||||||
|
|
||||||
|
from homeassistant.components.aemet.const import DOMAIN
|
||||||
|
from homeassistant.core import HomeAssistant
|
||||||
|
|
||||||
|
from .util import async_init_integration
|
||||||
|
|
||||||
|
from tests.components.diagnostics import get_diagnostics_for_config_entry
|
||||||
|
from tests.typing import ClientSessionGenerator
|
||||||
|
|
||||||
|
|
||||||
|
async def test_config_entry_diagnostics(
|
||||||
|
hass: HomeAssistant,
|
||||||
|
hass_client: ClientSessionGenerator,
|
||||||
|
snapshot: SnapshotAssertion,
|
||||||
|
) -> None:
|
||||||
|
"""Test config entry diagnostics."""
|
||||||
|
await async_init_integration(hass)
|
||||||
|
|
||||||
|
assert hass.data[DOMAIN]
|
||||||
|
config_entry = hass.config_entries.async_entries(DOMAIN)[0]
|
||||||
|
|
||||||
|
with patch(
|
||||||
|
"homeassistant.components.aemet.AEMET.raw_data",
|
||||||
|
return_value={},
|
||||||
|
):
|
||||||
|
result = await get_diagnostics_for_config_entry(hass, hass_client, config_entry)
|
||||||
|
assert result == snapshot
|
@ -63,6 +63,7 @@ async def async_init_integration(hass: HomeAssistant):
|
|||||||
CONF_LONGITUDE: "-3.72935236",
|
CONF_LONGITUDE: "-3.72935236",
|
||||||
CONF_NAME: "AEMET",
|
CONF_NAME: "AEMET",
|
||||||
},
|
},
|
||||||
|
entry_id="7442b231f139e813fc1939281123f220",
|
||||||
)
|
)
|
||||||
config_entry.add_to_hass(hass)
|
config_entry.add_to_hass(hass)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user