16#define LOG_EVENT(prefix, type, obj) \
17 if ((obj) != nullptr) { \
18 ESP_LOGCONFIG(TAG, "%s%s '%s'", prefix, LOG_STR_LITERAL(type), (obj)->get_name().c_str()); \
19 LOG_ENTITY_ICON(TAG, prefix, *(obj)); \
20 LOG_ENTITY_DEVICE_CLASS(TAG, prefix, *(obj)); \
25 void trigger(
const std::string &event_type);
29 this->
types_ = event_types;
30 this->last_event_type_ =
nullptr;
55 if (this->last_event_type_ ==
nullptr)
56 return std::numeric_limits<uint8_t>::max();
59 for (uint8_t i = 0; i <
size; i++) {
60 if (this->
types_[i] == this->last_event_type_)
63 return std::numeric_limits<uint8_t>::max();
67 bool has_event()
const {
return this->last_event_type_ !=
nullptr; }
78 const char *last_event_type_{
nullptr};
Fixed-capacity vector - allocates once at runtime, never reallocates This avoids std::vector template...
StringRef is a reference to a string owned by something else.
static StringRef from_maybe_nullptr(const char *s)
LazyCallbackManager< void(StringRef event_type)> event_callback_
void set_event_types(std::initializer_list< const char * > event_types)
Set the event types supported by this event (from initializer list).
bool has_event() const
Check if an event has been triggered.
void set_event_types(std::initializer_list< std::string > event_types)=delete
const FixedVector< const char * > & get_event_types() const
Return the event types supported by this event.
void set_event_types(const FixedVector< std::string > &event_types)=delete
uint8_t get_last_event_type_index() const
Return index of last triggered event type, or max uint8_t if no event triggered yet.
void trigger(const std::string &event_type)
StringRef get_last_event_type() const
Return the last triggered event type, or empty StringRef if no event triggered yet.
void add_on_event_callback(std::function< void(StringRef event_type)> &&callback)
const char * get_event_type(uint8_t index) const
Return event type by index, or nullptr if index is out of bounds.
FixedVector< const char * > types_
void set_event_types(const std::vector< std::string > &event_types)=delete
Providing packet encoding functions for exchanging data with a remote host.