Migrate stream listeners to use run_immediately and eager tasks (#113660)

None of these need to a call_soon and can shutdown a bit faster
This commit is contained in:
J. Nick Koston 2024-03-17 06:42:25 -10:00 committed by GitHub
parent 25c4ab070b
commit d9bc09e93a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -35,6 +35,7 @@ from homeassistant.core import Event, HomeAssistant, callback
from homeassistant.exceptions import HomeAssistantError
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.typing import ConfigType
from homeassistant.util.async_ import create_eager_task
from .const import (
ATTR_ENDPOINTS,
@ -212,7 +213,7 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
# Only pass through PyAV log messages if stream logging is above DEBUG
cancel_logging_listener = hass.bus.async_listen(
EVENT_LOGGING_CHANGED, update_pyav_logging
EVENT_LOGGING_CHANGED, update_pyav_logging, run_immediately=True
)
# libav.mp4 and libav.swscaler have a few unimportant messages that are logged
# at logging.WARNING. Set those Logger levels to logging.ERROR
@ -256,14 +257,14 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
for stream in hass.data[DOMAIN][ATTR_STREAMS]:
stream.dynamic_stream_settings.preload_stream = False
if awaitables := [
asyncio.create_task(stream.stop())
create_eager_task(stream.stop())
for stream in hass.data[DOMAIN][ATTR_STREAMS]
]:
await asyncio.wait(awaitables)
_LOGGER.debug("Stopped stream workers")
cancel_logging_listener()
hass.bus.async_listen_once(EVENT_HOMEASSISTANT_STOP, shutdown)
hass.bus.async_listen_once(EVENT_HOMEASSISTANT_STOP, shutdown, run_immediately=True)
return True