Skip to content

Commit

Permalink
Adjust read timeout with corebluetooth to 10s
Browse files Browse the repository at this point in the history
5s would result in quite a few random failures with
HomeKit BLE devices because the device would have to
process a large dump of fragments which make it slow
to respond

Fixes Jc2k/aiohomekit#111

Example of code that slows down the device with many
encrypted writes before waiting for a read
https://github.com/Jc2k/aiohomekit/blob/0e22b4e0a16d6b01da2e65bfce99fb01b4c1c7f3/aiohomekit/controller/ble/client.py#L117
  • Loading branch information
bdraco committed Jul 18, 2022
1 parent 90a80fe commit e1c4ced
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Changed
* Add `py.typed` file so mypy discovers Bleak's type annotations
* UUID descriptions updated to 2022-03-16 assigned numbers document
* Replace use of deprecated ``asyncio.get_event_loop()`` in Android backend.
* Adjust default timeout for read_gatt_char with CoreBluetooth to 10s


`0.14.3`_ (2022-04-29)
Expand Down
7 changes: 5 additions & 2 deletions bleak/backends/corebluetooth/PeripheralDelegate.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,10 @@ async def discover_descriptors(self, characteristic: CBCharacteristic) -> NSArra

@objc.python_method
async def read_characteristic(
self, characteristic: CBCharacteristic, use_cached: bool = True
self,
characteristic: CBCharacteristic,
use_cached: bool = True,
timeout: int = 10,
) -> NSData:
if characteristic.value() is not None and use_cached:
return characteristic.value()
Expand All @@ -141,7 +144,7 @@ async def read_characteristic(
self._characteristic_read_futures[characteristic.handle()] = future
try:
self.peripheral.readValueForCharacteristic_(characteristic)
return await asyncio.wait_for(future, timeout=5)
return await asyncio.wait_for(future, timeout=timeout)
finally:
del self._characteristic_read_futures[characteristic.handle()]

Expand Down

0 comments on commit e1c4ced

Please sign in to comment.