diff --git a/esphome/const.py b/esphome/const.py index d58ed406c7..a4f2815845 100644 --- a/esphome/const.py +++ b/esphome/const.py @@ -441,6 +441,7 @@ CONF_WAIT_UNTIL = 'wait_until' CONF_WAKEUP_PIN = 'wakeup_pin' CONF_WARM_WHITE = 'warm_white' CONF_WARM_WHITE_COLOR_TEMPERATURE = 'warm_white_color_temperature' +CONF_WEB_SERVER = 'web_server' CONF_WHILE = 'while' CONF_WHITE = 'white' CONF_WIDTH = 'width' diff --git a/esphome/core.py b/esphome/core.py index 7aaf6b2c70..6e4f4bccd1 100644 --- a/esphome/core.py +++ b/esphome/core.py @@ -11,7 +11,7 @@ import re from typing import Any, Dict, List # noqa from esphome.const import CONF_ARDUINO_VERSION, CONF_ESPHOME, CONF_USE_ADDRESS, CONF_WIFI, \ - SOURCE_FILE_EXTENSIONS + SOURCE_FILE_EXTENSIONS, CONF_WEB_SERVER from esphome.helpers import ensure_unique_string, is_hassio from esphome.py_compat import IS_PY2, integer_types, text_type, string_types from esphome.util import OrderedDict @@ -594,6 +594,13 @@ class EsphomeCore(object): raise ValueError return self.esp_platform == 'ESP32' + @property + def web_server_enabled(self): + try: + return self.config[CONF_WEB_SERVER] is not None + except KeyError: + False + def add_job(self, func, *args, **kwargs): coro = coroutine(func) task = coro(*args, **kwargs) diff --git a/esphome/dashboard/dashboard.py b/esphome/dashboard/dashboard.py index 0d6a26c6ee..2ff4384fd8 100644 --- a/esphome/dashboard/dashboard.py +++ b/esphome/dashboard/dashboard.py @@ -430,6 +430,11 @@ class DashboardEntry(object): def update_new(self): return const.__version__ + @property + def web_server_enabled(self): + if self.storage is None: + return False + return self.storage.web_server_enabled class MainRequestHandler(BaseHandler): @authenticated diff --git a/esphome/dashboard/templates/index.html b/esphome/dashboard/templates/index.html index b7df4509cc..ff13c2f167 100644 --- a/esphome/dashboard/templates/index.html +++ b/esphome/dashboard/templates/index.html @@ -67,6 +67,9 @@
{{ escape(entry.name) }} + {% if entry.web_server_enabled %} + launch + {% end %} more_vert

diff --git a/esphome/storage_json.py b/esphome/storage_json.py index 4d789b969c..9ba08a9c79 100644 --- a/esphome/storage_json.py +++ b/esphome/storage_json.py @@ -37,7 +37,7 @@ def trash_storage_path(base_path): # type: (str) -> str class StorageJSON(object): def __init__(self, storage_version, name, esphome_version, src_version, arduino_version, address, esp_platform, board, build_path, - firmware_bin_path): + firmware_bin_path, web_server_enabled): # Version of the storage JSON schema assert storage_version is None or isinstance(storage_version, int) self.storage_version = storage_version # type: int @@ -61,6 +61,8 @@ class StorageJSON(object): self.build_path = build_path # type: str # The absolute path to the firmware binary self.firmware_bin_path = firmware_bin_path # type: str + # True if web server is enabled + self.web_server_enabled = web_server_enabled # type: bool def as_dict(self): return { @@ -74,6 +76,7 @@ class StorageJSON(object): 'board': self.board, 'build_path': self.build_path, 'firmware_bin_path': self.firmware_bin_path, + 'web_server_enabled': self.web_server_enabled, } def to_json(self): @@ -97,6 +100,7 @@ class StorageJSON(object): board=esph.board, build_path=esph.build_path, firmware_bin_path=esph.firmware_bin, + web_server_enabled=esph.web_server_enabled, ) @staticmethod @@ -113,6 +117,7 @@ class StorageJSON(object): board=board, build_path=None, firmware_bin_path=None, + web_server_enabled=False, ) @staticmethod @@ -130,9 +135,10 @@ class StorageJSON(object): board = storage.get('board') build_path = storage.get('build_path') firmware_bin_path = storage.get('firmware_bin_path') + web_server_enabled = storage.get('web_server_enabled') return StorageJSON(storage_version, name, esphome_version, src_version, arduino_version, address, esp_platform, board, build_path, - firmware_bin_path) + firmware_bin_path, web_server_enabled) @staticmethod def load(path): # type: (str) -> Optional[StorageJSON]