Fix css/js file loading for webserver when esphome not executed form config directory (#2207)

This commit is contained in:
Jesse Hills 2021-08-26 15:34:39 +12:00 committed by GitHub
parent 94b28102f5
commit b955527f6c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -13,7 +13,7 @@ from esphome.const import (
CONF_USERNAME,
CONF_PASSWORD,
)
from esphome.core import coroutine_with_priority
from esphome.core import CORE, coroutine_with_priority
AUTO_LOAD = ["json", "web_server_base"]
@ -61,9 +61,11 @@ async def to_code(config):
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:
path = CORE.relative_config_path(config[CONF_CSS_INCLUDE])
with open(path, "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:
path = CORE.relative_config_path(config[CONF_JS_INCLUDE])
with open(path, "r") as myfile:
cg.add(var.set_js_include(myfile.read()))