Skip to content

Commit d2661f6

Browse files
committed
added immediate argument to run_every
1 parent 3efe2d0 commit d2661f6

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

appdaemon/adapi.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,16 @@
1414
from pathlib import Path
1515
from typing import TYPE_CHECKING, Any, Literal, TypeVar, overload
1616

17-
from appdaemon import dependency
17+
from appdaemon import dependency, utils
1818
from appdaemon import exceptions as ade
19-
from appdaemon import utils
2019
from appdaemon.appdaemon import AppDaemon
2120
from appdaemon.entity import Entity
2221
from appdaemon.events import EventCallback
2322
from appdaemon.logging import Logging
2423
from appdaemon.models.config.app import AppConfig
2524
from appdaemon.parse import resolve_time_str
2625
from appdaemon.state import StateCallbackType
26+
2727
from .types import TimeDeltaLike
2828

2929
T = TypeVar("T")
@@ -3225,6 +3225,7 @@ async def run_every(
32253225
start: str | dt.time | dt.datetime | None = None,
32263226
interval: TimeDeltaLike = 0,
32273227
*args,
3228+
immediate: bool = False,
32283229
random_start: TimeDeltaLike | None = None,
32293230
random_end: TimeDeltaLike | None = None,
32303231
pin: bool | None = None,
@@ -3257,6 +3258,8 @@ async def run_every(
32573258
- If this is a ``timedelta`` object, the current date will be assumed.
32583259
32593260
*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.
32603263
random_start (int, optional): Start of range of the random time.
32613264
random_end (int, optional): End of range of the random time.
32623265
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
33103313
33113314
"""
33123315
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)
33143317

33153318
self.logger.debug(
33163319
"Registering %s for run_every in %s intervals, starting %s",

0 commit comments

Comments
 (0)