From 9c2917e8ec46756b21e0f5374e7ce2e771b27a6b Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Sat, 17 Jan 2026 14:15:29 -1000 Subject: [PATCH 1/3] [pipsolar] Store command strings in flash --- .../components/pipsolar/switch/pipsolar_switch.h | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/esphome/components/pipsolar/switch/pipsolar_switch.h b/esphome/components/pipsolar/switch/pipsolar_switch.h index 11ff6c853a..bb62d4794a 100644 --- a/esphome/components/pipsolar/switch/pipsolar_switch.h +++ b/esphome/components/pipsolar/switch/pipsolar_switch.h @@ -9,15 +9,18 @@ namespace pipsolar { class Pipsolar; class PipsolarSwitch : public switch_::Switch, public Component { public: - void set_parent(Pipsolar *parent) { this->parent_ = parent; }; - void set_on_command(const std::string &command) { this->on_command_ = command; }; - void set_off_command(const std::string &command) { this->off_command_ = command; }; + void set_parent(Pipsolar *parent) { this->parent_ = parent; } + void set_on_command(const char *command) { this->on_command_ = command; } + void set_off_command(const char *command) { this->off_command_ = command; } + /// Prevent accidental use of std::string which would dangle + void set_on_command(const std::string &command) = delete; + void set_off_command(const std::string &command) = delete; void dump_config() override; protected: void write_state(bool state) override; - std::string on_command_; - std::string off_command_; + const char *on_command_{nullptr}; + const char *off_command_{nullptr}; Pipsolar *parent_; }; From 48dc1331a43054f17cec2dbabfe9f3364538db46 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Sat, 17 Jan 2026 14:16:27 -1000 Subject: [PATCH 2/3] [pipsolar] Store command strings in flash --- esphome/components/pipsolar/output/pipsolar_output.cpp | 2 +- esphome/components/pipsolar/output/pipsolar_output.h | 8 +++++--- esphome/components/pipsolar/switch/pipsolar_switch.cpp | 4 ++-- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/esphome/components/pipsolar/output/pipsolar_output.cpp b/esphome/components/pipsolar/output/pipsolar_output.cpp index 163fbf4eb2..ebfb9a7bbc 100644 --- a/esphome/components/pipsolar/output/pipsolar_output.cpp +++ b/esphome/components/pipsolar/output/pipsolar_output.cpp @@ -9,7 +9,7 @@ static const char *const TAG = "pipsolar.output"; void PipsolarOutput::write_state(float state) { char tmp[10]; - sprintf(tmp, this->set_command_.c_str(), state); + snprintf(tmp, sizeof(tmp), this->set_command_, state); if (std::find(this->possible_values_.begin(), this->possible_values_.end(), state) != this->possible_values_.end()) { ESP_LOGD(TAG, "Will write: %s out of value %f / %02.0f", tmp, state, state); diff --git a/esphome/components/pipsolar/output/pipsolar_output.h b/esphome/components/pipsolar/output/pipsolar_output.h index b4b8000962..66eda8e391 100644 --- a/esphome/components/pipsolar/output/pipsolar_output.h +++ b/esphome/components/pipsolar/output/pipsolar_output.h @@ -15,13 +15,15 @@ class PipsolarOutput : public output::FloatOutput { public: PipsolarOutput() {} void set_parent(Pipsolar *parent) { this->parent_ = parent; } - void set_set_command(const std::string &command) { this->set_command_ = command; }; + void set_set_command(const char *command) { this->set_command_ = command; } + /// Prevent accidental use of std::string which would dangle + void set_set_command(const std::string &command) = delete; void set_possible_values(std::vector possible_values) { this->possible_values_ = std::move(possible_values); } - void set_value(float value) { this->write_state(value); }; + void set_value(float value) { this->write_state(value); } protected: void write_state(float state) override; - std::string set_command_; + const char *set_command_{nullptr}; Pipsolar *parent_; std::vector possible_values_; }; diff --git a/esphome/components/pipsolar/switch/pipsolar_switch.cpp b/esphome/components/pipsolar/switch/pipsolar_switch.cpp index 649d951618..58dee852eb 100644 --- a/esphome/components/pipsolar/switch/pipsolar_switch.cpp +++ b/esphome/components/pipsolar/switch/pipsolar_switch.cpp @@ -10,11 +10,11 @@ static const char *const TAG = "pipsolar.switch"; void PipsolarSwitch::dump_config() { LOG_SWITCH("", "Pipsolar Switch", this); } void PipsolarSwitch::write_state(bool state) { if (state) { - if (!this->on_command_.empty()) { + if (this->on_command_ != nullptr) { this->parent_->queue_command(this->on_command_); } } else { - if (!this->off_command_.empty()) { + if (this->off_command_ != nullptr) { this->parent_->queue_command(this->off_command_); } } From 533d3e518464fdcb23a20c61b594108709410e97 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Sat, 17 Jan 2026 14:17:15 -1000 Subject: [PATCH 3/3] [pipsolar] Store command strings in flash --- .../components/pipsolar/switch/pipsolar_switch.cpp | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/esphome/components/pipsolar/switch/pipsolar_switch.cpp b/esphome/components/pipsolar/switch/pipsolar_switch.cpp index 58dee852eb..512587511b 100644 --- a/esphome/components/pipsolar/switch/pipsolar_switch.cpp +++ b/esphome/components/pipsolar/switch/pipsolar_switch.cpp @@ -9,14 +9,9 @@ static const char *const TAG = "pipsolar.switch"; void PipsolarSwitch::dump_config() { LOG_SWITCH("", "Pipsolar Switch", this); } void PipsolarSwitch::write_state(bool state) { - if (state) { - if (this->on_command_ != nullptr) { - this->parent_->queue_command(this->on_command_); - } - } else { - if (this->off_command_ != nullptr) { - this->parent_->queue_command(this->off_command_); - } + const char *command = state ? this->on_command_ : this->off_command_; + if (command != nullptr) { + this->parent_->queue_command(command); } }