[text_sensor] Return state by const reference to avoid copies (#12661)
This commit is contained in:
@@ -78,8 +78,8 @@ void TextSensor::add_on_raw_state_callback(std::function<void(const std::string
|
||||
this->raw_callback_.add(std::move(callback));
|
||||
}
|
||||
|
||||
std::string TextSensor::get_state() const { return this->state; }
|
||||
std::string TextSensor::get_raw_state() const {
|
||||
const std::string &TextSensor::get_state() const { return this->state; }
|
||||
const std::string &TextSensor::get_raw_state() const {
|
||||
// Suppress deprecation warning - get_raw_state() is the replacement API
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
|
||||
|
||||
@@ -37,9 +37,9 @@ class TextSensor : public EntityBase, public EntityBase_DeviceClass {
|
||||
#pragma GCC diagnostic pop
|
||||
|
||||
/// Getter-syntax for .state.
|
||||
std::string get_state() const;
|
||||
const std::string &get_state() const;
|
||||
/// Getter-syntax for .raw_state
|
||||
std::string get_raw_state() const;
|
||||
const std::string &get_raw_state() const;
|
||||
|
||||
void publish_state(const std::string &state);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user