Skip to content

Commit

Permalink
Add ability to auto-cancel track_time_interval (home-assistant#91381)
Browse files Browse the repository at this point in the history
  • Loading branch information
epenet authored Apr 13, 2023
1 parent 77a445e commit 9744e72
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions homeassistant/helpers/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand All @@ -1426,7 +1429,9 @@ def interval_listener(now: datetime) -> None:
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:
Expand Down

0 comments on commit 9744e72

Please sign in to comment.