Increment the homekit config version when restarting (#47209)

If an entity changes between restart the iOS/controller
device may have cached the old chars for the accessory.
To force the iOS/controller to reload the chars, we
increment the config version when Home Assistant restarts
This commit is contained in:
J. Nick Koston 2021-02-28 22:42:09 -06:00 committed by GitHub
parent 0e9f2dc272
commit 853da40e70
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 2 deletions

View File

@ -491,8 +491,11 @@ class HomeKit:
# as pyhap uses a random one until state is restored
if os.path.exists(persist_file):
self.driver.load()
else:
self.driver.persist()
self.driver.state.config_version += 1
if self.driver.state.config_version > 65535:
self.driver.state.config_version = 1
self.driver.persist()
def reset_accessories(self, entity_ids):
"""Reset the accessory to load the latest configuration."""

View File

@ -540,6 +540,7 @@ async def test_homekit_start(hass, hk_driver, device_reg):
assert (device_registry.CONNECTION_NETWORK_MAC, formatted_mac) in device.connections
assert len(device_reg.devices) == 1
assert homekit.driver.state.config_version == 2
async def test_homekit_start_with_a_broken_accessory(hass, hk_driver, mock_zeroconf):