diff --git a/custom_components/pyscript/decorator.py b/custom_components/pyscript/decorator.py index 6c92c34..33af0d3 100644 --- a/custom_components/pyscript/decorator.py +++ b/custom_components/pyscript/decorator.py @@ -29,6 +29,21 @@ _LOGGER = logging.getLogger(__name__) +LEGACY_WAIT_UNTIL_ARGS = [ + "state_trigger", + "state_check_now", + "time_trigger", + "event_trigger", + "mqtt_trigger", + "mqtt_trigger_encoding", + "webhook_trigger", + "webhook_local_only", + "webhook_methods", + "timeout", + "state_hold", + "state_hold_false", +] + class DecoratorRegistry: """Decorator registry.""" @@ -102,8 +117,22 @@ async def get_decorator_by_expr(cls, ast_ctx: AstEval, dec_expr: ast.expr) -> De return None @classmethod - async def wait_until(cls, ast_ctx: AstEval, *_arg: Any, **kwargs: Any) -> Any: + async def wait_until(cls, ast_ctx: AstEval, *args: Any, **kwargs: Any) -> Any: """Build a temporary decorator manager that waits until one of trigger decorators fires.""" + + if len(args) > 0: + # Preserve legacy positional arguments for now; reject them in a future release. + ast_ctx.get_logger().warning( + "Ambiguous positional arguments in task.wait_until%s; use keyword arguments instead", + args, + ) + kwargs = kwargs.copy() + for i, arg in enumerate(args): + key = LEGACY_WAIT_UNTIL_ARGS[i] + if key in kwargs: + raise TypeError(f"task.wait_until() got multiple values for argument '{key}'") + kwargs[key] = arg + func_args = set(kwargs.keys()) if len(func_args) == 0: return {"trigger_type": "none"} diff --git a/custom_components/pyscript/decorators/timing.py b/custom_components/pyscript/decorators/timing.py index 67a4371..d431adc 100644 --- a/custom_components/pyscript/decorators/timing.py +++ b/custom_components/pyscript/decorators/timing.py @@ -77,7 +77,7 @@ class TimeTriggerDecorator(TriggerDecorator): run_on_startup: bool = False run_on_shutdown: bool = False timespec: list[str] - _cycle_task: asyncio.Task + _cycle_task: asyncio.Task = None async def validate(self) -> None: """Validate the decorator arguments.""" diff --git a/custom_components/pyscript/stubs/pyscript_builtins.py b/custom_components/pyscript/stubs/pyscript_builtins.py index 55b7044..c4b1736 100644 --- a/custom_components/pyscript/stubs/pyscript_builtins.py +++ b/custom_components/pyscript/stubs/pyscript_builtins.py @@ -438,6 +438,7 @@ def unique(task_name: str, kill_me: bool = False) -> None: @staticmethod def wait_until( + *, state_trigger: str | list[str] | None = None, time_trigger: str | list[str] | None = None, event_trigger: str | list[str] | None = None,