Add ability to auto-cancel track_time_interval (#91381)

pull/91363/head^2
epenet 2023-04-13 21:31:16 +02:00 committed by GitHub
parent 77a445ee16
commit 9744e72d5a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 7 additions and 2 deletions

View File

@ -1399,12 +1399,15 @@ def async_track_time_interval(
interval: timedelta,
*,
name: str | None = None,
cancel_on_shutdown: bool | None = None,
) -> CALLBACK_TYPE:
"""Add a listener that fires repetitively at every timedelta interval."""
remove: CALLBACK_TYPE
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:
"""Return the next interval."""
@ -1426,7 +1429,9 @@ def async_track_time_interval(
else:
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())
def remove_listener() -> None: