diff --git a/esphome/components/pipsolar/output/pipsolar_output.cpp b/esphome/components/pipsolar/output/pipsolar_output.cpp index ebfb9a7bbc..408af84430 100644 --- a/esphome/components/pipsolar/output/pipsolar_output.cpp +++ b/esphome/components/pipsolar/output/pipsolar_output.cpp @@ -13,7 +13,7 @@ void PipsolarOutput::write_state(float 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); - this->parent_->queue_command(std::string(tmp)); + this->parent_->queue_command(tmp); } else { ESP_LOGD(TAG, "Will not write: %s as it is not in list of allowed values", tmp); } diff --git a/esphome/components/pipsolar/pipsolar.cpp b/esphome/components/pipsolar/pipsolar.cpp index bafd5273da..681cc9d257 100644 --- a/esphome/components/pipsolar/pipsolar.cpp +++ b/esphome/components/pipsolar/pipsolar.cpp @@ -45,20 +45,20 @@ void Pipsolar::loop() { } else { ESP_LOGD(TAG, "command not successful"); } - this->command_queue_[this->command_queue_position_] = std::string(""); + this->command_queue_[this->command_queue_position_].clear(); this->command_queue_position_ = (command_queue_position_ + 1) % COMMAND_QUEUE_LENGTH; this->state_ = STATE_IDLE; } else { // crc failed // no log message necessary, check_incoming_crc_() logs - this->command_queue_[this->command_queue_position_] = std::string(""); + this->command_queue_[this->command_queue_position_].clear(); this->command_queue_position_ = (command_queue_position_ + 1) % COMMAND_QUEUE_LENGTH; this->state_ = STATE_IDLE; } } else { ESP_LOGD(TAG, "command %s response length not OK: with length %zu", this->command_queue_[this->command_queue_position_].c_str(), this->read_pos_); - this->command_queue_[this->command_queue_position_] = std::string(""); + this->command_queue_[this->command_queue_position_].clear(); this->command_queue_position_ = (command_queue_position_ + 1) % COMMAND_QUEUE_LENGTH; this->state_ = STATE_IDLE; } @@ -127,7 +127,7 @@ void Pipsolar::loop() { const char *command = this->command_queue_[this->command_queue_position_].c_str(); this->command_start_millis_ = millis(); ESP_LOGD(TAG, "command %s timeout", command); - this->command_queue_[this->command_queue_position_] = std::string(""); + this->command_queue_[this->command_queue_position_].clear(); this->command_queue_position_ = (command_queue_position_ + 1) % COMMAND_QUEUE_LENGTH; this->state_ = STATE_IDLE; return; @@ -722,7 +722,7 @@ void Pipsolar::publish_binary_sensor_(esphome::optional b, binary_sensor:: } } -esphome::optional Pipsolar::get_bit_(std::string bits, uint8_t bit_pos) { +esphome::optional Pipsolar::get_bit_(const std::string &bits, uint8_t bit_pos) { if (bit_pos >= bits.length()) { return {}; } diff --git a/esphome/components/pipsolar/pipsolar.h b/esphome/components/pipsolar/pipsolar.h index beae67a4e0..3487e04ba3 100644 --- a/esphome/components/pipsolar/pipsolar.h +++ b/esphome/components/pipsolar/pipsolar.h @@ -224,7 +224,7 @@ class Pipsolar : public uart::UARTDevice, public PollingComponent { void publish_binary_sensor_(esphome::optional b, binary_sensor::BinarySensor *sensor); - esphome::optional get_bit_(std::string bits, uint8_t bit_pos); + esphome::optional get_bit_(const std::string &bits, uint8_t bit_pos); std::string command_queue_[COMMAND_QUEUE_LENGTH]; uint8_t command_queue_position_ = 0; diff --git a/esphome/components/teleinfo/sensor/teleinfo_sensor.cpp b/esphome/components/teleinfo/sensor/teleinfo_sensor.cpp index ad9c6dae00..0d32d7f1d8 100644 --- a/esphome/components/teleinfo/sensor/teleinfo_sensor.cpp +++ b/esphome/components/teleinfo/sensor/teleinfo_sensor.cpp @@ -4,8 +4,7 @@ namespace esphome { namespace teleinfo { static const char *const TAG = "teleinfo_sensor"; -TeleInfoSensor::TeleInfoSensor(const char *tag) { this->tag = std::string(tag); } -void TeleInfoSensor::publish_val(const std::string &val) { +void TeleInfoSensor::publish_val(const char *val) { auto newval = parse_number(val).value_or(0.0f); publish_state(newval); } diff --git a/esphome/components/teleinfo/sensor/teleinfo_sensor.h b/esphome/components/teleinfo/sensor/teleinfo_sensor.h index 56781166ab..ccc12cae5f 100644 --- a/esphome/components/teleinfo/sensor/teleinfo_sensor.h +++ b/esphome/components/teleinfo/sensor/teleinfo_sensor.h @@ -7,8 +7,8 @@ namespace teleinfo { class TeleInfoSensor : public TeleInfoListener, public sensor::Sensor, public Component { public: - TeleInfoSensor(const char *tag); - void publish_val(const std::string &val) override; + TeleInfoSensor(const char *tag) { this->tag = tag; } + void publish_val(const char *val) override; void dump_config() override; }; diff --git a/esphome/components/teleinfo/teleinfo.cpp b/esphome/components/teleinfo/teleinfo.cpp index 4d617ae4e6..9750810530 100644 --- a/esphome/components/teleinfo/teleinfo.cpp +++ b/esphome/components/teleinfo/teleinfo.cpp @@ -172,15 +172,15 @@ void TeleInfo::loop() { /* Advance buf_finger to end of group */ buf_finger += field_len + 1 + 1 + 1; - publish_value_(std::string(tag_), std::string(val_)); + publish_value_(tag_, val_); } state_ = OFF; break; } } -void TeleInfo::publish_value_(const std::string &tag, const std::string &val) { +void TeleInfo::publish_value_(const char *tag, const char *val) { for (auto *element : teleinfo_listeners_) { - if (tag != element->tag) + if (strcmp(tag, element->tag) != 0) continue; element->publish_val(val); } diff --git a/esphome/components/teleinfo/teleinfo.h b/esphome/components/teleinfo/teleinfo.h index 0c6217853e..ca3c4db975 100644 --- a/esphome/components/teleinfo/teleinfo.h +++ b/esphome/components/teleinfo/teleinfo.h @@ -18,8 +18,8 @@ static const uint16_t MAX_TIMESTAMP_SIZE = 14; class TeleInfoListener { public: - std::string tag; - virtual void publish_val(const std::string &val){}; + const char *tag{nullptr}; + virtual void publish_val(const char *val){}; }; class TeleInfo : public PollingComponent, public uart::UARTDevice { public: @@ -48,7 +48,7 @@ class TeleInfo : public PollingComponent, public uart::UARTDevice { } state_{OFF}; bool read_chars_until_(bool drop, uint8_t c); bool check_crc_(const char *grp, const char *grp_end); - void publish_value_(const std::string &tag, const std::string &val); + void publish_value_(const char *tag, const char *val); }; } // namespace teleinfo } // namespace esphome diff --git a/esphome/components/teleinfo/text_sensor/teleinfo_text_sensor.cpp b/esphome/components/teleinfo/text_sensor/teleinfo_text_sensor.cpp index 87cf0dea17..7f1c90add2 100644 --- a/esphome/components/teleinfo/text_sensor/teleinfo_text_sensor.cpp +++ b/esphome/components/teleinfo/text_sensor/teleinfo_text_sensor.cpp @@ -4,8 +4,7 @@ namespace esphome { namespace teleinfo { static const char *const TAG = "teleinfo_text_sensor"; -TeleInfoTextSensor::TeleInfoTextSensor(const char *tag) { this->tag = std::string(tag); } -void TeleInfoTextSensor::publish_val(const std::string &val) { publish_state(val); } +void TeleInfoTextSensor::publish_val(const char *val) { publish_state(val); } void TeleInfoTextSensor::dump_config() { LOG_TEXT_SENSOR(" ", "Teleinfo Text Sensor", this); } } // namespace teleinfo } // namespace esphome diff --git a/esphome/components/teleinfo/text_sensor/teleinfo_text_sensor.h b/esphome/components/teleinfo/text_sensor/teleinfo_text_sensor.h index 5a7dc9d1a7..54a720866f 100644 --- a/esphome/components/teleinfo/text_sensor/teleinfo_text_sensor.h +++ b/esphome/components/teleinfo/text_sensor/teleinfo_text_sensor.h @@ -5,8 +5,8 @@ namespace esphome { namespace teleinfo { class TeleInfoTextSensor : public TeleInfoListener, public text_sensor::TextSensor, public Component { public: - TeleInfoTextSensor(const char *tag); - void publish_val(const std::string &val) override; + TeleInfoTextSensor(const char *tag) { this->tag = tag; } + void publish_val(const char *val) override; void dump_config() override; }; } // namespace teleinfo