|
14 | 14 | from pathlib import Path |
15 | 15 | from typing import TYPE_CHECKING, Any, Literal, TypeVar, overload |
16 | 16 |
|
17 | | -from appdaemon import dependency |
| 17 | +from appdaemon import dependency, utils |
18 | 18 | from appdaemon import exceptions as ade |
19 | | -from appdaemon import utils |
20 | 19 | from appdaemon.appdaemon import AppDaemon |
21 | 20 | from appdaemon.entity import Entity |
22 | 21 | from appdaemon.events import EventCallback |
23 | 22 | from appdaemon.logging import Logging |
24 | 23 | from appdaemon.models.config.app import AppConfig |
25 | 24 | from appdaemon.parse import resolve_time_str |
26 | 25 | from appdaemon.state import StateCallbackType |
| 26 | + |
27 | 27 | from .types import TimeDeltaLike |
28 | 28 |
|
29 | 29 | T = TypeVar("T") |
@@ -3225,6 +3225,7 @@ async def run_every( |
3225 | 3225 | start: str | dt.time | dt.datetime | None = None, |
3226 | 3226 | interval: TimeDeltaLike = 0, |
3227 | 3227 | *args, |
| 3228 | + immediate: bool = False, |
3228 | 3229 | random_start: TimeDeltaLike | None = None, |
3229 | 3230 | random_end: TimeDeltaLike | None = None, |
3230 | 3231 | pin: bool | None = None, |
@@ -3257,6 +3258,8 @@ async def run_every( |
3257 | 3258 | - If this is a ``timedelta`` object, the current date will be assumed. |
3258 | 3259 |
|
3259 | 3260 | *args: Arbitrary positional arguments to be provided to the callback function when it is triggered. |
| 3261 | + immediate (bool, optional): Whether to immediately fire the callback or wait until the first interval if the |
| 3262 | + start time is now. |
3260 | 3263 | random_start (int, optional): Start of range of the random time. |
3261 | 3264 | random_end (int, optional): End of range of the random time. |
3262 | 3265 | pin (bool, optional): Optional setting to override the default thread pinning behavior. By default, this is |
@@ -3310,7 +3313,7 @@ def timed_callback(self, **kwargs): ... # example callback |
3310 | 3313 |
|
3311 | 3314 | """ |
3312 | 3315 | interval = utils.parse_timedelta(interval) |
3313 | | - next_period = await self.AD.sched.get_next_period(interval, start) |
| 3316 | + next_period = await self.AD.sched.get_next_period(interval, start, immediate=immediate) |
3314 | 3317 |
|
3315 | 3318 | self.logger.debug( |
3316 | 3319 | "Registering %s for run_every in %s intervals, starting %s", |
|
0 commit comments