fix: pass BLEDevice to BleakClient for Bluetooth proxy support#153
Merged
broglep merged 3 commits intomeshtastic:mainfrom Mar 18, 2026
Merged
fix: pass BLEDevice to BleakClient for Bluetooth proxy support#153broglep merged 3 commits intomeshtastic:mainfrom
broglep merged 3 commits intomeshtastic:mainfrom
Conversation
When connecting via an ESPHome Bluetooth proxy, habluetooth requires a BLEDevice object (from HA's scanner cache) to route the connection through the correct proxy backend. Passing a raw address string causes BleakClient.connect() to fail with "No backend with an available connection slot that can reach address" because habluetooth cannot determine which proxy discovered the device. Look up the BLEDevice via async_ble_device_from_address before creating the BluetoothConnection, and pass it through to BleakClient. Falls back to the address string when no BLEDevice is available.
Collaborator
|
LGTM, lint needs small fix, then it can be merged |
990ef30 to
d4a03ef
Compare
Contributor
Author
|
Fixed the lint issue, ready to merge |
Use establish_connection() from bleak-retry-connector instead of calling BleakClient.connect() directly when a BLEDevice is available. This integrates with HA's bluetooth connection slot management and provides automatic retry logic for flaky BLE connections.
Contributor
Author
|
I pushed an additional commit that adds bleak-retry-connector support. When a BLEDevice is available, _connect() now uses establish_connection() instead of calling BleakClient.connect() directly. This resolves the habluetooth warning about unreliable connection establishment. Updated the PR description to cover both changes. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
When connecting to a Meshtastic device via Bluetooth, the integration passes a raw address string to
BleakClient. This causes two issues:habluetoothcannot determine which proxy backend can route the connection, resulting in:habluetoothlogs a warning on every connection:Fix
BLEDeviceviaasync_ble_device_from_address()before creating theBluetoothConnectionBLEDevicethrough toBluetoothConnectionsohabluetoothcan route through the correct proxyestablish_connection()frombleak-retry-connectorwhen aBLEDeviceis available, which handles connection slot management and automatic retriesBleakClient.connect()with the raw address string when noBLEDeviceis availableTesting
Tested with a Meshtastic device connected via Bluetooth and via an ESPHome Bluetooth proxy. Both the
BleakErrorand thehabluetoothwarning no longer appear after this fix.