fix: show all BLE devices in K1 console
This commit is contained in:
@@ -21,3 +21,19 @@ def test_advertisement_record_marks_k1_candidate() -> None:
|
||||
assert record["manufacturer_data_hex"] == {"123": "0102"}
|
||||
assert record["service_data_hex"] == {"service": "aa"}
|
||||
assert record["service_uuids"] == ["B", "a"]
|
||||
|
||||
|
||||
def test_advertisement_record_marks_observed_xgr_serial_name_as_k1_candidate() -> None:
|
||||
device = BLEDevice("F89438FA-55ED-85AD-EED7-734AC84746D8", "XGR-A46BE7", None)
|
||||
advertisement = AdvertisementData(
|
||||
local_name="XGR-A46BE7",
|
||||
manufacturer_data={},
|
||||
service_data={},
|
||||
service_uuids=[],
|
||||
tx_power=0,
|
||||
rssi=-60,
|
||||
platform_data=(),
|
||||
)
|
||||
|
||||
record = advertisement_record(device, advertisement)
|
||||
assert record["k1_name_candidate"] is True
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import asyncio
|
||||
from pathlib import Path
|
||||
from typing import Any
|
||||
|
||||
from pytest import MonkeyPatch
|
||||
|
||||
import k1link.web.app as web_app
|
||||
|
||||
|
||||
def test_ble_scan_exposes_every_device_and_only_labels_likely_k1(
|
||||
monkeypatch: MonkeyPatch,
|
||||
tmp_path: Path,
|
||||
) -> None:
|
||||
async def fake_scan(duration_seconds: float) -> dict[str, Any]:
|
||||
assert duration_seconds == 6.0
|
||||
return {
|
||||
"devices": [
|
||||
{
|
||||
"macos_uuid": "K1-UUID",
|
||||
"name": "XGR-A46BE7",
|
||||
"local_name": "XGR-A46BE7",
|
||||
"rssi": -51,
|
||||
"k1_name_candidate": True,
|
||||
},
|
||||
{
|
||||
"macos_uuid": "OTHER-UUID",
|
||||
"name": "AirPods Pro",
|
||||
"local_name": "AirPods Pro",
|
||||
"rssi": -62,
|
||||
"k1_name_candidate": False,
|
||||
},
|
||||
]
|
||||
}
|
||||
|
||||
monkeypatch.setattr(web_app, "scan", fake_scan)
|
||||
service = web_app.ConsoleService(tmp_path)
|
||||
|
||||
state = asyncio.run(service.scan_ble(6.0))
|
||||
|
||||
assert state["selected_device_id"] is None
|
||||
assert [device["device_id"] for device in state["devices"]] == [
|
||||
"K1-UUID",
|
||||
"OTHER-UUID",
|
||||
]
|
||||
assert [device["likely_k1"] for device in state["devices"]] == [True, False]
|
||||
|
||||
Reference in New Issue
Block a user