Ensure HomeKit accessories are started again after reset (#53372)
This commit is contained in:
parent
87e41e807c
commit
0f15d2bf19
2 changed files with 14 additions and 4 deletions
|
@ -557,6 +557,7 @@ class HomeKit:
|
|||
return
|
||||
if new_acc := self._async_create_single_accessory([state]):
|
||||
self.driver.accessory = new_acc
|
||||
self.hass.async_add_job(new_acc.run)
|
||||
await self.async_config_changed()
|
||||
|
||||
async def async_reset_accessories_in_bridge_mode(self, entity_ids):
|
||||
|
@ -586,7 +587,9 @@ class HomeKit:
|
|||
await self.async_config_changed()
|
||||
await asyncio.sleep(_HOMEKIT_CONFIG_UPDATE_TIME)
|
||||
for state in new:
|
||||
self.add_bridge_accessory(state)
|
||||
acc = self.add_bridge_accessory(state)
|
||||
if acc:
|
||||
self.hass.async_add_job(acc.run)
|
||||
await self.async_config_changed()
|
||||
|
||||
async def async_config_changed(self):
|
||||
|
@ -625,10 +628,12 @@ class HomeKit:
|
|||
acc = get_accessory(self.hass, self.driver, state, aid, conf)
|
||||
if acc is not None:
|
||||
self.bridge.add_accessory(acc)
|
||||
return acc
|
||||
except Exception: # pylint: disable=broad-except
|
||||
_LOGGER.exception(
|
||||
"Failed to create a HomeKit accessory for %s", state.entity_id
|
||||
)
|
||||
return None
|
||||
|
||||
def remove_bridge_accessory(self, aid):
|
||||
"""Try adding accessory to bridge if configured beforehand."""
|
||||
|
|
|
@ -646,7 +646,9 @@ async def test_homekit_reset_accessories(hass, mock_zeroconf):
|
|||
"pyhap.accessory_driver.AccessoryDriver.config_changed"
|
||||
) as hk_driver_config_changed, patch(
|
||||
"pyhap.accessory_driver.AccessoryDriver.async_start"
|
||||
), patch.object(
|
||||
), patch(
|
||||
f"{PATH_HOMEKIT}.accessories.HomeAccessory.run"
|
||||
) as mock_run, patch.object(
|
||||
homekit_base, "_HOMEKIT_CONFIG_UPDATE_TIME", 0
|
||||
):
|
||||
await async_init_entry(hass, entry)
|
||||
|
@ -667,6 +669,7 @@ async def test_homekit_reset_accessories(hass, mock_zeroconf):
|
|||
|
||||
assert hk_driver_config_changed.call_count == 2
|
||||
assert mock_add_accessory.called
|
||||
assert mock_run.called
|
||||
homekit.status = STATUS_READY
|
||||
|
||||
|
||||
|
@ -923,7 +926,9 @@ async def test_homekit_reset_single_accessory(hass, mock_zeroconf):
|
|||
"pyhap.accessory_driver.AccessoryDriver.config_changed"
|
||||
) as hk_driver_config_changed, patch(
|
||||
"pyhap.accessory_driver.AccessoryDriver.async_start"
|
||||
):
|
||||
), patch(
|
||||
f"{PATH_HOMEKIT}.accessories.HomeAccessory.run"
|
||||
) as mock_run:
|
||||
await async_init_entry(hass, entry)
|
||||
|
||||
homekit.status = STATUS_RUNNING
|
||||
|
@ -938,7 +943,7 @@ async def test_homekit_reset_single_accessory(hass, mock_zeroconf):
|
|||
blocking=True,
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert mock_run.called
|
||||
assert hk_driver_config_changed.call_count == 1
|
||||
homekit.status = STATUS_READY
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue