mirror of
https://github.com/home-assistant/core.git
synced 2026-04-17 23:53:49 +01:00
Add diagnostics to Casper Glow (#166807)
This commit is contained in:
31
homeassistant/components/casper_glow/diagnostics.py
Normal file
31
homeassistant/components/casper_glow/diagnostics.py
Normal file
@@ -0,0 +1,31 @@
|
||||
"""Diagnostics support for the Casper Glow integration."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Any
|
||||
|
||||
from homeassistant.components import bluetooth
|
||||
from homeassistant.components.diagnostics import async_redact_data
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
from .coordinator import CasperGlowConfigEntry
|
||||
|
||||
SERVICE_INFO_TO_REDACT = frozenset({"address", "name", "source", "device"})
|
||||
|
||||
|
||||
async def async_get_config_entry_diagnostics(
|
||||
hass: HomeAssistant, entry: CasperGlowConfigEntry
|
||||
) -> dict[str, Any]:
|
||||
"""Return diagnostics for a config entry."""
|
||||
coordinator = entry.runtime_data
|
||||
|
||||
service_info = bluetooth.async_last_service_info(
|
||||
hass, coordinator.device.address, connectable=True
|
||||
)
|
||||
|
||||
return {
|
||||
"service_info": async_redact_data(
|
||||
service_info.as_dict() if service_info else None,
|
||||
SERVICE_INFO_TO_REDACT,
|
||||
),
|
||||
}
|
||||
@@ -39,7 +39,7 @@ rules:
|
||||
|
||||
# Gold
|
||||
devices: done
|
||||
diagnostics: todo
|
||||
diagnostics: done
|
||||
discovery-update-info:
|
||||
status: exempt
|
||||
comment: No network discovery.
|
||||
|
||||
36
tests/components/casper_glow/snapshots/test_diagnostics.ambr
Normal file
36
tests/components/casper_glow/snapshots/test_diagnostics.ambr
Normal file
@@ -0,0 +1,36 @@
|
||||
# serializer version: 1
|
||||
# name: test_diagnostics
|
||||
dict({
|
||||
'service_info': dict({
|
||||
'address': '**REDACTED**',
|
||||
'advertisement': list([
|
||||
'Jar',
|
||||
dict({
|
||||
}),
|
||||
dict({
|
||||
}),
|
||||
list([
|
||||
]),
|
||||
-127,
|
||||
-60,
|
||||
list([
|
||||
list([
|
||||
]),
|
||||
]),
|
||||
]),
|
||||
'connectable': True,
|
||||
'device': '**REDACTED**',
|
||||
'manufacturer_data': dict({
|
||||
}),
|
||||
'name': '**REDACTED**',
|
||||
'raw': None,
|
||||
'rssi': -60,
|
||||
'service_data': dict({
|
||||
}),
|
||||
'service_uuids': list([
|
||||
]),
|
||||
'source': '**REDACTED**',
|
||||
'tx_power': -127,
|
||||
}),
|
||||
})
|
||||
# ---
|
||||
33
tests/components/casper_glow/test_diagnostics.py
Normal file
33
tests/components/casper_glow/test_diagnostics.py
Normal file
@@ -0,0 +1,33 @@
|
||||
"""Test the Casper Glow diagnostics."""
|
||||
|
||||
from unittest.mock import MagicMock
|
||||
|
||||
from syrupy.assertion import SnapshotAssertion
|
||||
from syrupy.filters import props
|
||||
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
from . import setup_integration
|
||||
|
||||
from tests.common import MockConfigEntry
|
||||
from tests.components.diagnostics import get_diagnostics_for_config_entry
|
||||
from tests.typing import ClientSessionGenerator
|
||||
|
||||
|
||||
async def test_diagnostics(
|
||||
hass: HomeAssistant,
|
||||
hass_client: ClientSessionGenerator,
|
||||
mock_config_entry: MockConfigEntry,
|
||||
mock_casper_glow: MagicMock,
|
||||
snapshot: SnapshotAssertion,
|
||||
) -> None:
|
||||
"""Test diagnostics for config entry."""
|
||||
|
||||
await setup_integration(hass, mock_config_entry)
|
||||
|
||||
result = await get_diagnostics_for_config_entry(
|
||||
hass, hass_client, mock_config_entry
|
||||
)
|
||||
assert result == snapshot(
|
||||
exclude=props("created_at", "modified_at", "entry_id", "time")
|
||||
)
|
||||
Reference in New Issue
Block a user