ESPHome 2026.11.0-dev
Loading...
Searching...
No Matches
button.cpp
Go to the documentation of this file.
1#include "button.h"
2#include "esphome/core/log.h"
3
4namespace esphome::button {
5
6ESPHOME_LOG_TAG(TAG, "button");
7
8// Function implementation of LOG_BUTTON macro to reduce code size
9void log_button(const char *tag, const char *prefix, const char *type, Button *obj) {
10 if (!log_entity_header(tag, prefix, type, obj)) {
11 return;
12 }
13 LOG_ENTITY_ICON(tag, prefix, *obj);
14}
15
17 ESP_LOGV(TAG, "'%s' Pressed.", LOG_STR_ARG(this->get_log_name()));
18 this->press_action();
19 this->press_callback_.call();
20}
21
22} // namespace esphome::button
const LogString * get_log_name() const
Get the name for a "%s" log argument (LOG_STR_ARG).
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:16
virtual void press_action()=0
You should implement this virtual method if you want to create your own button.
uint8_t type
ESPHOME_LOG_TAG(TAG, "button")
void log_button(const char *tag, const char *prefix, const char *type, Button *obj)
Definition button.cpp:9
bool log_entity_header(const char *tag, const char *prefix, const char *type, const EntityBase *obj)
Log "<prefix><type> '<name>'" for a dump_config header; returns false when obj is null.