19 this->options_buffer_ = std::make_unique<char[]>(this->options_buffer_size_);
20 this->option_list_ = std::make_unique<const char *[]>(this->max_options_);
37 bool matching = active !=
nullptr;
38 optional<size_t> new_active;
43 if (matching && active[match_len] == c) {
51 if (matching && active[match_len] ==
'\0' && !new_active.has_value())
55 matching = active !=
nullptr;
58 ESP_LOGW(TAG,
"'%s': Can't parse options %s", this->
entity_id_, options.
c_str());
61 if (
count > this->max_options_) {
62 ESP_LOGE(TAG,
"'%s': %zu options exceed max_options (%u)", this->
entity_id_, count, this->max_options_);
65 if (bytes > this->options_buffer_size_) {
66 ESP_LOGE(TAG,
"'%s': Options need %zu bytes, more than options_buffer_size (%u)", this->
entity_id_, bytes,
67 this->options_buffer_size_);
72 char *
buffer = this->options_buffer_.get();
74 size_t option_start = 0;
80 this->option_list_[index++] =
buffer + option_start;
81 option_start = offset;
87 if (new_active.has_value()) {
92 ESP_LOGD(TAG,
"'%s': Got %zu options", this->
entity_id_, count);
97 if (!index.has_value()) {
98 ESP_LOGW(TAG,
"'%s': State '%s' is not one of the options", this->
entity_id_, state.
c_str());
103 ESP_LOGD(TAG,
"'%s': Got state '%s'", this->
entity_id_, state.
c_str());
108 LOG_SELECT(
"",
"Homeassistant Select",
this);
112 " Options buffer size: %u",
113 this->
entity_id_, this->max_options_, this->options_buffer_size_);
120 ESP_LOGE(TAG,
"No clients connected to API server");
124#ifdef USE_API_WIZARD_LINKED_INPUTS
126 ESP_LOGW(TAG,
"'%s': No entity ID set yet", this->
get_name().c_str());
132 static const char SERVICE_SELECT[] PROGMEM =
"select.select_option";
133 static const char SERVICE_INPUT_SELECT[] PROGMEM =
"input_select.select_option";
134 static const char ENTITY_ID_KEY[] PROGMEM =
"entity_id";
135 static const char OPTION_KEY[] PROGMEM =
"option";
139 const bool input_helper = ESPHOME_strncmp_P(this->
entity_id_, SERVICE_INPUT_SELECT,
sizeof(
"input_") - 1) == 0;
144 auto &entity_id = resp.
data.emplace_back();
148 auto &option = resp.
data.emplace_back();
const StringRef & get_name() const
void set_has_state(bool state)
A string that may live in flash (on ESP8266): pointer and length, with no byte-reading operations.
static constexpr ProgmemStringRef from_lit(const char(&s)[N])
A PROGMEM char array, with its length known at compile time.
StringRef is a reference to a string owned by something else.
constexpr const char * c_str() const
void send_homeassistant_action(const HomeassistantActionRequest &call)
void subscribe_home_assistant_state(const char *entity_id, const char *attribute, std::function< void(StringRef)> &&f)
FixedVector< HomeassistantServiceMap > data
float get_setup_priority() const override
void dump_config() override
void state_changed_(StringRef state)
void control(size_t index) override
void options_changed_(StringRef options)
const char * option_at(size_t index) const
Return the option value at the provided index offset (as const char* from flash).
optional< size_t > index_of(const char *option, size_t len) const
Find the (optional) index offset of the provided option value.
void publish_state(const std::string &state)
void set_options_static(const char *const *options, size_t count)
Codegen only: points at a table that outlives the select.
APIServer * global_api_server
bool parse_python_list(StringRef src, C &&on_char, O &&on_item)
Walk a list attribute as Home Assistant sends it: the Python repr of a list of strings,...
ESPHOME_LOG_TAG(TAG, "homeassistant.binary_sensor")
constexpr float AFTER_CONNECTION
For components that should be initialized after a data connection (API/MQTT) is connected.