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 if (!(obj)->get_icon_ref().empty()) { \
20 ESP_LOGCONFIG(TAG, "%s Icon: '%s'", prefix, (obj)->get_icon_ref().c_str()); \
22 if (!(obj)->get_device_class_ref().empty()) { \
23 ESP_LOGCONFIG(TAG, "%s Device Class: '%s'", prefix, (obj)->get_device_class_ref().c_str()); \
29 void trigger(
const std::string &event_type);
33 this->
types_ = event_types;
34 this->last_event_type_ =
nullptr;
59 if (this->last_event_type_ ==
nullptr)
60 return std::numeric_limits<uint8_t>::max();
62 const uint8_t size =
static_cast<uint8_t
>(this->
types_.
size());
63 for (uint8_t i = 0; i < size; i++) {
64 if (this->
types_[i] == this->last_event_type_)
67 return std::numeric_limits<uint8_t>::max();
71 bool has_event()
const {
return this->last_event_type_ !=
nullptr; }
82 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)
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
LazyCallbackManager< void(const std::string &event_type)> event_callback_
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(const std::string &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.