[script] Use register_apply_action for script.stop (#19599)

This commit is contained in:
J. Nick Koston
2026-09-25 10:23:33 -04:00
committed by GitHub
parent a17285afc7
commit 3fb48e0bfa
3 changed files with 4 additions and 18 deletions
+2 -8
View File
@@ -9,7 +9,6 @@ CODEOWNERS = ["@esphome/core"]
script_ns = cg.esphome_ns.namespace("script")
Script = script_ns.class_("Script", automation.Trigger.template())
ScriptExecuteAction = script_ns.class_("ScriptExecuteAction", automation.Action)
ScriptStopAction = script_ns.class_("ScriptStopAction", automation.Action)
ScriptWaitAction = script_ns.class_("ScriptWaitAction", automation.Action, cg.Component)
SingleScript = script_ns.class_("SingleScript", Script)
RestartScript = script_ns.class_("RestartScript", Script)
@@ -206,16 +205,11 @@ async def script_execute_action_to_code(config, action_id, template_arg, args):
return var
@automation.register_action(
automation.register_apply_action(
"script.stop",
ScriptStopAction,
maybe_simple_id({cv.Required(CONF_ID): cv.use_id(Script)}),
synchronous=True,
automation.ApplyCall("stop()"),
)
async def script_stop_action_to_code(config, action_id, template_arg, args):
full_id, paren = await cg.get_variable_with_full_id(config[CONF_ID])
template_arg = cg.TemplateArguments(full_id.type, *template_arg)
return cg.new_Pvariable(action_id, template_arg, paren)
@automation.register_action(
-10
View File
@@ -257,16 +257,6 @@ template<class... As, typename... Ts> class ScriptExecuteAction<Script<As...>, T
Args args_;
};
template<class C, typename... Ts> class ScriptStopAction final : public Action<Ts...> {
public:
ScriptStopAction(C *script) : script_(script) {}
void play(const Ts &...x) override { this->script_->stop(); }
protected:
C *script_;
};
/** Wait for a script to finish before continuing.
*
* Uses queue-based storage to safely handle concurrent executions.
+2
View File
@@ -15,6 +15,8 @@ esphome:
strings: ["a", "b"]
- script.wait: my_script
- script.stop: my_script
- script.stop:
id: my_script_queued
- if:
condition:
- script.is_running: my_script