13 if (!condition->check(x...))
29 if (condition->check(x...))
43 bool check(Ts... x)
override {
return !this->condition_->check(x...); }
52 bool check(Ts... x)
override {
return this->f_(x...); }
55 std::function<bool(Ts...)>
f_;
62 TEMPLATABLE_VALUE(uint32_t, time);
64 void loop()
override { this->check_internal(); }
67 bool cond = this->condition_->check();
69 this->last_inactive_ =
millis();
74 if (!this->check_internal())
76 return millis() - this->last_inactive_ >= this->time_.value(x...);
81 uint32_t last_inactive_{0};
86 explicit StartupTrigger(
float setup_priority) : setup_priority_(setup_priority) {}
87 void setup()
override { this->trigger(); }
96 explicit ShutdownTrigger(
float setup_priority) : setup_priority_(setup_priority) {}
106 void loop()
override { this->trigger(); }
116 void play_complex(Ts... x)
override {
118 this->num_running_++;
119 this->set_timeout(this->delay_.value(x...), f);
126 void stop()
override { this->cancel_timeout(
""); }
133 void play(Ts... x)
override { this->f_(x...); }
136 std::function<void(Ts...)>
f_;
144 this->then_.add_actions(actions);
145 this->then_.add_action(
new LambdaAction<Ts...>([
this](Ts... x) { this->play_next_(x...); }));
149 this->else_.add_actions(actions);
150 this->else_.add_action(
new LambdaAction<Ts...>([
this](Ts... x) { this->play_next_(x...); }));
154 this->num_running_++;
155 bool res = this->condition_->check(x...);
157 if (this->then_.empty()) {
158 this->play_next_(x...);
159 }
else if (this->num_running_ > 0) {
160 this->then_.play(x...);
163 if (this->else_.empty()) {
164 this->play_next_(x...);
165 }
else if (this->num_running_ > 0) {
166 this->else_.play(x...);
190 this->then_.add_actions(actions);
192 if (this->num_running_ > 0 && this->condition_->check_tuple(this->var_)) {
194 if (this->num_running_ > 0) {
195 this->then_.play_tuple(this->var_);
199 this->play_next_tuple_(this->var_);
205 this->num_running_++;
207 this->var_ = std::make_tuple(x...);
209 if (!this->condition_->check_tuple(this->var_)) {
212 this->play_next_tuple_(this->var_);
216 if (this->num_running_ > 0) {
217 this->then_.play_tuple(this->var_);
224 void stop()
override { this->then_.stop(); }
229 std::tuple<Ts...> var_{};
237 this->then_.add_actions(actions);
240 if (this->iteration_ == this->count_.value(x...))
241 this->play_next_tuple_(this->var_);
243 this->then_.play_tuple(this->var_);
248 this->num_running_++;
249 this->var_ = std::make_tuple(x...);
250 this->iteration_ = 0;
251 this->then_.play_tuple(this->var_);
257 void stop()
override { this->then_.stop(); }
271 void play_complex(Ts... x)
override {
272 this->num_running_++;
274 if (this->condition_->check(x...)) {
275 if (this->num_running_ > 0) {
276 this->play_next_(x...);
280 this->var_ = std::make_tuple(x...);
282 if (this->timeout_value_.has_value()) {
284 this->set_timeout(
"timeout", this->timeout_value_.value(x...), f);
291 if (this->num_running_ == 0)
294 if (!this->condition_->check_tuple(this->var_)) {
298 this->cancel_timeout(
"timeout");
300 this->play_next_tuple_(this->var_);
308 void stop()
override { this->cancel_timeout(
"timeout"); }
312 std::tuple<Ts...> var_{};
320 if (this->component_->is_failed())
322 this->component_->update();
ForCondition(Condition<> *condition)
const float DATA
For components that import data from directly connected sensors like DHT.
void play(Ts... x) override
ActionList< Ts... > then_
float get_setup_priority() const override
TEMPLATABLE_VALUE(uint32_t, count) void add_then(const std
NotCondition(Condition< Ts... > *condition)
Condition< Ts... > * condition_
void play(Ts... x) override
Condition< Ts... > * condition_
void play_complex(Ts... x) override
ActionList< Ts... > else_
Condition< Ts... > * condition_
float get_setup_priority() const override
IfAction(Condition< Ts... > *condition)
ActionList< Ts... > then_
bool check(Ts... x) override
This class simplifies creating components that periodically check a state.
void on_shutdown() override
void add_then(const std::vector< Action< Ts... > *> &actions)
std::function< void(Ts...)> f_
void play(Ts... x) override
void play(Ts... x) override
uint32_t IRAM_ATTR HOT millis()
float get_setup_priority() const override
void play(Ts... x) override
WhileAction(Condition< Ts... > *condition)
Base class for all automation conditions.
std::vector< Condition< Ts... > * > conditions_
LambdaAction(std::function< void(Ts...)> &&f)
bool check(Ts... x) override
PollingComponent * component_
void add_else(const std::vector< Action< Ts... > *> &actions)
ActionList< Ts... > then_
bool check(Ts... x) override
TEMPLATABLE_VALUE(uint32_t, delay) void play_complex(Ts... x) override
AndCondition(const std::vector< Condition< Ts... > *> &conditions)
ShutdownTrigger(float setup_priority)
LambdaCondition(std::function< bool(Ts...)> &&f)
TEMPLATABLE_VALUE(uint32_t, timeout_value) void play_complex(Ts... x) override
void play_complex(Ts... x) override
void add_then(const std::vector< Action< Ts... > *> &actions)
float get_setup_priority() const override
void play_complex(Ts... x) override
void play(Ts... x) override
const float HARDWARE
For components that deal with hardware and are very important like GPIO switch.
StartupTrigger(float setup_priority)
void play(Ts... x) override
bool check(Ts... x) override
WaitUntilAction(Condition< Ts... > *condition)
float get_setup_priority() const override
Condition< Ts... > * condition_
UpdateComponentAction(PollingComponent *component)
float get_setup_priority() const override
OrCondition(const std::vector< Condition< Ts... > *> &conditions)
bool check(Ts... x) override
std::vector< Condition< Ts... > * > conditions_
void IRAM_ATTR HOT delay(uint32_t ms)
std::function< bool(Ts...)> f_