16#ifdef USE_API_WIZARD_INPUTS
17#ifdef USE_API_WIZARD_MULTIPLE_INPUTS
20static size_t wizard_join_entity_ids(
const char *value,
size_t length,
char *
out) {
24 const char *comma =
static_cast<const char *
>(memchr(value,
',',
end - value));
25 const char *id_end = comma !=
nullptr ? comma :
end;
26 while (value < id_end && *value ==
' ')
28 while (id_end > value && id_end[-1] ==
' ')
30 size_t id_length = id_end - value;
31 if (id_length == 0 || memchr(value,
'.', id_length) ==
nullptr)
39 memcpy(
out + joined, value, id_length);
48static bool wizard_entity_id_valid(
const char *entity_id,
size_t length) {
49 return length > 0 &&
length < WIZARD_ENTITY_ID_BUFFER_SIZE && memchr(entity_id,
'.',
length) !=
nullptr;
55 for (
size_t i = 0; i < API_WIZARD_INPUT_COUNT; i++) {
61#ifdef USE_API_WIZARD_MULTIPLE_INPUTS
62 if (entry.
size != 0) {
64 const size_t joined = wizard_join_entity_ids(value,
length,
nullptr);
65 if (joined == 0 || joined >= entry.
size)
72 if (!wizard_entity_id_valid(value,
length))
78 ESP_LOGW(TAG,
"Ignoring an entity id for an unknown wizard input, or one that is not valid");
85 resp.
data = API_WIZARD_DATA;
86 resp.
data_len = API_WIZARD_DATA_SIZE;
92#ifdef USE_API_WIZARD_INPUTS
95 if (entity_id ==
nullptr)
97#ifdef USE_API_WIZARD_LINKED_INPUTS
100 client->resend_state_subscriptions(entity_id);
106#ifdef USE_API_WIZARD_LINKED_INPUTS
111 if (it.entity_id != entity_id)
StringRef is a reference to a string owned by something else.
constexpr const char * c_str() const
constexpr size_type size() const
struct esphome::api::APIConnection::APIFlags flags_
void on_wizard_input_set_request(const WizardInputSetRequest &msg)
void resend_state_subscriptions(const char *entity_id)
Tell this client about the subscriptions whose entity id is stored in the given buffer,...
bool send_message(const T &msg)
Returns false as soon as the TCP buffer is full.
void on_device_wizard_request()
const std::vector< HomeAssistantStateSubscription > & get_state_subs() const
ActiveClientsView active_clients() const
std::vector< uint8_t > & out
ESPHOME_LOG_TAG(TAG, "api.connection")
const char * wizard_set_input(const WizardInputSetRequest &msg)
Apply a WizardInputSetRequest: validate it and copy the entity id into the input's buffer.
void progmem_memcpy(void *dst, const void *src, size_t len)
uint8_t home_assistant_states
Where the entity id of an input is kept, found by the key the client uses for it.