@@ -448,7 +448,6 @@ def __init__(
448448 self .time_active = trig_cfg .get ("time_active" , {}).get ("args" , None )
449449 self .task_unique = trig_cfg .get ("task_unique" , {}).get ("args" , None )
450450 self .task_unique_kwargs = trig_cfg .get ("task_unique" , {}).get ("kwargs" , None )
451- self .task_unique_func = None
452451 self .action = trig_cfg .get ("action" )
453452 self .action_ast_ctx = trig_cfg .get ("action_ast_ctx" )
454453 self .global_sym_table = trig_cfg .get ("global_sym_table" , {})
@@ -507,9 +506,6 @@ def __init__(
507506 return
508507 self .have_trigger = True
509508
510- if self .task_unique :
511- self .task_unique_func = Function .task_unique_factory (self .action_ast_ctx )
512-
513509 self .setup_ok = True
514510
515511 def stop (self ):
@@ -534,13 +530,6 @@ async def trigger_watch(self):
534530
535531 try :
536532
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-
544533 if self .state_trigger is not None :
545534 self .state_trig_ident = await self .state_trig_expr .get_names ()
546535 _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):
655644 notify_type ,
656645 func_args ,
657646 )
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+
658663 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+ )
660667 )
661668
662669 except asyncio .CancelledError :
0 commit comments