ESPHome 2026.5.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
25class Button : public EntityBase {
26 public:
31 void press();
32
37 template<typename F> void add_on_press_callback(F &&callback) {
38 this->press_callback_.add(std::forward<F>(callback));
39 }
40
41 protected:
44 virtual void press_action() = 0;
45
47};
48
49} // namespace esphome::button
Base class for all buttons.
Definition button.h:25
LazyCallbackManager< void()> press_callback_
Definition button.h:46
void press()
Press this button.
Definition button.cpp:18
void add_on_press_callback(F &&callback)
Set callback for state changes.
Definition button.h:37
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
const char * tag
Definition log.h:74