Device description in dashboard (#707)

* Description

* Review fixes

* Test

* Label

* Description renamed to comment
This commit is contained in:
Nikolay Vasilchuk 2019-10-14 12:27:07 +03:00 committed by Otto Winter
parent 0eadda77b0
commit be91cfb261
8 changed files with 40 additions and 5 deletions

View file

@ -86,6 +86,7 @@ CONF_COLOR_CORRECT = 'color_correct'
CONF_COLOR_TEMPERATURE = 'color_temperature'
CONF_COMMAND = 'command'
CONF_COMMAND_TOPIC = 'command_topic'
CONF_COMMENT = 'comment'
CONF_COMMIT = 'commit'
CONF_COMPONENTS = 'components'
CONF_COMPONENT_ID = 'component_id'

View file

@ -10,8 +10,8 @@ import re
# pylint: disable=unused-import, wrong-import-order
from typing import Any, Dict, List # noqa
from esphome.const import CONF_ARDUINO_VERSION, CONF_ESPHOME, CONF_USE_ADDRESS, CONF_WIFI, \
SOURCE_FILE_EXTENSIONS
from esphome.const import CONF_ARDUINO_VERSION, SOURCE_FILE_EXTENSIONS, \
CONF_COMMENT, CONF_ESPHOME, CONF_USE_ADDRESS, CONF_WIFI
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
@ -539,6 +539,13 @@ class EsphomeCore(object):
return None
@property
def comment(self): # type: () -> str
if CONF_COMMENT in self.config[CONF_ESPHOME]:
return self.config[CONF_ESPHOME][CONF_COMMENT]
return None
def _add_active_coroutine(self, instance_id, obj):
self.active_coroutines[instance_id] = obj

View file

@ -7,7 +7,7 @@ import esphome.config_validation as cv
from esphome import automation, pins
from esphome.const import ARDUINO_VERSION_ESP32_DEV, ARDUINO_VERSION_ESP8266_DEV, \
CONF_ARDUINO_VERSION, CONF_BOARD, CONF_BOARD_FLASH_MODE, CONF_BUILD_PATH, \
CONF_ESPHOME, CONF_INCLUDES, CONF_LIBRARIES, \
CONF_COMMENT, CONF_ESPHOME, CONF_INCLUDES, CONF_LIBRARIES, \
CONF_NAME, CONF_ON_BOOT, CONF_ON_LOOP, CONF_ON_SHUTDOWN, CONF_PLATFORM, \
CONF_PLATFORMIO_OPTIONS, CONF_PRIORITY, CONF_TRIGGER_ID, \
CONF_ESP8266_RESTORE_FROM_FLASH, ARDUINO_VERSION_ESP8266_2_3_0, \
@ -113,6 +113,7 @@ CONFIG_SCHEMA = cv.Schema({
cv.Required(CONF_NAME): cv.valid_name,
cv.Required(CONF_PLATFORM): cv.one_of('ESP8266', 'ESP32', upper=True),
cv.Required(CONF_BOARD): validate_board,
cv.Optional(CONF_COMMENT): cv.string,
cv.Optional(CONF_ARDUINO_VERSION, default='recommended'): validate_arduino_version,
cv.Optional(CONF_BUILD_PATH, default=default_build_path): cv.string,
cv.Optional(CONF_PLATFORMIO_OPTIONS, default={}): cv.Schema({

View file

@ -401,6 +401,12 @@ class DashboardEntry(object):
return self.filename[:-len('.yaml')]
return self.storage.name
@property
def comment(self):
if self.storage is None:
return None
return self.storage.comment
@property
def esp_platform(self):
if self.storage is None:

View file

@ -247,3 +247,10 @@ ul.stepper:not(.horizontal) .step.active::before, ul.stepper:not(.horizontal) .s
padding: 10px 15px;
margin-top: 15px;
}
.card-comment {
margin-bottom: 8px;
font-size: 14px;
color: #444;
font-style: italic;
}

View file

@ -79,6 +79,11 @@
{% end %}
<i class="material-icons right dropdown-trigger" data-target="dropdown-{{ i }}">more_vert</i>
</span>
{% if entry.comment %}
<div class="card-comment">
{{ escape(entry.comment) }}
</div>
{% end %}
<p>
<span class="status-indicator unknown" data-node="{{ entry.filename }}">
<span class="status-indicator-icon"></span>

View file

@ -35,7 +35,7 @@ def trash_storage_path(base_path): # type: (str) -> str
# pylint: disable=too-many-instance-attributes
class StorageJSON(object):
def __init__(self, storage_version, name, esphome_version,
def __init__(self, storage_version, name, comment, esphome_version,
src_version, arduino_version, address, esp_platform, board, build_path,
firmware_bin_path, loaded_integrations):
# Version of the storage JSON schema
@ -43,6 +43,8 @@ class StorageJSON(object):
self.storage_version = storage_version # type: int
# The name of the node
self.name = name # type: str
# The comment of the node
self.comment = comment # type: str
# The esphome version this was compiled with
self.esphome_version = esphome_version # type: str
# The version of the file in src/main.cpp - Used to migrate the file
@ -69,6 +71,7 @@ class StorageJSON(object):
return {
'storage_version': self.storage_version,
'name': self.name,
'comment': self.comment,
'esphome_version': self.esphome_version,
'src_version': self.src_version,
'arduino_version': self.arduino_version,
@ -93,6 +96,7 @@ class StorageJSON(object):
return StorageJSON(
storage_version=1,
name=esph.name,
comment=esph.comment,
esphome_version=const.__version__,
src_version=1,
arduino_version=esph.arduino_version,
@ -110,6 +114,7 @@ class StorageJSON(object):
return StorageJSON(
storage_version=1,
name=name,
comment=None,
esphome_version=const.__version__,
src_version=1,
arduino_version=None,
@ -128,6 +133,7 @@ class StorageJSON(object):
storage = json.loads(text, encoding='utf-8')
storage_version = storage['storage_version']
name = storage.get('name')
comment = storage.get('comment')
esphome_version = storage.get('esphome_version', storage.get('esphomeyaml_version'))
src_version = storage.get('src_version')
arduino_version = storage.get('arduino_version')
@ -137,7 +143,7 @@ class StorageJSON(object):
build_path = storage.get('build_path')
firmware_bin_path = storage.get('firmware_bin_path')
loaded_integrations = storage.get('loaded_integrations', [])
return StorageJSON(storage_version, name, esphome_version,
return StorageJSON(storage_version, name, comment, esphome_version,
src_version, arduino_version, address, esp_platform, board, build_path,
firmware_bin_path, loaded_integrations)

View file

@ -1,5 +1,6 @@
esphome:
name: $devicename
comment: $devicecomment
platform: ESP8266
board: d1_mini
build_path: build/test3
@ -12,6 +13,7 @@ esphome:
substitutions:
devicename: test3
devicecomment: test3 device
api:
port: 8000