ESPHome 2026.11.0-dev
Loading...
Searching...
No Matches
text.h
Go to the documentation of this file.
1#pragma once
2
6#include "text_call.h"
7#include "text_traits.h"
8
9namespace esphome::text {
10
11#define LOG_TEXT(prefix, type, obj) \
12 if (log_entity_header(TAG, prefix, LOG_STR_LITERAL(type), (obj))) { \
13 LOG_ENTITY_ICON(TAG, prefix, *(obj)); \
14 }
15
20class Text : public EntityBase {
21 public:
22 std::string state;
24
25 void publish_state(const std::string &state) { this->publish_state(state.data(), state.size()); }
26 void publish_state(const char *state) { this->publish_state(state, strlen(state)); }
27 void publish_state(const char *state, size_t len);
28
30 TextCall make_call() { return TextCall(this); }
31
32 template<typename F> void add_on_state_callback(F &&callback) {
33 this->state_callback_.add(std::forward<F>(callback));
34 }
35
36 protected:
37 friend class TextCall;
38
45 virtual void control(const std::string &value) = 0;
46
47 LazyCallbackManager<void(const std::string &)> state_callback_;
48};
49
50} // namespace esphome::text
Base-class for all text inputs.
Definition text.h:20
void add_on_state_callback(F &&callback)
Definition text.h:32
void publish_state(const char *state)
Definition text.h:26
LazyCallbackManager< void(const std::string &)> state_callback_
Definition text.h:47
void publish_state(const std::string &state)
Definition text.h:25
TextCall make_call()
Instantiate a TextCall object to modify this text component's state.
Definition text.h:30
virtual void control(const std::string &value)=0
Set the value of the text input, this is a virtual method that each text input integration must imple...
std::string state
Definition text.h:22
TextTraits traits
Definition text.h:23
friend class TextCall
Definition text.h:37
const void size_t len
Definition hal.h:68