Skip to content

Commit

Permalink
p4a notify repair
Browse files Browse the repository at this point in the history
  • Loading branch information
tsiens authored Mar 17, 2024
1 parent 5e294f4 commit eaf3e45
Showing 1 changed file with 24 additions and 9 deletions.
33 changes: 24 additions & 9 deletions bleak/backends/p4android/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -429,13 +429,26 @@ async def write_gatt_descriptor(

async def start_notify(
self,
characteristic: BleakGATTCharacteristic,
char_specifier: Union[BleakGATTCharacteristicP4Android, int, str, uuid.UUID],
callback: NotifyCallback,
**kwargs,
) -> None:
"""
Activate notifications/indications on a characteristic.
Args:
char_specifier (BleakGATTCharacteristicP4Android, int, str or UUID): The characteristic to deactivate
notification/indication on, specified by either integer handle, UUID or
directly by the BleakGATTCharacteristicP4Android object representing it.
"""
if not isinstance(char_specifier, BleakGATTCharacteristicP4Android):
characteristic = self.services.get_characteristic(char_specifier)
else:
characteristic = char_specifier
if not characteristic:
raise BleakCharacteristicNotFoundError(char_specifier)

self._subscriptions[characteristic.handle] = callback

assert self.__gatt is not None
Expand All @@ -445,10 +458,11 @@ async def start_notify(
f"Failed to enable notification for characteristic {characteristic.uuid}"
)

await self.write_gatt_descriptor(
characteristic.notification_descriptor,
defs.BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE,
)
if characteristic.notification_descriptor:
await self.write_gatt_descriptor(
characteristic.notification_descriptor,
defs.BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE,
)

async def stop_notify(
self,
Expand All @@ -469,10 +483,11 @@ async def stop_notify(
if not characteristic:
raise BleakCharacteristicNotFoundError(char_specifier)

await self.write_gatt_descriptor(
characteristic.notification_descriptor,
defs.BluetoothGattDescriptor.DISABLE_NOTIFICATION_VALUE,
)
if characteristic.notification_descriptor:
await self.write_gatt_descriptor(
characteristic.notification_descriptor,
defs.BluetoothGattDescriptor.DISABLE_NOTIFICATION_VALUE,
)

if not self.__gatt.setCharacteristicNotification(characteristic.obj, False):
raise BleakError(
Expand Down

0 comments on commit eaf3e45

Please sign in to comment.