ESPHome  2024.10.2
text.h
Go to the documentation of this file.
1 #pragma once
2 
5 #include "esphome/core/helpers.h"
6 #include "text_call.h"
7 #include "text_traits.h"
8 
9 namespace esphome {
10 namespace 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 
24 class 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 
51  bool has_state_{false};
52 };
53 
54 } // namespace text
55 } // namespace esphome
bool has_state_
Definition: text.h:51
std::string state
Definition: text.h:26
friend class TextCall
Definition: text.h:40
TextTraits traits
Definition: text.h:27
Base-class for all text inputs.
Definition: text.h:24
CallbackManager< void(std::string)> state_callback_
Definition: text.h:50
TextCall make_call()
Instantiate a TextCall object to modify this text component&#39;s state.
Definition: text.h:35
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
void publish_state(const std::string &state)
Definition: text.cpp:9
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...
Implementation of SPI Controller mode.
Definition: a01nyub.cpp:7