mirror of
https://github.com/esphome/esphome.git
synced 2025-09-25 06:32:22 +01:00
Webserver - include css, js in index (#932)
* add new config options * init variables in code * load css and js in python * update print inside webserver * fix indentation * fix indentation * indentation fix * fix condition in init * use cv.file_ instead of cv.string * do not import EsphomeError * support embedding js and css at the same time as defined in url * handle css as separate page * handle js as separate page * fix copy and paste error
This commit is contained in:
@@ -3,7 +3,7 @@ import esphome.config_validation as cv
|
||||
from esphome.components import web_server_base
|
||||
from esphome.components.web_server_base import CONF_WEB_SERVER_BASE_ID
|
||||
from esphome.const import (
|
||||
CONF_CSS_URL, CONF_ID, CONF_JS_URL, CONF_PORT,
|
||||
CONF_CSS_INCLUDE, CONF_CSS_URL, CONF_ID, CONF_JS_INCLUDE, CONF_JS_URL, CONF_PORT,
|
||||
CONF_AUTH, CONF_USERNAME, CONF_PASSWORD)
|
||||
from esphome.core import coroutine_with_priority
|
||||
|
||||
@@ -16,7 +16,9 @@ CONFIG_SCHEMA = cv.Schema({
|
||||
cv.GenerateID(): cv.declare_id(WebServer),
|
||||
cv.Optional(CONF_PORT, default=80): cv.port,
|
||||
cv.Optional(CONF_CSS_URL, default="https://esphome.io/_static/webserver-v1.min.css"): cv.string,
|
||||
cv.Optional(CONF_CSS_INCLUDE): cv.file_,
|
||||
cv.Optional(CONF_JS_URL, default="https://esphome.io/_static/webserver-v1.min.js"): cv.string,
|
||||
cv.Optional(CONF_JS_INCLUDE): cv.file_,
|
||||
cv.Optional(CONF_AUTH): cv.Schema({
|
||||
cv.Required(CONF_USERNAME): cv.string_strict,
|
||||
cv.Required(CONF_PASSWORD): cv.string_strict,
|
||||
@@ -39,3 +41,11 @@ def to_code(config):
|
||||
if CONF_AUTH in config:
|
||||
cg.add(var.set_username(config[CONF_AUTH][CONF_USERNAME]))
|
||||
cg.add(var.set_password(config[CONF_AUTH][CONF_PASSWORD]))
|
||||
if CONF_CSS_INCLUDE in config:
|
||||
cg.add_define('WEBSERVER_CSS_INCLUDE')
|
||||
with open(config[CONF_CSS_INCLUDE], "r") as myfile:
|
||||
cg.add(var.set_css_include(myfile.read()))
|
||||
if CONF_JS_INCLUDE in config:
|
||||
cg.add_define('WEBSERVER_JS_INCLUDE')
|
||||
with open(config[CONF_JS_INCLUDE], "r") as myfile:
|
||||
cg.add(var.set_js_include(myfile.read()))
|
||||
|
Reference in New Issue
Block a user