diff --git a/esphome/components/api/api.proto b/esphome/components/api/api.proto index e115e4630d..f6eb8ec1c9 100644 --- a/esphome/components/api/api.proto +++ b/esphome/components/api/api.proto @@ -2147,7 +2147,7 @@ message ListEntitiesEventResponse { EntityCategory entity_category = 7; string device_class = 8; - repeated string event_types = 9 [(container_pointer_no_template) = "FixedVector"]; + repeated string event_types = 9 [(container_pointer_no_template) = "std::vector"]; uint32 device_id = 10 [(field_ifdef) = "USE_DEVICES"]; } message EventResponse { diff --git a/esphome/components/api/api_pb2.h b/esphome/components/api/api_pb2.h index 358049026e..df793eb262 100644 --- a/esphome/components/api/api_pb2.h +++ b/esphome/components/api/api_pb2.h @@ -2788,7 +2788,7 @@ class ListEntitiesEventResponse final : public InfoResponseProtoMessage { #endif StringRef device_class_ref_{}; void set_device_class(const StringRef &ref) { this->device_class_ref_ = ref; } - const FixedVector *event_types{}; + const std::vector *event_types{}; void encode(ProtoWriteBuffer buffer) const override; void calculate_size(ProtoSize &size) const override; #ifdef HAS_PROTO_MESSAGE_DUMP diff --git a/esphome/components/event/event.h b/esphome/components/event/event.h index 822785dece..3107a11477 100644 --- a/esphome/components/event/event.h +++ b/esphome/components/event/event.h @@ -2,6 +2,7 @@ #include #include +#include #include "esphome/core/component.h" #include "esphome/core/entity_base.h" @@ -30,13 +31,23 @@ class Event : public EntityBase, public EntityBase_DeviceClass { this->types_ = event_types; this->last_event_type_ = nullptr; // Reset when types change } + /// Set the event types supported by this event (from vector). + void set_event_types(const std::vector &event_types) { + this->types_ = event_types; + this->last_event_type_ = nullptr; // Reset when types change + } + /// Set the event types supported by this event (from C array). + template void set_event_types(const char *const (&event_types)[N]) { + this->types_.assign(event_types, event_types + N); + this->last_event_type_ = nullptr; // Reset when types change + } // Deleted overloads to catch incorrect std::string usage at compile time with clear error messages void set_event_types(std::initializer_list event_types) = delete; - void set_event_types(const FixedVector &event_types) = delete; + void set_event_types(const std::vector &event_types) = delete; /// Return the event types supported by this event. - const FixedVector &get_event_types() const { return this->types_; } + const std::vector &get_event_types() const { return this->types_; } /// Return the last triggered event type (pointer to string in types_), or nullptr if no event triggered yet. const char *get_last_event_type() const { return this->last_event_type_; } @@ -45,7 +56,7 @@ class Event : public EntityBase, public EntityBase_DeviceClass { protected: CallbackManager event_callback_; - FixedVector types_; + std::vector types_; private: /// Last triggered event type - must point to entry in types_ to ensure valid lifetime.