13 void esp_logw_(
int line,
const char *format,
const char *param) {
14 esp_log_(ESPHOME_LOG_LEVEL_WARN, line, format, param);
16 void esp_logd_(
int line,
const char *format,
const char *param) {
17 esp_log_(ESPHOME_LOG_LEVEL_DEBUG, line, format, param);
19 void esp_log_(
int level,
int line,
const char *format,
const char *param);
29 virtual void execute(Ts...) = 0;
31 virtual bool is_running() {
return this->is_action_running(); }
33 virtual void stop() { this->stop_action(); }
37 this->execute_tuple_(tuple,
typename gens<
sizeof...(Ts)>::
type());
45 this->execute(std::get<S>(tuple)...);
59 if (this->is_action_running()) {
60 this->
esp_logw_(__LINE__,
"Script '%s' is already running! (mode: single)", this->name_.c_str());
76 if (this->is_action_running()) {
77 this->
esp_logd_(__LINE__,
"Script '%s' restarting (mode: restart)", this->name_.c_str());
92 if (this->is_action_running() || this->num_runs_ > 0) {
95 if (this->max_runs_ != 0 && this->num_runs_ + 1 >= this->max_runs_) {
96 this->
esp_logw_(__LINE__,
"Script '%s' maximum number of queued runs exceeded!", this->name_.c_str());
100 this->
esp_logd_(__LINE__,
"Script '%s' queueing new instance (mode: queued)", this->name_.c_str());
102 this->var_queue_.push(std::make_tuple(
x...));
117 if (this->num_runs_ != 0 && !this->is_action_running()) {
119 auto &vars = this->var_queue_.front();
120 this->var_queue_.pop();
121 this->trigger_tuple_(vars,
typename gens<
sizeof...(Ts)>::
type());
129 this->trigger(std::get<S>(tuple)...);
145 if (this->max_runs_ != 0 && this->automation_parent_->num_running() >= this->max_runs_) {
146 this->
esp_logw_(__LINE__,
"Script '%s' maximum number of parallel runs exceeded!", this->name_.c_str());
167 void play(Ts...
x)
override { this->script_->execute_tuple(this->eval_args_(
x...)); }
175 template<std::
size_t N>
177 std::integral_constant<std::size_t, N> , Ts... ) {}
179 template<std::
size_t I, std::
size_t N>
180 void eval_args_impl_(std::tuple<As...> &evaled_args, std::integral_constant<std::size_t, I> ,
181 std::integral_constant<std::size_t, N> n, Ts...
x) {
182 std::get<I>(evaled_args) = std::get<I>(args_).value(
x...);
183 eval_args_impl_(evaled_args, std::integral_constant<std::size_t, I + 1>{}, n,
188 std::tuple<As...> evaled_args;
189 eval_args_impl_(evaled_args, std::integral_constant<std::size_t, 0>{}, std::tuple_size<Args>{},
x...);
201 void play(Ts...
x)
override { this->script_->stop(); }
211 bool check(Ts...
x)
override {
return this->parent_->is_running(); }
222 this->num_running_++;
224 if (!this->script_->is_running()) {
225 this->play_next_(
x...);
228 this->var_ = std::make_tuple(
x...);
233 if (this->num_running_ == 0)
236 if (this->script_->is_running())
239 this->play_next_tuple_(this->var_);
249 std::tuple<Ts...> var_{};
const float DATA
For components that import data from directly connected sensors like DHT.
A script type that queues new instances that are created.
void execute(Ts... x) override
void set_max_runs(int max_runs)
bool check(Ts... x) override
void execute_tuple_(const std::tuple< Ts... > &tuple, seq< S... >)
A script type that restarts scripts from the beginning when a new instance is started.
std::queue< std::tuple< Ts... > > var_queue_
virtual bool is_running()
Check if any instance of this script is currently running.
void trigger_tuple_(const std::tuple< Ts... > &tuple, seq< S... >)
virtual void stop()
Stop all instances of this script.
ScriptStopAction(C *script)
IsRunningCondition(C *parent)
void execute(Ts... x) override
void play(Ts... x) override
A script type that executes new instances in parallel.
std::tuple< As... > eval_args_(Ts... x)
void esp_logw_(int line, const char *format, const char *param)
void play(Ts... x) override
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 execute(Ts... x) override
std::tuple< TemplatableValue< As, Ts... >... > Args
Base class for all automation conditions.
void set_name(const std::string &name)
void execute_tuple(const std::tuple< Ts... > &tuple)
A script type for which only a single instance at a time is allowed.
The abstract base class for all script types.
void set_max_runs(int max_runs)
float get_setup_priority() const override
void play(Ts... x) override
ScriptExecuteAction(Script< As... > *script)
void esp_log_(int level, int line, const char *format, const char *param)
Implementation of SPI Controller mode.
Script< As... > * script_
void play_complex(Ts... x) override
ScriptWaitAction(C *script)
void esp_logd_(int line, const char *format, const char *param)
void execute(Ts... x) override
void eval_args_impl_(std::tuple< As... > &, std::integral_constant< std::size_t, N >, std::integral_constant< std::size_t, N >, Ts...)