diff --git a/homeassistant/helpers/script.py b/homeassistant/helpers/script.py index ac53a3e32a2..5e660ba7b7f 100644 --- a/homeassistant/helpers/script.py +++ b/homeassistant/helpers/script.py @@ -1,6 +1,7 @@ """Helpers to execute scripts.""" import logging +from contextlib import suppress from itertools import islice from typing import Optional, Sequence @@ -95,7 +96,9 @@ class Script(): def async_script_delay(now): """Handle delay.""" # pylint: disable=cell-var-from-loop - self._async_remove_listener() + with suppress(ValueError): + self._async_listener.remove(unsub) + self.hass.async_create_task( self.async_run(variables, context)) @@ -240,7 +243,8 @@ class Script(): @callback def async_script_timeout(now): """Call after timeout is retrieve.""" - self._async_remove_listener() + with suppress(ValueError): + self._async_listener.remove(unsub) # Check if we want to continue to execute # the script after the timeout