1
0
mirror of https://github.com/esphome/esphome.git synced 2025-10-31 23:21:54 +00:00

[select] Store options in flash to reduce RAM usage

This commit is contained in:
J. Nick Koston
2025-10-24 04:27:41 -07:00
parent 18b12f845d
commit 83e4013a25
3 changed files with 2 additions and 8 deletions

View File

@@ -9,8 +9,7 @@ static const char *const TAG = "copy.select";
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);
traits.set_options(source_->traits.get_options());
if (source_->has_state())
this->publish_state(source_->state);

View File

@@ -54,7 +54,7 @@ optional<size_t> Select::active_index() const {
optional<std::string> Select::at(size_t index) const {
if (this->has_index(index)) {
const auto &options = traits.get_options();
return std::string(options.at(index));
return std::string(options[index]);
} else {
return {};
}

View File

@@ -322,11 +322,6 @@ template<typename T> class FixedVector {
T &operator[](size_t i) { return data_[i]; }
const T &operator[](size_t i) const { return data_[i]; }
/// Access element with bounds checking (matches std::vector behavior)
/// Caller must ensure index is valid (i < size())
T &at(size_t i) { return data_[i]; }
const T &at(size_t i) const { return data_[i]; }
// Iterator support for range-based for loops
T *begin() { return data_; }
T *end() { return data_ + size_; }