mirror of
https://github.com/esphome/esphome.git
synced 2025-10-03 10:32:21 +01:00
Merge branch 'script_name' into integration
This commit is contained in:
@@ -124,7 +124,7 @@ async def to_code(config):
|
|||||||
template, func_args = parameters_to_template(conf[CONF_PARAMETERS])
|
template, func_args = parameters_to_template(conf[CONF_PARAMETERS])
|
||||||
trigger = cg.new_Pvariable(conf[CONF_ID], template)
|
trigger = cg.new_Pvariable(conf[CONF_ID], template)
|
||||||
# Add a human-readable name to the script
|
# Add a human-readable name to the script
|
||||||
cg.add(trigger.set_name(conf[CONF_ID].id))
|
cg.add(trigger.set_name(cg.LogStringLiteral(conf[CONF_ID].id)))
|
||||||
|
|
||||||
if CONF_MAX_RUNS in conf:
|
if CONF_MAX_RUNS in conf:
|
||||||
cg.add(trigger.set_max_runs(conf[CONF_MAX_RUNS]))
|
cg.add(trigger.set_max_runs(conf[CONF_MAX_RUNS]))
|
||||||
|
@@ -48,14 +48,14 @@ template<typename... Ts> class Script : public ScriptLogger, public Trigger<Ts..
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Internal function to give scripts readable names.
|
// Internal function to give scripts readable names.
|
||||||
void set_name(const std::string &name) { name_ = name; }
|
void set_name(const LogString *name) { name_ = name; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
template<int... S> void execute_tuple_(const std::tuple<Ts...> &tuple, seq<S...> /*unused*/) {
|
template<int... S> void execute_tuple_(const std::tuple<Ts...> &tuple, seq<S...> /*unused*/) {
|
||||||
this->execute(std::get<S>(tuple)...);
|
this->execute(std::get<S>(tuple)...);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string name_;
|
const LogString *name_{nullptr};
|
||||||
};
|
};
|
||||||
|
|
||||||
/** A script type for which only a single instance at a time is allowed.
|
/** A script type for which only a single instance at a time is allowed.
|
||||||
@@ -68,7 +68,7 @@ template<typename... Ts> class SingleScript : public Script<Ts...> {
|
|||||||
void execute(Ts... x) override {
|
void execute(Ts... x) override {
|
||||||
if (this->is_action_running()) {
|
if (this->is_action_running()) {
|
||||||
this->esp_logw_(__LINE__, ESPHOME_LOG_FORMAT("Script '%s' is already running! (mode: single)"),
|
this->esp_logw_(__LINE__, ESPHOME_LOG_FORMAT("Script '%s' is already running! (mode: single)"),
|
||||||
this->name_.c_str());
|
LOG_STR_ARG(this->name_));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -85,7 +85,7 @@ template<typename... Ts> class RestartScript : public Script<Ts...> {
|
|||||||
public:
|
public:
|
||||||
void execute(Ts... x) override {
|
void execute(Ts... x) override {
|
||||||
if (this->is_action_running()) {
|
if (this->is_action_running()) {
|
||||||
this->esp_logd_(__LINE__, ESPHOME_LOG_FORMAT("Script '%s' restarting (mode: restart)"), this->name_.c_str());
|
this->esp_logd_(__LINE__, ESPHOME_LOG_FORMAT("Script '%s' restarting (mode: restart)"), LOG_STR_ARG(this->name_));
|
||||||
this->stop_action();
|
this->stop_action();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -105,12 +105,12 @@ template<typename... Ts> class QueueingScript : public Script<Ts...>, public Com
|
|||||||
// num_runs_ + 1
|
// num_runs_ + 1
|
||||||
if (this->max_runs_ != 0 && this->num_runs_ + 1 >= this->max_runs_) {
|
if (this->max_runs_ != 0 && this->num_runs_ + 1 >= this->max_runs_) {
|
||||||
this->esp_logw_(__LINE__, ESPHOME_LOG_FORMAT("Script '%s' maximum number of queued runs exceeded!"),
|
this->esp_logw_(__LINE__, ESPHOME_LOG_FORMAT("Script '%s' maximum number of queued runs exceeded!"),
|
||||||
this->name_.c_str());
|
LOG_STR_ARG(this->name_));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
this->esp_logd_(__LINE__, ESPHOME_LOG_FORMAT("Script '%s' queueing new instance (mode: queued)"),
|
this->esp_logd_(__LINE__, ESPHOME_LOG_FORMAT("Script '%s' queueing new instance (mode: queued)"),
|
||||||
this->name_.c_str());
|
LOG_STR_ARG(this->name_));
|
||||||
this->num_runs_++;
|
this->num_runs_++;
|
||||||
this->var_queue_.push(std::make_tuple(x...));
|
this->var_queue_.push(std::make_tuple(x...));
|
||||||
return;
|
return;
|
||||||
@@ -157,7 +157,7 @@ template<typename... Ts> class ParallelScript : public Script<Ts...> {
|
|||||||
void execute(Ts... x) override {
|
void execute(Ts... x) override {
|
||||||
if (this->max_runs_ != 0 && this->automation_parent_->num_running() >= this->max_runs_) {
|
if (this->max_runs_ != 0 && this->automation_parent_->num_running() >= this->max_runs_) {
|
||||||
this->esp_logw_(__LINE__, ESPHOME_LOG_FORMAT("Script '%s' maximum number of parallel runs exceeded!"),
|
this->esp_logw_(__LINE__, ESPHOME_LOG_FORMAT("Script '%s' maximum number of parallel runs exceeded!"),
|
||||||
this->name_.c_str());
|
LOG_STR_ARG(this->name_));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this->trigger(x...);
|
this->trigger(x...);
|
||||||
|
Reference in New Issue
Block a user