15#ifdef USE_STORE_LOG_STR_IN_FLASH
16 void esp_logw_(
int line,
const __FlashStringHelper *format,
const char *param) {
17 esp_log_(ESPHOME_LOG_LEVEL_WARN, line, format, param);
19 void esp_logd_(
int line,
const __FlashStringHelper *format,
const char *param) {
20 esp_log_(ESPHOME_LOG_LEVEL_DEBUG, line, format, param);
22 void esp_log_(
int level,
int line,
const __FlashStringHelper *format,
const char *param);
24 void esp_logw_(
int line,
const char *format,
const char *param) {
25 esp_log_(ESPHOME_LOG_LEVEL_WARN, line, format, param);
27 void esp_logd_(
int line,
const char *format,
const char *param) {
28 esp_log_(ESPHOME_LOG_LEVEL_DEBUG, line, format, param);
30 void esp_log_(
int level,
int line,
const char *format,
const char *param);
57 this->
execute(std::get<S>(tuple)...);
60 const LogString *
name_{
nullptr};
72 this->
esp_logw_(__LINE__, ESPHOME_LOG_FORMAT(
"Script '%s' is already running! (mode: single)"),
73 LOG_STR_ARG(this->
name_));
90 this->
esp_logd_(__LINE__, ESPHOME_LOG_FORMAT(
"Script '%s' restarting (mode: restart)"), LOG_STR_ARG(this->
name_));
120 this->
esp_logw_(__LINE__, ESPHOME_LOG_FORMAT(
"Script '%s' max instances (running + queued) reached!"),
121 LOG_STR_ARG(this->
name_));
128 this->
esp_logd_(__LINE__, ESPHOME_LOG_FORMAT(
"Script '%s' queueing new instance (mode: queued)"),
129 LOG_STR_ARG(this->
name_));
131 const size_t queue_capacity =
static_cast<size_t>(this->
max_runs_ - 1);
134 this->
var_queue_[write_pos] = std::make_unique<std::tuple<Ts...>>(
x...);
157 const size_t queue_capacity =
static_cast<size_t>(this->
max_runs_ - 1);
159 this->queue_front_ = (this->queue_front_ + 1) % queue_capacity;
173 this->
var_queue_ = std::make_unique<std::unique_ptr<std::tuple<Ts...>>[]>(this->
max_runs_ - 1);
178 this->
trigger(std::get<S>(tuple)...);
184 std::unique_ptr<std::unique_ptr<std::tuple<Ts...>>[]>
var_queue_;
196 this->
esp_logw_(__LINE__, ESPHOME_LOG_FORMAT(
"Script '%s' maximum number of parallel runs exceeded!"),
197 LOG_STR_ARG(this->
name_));
218 void play(
const Ts &...
x)
override { this->script_->execute_tuple(this->eval_args_(
x...)); }
226 template<std::
size_t N>
228 std::integral_constant<std::size_t, N> , Ts... ) {}
230 template<std::
size_t I, std::
size_t N>
231 void eval_args_impl_(std::tuple<As...> &evaled_args, std::integral_constant<std::size_t, I> ,
232 std::integral_constant<std::size_t, N> n, Ts...
x) {
233 std::get<I>(evaled_args) = std::get<I>(args_).value(
x...);
234 eval_args_impl_(evaled_args, std::integral_constant<std::size_t, I + 1>{}, n,
239 std::tuple<As...> evaled_args;
240 eval_args_impl_(evaled_args, std::integral_constant<std::size_t, 0>{}, std::tuple_size<Args>{},
x...);
287 if (!this->
script_->is_running()) {
303 if (this->
script_->is_running())
315 void play(
const Ts &...
x)
override {
void play_next_(const Ts &...x)
int num_running()
Return the number of actions in the action part of this automation that are currently running.
void enable_loop()
Enable this component's loop.
void disable_loop()
Disable this component's loop.
Base class for all automation conditions.
void trigger(const Ts &...x)
Automation< Ts... > * automation_parent_
IsRunningCondition(C *parent)
bool check(const Ts &...x) override
A script type that executes new instances in parallel.
void execute(Ts... x) override
void set_max_runs(int max_runs)
A script type that queues new instances that are created.
void trigger_tuple_(const std::tuple< Ts... > &tuple, seq< S... >)
void execute(Ts... x) override
void set_max_runs(int max_runs)
std::unique_ptr< std::unique_ptr< std::tuple< Ts... > >[]> var_queue_
A script type that restarts scripts from the beginning when a new instance is started.
void execute(Ts... x) override
void play(const Ts &...x) override
Script< As... > * script_
void eval_args_impl_(std::tuple< As... > &evaled_args, std::integral_constant< std::size_t, I >, std::integral_constant< std::size_t, N > n, Ts... x)
void eval_args_impl_(std::tuple< As... > &, std::integral_constant< std::size_t, N >, std::integral_constant< std::size_t, N >, Ts...)
std::tuple< TemplatableValue< As, Ts... >... > Args
std::tuple< As... > eval_args_(Ts... x)
ScriptExecuteAction(Script< As... > *script)
The abstract base class for all script types.
void execute_tuple_(const std::tuple< Ts... > &tuple, seq< S... >)
virtual bool is_running()
Check if any instance of this script is currently running.
virtual void execute(Ts...)=0
Execute a new instance of this script.
void execute_tuple(const std::tuple< Ts... > &tuple)
virtual void stop()
Stop all instances of this script.
void set_name(const LogString *name)
void esp_logd_(int line, const char *format, const char *param)
void esp_logd_(int line, const __FlashStringHelper *format, const char *param)
void esp_logw_(int line, const char *format, const char *param)
void esp_logw_(int line, const __FlashStringHelper *format, const char *param)
void esp_log_(int level, int line, const __FlashStringHelper *format, const char *param)
void play(const Ts &...x) override
ScriptStopAction(C *script)
Wait for a script to finish before continuing.
void play_next_tuple_(const std::tuple< Ts... > &tuple, seq< S... >)
void play(const Ts &...x) override
ScriptWaitAction(C *script)
void play_complex(const Ts &...x) override
std::forward_list< std::tuple< Ts... > > param_queue_
A script type for which only a single instance at a time is allowed.
void execute(Ts... x) override
Providing packet encoding functions for exchanging data with a remote host.