ESPHome 2025.5.0
Loading...
Searching...
No Matches
button.h
Go to the documentation of this file.
1#pragma once
2
6
7namespace esphome {
8namespace 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
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 add_on_press_callback(std::function< void()> &&callback)
Set callback for state changes.
Definition button.cpp:14
CallbackManager< void()> press_callback_
Definition button.h:48
void press()
Press this button.
Definition button.cpp:9
virtual void press_action()=0
You should implement this virtual method if you want to create your own button.
Providing packet encoding functions for exchanging data with a remote host.
Definition a01nyub.cpp:7