ESPHome 2025.5.0
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#ifdef USE_ESP32
18#include <freertos/FreeRTOS.h>
19#include <freertos/semphr.h>
20#include <deque>
21#endif
22
23#if USE_WEBSERVER_VERSION >= 2
24extern const uint8_t ESPHOME_WEBSERVER_INDEX_HTML[] PROGMEM;
25extern const size_t ESPHOME_WEBSERVER_INDEX_HTML_SIZE;
26#endif
27
28#ifdef USE_WEBSERVER_CSS_INCLUDE
29extern const uint8_t ESPHOME_WEBSERVER_CSS_INCLUDE[] PROGMEM;
30extern const size_t ESPHOME_WEBSERVER_CSS_INCLUDE_SIZE;
31#endif
32
33#ifdef USE_WEBSERVER_JS_INCLUDE
34extern const uint8_t ESPHOME_WEBSERVER_JS_INCLUDE[] PROGMEM;
35extern const size_t ESPHOME_WEBSERVER_JS_INCLUDE_SIZE;
36#endif
37
38namespace esphome {
39namespace web_server {
40
42struct UrlMatch {
43 std::string domain;
44 std::string id;
45 std::string method;
46 bool valid;
47};
48
50 float weight;
51 uint64_t group_id;
52};
53
55 std::string name;
56 float weight;
57};
58
60
61/*
62 In order to defer updates in arduino mode, we need to create one AsyncEventSource per incoming request to /events.
63 This is because only minimal changes were made to the ESPAsyncWebServer lib_dep, it was undesirable to put deferred
64 update logic into that library. We need one deferred queue per connection so instead of one AsyncEventSource with
65 multiple clients, we have multiple event sources with one client each. This is slightly awkward which is why it's
66 implemented in a more straightforward way for ESP-IDF. Arudino platform will eventually go away and this workaround
67 can be forgotten.
68*/
69#ifdef USE_ARDUINO
70using message_generator_t = std::string(WebServer *, void *);
71
73class DeferredUpdateEventSource : public AsyncEventSource {
75
76 /*
77 This class holds a pointer to the source component that wants to publish a state event, and a pointer to a function
78 that will lazily generate that event. The two pointers allow dedup in the deferred queue if multiple publishes for
79 the same component are backed up, and take up only 8 bytes of memory. The entry in the deferred queue (a
80 std::vector) is the DeferredEvent instance itself (not a pointer to one elsewhere in heap) so still only 8 bytes per
81 entry (and no heap fragmentation). Even 100 backed up events (you'd have to have at least 100 sensors publishing
82 because of dedup) would take up only 0.8 kB.
83 */
84 struct DeferredEvent {
85 friend class DeferredUpdateEventSource;
86
87 protected:
88 void *source_;
90
91 public:
92 DeferredEvent(void *source, message_generator_t *message_generator)
93 : source_(source), message_generator_(message_generator) {}
94 bool operator==(const DeferredEvent &test) const {
95 return (source_ == test.source_ && message_generator_ == test.message_generator_);
96 }
97 } __attribute__((packed));
98
99 protected:
100 // surface a couple methods from the base class
101 using AsyncEventSource::handleRequest;
102 using AsyncEventSource::try_send;
103
105 // vector is used very specifically for its zero memory overhead even though items are popped from the front (memory
106 // footprint is more important than speed here)
107 std::vector<DeferredEvent> deferred_queue_;
109
110 // helper for allowing only unique entries in the queue
111 void deq_push_back_with_dedup_(void *source, message_generator_t *message_generator);
112
114
115 public:
116 DeferredUpdateEventSource(WebServer *ws, const String &url)
117 : AsyncEventSource(url), entities_iterator_(ListEntitiesIterator(ws, this)), web_server_(ws) {}
118
119 void loop();
120
121 void deferrable_send_state(void *source, const char *event_type, message_generator_t *message_generator);
122 void try_send_nodefer(const char *message, const char *event = nullptr, uint32_t id = 0, uint32_t reconnect = 0);
123};
124
125class DeferredUpdateEventSourceList : public std::list<DeferredUpdateEventSource *> {
126 protected:
129
130 public:
131 void loop();
132
133 void deferrable_send_state(void *source, const char *event_type, message_generator_t *message_generator);
134 void try_send_nodefer(const char *message, const char *event = nullptr, uint32_t id = 0, uint32_t reconnect = 0);
135
136 void add_new_client(WebServer *ws, AsyncWebServerRequest *request);
137};
138#endif
139
149class WebServer : public Controller, public Component, public AsyncWebHandler {
150#ifdef USE_ARDUINO
152#endif
153
154 public:
156
157#if USE_WEBSERVER_VERSION == 1
163 void set_css_url(const char *css_url);
164
170 void set_js_url(const char *js_url);
171#endif
172
173#ifdef USE_WEBSERVER_CSS_INCLUDE
178 void set_css_include(const char *css_include);
179#endif
180
181#ifdef USE_WEBSERVER_JS_INCLUDE
186 void set_js_include(const char *js_include);
187#endif
188
194 void set_include_internal(bool include_internal) { include_internal_ = include_internal; }
199 void set_allow_ota(bool allow_ota) { this->allow_ota_ = allow_ota; }
204 void set_expose_log(bool expose_log) { this->expose_log_ = expose_log; }
205
206 // ========== INTERNAL METHODS ==========
207 // (In most use cases you won't need these)
209 void setup() override;
210 void loop() override;
211
212 void dump_config() override;
213
215 float get_setup_priority() const override;
216
218 void handle_index_request(AsyncWebServerRequest *request);
219
221 std::string get_config_json();
222
223#ifdef USE_WEBSERVER_CSS_INCLUDE
225 void handle_css_request(AsyncWebServerRequest *request);
226#endif
227
228#ifdef USE_WEBSERVER_JS_INCLUDE
230 void handle_js_request(AsyncWebServerRequest *request);
231#endif
232
233#ifdef USE_WEBSERVER_PRIVATE_NETWORK_ACCESS
234 // Handle Private Network Access CORS OPTIONS request
235 void handle_pna_cors_request(AsyncWebServerRequest *request);
236#endif
237
238#ifdef USE_SENSOR
239 void on_sensor_update(sensor::Sensor *obj, float state) override;
241 void handle_sensor_request(AsyncWebServerRequest *request, const UrlMatch &match);
242
243 static std::string sensor_state_json_generator(WebServer *web_server, void *source);
244 static std::string sensor_all_json_generator(WebServer *web_server, void *source);
246 std::string sensor_json(sensor::Sensor *obj, float value, JsonDetail start_config);
247#endif
248
249#ifdef USE_SWITCH
250 void on_switch_update(switch_::Switch *obj, bool state) override;
251
253 void handle_switch_request(AsyncWebServerRequest *request, const UrlMatch &match);
254
255 static std::string switch_state_json_generator(WebServer *web_server, void *source);
256 static std::string switch_all_json_generator(WebServer *web_server, void *source);
258 std::string switch_json(switch_::Switch *obj, bool value, JsonDetail start_config);
259#endif
260
261#ifdef USE_BUTTON
263 void handle_button_request(AsyncWebServerRequest *request, const UrlMatch &match);
264
265 static std::string button_state_json_generator(WebServer *web_server, void *source);
266 static std::string button_all_json_generator(WebServer *web_server, void *source);
268 std::string button_json(button::Button *obj, JsonDetail start_config);
269#endif
270
271#ifdef USE_BINARY_SENSOR
273
275 void handle_binary_sensor_request(AsyncWebServerRequest *request, const UrlMatch &match);
276
277 static std::string binary_sensor_state_json_generator(WebServer *web_server, void *source);
278 static std::string binary_sensor_all_json_generator(WebServer *web_server, void *source);
280 std::string binary_sensor_json(binary_sensor::BinarySensor *obj, bool value, JsonDetail start_config);
281#endif
282
283#ifdef USE_FAN
284 void on_fan_update(fan::Fan *obj) override;
285
287 void handle_fan_request(AsyncWebServerRequest *request, const UrlMatch &match);
288
289 static std::string fan_state_json_generator(WebServer *web_server, void *source);
290 static std::string fan_all_json_generator(WebServer *web_server, void *source);
292 std::string fan_json(fan::Fan *obj, JsonDetail start_config);
293#endif
294
295#ifdef USE_LIGHT
296 void on_light_update(light::LightState *obj) override;
297
299 void handle_light_request(AsyncWebServerRequest *request, const UrlMatch &match);
300
301 static std::string light_state_json_generator(WebServer *web_server, void *source);
302 static std::string light_all_json_generator(WebServer *web_server, void *source);
304 std::string light_json(light::LightState *obj, JsonDetail start_config);
305#endif
306
307#ifdef USE_TEXT_SENSOR
308 void on_text_sensor_update(text_sensor::TextSensor *obj, const std::string &state) override;
309
311 void handle_text_sensor_request(AsyncWebServerRequest *request, const UrlMatch &match);
312
313 static std::string text_sensor_state_json_generator(WebServer *web_server, void *source);
314 static std::string text_sensor_all_json_generator(WebServer *web_server, void *source);
316 std::string text_sensor_json(text_sensor::TextSensor *obj, const std::string &value, JsonDetail start_config);
317#endif
318
319#ifdef USE_COVER
320 void on_cover_update(cover::Cover *obj) override;
321
323 void handle_cover_request(AsyncWebServerRequest *request, const UrlMatch &match);
324
325 static std::string cover_state_json_generator(WebServer *web_server, void *source);
326 static std::string cover_all_json_generator(WebServer *web_server, void *source);
328 std::string cover_json(cover::Cover *obj, JsonDetail start_config);
329#endif
330
331#ifdef USE_NUMBER
332 void on_number_update(number::Number *obj, float state) override;
334 void handle_number_request(AsyncWebServerRequest *request, const UrlMatch &match);
335
336 static std::string number_state_json_generator(WebServer *web_server, void *source);
337 static std::string number_all_json_generator(WebServer *web_server, void *source);
339 std::string number_json(number::Number *obj, float value, JsonDetail start_config);
340#endif
341
342#ifdef USE_DATETIME_DATE
343 void on_date_update(datetime::DateEntity *obj) override;
345 void handle_date_request(AsyncWebServerRequest *request, const UrlMatch &match);
346
347 static std::string date_state_json_generator(WebServer *web_server, void *source);
348 static std::string date_all_json_generator(WebServer *web_server, void *source);
350 std::string date_json(datetime::DateEntity *obj, JsonDetail start_config);
351#endif
352
353#ifdef USE_DATETIME_TIME
354 void on_time_update(datetime::TimeEntity *obj) override;
356 void handle_time_request(AsyncWebServerRequest *request, const UrlMatch &match);
357
358 static std::string time_state_json_generator(WebServer *web_server, void *source);
359 static std::string time_all_json_generator(WebServer *web_server, void *source);
361 std::string time_json(datetime::TimeEntity *obj, JsonDetail start_config);
362#endif
363
364#ifdef USE_DATETIME_DATETIME
367 void handle_datetime_request(AsyncWebServerRequest *request, const UrlMatch &match);
368
369 static std::string datetime_state_json_generator(WebServer *web_server, void *source);
370 static std::string datetime_all_json_generator(WebServer *web_server, void *source);
372 std::string datetime_json(datetime::DateTimeEntity *obj, JsonDetail start_config);
373#endif
374
375#ifdef USE_TEXT
376 void on_text_update(text::Text *obj, const std::string &state) override;
378 void handle_text_request(AsyncWebServerRequest *request, const UrlMatch &match);
379
380 static std::string text_state_json_generator(WebServer *web_server, void *source);
381 static std::string text_all_json_generator(WebServer *web_server, void *source);
383 std::string text_json(text::Text *obj, const std::string &value, JsonDetail start_config);
384#endif
385
386#ifdef USE_SELECT
387 void on_select_update(select::Select *obj, const std::string &state, size_t index) override;
389 void handle_select_request(AsyncWebServerRequest *request, const UrlMatch &match);
390
391 static std::string select_state_json_generator(WebServer *web_server, void *source);
392 static std::string select_all_json_generator(WebServer *web_server, void *source);
394 std::string select_json(select::Select *obj, const std::string &value, JsonDetail start_config);
395#endif
396
397#ifdef USE_CLIMATE
398 void on_climate_update(climate::Climate *obj) override;
400 void handle_climate_request(AsyncWebServerRequest *request, const UrlMatch &match);
401
402 static std::string climate_state_json_generator(WebServer *web_server, void *source);
403 static std::string climate_all_json_generator(WebServer *web_server, void *source);
405 std::string climate_json(climate::Climate *obj, JsonDetail start_config);
406#endif
407
408#ifdef USE_LOCK
409 void on_lock_update(lock::Lock *obj) override;
410
412 void handle_lock_request(AsyncWebServerRequest *request, const UrlMatch &match);
413
414 static std::string lock_state_json_generator(WebServer *web_server, void *source);
415 static std::string lock_all_json_generator(WebServer *web_server, void *source);
417 std::string lock_json(lock::Lock *obj, lock::LockState value, JsonDetail start_config);
418#endif
419
420#ifdef USE_VALVE
421 void on_valve_update(valve::Valve *obj) override;
422
424 void handle_valve_request(AsyncWebServerRequest *request, const UrlMatch &match);
425
426 static std::string valve_state_json_generator(WebServer *web_server, void *source);
427 static std::string valve_all_json_generator(WebServer *web_server, void *source);
429 std::string valve_json(valve::Valve *obj, JsonDetail start_config);
430#endif
431
432#ifdef USE_ALARM_CONTROL_PANEL
434
436 void handle_alarm_control_panel_request(AsyncWebServerRequest *request, const UrlMatch &match);
437
438 static std::string alarm_control_panel_state_json_generator(WebServer *web_server, void *source);
439 static std::string alarm_control_panel_all_json_generator(WebServer *web_server, void *source);
443#endif
444
445#ifdef USE_EVENT
446 void on_event(event::Event *obj, const std::string &event_type) override;
447
448 static std::string event_state_json_generator(WebServer *web_server, void *source);
449 static std::string event_all_json_generator(WebServer *web_server, void *source);
450
452 void handle_event_request(AsyncWebServerRequest *request, const UrlMatch &match);
453
455 std::string event_json(event::Event *obj, const std::string &event_type, JsonDetail start_config);
456#endif
457
458#ifdef USE_UPDATE
459 void on_update(update::UpdateEntity *obj) override;
460
462 void handle_update_request(AsyncWebServerRequest *request, const UrlMatch &match);
463
464 static std::string update_state_json_generator(WebServer *web_server, void *source);
465 static std::string update_all_json_generator(WebServer *web_server, void *source);
467 std::string update_json(update::UpdateEntity *obj, JsonDetail start_config);
468#endif
469
471 bool canHandle(AsyncWebServerRequest *request) override;
473 void handleRequest(AsyncWebServerRequest *request) override;
475 bool isRequestHandlerTrivial() override; // NOLINT(readability-identifier-naming)
476
477 void add_entity_config(EntityBase *entity, float weight, uint64_t group);
478 void add_sorting_group(uint64_t group_id, const std::string &group_name, float weight);
479
480 std::map<EntityBase *, SortingComponents> sorting_entitys_;
481 std::map<uint64_t, SortingGroup> sorting_groups_;
482 bool include_internal_{false};
483
484 protected:
485 void schedule_(std::function<void()> &&f);
487#ifdef USE_ARDUINO
489#endif
490#ifdef USE_ESP_IDF
491 AsyncEventSource events_{"/events", this};
492#endif
493
494#if USE_WEBSERVER_VERSION == 1
495 const char *css_url_{nullptr};
496 const char *js_url_{nullptr};
497#endif
498#ifdef USE_WEBSERVER_CSS_INCLUDE
499 const char *css_include_{nullptr};
500#endif
501#ifdef USE_WEBSERVER_JS_INCLUDE
502 const char *js_include_{nullptr};
503#endif
504 bool allow_ota_{true};
505 bool expose_log_{true};
506#ifdef USE_ESP32
507 std::deque<std::function<void()>> to_schedule_;
508 SemaphoreHandle_t to_schedule_lock_;
509#endif
510};
511
512} // namespace web_server
513} // namespace esphome
514#endif
bool operator==(const DeferredMessage &test) const
void * source_
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:63
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:57
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:116
void try_send_nodefer(const char *message, const char *event=nullptr, uint32_t id=0, uint32_t reconnect=0)
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:107
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:149
void set_allow_ota(bool allow_ota)
Set whether or not the webserver should expose the OTA form and handler.
Definition web_server.h:199
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.
bool canHandle(AsyncWebServerRequest *request) override
Override the web handler's canHandle method.
void set_expose_log(bool expose_log)
Set whether or not the webserver should expose the Log.
Definition web_server.h:204
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:480
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)
std::deque< std::function< void()> > to_schedule_
Definition web_server.h:507
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>'.
void schedule_(std::function< void()> &&f)
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)
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>'.
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:488
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:194
bool isRequestHandlerTrivial() override
This web handle is not trivial.
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 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)
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>'.
SemaphoreHandle_t to_schedule_lock_
Definition web_server.h:508
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:486
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)
void on_binary_sensor_update(binary_sensor::BinarySensor *obj, bool state) override
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:481
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)
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 handle_datetime_request(AsyncWebServerRequest *request, const UrlMatch &match)
Handle a datetime request under '/datetime/<id>'.
void on_event(event::Event *obj, const std::string &event_type) override
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 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:70
Providing packet encoding functions for exchanging data with a remote host.
Definition a01nyub.cpp:7
Internal helper struct that is used to parse incoming URLs.
Definition web_server.h:42
bool valid
Whether this match is valid.
Definition web_server.h:46
std::string domain
The domain of the component, for example "sensor".
Definition web_server.h:43
std::string id
The id of the device that's being accessed, for example "living_room_fan".
Definition web_server.h:44
std::string method
The method that's being called, for example "turn_on".
Definition web_server.h:45
const uint8_t ESPHOME_WEBSERVER_INDEX_HTML[] PROGMEM
Definition web_server.h:29
const size_t ESPHOME_WEBSERVER_INDEX_HTML_SIZE
message_generator_t * message_generator_
Definition web_server.h:4
const size_t ESPHOME_WEBSERVER_CSS_INCLUDE_SIZE
const size_t ESPHOME_WEBSERVER_JS_INCLUDE_SIZE
DeferredEvent(void *source, message_generator_t *message_generator)
Definition web_server.h:7