mirror of
https://github.com/home-assistant/core.git
synced 2025-04-24 01:08:12 +00:00
Add diagnostics to GDACS integration (#125296)
* simple diagnostics * add service status information * remove from no diagnostics list * wip * cater for the case where status info is undefined * make test work * code reformatted * add snapshot data * simplify code
This commit is contained in:
parent
984eba809c
commit
b5831344a0
39
homeassistant/components/gdacs/diagnostics.py
Normal file
39
homeassistant/components/gdacs/diagnostics.py
Normal file
@ -0,0 +1,39 @@
|
||||
"""Diagnostics support for GDACS integration."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Any
|
||||
|
||||
from aio_georss_client.status_update import StatusUpdate
|
||||
|
||||
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 . import GdacsFeedEntityManager
|
||||
from .const import DOMAIN, FEED
|
||||
|
||||
TO_REDACT = {CONF_LATITUDE, CONF_LONGITUDE}
|
||||
|
||||
|
||||
async def async_get_config_entry_diagnostics(
|
||||
hass: HomeAssistant, config_entry: ConfigEntry
|
||||
) -> dict[str, Any]:
|
||||
"""Return diagnostics for a config entry."""
|
||||
data: dict[str, Any] = {
|
||||
"info": async_redact_data(config_entry.data, TO_REDACT),
|
||||
}
|
||||
|
||||
manager: GdacsFeedEntityManager = hass.data[DOMAIN][FEED][config_entry.entry_id]
|
||||
status_info: StatusUpdate = manager.status_info()
|
||||
if status_info:
|
||||
data["service"] = {
|
||||
"status": status_info.status,
|
||||
"total": status_info.total,
|
||||
"last_update": status_info.last_update,
|
||||
"last_update_successful": status_info.last_update_successful,
|
||||
"last_timestamp": status_info.last_timestamp,
|
||||
}
|
||||
|
||||
return data
|
@ -117,7 +117,6 @@ NO_IOT_CLASS = [
|
||||
# https://github.com/home-assistant/developers.home-assistant/pull/1512
|
||||
NO_DIAGNOSTICS = [
|
||||
"dlna_dms",
|
||||
"gdacs",
|
||||
"geonetnz_quakes",
|
||||
"hyperion",
|
||||
"nightscout",
|
||||
|
21
tests/components/gdacs/snapshots/test_diagnostics.ambr
Normal file
21
tests/components/gdacs/snapshots/test_diagnostics.ambr
Normal file
@ -0,0 +1,21 @@
|
||||
# serializer version: 1
|
||||
# name: test_entry_diagnostics
|
||||
dict({
|
||||
'info': dict({
|
||||
'categories': list([
|
||||
]),
|
||||
'latitude': '**REDACTED**',
|
||||
'longitude': '**REDACTED**',
|
||||
'radius': 25,
|
||||
'scan_interval': 300.0,
|
||||
'unit_system': 'metric',
|
||||
}),
|
||||
'service': dict({
|
||||
'last_timestamp': None,
|
||||
'last_update': '2024-09-05T15:00:00',
|
||||
'last_update_successful': '2024-09-05T15:00:00',
|
||||
'status': 'OK',
|
||||
'total': 0,
|
||||
}),
|
||||
})
|
||||
# ---
|
33
tests/components/gdacs/test_diagnostics.py
Normal file
33
tests/components/gdacs/test_diagnostics.py
Normal file
@ -0,0 +1,33 @@
|
||||
"""Test GDACS diagnostics."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from unittest.mock import patch
|
||||
|
||||
import pytest
|
||||
from syrupy import SnapshotAssertion
|
||||
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
from tests.common import MockConfigEntry
|
||||
from tests.components.diagnostics import get_diagnostics_for_config_entry
|
||||
from tests.typing import ClientSessionGenerator
|
||||
|
||||
|
||||
@pytest.mark.freeze_time("2024-09-05 15:00:00")
|
||||
async def test_entry_diagnostics(
|
||||
hass: HomeAssistant,
|
||||
hass_client: ClientSessionGenerator,
|
||||
snapshot: SnapshotAssertion,
|
||||
config_entry: MockConfigEntry,
|
||||
) -> None:
|
||||
"""Test config entry diagnostics."""
|
||||
with patch("aio_georss_client.feed.GeoRssFeed.update") as mock_feed_update:
|
||||
mock_feed_update.return_value = "OK", []
|
||||
|
||||
config_entry.add_to_hass(hass)
|
||||
await hass.config_entries.async_setup(config_entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
result = await get_diagnostics_for_config_entry(hass, hass_client, config_entry)
|
||||
assert result == snapshot
|
Loading…
x
Reference in New Issue
Block a user