Skip to content

Commit

Permalink
winrt: implement BleakScanner service_uuids kwarg
Browse files Browse the repository at this point in the history
This provides an implementation for the BleakScanner service_uuids
kwarg in the WinRT backend. As explained in the code comment, it is
not possible to use the OS-provided filter mechanism for technical
reasons.

Fixes #230
  • Loading branch information
dlech committed Dec 6, 2021
1 parent 3f26be6 commit afe2b85
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Added
-----

* Added ``service_uuids`` kwarg to ``BleakScanner``. This can be used to work
around issue of scanning not working on macOS 12. Issue #635.
around issue of scanning not working on macOS 12. Fixes #230. Works around #635.

Changed
-------
Expand Down
14 changes: 14 additions & 0 deletions bleak/backends/winrt/scanner.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,20 @@ def _received_handler(
# Get a "BLEDevice" from parse_event args
device = self._parse_adv_data(raw_data)

# On Windows, we have to fake service UUID filtering. If we were to pass
# a BluetoothLEAdvertisementFilter to the BluetoothLEAdvertisementWatcher
# with the service UUIDs appropriately set, we would no longer receive
# scan response data (which commonly contains the local device name).
# So we have to do it like this instead.

if self._service_uuids:
for uuid in device.metadata["uuids"]:
if uuid in self._service_uuids:
break
else:
# if there were no matching service uuids, the don't call the callback
return

service_data = {}

# Decode service data
Expand Down

0 comments on commit afe2b85

Please sign in to comment.