@@ -449,7 +449,6 @@ def __init__(
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 )
451451 self .action = trig_cfg .get ("action" )
452- self .action_ast_ctx = trig_cfg .get ("action_ast_ctx" )
453452 self .global_sym_table = trig_cfg .get ("global_sym_table" , {})
454453 self .notify_q = asyncio .Queue (0 )
455454 self .active_expr = None
@@ -622,14 +621,22 @@ async def trigger_watch(self):
622621 )
623622 continue
624623
624+ action_ast_ctx = AstEval (
625+ f"{ self .action .global_ctx_name } .{ self .action .name } " , self .action .global_ctx
626+ )
627+ Function .install_ast_funcs (action_ast_ctx )
628+ task_unique_func = None
629+ if self .task_unique is not None :
630+ task_unique_func = Function .task_unique_factory (action_ast_ctx )
631+
625632 #
626633 # check for @task_unique with kill_me=True
627634 #
628635 if (
629636 self .task_unique is not None
630637 and self .task_unique_kwargs
631638 and self .task_unique_kwargs ["kill_me" ]
632- and Function .unique_name_used (self . action_ast_ctx , self .task_unique )
639+ and Function .unique_name_used (action_ast_ctx , self .task_unique )
633640 ):
634641 _LOGGER .debug (
635642 "trigger %s got %s trigger, @task_unique kill_me=True prevented new action" ,
@@ -652,14 +659,6 @@ async def do_func_call(func, ast_ctx, task_unique, task_unique_func, **kwargs):
652659 if ast_ctx .get_exception_obj ():
653660 ast_ctx .get_logger ().error (ast_ctx .get_exception_long ())
654661
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-
663662 Function .create_task (
664663 do_func_call (
665664 self .action , action_ast_ctx , self .task_unique , task_unique_func , ** func_args
0 commit comments