ESPHome 2026.5.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 ((obj) != nullptr) { \
13 ESP_LOGCONFIG(TAG, "%s%s '%s'", prefix, LOG_STR_LITERAL(type), (obj)->get_name().c_str()); \
14 LOG_ENTITY_ICON(TAG, prefix, *(obj)); \
15 }
16
21class Text : public EntityBase {
22 public:
23 std::string state;
25
26 void publish_state(const std::string &state);
27 void publish_state(const char *state);
28 void publish_state(const char *state, size_t len);
29
31 TextCall make_call() { return TextCall(this); }
32
33 template<typename F> void add_on_state_callback(F &&callback) {
34 this->state_callback_.add(std::forward<F>(callback));
35 }
36
37 protected:
38 friend class TextCall;
39
46 virtual void control(const std::string &value) = 0;
47
48 LazyCallbackManager<void(const std::string &)> state_callback_;
49};
50
51} // namespace esphome::text
Base-class for all text inputs.
Definition text.h:21
void add_on_state_callback(F &&callback)
Definition text.h:33
LazyCallbackManager< void(const std::string &)> state_callback_
Definition text.h:48
void publish_state(const std::string &state)
Definition text.cpp:11
TextCall make_call()
Instantiate a TextCall object to modify this text component's state.
Definition text.h:31
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:23
TextTraits traits
Definition text.h:24
friend class TextCall
Definition text.h:38
std::string size_t len
Definition helpers.h:1045