fix(web): reveal NFC peripherals after detection

This commit is contained in:
Miayui
2026-09-21 11:04:18 +08:00
parent 448c8b31a0
commit b3bd90f748
9 changed files with 75 additions and 14 deletions
@@ -143,6 +143,7 @@ def test_each_detection_publishes_three_frames_per_device_and_then_stops() -> No
nfc["card"] = None
assert wait_until(lambda: service.snapshot()["state"] == "waiting_for_nfc")
assert service.snapshot()["detected_nfc_ids"] == ["E113B203"]
nfc["card"] = {"action": "present", "uid": "E113B203"}
assert wait_until(lambda: len(publications) == 12)
assert service.snapshot()["state"] == "burst_complete"
@@ -150,6 +151,29 @@ def test_each_detection_publishes_three_frames_per_device_and_then_stops() -> No
service.close()
def test_detected_devices_remain_latched_until_publisher_stops() -> None:
nfc: dict[str, Any] = {"card": {"action": "present", "uid": "E113B203"}}
service = NfcExtensionToyPublisher(
nfc_provider=lambda: nfc,
catalog_provider=lambda: [capability("light-on")],
publisher=lambda _payload: {"delivery_status": "queued"},
burst_window_s=0.03,
poll_interval_s=0.005,
)
service.start()
try:
assert wait_until(
lambda: service.snapshot()["detected_nfc_ids"] == ["E113B203"]
)
nfc["card"] = None
assert wait_until(lambda: service.snapshot()["state"] == "waiting_for_nfc")
assert service.snapshot()["detected_nfc_ids"] == ["E113B203"]
finally:
service.close()
assert service.snapshot()["detected_nfc_ids"] == []
def test_no_matching_ability_publishes_nothing() -> None:
nfc = {"card": {"action": "present", "uid": "E113B203"}}
publications: list[dict[str, Any]] = []
@@ -168,6 +192,7 @@ def test_no_matching_ability_publishes_nothing() -> None:
assert wait_until(
lambda: service.snapshot()["state"] == "no_matching_extension"
)
assert service.snapshot()["detected_nfc_ids"] == ["E113B203"]
time.sleep(0.05)
assert publications == []
finally: