15 if (!condition->check(x...))
31 if (condition->check(x...))
45 bool check(Ts... x)
override {
return !this->condition_->check(x...); }
54 bool check(Ts... x)
override {
return this->f_(x...); }
57 std::function<bool(Ts...)>
f_;
64 TEMPLATABLE_VALUE(uint32_t, time);
66 void loop()
override { this->check_internal(); }
69 bool cond = this->condition_->check();
71 this->last_inactive_ =
millis();
76 if (!this->check_internal())
78 return millis() - this->last_inactive_ >= this->time_.value(x...);
83 uint32_t last_inactive_{0};
88 explicit StartupTrigger(
float setup_priority) : setup_priority_(setup_priority) {}
89 void setup()
override { this->trigger(); }
98 explicit ShutdownTrigger(
float setup_priority) : setup_priority_(setup_priority) {}
108 void loop()
override { this->trigger(); }
118 void play_complex(Ts... x)
override {
120 this->num_running_++;
121 this->set_timeout(this->delay_.value(x...), f);
128 void stop()
override { this->cancel_timeout(
""); }
135 void play(Ts... x)
override { this->f_(x...); }
138 std::function<void(Ts...)>
f_;
146 this->then_.add_actions(actions);
147 this->then_.add_action(
new LambdaAction<Ts...>([
this](Ts... x) { this->play_next_(x...); }));
151 this->else_.add_actions(actions);
152 this->else_.add_action(
new LambdaAction<Ts...>([
this](Ts... x) { this->play_next_(x...); }));
156 this->num_running_++;
157 bool res = this->condition_->check(x...);
159 if (this->then_.empty()) {
160 this->play_next_(x...);
161 }
else if (this->num_running_ > 0) {
162 this->then_.play(x...);
165 if (this->else_.empty()) {
166 this->play_next_(x...);
167 }
else if (this->num_running_ > 0) {
168 this->else_.play(x...);
192 this->then_.add_actions(actions);
194 if (this->num_running_ > 0 && this->condition_->check_tuple(this->var_)) {
196 if (this->num_running_ > 0) {
197 this->then_.play_tuple(this->var_);
201 this->play_next_tuple_(this->var_);
207 this->num_running_++;
209 this->var_ = std::make_tuple(x...);
211 if (!this->condition_->check_tuple(this->var_)) {
214 this->play_next_tuple_(this->var_);
218 if (this->num_running_ > 0) {
219 this->then_.play_tuple(this->var_);
226 void stop()
override { this->then_.stop(); }
231 std::tuple<Ts...> var_{};
239 this->then_.add_actions(actions);
242 if (iteration >= this->count_.value(x...))
243 this->play_next_tuple_(this->var_);
245 this->then_.play(iteration, x...);
250 this->num_running_++;
251 this->var_ = std::make_tuple(x...);
252 this->then_.play(0, x...);
258 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_ready())
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
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
ActionList< uint32_t, Ts... > then_
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_