ESPHome 2026.11.0-dev
Loading...
Searching...
No Matches
api_wizard.h
Go to the documentation of this file.
1#pragma once
2
4
5#ifdef USE_API_WIZARD
6
7#include <cstddef>
8#include <cstdint>
9#ifdef USE_API_WIZARD_MULTIPLE_INPUTS
10#include <cstring>
11#endif
12
13#include "esphome/core/hal.h"
14#include "proto.h"
16
17namespace esphome::api {
18
19class WizardInputSetRequest;
20
22static constexpr size_t WIZARD_ENTITY_ID_BUFFER_SIZE = 256;
23
26extern const uint8_t API_WIZARD_DATA[] PROGMEM;
27
28#ifdef USE_API_WIZARD_INPUTS
31 uint32_t key; // FNV-1 hash of the ESPHome id of the input
32 char *entity_id; // RAM buffer, WIZARD_ENTITY_ID_BUFFER_SIZE bytes or size, shared with the homeassistant entity
33#ifdef USE_API_WIZARD_MULTIPLE_INPUTS
34 uint16_t size; // Buffer size of a multiple input, 0 for a single input
35#endif
36};
37
39extern const WizardInputEntry API_WIZARD_INPUTS[] PROGMEM;
40
44const char *wizard_set_input(const WizardInputSetRequest &msg);
45#endif
46
47#ifdef USE_API_WIZARD_STANDALONE_INPUTS
51 public:
52 explicit WizardInput(const char *entity_id) : entity_id_(entity_id) {}
55 StringRef entity_id() const { return StringRef(this->entity_id_); }
56 bool has_entity_id() const { return this->entity_id_[0] != '\0'; }
57#ifdef USE_API_WIZARD_MULTIPLE_INPUTS
59 size_t entity_id_count() const {
60 if (!this->has_entity_id())
61 return 0;
62 size_t count = 1;
63 for (const char *p = this->entity_id_; (p = strchr(p, ',')) != nullptr; p++)
64 count++;
65 return count;
66 }
69 template<typename F> void for_each_entity_id(F &&callback) const {
70 // The device stores the list without spaces or empty entries
71 const char *start = this->entity_id_;
72 while (*start != '\0') {
73 const char *end = strchr(start, ',');
74 if (end == nullptr)
75 end = start + strlen(start);
76 callback(StringRef(start, end - start));
77 start = *end == ',' ? end + 1 : end;
78 }
79 }
80#endif
81
82 protected:
83 const char *entity_id_;
84};
85#endif
86
87} // namespace esphome::api
88
89#endif // USE_API_WIZARD
StringRef is a reference to a string owned by something else.
Definition string_ref.h:31
An input of the wizard that is not tied to an entity of the device.
Definition api_wizard.h:50
bool has_entity_id() const
Definition api_wizard.h:56
StringRef entity_id() const
The Home Assistant entity ID, empty until the wizard sets one.
Definition api_wizard.h:55
void for_each_entity_id(F &&callback) const
Call callback(StringRef) for each entity ID in the list, in order.
Definition api_wizard.h:69
size_t entity_id_count() const
The number of entity IDs in the list, 0 until the wizard sets one.
Definition api_wizard.h:59
WizardInput(const char *entity_id)
Definition api_wizard.h:52
unsigned count
Definition gif.cpp:51
const char * wizard_set_input(const WizardInputSetRequest &msg)
Apply a WizardInputSetRequest: validate it and copy the entity id into the input's buffer.
static void uint32_t
Where the entity id of an input is kept, found by the key the client uses for it.
Definition api_wizard.h:30
uint32_t key
Definition api_wizard.h:31
uint16_t size
Definition api_wizard.h:34
char * entity_id
Definition api_wizard.h:32
uint8_t end[39]
Definition sun_gtil2.cpp:17
const uint8_t ESPHOME_WEBSERVER_INDEX_HTML[] PROGMEM
Definition web_server.h:30