observe: drop fallback hrefs on late notify; skip empty subpolls

on_notification discards from fallback_hrefs so a late first push
(after the 80% quorum snapshot) self-corrects instead of staying on
the 3s GET cadence. Empty subpoll slots skip the session lock.
This commit is contained in:
JayChickenK committed 2026-08-19 18:33:22 +02:00
1 parent 9a45afe949
commit 43076352ae
4 files changed
+63 -4

No files matched your search

+32
View File
@@ -1106,6 +1106,38 @@ async def test_observe_mode_skips_subpolls_when_nothing_is_silent(
mock_sleep.assert_not_called()
async def test_observe_mode_skips_empty_subpoll_slots(
hass: HomeAssistant, mock_entry, mock_coordinator_observe_session
) -> None:
"""Once hot is empty, odd slots would otherwise take the session lock
and dispatch a no-op executor job. Skip those."""
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]
coordinator._observe.mode = MODE_OBSERVE
coordinator._hot_hrefs = []
coordinator._warm_hrefs = ["/warm/vs/0"]
coordinator._observe.fallback_hrefs = {"/warm/vs/0"}
polled: list[list[str]] = []
def _capture(hrefs):
polled.append(list(hrefs))
with (
patch.object(coordinator, "_poll_hrefs_blocking", side_effect=_capture),
patch(
"custom_components.localthings.coordinator.asyncio.sleep",
new_callable=AsyncMock,
),
):
await coordinator._run_subpolls()
assert polled
for batch in polled:
assert batch == ["/warm/vs/0"]
async def test_write_marks_href_pending_before_post(
hass: HomeAssistant, mock_entry, mock_coordinator_observe_session
) -> None:
+18
View File
@@ -236,6 +236,24 @@ def test_enter_observe_mode_keeps_silent_hrefs_on_fallback():
mgr.close()
def test_on_notification_drops_href_from_fallback():
"""A late first notify (after the 80% snapshot) self-corrects
fallback_hrefs so a slow-but-pushing href is not polled for the rest
of the session -- multi-block resources being the reliable victim."""
mgr = _manager()
session = _FakeSession()
subscribed = {"/a/vs/0", "/b/vs/0", "/c/vs/0"}
mgr.on_notification("/a/vs/0", cbor2.dumps({"x": 1}))
mgr.on_notification("/b/vs/0", cbor2.dumps({"x": 1}))
try:
mgr.enter_observe_mode(session, subscribed)
assert mgr.fallback_hrefs == {"/c/vs/0"}
mgr.on_notification("/c/vs/0", cbor2.dumps({"x": 1}))
assert mgr.fallback_hrefs == set()
finally:
mgr.close()
def test_try_enter_observe_mode_meets_success_fraction_with_partial_notifies():
mgr = _manager()
session = _FakeSession()