mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-04-21 09:39:02 +00:00
feat(core): BLE pairing flow
This commit is contained in:
parent
5a18b9542a
commit
f119a0fffa
@ -1,4 +1,6 @@
|
||||
import storage.device
|
||||
from trezorio import ble
|
||||
|
||||
import trezorui_api
|
||||
from trezor import utils
|
||||
from trezor.ui.layouts import raise_if_not_confirmed
|
||||
@ -8,7 +10,7 @@ async def handle_device_menu() -> None:
|
||||
# MOCK DATA
|
||||
failed_backup = True
|
||||
battery_percentage = 22
|
||||
paired_devices = ["Trezor Suite"]
|
||||
paired_devices = ["Trezor Suite"] if ble.is_connected() else []
|
||||
# ###
|
||||
firmware_version = ".".join(map(str, utils.VERSION))
|
||||
device_name = storage.device.get_label() or "Trezor"
|
||||
@ -27,5 +29,11 @@ async def handle_device_menu() -> None:
|
||||
from apps.management.ble.pair_new_device import pair_new_device
|
||||
|
||||
await pair_new_device()
|
||||
elif menu_result == "DeviceDisconnect":
|
||||
from trezor.messages import BleUnpair
|
||||
|
||||
from apps.management.ble.unpair import unpair
|
||||
|
||||
await unpair(BleUnpair(all=False))
|
||||
else:
|
||||
raise RuntimeError(f"Unknown menu {menu_result}")
|
||||
|
@ -1,17 +1,40 @@
|
||||
from trezorio import ble
|
||||
|
||||
import trezorui_api
|
||||
from trezor.ui.layouts import interact
|
||||
from storage import device as storage_device
|
||||
from trezor.ui.layouts import CONFIRMED, raise_if_not_confirmed
|
||||
from trezor.wire import ActionCancelled
|
||||
|
||||
|
||||
def _end_pairing() -> None:
|
||||
if ble.peer_count() > 0:
|
||||
ble.start_advertising(True, storage_device.get_label())
|
||||
else:
|
||||
ble.stop_advertising()
|
||||
|
||||
|
||||
async def pair_new_device() -> None:
|
||||
label = "Trezor T3W1"
|
||||
await interact(
|
||||
trezorui_api.show_pairing_device_name(device_name=label),
|
||||
None,
|
||||
raise_on_cancel=None, # for UI testing
|
||||
)
|
||||
label = storage_device.get_label() or "Trezor T3W1"
|
||||
ble.start_advertising(False, label)
|
||||
try:
|
||||
code = await raise_if_not_confirmed(
|
||||
trezorui_api.show_pairing_device_name(
|
||||
device_name=label,
|
||||
),
|
||||
None,
|
||||
)
|
||||
if not isinstance(code, int):
|
||||
raise ActionCancelled
|
||||
|
||||
code = 12345
|
||||
await interact(
|
||||
trezorui_api.show_pairing_code(code=f"{code:0>6}"),
|
||||
None,
|
||||
)
|
||||
result = await raise_if_not_confirmed(
|
||||
trezorui_api.show_pairing_code(
|
||||
code=f"{code:0>6}",
|
||||
),
|
||||
None,
|
||||
)
|
||||
if result is CONFIRMED:
|
||||
ble.allow_pairing(code)
|
||||
else:
|
||||
ble.reject_pairing()
|
||||
finally:
|
||||
_end_pairing()
|
||||
|
Loading…
Reference in New Issue
Block a user