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:33:08 -06:00
parent 55b89faac8
commit 1150f8e6ba
2 changed files with 11 additions and 6 deletions

View File

@@ -35,7 +35,12 @@ void Select::publish_state(size_t index) {
this->state_callback_.call(std::string(option), index);
}
const char *Select::current_option() const { return this->option_at(this->active_index_); }
const char *Select::current_option() const {
if (!this->has_state() || !this->has_index(this->active_index_)) {
return "";
}
return this->option_at(this->active_index_);
}
void Select::add_on_state_callback(std::function<void(std::string, size_t)> &&callback) {
this->state_callback_.add(std::move(callback));

View File

@@ -77,6 +77,11 @@ class Select : public EntityBase {
void add_on_state_callback(std::function<void(std::string, size_t)> &&callback);
protected:
friend class SelectCall;
size_t active_index_{0};
/** 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.
@@ -87,11 +92,6 @@ class Select : public EntityBase {
*/
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, 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.