core
core copied to clipboard
Fix incorrect unique_id for BLE HomeKit devices
Proposed change
The unique_id of the config entry is supposed to be a normalized version of AccessoryPairingID for all transports. That allows a BLE pairing to be upgraded to a Thread pairing, and for discoveries to be correctly de-duplicated when a device is discoverable by Thread and by BLE.
We were however incorrectly using the BLE MAC address.
Luckily the entity map, the entity registry and the device registry were correctly using AccessoryPairingID, so we only have to add a migration for config entries.
(Strictly speaking, this was tested alongside https://github.com/Jc2k/aiohomekit/pull/282 and really they should be merged together although that is not required).
Type of change
- [ ] Dependency upgrade
- [x] Bugfix (non-breaking change which fixes an issue)
- [ ] New integration (thank you!)
- [ ] New feature (which adds functionality to an existing integration)
- [ ] Deprecation (breaking change to happen in the future)
- [ ] Breaking change (fix/feature causing existing functionality to break)
- [ ] Code quality improvements to existing code or addition of tests
Additional information
- This PR fixes or closes issue: fixes #
- This PR is related to issue:
- Link to documentation pull request:
Checklist
- [x] The code change is tested and works locally.
- [x] Local tests pass. Your PR cannot be merged unless tests pass
- [x] There is no commented out code in this PR.
- [x] I have followed the development checklist
- [x] The code has been formatted using Black (
black --fast homeassistant tests) - [x] Tests have been added to verify that the new code works.
If user exposed functionality or configuration variables are added/changed:
- [ ] Documentation added/updated for www.home-assistant.io
If the code communicates with devices, web services, or third-party tools:
- [ ] The manifest file has all fields filled out correctly.
Updated and included derived files by running:python3 -m script.hassfest. - [ ] New or updated dependencies have been added to
requirements_all.txt.
Updated by runningpython3 -m script.gen_requirements_all. - [ ] For the updated dependencies - a link to the changelog, or at minimum a diff between library versions is added to the PR description.
- [ ] Untested files have been added to
.coveragerc.
To help with the load of incoming pull requests:
- [ ] I have reviewed two other open pull requests in this repository.
Hey there @bdraco, mind taking a look at this pull request as it has been labeled with an integration (homekit_controller) you are listed as a code owner for? Thanks!
Code owner commands
Code owners of homekit_controller can trigger bot actions by commenting:
@home-assistant closeCloses the issue.@home-assistant rename Awesome new titleChange the title of the issue.@home-assistant reopenReopen the issue.@home-assistant unassign homekit_controllerRemoves the current integration label and assignees on the issue, add the integration domain after the command.
Testing with a nanoleaf bulb + everything already paired
before
{
"entry_id": "c2049ac24a6d6eec4fb7eebd00b20e45",
"version": 1,
"domain": "homekit_controller",
"title": "Nan",
"data": {
"AccessoryPairingID": "ED:06:2C:C7:EA:E2",
"AccessoryLTPK": "xx",
"iOSPairingId": "xx",
"iOSDeviceLTSK": "xx",
"iOSDeviceLTPK": "xx",
"AccessoryAddress": "E7:E4:48:E0:D0:85",
"Connection": "BLE"
},
"options": {},
"pref_disable_new_entities": false,
"pref_disable_polling": false,
"source": "bluetooth",
"unique_id": "E7:E4:48:E0:D0:85",
"disabled_by": null
}
]
verified ED:06:2C:C7:EA:E2 is the value in the entity map 👍
after .. Note its lower case
{
"entry_id": "c2049ac24a6d6eec4fb7eebd00b20e45",
"version": 1,
"domain": "homekit_controller",
"title": "Nan",
"data": {
"AccessoryPairingID": "ED:06:2C:C7:EA:E2",
"AccessoryLTPK": "xx",
"iOSPairingId": "xx",
"iOSDeviceLTSK": "xx",
"iOSDeviceLTPK": "xx",
"AccessoryAddress": "E7:E4:48:E0:D0:85",
"Connection": "BLE"
},
"options": {},
"pref_disable_new_entities": false,
"pref_disable_polling": false,
"source": "bluetooth",
"unique_id": "ed:06:2c:c7:ea:e2",
"disabled_by": null
}
Verified all ip accessories are lowercase
All working as expected 👍
We could take this opportunity to migrate everything to upper case (the migration would just work if we changed the normalise function) but I am not fussed either way.
We could take this opportunity to migrate everything to upper case (the migration would just work if we changed the normalise function) but I am not fussed either way.
I think lowercase is just fine. Comment was purely meant as an observation in case the behavior was unexpected and I needed to check it so I didn't forget while checking other things as I had not yet validated that it was expected by comparing with other existing entries.
retested 👍