@@ -250,7 +250,7 @@ def __init__(self, ast_ctx: AstEval, eval_func_var: EvalFuncVar) -> None:
250250
251251 def on_func_var_deleted ():
252252 if self .status is DecoratorManagerStatus .RUNNING :
253- self .hass .async_create_task (self .stop ())
253+ self .hass .async_create_task (self .safe_await ( self . stop () ))
254254
255255 weakref .finalize (eval_func_var , on_func_var_deleted )
256256
@@ -261,9 +261,8 @@ async def _call(self, data: DispatchData) -> None:
261261 for handler_dec in handlers :
262262 if await handler_dec .handle_call (data ) is False :
263263 self .logger .debug ("Calling canceled by %s" , handler_dec )
264- # notify handlers with "None"
265264 for result_handler_dec in result_handlers :
266- await result_handler_dec .handle_call_result (data , None )
265+ await self . safe_await ( result_handler_dec .handle_call_canceled (data ) )
267266 return
268267 # Fire an event indicating that pyscript is running
269268 # Note: the event must have an entity_id for logbook to work correctly.
@@ -277,10 +276,14 @@ async def _call(self, data: DispatchData) -> None:
277276
278277 try :
279278 result = await data .call_ast_ctx .call_func (self .eval_func , None , ** data .func_args )
280- for result_handler_dec in result_handlers :
281- await result_handler_dec .handle_call_result (data , result )
282279 except Exception as e :
280+ for result_handler_dec in result_handlers :
281+ await self .safe_await (result_handler_dec .handle_call_exception (data , e ))
283282 await self .handle_exception (e )
283+ return
284+
285+ for result_handler_dec in result_handlers :
286+ await self .safe_await (result_handler_dec .handle_call_result (data , result ))
284287
285288 async def dispatch (self , data : DispatchData ) -> None :
286289 """Handle a trigger dispatch: run guards, create a context, and invoke the function."""
@@ -290,6 +293,8 @@ async def dispatch(self, data: DispatchData) -> None:
290293 for dec in decorators :
291294 if await dec .handle_dispatch (data ) is False :
292295 self .logger .debug ("Trigger not active due to %s" , dec )
296+ for result_handler_dec in self .get_decorators (CallResultHandlerDecorator ):
297+ await self .safe_await (result_handler_dec .handle_call_canceled (data ))
293298 return
294299
295300 action_ast_ctx = AstEval (
0 commit comments