ESPHome
2022.12.8
esphome
esphome
components
button
button.cpp
Go to the documentation of this file.
1
#include "
button.h
"
2
#include "
esphome/core/log.h
"
3
4
namespace
esphome
{
5
namespace
button {
6
7
static
const
char
*
const
TAG =
"button"
;
8
9
Button::Button
(
const
std::string &
name
) :
EntityBase
(name) {}
10
Button::Button
() :
Button
(
""
) {}
11
12
void
Button::press
() {
13
ESP_LOGD(TAG,
"'%s' Pressed."
, this->
get_name
().c_str());
14
this->
press_action
();
15
this->
press_callback_
.call();
16
}
17
void
Button::add_on_press_callback
(std::function<
void
()> &&callback) { this->
press_callback_
.add(std::move(callback)); }
18
19
void
Button::set_device_class
(
const
std::string &device_class) { this->
device_class_
= device_class; }
20
std::string
Button::get_device_class
() {
return
this->
device_class_
; }
21
22
}
// namespace button
23
}
// namespace esphome
esphome::shelly_dimmer::name
const char * name
Definition:
stm32flash.h:78
esphome::button::Button
Base class for all buttons.
Definition:
button.h:22
esphome::EntityBase::get_name
const std::string & get_name() const
Definition:
entity_base.cpp:11
button.h
esphome::button::Button::device_class_
std::string device_class_
Definition:
button.h:51
esphome::button::Button::get_device_class
std::string get_device_class()
Get the device class for this button.
Definition:
button.cpp:20
esphome::button::Button::press
void press()
Press this button.
Definition:
button.cpp:12
esphome::EntityBase
Definition:
entity_base.h:15
esphome::button::Button::Button
Button()
Definition:
button.cpp:10
esphome::button::Button::add_on_press_callback
void add_on_press_callback(std::function< void()> &&callback)
Set callback for state changes.
Definition:
button.cpp:17
esphome::button::Button::press_action
virtual void press_action()=0
You should implement this virtual method if you want to create your own button.
esphome
Definition:
a4988.cpp:4
esphome::button::Button::set_device_class
void set_device_class(const std::string &device_class)
Set the Home Assistant device class (see button::device_class).
Definition:
button.cpp:19
log.h
esphome::button::Button::press_callback_
CallbackManager< void()> press_callback_
Definition:
button.h:50
Generated by
1.8.13