Skip to content

Commit

Permalink
web_server support for v3 (esphome#6203)
Browse files Browse the repository at this point in the history
  • Loading branch information
RFDarter authored Mar 20, 2024
1 parent 774cbde commit 7e8e658
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 4 deletions.
9 changes: 7 additions & 2 deletions esphome/components/web_server/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ def default_url(config):
config[CONF_CSS_URL] = ""
if not (CONF_JS_URL in config):
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


Expand All @@ -64,7 +69,7 @@ def validate_ota(config):
{
cv.GenerateID(): cv.declare_id(WebServer),
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_INCLUDE): cv.file_,
cv.Optional(CONF_JS_URL): cv.string,
Expand Down Expand Up @@ -152,7 +157,7 @@ async def to_code(config):
cg.add_define("USE_WEBSERVER")
cg.add_define("USE_WEBSERVER_PORT", config[CONF_PORT])
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.
add_resource_as_progmem("INDEX_HTML", build_index_html(config), compress=False)
else:
Expand Down
2 changes: 1 addition & 1 deletion esphome/components/web_server/web_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ void WebServer::handle_index_request(AsyncWebServerRequest *request) {
stream->print(F("</article></body></html>"));
request->send(stream);
}
#elif USE_WEBSERVER_VERSION == 2
#elif USE_WEBSERVER_VERSION >= 2
void WebServer::handle_index_request(AsyncWebServerRequest *request) {
AsyncWebServerResponse *response =
request->beginResponse_P(200, "text/html", ESPHOME_WEBSERVER_INDEX_HTML, ESPHOME_WEBSERVER_INDEX_HTML_SIZE);
Expand Down
2 changes: 1 addition & 1 deletion esphome/components/web_server/web_server.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#include <freertos/semphr.h>
#endif

#if USE_WEBSERVER_VERSION == 2
#if USE_WEBSERVER_VERSION >= 2
extern const uint8_t ESPHOME_WEBSERVER_INDEX_HTML[] PROGMEM;
extern const size_t ESPHOME_WEBSERVER_INDEX_HTML_SIZE;
#endif
Expand Down
3 changes: 3 additions & 0 deletions tests/test10.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ logger:
api:
reboot_timeout: 10min

web_server:
version: 3

time:
- platform: sntp

Expand Down

0 comments on commit 7e8e658

Please sign in to comment.