mirror of
https://github.com/home-assistant/core.git
synced 2026-12-03 04:08:19 -04:00
Add diagnostics to Chef iQ (#189110)
Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Fable 5.1
parent
6b1827257e
commit
33ee669a61
@@ -0,0 +1,29 @@
|
||||
"""Diagnostics support for Chef iQ."""
|
||||
|
||||
from typing import TYPE_CHECKING, Any
|
||||
|
||||
from homeassistant.components import bluetooth
|
||||
from homeassistant.components.diagnostics import async_redact_data
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
from . import ChefIqConfigEntry
|
||||
|
||||
SERVICE_INFO_TO_REDACT = frozenset(
|
||||
{"address", "advertisement", "device", "name", "source"}
|
||||
)
|
||||
|
||||
|
||||
async def async_get_config_entry_diagnostics(
|
||||
hass: HomeAssistant, entry: ChefIqConfigEntry
|
||||
) -> dict[str, Any]:
|
||||
"""Return diagnostics for a config entry."""
|
||||
address = entry.unique_id
|
||||
if TYPE_CHECKING:
|
||||
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,
|
||||
),
|
||||
}
|
||||
@@ -68,7 +68,7 @@ rules:
|
||||
test-coverage: done
|
||||
# Gold
|
||||
devices: done
|
||||
diagnostics: todo
|
||||
diagnostics: done
|
||||
discovery-update-info:
|
||||
status: exempt
|
||||
comment: |
|
||||
|
||||
@@ -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({
|
||||
'1485': dict({
|
||||
'__type': "<class 'bytes'>",
|
||||
'repr': "b'\\x03P\\xc9\\x14e\\xca\\x07\\x9ad \\x1e\\x01\\x03\\x01\\x00z\\xc4'",
|
||||
}),
|
||||
}),
|
||||
'name': '**REDACTED**',
|
||||
'raw': None,
|
||||
'rssi': -60,
|
||||
'service_data': dict({
|
||||
}),
|
||||
'service_uuids': list([
|
||||
]),
|
||||
'source': '**REDACTED**',
|
||||
'tx_power': -127,
|
||||
}),
|
||||
})
|
||||
# ---
|
||||
@@ -0,0 +1,47 @@
|
||||
"""Test Chef iQ diagnostics."""
|
||||
|
||||
from pytest_homeassistant.common import MockConfigEntry
|
||||
from pytest_homeassistant.components.bluetooth import inject_bluetooth_service_info
|
||||
from pytest_homeassistant.components.diagnostics import get_diagnostics_for_config_entry
|
||||
from pytest_homeassistant.typing import ClientSessionGenerator
|
||||
from syrupy.assertion import SnapshotAssertion
|
||||
from syrupy.filters import props
|
||||
|
||||
from homeassistant.components.chef_iq.const import DOMAIN
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
from . import ADDRESS, CHEFIQ_STATUS_SERVICE_INFO, TITLE
|
||||
|
||||
|
||||
async def test_diagnostics(
|
||||
hass: HomeAssistant,
|
||||
hass_client: ClientSessionGenerator,
|
||||
snapshot: SnapshotAssertion,
|
||||
) -> None:
|
||||
"""Test the diagnostics hold the latest advertisement, redacted."""
|
||||
# A user-edited title may hold personal information; it must not be exported.
|
||||
entry = MockConfigEntry(domain=DOMAIN, unique_id=ADDRESS, title="Backyard smoker")
|
||||
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, CHEFIQ_STATUS_SERVICE_INFO)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert await get_diagnostics_for_config_entry(hass, hass_client, entry) == snapshot(
|
||||
exclude=props("time")
|
||||
)
|
||||
|
||||
|
||||
async def test_diagnostics_without_advertisement(
|
||||
hass: HomeAssistant, hass_client: ClientSessionGenerator
|
||||
) -> None:
|
||||
"""Test the diagnostics of an entry whose probe has not been seen yet."""
|
||||
entry = MockConfigEntry(domain=DOMAIN, unique_id=ADDRESS, title=TITLE)
|
||||
entry.add_to_hass(hass)
|
||||
assert await hass.config_entries.async_setup(entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert await get_diagnostics_for_config_entry(hass, hass_client, entry) == {
|
||||
"service_info": None
|
||||
}
|
||||
Reference in New Issue
Block a user