mirror of
https://github.com/esphome/esphome.git
synced 2025-10-05 19:33:47 +01:00
Addressable updates
This commit is contained in:
@@ -8,6 +8,7 @@ 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)
|
||||
IsRunningCondition = script_ns.class_('IsRunningCondition', automation.Condition)
|
||||
|
||||
CONFIG_SCHEMA = automation.validate_automation({
|
||||
cv.Required(CONF_ID): cv.declare_id(Script),
|
||||
@@ -34,3 +35,11 @@ def script_execute_action_to_code(config, action_id, template_arg, args):
|
||||
def script_stop_action_to_code(config, action_id, template_arg, args):
|
||||
paren = yield cg.get_variable(config[CONF_ID])
|
||||
yield cg.new_Pvariable(action_id, template_arg, paren)
|
||||
|
||||
|
||||
@automation.register_condition('script.is_running', IsRunningCondition, automation.maybe_simple_id({
|
||||
cv.Required(CONF_ID): cv.use_id(Script)
|
||||
}))
|
||||
def script_is_running_to_code(config, condition_id, template_arg, args):
|
||||
paren = yield cg.get_variable(config[CONF_ID])
|
||||
yield cg.new_Pvariable(condition_id, template_arg, paren)
|
||||
|
@@ -7,7 +7,16 @@ namespace script {
|
||||
|
||||
class Script : public Trigger<> {
|
||||
public:
|
||||
void execute() { this->trigger(); }
|
||||
void execute() {
|
||||
bool prev = this->in_stack_;
|
||||
this->in_stack_ = true;
|
||||
this->trigger();
|
||||
this->in_stack_ = prev;
|
||||
}
|
||||
bool script_is_running() { return this->in_stack_ || this->is_running(); }
|
||||
|
||||
protected:
|
||||
bool in_stack_{false};
|
||||
};
|
||||
|
||||
template<typename... Ts> class ScriptExecuteAction : public Action<Ts...> {
|
||||
@@ -30,5 +39,15 @@ template<typename... Ts> class ScriptStopAction : public Action<Ts...> {
|
||||
Script *script_;
|
||||
};
|
||||
|
||||
template<typename... Ts> class IsRunningCondition : public Condition<Ts...> {
|
||||
public:
|
||||
explicit IsRunningCondition(Script *parent) : parent_(parent) {}
|
||||
|
||||
bool check(Ts... x) override { return this->parent_->script_is_running(); }
|
||||
|
||||
protected:
|
||||
Script *parent_;
|
||||
};
|
||||
|
||||
} // namespace script
|
||||
} // namespace esphome
|
||||
|
Reference in New Issue
Block a user