Skip to content

Commit 6b4ea76

Browse files
committed
allow once() to have offsets that fall before or after today
1 parent a216aea commit 6b4ea76

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

custom_components/pyscript/trigger.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -717,11 +717,12 @@ def timer_trigger_next(cls, time_spec, now, startup_time):
717717

718718
elif len(match1) == 3:
719719
this_t = cls.parse_date_time(match1[1].strip(), 0, now, startup_time)
720-
if this_t <= now and this_t != startup_time:
720+
day_offset = (now - this_t).days + 1
721+
if day_offset != 0 and this_t != startup_time:
721722
#
722-
# Try tomorrow (won't make a difference if spec has full date)
723+
# Try a day offset (won't make a difference if spec has full date)
723724
#
724-
this_t = cls.parse_date_time(match1[1].strip(), 1, now, startup_time)
725+
this_t = cls.parse_date_time(match1[1].strip(), day_offset, now, startup_time)
725726
startup = now == this_t and now == startup_time
726727
if (now < this_t or startup) and (next_time is None or this_t < next_time):
727728
next_time = this_t

tests/test_unit_trigger.py

+4
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,10 @@ def test_timer_active_check(hass, spec, now, expected):
209209
[["once(2019/9/1 8:00)"], [None]],
210210
[["once(2019/9/1 15:00)"], [dt(2019, 9, 1, 15, 0, 0, 0)]],
211211
[["once(15:00)"], [dt(2019, 9, 1, 15, 0, 0, 0)]],
212+
[["once(15:00 + 2d)"], [dt(2019, 9, 1, 15, 0, 0, 0), dt(2019, 9, 2, 15, 0, 0, 0)]],
213+
[["once(15:00 - 48h)"], [dt(2019, 9, 1, 15, 0, 0, 0), dt(2019, 9, 2, 15, 0, 0, 0)]],
214+
[["once(11:00 + 2d)"], [dt(2019, 9, 2, 11, 0, 0, 0), dt(2019, 9, 3, 11, 0, 0, 0)]],
215+
[["once(11:00 - 48h)"], [dt(2019, 9, 2, 11, 0, 0, 0), dt(2019, 9, 3, 11, 0, 0, 0)]],
212216
[["once(13:00:0.09)"], [dt(2019, 9, 2, 13, 0, 0, 90000)]],
213217
[["once(9:00)"], [dt(2019, 9, 2, 9, 0, 0, 0)]],
214218
[["once(wed 9:00)"], [dt(2019, 9, 4, 9, 0, 0, 0)]],

0 commit comments

Comments
 (0)