ESPHome  2024.9.2
event.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <set>
4 #include <string>
5 
8 #include "esphome/core/helpers.h"
9 
10 namespace esphome {
11 namespace event {
12 
13 #define LOG_EVENT(prefix, type, obj) \
14  if ((obj) != nullptr) { \
15  ESP_LOGCONFIG(TAG, "%s%s '%s'", prefix, LOG_STR_LITERAL(type), (obj)->get_name().c_str()); \
16  if (!(obj)->get_icon().empty()) { \
17  ESP_LOGCONFIG(TAG, "%s Icon: '%s'", prefix, (obj)->get_icon().c_str()); \
18  } \
19  if (!(obj)->get_device_class().empty()) { \
20  ESP_LOGCONFIG(TAG, "%s Device Class: '%s'", prefix, (obj)->get_device_class().c_str()); \
21  } \
22  }
23 
24 class Event : public EntityBase, public EntityBase_DeviceClass {
25  public:
26  void trigger(const std::string &event_type);
27  void set_event_types(const std::set<std::string> &event_types) { this->types_ = event_types; }
28  std::set<std::string> get_event_types() const { return this->types_; }
29  void add_on_event_callback(std::function<void(const std::string &event_type)> &&callback);
30 
31  protected:
33  std::set<std::string> types_;
34 };
35 
36 } // namespace event
37 } // namespace esphome
std::set< std::string > get_event_types() const
Definition: event.h:28
void add_on_event_callback(std::function< void(const std::string &event_type)> &&callback)
Definition: event.cpp:19
void set_event_types(const std::set< std::string > &event_types)
Definition: event.h:27
void trigger(const std::string &event_type)
Definition: event.cpp:10
Implementation of SPI Controller mode.
Definition: a01nyub.cpp:7
std::set< std::string > types_
Definition: event.h:33
CallbackManager< void(const std::string &event_type)> event_callback_
Definition: event.h:32