ESPHome  2024.11.0
event.cpp
Go to the documentation of this file.
1 #include "event.h"
2 
3 #include "esphome/core/log.h"
4 
5 namespace esphome {
6 namespace event {
7 
8 static const char *const TAG = "event";
9 
10 void Event::trigger(const std::string &event_type) {
11  if (types_.find(event_type) == types_.end()) {
12  ESP_LOGE(TAG, "'%s': invalid event type for trigger(): %s", this->get_name().c_str(), event_type.c_str());
13  return;
14  }
15  ESP_LOGD(TAG, "'%s' Triggered event '%s'", this->get_name().c_str(), event_type.c_str());
16  this->event_callback_.call(event_type);
17 }
18 
19 void Event::add_on_event_callback(std::function<void(const std::string &event_type)> &&callback) {
20  this->event_callback_.add(std::move(callback));
21 }
22 
23 } // namespace event
24 } // namespace esphome
void add_on_event_callback(std::function< void(const std::string &event_type)> &&callback)
Definition: event.cpp:19
void trigger(const std::string &event_type)
Definition: event.cpp:10
constexpr const char * c_str() const
Definition: string_ref.h:68
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
const StringRef & get_name() const
Definition: entity_base.cpp:10