From 3d6224d1b10d4431bb0dacfe1fd74c9ab0fb71aa Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Fri, 24 Oct 2025 04:22:22 -0700 Subject: [PATCH] [select] Store options in flash to reduce RAM usage --- esphome/components/copy/select/copy_select.cpp | 2 +- esphome/components/select/select_traits.cpp | 2 ++ esphome/components/select/select_traits.h | 1 + 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/esphome/components/copy/select/copy_select.cpp b/esphome/components/copy/select/copy_select.cpp index 6618ae6347..be90af5a13 100644 --- a/esphome/components/copy/select/copy_select.cpp +++ b/esphome/components/copy/select/copy_select.cpp @@ -10,7 +10,7 @@ void CopySelect::setup() { source_->add_on_state_callback([this](const std::string &value, size_t index) { this->publish_state(value); }); const auto &source_options = source_->traits.get_options(); - traits.set_options({source_options.begin(), source_options.end()}); + traits.set_options(source_options); if (source_->has_state()) this->publish_state(source_->state); diff --git a/esphome/components/select/select_traits.cpp b/esphome/components/select/select_traits.cpp index 06bd2404c2..90a70393d1 100644 --- a/esphome/components/select/select_traits.cpp +++ b/esphome/components/select/select_traits.cpp @@ -5,6 +5,8 @@ namespace select { void SelectTraits::set_options(std::initializer_list options) { this->options_ = options; } +void SelectTraits::set_options(const FixedVector &options) { this->options_ = options; } + const FixedVector &SelectTraits::get_options() const { return this->options_; } } // namespace select diff --git a/esphome/components/select/select_traits.h b/esphome/components/select/select_traits.h index 8f8fe3b71f..b504f08298 100644 --- a/esphome/components/select/select_traits.h +++ b/esphome/components/select/select_traits.h @@ -9,6 +9,7 @@ namespace select { class SelectTraits { public: void set_options(std::initializer_list options); + void set_options(const FixedVector &options); const FixedVector &get_options() const; protected: