Bound subdevice discovery during setup
This commit is contained in:
1 parent
ba5a3b529d
commit
71f2101d11
4 files changed
+258
-17
No files matched your search
@@ -253,6 +253,23 @@ async def test_fac_bora_2in1_unique_ids_include_subdevice_prefix(hass: HomeAssis
|
||||
# capture instead of the synthetic sessions test_subdevices.py uses.
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
async def test_flat_probe_priority_puts_live_climate_state_before_cold_metrics(
|
||||
hass: HomeAssistant,
|
||||
):
|
||||
"""Registry metadata drives fallback order without a model-specific list."""
|
||||
resources, _oic_res, _seeds = _load_device_full(
|
||||
'airconditioner_fac_bora_205_flat'
|
||||
)
|
||||
coordinator = _coordinator(hass)
|
||||
|
||||
priority = coordinator._subdevice_probe_priority(resources)
|
||||
|
||||
assert '/mode/vs/0' in priority[:4]
|
||||
assert priority.index('/mode/vs/0') < priority.index(
|
||||
'/energy/consumption/vs/0'
|
||||
)
|
||||
|
||||
|
||||
async def test_fac_bora_205_flat_fallback_finds_candidate_but_gate_holds_it_back(
|
||||
hass: HomeAssistant,
|
||||
):
|
||||
|
||||
@@ -7,6 +7,7 @@ from __future__ import annotations
|
||||
|
||||
import cbor2
|
||||
|
||||
from custom_components.localthings.registry import subdevices as subdevices_module
|
||||
from custom_components.localthings.registry.capability import Capability
|
||||
from custom_components.localthings.registry.entities import BinarySensorDesc, SensorDesc
|
||||
from custom_components.localthings.registry.subdevices import (
|
||||
@@ -318,6 +319,116 @@ def test_enumerate_prefixed_flat_fallback_probe_log_reports_every_href_tried():
|
||||
assert probes[f'/{_UUID}/mode/vs/0'] is True
|
||||
|
||||
|
||||
def test_enumeration_budget_bounds_silent_prefixed_fallback_and_uses_priority(
|
||||
monkeypatch,
|
||||
):
|
||||
"""A firmware that drops unknown prefixed paths cannot stall setup.
|
||||
|
||||
The Collection probe gets the larger blockwise allowance. The preferred
|
||||
live-state href is then attempted first, and the last Property probe is
|
||||
clamped to exactly the time left in the shared enumeration budget.
|
||||
"""
|
||||
class Clock:
|
||||
now = 0.0
|
||||
|
||||
def monotonic(self):
|
||||
return self.now
|
||||
|
||||
class SilentSession:
|
||||
def __init__(self, clock):
|
||||
self.clock = clock
|
||||
self.calls = []
|
||||
|
||||
def get(self, path, timeout=10.0):
|
||||
self.calls.append((tuple(path), timeout))
|
||||
self.clock.now += timeout
|
||||
raise TimeoutError
|
||||
|
||||
def pace(self):
|
||||
pass
|
||||
|
||||
clock = Clock()
|
||||
session = SilentSession(clock)
|
||||
monkeypatch.setattr(subdevices_module.time, 'monotonic', clock.monotonic)
|
||||
resources = {
|
||||
'/subdevices/vs/0': {
|
||||
'x.com.samsung.da.subdeviceIdList': [_UUID],
|
||||
},
|
||||
'/power/vs/0': {'power': 'On'},
|
||||
'/mode/vs/0': {'mode': 'Cool'},
|
||||
}
|
||||
|
||||
found, extra = enumerate_subdevices(
|
||||
session,
|
||||
resources,
|
||||
oic_res_links=[],
|
||||
preferred_hrefs=('/mode/vs/0',),
|
||||
time_budget=7.0,
|
||||
collection_timeout=4.0,
|
||||
property_timeout=2.0,
|
||||
)
|
||||
|
||||
assert found == []
|
||||
assert extra == {}
|
||||
assert clock.now == 7.0
|
||||
assert session.calls == [
|
||||
((_UUID, 'device', '0'), 4.0),
|
||||
((_UUID, 'mode', 'vs', '0'), 2.0),
|
||||
((_UUID, 'power', 'vs', '0'), 1.0),
|
||||
]
|
||||
|
||||
|
||||
def test_enumeration_keeps_preferred_response_found_before_budget_expires(
|
||||
monkeypatch,
|
||||
):
|
||||
"""A useful early response survives later silent probes hitting the cap."""
|
||||
class Clock:
|
||||
now = 0.0
|
||||
|
||||
def monotonic(self):
|
||||
return self.now
|
||||
|
||||
class PartlyResponsiveSession:
|
||||
def __init__(self, clock):
|
||||
self.clock = clock
|
||||
|
||||
def get(self, path, timeout=10.0):
|
||||
if tuple(path) == (_UUID, 'mode', 'vs', '0'):
|
||||
return 0x45, cbor2.dumps({'mode': 'Cool'})
|
||||
self.clock.now += timeout
|
||||
raise TimeoutError
|
||||
|
||||
def pace(self):
|
||||
pass
|
||||
|
||||
clock = Clock()
|
||||
monkeypatch.setattr(subdevices_module.time, 'monotonic', clock.monotonic)
|
||||
resources = {
|
||||
'/subdevices/vs/0': {
|
||||
'x.com.samsung.da.subdeviceIdList': [_UUID],
|
||||
},
|
||||
'/power/vs/0': {'power': 'On'},
|
||||
'/mode/vs/0': {'mode': 'Cool'},
|
||||
}
|
||||
|
||||
found, extra = enumerate_subdevices(
|
||||
PartlyResponsiveSession(clock),
|
||||
resources,
|
||||
oic_res_links=[],
|
||||
preferred_hrefs=('/mode/vs/0',),
|
||||
time_budget=7.0,
|
||||
collection_timeout=4.0,
|
||||
property_timeout=2.0,
|
||||
)
|
||||
|
||||
assert [(subdevice.kind, subdevice.key) for subdevice in found] == [
|
||||
('prefixed', _UUID),
|
||||
]
|
||||
assert found[0].flat_hrefs == ('/mode/vs/0',)
|
||||
assert extra == {f'/{_UUID}/mode/vs/0': {'mode': 'Cool'}}
|
||||
assert clock.now == 7.0
|
||||
|
||||
|
||||
def test_enumerate_prefixed_flat_fallback_with_no_master_hrefs_to_probe_is_a_no_op():
|
||||
"""The master itself having nothing but /subdevices/vs/0 in its own
|
||||
resources this cycle (e.g. a very first, mostly-empty poll) must not
|
||||
|
||||
Reference in new issue
Block a user