Add diagnostics to OKOK scale integration (#187406)

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
rrooggiieerr
2026-10-20 00:18:00 +02:00
committed by GitHub
co-authored by Copilot Autofix powered by AI
parent 24af40bc8c
commit 9b4cd3839f
5 changed files with 91 additions and 2 deletions
@@ -0,0 +1,28 @@
"""Diagnostics support for the OKOK Scale 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 OKOKScaleConfigEntry
SERVICE_INFO_TO_REDACT = frozenset(
{"address", "advertisement", "device", "name", "source"}
)
async def async_get_config_entry_diagnostics(
hass: HomeAssistant, entry: OKOKScaleConfigEntry
) -> 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,
),
}
@@ -28,6 +28,6 @@
"integration_type": "device",
"iot_class": "local_push",
"loggers": ["okokscale"],
"quality_scale": "silver",
"quality_scale": "platinum",
"requirements": ["okokscale==0.0.4"]
}
@@ -64,7 +64,7 @@ rules:
# Gold
devices: done
diagnostics: todo
diagnostics: done
discovery-update-info:
status: exempt
comment: This integration uses Bluetooth and addresses don't change.
@@ -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({
'61695': dict({
'__type': "<class 'bytes'>",
'repr': "b'\\x02\\x04T\\x03\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00P\\xfb\\x19\\x01#E'",
}),
}),
'name': '**REDACTED**',
'raw': None,
'rssi': -60,
'service_data': dict({
}),
'service_uuids': list([
]),
'source': '**REDACTED**',
'tx_power': -127,
}),
})
# ---
@@ -0,0 +1,35 @@
"""Tests for the diagnostics data provided by the OKOK Scale integration."""
import pytest
from pytest_homeassistant.common import MockConfigEntry
from pytest_homeassistant.components.bluetooth import (
inject_bluetooth_service_info_bleak,
)
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.core import HomeAssistant
from . import OKOK_F0_SERVICE_INFO
@pytest.mark.usefixtures("mock_bluetooth")
async def test_diagnostics(
hass: HomeAssistant,
hass_client: ClientSessionGenerator,
mock_config_entry: MockConfigEntry,
snapshot: SnapshotAssertion,
) -> None:
"""Test diagnostics for a config entry."""
mock_config_entry.add_to_hass(hass)
assert await hass.config_entries.async_setup(mock_config_entry.entry_id)
await hass.async_block_till_done()
inject_bluetooth_service_info_bleak(hass, OKOK_F0_SERVICE_INFO)
await hass.async_block_till_done(wait_background_tasks=True)
assert await get_diagnostics_for_config_entry(
hass, hass_client, mock_config_entry
) == snapshot(exclude=props("created_at", "modified_at", "entry_id", "time"))