ESPHome 2026.11.0-dev
Loading...
Searching...
No Matches
text.cpp
Go to the documentation of this file.
1#include "text.h"
4#include "esphome/core/log.h"
5#include <cstring>
6
7namespace esphome::text {
8
9ESPHOME_LOG_TAG(TAG, "text");
10
11void Text::publish_state(const char *state, size_t len) {
12 this->set_has_state(true);
13 // Only assign if changed to avoid heap allocation
14 if (len != this->state.size() || memcmp(state, this->state.data(), len) != 0) {
15 this->state.assign(state, len);
16 }
17 if (this->traits.get_mode() == TEXT_MODE_PASSWORD) {
18 ESP_LOGV(TAG, "'%s' >> " LOG_SECRET("'%s'"), LOG_STR_ARG(this->get_log_name()), this->state.c_str());
19 } else {
20 ESP_LOGV(TAG, "'%s' >> '%s'", LOG_STR_ARG(this->get_log_name()), this->state.c_str());
21 }
22 this->state_callback_.call(this->state);
23#if defined(USE_TEXT) && defined(USE_CONTROLLER_REGISTRY)
24 ControllerRegistry::notify_text_update(this);
25#endif
26}
27
28} // namespace esphome::text
const LogString * get_log_name() const
Get the name for a "%s" log argument (LOG_STR_ARG).
void set_has_state(bool state)
LazyCallbackManager< void(const std::string &)> state_callback_
Definition text.h:47
void publish_state(const std::string &state)
Definition text.h:25
std::string state
Definition text.h:22
TextTraits traits
Definition text.h:23
TextMode get_mode() const
Definition text_traits.h:30
bool state
Definition fan.h:2
ESPHOME_LOG_TAG(TAG, "text")
const void size_t len
Definition hal.h:68