winrt: simplify force_indicate logic
This simplifies the logic of selecting indications or notifications
and raises an error when neither are supported instead of disabling
notifications/indications.
@@ -760,18 +760,13 @@ class BleakClientWinRT(BaseBleakClient):
await self.stop_notify(characteristic)
characteristic_obj = characteristic.obj
- if (
- characteristic_obj.characteristic_properties
- & GattCharacteristicProperties.NOTIFY
- ):
+
+ # If we want to force indicate even when notify is available, also check if the device
+ # actually supports indicate as well.
if kwargs.get("force_indicate", False) and (
characteristic_obj.characteristic_properties
- & GattCharacteristicProperties.INDICATE
+ & GattCharacteristicProperties.NOTIFY
):
- # If we want to force indicate even when notify is available, also check if the device
- # actually supports indicate as well.
- cccd = GattClientCharacteristicConfigurationDescriptorValue.INDICATE
- else:
cccd = GattClientCharacteristicConfigurationDescriptorValue.NOTIFY
elif (
characteristic_obj.characteristic_properties
@@ -779,7 +774,9 @@ class BleakClientWinRT(BaseBleakClient):
):
cccd = GattClientCharacteristicConfigurationDescriptorValue.INDICATE
else:
- cccd = GattClientCharacteristicConfigurationDescriptorValue.NONE
+ raise BleakError(
+ "characteristic does not support notifications or indications"
+ )
fcn = _notification_wrapper(bleak_callback, asyncio.get_event_loop())
event_handler_token = characteristic_obj.add_value_changed(fcn)
