32 bool matching = active !=
nullptr;
33 optional<size_t> new_active;
38 if (matching && active[match_len] == c) {
46 if (matching && active[match_len] ==
'\0' && !new_active.has_value())
50 matching = active !=
nullptr;
53 ESP_LOGW(TAG,
"'%s': Can't parse options %s", this->
entity_id_, options.
c_str());
56 if (
count > this->max_options_) {
57 ESP_LOGE(TAG,
"'%s': %zu options exceed max_options (%u)", this->
entity_id_, count, this->max_options_);
60 if (bytes > this->options_buffer_size_) {
61 ESP_LOGE(TAG,
"'%s': Options need %zu bytes, more than options_buffer_size (%u)", this->
entity_id_, bytes,
62 this->options_buffer_size_);
67 char *
buffer = this->options_buffer_;
69 size_t option_start = 0;
75 this->option_list_[index++] =
buffer + option_start;
76 option_start = offset;
82 if (new_active.has_value()) {
87 ESP_LOGD(TAG,
"'%s': Got %zu options", this->
entity_id_, count);
92 if (!index.has_value()) {
93 ESP_LOGW(TAG,
"'%s': State '%s' is not one of the options", this->
entity_id_, state.
c_str());
103 LOG_SELECT(
"",
"Homeassistant Select",
this);
107 " Options buffer size: %u",
108 this->
entity_id_, this->max_options_, this->options_buffer_size_);
116 static constexpr char SERVICE_SELECT[]
PROGMEM =
"select.select_option";
117 static constexpr char SERVICE_INPUT_SELECT[]
PROGMEM =
"input_select.select_option";
118 static constexpr char OPTION_KEY[]
PROGMEM =
"option";
128 auto &option = resp.
data.emplace_back();
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
bool send_homeassistant_action(const HomeassistantActionRequest &call)
Returns false when no subscribed client took the request, so it was dropped.
void subscribe_home_assistant_state(const char *entity_id, const char *attribute, F &&f)
For internal components: entity_id and attribute must live as long as the server.
FixedVector< HomeassistantServiceMap > data
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,...
void add_entity_id(api::HomeassistantActionRequest &resp, const char *entity_id)
Adds the entity_id entry to an action's data.
bool can_send_action(const char *tag, const char *entity_id, EntityBase *entity)
Logs and returns false when no API client is connected or no entity is linked yet.
ESPHOME_LOG_TAG(TAG, "homeassistant.binary_sensor")
bool is_input_helper(const char *entity_id, const char *input_service)
True if entity_id is an input helper; input_service must start with "input_".
static void const char const char * state
constexpr ColorMode COLOR_MODE_LOOKUP[] PROGMEM