1
0
mirror of https://github.com/esphome/esphome.git synced 2025-03-14 14:48:18 +00:00

added link from dashboard to web server, if configured

This commit is contained in:
gitolicious 2019-05-25 22:34:16 +00:00
parent df50b95e5a
commit 6aa89fe608
5 changed files with 25 additions and 3 deletions

View File

@ -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'

View File

@ -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)

View File

@ -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

View File

@ -67,6 +67,9 @@
<div class="card-content">
<span class="card-title">
{{ escape(entry.name) }}
{% if entry.web_server_enabled %}
<a href="http://{{ escape(entry.address) }}" target="_blank"><i class="material-icons icon-grey">launch</i></a>
{% end %}
<i class="material-icons right dropdown-trigger" data-target="dropdown-{{ i }}">more_vert</i>
</span>
<p>

View File

@ -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]