ESPHome 2025.5.0
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 {
10namespace text {
11
12#define LOG_TEXT(prefix, type, obj) \
13 if ((obj) != nullptr) { \
14 ESP_LOGCONFIG(TAG, "%s%s '%s'", prefix, LOG_STR_LITERAL(type), (obj)->get_name().c_str()); \
15 if (!(obj)->get_icon().empty()) { \
16 ESP_LOGCONFIG(TAG, "%s Icon: '%s'", prefix, (obj)->get_icon().c_str()); \
17 } \
18 }
19
24class Text : public EntityBase {
25 public:
26 std::string state;
28
29 void publish_state(const std::string &state);
30
32 bool has_state() const { return has_state_; }
33
35 TextCall make_call() { return TextCall(this); }
36
37 void add_on_state_callback(std::function<void(std::string)> &&callback);
38
39 protected:
40 friend class TextCall;
41
48 virtual void control(const std::string &value) = 0;
49
50 CallbackManager<void(std::string)> state_callback_;
51 bool has_state_{false};
52};
53
54} // namespace text
55} // namespace esphome
Base-class for all text inputs.
Definition text.h:24
void publish_state(const std::string &state)
Definition text.cpp:9
TextCall make_call()
Instantiate a TextCall object to modify this text component's state.
Definition text.h:35
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...
void add_on_state_callback(std::function< void(std::string)> &&callback)
Definition text.cpp:21
bool has_state() const
Return whether this text input has gotten a full state yet.
Definition text.h:32
std::string state
Definition text.h:26
TextTraits traits
Definition text.h:27
CallbackManager< void(std::string)> state_callback_
Definition text.h:50
friend class TextCall
Definition text.h:40
Providing packet encoding functions for exchanging data with a remote host.
Definition a01nyub.cpp:7