Skip to content

fix(homekit): work with HAP-python 5.2 as well as 5.0 - #241

Merged
lollox80 merged 1 commit into
mainfrom
fix/hap-python-5.2-compat
Dec 2, 2026
Merged

lollox80 merged 1 commit into
mainfrom
fix/hap-python-5.2-compat

Conversation

@lollox80

@lollox80 lollox80 commented Dec 1, 2026

Copy link
Copy Markdown
Collaborator

What and why

#238 moves HAP-python from 5.0.0 to 5.2.0, the version Home Assistant core is moving to (2026.12), and two tests fail. One of the two failures is a real bug: with 5.2 pair-setup stops at M1 with a 500, so the HomeKit doorbell cannot be paired.

5.0: srp_verifier is a plain attribute that setup_srp_verifier() assigns.
5.2: it is a read-only property over _srp_verifier, so our assignment of the counting verifier raises AttributeError.

_Driver now has its own srp_verifier property, with a setter, over _srp_verifier. It serves both versions without checking the version number. The other failure was only in the tests: the _driver() helper skips __init__ and lacked accessory, which 5.2's unpair() reads.

pyhap 5.2's own lockout

From 5.2 pyhap refuses pair-setup for 60 s after five wrong codes. Our count of ten wrong codes in a row, which changes the setup code and notifies the user, is unchanged:

  • A refused attempt reaches no verifier, so it neither counts nor resets.
  • pyhap's pause does not reset our count: in an uninterrupted run of wrong codes the tenth still changes the setup code, after one pause.
  • The pause applies to every pair-setup step, so another client's failures can also interrupt a pairing in progress.
  • At the tenth failure pyhap's second pause starts as well, so pairing with the new code has to wait up to 60 s.
  • At the fifth wrong code pyhap only logs a warning; we still notify only at the tenth.

Tests

  • Pair-setup M1 to M4 with a real SRP client through pyhap's HTTP handler: wrong code counted, right code accepted, same session key on both sides.
  • Ten wrong codes across pyhap's lockout.
  • _Driver built by the installed pyhap's __init__.
  • Without the fix, these three and test_pyhaps_verifier_is_the_counting_one fail with 5.2.0.

Tested on Windows 11, Python 3.13, with both versions:

HAP-python 5.0.0: CHECK VERDE, 2504 passed, 32 skipped, coverage 97.22%
HAP-python 5.2.0: CHECK VERDE, 2504 passed, 32 skipped, coverage 97.21%

Not tested: pairing with a real iPhone, M5/M6, and a running Home Assistant 2026.12. Test at the intercom: not needed (no SIP, media, door or registration code is touched).

Changelog: Bug fixes - HomeKit pairing works with HAP-python 5.2 (Home Assistant 2026.12).

HAP-python 5.2 makes AccessoryDriver.srp_verifier a read-only property over
_srp_verifier. Replacing it with the counting verifier raised AttributeError,
so pair-setup failed at M1. _Driver now has its own property, with a setter,
over the same attribute: 5.0's assignments and 5.2's direct write both end up
there.

The tests now run pair-setup up to M4 with a real SRP client, and the ten
wrong codes across the 60 s lockout that 5.2 adds.
@lollox80
lollox80 added this pull request to the merge queue Dec 2, 2026
Merged via the queue into main with commit d14a09b Dec 2, 2026
7 checks passed
@lollox80
lollox80 deleted the fix/hap-python-5.2-compat branch December 2, 2026 00:36
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.

1 participant