bleak
bleak copied to clipboard
Dynamically select default BlueZ adapter if not provided
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
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.
I made the required changes to get this merged. Thanks for the contribution!