ESPHome  2022.6.2
Public Member Functions | Protected Member Functions | Protected Attributes
esphome::button::Button Class Referenceabstract

Base class for all buttons. More...

#include <button.h>

Inheritance diagram for esphome::button::Button:
esphome::EntityBase esphome::copy::CopyButton esphome::output::OutputButton esphome::restart::RestartButton esphome::safe_mode::SafeModeButton esphome::shutdown::ShutdownButton esphome::template_::TemplateButton esphome::wake_on_lan::WakeOnLanButton

Public Member Functions

 Button ()
 
 Button (const std::string &name)
 
void press ()
 Press this button. More...
 
void add_on_press_callback (std::function< void()> &&callback)
 Set callback for state changes. More...
 
void set_device_class (const std::string &device_class)
 Set the Home Assistant device class (see button::device_class). More...
 
std::string get_device_class ()
 Get the device class for this button. More...
 
- Public Member Functions inherited from esphome::EntityBase
 EntityBase ()
 
 EntityBase (std::string name)
 
const std::string & get_name () const
 
void set_name (const std::string &name)
 
const std::string & get_object_id ()
 
uint32_t get_object_id_hash ()
 
bool is_internal () const
 
void set_internal (bool internal)
 
bool is_disabled_by_default () const
 
void set_disabled_by_default (bool disabled_by_default)
 
EntityCategory get_entity_category () const
 
void set_entity_category (EntityCategory entity_category)
 
const std::string & get_icon () const
 
void set_icon (const std::string &name)
 

Protected Member Functions

virtual void press_action ()=0
 You should implement this virtual method if you want to create your own button. More...
 
- Protected Member Functions inherited from esphome::EntityBase
virtual uint32_t hash_base ()
 The hash_base() function has been deprecated. More...
 
void calc_object_id_ ()
 

Protected Attributes

CallbackManager< void()> press_callback_ {}
 
std::string device_class_ {}
 
- Protected Attributes inherited from esphome::EntityBase
std::string name_
 
std::string object_id_
 
std::string icon_
 
uint32_t object_id_hash_
 
bool internal_ {false}
 
bool disabled_by_default_ {false}
 
EntityCategory entity_category_ {ENTITY_CATEGORY_NONE}
 

Detailed Description

Base class for all buttons.

A button is just a momentary switch that does not have a state, only a trigger.

Definition at line 22 of file button.h.

Constructor & Destructor Documentation

◆ Button() [1/2]

esphome::button::Button::Button ( )
explicit

Definition at line 10 of file button.cpp.

◆ Button() [2/2]

esphome::button::Button::Button ( const std::string &  name)
explicit

Definition at line 9 of file button.cpp.

Member Function Documentation

◆ add_on_press_callback()

void esphome::button::Button::add_on_press_callback ( std::function< void()> &&  callback)

Set callback for state changes.

Parameters
callbackThe void() callback.

Definition at line 17 of file button.cpp.

◆ get_device_class()

std::string esphome::button::Button::get_device_class ( )

Get the device class for this button.

Definition at line 20 of file button.cpp.

◆ press()

void esphome::button::Button::press ( )

Press this button.

This is called by the front-end.

For implementing buttons, please override press_action.

Definition at line 12 of file button.cpp.

◆ press_action()

virtual void esphome::button::Button::press_action ( )
protectedpure virtual

◆ set_device_class()

void esphome::button::Button::set_device_class ( const std::string &  device_class)

Set the Home Assistant device class (see button::device_class).

Definition at line 19 of file button.cpp.

Field Documentation

◆ device_class_

std::string esphome::button::Button::device_class_ {}
protected

Definition at line 51 of file button.h.

◆ press_callback_

CallbackManager<void()> esphome::button::Button::press_callback_ {}
protected

Definition at line 50 of file button.h.


The documentation for this class was generated from the following files: