Skip to content

Commit adbf752

Browse files
committed
fix task.wait_until() trigger_type return when there is a timeout
with other triggers that don't occur first, and added test case
1 parent 6abc2de commit adbf752

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

custom_components/pyscript/trigger.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,7 @@ async def wait_until(
213213
ret = {"trigger_type": "timeout"}
214214
break
215215
if this_timeout is None or this_timeout > time_left:
216+
ret = {"trigger_type": "timeout"}
216217
this_timeout = time_left
217218
if this_timeout is None:
218219
if state_trigger is None and event_trigger is None:
@@ -233,7 +234,8 @@ async def wait_until(
233234
notify_q.get(), timeout=this_timeout
234235
)
235236
except asyncio.TimeoutError:
236-
ret = {"trigger_type": "time"}
237+
if not ret:
238+
ret = {"trigger_type": "time"}
237239
break
238240
if notify_type == "state":
239241
if state_trig_expr is None:

tests/custom_components/pyscript/test_func.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,15 @@ def func4(trigger_type=None, event_type=None, **kwargs):
201201
log.info(f"func4 trigger_type = {res}")
202202
pyscript.done = [seq_num, res]
203203
204+
seq_num += 1
205+
#
206+
# make sure a short timeout works when there is only a state trigger
207+
# that isn't true
208+
#
209+
res = task.wait_until(state_trigger="pyscript.f4var2 == '20'", timeout=1e-6)
210+
log.info(f"func4 trigger_type = {res}")
211+
pyscript.done = [seq_num, res]
212+
204213
seq_num += 1
205214
#
206215
# make sure a short timeout works when there are no other triggers
@@ -351,9 +360,9 @@ def func4(trigger_type=None, event_type=None, **kwargs):
351360
assert literal_eval(hass.states.get("pyscript.setVar3").state) == {"foo": "bar"}
352361

353362
#
354-
# check for the three time triggers, two timeouts and two none
363+
# check for the four time triggers, three timeouts and two none
355364
#
356-
for trig_type in ["time"] * 4 + ["timeout"] * 2 + ["none"] * 2:
365+
for trig_type in ["time"] * 4 + ["timeout"] * 3 + ["none"] * 2:
357366
seq_num += 1
358367
assert literal_eval(await wait_until_done(notify_q)) == [
359368
seq_num,

0 commit comments

Comments
 (0)