23 bool check(
const Ts &...
x)
override {
25 if (!condition->check(
x...))
41 bool check(
const Ts &...
x)
override {
43 if (condition->check(
x...))
68 bool check(
const Ts &...
x)
override {
71 result += condition->check(
x...);
84 bool check(
const Ts &...
x)
override {
return this->
f_(x...); }
87 std::function<bool(Ts...)>
f_;
96 bool check(
const Ts &...
x)
override {
return this->
f_(x...); }
160#ifdef ESPHOME_PROJECT_NAME
166 char previous_version[30];
167 char current_version[30] = ESPHOME_PROJECT_VERSION_30;
168 if (pref.
load(&previous_version)) {
169 int cmp = strcmp(previous_version, current_version);
171 this->
trigger(previous_version);
174 pref.
save(¤t_version);
199 if constexpr (
sizeof...(Ts) == 0) {
201 nullptr, Scheduler::SchedulerItem::TIMEOUT, Scheduler::NameType::SELF_POINTER,
202 reinterpret_cast<const char *
>(
this), 0, this->delay_.value(),
203 [
this]() { this->play_next_(); },
204 false, this->num_running_ > 1);
210 auto f = [
this,
x...]()
mutable { this->
play_next_(x...); };
212 nullptr, Scheduler::SchedulerItem::TIMEOUT, Scheduler::NameType::SELF_POINTER,
213 reinterpret_cast<const char *
>(
this), 0, this->delay_.value(
x...),
215 false, this->num_running_ > 1);
219 void play(
const Ts &...
x)
override {
229 void play(
const Ts &...
x)
override { this->
f_(x...); }
232 std::function<void(Ts...)>
f_;
242 void play(
const Ts &...
x)
override { this->
f_(x...); }
300 this->
else_.add_actions(actions);
307 if (!this->
then_.
empty() && this->num_running_ > 0) {
311 }
else if constexpr (HasElse) {
312 if (!this->
else_.empty() && this->num_running_ > 0) {
313 this->
else_.play(x...);
320 void play(
const Ts &...
x)
override {
325 if constexpr (HasElse) {
366 void play(
const Ts &...
x)
override {
379 if (this->parent_->num_running_ > 0 && this->parent_->condition_->check(
x...)) {
381 this->parent_->then_.play(
x...);
384 this->parent_->play_next_(
x...);
417 if (this->count_.value(
x...) > 0) {
424 void play(
const Ts &...
x)
override {
436 uint32_t next_iteration = iteration + 1;
437 if (next_iteration >= this->parent_->count_.value(
x...)) {
438 this->parent_->play_next_(
x...);
440 this->parent_->then_.play(next_iteration,
x...);
457 void setup()
override {
479 auto timeout = this->timeout_value_.optional_value(
x...);
480 this->
var_queue_.emplace_back(now, timeout, std::make_tuple(
x...));
505 void play(
const Ts &...
x)
override {
513 this->
var_queue_.remove_if([&](
auto &queued) {
514 auto start = std::get<uint32_t>(queued);
515 auto timeout = std::get<optional<uint32_t>>(queued);
516 auto &var = std::get<std::tuple<Ts...>>(queued);
519 auto expired = timeout && (now - start) >= *timeout;
535 std::list<std::tuple<uint32_t, optional<uint32_t>, std::tuple<Ts...>>>
var_queue_{};
542 void play(
const Ts &...
x)
override {
556 void play(
const Ts &...
x)
override {
571 void play(
const Ts &...
x)
override {
575 optional<uint32_t> update_interval = this->update_interval_.optional_value(
x...);
576 if (update_interval.has_value()) {
void play_next_(const Ts &...x)
virtual void play(const Ts &...x)=0
void play_next_tuple_(const std::tuple< Ts... > &tuple, std::index_sequence< S... >)
virtual void play_complex(const Ts &...x)
void add_action(Action< Ts... > *action)
void add_actions(const std::initializer_list< Action< Ts... > * > &actions)
void play(const Ts &...x) ESPHOME_ALWAYS_INLINE
AndCondition(std::initializer_list< Condition< Ts... > * > conditions)
bool check(const Ts &...x) override
std::array< Condition< Ts... > *, N > conditions_
uint32_t IRAM_ATTR HOT get_loop_component_start_time() const
Get the cached time in milliseconds from when the current component started its loop execution.
virtual void setup()
Where the component's initialization should happen.
void enable_loop()
Enable this component's loop.
void disable_loop()
Disable this component's loop.
Base class for all automation conditions.
bool check_tuple(const std::tuple< Ts... > &tuple)
Call check with a tuple of values as parameter.
virtual bool check(const Ts &...x)=0
Check whether this condition passes. This condition check must be instant, and not cause any delays.
Simple continuation action that calls play_next_ on a parent action.
void play(const Ts &...x) override
Action< Ts... > * parent_
ContinuationAction(Action< Ts... > *parent)
void play(const Ts &...x) override
TEMPLATABLE_VALUE(uint32_t, delay) void play_complex(const Ts &...x) override
bool check_internal_(uint32_t now)
ForCondition(Condition<> *condition)
float get_setup_priority() const override
bool check(const Ts &...x) override
TEMPLATABLE_VALUE(uint32_t, time)
ActionList< Ts... > then_
Condition< Ts... > * condition_
OptionalContinuation< HasElse, Ts... > else_continuation_
void play(const Ts &...x) override
void add_then(const std::initializer_list< Action< Ts... > * > &actions)
void play_complex(const Ts &...x) override
std::conditional_t< HasElse, ActionList< Ts... >, NoElse > else_
ContinuationAction< Ts... > then_continuation_
IfAction(Condition< Ts... > *condition)
void add_else(const std::initializer_list< Action< Ts... > * > &actions)
LambdaAction(std::function< void(Ts...)> &&f)
void play(const Ts &...x) override
std::function< void(Ts...)> f_
bool check(const Ts &...x) override
LambdaCondition(std::function< bool(Ts...)> &&f)
std::function< bool(Ts...)> f_
float get_setup_priority() const override
Condition< Ts... > * condition_
bool check(const Ts &...x) override
NotCondition(Condition< Ts... > *condition)
OrCondition(std::initializer_list< Condition< Ts... > * > conditions)
bool check(const Ts &...x) override
std::array< Condition< Ts... > *, N > conditions_
This class simplifies creating components that periodically check a state.
void set_update_interval(uint32_t update_interval)
Manually set the update interval in ms for this polling object.
float get_setup_priority() const override
ActionList< uint32_t, Ts... > then_
TEMPLATABLE_VALUE(uint32_t, count) void add_then(const std
void play_complex(const Ts &...x) override
void play(const Ts &...x) override
RepeatLoopContinuation< Ts... > loop_continuation_
Loop continuation for RepeatAction that increments iteration and repeats or continues.
RepeatLoopContinuation(RepeatAction< Ts... > *parent)
RepeatAction< Ts... > * parent_
void play(const uint32_t &iteration, const Ts &...x) override
ResumeComponentAction(PollingComponent *component)
TEMPLATABLE_VALUE(uint32_t, update_interval) void play(const 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)
Optimized lambda action for stateless lambdas (no capture).
void play(const Ts &...x) override
StatelessLambdaAction(void(*f)(Ts...))
Optimized lambda condition for stateless lambdas (no capture).
bool check(const Ts &...x) override
StatelessLambdaCondition(bool(*f)(Ts...))
SuspendComponentAction(PollingComponent *component)
void play(const Ts &...x) override
PollingComponent * component_
void trigger(const Ts &...x) ESPHOME_ALWAYS_INLINE
void play(const Ts &...x) override
PollingComponent * component_
UpdateComponentAction(PollingComponent *component)
Wait until a condition is true to continue execution.
WaitUntilAction(Condition< Ts... > *condition)
TEMPLATABLE_VALUE(uint32_t, timeout_value) void setup() override
void play_complex(const Ts &...x) override
void play(const Ts &...x) override
bool process_queue_(uint32_t now)
Condition< Ts... > * condition_
std::list< std::tuple< uint32_t, optional< uint32_t >, std::tuple< Ts... > > > var_queue_
float get_setup_priority() const override
void add_then(const std::initializer_list< Action< Ts... > * > &actions)
WhileAction(Condition< Ts... > *condition)
void play(const Ts &...x) override
void play_complex(const Ts &...x) override
Condition< Ts... > * condition_
WhileLoopContinuation< Ts... > loop_continuation_
ActionList< Ts... > then_
Loop continuation for WhileAction that checks condition and repeats or continues.
WhileLoopContinuation(WhileAction< Ts... > *parent)
void play(const Ts &...x) override
WhileAction< Ts... > * parent_
std::array< Condition< Ts... > *, N > conditions_
bool check(const Ts &...x) override
XorCondition(std::initializer_list< Condition< Ts... > * > conditions)
const Component * component
constexpr float DATA
For components that import data from directly connected sensors like DHT.
constexpr float PROCESSOR
For components that use data from sensors like displays.
ESPPreferences * global_preferences
uint32_t fnv1_hash(const char *str)
Calculate a FNV-1 hash of str.
void init_array_from(std::array< T, N > &dest, std::initializer_list< T > src)
Initialize a std::array from an initializer_list.
void HOT delay(uint32_t ms)
uint32_t IRAM_ATTR HOT millis()
Application App
Global storage of Application pointer - only one Application can exist.
OptionalContinuation(Action< Ts... > *)
ContinuationAction< Ts... > action
OptionalContinuation(Action< Ts... > *parent)
ESPPreferenceObject make_preference(size_t, uint32_t, bool)
bool sync()
Commit pending writes to flash.