Skip to content

Commit

Permalink
Merge pull request hbldh#541 from dlech/mac-fixes
Browse files Browse the repository at this point in the history
Mac fixes
  • Loading branch information
dlech authored May 26, 2021
2 parents ce63ed4 + 4d53f34 commit 0758552
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ Fixed
* Minor fix for disconnection event handling in BlueZ backend. Fixes #491.
* Corrections for the Philips Hue lamp example. Merged #505
* Fixed BleakClientBlueZDBus.pair() method always returning True. Fixes #503.
* Fixed waiting for notification start/stop to complete in CoreBluetooth backend.
* Fixed write without response on BlueZ < 5.51.


Expand Down
21 changes: 11 additions & 10 deletions bleak/backends/corebluetooth/PeripheralDelegate.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
CBService,
CBCharacteristic,
CBDescriptor,
NSArray,
NSData,
NSError,
)
Expand Down Expand Up @@ -78,9 +79,9 @@ def initWithPeripheral_(self, peripheral: CBPeripheral):

return self

async def discoverServices(self, use_cached=True) -> [CBService]:
async def discoverServices(self, use_cached=True) -> NSArray:
event = self._services_discovered_event
if event.is_set() and (use_cached is True):
if event.is_set() and use_cached:
return self.peripheral.services()

event.clear()
Expand All @@ -92,8 +93,8 @@ async def discoverServices(self, use_cached=True) -> [CBService]:

async def discoverCharacteristics_(
self, service: CBService, use_cached=True
) -> [CBCharacteristic]:
if service.characteristics() is not None and use_cached is True:
) -> NSArray:
if service.characteristics() is not None and use_cached:
return service.characteristics()

sUUID = service.UUID().UUIDString()
Expand All @@ -105,8 +106,8 @@ async def discoverCharacteristics_(

async def discoverDescriptors_(
self, characteristic: CBCharacteristic, use_cached=True
) -> [CBDescriptor]:
if characteristic.descriptors() is not None and use_cached is True:
) -> NSArray:
if characteristic.descriptors() is not None and use_cached:
return characteristic.descriptors()

cUUID = characteristic.UUID().UUIDString()
Expand All @@ -119,7 +120,7 @@ async def discoverDescriptors_(
async def readCharacteristic_(
self, characteristic: CBCharacteristic, use_cached=True
) -> NSData:
if characteristic.value() is not None and use_cached is True:
if characteristic.value() is not None and use_cached:
return characteristic.value()

cUUID = characteristic.UUID().UUIDString()
Expand All @@ -145,7 +146,7 @@ def getMtuSize(self) -> int:
async def readDescriptor_(
self, descriptor: CBDescriptor, use_cached=True
) -> NSData:
if descriptor.value() is not None and use_cached is True:
if descriptor.value() is not None and use_cached:
return descriptor.value()

dUUID = descriptor.UUID().UUIDString()
Expand Down Expand Up @@ -196,7 +197,7 @@ async def startNotify_cb_(
event = self._characteristic_notify_change_events.get_cleared(c_handle)
self.peripheral.setNotifyValue_forCharacteristic_(True, characteristic)
# wait for peripheral_didUpdateNotificationStateForCharacteristic_error_ to set event
# await event.wait()
await event.wait()

return True

Expand All @@ -208,7 +209,7 @@ async def stopNotify_(self, characteristic: CBCharacteristic) -> bool:
event = self._characteristic_notify_change_events.get_cleared(c_handle)
self.peripheral.setNotifyValue_forCharacteristic_(False, characteristic)
# wait for peripheral_didUpdateNotificationStateForCharacteristic_error_ to set event
# await event.wait()
await event.wait()

self._characteristic_notify_callbacks.pop(c_handle)

Expand Down

0 comments on commit 0758552

Please sign in to comment.