1
0
mirror of https://github.com/home-assistant/core.git synced 2025-12-24 12:59:34 +00:00

Avoid lingering timer on script shutdown (#89753)

This commit is contained in:
epenet
2023-03-16 08:00:21 +01:00
committed by GitHub
parent c707ddbf7c
commit 913156b0e0
5 changed files with 46 additions and 5 deletions

View File

@@ -66,6 +66,7 @@ from homeassistant.const import (
from homeassistant.core import (
SERVICE_CALL_LIMIT,
Context,
Event,
HassJob,
HomeAssistant,
callback,
@@ -1074,7 +1075,17 @@ class _QueuedScriptRun(_ScriptRun):
super()._finish()
async def _async_stop_scripts_after_shutdown(hass, point_in_time):
@callback
def _schedule_stop_scripts_after_shutdown(hass: HomeAssistant) -> None:
"""Stop running Script objects started after shutdown."""
async_call_later(
hass, _SHUTDOWN_MAX_WAIT, partial(_async_stop_scripts_after_shutdown, hass)
)
async def _async_stop_scripts_after_shutdown(
hass: HomeAssistant, point_in_time: datetime
) -> None:
"""Stop running Script objects started after shutdown."""
hass.data[DATA_NEW_SCRIPT_RUNS_NOT_ALLOWED] = None
running_scripts = [
@@ -1091,11 +1102,9 @@ async def _async_stop_scripts_after_shutdown(hass, point_in_time):
)
async def _async_stop_scripts_at_shutdown(hass, event):
async def _async_stop_scripts_at_shutdown(hass: HomeAssistant, event: Event) -> None:
"""Stop running Script objects started before shutdown."""
async_call_later(
hass, _SHUTDOWN_MAX_WAIT, partial(_async_stop_scripts_after_shutdown, hass)
)
_schedule_stop_scripts_after_shutdown(hass)
running_scripts = [
script