mirror of
https://github.com/home-assistant/core.git
synced 2026-12-02 19:57:03 -04:00
Add diagnostics to OpenSky Network (#186510)
Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude
parent
3a3c2b0e30
commit
ae2e362ca9
@@ -0,0 +1,21 @@
|
||||
"""Diagnostics support for OpenSky."""
|
||||
|
||||
from typing import Any
|
||||
|
||||
from homeassistant.components.diagnostics import async_redact_data
|
||||
from homeassistant.const import CONF_PASSWORD, CONF_USERNAME
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
from .coordinator import OpenSkyConfigEntry
|
||||
|
||||
TO_REDACT = {CONF_PASSWORD, CONF_USERNAME}
|
||||
|
||||
|
||||
async def async_get_config_entry_diagnostics(
|
||||
hass: HomeAssistant, entry: OpenSkyConfigEntry
|
||||
) -> dict[str, Any]:
|
||||
"""Return diagnostics for a config entry."""
|
||||
return {
|
||||
"options": async_redact_data(entry.options, TO_REDACT),
|
||||
"flights_in_area": entry.runtime_data.data,
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
# serializer version: 1
|
||||
# name: test_diagnostics
|
||||
dict({
|
||||
'flights_in_area': 1,
|
||||
'options': dict({
|
||||
'altitude': 12500.0,
|
||||
'contributing_user': True,
|
||||
'password': '**REDACTED**',
|
||||
'radius': 10.0,
|
||||
'username': '**REDACTED**',
|
||||
}),
|
||||
})
|
||||
# ---
|
||||
@@ -0,0 +1,29 @@
|
||||
"""Tests for the OpenSky diagnostics."""
|
||||
|
||||
import pytest
|
||||
from pytest_homeassistant.common import MockConfigEntry
|
||||
from pytest_homeassistant.components.diagnostics import get_diagnostics_for_config_entry
|
||||
from pytest_homeassistant.typing import ClientSessionGenerator
|
||||
from syrupy.assertion import SnapshotAssertion
|
||||
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
from . import setup_integration
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("opensky_client")
|
||||
async def test_diagnostics(
|
||||
hass: HomeAssistant,
|
||||
hass_client: ClientSessionGenerator,
|
||||
config_entry_authenticated: MockConfigEntry,
|
||||
snapshot: SnapshotAssertion,
|
||||
) -> None:
|
||||
"""Test diagnostics."""
|
||||
await setup_integration(hass, config_entry_authenticated)
|
||||
|
||||
assert (
|
||||
await get_diagnostics_for_config_entry(
|
||||
hass, hass_client, config_entry_authenticated
|
||||
)
|
||||
== snapshot
|
||||
)
|
||||
Reference in New Issue
Block a user