mirror of
https://github.com/home-assistant/core.git
synced 2026-12-02 19:57:03 -04:00
Add diagnostics support for Qingping (#184794)
Co-authored-by: Claude Code <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
"""Diagnostics support for the Qingping integration."""
|
||||
|
||||
from typing import Any
|
||||
|
||||
from homeassistant.components import bluetooth
|
||||
from homeassistant.components.diagnostics import async_redact_data
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
from . import QingpingConfigEntry
|
||||
|
||||
SERVICE_INFO_TO_REDACT = frozenset(
|
||||
{"address", "advertisement", "device", "name", "source"}
|
||||
)
|
||||
|
||||
|
||||
async def async_get_config_entry_diagnostics(
|
||||
hass: HomeAssistant, entry: QingpingConfigEntry
|
||||
) -> dict[str, Any]:
|
||||
"""Return diagnostics for a config entry."""
|
||||
address = entry.unique_id
|
||||
assert address is not None
|
||||
service_info = bluetooth.async_last_service_info(hass, address, connectable=False)
|
||||
return {
|
||||
"service_info": async_redact_data(
|
||||
service_info.as_dict() if service_info else None,
|
||||
SERVICE_INFO_TO_REDACT,
|
||||
),
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
# serializer version: 1
|
||||
# name: test_diagnostics
|
||||
dict({
|
||||
'service_info': dict({
|
||||
'address': '**REDACTED**',
|
||||
'advertisement': '**REDACTED**',
|
||||
'connectable': True,
|
||||
'device': '**REDACTED**',
|
||||
'manufacturer_data': dict({
|
||||
}),
|
||||
'name': '**REDACTED**',
|
||||
'raw': None,
|
||||
'rssi': -60,
|
||||
'service_data': dict({
|
||||
'0000fdcd-0000-1000-8000-00805f9b34fb': dict({
|
||||
'__type': "<class 'bytes'>",
|
||||
'repr': "b'H\\x12\\xcd\\xd5`4-X\\x08\\x04\\x00\\r\\x00\\x00\\x0f\\x01\\xee'",
|
||||
}),
|
||||
}),
|
||||
'service_uuids': list([
|
||||
]),
|
||||
'source': '**REDACTED**',
|
||||
'tx_power': -127,
|
||||
}),
|
||||
})
|
||||
# ---
|
||||
@@ -0,0 +1,33 @@
|
||||
"""Tests for the diagnostics data provided by the Qingping integration."""
|
||||
|
||||
from syrupy.assertion import SnapshotAssertion
|
||||
from syrupy.filters import props
|
||||
|
||||
from homeassistant.components.qingping.const import DOMAIN
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
from . import LIGHT_AND_SIGNAL_SERVICE_INFO
|
||||
|
||||
from tests.common import MockConfigEntry
|
||||
from tests.components.bluetooth import inject_bluetooth_service_info
|
||||
from tests.components.diagnostics import get_diagnostics_for_config_entry
|
||||
from tests.typing import ClientSessionGenerator
|
||||
|
||||
|
||||
async def test_diagnostics(
|
||||
hass: HomeAssistant,
|
||||
hass_client: ClientSessionGenerator,
|
||||
snapshot: SnapshotAssertion,
|
||||
) -> None:
|
||||
"""Test diagnostics for a config entry."""
|
||||
entry = MockConfigEntry(domain=DOMAIN, unique_id="aa:bb:cc:dd:ee:ff")
|
||||
entry.add_to_hass(hass)
|
||||
assert await hass.config_entries.async_setup(entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
inject_bluetooth_service_info(hass, LIGHT_AND_SIGNAL_SERVICE_INFO)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert await get_diagnostics_for_config_entry(hass, hass_client, entry) == snapshot(
|
||||
exclude=props("created_at", "modified_at", "entry_id", "time")
|
||||
)
|
||||
Reference in New Issue
Block a user