ESPHome 2026.5.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:
173 bool loop();
174
175 void deferrable_send_state(void *source, const char *event_type, message_generator_t *message_generator);
176 void try_send_nodefer(const char *message, const char *event = nullptr, uint32_t id = 0, uint32_t reconnect = 0);
177
178 void add_new_client(WebServer *ws, AsyncWebServerRequest *request);
179};
180#endif
181
191class WebServer final : public Controller, public Component, public AsyncWebHandler {
192#if !defined(USE_ESP32) && defined(USE_ARDUINO)
194#endif
195
196 public:
198
199#if USE_WEBSERVER_VERSION == 1
205 void set_css_url(const char *css_url);
206
212 void set_js_url(const char *js_url);
213#endif
214
215#ifdef USE_WEBSERVER_CSS_INCLUDE
220 void set_css_include(const char *css_include);
221#endif
222
223#ifdef USE_WEBSERVER_JS_INCLUDE
228 void set_js_include(const char *js_include);
229#endif
230
236 void set_include_internal(bool include_internal) { include_internal_ = include_internal; }
241 void set_expose_log(bool expose_log) { this->expose_log_ = expose_log; }
242
243 // ========== INTERNAL METHODS ==========
244 // (In most use cases you won't need these)
246 void setup() override;
247 void loop() override;
248
249 void dump_config() override;
250
251#ifdef USE_LOGGER
252 void on_log(uint8_t level, const char *tag, const char *message, size_t message_len);
253#endif
254
256 float get_setup_priority() const override;
257
259 void handle_index_request(AsyncWebServerRequest *request);
260
263
264#ifdef USE_WEBSERVER_CSS_INCLUDE
266 void handle_css_request(AsyncWebServerRequest *request);
267#endif
268
269#ifdef USE_WEBSERVER_JS_INCLUDE
271 void handle_js_request(AsyncWebServerRequest *request);
272#endif
273
274#ifdef USE_WEBSERVER_PRIVATE_NETWORK_ACCESS
275 // Handle Private Network Access CORS OPTIONS request
276 void handle_pna_cors_request(AsyncWebServerRequest *request);
277#endif
278
279#ifdef USE_SENSOR
280 void on_sensor_update(sensor::Sensor *obj) override;
282 void handle_sensor_request(AsyncWebServerRequest *request, const UrlMatch &match);
283
286#endif
287
288#ifdef USE_SWITCH
289 void on_switch_update(switch_::Switch *obj) override;
290
292 void handle_switch_request(AsyncWebServerRequest *request, const UrlMatch &match);
293
296#endif
297
298#ifdef USE_BUTTON
300 void handle_button_request(AsyncWebServerRequest *request, const UrlMatch &match);
301
302 // Buttons are stateless, so there is no button_state_json_generator
304#endif
305
306#ifdef USE_BINARY_SENSOR
308
310 void handle_binary_sensor_request(AsyncWebServerRequest *request, const UrlMatch &match);
311
314#endif
315
316#ifdef USE_FAN
317 void on_fan_update(fan::Fan *obj) override;
318
320 void handle_fan_request(AsyncWebServerRequest *request, const UrlMatch &match);
321
324#endif
325
326#ifdef USE_LIGHT
327 void on_light_update(light::LightState *obj) override;
328
330 void handle_light_request(AsyncWebServerRequest *request, const UrlMatch &match);
331
334#endif
335
336#ifdef USE_TEXT_SENSOR
338
340 void handle_text_sensor_request(AsyncWebServerRequest *request, const UrlMatch &match);
341
344#endif
345
346#ifdef USE_COVER
347 void on_cover_update(cover::Cover *obj) override;
348
350 void handle_cover_request(AsyncWebServerRequest *request, const UrlMatch &match);
351
354#endif
355
356#ifdef USE_NUMBER
357 void on_number_update(number::Number *obj) override;
359 void handle_number_request(AsyncWebServerRequest *request, const UrlMatch &match);
360
363#endif
364
365#ifdef USE_DATETIME_DATE
366 void on_date_update(datetime::DateEntity *obj) override;
368 void handle_date_request(AsyncWebServerRequest *request, const UrlMatch &match);
369
372#endif
373
374#ifdef USE_DATETIME_TIME
375 void on_time_update(datetime::TimeEntity *obj) override;
377 void handle_time_request(AsyncWebServerRequest *request, const UrlMatch &match);
378
381#endif
382
383#ifdef USE_DATETIME_DATETIME
386 void handle_datetime_request(AsyncWebServerRequest *request, const UrlMatch &match);
387
390#endif
391
392#ifdef USE_TEXT
393 void on_text_update(text::Text *obj) override;
395 void handle_text_request(AsyncWebServerRequest *request, const UrlMatch &match);
396
399#endif
400
401#ifdef USE_SELECT
402 void on_select_update(select::Select *obj) override;
404 void handle_select_request(AsyncWebServerRequest *request, const UrlMatch &match);
405
408#endif
409
410#ifdef USE_CLIMATE
411 void on_climate_update(climate::Climate *obj) override;
413 void handle_climate_request(AsyncWebServerRequest *request, const UrlMatch &match);
414
417#endif
418
419#ifdef USE_LOCK
420 void on_lock_update(lock::Lock *obj) override;
421
423 void handle_lock_request(AsyncWebServerRequest *request, const UrlMatch &match);
424
427#endif
428
429#ifdef USE_VALVE
430 void on_valve_update(valve::Valve *obj) override;
431
433 void handle_valve_request(AsyncWebServerRequest *request, const UrlMatch &match);
434
437#endif
438
439#ifdef USE_ALARM_CONTROL_PANEL
441
443 void handle_alarm_control_panel_request(AsyncWebServerRequest *request, const UrlMatch &match);
444
447#endif
448
449#ifdef USE_WATER_HEATER
451
453 void handle_water_heater_request(AsyncWebServerRequest *request, const UrlMatch &match);
454
457#endif
458
459#ifdef USE_INFRARED
461 void handle_infrared_request(AsyncWebServerRequest *request, const UrlMatch &match);
462
464#endif
465
466#ifdef USE_EVENT
467 void on_event(event::Event *obj) override;
468
471
473 void handle_event_request(AsyncWebServerRequest *request, const UrlMatch &match);
474#endif
475
476#ifdef USE_UPDATE
477 void on_update(update::UpdateEntity *obj) override;
478
480 void handle_update_request(AsyncWebServerRequest *request, const UrlMatch &match);
481
484#endif
485
487 bool canHandle(AsyncWebServerRequest *request) const override;
489 void handleRequest(AsyncWebServerRequest *request) override;
491 bool isRequestHandlerTrivial() const override; // NOLINT(readability-identifier-naming)
492
493#ifdef USE_WEBSERVER_SORTING
494 void add_entity_config(EntityBase *entity, float weight, uint64_t group);
495 void add_sorting_group(uint64_t group_id, const std::string &group_name, float weight);
496
497 std::map<EntityBase *, SortingComponents> sorting_entitys_;
498 std::map<uint64_t, SortingGroup> sorting_groups_;
499#endif
500
501 bool include_internal_{false};
502
503 protected:
504 void add_sorting_info_(JsonObject &root, EntityBase *entity);
505
506#ifdef USE_LIGHT
507 // Helper to parse and apply a float parameter with optional scaling
508 template<typename T, typename Ret>
509 void parse_light_param_(AsyncWebServerRequest *request, ParamNameType param_name, T &call, Ret (T::*setter)(float),
510 float scale = 1.0f) {
511 auto value = parse_number<float>(request->arg(param_name).c_str());
512 if (value.has_value()) {
513 (call.*setter)(*value / scale);
514 }
515 }
516
517 // Helper to parse and apply a uint32_t parameter with optional scaling
518 template<typename T, typename Ret>
519 void parse_light_param_uint_(AsyncWebServerRequest *request, ParamNameType param_name, T &call,
520 Ret (T::*setter)(uint32_t), uint32_t scale = 1) {
521 auto value = parse_number<uint32_t>(request->arg(param_name).c_str());
522 if (value.has_value()) {
523 (call.*setter)(*value * scale);
524 }
525 }
526#endif
527
528 // Generic helper to parse and apply a numeric parameter
529 template<typename NumT, typename T, typename Ret>
530 void parse_num_param_(AsyncWebServerRequest *request, ParamNameType param_name, T &call, Ret (T::*setter)(NumT)) {
531 auto value = parse_number<NumT>(request->arg(param_name).c_str());
532 if (value.has_value()) {
533 (call.*setter)(*value);
534 }
535 }
536
537 // Generic helper to parse and apply a string parameter using const char* setter (avoids std::string allocation)
538 template<typename T, typename Ret>
539 void parse_cstr_param_(AsyncWebServerRequest *request, ParamNameType param_name, T &call,
540 Ret (T::*setter)(const char *, size_t)) {
541 if (request->hasArg(param_name)) {
542 const auto &value = request->arg(param_name);
543 (call.*setter)(value.c_str(), value.length());
544 }
545 }
546
547 // Generic helper to parse and apply a bool parameter
548 // Accepts: "on", "true", "1" (case-insensitive) as true
549 // Accepts: "off", "false", "0" (case-insensitive) as false
550 // Invalid values are ignored (setter not called)
551 template<typename T, typename Ret>
552 void parse_bool_param_(AsyncWebServerRequest *request, ParamNameType param_name, T &call, Ret (T::*setter)(bool)) {
553 const auto &param_value = request->arg(param_name);
554 // Arduino String has isEmpty() not empty(), use length() for cross-platform compatibility
555 if (param_value.length() > 0) { // NOLINT(readability-container-size-empty)
556 // First check on/off (default), then true/false (custom)
557 auto val = parse_on_off(param_value.c_str());
558 if (val == PARSE_NONE) {
559 val = parse_on_off(param_value.c_str(), "true", "false");
560 }
561 if (val == PARSE_ON || param_value == "1") {
562 (call.*setter)(true);
563 } else if (val == PARSE_OFF || param_value == "0") {
564 (call.*setter)(false);
565 }
566 // PARSE_NONE/PARSE_TOGGLE: ignore invalid values
567 }
568 }
569
571#ifdef USE_ESP32
572 AsyncEventSource events_{"/events", this};
573#elif USE_ARDUINO
575#endif
576
577#if USE_WEBSERVER_VERSION == 1
578 const char *css_url_{nullptr};
579 const char *js_url_{nullptr};
580#endif
581#ifdef USE_WEBSERVER_CSS_INCLUDE
582 const char *css_include_{nullptr};
583#endif
584#ifdef USE_WEBSERVER_JS_INCLUDE
585 const char *js_include_{nullptr};
586#endif
587 bool expose_log_{true};
588
589 private:
590#ifdef USE_SENSOR
591 json::SerializationBuffer<> sensor_json_(sensor::Sensor *obj, float value, JsonDetail start_config);
592#endif
593#ifdef USE_SWITCH
594 json::SerializationBuffer<> switch_json_(switch_::Switch *obj, bool value, JsonDetail start_config);
595#endif
596#ifdef USE_BUTTON
597 json::SerializationBuffer<> button_json_(button::Button *obj, JsonDetail start_config);
598#endif
599#ifdef USE_BINARY_SENSOR
600 json::SerializationBuffer<> binary_sensor_json_(binary_sensor::BinarySensor *obj, bool value,
601 JsonDetail start_config);
602#endif
603#ifdef USE_FAN
604 json::SerializationBuffer<> fan_json_(fan::Fan *obj, JsonDetail start_config);
605#endif
606#ifdef USE_LIGHT
607 json::SerializationBuffer<> light_json_(light::LightState *obj, JsonDetail start_config);
608#endif
609#ifdef USE_TEXT_SENSOR
610 json::SerializationBuffer<> text_sensor_json_(text_sensor::TextSensor *obj, const std::string &value,
611 JsonDetail start_config);
612#endif
613#ifdef USE_COVER
614 json::SerializationBuffer<> cover_json_(cover::Cover *obj, JsonDetail start_config);
615#endif
616#ifdef USE_NUMBER
617 json::SerializationBuffer<> number_json_(number::Number *obj, float value, JsonDetail start_config);
618#endif
619#ifdef USE_DATETIME_DATE
620 json::SerializationBuffer<> date_json_(datetime::DateEntity *obj, JsonDetail start_config);
621#endif
622#ifdef USE_DATETIME_TIME
623 json::SerializationBuffer<> time_json_(datetime::TimeEntity *obj, JsonDetail start_config);
624#endif
625#ifdef USE_DATETIME_DATETIME
626 json::SerializationBuffer<> datetime_json_(datetime::DateTimeEntity *obj, JsonDetail start_config);
627#endif
628#ifdef USE_TEXT
629 json::SerializationBuffer<> text_json_(text::Text *obj, const std::string &value, JsonDetail start_config);
630#endif
631#ifdef USE_SELECT
632 json::SerializationBuffer<> select_json_(select::Select *obj, StringRef value, JsonDetail start_config);
633#endif
634#ifdef USE_CLIMATE
635 json::SerializationBuffer<> climate_json_(climate::Climate *obj, JsonDetail start_config);
636#endif
637#ifdef USE_LOCK
638 json::SerializationBuffer<> lock_json_(lock::Lock *obj, lock::LockState value, JsonDetail start_config);
639#endif
640#ifdef USE_VALVE
641 json::SerializationBuffer<> valve_json_(valve::Valve *obj, JsonDetail start_config);
642#endif
643#ifdef USE_ALARM_CONTROL_PANEL
646 JsonDetail start_config);
647#endif
648#ifdef USE_EVENT
649 json::SerializationBuffer<> event_json_(event::Event *obj, StringRef event_type, JsonDetail start_config);
650#endif
651#ifdef USE_WATER_HEATER
652 json::SerializationBuffer<> water_heater_json_(water_heater::WaterHeater *obj, JsonDetail start_config);
653#endif
654#ifdef USE_INFRARED
655 json::SerializationBuffer<> infrared_json_(infrared::Infrared *obj, JsonDetail start_config);
656#endif
657#ifdef USE_UPDATE
658 json::SerializationBuffer<> update_json_(update::UpdateEntity *obj, JsonDetail start_config);
659#endif
660};
661
662} // namespace esphome::web_server
663#endif
media_source::MediaSource * source
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:187
Base class for all cover devices.
Definition cover.h:110
Infrared - Base class for infrared remote control implementations.
Definition infrared.h:114
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)
bool loop()
Returns true if there are event sources remaining (including pending cleanup).
This class allows users to create a web server with their ESP nodes.
Definition web_server.h:191
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:241
json::SerializationBuffer get_config_json()
Return the webserver configuration as JSON.
std::map< EntityBase *, SortingComponents > sorting_entitys_
Definition web_server.h:497
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:519
static json::SerializationBuffer datetime_all_json_generator(WebServer *web_server, void *source)
DeferredUpdateEventSourceList events_
Definition web_server.h:574
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:236
void parse_light_param_(AsyncWebServerRequest *request, ParamNameType param_name, T &call, Ret(T::*setter)(float), float scale=1.0f)
Definition web_server.h:509
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:570
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:552
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:539
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:498
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:530
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:35
mopeka_std_values val[3]
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
const char * tag
Definition log.h:74
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:510
optional< T > parse_number(const char *str)
Parse an unsigned decimal number from a null-terminated string.
Definition helpers.h:1160
@ PARSE_ON
Definition helpers.h:1701
@ PARSE_OFF
Definition helpers.h:1702
@ PARSE_NONE
Definition helpers.h:1700
static void uint32_t
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