From a992162698f617d4d0dddfed1a25a43ed51c2ea9 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Sat, 22 Aug 2026 00:57:25 -0500 Subject: [PATCH] [select] Inline size() and use the length based index_of in has_option --- esphome/components/select/select.cpp | 5 ----- esphome/components/select/select.h | 4 ++-- 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/esphome/components/select/select.cpp b/esphome/components/select/select.cpp index 9fd6b2b1b8..05a0ee1ed9 100644 --- a/esphome/components/select/select.cpp +++ b/esphome/components/select/select.cpp @@ -32,11 +32,6 @@ void Select::publish_state(size_t index) { #endif } -size_t Select::size() const { - const auto &options = traits.get_options(); - return options.size(); -} - optional Select::index_of(const char *option, size_t len) const { const auto &options = traits.get_options(); for (size_t i = 0; i < options.size(); i++) { diff --git a/esphome/components/select/select.h b/esphome/components/select/select.h index 0813fe9cf2..2294f34e62 100644 --- a/esphome/components/select/select.h +++ b/esphome/components/select/select.h @@ -48,14 +48,14 @@ class Select : public EntityBase { SelectCall make_call() { return SelectCall(this); } /// Return whether this select component contains the provided option. - bool has_option(const std::string &option) const { return this->index_of(option.c_str()).has_value(); } + bool has_option(const std::string &option) const { return this->index_of(option).has_value(); } bool has_option(const char *option) const { return this->index_of(option).has_value(); } /// Return whether this select component contains the provided index offset. bool has_index(size_t index) const { return index < this->size(); } /// Return the number of options in this select component. - size_t size() const; + size_t size() const { return this->traits.get_options().size(); } /// Find the (optional) index offset of the provided option value. optional index_of(const char *option, size_t len) const;