22#if USE_WEBSERVER_VERSION >= 2
23extern const uint8_t ESPHOME_WEBSERVER_INDEX_HTML[]
PROGMEM;
27#ifdef USE_WEBSERVER_CSS_INCLUDE
28extern const uint8_t ESPHOME_WEBSERVER_CSS_INCLUDE[]
PROGMEM;
32#ifdef USE_WEBSERVER_JS_INCLUDE
33extern const uint8_t ESPHOME_WEBSERVER_JS_INCLUDE[]
PROGMEM;
51#define DEFER_ACTION(capture, action) this->defer([capture]() mutable { action; })
70 bool domain_equals(
const char *str)
const {
return this->domain == str; }
71 bool method_equals(
const char *str)
const {
return this->method == str; }
75 bool domain_equals(
const __FlashStringHelper *str)
const {
return this->domain == str; }
76 bool method_equals(
const __FlashStringHelper *str)
const {
return this->method == str; }
84#ifdef USE_WEBSERVER_SORTING
106#if !defined(USE_ESP32) && defined(USE_ARDUINO)
121 struct DeferredEvent {
130 : source_(source), message_generator_(message_generator) {}
131 bool operator==(
const DeferredEvent &test)
const {
132 return (source_ == test.source_ && message_generator_ == test.message_generator_);
136 "DeferredEvent should have no padding");
140 using AsyncEventSource::handleRequest;
141 using AsyncEventSource::send;
163 void try_send_nodefer(
const char *
message,
const char *event =
nullptr, uint32_t
id = 0, uint32_t reconnect = 0);
175 void try_send_nodefer(
const char *
message,
const char *event =
nullptr, uint32_t
id = 0, uint32_t reconnect = 0);
191#if !defined(USE_ESP32) && defined(USE_ARDUINO)
198#if USE_WEBSERVER_VERSION == 1
214#ifdef USE_WEBSERVER_CSS_INCLUDE
222#ifdef USE_WEBSERVER_JS_INCLUDE
245 void setup()
override;
246 void loop()
override;
251 void on_log(uint8_t level,
const char *tag,
const char *
message,
size_t message_len);
263#ifdef USE_WEBSERVER_CSS_INCLUDE
268#ifdef USE_WEBSERVER_JS_INCLUDE
273#ifdef USE_WEBSERVER_PRIVATE_NETWORK_ACCESS
305#ifdef USE_BINARY_SENSOR
335#ifdef USE_TEXT_SENSOR
364#ifdef USE_DATETIME_DATE
373#ifdef USE_DATETIME_TIME
382#ifdef USE_DATETIME_DATETIME
438#ifdef USE_ALARM_CONTROL_PANEL
448#ifdef USE_WATER_HEATER
486 bool canHandle(AsyncWebServerRequest *request)
const override;
492#ifdef USE_WEBSERVER_SORTING
494 void add_sorting_group(uint64_t group_id,
const std::string &group_name,
float weight);
507 template<
typename T,
typename Ret>
509 float scale = 1.0f) {
511 if (value.has_value()) {
512 (
call.*setter)(*value / scale);
517 template<
typename T,
typename Ret>
519 Ret (T::*setter)(uint32_t), uint32_t scale = 1) {
521 if (value.has_value()) {
522 (
call.*setter)(*value * scale);
528 template<
typename NumT,
typename T,
typename Ret>
531 if (value.has_value()) {
532 (
call.*setter)(*value);
537 template<
typename T,
typename Ret>
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());
550 template<
typename T,
typename Ret>
552 const auto ¶m_value = request->arg(param_name);
554 if (param_value.length() > 0) {
561 (
call.*setter)(
true);
563 (
call.*setter)(
false);
576#if USE_WEBSERVER_VERSION == 1
580#ifdef USE_WEBSERVER_CSS_INCLUDE
583#ifdef USE_WEBSERVER_JS_INCLUDE
598#ifdef USE_BINARY_SENSOR
608#ifdef USE_TEXT_SENSOR
618#ifdef USE_DATETIME_DATE
621#ifdef USE_DATETIME_TIME
624#ifdef USE_DATETIME_DATETIME
642#ifdef USE_ALARM_CONTROL_PANEL
650#ifdef USE_WATER_HEATER
StringRef is a reference to a string owned by something else.
Base class for all binary_sensor-type classes.
ClimateDevice - This is the base class for all climate integrations.
Base class for all cover devices.
Infrared - Base class for infrared remote control implementations.
Buffer for JSON serialization that uses stack allocation for small payloads.
This class represents the communication layer between the front-end MQTT layer and the hardware outpu...
Base class for all locks.
Base-class for all numbers.
Base-class for all selects.
Base-class for all sensors.
Base class for all switches.
Base-class for all text inputs.
Base class for all valve devices.
void process_deferred_queue_()
DeferredUpdateEventSource(WebServer *ws, const String &url)
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
uint16_t consecutive_send_failures_
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)
ListEntitiesIterator entities_iterator_
std::vector< DeferredEvent > deferred_queue_
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.
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.
json::SerializationBuffer get_config_json()
Return the webserver configuration as JSON.
std::map< EntityBase *, SortingComponents > sorting_entitys_
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)
void dump_config() override
static json::SerializationBuffer datetime_all_json_generator(WebServer *web_server, void *source)
DeferredUpdateEventSourceList events_
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.
void parse_light_param_(AsyncWebServerRequest *request, ParamNameType param_name, T &call, Ret(T::*setter)(float), float scale=1.0f)
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_
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))
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))
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_
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))
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)
const char * css_include_
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
LockState
Enum for all states a lock can be in.
const __FlashStringHelper * ParamNameType
json::SerializationBuffer<>(WebServer *, void *) message_generator_t
ParseOnOffState parse_on_off(const char *str, const char *on, const char *off)
Parse a string that contains either on, off or toggle.
optional< T > parse_number(const char *str)
Parse an unsigned decimal number from a null-terminated string.
Result of matching a URL against an entity.
bool matched
True if entity matched the URL.
bool action_is_empty
True if no action/method segment in URL.
Internal helper struct that is used to parse incoming URLs.
StringRef device_name
Device name within URL, empty for main device.
bool valid
Whether this match is valid.
bool domain_equals(const __FlashStringHelper *str) const
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".
bool domain_equals(const char *str) const
bool method_equals(const __FlashStringHelper *str) const
bool method_equals(const char *str) const
StringRef domain
Domain within URL, for example "sensor".
StringRef id
Entity name/id within URL, for example "Temperature".
const uint8_t ESPHOME_WEBSERVER_INDEX_HTML[] PROGMEM
const size_t ESPHOME_WEBSERVER_INDEX_HTML_SIZE
const size_t ESPHOME_WEBSERVER_CSS_INCLUDE_SIZE
const size_t ESPHOME_WEBSERVER_JS_INCLUDE_SIZE