web_server support for v3 (#6203)

This commit is contained in:
RFDarter 2024-03-20 04:37:18 +01:00 committed by GitHub
parent 774cbde1b6
commit 7e8e658999
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 12 additions and 4 deletions

View file

@ -44,6 +44,11 @@ def default_url(config):
config[CONF_CSS_URL] = "" config[CONF_CSS_URL] = ""
if not (CONF_JS_URL in config): if not (CONF_JS_URL in config):
config[CONF_JS_URL] = "https://oi.esphome.io/v2/www.js" config[CONF_JS_URL] = "https://oi.esphome.io/v2/www.js"
if config[CONF_VERSION] == 3:
if not (CONF_CSS_URL in config):
config[CONF_CSS_URL] = ""
if not (CONF_JS_URL in config):
config[CONF_JS_URL] = "https://oi.esphome.io/v3/www.js"
return config return config
@ -64,7 +69,7 @@ CONFIG_SCHEMA = cv.All(
{ {
cv.GenerateID(): cv.declare_id(WebServer), cv.GenerateID(): cv.declare_id(WebServer),
cv.Optional(CONF_PORT, default=80): cv.port, cv.Optional(CONF_PORT, default=80): cv.port,
cv.Optional(CONF_VERSION, default=2): cv.one_of(1, 2, int=True), cv.Optional(CONF_VERSION, default=2): cv.one_of(1, 2, 3, int=True),
cv.Optional(CONF_CSS_URL): cv.string, cv.Optional(CONF_CSS_URL): cv.string,
cv.Optional(CONF_CSS_INCLUDE): cv.file_, cv.Optional(CONF_CSS_INCLUDE): cv.file_,
cv.Optional(CONF_JS_URL): cv.string, cv.Optional(CONF_JS_URL): cv.string,
@ -152,7 +157,7 @@ async def to_code(config):
cg.add_define("USE_WEBSERVER") cg.add_define("USE_WEBSERVER")
cg.add_define("USE_WEBSERVER_PORT", config[CONF_PORT]) cg.add_define("USE_WEBSERVER_PORT", config[CONF_PORT])
cg.add_define("USE_WEBSERVER_VERSION", version) cg.add_define("USE_WEBSERVER_VERSION", version)
if version == 2: if version >= 2:
# Don't compress the index HTML as the data sizes are almost the same. # Don't compress the index HTML as the data sizes are almost the same.
add_resource_as_progmem("INDEX_HTML", build_index_html(config), compress=False) add_resource_as_progmem("INDEX_HTML", build_index_html(config), compress=False)
else: else:

View file

@ -358,7 +358,7 @@ void WebServer::handle_index_request(AsyncWebServerRequest *request) {
stream->print(F("</article></body></html>")); stream->print(F("</article></body></html>"));
request->send(stream); request->send(stream);
} }
#elif USE_WEBSERVER_VERSION == 2 #elif USE_WEBSERVER_VERSION >= 2
void WebServer::handle_index_request(AsyncWebServerRequest *request) { void WebServer::handle_index_request(AsyncWebServerRequest *request) {
AsyncWebServerResponse *response = AsyncWebServerResponse *response =
request->beginResponse_P(200, "text/html", ESPHOME_WEBSERVER_INDEX_HTML, ESPHOME_WEBSERVER_INDEX_HTML_SIZE); request->beginResponse_P(200, "text/html", ESPHOME_WEBSERVER_INDEX_HTML, ESPHOME_WEBSERVER_INDEX_HTML_SIZE);

View file

@ -13,7 +13,7 @@
#include <freertos/semphr.h> #include <freertos/semphr.h>
#endif #endif
#if USE_WEBSERVER_VERSION == 2 #if USE_WEBSERVER_VERSION >= 2
extern const uint8_t ESPHOME_WEBSERVER_INDEX_HTML[] PROGMEM; extern const uint8_t ESPHOME_WEBSERVER_INDEX_HTML[] PROGMEM;
extern const size_t ESPHOME_WEBSERVER_INDEX_HTML_SIZE; extern const size_t ESPHOME_WEBSERVER_INDEX_HTML_SIZE;
#endif #endif

View file

@ -23,6 +23,9 @@ logger:
api: api:
reboot_timeout: 10min reboot_timeout: 10min
web_server:
version: 3
time: time:
- platform: sntp - platform: sntp