13#include <forward_list>
20 bool check(
const Ts &...
x)
override {
22 if (!condition->check(
x...))
36 bool check(
const Ts &...
x)
override {
38 if (condition->check(
x...))
61 bool check(
const Ts &...
x)
override {
64 result += condition->check(
x...);
77 bool check(
const Ts &...
x)
override {
return this->
f_(x...); }
80 std::function<bool(Ts...)>
f_;
89 bool check(
const Ts &...
x)
override {
return this->
f_(x...); }
153#ifdef ESPHOME_PROJECT_NAME
157 uint32_t hash =
fnv1_hash(ESPHOME_PROJECT_NAME);
159 char previous_version[30];
160 char current_version[30] = ESPHOME_PROJECT_VERSION_30;
161 if (pref.
load(&previous_version)) {
162 int cmp = strcmp(previous_version, current_version);
164 this->
trigger(previous_version);
167 pref.
save(¤t_version);
190 App.scheduler.set_timer_common_(
this, Scheduler::SchedulerItem::TIMEOUT,
191 true,
"delay", this->delay_.value(
x...), std::move(f),
192 false, this->num_running_ > 1);
196 void play(
const Ts &...
x)
override {
206 void play(
const Ts &...
x)
override { this->
f_(x...); }
209 std::function<void(Ts...)>
f_;
219 void play(
const Ts &...
x)
override { this->
f_(x...); }
247 void play(
const Ts &...
x)
override;
285 void play(
const Ts &...
x)
override {
325 void play(
const Ts &...
x)
override {
337 if (this->parent_->num_running_ > 0 && this->parent_->condition_->check(
x...)) {
339 this->parent_->then_.play(
x...);
342 this->parent_->play_next_(
x...);
355 void play(
const uint32_t &iteration,
const Ts &...
x)
override;
374 if (this->count_.value(
x...) > 0) {
381 void play(
const Ts &...
x)
override {
392 uint32_t next_iteration = iteration + 1;
393 if (next_iteration >= this->parent_->count_.value(
x...)) {
394 this->parent_->play_next_(
x...);
396 this->parent_->then_.play(next_iteration,
x...);
413 void setup()
override {
435 auto timeout = this->timeout_value_.optional_value(
x...);
436 this->
var_queue_.emplace_front(now, timeout, std::make_tuple(
x...));
460 void play(
const Ts &...
x)
override {
468 this->
var_queue_.remove_if([&](
auto &queued) {
469 auto start = std::get<uint32_t>(queued);
470 auto timeout = std::get<optional<uint32_t>>(queued);
471 auto &var = std::get<std::tuple<Ts...>>(queued);
474 auto expired = timeout && (now - start) >= *timeout;
490 std::forward_list<std::tuple<uint32_t, optional<uint32_t>, std::tuple<Ts...>>>
var_queue_{};
497 void play(
const Ts &...
x)
override {
511 void play(
const Ts &...
x)
override {
526 void play(
const Ts &...
x)
override {
void play_next_tuple_(const std::tuple< Ts... > &tuple, seq< S... >)
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 play(const Ts &...x)
void add_actions(const std::initializer_list< Action< Ts... > * > &actions)
bool check(const Ts &...x) override
AndCondition(std::initializer_list< Condition< Ts... > * > conditions)
FixedVector< Condition< Ts... > * > 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.
bool cancel_timeout(const std::string &name)
Cancel a timeout function.
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
float get_setup_priority() const override
virtual bool sync()=0
Commit pending writes to flash.
virtual ESPPreferenceObject make_preference(size_t length, uint32_t type, bool in_flash)=0
Fixed-capacity vector - allocates once at runtime, never reallocates This avoids std::vector template...
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)
Condition< Ts... > * condition_
void play_complex(const Ts &...x) override
void add_then(const std::initializer_list< Action< Ts... > * > &actions)
void add_else(const std::initializer_list< Action< Ts... > * > &actions)
ActionList< Ts... > else_
void play(const Ts &...x) override
ActionList< Ts... > then_
IfAction(Condition< Ts... > *condition)
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)
FixedVector< Condition< Ts... > * > conditions_
bool check(const Ts &...x) override
OrCondition(std::initializer_list< Condition< Ts... > * > conditions)
This class simplifies creating components that periodically check a state.
virtual 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
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)
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
std::forward_list< std::tuple< uint32_t, optional< uint32_t >, std::tuple< Ts... > > > var_queue_
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)
WhileAction(Condition< Ts... > *condition)
void play(const Ts &...x) override
void play_complex(const Ts &...x) override
Condition< Ts... > * condition_
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_
FixedVector< Condition< Ts... > * > conditions_
XorCondition(std::initializer_list< Condition< Ts... > * > conditions)
bool check(const Ts &...x) override
value_type const & value() const
const Component * component
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.