3 #include "list_entities.h" 18 #include <freertos/FreeRTOS.h> 19 #include <freertos/semphr.h> 23 #if USE_WEBSERVER_VERSION >= 2 24 extern const uint8_t ESPHOME_WEBSERVER_INDEX_HTML[]
PROGMEM;
28 #ifdef USE_WEBSERVER_CSS_INCLUDE 29 extern const uint8_t ESPHOME_WEBSERVER_CSS_INCLUDE[]
PROGMEM;
33 #ifdef USE_WEBSERVER_JS_INCLUDE 34 extern const uint8_t ESPHOME_WEBSERVER_JS_INCLUDE[]
PROGMEM;
39 namespace web_server {
95 return (source_ == test.source_ && message_generator_ == test.message_generator_);
101 using AsyncEventSource::handleRequest;
102 using AsyncEventSource::try_send;
113 void process_deferred_queue_();
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);
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);
136 void add_new_client(
WebServer *ws, AsyncWebServerRequest *request);
157 #if USE_WEBSERVER_VERSION == 1 163 void set_css_url(
const char *css_url);
170 void set_js_url(
const char *js_url);
173 #ifdef USE_WEBSERVER_CSS_INCLUDE 178 void set_css_include(
const char *css_include);
181 #ifdef USE_WEBSERVER_JS_INCLUDE 186 void set_js_include(
const char *js_include);
209 void setup()
override;
210 void loop()
override;
212 void dump_config()
override;
215 float get_setup_priority()
const override;
218 void handle_index_request(AsyncWebServerRequest *request);
221 std::string get_config_json();
223 #ifdef USE_WEBSERVER_CSS_INCLUDE 224 void handle_css_request(AsyncWebServerRequest *request);
228 #ifdef USE_WEBSERVER_JS_INCLUDE 229 void handle_js_request(AsyncWebServerRequest *request);
233 #ifdef USE_WEBSERVER_PRIVATE_NETWORK_ACCESS 235 void handle_pna_cors_request(AsyncWebServerRequest *request);
241 void handle_sensor_request(AsyncWebServerRequest *request,
const UrlMatch &match);
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);
253 void handle_switch_request(AsyncWebServerRequest *request,
const UrlMatch &match);
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);
262 void handle_button_request(AsyncWebServerRequest *request,
const UrlMatch &match);
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);
271 #ifdef USE_BINARY_SENSOR 275 void handle_binary_sensor_request(AsyncWebServerRequest *request,
const UrlMatch &match);
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);
284 void on_fan_update(
fan::Fan *obj)
override;
287 void handle_fan_request(AsyncWebServerRequest *request,
const UrlMatch &match);
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);
299 void handle_light_request(AsyncWebServerRequest *request,
const UrlMatch &match);
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);
307 #ifdef USE_TEXT_SENSOR 311 void handle_text_sensor_request(AsyncWebServerRequest *request,
const UrlMatch &match);
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);
323 void handle_cover_request(AsyncWebServerRequest *request,
const UrlMatch &match);
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);
334 void handle_number_request(AsyncWebServerRequest *request,
const UrlMatch &match);
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);
342 #ifdef USE_DATETIME_DATE 345 void handle_date_request(AsyncWebServerRequest *request,
const UrlMatch &match);
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);
353 #ifdef USE_DATETIME_TIME 356 void handle_time_request(AsyncWebServerRequest *request,
const UrlMatch &match);
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);
364 #ifdef USE_DATETIME_DATETIME 367 void handle_datetime_request(AsyncWebServerRequest *request,
const UrlMatch &match);
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);
376 void on_text_update(
text::Text *obj,
const std::string &state)
override;
378 void handle_text_request(AsyncWebServerRequest *request,
const UrlMatch &match);
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);
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);
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);
400 void handle_climate_request(AsyncWebServerRequest *request,
const UrlMatch &match);
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);
409 void on_lock_update(
lock::Lock *obj)
override;
412 void handle_lock_request(AsyncWebServerRequest *request,
const UrlMatch &match);
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);
424 void handle_valve_request(AsyncWebServerRequest *request,
const UrlMatch &match);
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);
432 #ifdef USE_ALARM_CONTROL_PANEL 436 void handle_alarm_control_panel_request(AsyncWebServerRequest *request,
const UrlMatch &match);
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);
446 void on_event(
event::Event *obj,
const std::string &event_type)
override;
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);
452 void handle_event_request(AsyncWebServerRequest *request,
const UrlMatch &match);
462 void handle_update_request(AsyncWebServerRequest *request,
const UrlMatch &match);
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);
471 bool canHandle(AsyncWebServerRequest *request)
override;
473 void handleRequest(AsyncWebServerRequest *request)
override;
475 bool isRequestHandlerTrivial()
override;
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);
482 bool include_internal_{
false};
485 void schedule_(std::function<
void()> &&f);
491 AsyncEventSource events_{
"/events",
this};
494 #if USE_WEBSERVER_VERSION == 1 495 const char *css_url_{
nullptr};
496 const char *js_url_{
nullptr};
498 #ifdef USE_WEBSERVER_CSS_INCLUDE 499 const char *css_include_{
nullptr};
501 #ifdef USE_WEBSERVER_JS_INCLUDE 502 const char *js_include_{
nullptr};
504 bool allow_ota_{
true};
505 bool expose_log_{
true};
Base class for all switches.
message_generator_t * message_generator_
const size_t ESPHOME_WEBSERVER_CSS_INCLUDE_SIZE
This class represents the communication layer between the front-end MQTT layer and the hardware outpu...
Base class for all cover devices.
void set_allow_ota(bool allow_ota)
Set whether or not the webserver should expose the OTA form and handler.
SemaphoreHandle_t to_schedule_lock_
This class allows users to create a web server with their ESP nodes.
std::vector< DeferredEvent > deferred_queue_
std::map< EntityBase *, SortingComponents > sorting_entitys_
DeferredEvent(void *source, message_generator_t *message_generator)
DeferredUpdateEventSource(WebServer *ws, const String &url)
void set_include_internal(bool include_internal)
Determine whether internal components should be displayed on the web server.
Base-class for all text inputs.
void set_expose_log(bool expose_log)
Set whether or not the webserver should expose the Log.
const size_t ESPHOME_WEBSERVER_JS_INCLUDE_SIZE
Internal helper struct that is used to parse incoming URLs.
std::map< uint64_t, SortingGroup > sorting_groups_
const size_t ESPHOME_WEBSERVER_INDEX_HTML_SIZE
std::string domain
The domain of the component, for example "sensor".
DeferredUpdateEventSourceList events_
Base-class for all numbers.
bool valid
Whether this match is valid.
enum esphome::EntityCategory __attribute__
friend class DeferredUpdateEventSource
std::string id
The id of the device that's being accessed, for example "living_room_fan".
ListEntitiesIterator entities_iterator_
const uint8_t ESPHOME_WEBSERVER_INDEX_HTML [] PROGMEM
bool operator==(optional< T > const &x, optional< U > const &y)
std::string(WebServer *, void *) message_generator_t
Base-class for all selects.
web_server_base::WebServerBase * base_
Implementation of SPI Controller mode.
Base class for all valve devices.
Base class for all binary_sensor-type classes.
LockState
Enum for all states a lock can be in.
Base-class for all sensors.
std::deque< std::function< void()> > to_schedule_
std::string method
The method that's being called, for example "turn_on".
Base class for all locks.
ClimateDevice - This is the base class for all climate integrations.