21#if defined(__GNUC__) || defined(__clang__)
22#pragma GCC diagnostic push
23#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
26template<
int...>
struct ESPDEPRECATED(
"Use std::index_sequence instead. Removed in 2026.6.0",
"2025.12.0")
seq {};
27template<
int N,
int... S>
28struct ESPDEPRECATED(
"Use std::make_index_sequence instead. Removed in 2026.6.0",
"2025.12.0") gens
29 : gens<N - 1, N - 1, S...> {};
30template<
int... S>
struct gens<0, S...> {
using type =
seq<S...>; };
32#if defined(__GNUC__) || defined(__clang__)
33#pragma GCC diagnostic pop
37#define TEMPLATABLE_VALUE_(type, name) \
39 TemplatableValue<type, Ts...> name##_{}; \
42 template<typename V> void set_##name(V name) { this->name##_ = name; }
44#define TEMPLATABLE_VALUE(type, name) TEMPLATABLE_VALUE_(type, name)
49 static constexpr bool USE_HEAP_STORAGE = std::same_as<T, std::string>;
66 this->
static_str_ =
reinterpret_cast<const char *
>(str);
71 if constexpr (USE_HEAP_STORAGE) {
80 TemplatableValue(F f)
requires std::invocable<F, X...> && std::convertible_to<F, T (*)(X...)>
88 this->
f_ =
new std::function<T(X...)>(std::move(f));
94 if constexpr (USE_HEAP_STORAGE) {
100 this->
f_ =
new std::function<T(X...)>(*other.
f_);
111 if constexpr (USE_HEAP_STORAGE) {
112 this->
value_ = other.value_;
113 other.value_ =
nullptr;
115 new (&this->
value_) T(std::move(other.value_));
130 if (
this != &other) {
138 if (
this != &other) {
147 if constexpr (USE_HEAP_STORAGE) {
161 switch (this->
type_) {
165 return (*this->
f_)(
x...);
167 if constexpr (USE_HEAP_STORAGE) {
175 if constexpr (std::same_as<T, std::string>) {
178 __builtin_unreachable();
182 if constexpr (std::same_as<T, std::string>) {
184 std::string result(
len,
'\0');
185 memcpy_P(result.data(), this->static_str_,
len);
188 __builtin_unreachable();
205 return default_value;
222 bool is_empty() const requires std::same_as<T, std::
string> {
223 switch (this->
type_) {
235 return this->
value_->empty();
237 return this->
value().empty();
249 switch (this->
type_) {
263 size_t copy_len = std::min(
len, lambda_buf_size - 1);
265 lambda_buf[copy_len] =
'\0';
272 std::string result = this->
value();
273 size_t copy_len = std::min(result.size(), lambda_buf_size - 1);
274 memcpy(lambda_buf, result.data(), copy_len);
275 lambda_buf[copy_len] =
'\0';
281 protected : enum : uint8_t {
294 std::function<T(X...)> *
f_;
311 return this->
check_tuple_(tuple, std::make_index_sequence<
sizeof...(Ts)>{});
315 template<
size_t... S>
bool check_tuple_(
const std::tuple<Ts...> &tuple, std::index_sequence<S...> ) {
316 return this->
check(std::get<S>(tuple)...);
320template<
typename... Ts>
class Automation;
349template<
typename... Ts>
class ActionList;
372 if (this->
next_ !=
nullptr)
381 virtual void play(
const Ts &...
x) = 0;
385 if (this->
next_ !=
nullptr) {
390 template<
size_t... S>
void play_next_tuple_(
const std::tuple<Ts...> &tuple, std::index_sequence<S...> ) {
399 if (this->
next_ !=
nullptr) {
405 if (this->
next_ ==
nullptr)
428 for (
auto *action : actions) {
437 this->
play_tuple_(tuple, std::make_index_sequence<
sizeof...(Ts)>{});
459 template<
size_t... S>
void play_tuple_(
const std::tuple<Ts...> &tuple, std::index_sequence<S...> ) {
460 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) The pointer is always dir...
const char * get_static_string() const
Get the static string pointer (only valid if is_static_string() returns true) The pointer is always d...
TemplatableValue & operator=(const TemplatableValue &other)
T value_or(X... x, T default_value)
TemplatableValue(const __FlashStringHelper *str)
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
uint8_t progmem_read_byte(const uint8_t *addr)