ESPHome  2024.11.0
text.cpp
Go to the documentation of this file.
1 #include "text.h"
2 #include "esphome/core/log.h"
3 
4 namespace esphome {
5 namespace text {
6 
7 static const char *const TAG = "text";
8 
9 void Text::publish_state(const std::string &state) {
10  this->has_state_ = true;
11  this->state = state;
12  if (this->traits.get_mode() == TEXT_MODE_PASSWORD) {
13  ESP_LOGD(TAG, "'%s': Sending state " LOG_SECRET("'%s'"), this->get_name().c_str(), state.c_str());
14 
15  } else {
16  ESP_LOGD(TAG, "'%s': Sending state %s", this->get_name().c_str(), state.c_str());
17  }
18  this->state_callback_.call(state);
19 }
20 
21 void Text::add_on_state_callback(std::function<void(std::string)> &&callback) {
22  this->state_callback_.add(std::move(callback));
23 }
24 
25 } // namespace text
26 } // namespace esphome
bool has_state_
Definition: text.h:51
TextMode get_mode() const
Definition: text_traits.h:29
std::string state
Definition: text.h:26
TextTraits traits
Definition: text.h:27
CallbackManager< void(std::string)> state_callback_
Definition: text.h:50
const char *const TAG
Definition: spi.cpp:8
void add_on_state_callback(std::function< void(std::string)> &&callback)
Definition: text.cpp:21
void publish_state(const std::string &state)
Definition: text.cpp:9
constexpr const char * c_str() const
Definition: string_ref.h:68
Implementation of SPI Controller mode.
Definition: a01nyub.cpp:7
const StringRef & get_name() const
Definition: entity_base.cpp:10
bool state
Definition: fan.h:34