Problem
create_ble(pin=...) / BLEConnection(pin=...) stores the PIN and calls client.pair() (ble_cx.py:113-116), but on BlueZ the default agent (no input/output) can't answer the RequestPasskey/RequestPinCode that pair() triggers. Pairing fails with AuthenticationFailed, the connection logs a warning and continues (ble_cx.py:118-122), so pin= is effectively a no-op on Linux/BlueZ today.
This is masked because tests/test_ble_pin_pairing.py mocks pair() and never exercises a real agent.
Fix
Register a short-lived org.bluez.Agent1 (via dbus_fast) that answers RequestPasskey/RequestPinCode with the configured PIN, around the pair() call in ble_cx.py:
- gate on
if pin is not None
- lazy-import
dbus_fast (already pulled in by bleak on Linux; no cost elsewhere)
- register before
pair(), unregister in finally
- degrade gracefully where DBus/BlueZ isn't present (non-Linux), same as today
A working reference implementation already exists in the Home Assistant integration PR meshcore-dev/meshcore-ha#294 (ble_pairing_agent.py). It's pure BLE-transport plumbing with no HA dependencies, so it belongs here next to pair() rather than in each consumer. Once it lands, meshcore-ha (and meshcore-cli, bots, the SDK's own examples/ble_pin_pairing_example.py) just pass pin= and get working passkey pairing.
@drewmccal authored the reference implementation and is best placed to port it; happy to review.
Affects
Problem
create_ble(pin=...)/BLEConnection(pin=...)stores the PIN and callsclient.pair()(ble_cx.py:113-116), but on BlueZ the default agent (no input/output) can't answer theRequestPasskey/RequestPinCodethatpair()triggers. Pairing fails withAuthenticationFailed, the connection logs a warning and continues (ble_cx.py:118-122), sopin=is effectively a no-op on Linux/BlueZ today.This is masked because
tests/test_ble_pin_pairing.pymockspair()and never exercises a real agent.Fix
Register a short-lived
org.bluez.Agent1(viadbus_fast) that answersRequestPasskey/RequestPinCodewith the configured PIN, around thepair()call inble_cx.py:if pin is not Nonedbus_fast(already pulled in bybleakon Linux; no cost elsewhere)pair(), unregister infinallyA working reference implementation already exists in the Home Assistant integration PR meshcore-dev/meshcore-ha#294 (
ble_pairing_agent.py). It's pure BLE-transport plumbing with no HA dependencies, so it belongs here next topair()rather than in each consumer. Once it lands, meshcore-ha (and meshcore-cli, bots, the SDK's ownexamples/ble_pin_pairing_example.py) just passpin=and get working passkey pairing.@drewmccal authored the reference implementation and is best placed to port it; happy to review.
Affects