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

Fix minor WinRT backend bugs #537

Merged
merged 3 commits into from
May 13, 2021
Merged

Conversation

devanlai
Copy link
Contributor

This pull request addresses some minor issues I found while trying out the WinRT backend, as documented in #536. After some gentle ribbing from @dlech, I decided to roll these changes up into a pull request.

For me, these changes were sufficient to allow me to scan for a custom BLE device using the local name as a scan filter, connect to it, and interact with the characteristics.

I ended up making three changes:

  1. Updating the WinRT backend to implement the discovered_devices property instead of the old get_discovered_devices() method.
  2. Fixing an assertion in the UUID construction when the device has 128-bit service UUIDs.
  3. Fixing a typo in the advertisement filter attribute of watcher objects

For reference, I was able to filter on the local name with a variant on the following code:

from winrt.windows.devices.bluetooth.advertisement import BluetoothLEAdvertisementFilter, BluetoothLEAdvertisementBytePattern
from winrt.windows.security.cryptography import CryptographicBuffer

# Match on the complete local name field (0x09)
local_name = "mydevice"
adv_filter = BluetoothLEAdvertisementFilter()
local_name_bytes = CryptographicBuffer.create_from_byte_array(list(bytearray(local_name.encode("ascii"))))
name_byte_pattern = BluetoothLEAdvertisementBytePattern(0x09, 0, local_name_bytes)
adv_filter.byte_patterns.append(name_byte_pattern)

devices = await bleak.BleakScanner.discover(AdvertisementFilter=adv_filter)

If you'd prefer, I can squash these changes into a single commit.

Bring the winrt backend in line with other backends now that
get_discovered_devices is replaced by discovered_devices.
Convert to bytes before passing in data to the UUID constructor
@dlech dlech merged commit 5e0a35a into hbldh:develop May 13, 2021
@dlech
Copy link
Collaborator

dlech commented May 13, 2021

Looks good to me. Thanks for the fixes!

@devanlai devanlai deleted the winrt-minor-fixes branch May 17, 2021 23:55
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