26 template<
typename... Cs>
27 requires(
sizeof...(Cs) == N)
29 bool check(
const Ts &...
x)
override {
31 if (!condition->check(
x...))
48 template<
typename... Cs>
49 requires(
sizeof...(Cs) == N)
51 bool check(
const Ts &...
x)
override {
53 if (condition->check(
x...))
79 template<
typename... Cs>
80 requires(
sizeof...(Cs) == N)
82 bool check(
const Ts &...
x)
override {
85 result += condition->check(
x...);
98 bool check(
const Ts &...
x)
override {
return this->
f_(x...); }
101 std::function<bool(Ts...)>
f_;
110 bool check(
const Ts &...
x)
override {
return this->
f_(x...); }
174#ifdef ESPHOME_PROJECT_NAME
180 char previous_version[30];
181 char current_version[30] = ESPHOME_PROJECT_VERSION_30;
182 if (pref.
load(&previous_version)) {
183 int cmp = strcmp(previous_version, current_version);
185 this->
trigger(previous_version);
188 pref.
save(¤t_version);
215 if constexpr (
sizeof...(Ts) == 0) {
218 nullptr, Scheduler::SchedulerItem::TIMEOUT, Scheduler::NameType::SELF_POINTER,
219 reinterpret_cast<const char *
>(
this), 0, this->delay_.value(),
221 this->num_running_ > 1,
230 auto f = [
this,
x...]()
mutable { this->
play_next_(x...); };
232 nullptr, Scheduler::SchedulerItem::TIMEOUT, Scheduler::NameType::SELF_POINTER,
233 reinterpret_cast<const char *
>(
this), 0, this->delay_.value(
x...),
235 this->num_running_ > 1,
241 void play(
const Ts &...
x)
override { }
250 void play(
const Ts &...
x)
override { this->
f_(x...); }
253 std::function<void(Ts...)>
f_;
263 void play(
const Ts &...
x)
override { this->
f_(x...); }
275 void play(
const Ts &...
x)
override { Fn(
x...); }
281 bool check(
const Ts &...
x)
override {
return Fn(
x...); }
299 this->
else_.add_actions(actions);
300 this->
else_.set_owner(
this);
310 this->
else_.add_action(action);
315 this->
else_.set_owner(
this);
322 if (!this->
then_.
empty() && this->num_running_ > 0) {
326 }
else if constexpr (HasElse) {
327 if (!this->
else_.empty() && this->num_running_ > 0) {
340 if constexpr (HasElse) {
387 void play(
const Ts &...
x)
override {
435 if (this->count_.value(
x...) > 0) {
442 void play(
const Ts &...
x)
override { }
453 uint32_t next_iteration = iteration + 1;
454 if (next_iteration >= this->parent_->count_.value(
x...)) {
455 this->parent_->play_next_(
x...);
457 this->parent_->then_.play(next_iteration,
x...);
474 void setup()
override {
496 auto timeout = this->timeout_value_.optional_value(
x...);
525 void play(
const Ts &...
x)
override { }
533 std::tuple<stored_trigger_arg_t<Ts>...>
args;
543 std::list<QueueItem> queue;
545 std::list<QueueItem> pending;
546 while (!queue.empty()) {
547 auto it = queue.begin();
548 auto start = it->start;
549 auto timeout = it->timeout;
552 auto expired = timeout && (now - start) >= *timeout;
555 if (!expired && !std::apply([
this](
auto &...args) {
return this->
condition_->
check(args...); }, it->args)) {
556 pending.splice(pending.end(), queue, it);
563 std::list<QueueItem> completed;
564 completed.splice(completed.begin(), queue, it);
566 std::apply([
this](
auto &...args) { this->
play_next_(args...); }, completed.front().args);
591 void play(
const Ts &...
x)
override {
605 void play(
const Ts &...
x)
override {
620 void play(
const Ts &...
x)
override {
624 optional<uint32_t> update_interval = this->update_interval_.optional_value(
x...);
625 if (update_interval.has_value()) {
void play_next_(const Ts &...x)
virtual void play(const Ts &...x)=0
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
void set_owner(Action< Ts... > *owner)
Resume owner via play() when the list finishes; call once, after adding actions.
AndCondition(std::initializer_list< Condition< Ts... > * > conditions)
bool check(const Ts &...x) override
std::array< Condition< Ts... > *, N > conditions_
AndCondition(Cs *...conditions)
const LogString * get_current_source()
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.
Runs one codegen-generated function that has the parent and every field baked in.
void play(const Ts &...x) override
Condition counterpart of ApplyAction: one codegen-generated predicate with the parent baked in.
bool check(const Ts &...x) override
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.
virtual bool check(const Ts &...x)=0
Check whether this condition passes. This condition check must be instant, and not cause any delays.
void play(const Ts &...x) override
TEMPLATABLE_VALUE(uint32_t, delay) void play_complex(const Ts &...x) override
constexpr DelayAction() noexcept
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_
void play(const Ts &...x) override
void add_then(const std::initializer_list< Action< Ts... > * > &actions)
void play_complex(const Ts &...x) final
std::conditional_t< HasElse, ActionList< Ts... >, NoElse > else_
void add_else_action(Action< Ts... > *action)
void add_then_action(Action< Ts... > *action)
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)
OrCondition(Cs *...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 add_then_action(Action< uint32_t, Ts... > *action)
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)
std::list< QueueItem > var_queue_
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_
float get_setup_priority() const override
void add_then(const std::initializer_list< Action< Ts... > * > &actions)
void play_complex(const Ts &...x) final
WhileAction(Condition< Ts... > *condition)
void play(const Ts &...x) override
void add_then_action(Action< Ts... > *action)
Condition< Ts... > * condition_
ActionList< Ts... > then_
std::array< Condition< Ts... > *, N > conditions_
XorCondition(Cs *...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.
ESPPreferenceObject make_preference(size_t, uint32_t, bool)
bool sync()
Commit pending writes to flash.
std::tuple< stored_trigger_arg_t< Ts >... > args
optional< uint32_t > timeout
QueueItem(uint32_t start, optional< uint32_t > timeout, const Ts &...x)