20 if (!condition->check(
x...))
36 if (condition->check(
x...))
62 result += condition->check(
x...);
75 bool check(Ts...
x)
override {
return this->
f_(
x...); }
78 std::function<bool(Ts...)>
f_;
133#ifdef ESPHOME_PROJECT_NAME
137 uint32_t hash =
fnv1_hash(ESPHOME_PROJECT_NAME);
139 char previous_version[30];
140 char current_version[30] = ESPHOME_PROJECT_VERSION_30;
141 if (pref.
load(&previous_version)) {
142 int cmp = strcmp(previous_version, current_version);
144 this->
trigger(previous_version);
147 pref.
save(¤t_version);
170 App.scheduler.set_timer_common_(
this, Scheduler::SchedulerItem::TIMEOUT,
171 true,
"delay", this->delay_.value(
x...), std::move(f),
172 false, this->num_running_ > 1);
189 std::function<void(Ts...)>
f_;
245 if (this->num_running_ > 0 && this->condition_->check_tuple(this->var_)) {
247 if (this->num_running_ > 0) {
248 this->then_.play_tuple(this->var_);
252 this->play_next_tuple_(this->var_);
258 this->num_running_++;
260 this->var_ = std::make_tuple(
x...);
262 if (!this->condition_->check_tuple(this->var_)) {
265 this->play_next_tuple_(this->var_);
269 if (this->num_running_ > 0) {
270 this->then_.play_tuple(this->var_);
277 void stop()
override { this->then_.stop(); }
282 std::tuple<Ts...> var_{};
290 this->then_.add_actions(actions);
293 if (iteration >= this->count_.value(x...)) {
294 this->play_next_tuple_(this->var_);
296 this->then_.play(iteration, x...);
302 this->num_running_++;
303 this->var_ = std::make_tuple(
x...);
304 if (this->count_.value(
x...) > 0) {
305 this->then_.play(0,
x...);
307 this->play_next_tuple_(this->var_);
314 void stop()
override { this->then_.stop(); }
327 void play_complex(Ts...
x)
override {
328 this->num_running_++;
330 if (this->condition_->check(
x...)) {
331 if (this->num_running_ > 0) {
332 this->play_next_(
x...);
336 this->var_ = std::make_tuple(
x...);
338 if (this->timeout_value_.has_value()) {
340 this->set_timeout(
"timeout", this->timeout_value_.value(
x...), f);
347 if (this->num_running_ == 0)
350 if (!this->condition_->check_tuple(this->var_)) {
354 this->cancel_timeout(
"timeout");
356 this->play_next_tuple_(this->var_);
364 void stop()
override { this->cancel_timeout(
"timeout"); }
368 std::tuple<Ts...> var_{};
376 if (!this->component_->is_ready())
378 this->component_->update();
390 if (!this->component_->is_ready())
392 this->component_->stop_poller();
404 void play(Ts...
x)
override {
405 if (!this->component_->is_ready()) {
410 this->component_->set_update_interval(update_interval.
value());
412 this->component_->start_poller();
virtual void play_complex(Ts... x)
void add_action(Action< Ts... > *action)
void add_actions(const std::vector< Action< Ts... > * > &actions)
AndCondition(const std::vector< Condition< Ts... > * > &conditions)
std::vector< Condition< Ts... > * > conditions_
bool check(Ts... x) override
bool cancel_timeout(const std::string &name)
Cancel a timeout function.
Base class for all automation conditions.
virtual bool check(Ts... x)=0
Check whether this condition passes. This condition check must be instant, and not cause any delays.
void play(Ts... x) override
float get_setup_priority() const override
TEMPLATABLE_VALUE(uint32_t, delay) void play_complex(Ts... x) override
virtual bool sync()=0
Commit pending writes to flash.
virtual ESPPreferenceObject make_preference(size_t length, uint32_t type, bool in_flash)=0
ForCondition(Condition<> *condition)
float get_setup_priority() const override
bool check(Ts... x) override
TEMPLATABLE_VALUE(uint32_t, time)
Condition< Ts... > * condition_
void play_complex(Ts... x) override
ActionList< Ts... > else_
void add_else(const std::vector< Action< Ts... > * > &actions)
void play(Ts... x) override
void add_then(const std::vector< Action< Ts... > * > &actions)
ActionList< Ts... > then_
IfAction(Condition< Ts... > *condition)
LambdaAction(std::function< void(Ts...)> &&f)
std::function< void(Ts...)> f_
void play(Ts... x) override
bool check(Ts... x) override
LambdaCondition(std::function< bool(Ts...)> &&f)
std::function< bool(Ts...)> f_
float get_setup_priority() const override
bool check(Ts... x) override
Condition< Ts... > * condition_
NotCondition(Condition< Ts... > *condition)
std::vector< Condition< Ts... > * > conditions_
bool check(Ts... x) override
OrCondition(const std::vector< Condition< Ts... > * > &conditions)
This class simplifies creating components that periodically check a state.
float get_setup_priority() const override
ActionList< uint32_t, Ts... > then_
TEMPLATABLE_VALUE(uint32_t, count) void add_then(const std
void play(Ts... x) override
void play_complex(Ts... x) override
ResumeComponentAction(PollingComponent *component)
TEMPLATABLE_VALUE(uint32_t, update_interval) void play(Ts... x) override
PollingComponent * component_
ShutdownTrigger(float setup_priority)
float get_setup_priority() const override
void on_shutdown() override
float get_setup_priority() const override
StartupTrigger(float setup_priority)
SuspendComponentAction(PollingComponent *component)
PollingComponent * component_
void play(Ts... x) override
void play(Ts... x) override
PollingComponent * component_
UpdateComponentAction(PollingComponent *component)
WaitUntilAction(Condition< Ts... > *condition)
void play(Ts... x) override
Condition< Ts... > * condition_
TEMPLATABLE_VALUE(uint32_t, timeout_value) void play_complex(Ts... x) override
float get_setup_priority() const override
WhileAction(Condition< Ts... > *condition)
void play(Ts... x) override
void play_complex(Ts... x) override
void add_then(const std::vector< Action< Ts... > * > &actions)
Condition< Ts... > * condition_
ActionList< Ts... > then_
bool check(Ts... x) override
std::vector< Condition< Ts... > * > conditions_
XorCondition(const std::vector< Condition< Ts... > * > &conditions)
value_type const & value() const
const float DATA
For components that import data from directly connected sensors like DHT.
const float HARDWARE
For components that deal with hardware and are very important like GPIO switch.
const float PROCESSOR
For components that use data from sensors like displays.
Providing packet encoding functions for exchanging data with a remote host.
ESPPreferences * global_preferences
uint32_t fnv1_hash(const char *str)
Calculate a FNV-1 hash of str.
void IRAM_ATTR HOT delay(uint32_t ms)
uint32_t IRAM_ATTR HOT millis()
Application App
Global storage of Application pointer - only one Application can exist.