15template<
int...>
struct seq {};
16template<
int N,
int... S>
struct gens :
gens<N - 1, N - 1, S...> {};
17template<
int... S>
struct gens<0, S...> {
using type =
seq<S...>; };
19#define TEMPLATABLE_VALUE_(type, name) \
21 TemplatableValue<type, Ts...> name##_{}; \
24 template<typename V> void set_##name(V name) { this->name##_ = name; }
26#define TEMPLATABLE_VALUE(type, name) TEMPLATABLE_VALUE_(type, name)
38 TemplatableValue(F f)
requires std::invocable<F, X...> && std::convertible_to<F, T (*)(X...)>
46 this->
f_ =
new std::function<T(X...)>(std::move(f));
54 this->
f_ =
new std::function<T(X...)>(*other.
f_);
63 new (&this->
value_) T(std::move(other.value_));
102 switch (this->
type_) {
106 return (*this->
f_)(
x...);
124 return default_value;
139 std::function<T(X...)> *
f_;
160 return this->
check(std::get<S>(tuple)...);
164template<
typename... Ts>
class Automation;
193template<
typename... Ts>
class ActionList;
216 if (this->
next_ !=
nullptr)
225 virtual void play(
const Ts &...
x) = 0;
229 if (this->
next_ !=
nullptr) {
243 if (this->
next_ !=
nullptr) {
249 if (this->
next_ ==
nullptr)
272 for (
auto *action : actions) {
302 this->
play(std::get<S>(tuple)...);
virtual bool is_running()
Check if this or any of the following actions are currently running.
void play_next_tuple_(const std::tuple< Ts... > &tuple, seq< S... >)
void play_next_(const Ts &...x)
virtual void stop_complex()
virtual void play(const Ts &...x)=0
void play_next_tuple_(const std::tuple< Ts... > &tuple)
int num_running_
The number of instances of this sequence in the list of actions that is currently being executed.
int num_running_total()
The total number of actions that are currently running in this plus any of the following actions in t...
virtual void play_complex(const Ts &...x)
void add_action(Action< Ts... > *action)
Action< Ts... > * actions_end_
void play(const Ts &...x)
void play_tuple(const std::tuple< Ts... > &tuple)
bool is_running()
Check if any action in this action list is currently running.
void play_tuple_(const std::tuple< Ts... > &tuple, seq< S... >)
void add_actions(const std::initializer_list< Action< Ts... > * > &actions)
Action< Ts... > * actions_begin_
int num_running()
Return the number of actions in this action list that are currently running.
void add_action(Action< Ts... > *action)
void trigger(const Ts &...x)
Trigger< Ts... > * trigger_
int num_running()
Return the number of actions in the action part of this automation that are currently running.
Automation(Trigger< Ts... > *trigger)
void add_actions(const std::initializer_list< Action< Ts... > * > &actions)
ActionList< Ts... > actions_
Base class for all automation conditions.
bool check_tuple(const std::tuple< Ts... > &tuple)
Call check with a tuple of values as parameter.
bool check_tuple_(const std::tuple< Ts... > &tuple, seq< S... >)
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.
TemplatableValue(const TemplatableValue &other)
TemplatableValue(F value)
std::function< T(X...)> * f_
TemplatableValue & operator=(TemplatableValue &&other) noexcept
enum esphome::TemplatableValue::@167 type_
TemplatableValue(TemplatableValue &&other) noexcept
TemplatableValue & operator=(const TemplatableValue &other)
T value_or(X... x, T default_value)
optional< T > optional_value(X... x)
void trigger(const Ts &...x)
Inform the parent automation that the event has triggered.
Automation< Ts... > * automation_parent_
void stop_action()
Stop any action connected to this trigger.
bool is_action_running()
Returns true if any action connected to this trigger is running.
void set_automation_parent(Automation< Ts... > *automation_parent)
Providing packet encoding functions for exchanging data with a remote host.