mirror of
https://github.com/home-assistant/core.git
synced 2025-07-24 21:57:51 +00:00
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:
parent
25c4ab070b
commit
d9bc09e93a
@ -35,6 +35,7 @@ from homeassistant.core import Event, HomeAssistant, callback
|
|||||||
from homeassistant.exceptions import HomeAssistantError
|
from homeassistant.exceptions import HomeAssistantError
|
||||||
import homeassistant.helpers.config_validation as cv
|
import homeassistant.helpers.config_validation as cv
|
||||||
from homeassistant.helpers.typing import ConfigType
|
from homeassistant.helpers.typing import ConfigType
|
||||||
|
from homeassistant.util.async_ import create_eager_task
|
||||||
|
|
||||||
from .const import (
|
from .const import (
|
||||||
ATTR_ENDPOINTS,
|
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
|
# Only pass through PyAV log messages if stream logging is above DEBUG
|
||||||
cancel_logging_listener = hass.bus.async_listen(
|
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
|
# libav.mp4 and libav.swscaler have a few unimportant messages that are logged
|
||||||
# at logging.WARNING. Set those Logger levels to logging.ERROR
|
# 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]:
|
for stream in hass.data[DOMAIN][ATTR_STREAMS]:
|
||||||
stream.dynamic_stream_settings.preload_stream = False
|
stream.dynamic_stream_settings.preload_stream = False
|
||||||
if awaitables := [
|
if awaitables := [
|
||||||
asyncio.create_task(stream.stop())
|
create_eager_task(stream.stop())
|
||||||
for stream in hass.data[DOMAIN][ATTR_STREAMS]
|
for stream in hass.data[DOMAIN][ATTR_STREAMS]
|
||||||
]:
|
]:
|
||||||
await asyncio.wait(awaitables)
|
await asyncio.wait(awaitables)
|
||||||
_LOGGER.debug("Stopped stream workers")
|
_LOGGER.debug("Stopped stream workers")
|
||||||
cancel_logging_listener()
|
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
|
return True
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user