Skip to content

Commit

Permalink
Added force_notify keyword argument for WinRT backend client's `sta…
Browse files Browse the repository at this point in the history
…rt_notify` method.

Fixes #526
  • Loading branch information
hbldh committed Aug 10, 2021
1 parent ca647de commit c569a33
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Added
~~~~~
* Allow 16-bit UUID string arguments to ``get_service()`` and ``get_characteristic()``.
* Added ``register_uuids()`` to augment the uuid-to-description mapping.
* Added ``force_notify`` keyword argument for WinRT backend client's ``start_notify`` method. Fixes #526.

Fixed
~~~~~
Expand Down
14 changes: 13 additions & 1 deletion bleak/backends/winrt/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -734,6 +734,10 @@ def callback(sender, data):
UUID or directly by the BleakGATTCharacteristic object representing it.
callback (function): The function to be called on notification.
Keyword Args:
force_notify (bool): If this is set to True, then Bleak will set up notification request instead of a
indication request, given that the characteristic supports notifications as well as indications.
"""
if inspect.iscoroutinefunction(callback):

Expand All @@ -758,7 +762,15 @@ def bleak_callback(s, d):
characteristic_obj.characteristic_properties
& GattCharacteristicProperties.INDICATE
):
cccd = GattClientCharacteristicConfigurationDescriptorValue.INDICATE
if kwargs.get("force_notify", False) and (
characteristic_obj.characteristic_properties
& GattCharacteristicProperties.NOTIFY
):
# If we want to force notify even when indicate is available, also check if the device
# actually supports notify as well.
cccd = GattClientCharacteristicConfigurationDescriptorValue.INDICATE
else:
cccd = GattClientCharacteristicConfigurationDescriptorValue.INDICATE
elif (
characteristic_obj.characteristic_properties
& GattCharacteristicProperties.NOTIFY
Expand Down

0 comments on commit c569a33

Please sign in to comment.