diff --git a/esphome/components/api/api_connection.cpp b/esphome/components/api/api_connection.cpp index 32b0f0d953..2a570b53e8 100644 --- a/esphome/components/api/api_connection.cpp +++ b/esphome/components/api/api_connection.cpp @@ -478,10 +478,7 @@ uint16_t APIConnection::try_send_light_info(EntityBase *entity, APIConnection *c ListEntitiesLightResponse msg; auto traits = light->get_traits(); const auto &color_modes_mask = traits.get_supported_color_modes(); - msg.supported_color_modes.init(color_modes_mask.size()); - for (auto mode : color_modes_mask) { - msg.supported_color_modes.push_back(static_cast(mode)); - } + msg.supported_color_modes = color_modes_mask.get_mask(); if (traits.supports_color_capability(light::ColorCapability::COLOR_TEMPERATURE) || traits.supports_color_capability(light::ColorCapability::COLD_WARM_WHITE)) { msg.min_mireds = traits.get_min_mireds(); diff --git a/esphome/components/light/color_mode.h b/esphome/components/light/color_mode.h index d58ab73fdf..fa3a0aaaac 100644 --- a/esphome/components/light/color_mode.h +++ b/esphome/components/light/color_mode.h @@ -169,6 +169,9 @@ class ColorModeMask { constexpr Iterator begin() const { return Iterator(mask_, 0); } constexpr Iterator end() const { return Iterator(mask_, 16); } + /// Get the raw bitmask value for API encoding + constexpr uint16_t get_mask() const { return this->mask_; } + private: uint16_t mask_{0};