Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Notify callback rework #1020

Merged
merged 2 commits into from
Sep 22, 2022
Merged

Notify callback rework #1020

merged 2 commits into from
Sep 22, 2022

Conversation

dlech
Copy link
Collaborator

@dlech dlech commented Sep 22, 2022

Fixes #759.

See commit messages and the issue for details.

* Repeated code for BleakClient.start_notify() is moved from the
  backends to the top-level BleakClient class.
* self._notification_callbacks is removed from BaseBleakClient since
  it is not used in all backends.
* A new (internal) NotifyCallback type alias is added so we don't have
  to repeat the Callable with args multiple times.
* BaseBleakClient.start_notify() arg types are changed.

The battery workaround in the BlueZ backend is removed since the
refactored top-level code will fail before calling the backend code.
Hopefully this should mostly go unnoticed since it will only affect
BlueZ < 5.55 and most users are reporting at least that version on
GitHub.
This is a breaking change that changes the first argument of the
notification callback from the handle to the BleakGATTCharacteristic
object.

This has been a commonly reported problem by users (so much so it is
in our troubleshooting guide which can now be removed) and #759 has
received positive feedback for the breaking change.

It is likely that most users don't use the first argument anyway, so
in those cases, this won't actually be a breaking change.

Fixes: #759
@dlech dlech merged commit be97338 into develop Sep 22, 2022
@dlech dlech deleted the notify-callback-rework branch September 22, 2022 15:42
@chill-git
Copy link

Hello,

I am trying to use this new feature, but not sure how.

My use case: I am connecting to multiple identical devices, and want to set up a notification for the same characteristic in all the devices. Eg. identical temperature sensors in different rooms.
I use start_notify to set up the same callback function, which recovers the data, and should match it to the sensor.

How does the BleakGATTCharacteristic tell me which BLEDevice sent the notification?

Thanks!

@dlech
Copy link
Collaborator Author

dlech commented Oct 30, 2022

There is still some additional work that needs to be done to add a "parent" property to the characteristics and services to be able to get the BleakClient from the characteristic object.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

proposed breaking change: change handle argument type in notification callbacks
2 participants