From 853da40e703933b17646863be373c3b5653de8f0 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Sun, 28 Feb 2021 22:42:09 -0600 Subject: [PATCH] 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 --- homeassistant/components/homekit/__init__.py | 7 +++++-- tests/components/homekit/test_homekit.py | 1 + 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/homeassistant/components/homekit/__init__.py b/homeassistant/components/homekit/__init__.py index 534ea3c6f95..c042872f4cd 100644 --- a/homeassistant/components/homekit/__init__.py +++ b/homeassistant/components/homekit/__init__.py @@ -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.""" diff --git a/tests/components/homekit/test_homekit.py b/tests/components/homekit/test_homekit.py index ec324602684..9ce3e96f06f 100644 --- a/tests/components/homekit/test_homekit.py +++ b/tests/components/homekit/test_homekit.py @@ -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):