ESPHome  2024.5.4
button.h
Go to the documentation of this file.
1 #pragma once
2 
5 #include "esphome/core/helpers.h"
6 
7 namespace esphome {
8 namespace button {
9 
10 #define LOG_BUTTON(prefix, type, obj) \
11  if ((obj) != nullptr) { \
12  ESP_LOGCONFIG(TAG, "%s%s '%s'", prefix, LOG_STR_LITERAL(type), (obj)->get_name().c_str()); \
13  if (!(obj)->get_icon().empty()) { \
14  ESP_LOGCONFIG(TAG, "%s Icon: '%s'", prefix, (obj)->get_icon().c_str()); \
15  } \
16  }
17 
18 #define SUB_BUTTON(name) \
19  protected: \
20  button::Button *name##_button_{nullptr}; \
21 \
22  public: \
23  void set_##name##_button(button::Button *button) { this->name##_button_ = button; }
24 
29 class Button : public EntityBase, public EntityBase_DeviceClass {
30  public:
35  void press();
36 
41  void add_on_press_callback(std::function<void()> &&callback);
42 
43  protected:
46  virtual void press_action() = 0;
47 
49 };
50 
51 } // namespace button
52 } // namespace esphome
Base class for all buttons.
Definition: button.h:29
void press()
Press this button.
Definition: button.cpp:9
void add_on_press_callback(std::function< void()> &&callback)
Set callback for state changes.
Definition: button.cpp:14
virtual void press_action()=0
You should implement this virtual method if you want to create your own button.
This is a workaround until we can figure out a way to get the tflite-micro idf component code availab...
Definition: a01nyub.cpp:7
CallbackManager< void()> press_callback_
Definition: button.h:48