ESPHome 2025.5.0
Loading...
Searching...
No Matches
event.h
Go to the documentation of this file.
1#pragma once
2
3#include <set>
4#include <string>
5
9
10namespace esphome {
11namespace 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
24class Event : public EntityBase, public EntityBase_DeviceClass {
25 public:
26 const std::string *last_event_type;
27
28 void trigger(const std::string &event_type);
29 void set_event_types(const std::set<std::string> &event_types) { this->types_ = event_types; }
30 std::set<std::string> get_event_types() const { return this->types_; }
31 void add_on_event_callback(std::function<void(const std::string &event_type)> &&callback);
32
33 protected:
34 CallbackManager<void(const std::string &event_type)> event_callback_;
35 std::set<std::string> types_;
36};
37
38} // namespace event
39} // namespace esphome
void set_event_types(const std::set< std::string > &event_types)
Definition event.h:29
std::set< std::string > get_event_types() const
Definition event.h:30
const std::string * last_event_type
Definition event.h:26
std::set< std::string > types_
Definition event.h:35
void trigger(const std::string &event_type)
Definition event.cpp:10
void add_on_event_callback(std::function< void(const std::string &event_type)> &&callback)
Definition event.cpp:21
CallbackManager< void(const std::string &event_type)> event_callback_
Definition event.h:34
Providing packet encoding functions for exchanging data with a remote host.
Definition a01nyub.cpp:7