36#ifdef USE_SCRIPT_ON_STOP
64#ifdef USE_SCRIPT_ON_STOP
69 const LogString *
name_{
nullptr};
70#ifdef USE_SCRIPT_ON_STOP
84 this->
esp_logw_(__LINE__, ESPHOME_LOG_FORMAT(
"Script '%s' is already running! (mode: single)"),
85 LOG_STR_ARG(this->
name_));
102 this->
esp_logd_(__LINE__, ESPHOME_LOG_FORMAT(
"Script '%s' restarting (mode: restart)"), LOG_STR_ARG(this->
name_));
104#ifdef USE_SCRIPT_ON_STOP
137 this->
esp_logw_(__LINE__, ESPHOME_LOG_FORMAT(
"Script '%s' max instances (running + queued) reached!"),
138 LOG_STR_ARG(this->
name_));
145 this->
esp_logd_(__LINE__, ESPHOME_LOG_FORMAT(
"Script '%s' queueing new instance (mode: queued)"),
146 LOG_STR_ARG(this->
name_));
148 const size_t queue_capacity =
static_cast<size_t>(this->
max_runs_ - 1);
151 this->
var_queue_[write_pos] = std::make_unique<std::tuple<Ts...>>(
x...);
165#ifdef USE_SCRIPT_ON_STOP
174#ifdef USE_SCRIPT_ON_STOP
186 const size_t queue_capacity =
static_cast<size_t>(this->
max_runs_ - 1);
188 this->queue_front_ = (this->queue_front_ + 1) % queue_capacity;
189 this->
trigger_tuple_(*tuple_ptr, std::make_index_sequence<
sizeof...(Ts)>{});
211 this->
var_queue_ = std::make_unique<std::unique_ptr<std::tuple<Ts...>>[]>(this->
max_runs_ - 1);
215 template<
size_t... S>
void trigger_tuple_(
const std::tuple<Ts...> &tuple, std::index_sequence<S...> ) {
222 std::unique_ptr<std::unique_ptr<std::tuple<Ts...>>[]>
var_queue_;
234 this->
esp_logw_(__LINE__, ESPHOME_LOG_FORMAT(
"Script '%s' maximum number of parallel runs exceeded!"),
235 LOG_STR_ARG(this->
name_));
270 if (!this->
script_->is_running()) {
289 if (this->
script_->is_running())
299 std::apply([
this](
auto &...args) { this->
play_next_(args...); }, params);
306 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.
bool is_idle() const
Check if this component is idle.
RAII guard that publishes a current source (e.g.
Automation< Ts... > * automation_parent_
void trigger(const Ts &...x) ESPHOME_ALWAYS_INLINE
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, std::index_sequence< 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
The abstract base class for all script types.
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.
Trigger * get_stop_trigger()
virtual void stop()
Stop all instances of this script. Fires the on_stop trigger once if any instance was running.
void run_actions_(const Ts &...x) ESPHOME_ALWAYS_INLINE
void set_name(const LogString *name)
void esp_logw_(int line, ProgmemStr format, const char *param)
void esp_logd_(int line, ProgmemStr format, const char *param)
void esp_log_(int level, int line, ProgmemStr format, const char *param)
Wait for a script to finish before continuing.
void play(const Ts &...x) override
ScriptWaitAction(C *script)
std::list< std::tuple< stored_trigger_arg_t< Ts >... > > param_queue_
void play_complex(const Ts &...x) override
A script type for which only a single instance at a time is allowed.
void execute(Ts... x) override
const __FlashStringHelper * ProgmemStr