43 ESP_LOGW(TAG,
"'%s' - Index value %zu out of bounds", LOG_STR_ARG(this->
parent_->
get_log_name()), index);
51optional<size_t> SelectCall::calculate_target_index_(
const char *name) {
54 ESP_LOGW(TAG,
"'%s' - Select has no options", name);
67 ESP_LOGV(TAG,
"'%s' - Setting", name);
68 if (!this->
index_.has_value()) {
69 ESP_LOGW(TAG,
"'%s' - No option set", name);
76 ESP_LOGV(TAG,
"'%s' - Selecting %s, with%s cycling", name,
78 this->
cycle_ ? LOG_STR_LITERAL(
"") : LOG_STR_LITERAL(
"out"));
92 return active_index - 1;
96 return active_index + 1;
104 const auto *name = LOG_STR_ARG(parent->get_log_name());
107 ESP_LOGW(TAG,
"'%s' - SelectCall performed without selecting an operation", name);
112 auto target_index = this->calculate_target_index_(name);
113 if (!target_index.has_value()) {
117 auto idx = target_index.value();
119 ESP_LOGV(TAG,
"'%s' - Set selected option to: %s", name, parent->option_at(idx));
120 parent->control(idx);
const LogString * get_log_name() const
Get the name for a "%s" log argument (LOG_STR_ARG).
SelectCall & select_next(bool cycle)
SelectCall & with_index(size_t index)
optional< size_t > index_
SelectCall & select_last()
SelectCall & with_cycle(bool cycle)
SelectCall & select_previous(bool cycle)
SelectOperation operation_
SelectCall & with_operation(SelectOperation operation)
SelectCall & set_index(size_t index)
SelectCall & set_option(const char *option, size_t len)
SelectCall & select_first()
SelectCall & with_option(const char *option, size_t len)
size_t size() const
Return the number of options in this select component.
optional< size_t > index_of(const char *option, size_t len) const
Find the (optional) index offset of the provided option value.
const SelectOptions & get_options() const
ESPHOME_LOG_TAG(TAG, "select")