ESPHome 2026.3.0-dev
Loading...
Searching...
No Matches
web_server.h
Go to the documentation of this file.
1#pragma once
2
3#include "list_entities.h"
4
7#ifdef USE_WEBSERVER
11#ifdef USE_LOGGER
13#endif
14
15#include <functional>
16#include <list>
17#include <map>
18#include <string>
19#include <utility>
20#include <vector>
21
22#if USE_WEBSERVER_VERSION >= 2
23extern const uint8_t ESPHOME_WEBSERVER_INDEX_HTML[] PROGMEM;
24extern const size_t ESPHOME_WEBSERVER_INDEX_HTML_SIZE;
25#endif
26
27#ifdef USE_WEBSERVER_CSS_INCLUDE
28extern const uint8_t ESPHOME_WEBSERVER_CSS_INCLUDE[] PROGMEM;
29extern const size_t ESPHOME_WEBSERVER_CSS_INCLUDE_SIZE;
30#endif
31
32#ifdef USE_WEBSERVER_JS_INCLUDE
33extern const uint8_t ESPHOME_WEBSERVER_JS_INCLUDE[] PROGMEM;
34extern const size_t ESPHOME_WEBSERVER_JS_INCLUDE_SIZE;
35#endif
36
37namespace esphome::web_server {
38
39// Type for parameter names that can be stored in flash on ESP8266
40#ifdef USE_ESP8266
41using ParamNameType = const __FlashStringHelper *;
42#else
43using ParamNameType = const char *;
44#endif
45
46// All platforms need to defer actions to main loop thread.
47// Multi-core platforms need this for thread safety.
48// ESP8266 needs this because ESPAsyncWebServer callbacks run in "sys" context
49// (SDK system context), not "cont" context (continuation/main loop). Calling
50// yield() from sys context causes a panic in the Arduino core.
51#define DEFER_ACTION(capture, action) this->defer([capture]() mutable { action; })
52
58
60struct UrlMatch {
64#ifdef USE_DEVICES
66#endif
67 bool valid{false};
68
69 // Helper methods for string comparisons
70 bool domain_equals(const char *str) const { return this->domain == str; }
71 bool method_equals(const char *str) const { return this->method == str; }
72
73#ifdef USE_ESP8266
74 // Overloads for flash strings on ESP8266
75 bool domain_equals(const __FlashStringHelper *str) const { return this->domain == str; }
76 bool method_equals(const __FlashStringHelper *str) const { return this->method == str; }
77#endif
78
82};
83
84#ifdef USE_WEBSERVER_SORTING
86 float weight;
87 uint64_t group_id;
88};
89
91 std::string name;
92 float weight;
93};
94#endif
95
97
98/*
99 In order to defer updates in arduino mode, we need to create one AsyncEventSource per incoming request to /events.
100 This is because only minimal changes were made to the ESPAsyncWebServer lib_dep, it was undesirable to put deferred
101 update logic into that library. We need one deferred queue per connection so instead of one AsyncEventSource with
102 multiple clients, we have multiple event sources with one client each. This is slightly awkward which is why it's
103 implemented in a more straightforward way for ESP-IDF. Arduino platform will eventually go away and this workaround
104 can be forgotten.
105*/
106#if !defined(USE_ESP32) && defined(USE_ARDUINO)
108
110class DeferredUpdateEventSource final : public AsyncEventSource {
112
113 /*
114 This class holds a pointer to the source component that wants to publish a state event, and a pointer to a function
115 that will lazily generate that event. The two pointers allow dedup in the deferred queue if multiple publishes for
116 the same component are backed up, and take up only two pointers of memory. The entry in the deferred queue (a
117 std::vector) is the DeferredEvent instance itself (not a pointer to one elsewhere in heap) so still only two
118 pointers per entry (and no heap fragmentation). Even 100 backed up events (you'd have to have at least 100 sensors
119 publishing because of dedup) would take up only 0.8 kB.
120 */
121 struct DeferredEvent {
122 friend class DeferredUpdateEventSource;
123
124 protected:
125 void *source_;
126 message_generator_t *message_generator_;
127
128 public:
129 DeferredEvent(void *source, message_generator_t *message_generator)
130 : source_(source), message_generator_(message_generator) {}
131 bool operator==(const DeferredEvent &test) const {
132 return (source_ == test.source_ && message_generator_ == test.message_generator_);
133 }
134 };
135 static_assert(sizeof(DeferredEvent) == sizeof(void *) + sizeof(message_generator_t *),
136 "DeferredEvent should have no padding");
137
138 protected:
139 // surface a couple methods from the base class
140 using AsyncEventSource::handleRequest;
141 using AsyncEventSource::send;
142
144 // vector is used very specifically for its zero memory overhead even though items are popped from the front (memory
145 // footprint is more important than speed here)
146 std::vector<DeferredEvent> deferred_queue_;
149 static constexpr uint16_t MAX_CONSECUTIVE_SEND_FAILURES = 2500; // ~20 seconds at 125Hz loop rate
150
151 // helper for allowing only unique entries in the queue
152 void deq_push_back_with_dedup_(void *source, message_generator_t *message_generator);
153
155
156 public:
157 DeferredUpdateEventSource(WebServer *ws, const String &url)
158 : AsyncEventSource(url), entities_iterator_(ListEntitiesIterator(ws, this)), web_server_(ws) {}
159
160 void loop();
161
162 void deferrable_send_state(void *source, const char *event_type, message_generator_t *message_generator);
163 void try_send_nodefer(const char *message, const char *event = nullptr, uint32_t id = 0, uint32_t reconnect = 0);
164};
165
166class DeferredUpdateEventSourceList final : public std::list<DeferredUpdateEventSource *> {
167 protected:
170
171 public:
172 void loop();
173
174 void deferrable_send_state(void *source, const char *event_type, message_generator_t *message_generator);
175 void try_send_nodefer(const char *message, const char *event = nullptr, uint32_t id = 0, uint32_t reconnect = 0);
176
177 void add_new_client(WebServer *ws, AsyncWebServerRequest *request);
178};
179#endif
180
190class WebServer final : public Controller, public Component, public AsyncWebHandler {
191#if !defined(USE_ESP32) && defined(USE_ARDUINO)
193#endif
194
195 public:
197
198#if USE_WEBSERVER_VERSION == 1
204 void set_css_url(const char *css_url);
205
211 void set_js_url(const char *js_url);
212#endif
213
214#ifdef USE_WEBSERVER_CSS_INCLUDE
219 void set_css_include(const char *css_include);
220#endif
221
222#ifdef USE_WEBSERVER_JS_INCLUDE
227 void set_js_include(const char *js_include);
228#endif
229
235 void set_include_internal(bool include_internal) { include_internal_ = include_internal; }
240 void set_expose_log(bool expose_log) { this->expose_log_ = expose_log; }
241
242 // ========== INTERNAL METHODS ==========
243 // (In most use cases you won't need these)
245 void setup() override;
246 void loop() override;
247
248 void dump_config() override;
249
250#ifdef USE_LOGGER
251 void on_log(uint8_t level, const char *tag, const char *message, size_t message_len);
252#endif
253
255 float get_setup_priority() const override;
256
258 void handle_index_request(AsyncWebServerRequest *request);
259
262
263#ifdef USE_WEBSERVER_CSS_INCLUDE
265 void handle_css_request(AsyncWebServerRequest *request);
266#endif
267
268#ifdef USE_WEBSERVER_JS_INCLUDE
270 void handle_js_request(AsyncWebServerRequest *request);
271#endif
272
273#ifdef USE_WEBSERVER_PRIVATE_NETWORK_ACCESS
274 // Handle Private Network Access CORS OPTIONS request
275 void handle_pna_cors_request(AsyncWebServerRequest *request);
276#endif
277
278#ifdef USE_SENSOR
279 void on_sensor_update(sensor::Sensor *obj) override;
281 void handle_sensor_request(AsyncWebServerRequest *request, const UrlMatch &match);
282
283 static json::SerializationBuffer<> sensor_state_json_generator(WebServer *web_server, void *source);
284 static json::SerializationBuffer<> sensor_all_json_generator(WebServer *web_server, void *source);
285#endif
286
287#ifdef USE_SWITCH
288 void on_switch_update(switch_::Switch *obj) override;
289
291 void handle_switch_request(AsyncWebServerRequest *request, const UrlMatch &match);
292
293 static json::SerializationBuffer<> switch_state_json_generator(WebServer *web_server, void *source);
294 static json::SerializationBuffer<> switch_all_json_generator(WebServer *web_server, void *source);
295#endif
296
297#ifdef USE_BUTTON
299 void handle_button_request(AsyncWebServerRequest *request, const UrlMatch &match);
300
301 // Buttons are stateless, so there is no button_state_json_generator
302 static json::SerializationBuffer<> button_all_json_generator(WebServer *web_server, void *source);
303#endif
304
305#ifdef USE_BINARY_SENSOR
307
309 void handle_binary_sensor_request(AsyncWebServerRequest *request, const UrlMatch &match);
310
313#endif
314
315#ifdef USE_FAN
316 void on_fan_update(fan::Fan *obj) override;
317
319 void handle_fan_request(AsyncWebServerRequest *request, const UrlMatch &match);
320
321 static json::SerializationBuffer<> fan_state_json_generator(WebServer *web_server, void *source);
322 static json::SerializationBuffer<> fan_all_json_generator(WebServer *web_server, void *source);
323#endif
324
325#ifdef USE_LIGHT
326 void on_light_update(light::LightState *obj) override;
327
329 void handle_light_request(AsyncWebServerRequest *request, const UrlMatch &match);
330
331 static json::SerializationBuffer<> light_state_json_generator(WebServer *web_server, void *source);
332 static json::SerializationBuffer<> light_all_json_generator(WebServer *web_server, void *source);
333#endif
334
335#ifdef USE_TEXT_SENSOR
337
339 void handle_text_sensor_request(AsyncWebServerRequest *request, const UrlMatch &match);
340
343#endif
344
345#ifdef USE_COVER
346 void on_cover_update(cover::Cover *obj) override;
347
349 void handle_cover_request(AsyncWebServerRequest *request, const UrlMatch &match);
350
351 static json::SerializationBuffer<> cover_state_json_generator(WebServer *web_server, void *source);
352 static json::SerializationBuffer<> cover_all_json_generator(WebServer *web_server, void *source);
353#endif
354
355#ifdef USE_NUMBER
356 void on_number_update(number::Number *obj) override;
358 void handle_number_request(AsyncWebServerRequest *request, const UrlMatch &match);
359
360 static json::SerializationBuffer<> number_state_json_generator(WebServer *web_server, void *source);
361 static json::SerializationBuffer<> number_all_json_generator(WebServer *web_server, void *source);
362#endif
363
364#ifdef USE_DATETIME_DATE
365 void on_date_update(datetime::DateEntity *obj) override;
367 void handle_date_request(AsyncWebServerRequest *request, const UrlMatch &match);
368
369 static json::SerializationBuffer<> date_state_json_generator(WebServer *web_server, void *source);
370 static json::SerializationBuffer<> date_all_json_generator(WebServer *web_server, void *source);
371#endif
372
373#ifdef USE_DATETIME_TIME
374 void on_time_update(datetime::TimeEntity *obj) override;
376 void handle_time_request(AsyncWebServerRequest *request, const UrlMatch &match);
377
378 static json::SerializationBuffer<> time_state_json_generator(WebServer *web_server, void *source);
379 static json::SerializationBuffer<> time_all_json_generator(WebServer *web_server, void *source);
380#endif
381
382#ifdef USE_DATETIME_DATETIME
385 void handle_datetime_request(AsyncWebServerRequest *request, const UrlMatch &match);
386
388 static json::SerializationBuffer<> datetime_all_json_generator(WebServer *web_server, void *source);
389#endif
390
391#ifdef USE_TEXT
392 void on_text_update(text::Text *obj) override;
394 void handle_text_request(AsyncWebServerRequest *request, const UrlMatch &match);
395
396 static json::SerializationBuffer<> text_state_json_generator(WebServer *web_server, void *source);
397 static json::SerializationBuffer<> text_all_json_generator(WebServer *web_server, void *source);
398#endif
399
400#ifdef USE_SELECT
401 void on_select_update(select::Select *obj) override;
403 void handle_select_request(AsyncWebServerRequest *request, const UrlMatch &match);
404
405 static json::SerializationBuffer<> select_state_json_generator(WebServer *web_server, void *source);
406 static json::SerializationBuffer<> select_all_json_generator(WebServer *web_server, void *source);
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
415 static json::SerializationBuffer<> climate_all_json_generator(WebServer *web_server, void *source);
416#endif
417
418#ifdef USE_LOCK
419 void on_lock_update(lock::Lock *obj) override;
420
422 void handle_lock_request(AsyncWebServerRequest *request, const UrlMatch &match);
423
424 static json::SerializationBuffer<> lock_state_json_generator(WebServer *web_server, void *source);
425 static json::SerializationBuffer<> lock_all_json_generator(WebServer *web_server, void *source);
426#endif
427
428#ifdef USE_VALVE
429 void on_valve_update(valve::Valve *obj) override;
430
432 void handle_valve_request(AsyncWebServerRequest *request, const UrlMatch &match);
433
434 static json::SerializationBuffer<> valve_state_json_generator(WebServer *web_server, void *source);
435 static json::SerializationBuffer<> valve_all_json_generator(WebServer *web_server, void *source);
436#endif
437
438#ifdef USE_ALARM_CONTROL_PANEL
440
442 void handle_alarm_control_panel_request(AsyncWebServerRequest *request, const UrlMatch &match);
443
446#endif
447
448#ifdef USE_WATER_HEATER
450
452 void handle_water_heater_request(AsyncWebServerRequest *request, const UrlMatch &match);
453
456#endif
457
458#ifdef USE_INFRARED
460 void handle_infrared_request(AsyncWebServerRequest *request, const UrlMatch &match);
461
462 static json::SerializationBuffer<> infrared_all_json_generator(WebServer *web_server, void *source);
463#endif
464
465#ifdef USE_EVENT
466 void on_event(event::Event *obj) override;
467
468 static json::SerializationBuffer<> event_state_json_generator(WebServer *web_server, void *source);
469 static json::SerializationBuffer<> event_all_json_generator(WebServer *web_server, void *source);
470
472 void handle_event_request(AsyncWebServerRequest *request, const UrlMatch &match);
473#endif
474
475#ifdef USE_UPDATE
476 void on_update(update::UpdateEntity *obj) override;
477
479 void handle_update_request(AsyncWebServerRequest *request, const UrlMatch &match);
480
481 static json::SerializationBuffer<> update_state_json_generator(WebServer *web_server, void *source);
482 static json::SerializationBuffer<> update_all_json_generator(WebServer *web_server, void *source);
483#endif
484
486 bool canHandle(AsyncWebServerRequest *request) const override;
488 void handleRequest(AsyncWebServerRequest *request) override;
490 bool isRequestHandlerTrivial() const override; // NOLINT(readability-identifier-naming)
491
492#ifdef USE_WEBSERVER_SORTING
493 void add_entity_config(EntityBase *entity, float weight, uint64_t group);
494 void add_sorting_group(uint64_t group_id, const std::string &group_name, float weight);
495
496 std::map<EntityBase *, SortingComponents> sorting_entitys_;
497 std::map<uint64_t, SortingGroup> sorting_groups_;
498#endif
499
500 bool include_internal_{false};
501
502 protected:
503 void add_sorting_info_(JsonObject &root, EntityBase *entity);
504
505#ifdef USE_LIGHT
506 // Helper to parse and apply a float parameter with optional scaling
507 template<typename T, typename Ret>
508 void parse_light_param_(AsyncWebServerRequest *request, ParamNameType param_name, T &call, Ret (T::*setter)(float),
509 float scale = 1.0f) {
510 auto value = parse_number<float>(request->arg(param_name).c_str());
511 if (value.has_value()) {
512 (call.*setter)(*value / scale);
513 }
514 }
515
516 // Helper to parse and apply a uint32_t parameter with optional scaling
517 template<typename T, typename Ret>
518 void parse_light_param_uint_(AsyncWebServerRequest *request, ParamNameType param_name, T &call,
519 Ret (T::*setter)(uint32_t), uint32_t scale = 1) {
520 auto value = parse_number<uint32_t>(request->arg(param_name).c_str());
521 if (value.has_value()) {
522 (call.*setter)(*value * scale);
523 }
524 }
525#endif
526
527 // Generic helper to parse and apply a numeric parameter
528 template<typename NumT, typename T, typename Ret>
529 void parse_num_param_(AsyncWebServerRequest *request, ParamNameType param_name, T &call, Ret (T::*setter)(NumT)) {
530 auto value = parse_number<NumT>(request->arg(param_name).c_str());
531 if (value.has_value()) {
532 (call.*setter)(*value);
533 }
534 }
535
536 // Generic helper to parse and apply a string parameter using const char* setter (avoids std::string allocation)
537 template<typename T, typename Ret>
538 void parse_cstr_param_(AsyncWebServerRequest *request, ParamNameType param_name, T &call,
539 Ret (T::*setter)(const char *, size_t)) {
540 if (request->hasArg(param_name)) {
541 const auto &value = request->arg(param_name);
542 (call.*setter)(value.c_str(), value.length());
543 }
544 }
545
546 // Generic helper to parse and apply a bool parameter
547 // Accepts: "on", "true", "1" (case-insensitive) as true
548 // Accepts: "off", "false", "0" (case-insensitive) as false
549 // Invalid values are ignored (setter not called)
550 template<typename T, typename Ret>
551 void parse_bool_param_(AsyncWebServerRequest *request, ParamNameType param_name, T &call, Ret (T::*setter)(bool)) {
552 const auto &param_value = request->arg(param_name);
553 // Arduino String has isEmpty() not empty(), use length() for cross-platform compatibility
554 if (param_value.length() > 0) { // NOLINT(readability-container-size-empty)
555 // First check on/off (default), then true/false (custom)
556 auto val = parse_on_off(param_value.c_str());
557 if (val == PARSE_NONE) {
558 val = parse_on_off(param_value.c_str(), "true", "false");
559 }
560 if (val == PARSE_ON || param_value == "1") {
561 (call.*setter)(true);
562 } else if (val == PARSE_OFF || param_value == "0") {
563 (call.*setter)(false);
564 }
565 // PARSE_NONE/PARSE_TOGGLE: ignore invalid values
566 }
567 }
568
570#ifdef USE_ESP32
571 AsyncEventSource events_{"/events", this};
572#elif USE_ARDUINO
574#endif
575
576#if USE_WEBSERVER_VERSION == 1
577 const char *css_url_{nullptr};
578 const char *js_url_{nullptr};
579#endif
580#ifdef USE_WEBSERVER_CSS_INCLUDE
581 const char *css_include_{nullptr};
582#endif
583#ifdef USE_WEBSERVER_JS_INCLUDE
584 const char *js_include_{nullptr};
585#endif
586 bool expose_log_{true};
587
588 private:
589#ifdef USE_SENSOR
590 json::SerializationBuffer<> sensor_json_(sensor::Sensor *obj, float value, JsonDetail start_config);
591#endif
592#ifdef USE_SWITCH
593 json::SerializationBuffer<> switch_json_(switch_::Switch *obj, bool value, JsonDetail start_config);
594#endif
595#ifdef USE_BUTTON
596 json::SerializationBuffer<> button_json_(button::Button *obj, JsonDetail start_config);
597#endif
598#ifdef USE_BINARY_SENSOR
599 json::SerializationBuffer<> binary_sensor_json_(binary_sensor::BinarySensor *obj, bool value,
600 JsonDetail start_config);
601#endif
602#ifdef USE_FAN
603 json::SerializationBuffer<> fan_json_(fan::Fan *obj, JsonDetail start_config);
604#endif
605#ifdef USE_LIGHT
606 json::SerializationBuffer<> light_json_(light::LightState *obj, JsonDetail start_config);
607#endif
608#ifdef USE_TEXT_SENSOR
609 json::SerializationBuffer<> text_sensor_json_(text_sensor::TextSensor *obj, const std::string &value,
610 JsonDetail start_config);
611#endif
612#ifdef USE_COVER
613 json::SerializationBuffer<> cover_json_(cover::Cover *obj, JsonDetail start_config);
614#endif
615#ifdef USE_NUMBER
616 json::SerializationBuffer<> number_json_(number::Number *obj, float value, JsonDetail start_config);
617#endif
618#ifdef USE_DATETIME_DATE
619 json::SerializationBuffer<> date_json_(datetime::DateEntity *obj, JsonDetail start_config);
620#endif
621#ifdef USE_DATETIME_TIME
622 json::SerializationBuffer<> time_json_(datetime::TimeEntity *obj, JsonDetail start_config);
623#endif
624#ifdef USE_DATETIME_DATETIME
625 json::SerializationBuffer<> datetime_json_(datetime::DateTimeEntity *obj, JsonDetail start_config);
626#endif
627#ifdef USE_TEXT
628 json::SerializationBuffer<> text_json_(text::Text *obj, const std::string &value, JsonDetail start_config);
629#endif
630#ifdef USE_SELECT
631 json::SerializationBuffer<> select_json_(select::Select *obj, StringRef value, JsonDetail start_config);
632#endif
633#ifdef USE_CLIMATE
634 json::SerializationBuffer<> climate_json_(climate::Climate *obj, JsonDetail start_config);
635#endif
636#ifdef USE_LOCK
637 json::SerializationBuffer<> lock_json_(lock::Lock *obj, lock::LockState value, JsonDetail start_config);
638#endif
639#ifdef USE_VALVE
640 json::SerializationBuffer<> valve_json_(valve::Valve *obj, JsonDetail start_config);
641#endif
642#ifdef USE_ALARM_CONTROL_PANEL
645 JsonDetail start_config);
646#endif
647#ifdef USE_EVENT
648 json::SerializationBuffer<> event_json_(event::Event *obj, StringRef event_type, JsonDetail start_config);
649#endif
650#ifdef USE_WATER_HEATER
651 json::SerializationBuffer<> water_heater_json_(water_heater::WaterHeater *obj, JsonDetail start_config);
652#endif
653#ifdef USE_INFRARED
654 json::SerializationBuffer<> infrared_json_(infrared::Infrared *obj, JsonDetail start_config);
655#endif
656#ifdef USE_UPDATE
657 json::SerializationBuffer<> update_json_(update::UpdateEntity *obj, JsonDetail start_config);
658#endif
659};
660
661} // namespace esphome::web_server
662#endif
StringRef is a reference to a string owned by something else.
Definition string_ref.h:26
Base class for all binary_sensor-type classes.
Base class for all buttons.
Definition button.h:25
ClimateDevice - This is the base class for all climate integrations.
Definition climate.h:186
Base class for all cover devices.
Definition cover.h:110
Infrared - Base class for infrared remote control implementations.
Definition infrared.h:110
Buffer for JSON serialization that uses stack allocation for small payloads.
Definition json_util.h:22
This class represents the communication layer between the front-end MQTT layer and the hardware outpu...
Definition light_state.h:93
Base class for all locks.
Definition lock.h:110
Base-class for all numbers.
Definition number.h:29
Base-class for all selects.
Definition select.h:29
Base-class for all sensors.
Definition sensor.h:47
Base class for all switches.
Definition switch.h:38
Base-class for all text inputs.
Definition text.h:21
Base class for all valve devices.
Definition valve.h:104
DeferredUpdateEventSource(WebServer *ws, const String &url)
Definition web_server.h:157
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:149
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:146
void on_client_connect_(DeferredUpdateEventSource *source)
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_disconnect_(DeferredUpdateEventSource *source)
This class allows users to create a web server with their ESP nodes.
Definition web_server.h:190
void setup() override
Setup the internal web server and register handlers.
void on_update(update::UpdateEntity *obj) override
void on_water_heater_update(water_heater::WaterHeater *obj) override
void set_expose_log(bool expose_log)
Set whether or not the webserver should expose the Log.
Definition web_server.h:240
json::SerializationBuffer get_config_json()
Return the webserver configuration as JSON.
std::map< EntityBase *, SortingComponents > sorting_entitys_
Definition web_server.h:496
static json::SerializationBuffer text_state_json_generator(WebServer *web_server, void *source)
void on_text_update(text::Text *obj) override
void on_light_update(light::LightState *obj) override
static json::SerializationBuffer datetime_state_json_generator(WebServer *web_server, void *source)
void on_cover_update(cover::Cover *obj) override
static json::SerializationBuffer lock_all_json_generator(WebServer *web_server, void *source)
static json::SerializationBuffer alarm_control_panel_all_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.
static json::SerializationBuffer text_all_json_generator(WebServer *web_server, void *source)
static json::SerializationBuffer switch_all_json_generator(WebServer *web_server, void *source)
void handle_select_request(AsyncWebServerRequest *request, const UrlMatch &match)
Handle a select request under '/select/<id>'.
void on_log(uint8_t level, const char *tag, const char *message, size_t message_len)
static json::SerializationBuffer event_all_json_generator(WebServer *web_server, void *source)
static json::SerializationBuffer update_all_json_generator(WebServer *web_server, void *source)
static json::SerializationBuffer text_sensor_all_json_generator(WebServer *web_server, void *source)
void handle_water_heater_request(AsyncWebServerRequest *request, const UrlMatch &match)
Handle a water_heater request under '/water_heater/<id>/<mode/set>'.
bool isRequestHandlerTrivial() const override
This web handle is not trivial.
static json::SerializationBuffer cover_all_json_generator(WebServer *web_server, void *source)
WebServer(web_server_base::WebServerBase *base)
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, ParamNameType param_name, T &call, Ret(T::*setter)(uint32_t), uint32_t scale=1)
Definition web_server.h:518
static json::SerializationBuffer datetime_all_json_generator(WebServer *web_server, void *source)
DeferredUpdateEventSourceList events_
Definition web_server.h:573
static json::SerializationBuffer light_state_json_generator(WebServer *web_server, void *source)
static json::SerializationBuffer climate_state_json_generator(WebServer *web_server, void *source)
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
static json::SerializationBuffer date_all_json_generator(WebServer *web_server, void *source)
static json::SerializationBuffer sensor_state_json_generator(WebServer *web_server, void *source)
void on_number_update(number::Number *obj) override
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:235
void parse_light_param_(AsyncWebServerRequest *request, ParamNameType param_name, T &call, Ret(T::*setter)(float), float scale=1.0f)
Definition web_server.h:508
void handle_css_request(AsyncWebServerRequest *request)
Handle included css request under '/0.css'.
static json::SerializationBuffer select_all_json_generator(WebServer *web_server, void *source)
static json::SerializationBuffer infrared_all_json_generator(WebServer *web_server, void *source)
void on_valve_update(valve::Valve *obj) override
void on_climate_update(climate::Climate *obj) override
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 json::SerializationBuffer sensor_all_json_generator(WebServer *web_server, void *source)
void on_binary_sensor_update(binary_sensor::BinarySensor *obj) override
void handle_text_request(AsyncWebServerRequest *request, const UrlMatch &match)
Handle a text input request under '/text/<id>'.
static json::SerializationBuffer number_all_json_generator(WebServer *web_server, void *source)
void handle_cover_request(AsyncWebServerRequest *request, const UrlMatch &match)
Handle a cover request under '/cover/<id>/<open/close/stop/set>'.
static json::SerializationBuffer select_state_json_generator(WebServer *web_server, void *source)
void on_switch_update(switch_::Switch *obj) override
static json::SerializationBuffer water_heater_state_json_generator(WebServer *web_server, void *source)
web_server_base::WebServerBase * base_
Definition web_server.h:569
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 json::SerializationBuffer time_state_json_generator(WebServer *web_server, void *source)
void handle_text_sensor_request(AsyncWebServerRequest *request, const UrlMatch &match)
Handle a text sensor request under '/text_sensor/<id>'.
void parse_bool_param_(AsyncWebServerRequest *request, ParamNameType param_name, T &call, Ret(T::*setter)(bool))
Definition web_server.h:551
void handle_date_request(AsyncWebServerRequest *request, const UrlMatch &match)
Handle a date request under '/date/<id>'.
void set_js_url(const char *js_url)
Set the URL to the script that's embedded in the index page.
void handle_infrared_request(AsyncWebServerRequest *request, const UrlMatch &match)
Handle an infrared request under '/infrared/<id>/transmit'.
void handle_sensor_request(AsyncWebServerRequest *request, const UrlMatch &match)
Handle a sensor request under '/sensor/<id>'.
void handle_number_request(AsyncWebServerRequest *request, const UrlMatch &match)
Handle a number request under '/number/<id>'.
void handle_index_request(AsyncWebServerRequest *request)
Handle an index request under '/'.
void handle_js_request(AsyncWebServerRequest *request)
Handle included js request under '/0.js'.
static json::SerializationBuffer valve_state_json_generator(WebServer *web_server, void *source)
static json::SerializationBuffer fan_all_json_generator(WebServer *web_server, void *source)
void set_js_include(const char *js_include)
Set local path to the script that's embedded in the index page.
static json::SerializationBuffer lock_state_json_generator(WebServer *web_server, void *source)
static json::SerializationBuffer update_state_json_generator(WebServer *web_server, void *source)
void handleRequest(AsyncWebServerRequest *request) override
Override the web handler's handleRequest method.
static json::SerializationBuffer button_all_json_generator(WebServer *web_server, void *source)
void on_datetime_update(datetime::DateTimeEntity *obj) override
void handle_fan_request(AsyncWebServerRequest *request, const UrlMatch &match)
Handle a fan request under '/fan/<id>/</turn_on/turn_off/toggle>'.
static json::SerializationBuffer alarm_control_panel_state_json_generator(WebServer *web_server, void *source)
static json::SerializationBuffer time_all_json_generator(WebServer *web_server, void *source)
void parse_cstr_param_(AsyncWebServerRequest *request, ParamNameType param_name, T &call, Ret(T::*setter)(const char *, size_t))
Definition web_server.h:538
static json::SerializationBuffer water_heater_all_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>'.
static json::SerializationBuffer date_state_json_generator(WebServer *web_server, void *source)
void handle_binary_sensor_request(AsyncWebServerRequest *request, const UrlMatch &match)
Handle a binary sensor request under '/binary_sensor/<id>'.
void handle_time_request(AsyncWebServerRequest *request, const UrlMatch &match)
Handle a time request under '/time/<id>'.
void on_sensor_update(sensor::Sensor *obj) override
std::map< uint64_t, SortingGroup > sorting_groups_
Definition web_server.h:497
void set_css_include(const char *css_include)
Set local path to the script that's embedded in the index page.
bool canHandle(AsyncWebServerRequest *request) const override
Override the web handler's canHandle method.
static json::SerializationBuffer climate_all_json_generator(WebServer *web_server, void *source)
static json::SerializationBuffer fan_state_json_generator(WebServer *web_server, void *source)
void on_event(event::Event *obj) override
static json::SerializationBuffer cover_state_json_generator(WebServer *web_server, void *source)
void handle_pna_cors_request(AsyncWebServerRequest *request)
static json::SerializationBuffer binary_sensor_state_json_generator(WebServer *web_server, void *source)
void on_fan_update(fan::Fan *obj) override
void handle_datetime_request(AsyncWebServerRequest *request, const UrlMatch &match)
Handle a datetime request under '/datetime/<id>'.
static json::SerializationBuffer event_state_json_generator(WebServer *web_server, void *source)
static json::SerializationBuffer binary_sensor_all_json_generator(WebServer *web_server, void *source)
void handle_alarm_control_panel_request(AsyncWebServerRequest *request, const UrlMatch &match)
Handle a alarm_control_panel request under '/alarm_control_panel/<id>'.
void on_lock_update(lock::Lock *obj) override
static json::SerializationBuffer switch_state_json_generator(WebServer *web_server, void *source)
float get_setup_priority() const override
MQTT setup priority.
void on_select_update(select::Select *obj) override
void on_time_update(datetime::TimeEntity *obj) override
void parse_num_param_(AsyncWebServerRequest *request, ParamNameType param_name, T &call, Ret(T::*setter)(NumT))
Definition web_server.h:529
static json::SerializationBuffer text_sensor_state_json_generator(WebServer *web_server, void *source)
static json::SerializationBuffer number_state_json_generator(WebServer *web_server, void *source)
static json::SerializationBuffer valve_all_json_generator(WebServer *web_server, void *source)
void handle_update_request(AsyncWebServerRequest *request, const UrlMatch &match)
Handle a update request under '/update/<id>'.
static json::SerializationBuffer light_all_json_generator(WebServer *web_server, void *source)
void add_sorting_group(uint64_t group_id, const std::string &group_name, float weight)
void handle_climate_request(AsyncWebServerRequest *request, const UrlMatch &match)
Handle a climate request under '/climate/<id>'.
void on_text_sensor_update(text_sensor::TextSensor *obj) override
const char * message
Definition component.cpp:38
mopeka_std_values val[4]
LockState
Enum for all states a lock can be in.
Definition lock.h:23
const __FlashStringHelper * ParamNameType
Definition web_server.h:41
json::SerializationBuffer<>(WebServer *, void *) message_generator_t
Definition web_server.h:107
ParseOnOffState parse_on_off(const char *str, const char *on, const char *off)
Parse a string that contains either on, off or toggle.
Definition helpers.cpp:454
optional< T > parse_number(const char *str)
Parse an unsigned decimal number from a null-terminated string.
Definition helpers.h:910
@ PARSE_ON
Definition helpers.h:1436
@ PARSE_OFF
Definition helpers.h:1437
@ PARSE_NONE
Definition helpers.h:1435
Result of matching a URL against an entity.
Definition web_server.h:54
bool matched
True if entity matched the URL.
Definition web_server.h:55
bool action_is_empty
True if no action/method segment in URL.
Definition web_server.h:56
Internal helper struct that is used to parse incoming URLs.
Definition web_server.h:60
StringRef device_name
Device name within URL, empty for main device.
Definition web_server.h:65
bool valid
Whether this match is valid.
Definition web_server.h:67
bool domain_equals(const __FlashStringHelper *str) const
Definition web_server.h:75
EntityMatchResult match_entity(EntityBase *entity) const
Match entity by name first, then fall back to object_id with deprecation warning Returns EntityMatchR...
StringRef method
Method within URL, for example "turn_on".
Definition web_server.h:63
bool domain_equals(const char *str) const
Definition web_server.h:70
bool method_equals(const __FlashStringHelper *str) const
Definition web_server.h:76
bool method_equals(const char *str) const
Definition web_server.h:71
StringRef domain
Domain within URL, for example "sensor".
Definition web_server.h:61
StringRef id
Entity name/id within URL, for example "Temperature".
Definition web_server.h:62
const uint8_t ESPHOME_WEBSERVER_INDEX_HTML[] PROGMEM
Definition web_server.h:28
const size_t ESPHOME_WEBSERVER_INDEX_HTML_SIZE
const size_t ESPHOME_WEBSERVER_CSS_INCLUDE_SIZE
const size_t ESPHOME_WEBSERVER_JS_INCLUDE_SIZE