From e5e85b010ce0b6e5a440063934dd59ec0e84f022 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Sun, 29 Mar 2026 16:08:43 -1000 Subject: [PATCH] merge --- esphome/components/select/select.h | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/esphome/components/select/select.h b/esphome/components/select/select.h index 1d1ccfccdd..465283d92a 100644 --- a/esphome/components/select/select.h +++ b/esphome/components/select/select.h @@ -80,21 +80,23 @@ class Select : public EntityBase { this->state_callback_.add(std::forward(callback)); } - /** Set the value of the select by index, this is an optional virtual method. - * - * This method is called by the SelectCall when the index is already known. - * Default implementation converts to string and calls control(). - * Override this to work directly with indices and avoid string conversions. - * - * @param index The index as validated by the SelectCall. - */ - virtual void control(size_t index) { this->control(this->option_at(index)); } - protected: friend class SelectCall; size_t active_index_{0}; + /** Set the value of the select by index, this is an optional virtual method. + * + * IMPORTANT: At least ONE of the two control() methods must be overridden by derived classes. + * Overriding this index-based version is PREFERRED as it avoids string conversions. + * + * This method is called by the SelectCall when the index is already known. + * Default implementation converts to string and calls control(const std::string&). + * + * @param index The index as validated by the SelectCall. + */ + virtual void control(size_t index) { this->control(this->option_at(index)); } + /** Set the value of the select, this is a virtual method that each select integration can implement. * * IMPORTANT: At least ONE of the two control() methods must be overridden by derived classes.