mirror of
https://github.com/esphome/esphome.git
synced 2026-08-22 22:26:21 +00:00
[select] Inline size() and use the length based index_of in has_option
This commit is contained in:
@@ -32,11 +32,6 @@ void Select::publish_state(size_t index) {
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Select::size() const {
|
|
||||||
const auto &options = traits.get_options();
|
|
||||||
return options.size();
|
|
||||||
}
|
|
||||||
|
|
||||||
optional<size_t> Select::index_of(const char *option, size_t len) const {
|
optional<size_t> Select::index_of(const char *option, size_t len) const {
|
||||||
const auto &options = traits.get_options();
|
const auto &options = traits.get_options();
|
||||||
for (size_t i = 0; i < options.size(); i++) {
|
for (size_t i = 0; i < options.size(); i++) {
|
||||||
|
|||||||
@@ -48,14 +48,14 @@ class Select : public EntityBase {
|
|||||||
SelectCall make_call() { return SelectCall(this); }
|
SelectCall make_call() { return SelectCall(this); }
|
||||||
|
|
||||||
/// Return whether this select component contains the provided option.
|
/// 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(); }
|
bool has_option(const char *option) const { return this->index_of(option).has_value(); }
|
||||||
|
|
||||||
/// Return whether this select component contains the provided index offset.
|
/// Return whether this select component contains the provided index offset.
|
||||||
bool has_index(size_t index) const { return index < this->size(); }
|
bool has_index(size_t index) const { return index < this->size(); }
|
||||||
|
|
||||||
/// Return the number of options in this select component.
|
/// 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.
|
/// Find the (optional) index offset of the provided option value.
|
||||||
optional<size_t> index_of(const char *option, size_t len) const;
|
optional<size_t> index_of(const char *option, size_t len) const;
|
||||||
|
|||||||
Reference in New Issue
Block a user