Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@bojanpotocnik
Copy link
Contributor

@bojanpotocnik bojanpotocnik commented Jul 7, 2023

Enable using BleakScanner() as an async iterator (async for), combining detection_callback and filtering functionality. BleakScanner().devices() method has the same functionality with option to provide timeout.

I noticed that almost every time I use bleak, one of the first things is to create scanner method which combines discover() and find_device_by_filter() functionality "in concurrent fashion", without the need of using callbacks and queue. This enables reporting scanned devices immediately while giving all the filtering flexibility, even when scanning for multiple devices with different filters.

@bojanpotocnik bojanpotocnik force-pushed the scanner_async_iterator branch 2 times, most recently from 7e5b4a1 to 4148a1d Compare July 7, 2023 23:20
Copy link
Collaborator

@dlech dlech left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this. This is something that I have been wanting to add for a while.

I have made some suggestions on how we could simplify the implementation and usage a bit.

@bojanpotocnik bojanpotocnik force-pushed the scanner_async_iterator branch 2 times, most recently from d3fc836 to 4646aea Compare July 10, 2023 20:11
@bojanpotocnik bojanpotocnik requested a review from dlech July 11, 2023 06:05
@bojanpotocnik bojanpotocnik force-pushed the scanner_async_iterator branch from 4646aea to caa2484 Compare July 13, 2023 07:39
@bojanpotocnik bojanpotocnik requested a review from dlech July 13, 2023 08:26
@dlech
Copy link
Collaborator

dlech commented Jul 13, 2023

We also need to expand the "Getting discovered devices and advertisement data" section in scanner.rst so that the new method is included in the documentation.

@dlech dlech marked this pull request as draft July 18, 2023 17:05
@dlech dlech marked this pull request as ready for review July 18, 2023 17:05
@bojanpotocnik bojanpotocnik force-pushed the scanner_async_iterator branch from caa2484 to 32b30e8 Compare July 18, 2023 22:29
@bojanpotocnik bojanpotocnik force-pushed the scanner_async_iterator branch from 32b30e8 to 01c6657 Compare July 18, 2023 23:44
@bojanpotocnik bojanpotocnik force-pushed the scanner_async_iterator branch from 01c6657 to f1c8af1 Compare July 19, 2023 06:31
@bojanpotocnik bojanpotocnik requested a review from dlech July 19, 2023 06:31
@bojanpotocnik
Copy link
Contributor Author

The last two comments are here so you can see the alternative implementations - I can add any of them back if desired.

@bojanpotocnik bojanpotocnik force-pushed the scanner_async_iterator branch 2 times, most recently from 2cb1bb0 to b8d7a38 Compare July 21, 2023 14:57
Add `advertisement_data()` async iterator method to the `BleakScanner`
which yields results of the ongoing scan.
@bojanpotocnik bojanpotocnik force-pushed the scanner_async_iterator branch from b8d7a38 to 883892e Compare July 23, 2023 07:38
@bojanpotocnik bojanpotocnik requested a review from dlech July 23, 2023 07:38
@dlech dlech merged commit 8a720ab into hbldh:develop Jul 23, 2023
@dlech
Copy link
Collaborator

dlech commented Jul 23, 2023

Thanks for all of the work on this! It was more complicated than I expected.

@bojanpotocnik bojanpotocnik deleted the scanner_async_iterator branch July 24, 2023 05:52
@dlech dlech mentioned this pull request Sep 2, 2023
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

Successfully merging this pull request may close these issues.

2 participants