19#if defined(__GNUC__) || defined(__clang__)
20#pragma GCC diagnostic push
21#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
24template<
int...>
struct ESPDEPRECATED(
"Use std::index_sequence instead. Removed in 2026.6.0",
"2025.12.0")
seq {};
25template<
int N,
int... S>
26struct ESPDEPRECATED(
"Use std::make_index_sequence instead. Removed in 2026.6.0",
"2025.12.0") gens
27 : gens<N - 1, N - 1, S...> {};
28template<
int... S>
struct gens<0, S...> {
using type =
seq<S...>; };
30#if defined(__GNUC__) || defined(__clang__)
31#pragma GCC diagnostic pop
35#define TEMPLATABLE_VALUE_(type, name) \
37 TemplatableValue<type, Ts...> name##_{}; \
40 template<typename V> void set_##name(V name) { this->name##_ = name; }
42#define TEMPLATABLE_VALUE(type, name) TEMPLATABLE_VALUE_(type, name)
47 static constexpr bool USE_HEAP_STORAGE = std::same_as<T, std::string>;
59 if constexpr (USE_HEAP_STORAGE) {
68 TemplatableValue(F f)
requires std::invocable<F, X...> && std::convertible_to<F, T (*)(X...)>
76 this->
f_ =
new std::function<T(X...)>(std::move(f));
82 if constexpr (USE_HEAP_STORAGE) {
88 this->
f_ =
new std::function<T(X...)>(*other.
f_);
99 if constexpr (USE_HEAP_STORAGE) {
100 this->
value_ = other.value_;
101 other.value_ =
nullptr;
103 new (&this->
value_) T(std::move(other.value_));
118 if (
this != &other) {
126 if (
this != &other) {
135 if constexpr (USE_HEAP_STORAGE) {
149 switch (this->
type_) {
153 return (*this->
f_)(
x...);
155 if constexpr (USE_HEAP_STORAGE) {
163 if constexpr (std::same_as<T, std::string>) {
166 __builtin_unreachable();
182 return default_value;
207 std::function<T(X...)> *
f_;
224 return this->
check_tuple_(tuple, std::make_index_sequence<
sizeof...(Ts)>{});
228 template<
size_t... S>
bool check_tuple_(
const std::tuple<Ts...> &tuple, std::index_sequence<S...> ) {
229 return this->
check(std::get<S>(tuple)...);
233template<
typename... Ts>
class Automation;
262template<
typename... Ts>
class ActionList;
285 if (this->
next_ !=
nullptr)
294 virtual void play(
const Ts &...
x) = 0;
298 if (this->
next_ !=
nullptr) {
303 template<
size_t... S>
void play_next_tuple_(
const std::tuple<Ts...> &tuple, std::index_sequence<S...> ) {
312 if (this->
next_ !=
nullptr) {
318 if (this->
next_ ==
nullptr)
341 for (
auto *action : actions) {
350 this->
play_tuple_(tuple, std::make_index_sequence<
sizeof...(Ts)>{});
372 template<
size_t... S>
void play_tuple_(
const std::tuple<Ts...> &tuple, std::index_sequence<S...> ) {
373 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_(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...
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)
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 add_actions(const std::initializer_list< Action< Ts... > * > &actions)
Action< Ts... > * actions_begin_
void play_tuple_(const std::tuple< Ts... > &tuple, std::index_sequence< S... >)
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, std::index_sequence< S... >)
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.
TemplatableValue(const TemplatableValue &other)
TemplatableValue(F value)
std::function< T(X...)> * f_
TemplatableValue(const char *str)
TemplatableValue & operator=(TemplatableValue &&other) noexcept
enum esphome::TemplatableValue::@185 type_
TemplatableValue(TemplatableValue &&other) noexcept
bool is_static_string() const
Check if this holds a static string (const char* stored without allocation)
const char * get_static_string() const
Get the static string pointer (only valid if is_static_string() returns true)
TemplatableValue & operator=(const TemplatableValue &other)
T value_or(X... x, T default_value)
optional< T > optional_value(X... x)
std::conditional_t< USE_HEAP_STORAGE, T *, T > ValueStorage
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.
struct ESPDEPRECATED("Use std::index_sequence instead. Removed in 2026.6.0", "2025.12.0") seq