ESPHome
2026.11.0-dev
Loading...
Searching...
No Matches
esphome
components
text
text.cpp
Go to the documentation of this file.
1
#include "
text.h
"
2
#include "
esphome/core/defines.h
"
3
#include "
esphome/core/controller_registry.h
"
4
#include "
esphome/core/log.h
"
5
#include <cstring>
6
7
namespace
esphome::text
{
8
9
ESPHOME_LOG_TAG
(TAG,
"text"
);
10
11
void
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
esphome::EntityBase::get_log_name
const LogString * get_log_name() const
Get the name for a "%s" log argument (LOG_STR_ARG).
Definition
entity_base.h:100
esphome::EntityBase::set_has_state
void set_has_state(bool state)
Definition
entity_base.h:182
esphome::text::Text::state_callback_
LazyCallbackManager< void(const std::string &)> state_callback_
Definition
text.h:47
esphome::text::Text::publish_state
void publish_state(const std::string &state)
Definition
text.h:25
esphome::text::Text::state
std::string state
Definition
text.h:22
esphome::text::Text::traits
TextTraits traits
Definition
text.h:23
esphome::text::TextTraits::get_mode
TextMode get_mode() const
Definition
text_traits.h:30
controller_registry.h
defines.h
state
bool state
Definition
fan.h:2
log.h
esphome::text
Definition
text.cpp:7
esphome::text::ESPHOME_LOG_TAG
ESPHOME_LOG_TAG(TAG, "text")
esphome::text::TEXT_MODE_PASSWORD
@ TEXT_MODE_PASSWORD
Definition
text_traits.h:11
esphome::len
const void size_t len
Definition
hal.h:68
text.h
Generated by
1.12.0