1
0
mirror of https://github.com/home-assistant/core.git synced 2026-02-28 05:46:00 +00:00

Add diagnostics to met (#157805)

Co-authored-by: mik-laj <12058428+mik-laj@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
Kamil Breguła
2026-02-24 21:34:54 +01:00
committed by GitHub
parent 6abefc852d
commit dfbd4ffb2d
3 changed files with 72 additions and 0 deletions

View File

@@ -0,0 +1,30 @@
"""Diagnostics support for Met.no integration."""
from typing import Any
from homeassistant.components.diagnostics import async_redact_data
from homeassistant.const import CONF_LATITUDE, CONF_LONGITUDE
from homeassistant.core import HomeAssistant
from .coordinator import MetWeatherConfigEntry
TO_REDACT = [
CONF_LATITUDE,
CONF_LONGITUDE,
]
async def async_get_config_entry_diagnostics(
hass: HomeAssistant, entry: MetWeatherConfigEntry
) -> dict[str, Any]:
"""Return diagnostics for a config entry."""
coordinator_data = entry.runtime_data.data
return {
"entry_data": async_redact_data(entry.data, TO_REDACT),
"data": {
"current_weather_data": coordinator_data.current_weather_data,
"daily_forecast": coordinator_data.daily_forecast,
"hourly_forecast": coordinator_data.hourly_forecast,
},
}

View File

@@ -0,0 +1,19 @@
# serializer version: 1
# name: test_entry_diagnostics
dict({
'data': dict({
'current_weather_data': dict({
}),
'daily_forecast': list([
]),
'hourly_forecast': list([
]),
}),
'entry_data': dict({
'elevation': 1.0,
'latitude': '**REDACTED**',
'longitude': '**REDACTED**',
'name': 'test',
}),
})
# ---

View File

@@ -0,0 +1,23 @@
"""Test Met.no diagnostics."""
from syrupy.assertion import SnapshotAssertion
from homeassistant.core import HomeAssistant
from . import init_integration
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,
) -> None:
"""Test config entry diagnostics."""
mock_config_entry = await init_integration(hass)
assert (
await get_diagnostics_for_config_entry(hass, hass_client, mock_config_entry)
== snapshot
)