Eagerly shutdown homekit_controller at the stop event (#113650)

This commit is contained in:
J. Nick Koston 2024-03-16 17:15:46 -10:00 committed by GitHub
parent 4d430520a0
commit 309fcb5c30
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 8 additions and 3 deletions

View File

@ -24,6 +24,7 @@ from homeassistant.core import Event, HomeAssistant
from homeassistant.exceptions import ConfigEntryNotReady
from homeassistant.helpers import config_validation as cv, device_registry as dr
from homeassistant.helpers.typing import ConfigType
from homeassistant.util.async_ import create_eager_task
from .config_flow import normalize_hkid
from .connection import HKDevice
@ -80,12 +81,14 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
async def _async_stop_homekit_controller(event: Event) -> None:
await asyncio.gather(
*(
connection.async_unload()
create_eager_task(connection.async_unload())
for connection in hass.data[KNOWN_DEVICES].values()
)
)
hass.bus.async_listen_once(EVENT_HOMEASSISTANT_STOP, _async_stop_homekit_controller)
hass.bus.async_listen_once(
EVENT_HOMEASSISTANT_STOP, _async_stop_homekit_controller, run_immediately=True
)
return True

View File

@ -77,7 +77,9 @@ async def async_get_controller(hass: HomeAssistant) -> Controller:
# Right now _async_stop_homekit_controller is only called on HA exiting
# So we don't have to worry about leaking a callback here.
hass.bus.async_listen_once(EVENT_HOMEASSISTANT_STOP, _async_stop_homekit_controller)
hass.bus.async_listen_once(
EVENT_HOMEASSISTANT_STOP, _async_stop_homekit_controller, run_immediately=True
)
await controller.async_start()