diff --git a/esphome/components/select/select.cpp b/esphome/components/select/select.cpp index 37887da27c..beb72aa320 100644 --- a/esphome/components/select/select.cpp +++ b/esphome/components/select/select.cpp @@ -28,12 +28,12 @@ bool Select::has_option(const std::string &option) const { return this->index_of bool Select::has_index(size_t index) const { return index < this->size(); } size_t Select::size() const { - auto options = traits.get_options(); + const auto &options = traits.get_options(); return options.size(); } optional Select::index_of(const std::string &option) const { - auto options = traits.get_options(); + const auto &options = traits.get_options(); auto it = std::find(options.begin(), options.end(), option); if (it == options.end()) { return {}; @@ -51,7 +51,7 @@ optional Select::active_index() const { optional Select::at(size_t index) const { if (this->has_index(index)) { - auto options = traits.get_options(); + const auto &options = traits.get_options(); return options.at(index); } else { return {}; diff --git a/esphome/components/select/select_call.cpp b/esphome/components/select/select_call.cpp index 85f755645c..a8272f8622 100644 --- a/esphome/components/select/select_call.cpp +++ b/esphome/components/select/select_call.cpp @@ -45,7 +45,7 @@ void SelectCall::perform() { auto *parent = this->parent_; const auto *name = parent->get_name().c_str(); const auto &traits = parent->traits; - auto options = traits.get_options(); + const auto &options = traits.get_options(); if (this->operation_ == SELECT_OP_NONE) { ESP_LOGW(TAG, "'%s' - SelectCall performed without selecting an operation", name);