ESPHome 2026.1.0-dev
Loading...
Searching...
No Matches
button.h
Go to the documentation of this file.
1#pragma once
2
6
7namespace esphome::button {
8
9class Button;
10void log_button(const char *tag, const char *prefix, const char *type, Button *obj);
11
12#define LOG_BUTTON(prefix, type, obj) log_button(TAG, prefix, LOG_STR_LITERAL(type), obj)
13
14#define SUB_BUTTON(name) \
15 protected: \
16 button::Button *name##_button_{nullptr}; \
17\
18 public: \
19 void set_##name##_button(button::Button *button) { this->name##_button_ = button; }
20
26 public:
31 void press();
32
37 void add_on_press_callback(std::function<void()> &&callback);
38
39 protected:
42 virtual void press_action() = 0;
43
45};
46
47} // namespace esphome::button
Base class for all buttons.
Definition button.h:25
LazyCallbackManager< void()> press_callback_
Definition button.h:44
void add_on_press_callback(std::function< void()> &&callback)
Set callback for state changes.
Definition button.cpp:26
void press()
Press this button.
Definition button.cpp:21
virtual void press_action()=0
You should implement this virtual method if you want to create your own button.
uint16_t type
void log_button(const char *tag, const char *prefix, const char *type, Button *obj)
Definition button.cpp:9