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