mirror of
https://github.com/home-assistant/core.git
synced 2026-12-02 19:57:03 -04:00
Add diagnostics to Ping (#193866)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
7a92cff84b
commit
09337d4011
@@ -0,0 +1,30 @@
|
||||
"""Diagnostics support for Ping."""
|
||||
|
||||
from typing import Any
|
||||
|
||||
from homeassistant.components.diagnostics import async_redact_data
|
||||
from homeassistant.const import CONF_HOST
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
from . import DATA_PRIVILEGED_KEY
|
||||
from .coordinator import PingConfigEntry
|
||||
|
||||
PING_METHODS = {
|
||||
None: "ping_command",
|
||||
True: "icmp_privileged",
|
||||
False: "icmp_unprivileged",
|
||||
}
|
||||
|
||||
|
||||
async def async_get_config_entry_diagnostics(
|
||||
hass: HomeAssistant, entry: PingConfigEntry
|
||||
) -> dict[str, Any]:
|
||||
"""Return diagnostics for a config entry."""
|
||||
coordinator = entry.runtime_data
|
||||
return {
|
||||
"options": async_redact_data(entry.options, {CONF_HOST}),
|
||||
"ping_method": PING_METHODS[hass.data[DATA_PRIVILEGED_KEY]],
|
||||
"last_update_success": coordinator.last_update_success,
|
||||
"is_alive": coordinator.data.is_alive,
|
||||
"data": coordinator.data.data,
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
# serializer version: 1
|
||||
# name: test_entry_diagnostics
|
||||
dict({
|
||||
'data': dict({
|
||||
'avg': 4.8,
|
||||
'jitter': 3.5,
|
||||
'loss': 0.0,
|
||||
'max': 10,
|
||||
'min': 1,
|
||||
}),
|
||||
'is_alive': True,
|
||||
'last_update_success': True,
|
||||
'options': dict({
|
||||
'consider_home': 180,
|
||||
'count': 10.0,
|
||||
'host': '**REDACTED**',
|
||||
}),
|
||||
'ping_method': 'icmp_privileged',
|
||||
})
|
||||
# ---
|
||||
@@ -0,0 +1,23 @@
|
||||
"""Tests for the Ping 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
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("setup_integration")
|
||||
async def test_entry_diagnostics(
|
||||
hass: HomeAssistant,
|
||||
hass_client: ClientSessionGenerator,
|
||||
config_entry: MockConfigEntry,
|
||||
snapshot: SnapshotAssertion,
|
||||
) -> None:
|
||||
"""Test config entry diagnostics redact the host."""
|
||||
assert (
|
||||
await get_diagnostics_for_config_entry(hass, hass_client, config_entry)
|
||||
== snapshot
|
||||
)
|
||||
Reference in New Issue
Block a user