18 if (!condition->check(
x...))
34 if (condition->check(
x...))
60 result += condition->check(
x...);
73 bool check(Ts...
x)
override {
return this->
f_(
x...); }
76 std::function<bool(Ts...)>
f_;
131#ifdef ESPHOME_PROJECT_NAME
135 uint32_t hash =
fnv1_hash(ESPHOME_PROJECT_NAME);
137 char previous_version[30];
138 char current_version[30] = ESPHOME_PROJECT_VERSION_30;
139 if (pref.
load(&previous_version)) {
140 int cmp = strcmp(previous_version, current_version);
142 this->
trigger(previous_version);
145 pref.
save(¤t_version);
178 std::function<void(Ts...)>
f_;
234 if (this->num_running_ > 0 && this->condition_->check_tuple(this->var_)) {
236 if (this->num_running_ > 0) {
237 this->then_.play_tuple(this->var_);
241 this->play_next_tuple_(this->var_);
247 this->num_running_++;
249 this->var_ = std::make_tuple(
x...);
251 if (!this->condition_->check_tuple(this->var_)) {
254 this->play_next_tuple_(this->var_);
258 if (this->num_running_ > 0) {
259 this->then_.play_tuple(this->var_);
266 void stop()
override { this->then_.stop(); }
271 std::tuple<Ts...> var_{};
279 this->then_.add_actions(actions);
282 if (iteration >= this->count_.value(x...)) {
283 this->play_next_tuple_(this->var_);
285 this->then_.play(iteration, x...);
291 this->num_running_++;
292 this->var_ = std::make_tuple(
x...);
293 if (this->count_.value(
x...) > 0) {
294 this->then_.play(0,
x...);
296 this->play_next_tuple_(this->var_);
303 void stop()
override { this->then_.stop(); }
316 void play_complex(Ts...
x)
override {
317 this->num_running_++;
319 if (this->condition_->check(
x...)) {
320 if (this->num_running_ > 0) {
321 this->play_next_(
x...);
325 this->var_ = std::make_tuple(
x...);
327 if (this->timeout_value_.has_value()) {
329 this->set_timeout(
"timeout", this->timeout_value_.value(
x...), f);
336 if (this->num_running_ == 0)
339 if (!this->condition_->check_tuple(this->var_)) {
343 this->cancel_timeout(
"timeout");
345 this->play_next_tuple_(this->var_);
353 void stop()
override { this->cancel_timeout(
"timeout"); }
357 std::tuple<Ts...> var_{};
365 if (!this->component_->is_ready())
367 this->component_->update();
379 if (!this->component_->is_ready())
381 this->component_->stop_poller();
393 void play(Ts...
x)
override {
394 if (!this->component_->is_ready()) {
399 this->component_->set_update_interval(update_interval.
value());
401 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.
void set_timeout(const std::string &name, uint32_t timeout, std::function< void()> &&f)
Set a timeout function with a unique name.
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.
uint32_t fnv1_hash(const std::string &str)
Calculate a FNV-1 hash of str.
ESPPreferences * global_preferences
void IRAM_ATTR HOT delay(uint32_t ms)
uint32_t IRAM_ATTR HOT millis()