Skip to content

Commit cb5251b

Browse files
committed
fixed broken test
1 parent f89eaef commit cb5251b

File tree

2 files changed

+11
-10
lines changed

2 files changed

+11
-10
lines changed

custom_components/pyscript/trigger.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -906,17 +906,14 @@ async def trigger_watch(self):
906906
state_trig_waiting = False
907907
state_trig_notify_info = [None, None]
908908
state_false_time = None
909-
startup_time = None
909+
now = startup_time = None
910910
check_state_expr_on_start = self.state_check_now or self.state_hold_false is not None
911911

912912
while True:
913913
timeout = None
914914
state_trig_timeout = False
915915
notify_info = None
916916
notify_type = None
917-
now = dt_now()
918-
if startup_time is None:
919-
startup_time = now
920917
if self.run_on_startup:
921918
#
922919
# first time only - skip waiting for other triggers
@@ -937,6 +934,9 @@ async def trigger_watch(self):
937934
check_state_expr_on_start = False
938935
else:
939936
if self.time_trigger:
937+
now = dt_now()
938+
if startup_time is None:
939+
startup_time = now
940940
time_next = TrigTime.timer_trigger_next(self.time_trigger, now, startup_time)
941941
_LOGGER.debug(
942942
"trigger %s time_next = %s, now = %s", self.name, time_next, now,
@@ -1081,6 +1081,10 @@ async def trigger_watch(self):
10811081
self.active_expr.get_logger().error(exc)
10821082
trig_ok = False
10831083
if trig_ok and self.time_active:
1084+
if now is None:
1085+
now = dt_now()
1086+
if startup_time is None:
1087+
startup_time = now
10841088
trig_ok = TrigTime.timer_active_check(self.time_active, now, startup_time)
10851089

10861090
if not trig_ok:

tests/test_function.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -191,11 +191,7 @@ async def test_state_trigger(hass, caplog):
191191
hass,
192192
notify_q,
193193
notify_q2,
194-
[
195-
dt(2020, 7, 1, 10, 59, 59, 999998),
196-
dt(2020, 7, 1, 10, 59, 59, 999998),
197-
dt(2020, 7, 1, 11, 59, 59, 999998),
198-
],
194+
[dt(2020, 7, 1, 10, 59, 59, 999998), dt(2020, 7, 1, 11, 59, 59, 999998)],
199195
"""
200196
201197
from math import sqrt
@@ -206,12 +202,13 @@ async def test_state_trigger(hass, caplog):
206202
#
207203
# Instead of just a bare @time_trigger, do a real time trigger.
208204
# The first value of now() causes func_startup_sync() to start almost
209-
# immediately. The remaining values of now() are all and hour later at
205+
# immediately. The remaining values of now() are all an hour later at
210206
# 11:59:59.999998, so this trigger won't happen again for another 24 hours.
211207
# (we don't use 11:59:59.999999 because of a bug in croniter.match();
212208
# see https://github.com/taichino/croniter/issues/151)
213209
#
214210
@time_trigger("once(2020/07/01 11:00:00)")
211+
#@time_trigger("startup")
215212
def func_startup_sync(trigger_type=None, trigger_time=None):
216213
global seq_num
217214

0 commit comments

Comments
 (0)