You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
BlueZ version (bluetoothctl -v) in case of Linux: 5.66
Description
When creating a BleakClient we can pass a callback to the disconnected_callback parameter to be called when the device disconnects. The type for this parameter is Optional[Callable[[BleakClient], None]] and the documentation for this parameter says "The callable must take one argument, which will be this client object." so I'm assuming the expected parameter is a BleakClient object.
However, the parameter is just forwarded to the backend, where at least in bluez, winrt and corebluetooth it is called with:
In general this is not much of a difference since most methods and properties in BleakClient are just forwarded to the self._backend but in the case of start_notify the backend and BleakClient are different:.
BleakClient.start_notify takes a callback with two arguments (Callable[[BleakGATTCharacteristic, bytearray], Union[None, Awaitable[None]]) but it wraps with a functools.partial or equivalent asyncio thing so that the backend gets a callback with only one argument (the bytearray). Also, the first argument (the characteristic) is converted to a BleakGATTCharacteristic if not already, so passing a string to cli.start_notify gets an error since the backend assumes it was already converted to the backend's type.
What I Did
The example to reproduce this requires to disconnect and reconnect the device. Start the example until you see some "on_notification" messages, then get the device out of range until you see the "on_disconnect" and then back in range so the reconnect triggers.
File ".../test.py", line 10, in on_disconnect_async
await cli.start_notify(CHAR_UUID, on_notification)
File ".../bleak/backends/bluezdbus/client.py", line 873, in start_notify
self._notification_callbacks[characteristic.path] = callback
AttributeError: 'str' object has no attribute 'path'
The text was updated successfully, but these errors were encountered:
bluetoothctl -v
) in case of Linux: 5.66Description
When creating a
BleakClient
we can pass a callback to thedisconnected_callback
parameter to be called when the device disconnects. The type for this parameter isOptional[Callable[[BleakClient], None]]
and the documentation for this parameter says "The callable must take one argument, which will be this client object." so I'm assuming the expected parameter is aBleakClient
object.However, the parameter is just forwarded to the backend, where at least in bluez, winrt and corebluetooth it is called with:
where
self
is the backend type.In general this is not much of a difference since most methods and properties in
BleakClient
are just forwarded to theself._backend
but in the case ofstart_notify
the backend andBleakClient
are different:.BleakClient.start_notify
takes a callback with two arguments (Callable[[BleakGATTCharacteristic, bytearray], Union[None, Awaitable[None]]
) but it wraps with afunctools.partial
or equivalent asyncio thing so that the backend gets a callback with only one argument (thebytearray
). Also, the first argument (the characteristic) is converted to a BleakGATTCharacteristic if not already, so passing a string tocli.start_notify
gets an error since the backend assumes it was already converted to the backend's type.What I Did
The example to reproduce this requires to disconnect and reconnect the device. Start the example until you see some "on_notification" messages, then get the device out of range until you see the "on_disconnect" and then back in range so the reconnect triggers.
The output is roughly:
followed by this exception:
The text was updated successfully, but these errors were encountered: