Add coverage-gap detection: ignored-hrefs registry, Repairs issue, redaction
Implements the first half of the device-capability-diagnostics spec: - registry/capabilities/ignored.py: known-noise hrefs (Bixby/voice provisioning, WiFi/BLE info, OTA/region housekeeping, and a couple of redundant hrefs) declared as no-entity Capability objects, so discover()'s existing unknown-resource reporting treats them as covered instead of flagging every device as having gaps. Folded into each by_type registry and into the global fallback CAPABILITIES set. - discovery.py: log() callback now passes the raw href instead of a formatted message, so callers can collect a clean unbound-hrefs list. - coordinator.py: wires that callback into self._unbound_hrefs, tracks device_type_name/one_ui_version, and raises (or clears) a Repairs issue when a device's type is unrecognized or it has genuinely unmodeled hrefs left over. - registry/redact.py: recursive, substring-keyed redaction for anything that looks like account/identity data, ahead of the diagnostics.py platform that will consume it. Verified against the real dishwasher/refrigerator fixtures: known-noise hrefs no longer show up as gaps, while genuine gaps (e.g. /bespoke/vs/0 on the fridge) still do.
This commit is contained in:
1 parent
b67e0e5cf5
commit
35b47d6b5a
14 files changed
+383
-11
No files matched your search
@@ -6,6 +6,7 @@ from unittest.mock import patch
|
||||
|
||||
import pytest
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers import issue_registry as ir
|
||||
|
||||
from custom_components.localthings.const import (
|
||||
DOMAIN, SUMMARY_INTERVAL_S,
|
||||
@@ -72,3 +73,84 @@ async def test_update_failed_on_persistent_poll_error(
|
||||
|
||||
# Setup fails — entry should not be in hass.data
|
||||
assert not result or mock_entry.entry_id not in hass.data.get(DOMAIN, {})
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Coverage-gap detection and the Repairs issue it raises
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
async def test_discovery_populates_device_type_and_unbound_hrefs(
|
||||
hass: HomeAssistant, mock_entry, mock_coordinator_session
|
||||
) -> None:
|
||||
"""The real refrigerator fixture is a recognized type with some gaps left."""
|
||||
await hass.config_entries.async_setup(mock_entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
coordinator: LocalThingsCoordinator = hass.data[DOMAIN][mock_entry.entry_id]
|
||||
assert coordinator.device_type_name == 'refrigerator'
|
||||
assert coordinator.one_ui_version == '7.0 Refrigerator'
|
||||
# Real, currently-unmodeled hrefs on this fixture (not noise — see
|
||||
# tests/test_registry_ignored.py for the noise-suppression checks).
|
||||
assert '/bespoke/vs/0' in coordinator._unbound_hrefs
|
||||
|
||||
|
||||
async def test_coverage_gap_issue_created_for_real_fixture_gaps(
|
||||
hass: HomeAssistant, mock_entry, mock_coordinator_session
|
||||
) -> None:
|
||||
"""A recognized device with leftover unbound hrefs still raises the issue."""
|
||||
await hass.config_entries.async_setup(mock_entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
issue_id = f"device_gap_{mock_entry.entry_id}"
|
||||
assert ir.async_get(hass).async_get_issue(DOMAIN, issue_id) is not None
|
||||
|
||||
|
||||
def test_update_coverage_gap_issue_creates_issue_for_unknown_type(
|
||||
hass: HomeAssistant, mock_entry
|
||||
) -> None:
|
||||
coordinator = LocalThingsCoordinator(hass, mock_entry)
|
||||
|
||||
coordinator._update_coverage_gap_issue(True, [], 'Test Appliance')
|
||||
|
||||
issue_id = f"device_gap_{mock_entry.entry_id}"
|
||||
issue = ir.async_get(hass).async_get_issue(DOMAIN, issue_id)
|
||||
assert issue is not None
|
||||
assert issue.translation_key == 'device_gap'
|
||||
assert issue.translation_placeholders == {'device_name': 'Test Appliance'}
|
||||
assert issue.is_fixable is False
|
||||
|
||||
|
||||
def test_update_coverage_gap_issue_creates_issue_for_unbound_hrefs(
|
||||
hass: HomeAssistant, mock_entry
|
||||
) -> None:
|
||||
coordinator = LocalThingsCoordinator(hass, mock_entry)
|
||||
|
||||
coordinator._update_coverage_gap_issue(False, ['/mystery/vs/0'], 'Test Appliance')
|
||||
|
||||
issue_id = f"device_gap_{mock_entry.entry_id}"
|
||||
assert ir.async_get(hass).async_get_issue(DOMAIN, issue_id) is not None
|
||||
|
||||
|
||||
def test_update_coverage_gap_issue_absent_when_fully_covered(
|
||||
hass: HomeAssistant, mock_entry
|
||||
) -> None:
|
||||
coordinator = LocalThingsCoordinator(hass, mock_entry)
|
||||
|
||||
coordinator._update_coverage_gap_issue(False, [], 'Test Appliance')
|
||||
|
||||
issue_id = f"device_gap_{mock_entry.entry_id}"
|
||||
assert ir.async_get(hass).async_get_issue(DOMAIN, issue_id) is None
|
||||
|
||||
|
||||
def test_update_coverage_gap_issue_clears_previous_issue(
|
||||
hass: HomeAssistant, mock_entry
|
||||
) -> None:
|
||||
"""A later discovery run with no gap deletes an issue raised earlier."""
|
||||
coordinator = LocalThingsCoordinator(hass, mock_entry)
|
||||
issue_id = f"device_gap_{mock_entry.entry_id}"
|
||||
|
||||
coordinator._update_coverage_gap_issue(True, [], 'Test Appliance')
|
||||
assert ir.async_get(hass).async_get_issue(DOMAIN, issue_id) is not None
|
||||
|
||||
coordinator._update_coverage_gap_issue(False, [], 'Test Appliance')
|
||||
assert ir.async_get(hass).async_get_issue(DOMAIN, issue_id) is None
|
||||
Reference in new issue
Block a user