1
0
mirror of https://github.com/esphome/esphome.git synced 2025-09-08 06:12:20 +01:00

Merge branch 'script_ram' into integration

This commit is contained in:
J. Nick Koston
2025-09-05 10:12:03 -05:00
2 changed files with 25 additions and 5 deletions

View File

@@ -6,9 +6,15 @@ namespace script {
static const char *const TAG = "script"; static const char *const TAG = "script";
#ifdef USE_STORE_LOG_STR_IN_FLASH
void ScriptLogger::esp_log_(int level, int line, const __FlashStringHelper *format, const char *param) {
esp_log_printf_(level, TAG, line, format, param);
}
#else
void ScriptLogger::esp_log_(int level, int line, const char *format, const char *param) { void ScriptLogger::esp_log_(int level, int line, const char *format, const char *param) {
esp_log_printf_(level, TAG, line, format, param); esp_log_printf_(level, TAG, line, format, param);
} }
#endif
} // namespace script } // namespace script
} // namespace esphome } // namespace esphome

View File

@@ -10,6 +10,15 @@ namespace script {
class ScriptLogger { class ScriptLogger {
protected: protected:
#ifdef USE_STORE_LOG_STR_IN_FLASH
void esp_logw_(int line, const __FlashStringHelper *format, const char *param) {
esp_log_(ESPHOME_LOG_LEVEL_WARN, line, format, param);
}
void esp_logd_(int line, const __FlashStringHelper *format, const char *param) {
esp_log_(ESPHOME_LOG_LEVEL_DEBUG, line, format, param);
}
void esp_log_(int level, int line, const __FlashStringHelper *format, const char *param);
#else
void esp_logw_(int line, const char *format, const char *param) { void esp_logw_(int line, const char *format, const char *param) {
esp_log_(ESPHOME_LOG_LEVEL_WARN, line, format, param); esp_log_(ESPHOME_LOG_LEVEL_WARN, line, format, param);
} }
@@ -17,6 +26,7 @@ class ScriptLogger {
esp_log_(ESPHOME_LOG_LEVEL_DEBUG, line, format, param); esp_log_(ESPHOME_LOG_LEVEL_DEBUG, line, format, param);
} }
void esp_log_(int level, int line, const char *format, const char *param); void esp_log_(int level, int line, const char *format, const char *param);
#endif
}; };
/// The abstract base class for all script types. /// The abstract base class for all script types.
@@ -57,7 +67,8 @@ template<typename... Ts> class SingleScript : 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_logw_(__LINE__, "Script '%s' is already running! (mode: single)", this->name_.c_str()); this->esp_logw_(__LINE__, ESPHOME_LOG_FORMAT("Script '%s' is already running! (mode: single)"),
this->name_.c_str());
return; return;
} }
@@ -74,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__, "Script '%s' restarting (mode: restart)", this->name_.c_str()); this->esp_logd_(__LINE__, ESPHOME_LOG_FORMAT("Script '%s' restarting (mode: restart)"), this->name_.c_str());
this->stop_action(); this->stop_action();
} }
@@ -93,11 +104,13 @@ template<typename... Ts> class QueueingScript : public Script<Ts...>, public Com
// num_runs_ is the number of *queued* instances, so total number of instances is // num_runs_ is the number of *queued* instances, so total number of instances is
// 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__, "Script '%s' maximum number of queued runs exceeded!", this->name_.c_str()); this->esp_logw_(__LINE__, ESPHOME_LOG_FORMAT("Script '%s' maximum number of queued runs exceeded!"),
this->name_.c_str());
return; return;
} }
this->esp_logd_(__LINE__, "Script '%s' queueing new instance (mode: queued)", this->name_.c_str()); this->esp_logd_(__LINE__, ESPHOME_LOG_FORMAT("Script '%s' queueing new instance (mode: queued)"),
this->name_.c_str());
this->num_runs_++; this->num_runs_++;
this->var_queue_.push(std::make_tuple(x...)); this->var_queue_.push(std::make_tuple(x...));
return; return;
@@ -143,7 +156,8 @@ template<typename... Ts> class ParallelScript : public Script<Ts...> {
public: public:
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__, "Script '%s' maximum number of parallel runs exceeded!", this->name_.c_str()); this->esp_logw_(__LINE__, ESPHOME_LOG_FORMAT("Script '%s' maximum number of parallel runs exceeded!"),
this->name_.c_str());
return; return;
} }
this->trigger(x...); this->trigger(x...);