Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 30 additions & 1 deletion custom_components/pyscript/decorator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down Expand Up @@ -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"}
Expand Down
2 changes: 1 addition & 1 deletion custom_components/pyscript/decorators/timing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down
1 change: 1 addition & 0 deletions custom_components/pyscript/stubs/pyscript_builtins.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Loading