20#if defined(__GNUC__) || defined(__clang__)
21#pragma GCC diagnostic push
22#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
25template<
int...>
struct ESPDEPRECATED(
"Use std::index_sequence instead. Removed in 2026.6.0",
"2025.12.0")
seq {};
26template<
int N,
int... S>
27struct ESPDEPRECATED(
"Use std::make_index_sequence instead. Removed in 2026.6.0",
"2025.12.0") gens
28 : gens<N - 1, N - 1, S...> {};
29template<
int... S>
struct gens<0, S...> {
using type =
seq<S...>; };
31#if defined(__GNUC__) || defined(__clang__)
32#pragma GCC diagnostic pop
36#define TEMPLATABLE_VALUE_(type, name) \
38 TemplatableValue<type, Ts...> name##_{}; \
41 template<typename V> void set_##name(V name) { this->name##_ = name; }
43#define TEMPLATABLE_VALUE(type, name) TEMPLATABLE_VALUE_(type, name)
48 static constexpr bool USE_HEAP_STORAGE = std::same_as<T, std::string>;
60 if constexpr (USE_HEAP_STORAGE) {
69 TemplatableValue(F f)
requires std::invocable<F, X...> && std::convertible_to<F, T (*)(X...)>
77 this->
f_ =
new std::function<T(X...)>(std::move(f));
83 if constexpr (USE_HEAP_STORAGE) {
89 this->
f_ =
new std::function<T(X...)>(*other.
f_);
100 if constexpr (USE_HEAP_STORAGE) {
101 this->
value_ = other.value_;
102 other.value_ =
nullptr;
104 new (&this->
value_) T(std::move(other.value_));
119 if (
this != &other) {
127 if (
this != &other) {
136 if constexpr (USE_HEAP_STORAGE) {
150 switch (this->
type_) {
154 return (*this->
f_)(
x...);
156 if constexpr (USE_HEAP_STORAGE) {
164 if constexpr (std::same_as<T, std::string>) {
167 __builtin_unreachable();
183 return default_value;
197 bool is_empty() const requires std::same_as<T, std::
string> {
198 switch (this->
type_) {
204 return this->
value_->empty();
206 return this->
value().empty();
217 switch (this->
type_) {
227 std::string result = this->
value();
228 size_t copy_len = std::min(result.size(), lambda_buf_size - 1);
229 memcpy(lambda_buf, result.data(), copy_len);
230 lambda_buf[copy_len] =
'\0';
236 protected : enum : uint8_t {
248 std::function<T(X...)> *
f_;
265 return this->
check_tuple_(tuple, std::make_index_sequence<
sizeof...(Ts)>{});
269 template<
size_t... S>
bool check_tuple_(
const std::tuple<Ts...> &tuple, std::index_sequence<S...> ) {
270 return this->
check(std::get<S>(tuple)...);
274template<
typename... Ts>
class Automation;
303template<
typename... Ts>
class ActionList;
326 if (this->
next_ !=
nullptr)
335 virtual void play(
const Ts &...
x) = 0;
339 if (this->
next_ !=
nullptr) {
344 template<
size_t... S>
void play_next_tuple_(
const std::tuple<Ts...> &tuple, std::index_sequence<S...> ) {
353 if (this->
next_ !=
nullptr) {
359 if (this->
next_ ==
nullptr)
382 for (
auto *action : actions) {
391 this->
play_tuple_(tuple, std::make_index_sequence<
sizeof...(Ts)>{});
413 template<
size_t... S>
void play_tuple_(
const std::tuple<Ts...> &tuple, std::index_sequence<S...> ) {
414 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.
StringRef is a reference to a string owned by something else.
TemplatableValue(const TemplatableValue &other)
TemplatableValue(F value)
bool is_empty() const
Check if the string value is empty without allocating (for std::string specialization).
std::function< T(X...)> * f_
TemplatableValue(const char *str)
TemplatableValue & operator=(TemplatableValue &&other) noexcept
StringRef ref_or_copy_to(char *lambda_buf, size_t lambda_buf_size) const
Get a StringRef to the string value without heap allocation when possible.
enum esphome::TemplatableValue::@186 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