"""Action: wait_until — wait for a template to appear (with timeout).""" import os import time class Action: name = "wait_until" def run(self, ctx, params): template = params["template"] confidence = params.get("confidence", 0.8) timeout = params.get("timeout", 30) poll = params.get("poll_interval", 1) tmpl_dir = ctx.get("_templates_dir", os.path.join(os.path.dirname(__file__), "..", "templates")) tpl_path = os.path.join(tmpl_dir, template) deadline = time.time() + timeout while time.time() < deadline: ctx["vision"].capture() pos = ctx["vision"].find_template(tpl_path, confidence) if pos is not None: ctx["log"].info("wait_until(%s) → found at %s", template, pos) return pos time.sleep(poll) ctx["log"].warning("wait_until(%s) → timeout after %.0fs", template, timeout) return None