Fix stale HomeKit characteristic entities after config changes - #177696
Open
jfremy wants to merge 2 commits into
Open
Fix stale HomeKit characteristic entities after config changes#177696jfremy wants to merge 2 commits into
jfremy wants to merge 2 commits into
Conversation
Characteristic-backed entities retained objects from the previous accessory map after a HomeKit configuration refresh, leaving their values stale even though polling updated the replacement map. Resolve the characteristic by IID from the current accessory map before reconfiguring the entity, and remove the entity when the characteristic disappeared. Add an Ecobee regression test that replaces the map with a new current-temperature value. Tests: HomeKit Controller suite (352 passed; unrelated connection retry-count test failed), Ecobee module (7 passed), patch-specific prek hooks (passed), all-files prek hooks (all passed except existing duplicate-module mypy error).
Contributor
|
Hey there @Jc2k, @bdraco, mind taking a look at this pull request as it has been labeled with an integration ( Code owner commandsCode owners of
|
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes stale HomeKit characteristic-backed entities after accessory-map replacement.
Changes:
- Rebinds entities to replacement characteristics during reconfiguration.
- Adds an Ecobee temperature regression test.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
homeassistant/components/homekit_controller/entity.py |
Refreshes characteristic references after configuration changes. |
tests/components/homekit_controller/specific_devices/test_ecobee3.py |
Verifies temperature updates from the replacement accessory map. |
jfremy
marked this pull request as ready for review
July 31, 2026 03:24
Exercise the BaseCharacteristicEntity config-change branches for a removed service and a removed characteristic using replacement accessory maps. Verify the derived sensor is removed in both cases so the rebind callback is fully covered. Tests: - uv run pytest tests/components/homekit_controller/test_sensor.py tests/components/homekit_controller/specific_devices/test_ecobee3.py (24 passed) - uv run prek run --files tests/components/homekit_controller/test_sensor.py (passed)
Contributor
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.
Suppressed comments (1)
tests/components/homekit_controller/test_sensor.py:383
- Exercise the real configuration-change path via
device_config_changedinstead of invoking entity and pairing internals. This bypassesHKDevice.async_update_new_accessories_state, so the test can pass even if normal config notifications no longer remove these entities; the existing helper also avoids coupling toDATA_INSTANCES,_accessories_state, and_async_config_changed.
helper.pairing._accessories_state = AccessoriesState(
accessories, helper.pairing.config_num + 1
)
entity._async_config_changed()
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Breaking change
None.
Proposed change
Context
HomeKit-over-IP climate accessories can stop updating characteristic-backed entities after a reconnect or configuration refresh, while reloading the integration temporarily restores updates. Similar symptoms were reported in #100331 and #102258. #116200 attempted to reduce HomeKit polling and #139550 later reverted those polling changes, but neither addresses stale characteristic references when aiohomekit replaces the accessory map. This fix has kept the affected current-temperature sensor updating for five days on a real AC controller.
Issue
When aiohomekit reports a configuration-number change, it replaces the accessory, service, and characteristic object graph.
HomeKitEntityrebinds its accessory and service during reconfiguration, butBaseCharacteristicEntityonly checks that a characteristic with the same IID exists and then keeps its originalself._charreference. Polling and events update the new characteristic object, while the entity continues reading the old object. It should rebindself._charto the characteristic in the current accessory map before reconfiguring.Fix
In
BaseCharacteristicEntity._async_config_changed, replace the characteristic-disappearance helper with logic that resolves the characteristic by IID from the current accessory map. If the accessory, service, or characteristic no longer exists, remove the entity as before. Otherwise, assign the resolved characteristic toself._charand then run the existing reconfiguration logic to rebuild polling and event subscriptions against the replacement map.Unit test
The Ecobee regression test first creates the current-temperature sensor from an accessory map where the value is
21.8. It then loads a fresh accessory map, changes that map's current-temperature value to22.4, and triggers the existing configuration-change flow that replaces the complete accessory map. The test verifies that the existing sensor now reports22.4; without the fix, it continues reading the old characteristic and remains at21.8.Type of change
Additional information
Checklist
ruff format homeassistant tests)If user exposed functionality or configuration variables are added/changed:
If the code communicates with devices, web services, or third-party tools:
Updated and included derived files by running:
python3 -m script.hassfest.requirements_all.txt.Updated by running:
python3 -m script.gen_requirements_all.To help with the load of incoming pull requests: