1
0
mirror of https://github.com/esphome/esphome.git synced 2025-11-20 00:35:44 +00:00

Addressable updates

This commit is contained in:
Otto Winter
2019-04-25 10:36:55 +02:00
parent 766f6c045d
commit 595dfe7e24
13 changed files with 193 additions and 41 deletions

View File

@@ -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