@@ -448,7 +448,6 @@ def __init__(
448
448
self .time_active = trig_cfg .get ("time_active" , {}).get ("args" , None )
449
449
self .task_unique = trig_cfg .get ("task_unique" , {}).get ("args" , None )
450
450
self .task_unique_kwargs = trig_cfg .get ("task_unique" , {}).get ("kwargs" , None )
451
- self .task_unique_func = None
452
451
self .action = trig_cfg .get ("action" )
453
452
self .action_ast_ctx = trig_cfg .get ("action_ast_ctx" )
454
453
self .global_sym_table = trig_cfg .get ("global_sym_table" , {})
@@ -507,9 +506,6 @@ def __init__(
507
506
return
508
507
self .have_trigger = True
509
508
510
- if self .task_unique :
511
- self .task_unique_func = Function .task_unique_factory (self .action_ast_ctx )
512
-
513
509
self .setup_ok = True
514
510
515
511
def stop (self ):
@@ -534,13 +530,6 @@ async def trigger_watch(self):
534
530
535
531
try :
536
532
537
- async def do_func_call (func , ast_ctx , task_unique , ** kwargs ):
538
- if task_unique and self .task_unique_func :
539
- await self .task_unique_func (task_unique )
540
- await func .call (ast_ctx , ** kwargs )
541
- if ast_ctx .get_exception_obj ():
542
- ast_ctx .get_logger ().error (ast_ctx .get_exception_long ())
543
-
544
533
if self .state_trigger is not None :
545
534
self .state_trig_ident = await self .state_trig_expr .get_names ()
546
535
_LOGGER .debug ("trigger %s: watching vars %s" , self .name , self .state_trig_ident )
@@ -655,8 +644,26 @@ async def do_func_call(func, ast_ctx, task_unique, **kwargs):
655
644
notify_type ,
656
645
func_args ,
657
646
)
647
+
648
+ async def do_func_call (func , ast_ctx , task_unique , task_unique_func , ** kwargs ):
649
+ if task_unique and task_unique_func :
650
+ await task_unique_func (task_unique )
651
+ await func .call (ast_ctx , ** kwargs )
652
+ if ast_ctx .get_exception_obj ():
653
+ ast_ctx .get_logger ().error (ast_ctx .get_exception_long ())
654
+
655
+ action_ast_ctx = AstEval (
656
+ f"{ self .action .global_ctx_name } .{ self .action .name } " , self .action .global_ctx
657
+ )
658
+ Function .install_ast_funcs (action_ast_ctx )
659
+ task_unique_func = None
660
+ if self .task_unique :
661
+ task_unique_func = Function .task_unique_factory (action_ast_ctx )
662
+
658
663
Function .create_task (
659
- do_func_call (self .action , self .action_ast_ctx , self .task_unique , ** func_args )
664
+ do_func_call (
665
+ self .action , action_ast_ctx , self .task_unique , task_unique_func , ** func_args
666
+ )
660
667
)
661
668
662
669
except asyncio .CancelledError :
0 commit comments