1
0
mirror of https://github.com/esphome/esphome.git synced 2025-11-03 08:31:47 +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};
/** 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().
* Override this to work directly with indices and avoid string conversions.
* Default implementation converts to string and calls control(const std::string&).
*
* @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.
*
* This method is called by control(size_t) when not overridden, or directly by external code.
* Integrations can either:
* 1. Override this method to handle string-based control (traditional approach)
* 2. Override control(size_t) instead to work with indices directly (recommended)
* IMPORTANT: At least ONE of the two control() methods must be overridden by derived classes.
* Overriding control(size_t) is PREFERRED as it avoids string conversions.
*
* 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).
*
* Delegation chain:
* - 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.
* @param value The value as validated by the caller.
*/
virtual void control(const std::string &value) {
auto index = this->index_of(value);