mirror of
https://github.com/esphome/esphome.git
synced 2026-09-28 23:40:25 +00:00
[script] Use register_apply_condition for script.is_running (#19558)
This commit is contained in:
@@ -11,7 +11,6 @@ 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)
|
||||
IsRunningCondition = script_ns.class_("IsRunningCondition", automation.Condition)
|
||||
SingleScript = script_ns.class_("SingleScript", Script)
|
||||
RestartScript = script_ns.class_("RestartScript", Script)
|
||||
QueueingScript = script_ns.class_("QueueingScript", Script, cg.Component)
|
||||
@@ -233,12 +232,8 @@ async def script_wait_action_to_code(config, action_id, template_arg, args):
|
||||
return var
|
||||
|
||||
|
||||
@automation.register_condition(
|
||||
automation.register_apply_condition(
|
||||
"script.is_running",
|
||||
IsRunningCondition,
|
||||
automation.maybe_simple_id({cv.Required(CONF_ID): cv.use_id(Script)}),
|
||||
"is_running()",
|
||||
)
|
||||
async def script_is_running_to_code(config, condition_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(condition_id, template_arg, paren)
|
||||
|
||||
@@ -276,16 +276,6 @@ template<class C, typename... Ts> class ScriptStopAction final : public Action<T
|
||||
C *script_;
|
||||
};
|
||||
|
||||
template<class C, typename... Ts> class IsRunningCondition final : public Condition<Ts...> {
|
||||
public:
|
||||
explicit IsRunningCondition(C *parent) : parent_(parent) {}
|
||||
|
||||
bool check(const Ts &...x) override { return this->parent_->is_running(); }
|
||||
|
||||
protected:
|
||||
C *parent_;
|
||||
};
|
||||
|
||||
/** Wait for a script to finish before continuing.
|
||||
*
|
||||
* Uses queue-based storage to safely handle concurrent executions.
|
||||
|
||||
Reference in New Issue
Block a user