ESPHome 2025.9.0-dev
Loading...
Searching...
No Matches
web_server.h
Go to the documentation of this file.
1#pragma once
2
6#ifdef USE_WEBSERVER
10
11#include <functional>
12#include <list>
13#include <map>
14#include <string>
15#include <utility>
16#include <vector>
17
18#if USE_WEBSERVER_VERSION >= 2
19extern const uint8_t ESPHOME_WEBSERVER_INDEX_HTML[] PROGMEM;
20extern const size_t ESPHOME_WEBSERVER_INDEX_HTML_SIZE;
21#endif
22
23#ifdef USE_WEBSERVER_CSS_INCLUDE
24extern const uint8_t ESPHOME_WEBSERVER_CSS_INCLUDE[] PROGMEM;
25extern const size_t ESPHOME_WEBSERVER_CSS_INCLUDE_SIZE;
26#endif
27
28#ifdef USE_WEBSERVER_JS_INCLUDE
29extern const uint8_t ESPHOME_WEBSERVER_JS_INCLUDE[] PROGMEM;
30extern const size_t ESPHOME_WEBSERVER_JS_INCLUDE_SIZE;
31#endif
32
33namespace esphome {
34namespace web_server {
35
37struct UrlMatch {
38 const char *domain;
39 const char *id;
40 const char *method;
41 uint8_t domain_len;
42 uint8_t id_len;
43 uint8_t method_len;
44 bool valid;
45
46 // Helper methods for string comparisons
47 bool domain_equals(const char *str) const {
48 return domain && domain_len == strlen(str) && memcmp(domain, str, domain_len) == 0;
49 }
50
51 bool id_equals(const std::string &str) const {
52 return id && id_len == str.length() && memcmp(id, str.c_str(), id_len) == 0;
53 }
54
55 bool method_equals(const char *str) const {
56 return method && method_len == strlen(str) && memcmp(method, str, method_len) == 0;
57 }
58
59 bool method_empty() const { return method_len == 0; }
60};
61
62#ifdef USE_WEBSERVER_SORTING
64 float weight;
65 uint64_t group_id;
66};
67
69 std::string name;
70 float weight;
71};
72#endif
73
75
76/*
77 In order to defer updates in arduino mode, we need to create one AsyncEventSource per incoming request to /events.
78 This is because only minimal changes were made to the ESPAsyncWebServer lib_dep, it was undesirable to put deferred
79 update logic into that library. We need one deferred queue per connection so instead of one AsyncEventSource with
80 multiple clients, we have multiple event sources with one client each. This is slightly awkward which is why it's
81 implemented in a more straightforward way for ESP-IDF. Arduino platform will eventually go away and this workaround
82 can be forgotten.
83*/
84#ifdef USE_ARDUINO
85using message_generator_t = std::string(WebServer *, void *);
86
88class DeferredUpdateEventSource : public AsyncEventSource {
90
91 /*
92 This class holds a pointer to the source component that wants to publish a state event, and a pointer to a function
93 that will lazily generate that event. The two pointers allow dedup in the deferred queue if multiple publishes for
94 the same component are backed up, and take up only 8 bytes of memory. The entry in the deferred queue (a
95 std::vector) is the DeferredEvent instance itself (not a pointer to one elsewhere in heap) so still only 8 bytes per
96 entry (and no heap fragmentation). Even 100 backed up events (you'd have to have at least 100 sensors publishing
97 because of dedup) would take up only 0.8 kB.
98 */
99 struct DeferredEvent {
100 friend class DeferredUpdateEventSource;
101
102 protected:
103 void *source_;
105
106 public:
107 DeferredEvent(void *source, message_generator_t *message_generator)
108 : source_(source), message_generator_(message_generator) {}
109 bool operator==(const DeferredEvent &test) const {
110 return (source_ == test.source_ && message_generator_ == test.message_generator_);
111 }
112 } __attribute__((packed));
113
114 protected:
115 // surface a couple methods from the base class
116 using AsyncEventSource::handleRequest;
117 using AsyncEventSource::send;
118
120 // vector is used very specifically for its zero memory overhead even though items are popped from the front (memory
121 // footprint is more important than speed here)
122 std::vector<DeferredEvent> deferred_queue_;
125 static constexpr uint16_t MAX_CONSECUTIVE_SEND_FAILURES = 2500; // ~20 seconds at 125Hz loop rate
126
127 // helper for allowing only unique entries in the queue
128 void deq_push_back_with_dedup_(void *source, message_generator_t *message_generator);
129
131
132 public:
133 DeferredUpdateEventSource(WebServer *ws, const String &url)
134 : AsyncEventSource(url), entities_iterator_(ListEntitiesIterator(ws, this)), web_server_(ws) {}
135
136 void loop();
137
138 void deferrable_send_state(void *source, const char *event_type, message_generator_t *message_generator);
139 void try_send_nodefer(const char *message, const char *event = nullptr, uint32_t id = 0, uint32_t reconnect = 0);
140};
141
142class DeferredUpdateEventSourceList : public std::list<DeferredUpdateEventSource *> {
143 protected:
146
147 public:
148 void loop();
149
150 void deferrable_send_state(void *source, const char *event_type, message_generator_t *message_generator);
151 void try_send_nodefer(const char *message, const char *event = nullptr, uint32_t id = 0, uint32_t reconnect = 0);
152
153 void add_new_client(WebServer *ws, AsyncWebServerRequest *request);
154};
155#endif
156
166class WebServer : public Controller, public Component, public AsyncWebHandler {
167#ifdef USE_ARDUINO
169#endif
170
171 public:
173
174#if USE_WEBSERVER_VERSION == 1
180 void set_css_url(const char *css_url);
181
187 void set_js_url(const char *js_url);
188#endif
189
190#ifdef USE_WEBSERVER_CSS_INCLUDE
195 void set_css_include(const char *css_include);
196#endif
197
198#ifdef USE_WEBSERVER_JS_INCLUDE
203 void set_js_include(const char *js_include);
204#endif
205
211 void set_include_internal(bool include_internal) { include_internal_ = include_internal; }
216 void set_expose_log(bool expose_log) { this->expose_log_ = expose_log; }
217
218 // ========== INTERNAL METHODS ==========
219 // (In most use cases you won't need these)
221 void setup() override;
222 void loop() override;
223
224 void dump_config() override;
225
227 float get_setup_priority() const override;
228
230 void handle_index_request(AsyncWebServerRequest *request);
231
233 std::string get_config_json();
234
235#ifdef USE_WEBSERVER_CSS_INCLUDE
237 void handle_css_request(AsyncWebServerRequest *request);
238#endif
239
240#ifdef USE_WEBSERVER_JS_INCLUDE
242 void handle_js_request(AsyncWebServerRequest *request);
243#endif
244
245#ifdef USE_WEBSERVER_PRIVATE_NETWORK_ACCESS
246 // Handle Private Network Access CORS OPTIONS request
247 void handle_pna_cors_request(AsyncWebServerRequest *request);
248#endif
249
250#ifdef USE_SENSOR
251 void on_sensor_update(sensor::Sensor *obj, float state) override;
253 void handle_sensor_request(AsyncWebServerRequest *request, const UrlMatch &match);
254
255 static std::string sensor_state_json_generator(WebServer *web_server, void *source);
256 static std::string sensor_all_json_generator(WebServer *web_server, void *source);
258 std::string sensor_json(sensor::Sensor *obj, float value, JsonDetail start_config);
259#endif
260
261#ifdef USE_SWITCH
262 void on_switch_update(switch_::Switch *obj, bool state) override;
263
265 void handle_switch_request(AsyncWebServerRequest *request, const UrlMatch &match);
266
267 static std::string switch_state_json_generator(WebServer *web_server, void *source);
268 static std::string switch_all_json_generator(WebServer *web_server, void *source);
270 std::string switch_json(switch_::Switch *obj, bool value, JsonDetail start_config);
271#endif
272
273#ifdef USE_BUTTON
275 void handle_button_request(AsyncWebServerRequest *request, const UrlMatch &match);
276
277 static std::string button_state_json_generator(WebServer *web_server, void *source);
278 static std::string button_all_json_generator(WebServer *web_server, void *source);
280 std::string button_json(button::Button *obj, JsonDetail start_config);
281#endif
282
283#ifdef USE_BINARY_SENSOR
285
287 void handle_binary_sensor_request(AsyncWebServerRequest *request, const UrlMatch &match);
288
289 static std::string binary_sensor_state_json_generator(WebServer *web_server, void *source);
290 static std::string binary_sensor_all_json_generator(WebServer *web_server, void *source);
292 std::string binary_sensor_json(binary_sensor::BinarySensor *obj, bool value, JsonDetail start_config);
293#endif
294
295#ifdef USE_FAN
296 void on_fan_update(fan::Fan *obj) override;
297
299 void handle_fan_request(AsyncWebServerRequest *request, const UrlMatch &match);
300
301 static std::string fan_state_json_generator(WebServer *web_server, void *source);
302 static std::string fan_all_json_generator(WebServer *web_server, void *source);
304 std::string fan_json(fan::Fan *obj, JsonDetail start_config);
305#endif
306
307#ifdef USE_LIGHT
308 void on_light_update(light::LightState *obj) override;
309
311 void handle_light_request(AsyncWebServerRequest *request, const UrlMatch &match);
312
313 static std::string light_state_json_generator(WebServer *web_server, void *source);
314 static std::string light_all_json_generator(WebServer *web_server, void *source);
316 std::string light_json(light::LightState *obj, JsonDetail start_config);
317#endif
318
319#ifdef USE_TEXT_SENSOR
320 void on_text_sensor_update(text_sensor::TextSensor *obj, const std::string &state) override;
321
323 void handle_text_sensor_request(AsyncWebServerRequest *request, const UrlMatch &match);
324
325 static std::string text_sensor_state_json_generator(WebServer *web_server, void *source);
326 static std::string text_sensor_all_json_generator(WebServer *web_server, void *source);
328 std::string text_sensor_json(text_sensor::TextSensor *obj, const std::string &value, JsonDetail start_config);
329#endif
330
331#ifdef USE_COVER
332 void on_cover_update(cover::Cover *obj) override;
333
335 void handle_cover_request(AsyncWebServerRequest *request, const UrlMatch &match);
336
337 static std::string cover_state_json_generator(WebServer *web_server, void *source);
338 static std::string cover_all_json_generator(WebServer *web_server, void *source);
340 std::string cover_json(cover::Cover *obj, JsonDetail start_config);
341#endif
342
343#ifdef USE_NUMBER
344 void on_number_update(number::Number *obj, float state) override;
346 void handle_number_request(AsyncWebServerRequest *request, const UrlMatch &match);
347
348 static std::string number_state_json_generator(WebServer *web_server, void *source);
349 static std::string number_all_json_generator(WebServer *web_server, void *source);
351 std::string number_json(number::Number *obj, float value, JsonDetail start_config);
352#endif
353
354#ifdef USE_DATETIME_DATE
355 void on_date_update(datetime::DateEntity *obj) override;
357 void handle_date_request(AsyncWebServerRequest *request, const UrlMatch &match);
358
359 static std::string date_state_json_generator(WebServer *web_server, void *source);
360 static std::string date_all_json_generator(WebServer *web_server, void *source);
362 std::string date_json(datetime::DateEntity *obj, JsonDetail start_config);
363#endif
364
365#ifdef USE_DATETIME_TIME
366 void on_time_update(datetime::TimeEntity *obj) override;
368 void handle_time_request(AsyncWebServerRequest *request, const UrlMatch &match);
369
370 static std::string time_state_json_generator(WebServer *web_server, void *source);
371 static std::string time_all_json_generator(WebServer *web_server, void *source);
373 std::string time_json(datetime::TimeEntity *obj, JsonDetail start_config);
374#endif
375
376#ifdef USE_DATETIME_DATETIME
379 void handle_datetime_request(AsyncWebServerRequest *request, const UrlMatch &match);
380
381 static std::string datetime_state_json_generator(WebServer *web_server, void *source);
382 static std::string datetime_all_json_generator(WebServer *web_server, void *source);
384 std::string datetime_json(datetime::DateTimeEntity *obj, JsonDetail start_config);
385#endif
386
387#ifdef USE_TEXT
388 void on_text_update(text::Text *obj, const std::string &state) override;
390 void handle_text_request(AsyncWebServerRequest *request, const UrlMatch &match);
391
392 static std::string text_state_json_generator(WebServer *web_server, void *source);
393 static std::string text_all_json_generator(WebServer *web_server, void *source);
395 std::string text_json(text::Text *obj, const std::string &value, JsonDetail start_config);
396#endif
397
398#ifdef USE_SELECT
399 void on_select_update(select::Select *obj, const std::string &state, size_t index) override;
401 void handle_select_request(AsyncWebServerRequest *request, const UrlMatch &match);
402
403 static std::string select_state_json_generator(WebServer *web_server, void *source);
404 static std::string select_all_json_generator(WebServer *web_server, void *source);
406 std::string select_json(select::Select *obj, const std::string &value, JsonDetail start_config);
407#endif
408
409#ifdef USE_CLIMATE
410 void on_climate_update(climate::Climate *obj) override;
412 void handle_climate_request(AsyncWebServerRequest *request, const UrlMatch &match);
413
414 static std::string climate_state_json_generator(WebServer *web_server, void *source);
415 static std::string climate_all_json_generator(WebServer *web_server, void *source);
417 std::string climate_json(climate::Climate *obj, JsonDetail start_config);
418#endif
419
420#ifdef USE_LOCK
421 void on_lock_update(lock::Lock *obj) override;
422
424 void handle_lock_request(AsyncWebServerRequest *request, const UrlMatch &match);
425
426 static std::string lock_state_json_generator(WebServer *web_server, void *source);
427 static std::string lock_all_json_generator(WebServer *web_server, void *source);
429 std::string lock_json(lock::Lock *obj, lock::LockState value, JsonDetail start_config);
430#endif
431
432#ifdef USE_VALVE
433 void on_valve_update(valve::Valve *obj) override;
434
436 void handle_valve_request(AsyncWebServerRequest *request, const UrlMatch &match);
437
438 static std::string valve_state_json_generator(WebServer *web_server, void *source);
439 static std::string valve_all_json_generator(WebServer *web_server, void *source);
441 std::string valve_json(valve::Valve *obj, JsonDetail start_config);
442#endif
443
444#ifdef USE_ALARM_CONTROL_PANEL
446
448 void handle_alarm_control_panel_request(AsyncWebServerRequest *request, const UrlMatch &match);
449
450 static std::string alarm_control_panel_state_json_generator(WebServer *web_server, void *source);
451 static std::string alarm_control_panel_all_json_generator(WebServer *web_server, void *source);
455#endif
456
457#ifdef USE_EVENT
458 void on_event(event::Event *obj, const std::string &event_type) override;
459
460 static std::string event_state_json_generator(WebServer *web_server, void *source);
461 static std::string event_all_json_generator(WebServer *web_server, void *source);
462
464 void handle_event_request(AsyncWebServerRequest *request, const UrlMatch &match);
465
467 std::string event_json(event::Event *obj, const std::string &event_type, JsonDetail start_config);
468#endif
469
470#ifdef USE_UPDATE
471 void on_update(update::UpdateEntity *obj) override;
472
474 void handle_update_request(AsyncWebServerRequest *request, const UrlMatch &match);
475
476 static std::string update_state_json_generator(WebServer *web_server, void *source);
477 static std::string update_all_json_generator(WebServer *web_server, void *source);
479 std::string update_json(update::UpdateEntity *obj, JsonDetail start_config);
480#endif
481
483 bool canHandle(AsyncWebServerRequest *request) const override;
485 void handleRequest(AsyncWebServerRequest *request) override;
487 bool isRequestHandlerTrivial() const override; // NOLINT(readability-identifier-naming)
488
489#ifdef USE_WEBSERVER_SORTING
490 void add_entity_config(EntityBase *entity, float weight, uint64_t group);
491 void add_sorting_group(uint64_t group_id, const std::string &group_name, float weight);
492
493 std::map<EntityBase *, SortingComponents> sorting_entitys_;
494 std::map<uint64_t, SortingGroup> sorting_groups_;
495#endif
496
497 bool include_internal_{false};
498
499 protected:
500 void add_sorting_info_(JsonObject &root, EntityBase *entity);
501
502#ifdef USE_LIGHT
503 // Helper to parse and apply a float parameter with optional scaling
504 template<typename T, typename Ret>
505 void parse_light_param_(AsyncWebServerRequest *request, const char *param_name, T &call, Ret (T::*setter)(float),
506 float scale = 1.0f) {
507 if (request->hasParam(param_name)) {
508 auto value = parse_number<float>(request->getParam(param_name)->value().c_str());
509 if (value.has_value()) {
510 (call.*setter)(*value / scale);
511 }
512 }
513 }
514
515 // Helper to parse and apply a uint32_t parameter with optional scaling
516 template<typename T, typename Ret>
517 void parse_light_param_uint_(AsyncWebServerRequest *request, const char *param_name, T &call,
518 Ret (T::*setter)(uint32_t), uint32_t scale = 1) {
519 if (request->hasParam(param_name)) {
520 auto value = parse_number<uint32_t>(request->getParam(param_name)->value().c_str());
521 if (value.has_value()) {
522 (call.*setter)(*value * scale);
523 }
524 }
525 }
526#endif
527
528 // Generic helper to parse and apply a float parameter
529 template<typename T, typename Ret>
530 void parse_float_param_(AsyncWebServerRequest *request, const char *param_name, T &call, Ret (T::*setter)(float)) {
531 if (request->hasParam(param_name)) {
532 auto value = parse_number<float>(request->getParam(param_name)->value().c_str());
533 if (value.has_value()) {
534 (call.*setter)(*value);
535 }
536 }
537 }
538
539 // Generic helper to parse and apply an int parameter
540 template<typename T, typename Ret>
541 void parse_int_param_(AsyncWebServerRequest *request, const char *param_name, T &call, Ret (T::*setter)(int)) {
542 if (request->hasParam(param_name)) {
543 auto value = parse_number<int>(request->getParam(param_name)->value().c_str());
544 if (value.has_value()) {
545 (call.*setter)(*value);
546 }
547 }
548 }
549
550 // Generic helper to parse and apply a string parameter
551 template<typename T, typename Ret>
552 void parse_string_param_(AsyncWebServerRequest *request, const char *param_name, T &call,
553 Ret (T::*setter)(const std::string &)) {
554 if (request->hasParam(param_name)) {
555 // .c_str() is required for Arduino framework where value() returns Arduino String instead of std::string
556 std::string value = request->getParam(param_name)->value().c_str(); // NOLINT(readability-redundant-string-cstr)
557 (call.*setter)(value);
558 }
559 }
560
562#ifdef USE_ARDUINO
564#endif
565#ifdef USE_ESP_IDF
566 AsyncEventSource events_{"/events", this};
567#endif
568
569#if USE_WEBSERVER_VERSION == 1
570 const char *css_url_{nullptr};
571 const char *js_url_{nullptr};
572#endif
573#ifdef USE_WEBSERVER_CSS_INCLUDE
574 const char *css_include_{nullptr};
575#endif
576#ifdef USE_WEBSERVER_JS_INCLUDE
577 const char *js_include_{nullptr};
578#endif
579 bool expose_log_{true};
580};
581
582} // namespace web_server
583} // namespace esphome
584#endif
Base class for all binary_sensor-type classes.
Base class for all buttons.
Definition button.h:29
ClimateDevice - This is the base class for all climate integrations.
Definition climate.h:168
Base class for all cover devices.
Definition cover.h:111
This class represents the communication layer between the front-end MQTT layer and the hardware outpu...
Definition light_state.h:66
Base class for all locks.
Definition lock.h:103
Base-class for all numbers.
Definition number.h:39
Base-class for all selects.
Definition select.h:31
Base-class for all sensors.
Definition sensor.h:59
Base class for all switches.
Definition switch.h:39
Base-class for all text inputs.
Definition text.h:24
Base class for all valve devices.
Definition valve.h:105
DeferredUpdateEventSource(WebServer *ws, const String &url)
Definition web_server.h:133
void try_send_nodefer(const char *message, const char *event=nullptr, uint32_t id=0, uint32_t reconnect=0)
static constexpr uint16_t MAX_CONSECUTIVE_SEND_FAILURES
Definition web_server.h:125
void deq_push_back_with_dedup_(void *source, message_generator_t *message_generator)
void deferrable_send_state(void *source, const char *event_type, message_generator_t *message_generator)
std::vector< DeferredEvent > deferred_queue_
Definition web_server.h:122
void add_new_client(WebServer *ws, AsyncWebServerRequest *request)
void deferrable_send_state(void *source, const char *event_type, message_generator_t *message_generator)
void try_send_nodefer(const char *message, const char *event=nullptr, uint32_t id=0, uint32_t reconnect=0)
void on_client_connect_(WebServer *ws, DeferredUpdateEventSource *source)
void on_client_disconnect_(DeferredUpdateEventSource *source)
This class allows users to create a web server with their ESP nodes.
Definition web_server.h:166
void setup() override
Setup the internal web server and register handlers.
void on_update(update::UpdateEntity *obj) override
static std::string text_sensor_all_json_generator(WebServer *web_server, void *source)
std::string light_json(light::LightState *obj, JsonDetail start_config)
Dump the light state as a JSON string.
void set_expose_log(bool expose_log)
Set whether or not the webserver should expose the Log.
Definition web_server.h:216
std::string date_json(datetime::DateEntity *obj, JsonDetail start_config)
Dump the date state with its value as a JSON string.
std::string get_config_json()
Return the webserver configuration as JSON.
std::map< EntityBase *, SortingComponents > sorting_entitys_
Definition web_server.h:493
static std::string binary_sensor_state_json_generator(WebServer *web_server, void *source)
std::string binary_sensor_json(binary_sensor::BinarySensor *obj, bool value, JsonDetail start_config)
Dump the binary sensor state with its value as a JSON string.
static std::string button_state_json_generator(WebServer *web_server, void *source)
static std::string lock_all_json_generator(WebServer *web_server, void *source)
void on_light_update(light::LightState *obj) override
static std::string date_all_json_generator(WebServer *web_server, void *source)
std::string update_json(update::UpdateEntity *obj, JsonDetail start_config)
Dump the update state with its value as a JSON string.
void on_cover_update(cover::Cover *obj) override
static std::string text_state_json_generator(WebServer *web_server, void *source)
void set_css_url(const char *css_url)
Set the URL to the CSS <link> that's sent to each client.
void handle_select_request(AsyncWebServerRequest *request, const UrlMatch &match)
Handle a select request under '/select/<id>'.
std::string number_json(number::Number *obj, float value, JsonDetail start_config)
Dump the number state with its value as a JSON string.
static std::string event_state_json_generator(WebServer *web_server, void *source)
std::string cover_json(cover::Cover *obj, JsonDetail start_config)
Dump the cover state as a JSON string.
static std::string datetime_all_json_generator(WebServer *web_server, void *source)
static std::string sensor_all_json_generator(WebServer *web_server, void *source)
bool isRequestHandlerTrivial() const override
This web handle is not trivial.
WebServer(web_server_base::WebServerBase *base)
std::string text_sensor_json(text_sensor::TextSensor *obj, const std::string &value, JsonDetail start_config)
Dump the text sensor state with its value as a JSON string.
void on_number_update(number::Number *obj, float state) override
void handle_switch_request(AsyncWebServerRequest *request, const UrlMatch &match)
Handle a switch request under '/switch/<id>/</turn_on/turn_off/toggle>'.
void handle_event_request(AsyncWebServerRequest *request, const UrlMatch &match)
Handle a event request under '/event<id>'.
void parse_light_param_uint_(AsyncWebServerRequest *request, const char *param_name, T &call, Ret(T::*setter)(uint32_t), uint32_t scale=1)
Definition web_server.h:517
std::string button_json(button::Button *obj, JsonDetail start_config)
Dump the button details with its value as a JSON string.
std::string valve_json(valve::Valve *obj, JsonDetail start_config)
Dump the valve state as a JSON string.
DeferredUpdateEventSourceList events_
Definition web_server.h:563
void handle_button_request(AsyncWebServerRequest *request, const UrlMatch &match)
Handle a button request under '/button/<id>/press'.
void on_date_update(datetime::DateEntity *obj) override
std::string text_json(text::Text *obj, const std::string &value, JsonDetail start_config)
Dump the text state with its value as a JSON string.
void add_entity_config(EntityBase *entity, float weight, uint64_t group)
void set_include_internal(bool include_internal)
Determine whether internal components should be displayed on the web server.
Definition web_server.h:211
std::string datetime_json(datetime::DateTimeEntity *obj, JsonDetail start_config)
Dump the datetime state with its value as a JSON string.
void handle_css_request(AsyncWebServerRequest *request)
Handle included css request under '/0.css'.
static std::string sensor_state_json_generator(WebServer *web_server, void *source)
void on_valve_update(valve::Valve *obj) override
void on_climate_update(climate::Climate *obj) override
void on_sensor_update(sensor::Sensor *obj, float state) override
static std::string switch_state_json_generator(WebServer *web_server, void *source)
void add_sorting_info_(JsonObject &root, EntityBase *entity)
void handle_light_request(AsyncWebServerRequest *request, const UrlMatch &match)
Handle a light request under '/light/<id>/</turn_on/turn_off/toggle>'.
static std::string event_all_json_generator(WebServer *web_server, void *source)
static std::string climate_state_json_generator(WebServer *web_server, void *source)
void on_binary_sensor_update(binary_sensor::BinarySensor *obj) override
static std::string number_all_json_generator(WebServer *web_server, void *source)
void handle_text_request(AsyncWebServerRequest *request, const UrlMatch &match)
Handle a text input request under '/text/<id>'.
void handle_cover_request(AsyncWebServerRequest *request, const UrlMatch &match)
Handle a cover request under '/cover/<id>/<open/close/stop/set>'.
void on_select_update(select::Select *obj, const std::string &state, size_t index) override
static std::string date_state_json_generator(WebServer *web_server, void *source)
static std::string valve_all_json_generator(WebServer *web_server, void *source)
static std::string text_all_json_generator(WebServer *web_server, void *source)
web_server_base::WebServerBase * base_
Definition web_server.h:561
static std::string binary_sensor_all_json_generator(WebServer *web_server, void *source)
static std::string light_state_json_generator(WebServer *web_server, void *source)
void handle_lock_request(AsyncWebServerRequest *request, const UrlMatch &match)
Handle a lock request under '/lock/<id>/</lock/unlock/open>'.
void on_alarm_control_panel_update(alarm_control_panel::AlarmControlPanel *obj) override
static std::string light_all_json_generator(WebServer *web_server, void *source)
std::string switch_json(switch_::Switch *obj, bool value, JsonDetail start_config)
Dump the switch state with its value as a JSON string.
void handle_text_sensor_request(AsyncWebServerRequest *request, const UrlMatch &match)
Handle a text sensor request under '/text_sensor/<id>'.
std::string sensor_json(sensor::Sensor *obj, float value, JsonDetail start_config)
Dump the sensor state with its value as a JSON string.
void handle_date_request(AsyncWebServerRequest *request, const UrlMatch &match)
Handle a date request under '/date/<id>'.
static std::string cover_all_json_generator(WebServer *web_server, void *source)
void set_js_url(const char *js_url)
Set the URL to the script that's embedded in the index page.
void handle_sensor_request(AsyncWebServerRequest *request, const UrlMatch &match)
Handle a sensor request under '/sensor/<id>'.
static std::string text_sensor_state_json_generator(WebServer *web_server, void *source)
void handle_number_request(AsyncWebServerRequest *request, const UrlMatch &match)
Handle a number request under '/number/<id>'.
static std::string alarm_control_panel_state_json_generator(WebServer *web_server, void *source)
void handle_index_request(AsyncWebServerRequest *request)
Handle an index request under '/'.
void handle_js_request(AsyncWebServerRequest *request)
Handle included js request under '/0.js'.
void set_js_include(const char *js_include)
Set local path to the script that's embedded in the index page.
void on_text_update(text::Text *obj, const std::string &state) override
static std::string fan_state_json_generator(WebServer *web_server, void *source)
static std::string update_state_json_generator(WebServer *web_server, void *source)
void handleRequest(AsyncWebServerRequest *request) override
Override the web handler's handleRequest method.
static std::string climate_all_json_generator(WebServer *web_server, void *source)
void on_datetime_update(datetime::DateTimeEntity *obj) override
std::string event_json(event::Event *obj, const std::string &event_type, JsonDetail start_config)
Dump the event details with its value as a JSON string.
void on_text_sensor_update(text_sensor::TextSensor *obj, const std::string &state) override
std::string time_json(datetime::TimeEntity *obj, JsonDetail start_config)
Dump the time state with its value as a JSON string.
void handle_fan_request(AsyncWebServerRequest *request, const UrlMatch &match)
Handle a fan request under '/fan/<id>/</turn_on/turn_off/toggle>'.
static std::string cover_state_json_generator(WebServer *web_server, void *source)
static std::string lock_state_json_generator(WebServer *web_server, void *source)
void handle_valve_request(AsyncWebServerRequest *request, const UrlMatch &match)
Handle a valve request under '/valve/<id>/<open/close/stop/set>'.
void handle_binary_sensor_request(AsyncWebServerRequest *request, const UrlMatch &match)
Handle a binary sensor request under '/binary_sensor/<id>'.
static std::string alarm_control_panel_all_json_generator(WebServer *web_server, void *source)
static std::string number_state_json_generator(WebServer *web_server, void *source)
void handle_time_request(AsyncWebServerRequest *request, const UrlMatch &match)
Handle a time request under '/time/<id>'.
std::map< uint64_t, SortingGroup > sorting_groups_
Definition web_server.h:494
void set_css_include(const char *css_include)
Set local path to the script that's embedded in the index page.
static std::string valve_state_json_generator(WebServer *web_server, void *source)
bool canHandle(AsyncWebServerRequest *request) const override
Override the web handler's canHandle method.
std::string lock_json(lock::Lock *obj, lock::LockState value, JsonDetail start_config)
Dump the lock state with its value as a JSON string.
void handle_pna_cors_request(AsyncWebServerRequest *request)
std::string fan_json(fan::Fan *obj, JsonDetail start_config)
Dump the fan state as a JSON string.
void on_fan_update(fan::Fan *obj) override
void parse_light_param_(AsyncWebServerRequest *request, const char *param_name, T &call, Ret(T::*setter)(float), float scale=1.0f)
Definition web_server.h:505
void handle_datetime_request(AsyncWebServerRequest *request, const UrlMatch &match)
Handle a datetime request under '/datetime/<id>'.
void parse_string_param_(AsyncWebServerRequest *request, const char *param_name, T &call, Ret(T::*setter)(const std::string &))
Definition web_server.h:552
void on_event(event::Event *obj, const std::string &event_type) override
void parse_float_param_(AsyncWebServerRequest *request, const char *param_name, T &call, Ret(T::*setter)(float))
Definition web_server.h:530
void handle_alarm_control_panel_request(AsyncWebServerRequest *request, const UrlMatch &match)
Handle a alarm_control_panel request under '/alarm_control_panel/<id>'.
static std::string time_state_json_generator(WebServer *web_server, void *source)
void on_lock_update(lock::Lock *obj) override
static std::string button_all_json_generator(WebServer *web_server, void *source)
static std::string select_state_json_generator(WebServer *web_server, void *source)
float get_setup_priority() const override
MQTT setup priority.
void parse_int_param_(AsyncWebServerRequest *request, const char *param_name, T &call, Ret(T::*setter)(int))
Definition web_server.h:541
void on_time_update(datetime::TimeEntity *obj) override
std::string select_json(select::Select *obj, const std::string &value, JsonDetail start_config)
Dump the select state with its value as a JSON string.
static std::string update_all_json_generator(WebServer *web_server, void *source)
void on_switch_update(switch_::Switch *obj, bool state) override
void handle_update_request(AsyncWebServerRequest *request, const UrlMatch &match)
Handle a update request under '/update/<id>'.
std::string climate_json(climate::Climate *obj, JsonDetail start_config)
Dump the climate details.
static std::string fan_all_json_generator(WebServer *web_server, void *source)
static std::string switch_all_json_generator(WebServer *web_server, void *source)
static std::string time_all_json_generator(WebServer *web_server, void *source)
void add_sorting_group(uint64_t group_id, const std::string &group_name, float weight)
static std::string select_all_json_generator(WebServer *web_server, void *source)
static std::string datetime_state_json_generator(WebServer *web_server, void *source)
void handle_climate_request(AsyncWebServerRequest *request, const UrlMatch &match)
Handle a climate request under '/climate/<id>'.
std::string alarm_control_panel_json(alarm_control_panel::AlarmControlPanel *obj, alarm_control_panel::AlarmControlPanelState value, JsonDetail start_config)
Dump the alarm_control_panel state with its value as a JSON string.
struct @67::@68 __attribute__
bool state
Definition fan.h:0
LockState
Enum for all states a lock can be in.
Definition lock.h:26
std::string(WebServer *, void *) message_generator_t
Definition web_server.h:85
Providing packet encoding functions for exchanging data with a remote host.
Definition a01nyub.cpp:7
optional< T > parse_number(const char *str)
Parse an unsigned decimal number from a null-terminated string.
Definition helpers.h:291
Internal helper struct that is used to parse incoming URLs.
Definition web_server.h:37
const char * domain
Pointer to domain within URL, for example "sensor".
Definition web_server.h:38
const char * id
Pointer to id within URL, for example "living_room_fan".
Definition web_server.h:39
bool valid
Whether this match is valid.
Definition web_server.h:44
uint8_t domain_len
Length of domain string.
Definition web_server.h:41
uint8_t method_len
Length of method string.
Definition web_server.h:43
const char * method
Pointer to method within URL, for example "turn_on".
Definition web_server.h:40
bool domain_equals(const char *str) const
Definition web_server.h:47
uint8_t id_len
Length of id string.
Definition web_server.h:42
bool method_equals(const char *str) const
Definition web_server.h:55
bool id_equals(const std::string &str) const
Definition web_server.h:51
const uint8_t ESPHOME_WEBSERVER_INDEX_HTML[] PROGMEM
Definition web_server.h:24
const size_t ESPHOME_WEBSERVER_INDEX_HTML_SIZE
message_generator_t * message_generator_
Definition web_server.h:4
bool operator==(const DeferredEvent &test) const
Definition web_server.h:9
const size_t ESPHOME_WEBSERVER_CSS_INCLUDE_SIZE
const size_t ESPHOME_WEBSERVER_JS_INCLUDE_SIZE
void * source_
Definition web_server.h:3
DeferredEvent(void *source, message_generator_t *message_generator)
Definition web_server.h:7