mirror of
https://github.com/esphome/esphome.git
synced 2026-08-22 22:26:21 +00:00
[text_sensor] Inline the trivial TextSensor forwarding overloads
This commit is contained in:
@@ -18,10 +18,6 @@ void log_text_sensor(const char *tag, const char *prefix, const char *type, Text
|
||||
LOG_ENTITY_ICON(tag, prefix, *obj);
|
||||
}
|
||||
|
||||
void TextSensor::publish_state(const std::string &state) { this->publish_state(state.data(), state.size()); }
|
||||
|
||||
void TextSensor::publish_state(const char *state) { this->publish_state(state, strlen(state)); }
|
||||
|
||||
void TextSensor::publish_state(const char *state, size_t len) {
|
||||
#ifdef USE_TEXT_SENSOR_FILTER
|
||||
if (this->filter_list_ == nullptr) {
|
||||
@@ -91,10 +87,6 @@ const std::string &TextSensor::get_raw_state() const {
|
||||
#endif
|
||||
return this->state; // No filters, raw == filtered
|
||||
}
|
||||
void TextSensor::internal_send_state_to_frontend(const std::string &state) {
|
||||
this->internal_send_state_to_frontend(state.data(), state.size());
|
||||
}
|
||||
|
||||
void TextSensor::internal_send_state_to_frontend(const char *state, size_t len) {
|
||||
// Only assign if changed to avoid heap allocation
|
||||
if (len != this->state.size() || memcmp(state, this->state.data(), len) != 0) {
|
||||
|
||||
@@ -37,8 +37,8 @@ class TextSensor : public EntityBase {
|
||||
/// Returns the raw (pre-filter) state.
|
||||
const std::string &get_raw_state() const;
|
||||
|
||||
void publish_state(const std::string &state);
|
||||
void publish_state(const char *state);
|
||||
void publish_state(const std::string &state) { this->publish_state(state.data(), state.size()); }
|
||||
void publish_state(const char *state) { this->publish_state(state, strlen(state)); }
|
||||
void publish_state(const char *state, size_t len);
|
||||
|
||||
#ifdef USE_TEXT_SENSOR_FILTER
|
||||
@@ -70,7 +70,9 @@ class TextSensor : public EntityBase {
|
||||
// ========== INTERNAL METHODS ==========
|
||||
// (In most use cases you won't need these)
|
||||
|
||||
void internal_send_state_to_frontend(const std::string &state);
|
||||
void internal_send_state_to_frontend(const std::string &state) {
|
||||
this->internal_send_state_to_frontend(state.data(), state.size());
|
||||
}
|
||||
void internal_send_state_to_frontend(const char *state, size_t len);
|
||||
|
||||
protected:
|
||||
|
||||
Reference in New Issue
Block a user