Add ability to auto-cancel track_time_interval (#91381)
parent
77a445ee16
commit
9744e72d5a
|
@ -1399,12 +1399,15 @@ def async_track_time_interval(
|
||||||
interval: timedelta,
|
interval: timedelta,
|
||||||
*,
|
*,
|
||||||
name: str | None = None,
|
name: str | None = None,
|
||||||
|
cancel_on_shutdown: bool | None = None,
|
||||||
) -> CALLBACK_TYPE:
|
) -> CALLBACK_TYPE:
|
||||||
"""Add a listener that fires repetitively at every timedelta interval."""
|
"""Add a listener that fires repetitively at every timedelta interval."""
|
||||||
remove: CALLBACK_TYPE
|
remove: CALLBACK_TYPE
|
||||||
interval_listener_job: HassJob[[datetime], None]
|
interval_listener_job: HassJob[[datetime], None]
|
||||||
|
|
||||||
job = HassJob(action, f"track time interval {interval}")
|
job = HassJob(
|
||||||
|
action, f"track time interval {interval}", cancel_on_shutdown=cancel_on_shutdown
|
||||||
|
)
|
||||||
|
|
||||||
def next_interval() -> datetime:
|
def next_interval() -> datetime:
|
||||||
"""Return the next interval."""
|
"""Return the next interval."""
|
||||||
|
@ -1426,7 +1429,9 @@ def async_track_time_interval(
|
||||||
else:
|
else:
|
||||||
job_name = f"track time interval {interval}"
|
job_name = f"track time interval {interval}"
|
||||||
|
|
||||||
interval_listener_job = HassJob(interval_listener, job_name)
|
interval_listener_job = HassJob(
|
||||||
|
interval_listener, job_name, cancel_on_shutdown=cancel_on_shutdown
|
||||||
|
)
|
||||||
remove = async_track_point_in_utc_time(hass, interval_listener_job, next_interval())
|
remove = async_track_point_in_utc_time(hass, interval_listener_job, next_interval())
|
||||||
|
|
||||||
def remove_listener() -> None:
|
def remove_listener() -> None:
|
||||||
|
|
Loading…
Reference in New Issue