Add names to homekit tasks to better track startup problems (#90802)

* Add names to homekit tasks to better track startup problems

* fix test
pull/91079/head^2
J. Nick Koston 2023-04-08 17:13:47 -10:00 committed by GitHub
parent 3be3226aaa
commit d442f2aedb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 9 deletions

View File

@ -597,7 +597,9 @@ class HomeKit:
await self._async_shutdown_accessory(acc)
if new_acc := self._async_create_single_accessory([state]):
self.driver.accessory = new_acc
self.hass.async_add_job(new_acc.run)
self.hass.async_create_task(
new_acc.run(), f"HomeKit Bridge Accessory: {new_acc.entity_id}"
)
await self.async_config_changed()
async def async_reset_accessories_in_bridge_mode(
@ -637,7 +639,9 @@ class HomeKit:
await asyncio.sleep(_HOMEKIT_CONFIG_UPDATE_TIME)
for state in new:
if acc := self.add_bridge_accessory(state):
self.hass.async_add_job(acc.run)
self.hass.async_create_task(
acc.run(), f"HomeKit Bridge Accessory: {acc.entity_id}"
)
await self.async_config_changed()
async def async_config_changed(self) -> None:

View File

@ -815,14 +815,10 @@ async def test_homekit_reset_accessories(
homekit = _mock_homekit(hass, entry, HOMEKIT_MODE_BRIDGE)
with patch(f"{PATH_HOMEKIT}.HomeKit", return_value=homekit), patch(
"pyhap.accessory.Bridge.add_accessory"
) as mock_add_accessory, patch(
"pyhap.accessory_driver.AccessoryDriver.config_changed"
), patch(
"pyhap.accessory_driver.AccessoryDriver.async_start"
), patch(
), patch("pyhap.accessory_driver.AccessoryDriver.async_start"), patch(
f"{PATH_HOMEKIT}.accessories.HomeAccessory.run"
), patch.object(
) as mock_run_accessory, patch.object(
homekit_base, "_HOMEKIT_CONFIG_UPDATE_TIME", 0
):
await async_init_entry(hass, entry)
@ -837,8 +833,9 @@ async def test_homekit_reset_accessories(
blocking=True,
)
await hass.async_block_till_done()
await hass.async_block_till_done()
assert mock_add_accessory.called
assert mock_run_accessory.called
homekit.status = STATUS_READY
await homekit.async_stop()