fix: show all BLE devices in K1 console
This commit is contained in:
+11
-6
@@ -81,6 +81,13 @@ class ConsoleService:
|
||||
elif selected_device_id is not None:
|
||||
phase = "device_selected"
|
||||
message = "K1 выбран. Теперь введите название и пароль Wi-Fi."
|
||||
elif devices:
|
||||
likely_count = sum(bool(item.get("likely_k1")) for item in devices)
|
||||
phase = "idle"
|
||||
message = (
|
||||
f"Найдено BLE-устройств: {len(devices)}. "
|
||||
f"Возможных K1: {likely_count}. Выберите нужное устройство."
|
||||
)
|
||||
else:
|
||||
phase = "idle"
|
||||
message = runtime["message"]
|
||||
@@ -107,7 +114,7 @@ class ConsoleService:
|
||||
}
|
||||
|
||||
async def scan_ble(self, duration_seconds: float) -> dict[str, Any]:
|
||||
self._set_operation("scanning", "Ищем K1 по Bluetooth (BLE)…")
|
||||
self._set_operation("scanning", "Сканируем все устройства Bluetooth (BLE)…")
|
||||
try:
|
||||
result = await scan(duration_seconds)
|
||||
devices = [
|
||||
@@ -117,16 +124,14 @@ class ConsoleService:
|
||||
"rssi": item["rssi"],
|
||||
"address": None,
|
||||
"connectable": True,
|
||||
"likely_k1": item["k1_name_candidate"],
|
||||
}
|
||||
for item in result["devices"]
|
||||
if item["k1_name_candidate"]
|
||||
]
|
||||
with self._lock:
|
||||
self._devices = devices
|
||||
if len(devices) == 1:
|
||||
self._selected_device_id = str(devices[0]["device_id"])
|
||||
self._operation_message = (
|
||||
f"Поиск завершён. Найдено устройств K1: {len(devices)}."
|
||||
f"Поиск завершён. Найдено BLE-устройств: {len(devices)}."
|
||||
)
|
||||
finally:
|
||||
with self._lock:
|
||||
@@ -136,7 +141,7 @@ class ConsoleService:
|
||||
async def connect(self, request: ConnectRequest) -> dict[str, Any]:
|
||||
known_ids = {str(item["device_id"]) for item in self.state()["devices"]}
|
||||
if request.device_id not in known_ids:
|
||||
raise ValueError("сначала найдите и выберите K1 через Bluetooth")
|
||||
raise ValueError("сначала найдите и выберите устройство через Bluetooth")
|
||||
self._set_operation(
|
||||
"provisioning",
|
||||
"Передаём в K1 настройки Wi-Fi одним подтверждённым запросом.",
|
||||
|
||||
Reference in New Issue
Block a user