Add support for pairing callbacks
Add support for pairing callbacks.
This is based on:
- https://github.com/hbldh/bleak/pull/1133
- https://github.com/hbldh/bleak/pull/1100
@tgagneret-embedded Thanks for picking this back up. We have a lot of Home Assistant users who are really excited about having this feature. As soon as this gets going, I'll work on adding support to ESPHome as well.
FYI @dlech , I drafted a PR to remove the duplicate code for pairing. I need to test the "Just works" pairing, I'm not sure I have a device to do test this.
https://github.com/hbldh/bleak/pull/1868
@tgagneret-embedded I opened a PR against your feature/pairing branch with the changes that @dlech requested here (except the one about moving the _pair method into a separate PR). Hope that helps.
https://github.com/tgagneret-embedded/bleak/pull/1
Codecov Report
:x: Patch coverage is 43.70861% with 85 lines in your changes missing coverage. Please review.
:white_check_mark: Project coverage is 34.98%. Comparing base (38892ff) to head (f76bda0).
Additional details and impacted files
@@ Coverage Diff @@
## develop #1864 +/- ##
===========================================
+ Coverage 34.60% 34.98% +0.37%
===========================================
Files 37 39 +2
Lines 3849 3993 +144
Branches 476 484 +8
===========================================
+ Hits 1332 1397 +65
- Misses 2490 2567 +77
- Partials 27 29 +2
| Flag | Coverage Δ | |
|---|---|---|
| macos-latest-py3.10 | 16.95% <7.94%> (-0.33%) |
:arrow_down: |
| macos-latest-py3.11 | 16.95% <7.94%> (-0.33%) |
:arrow_down: |
| macos-latest-py3.12 | 16.95% <7.94%> (-0.33%) |
:arrow_down: |
| macos-latest-py3.13 | 16.95% <7.94%> (-0.33%) |
:arrow_down: |
| macos-latest-py3.14 | 16.72% <7.94%> (-0.33%) |
:arrow_down: |
| ubuntu-latest-py3.10 | 23.11% <43.70%> (+0.82%) |
:arrow_up: |
| ubuntu-latest-py3.11 | 23.11% <43.70%> (+0.82%) |
:arrow_up: |
| ubuntu-latest-py3.12 | 23.11% <43.70%> (+0.82%) |
:arrow_up: |
| ubuntu-latest-py3.13 | 23.11% <43.70%> (+0.82%) |
:arrow_up: |
| ubuntu-latest-py3.14 | 21.19% <43.70%> (+0.91%) |
:arrow_up: |
| windows-latest-py3.10 | 16.90% <7.94%> (-0.33%) |
:arrow_down: |
| windows-latest-py3.11 | 16.90% <7.94%> (-0.33%) |
:arrow_down: |
| windows-latest-py3.12 | 16.90% <7.94%> (-0.33%) |
:arrow_down: |
| windows-latest-py3.13 | 16.90% <7.94%> (-0.33%) |
:arrow_down: |
| windows-latest-py3.14 | 16.61% <7.94%> (-0.32%) |
:arrow_down: |
Flags with carried forward coverage won't be shown. Click here to find out more.
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.
@tgagneret-embedded I opened a PR against your
feature/pairingbranch with the changes that @dlech requested here (except the one about moving the_pairmethod into a separate PR). Hope that helps.
I'm not sure why you changed https://github.com/tgagneret-embedded/bleak/pull/1/files#diff-aaae8a8eb8ab5923670dec887dfaf4d90aacacf551882aab9a51165920eae38d but I reverted it back since it does not work. Could you give me more detail to make sure it works correctly ?
Thanks
@tgagneret-embedded I opened a PR against your
feature/pairingbranch with the changes that @dlech requested here (except the one about moving the_pairmethod into a separate PR). Hope that helps. tgagneret-embedded#1I'm not sure why you changed https://github.com/tgagneret-embedded/bleak/pull/1/files#diff-aaae8a8eb8ab5923670dec887dfaf4d90aacacf551882aab9a51165920eae38d but I reverted it back since it does not work. Could you give me more detail to make sure it works correctly ?
Thanks
@dlech requested this change in this review comment: https://github.com/hbldh/bleak/pull/1864#discussion_r2572255647
The _get_device_property does the same thing as the method in question, but throws more helpful error messages in case of keys not being found in the dictionaries.
But it's possible I might have done something wrong when refactoring. I'll have another look.
@tgagneret-embedded I opened a PR against your
feature/pairingbranch with the changes that @dlech requested here (except the one about moving the_pairmethod into a separate PR). Hope that helps. tgagneret-embedded#1I'm not sure why you changed https://github.com/tgagneret-embedded/bleak/pull/1/files#diff-aaae8a8eb8ab5923670dec887dfaf4d90aacacf551882aab9a51165920eae38d but I reverted it back since it does not work. Could you give me more detail to make sure it works correctly ? Thanks
@dlech requested this change in this review comment: #1864 (comment) The
_get_device_propertydoes the same thing as the method in question, but throws more helpful error messages in case of keys not being found in the dictionaries. But it's possible I might have done something wrong when refactoring. I'll have another look.
I understand, maybe the naming is not correct. In my case I get the complete Device1 and not only one property of Device1.
@tgagneret-embedded I opened another PR based on your current feature/pairing branch. It should now reuse the _get_device_property method correctly for the Address and Alias attributes.
https://github.com/tgagneret-embedded/bleak/pull/2
@tgagneret-embedded I opened another PR based on your current
feature/pairingbranch. It should now reuse the_get_device_propertymethod correctly for theAddressandAliasattributes. tgagneret-embedded#2
https://github.com/hbldh/bleak/pull/1864#discussion_r2619338870