1
0
mirror of https://github.com/esphome/esphome.git synced 2025-11-17 07:15:48 +00:00

address review comments

This commit is contained in:
J. Nick Koston
2025-11-02 23:36:42 -06:00
parent 1150f8e6ba
commit 8e3d53cb03

View File

@@ -83,10 +83,12 @@ class Select : public EntityBase {
size_t active_index_{0}; size_t active_index_{0};
/** Set the value of the select by index, this is an optional virtual method. /** 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. * This method is called by the SelectCall when the index is already known.
* Default implementation converts to string and calls control(). * Default implementation converts to string and calls control(const std::string&).
* Override this to work directly with indices and avoid string conversions.
* *
* @param index The index as validated by the SelectCall. * @param index The index as validated by the SelectCall.
*/ */
@@ -94,18 +96,13 @@ class Select : public EntityBase {
/** Set the value of the select, this is a virtual method that each select integration can implement. /** Set the value of the select, this is a virtual method that each select integration can implement.
* *
* This method is called by control(size_t) when not overridden, or directly by external code. * IMPORTANT: At least ONE of the two control() methods must be overridden by derived classes.
* Integrations can either: * Overriding control(size_t) is PREFERRED as it avoids string conversions.
* 1. Override this method to handle string-based control (traditional approach)
* 2. Override control(size_t) instead to work with indices directly (recommended)
* *
* This method is called by control(size_t) when not overridden, or directly by external code.
* Default implementation converts to index and calls control(size_t). * Default implementation converts to index and calls control(size_t).
* *
* Delegation chain: * @param value The value as validated by the caller.
* - SelectCall::perform() → control(size_t) → [if not overridden] → control(string)
* - External code → control(string) → publish_state(string) → publish_state(size_t)
*
* @param value The value as validated by the SelectCall.
*/ */
virtual void control(const std::string &value) { virtual void control(const std::string &value) {
auto index = this->index_of(value); auto index = this->index_of(value);