bleak icon indicating copy to clipboard operation
bleak copied to clipboard

Dynamically select default BlueZ adapter if not provided

Open bojanpotocnik opened this issue 3 years ago • 1 comments

If specific adapter is not provided as a parameter, default adapter is selected automatically as a first adapter out of all powered adapter in the system, instead of using hardcoded "hci0".

Additional logic to only choose powered adapters is added for two convenience reasons:

  • If adapter is powered down but selected for operation, Bleak will not power it on. Consequently, org.bluez.Error.NotReady error will occur anyway when trying to use such adapter.
  • If user has multiple adapters present on the system but currently uses only some while others are powered off, it most probably wants to use one of the active adapters.

Solves #513

bojanpotocnik avatar Apr 22 '21 16:04 bojanpotocnik

We have made some changes recently that should help unblock this PR. There is now a BlueZManager with a global instance that we can use to get the current BlueZ D-Bus properties at any time (well almost any time - it must be in an async function). We should be able to add the proposed get_default_adapter as a method to this class and use it in BleackScanner.start() and BleakClient.connect() as needed.

dlech avatar Jul 25 '22 21:07 dlech

I made the required changes to get this merged. Thanks for the contribution!

dlech avatar Sep 12 '22 18:09 dlech