mirror of
https://github.com/esphome/esphome.git
synced 2025-01-18 12:05:41 +00:00
[event] Store `last_event_type
` in class (#8088)
This commit is contained in:
parent
c458fd18df
commit
e779a8bcb2
@ -8,11 +8,13 @@ namespace event {
|
|||||||
static const char *const TAG = "event";
|
static const char *const TAG = "event";
|
||||||
|
|
||||||
void Event::trigger(const std::string &event_type) {
|
void Event::trigger(const std::string &event_type) {
|
||||||
if (types_.find(event_type) == types_.end()) {
|
auto found = types_.find(event_type);
|
||||||
|
if (found == types_.end()) {
|
||||||
ESP_LOGE(TAG, "'%s': invalid event type for trigger(): %s", this->get_name().c_str(), event_type.c_str());
|
ESP_LOGE(TAG, "'%s': invalid event type for trigger(): %s", this->get_name().c_str(), event_type.c_str());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
ESP_LOGD(TAG, "'%s' Triggered event '%s'", this->get_name().c_str(), event_type.c_str());
|
last_event_type = &(*found);
|
||||||
|
ESP_LOGD(TAG, "'%s' Triggered event '%s'", this->get_name().c_str(), last_event_type->c_str());
|
||||||
this->event_callback_.call(event_type);
|
this->event_callback_.call(event_type);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -23,6 +23,8 @@ namespace event {
|
|||||||
|
|
||||||
class Event : public EntityBase, public EntityBase_DeviceClass {
|
class Event : public EntityBase, public EntityBase_DeviceClass {
|
||||||
public:
|
public:
|
||||||
|
const std::string *last_event_type;
|
||||||
|
|
||||||
void trigger(const std::string &event_type);
|
void trigger(const std::string &event_type);
|
||||||
void set_event_types(const std::set<std::string> &event_types) { this->types_ = event_types; }
|
void set_event_types(const std::set<std::string> &event_types) { this->types_ = event_types; }
|
||||||
std::set<std::string> get_event_types() const { return this->types_; }
|
std::set<std::string> get_event_types() const { return this->types_; }
|
||||||
|
Loading…
x
Reference in New Issue
Block a user