Join GitHub today
GitHub is home to over 36 million developers working together to host and review code, manage projects, and build software together.Sign up
Add an asyncio Lock around pairing, which cant be used concurrently #21933
I'll need to rebase this after #21901 is merged to fix a conflict in the
I was recently discussing plans for homekit_controller with another user/contributor and realised that there is no explicit locking around the pairing. The homekit_controller Pairing object is not safe to use concurrently, so users with bridges may be experiencing glitches as the asynchronicity trips up the session encryption.
I think there is already some logic around EntityPlatforms that limits concurrent polls (
It seemed like it would be easiest to reason about this if we used the async_ version of the entity API as much as possible and handled the locking needed for the pairing object on the HA side as close to the pairing object as possible. I also wanted an approach that played well with future plans to make an asyncio variant of homekit_python (the upstream we are using for this component).
I have tested this with a homekit_python demoserver.py setup as a fake bridge that has 50 fake light bulbs attached to it, and the tests pass locally.
As I was editing an adjacent function i've removed