Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Interest in specifying bleak adapter #36

Open
r-bt opened this issue Jun 6, 2023 · 4 comments
Open

Interest in specifying bleak adapter #36

r-bt opened this issue Jun 6, 2023 · 4 comments

Comments

@r-bt
Copy link

r-bt commented Jun 6, 2023

Hey, I was just wanted to check if you'd be interested in a PR to add the option to specify the specific Bluetooth adapter bleak should use?

@superfashi
Copy link
Member

a PR will be more than welcomed. Sorry that I am quite busy recently so cannot reply to issues promptly.

@r-bt
Copy link
Author

r-bt commented Jun 6, 2023

Awesome! Also when I was looking at bleak_adapter.py I noticed that you're passing the bluetooth device address as opposed to the BLEDevice to Bleak Client (e.g. bleak.BleakClient(address)). Is there a reason for this? In the bleak documentation there's a warning against doing so as it (from https://bleak.readthedocs.io/en/latest/api/client.html)

causes the connect() method to implicitly call BleakScanner.discover(). This is known to cause problems when trying to connect to multiple devices at the same time.

and

macOS does not provide access to the Bluetooth address for privacy/ security reasons. Instead it creates a UUID for each Bluetooth device which is used in place of the address on this platform.

which could actually be the cause of #35

@r-bt
Copy link
Author

r-bt commented Jun 7, 2023

Also I'm just wondering about why a new event loop and thread are created for each BleakClient? From digging around this works fine when passing Bluetooth addresses but on macOS if I pass a BLEDevice it gives this error

got Future <Future pending> attached to a different loop

Apparently this is a known issue with Bleak (see hbldh/bleak#1191 and hbldh/bleak#242) so they recommend against having multiple threads and event loops

the design paradigm for bleak is to have multiple connections all under 1 event loop in 1 thread

I can make a PR to address these issues but I just wanted to check if that would be something you'd be interested in?

@superfashi
Copy link
Member

Apparently BLEDevice uses future which attaches with a single event loop.

There is an async branch where I tried to write everything in async fashion. But the API is way too confusing.

I'm interested in your PR on this.

@r-bt r-bt mentioned this issue Jun 13, 2023
2 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants