From be91cfb261f67f4054d7875c2e49342ca112c7d7 Mon Sep 17 00:00:00 2001 From: Nikolay Vasilchuk Date: Mon, 14 Oct 2019 12:27:07 +0300 Subject: [PATCH] Device description in dashboard (#707) * Description * Review fixes * Test * Label * Description renamed to comment --- esphome/const.py | 1 + esphome/core.py | 11 +++++++++-- esphome/core_config.py | 3 ++- esphome/dashboard/dashboard.py | 6 ++++++ esphome/dashboard/static/esphome.css | 7 +++++++ esphome/dashboard/templates/index.html | 5 +++++ esphome/storage_json.py | 10 ++++++++-- tests/test3.yaml | 2 ++ 8 files changed, 40 insertions(+), 5 deletions(-) diff --git a/esphome/const.py b/esphome/const.py index 463c82bbc6..c169bd1393 100644 --- a/esphome/const.py +++ b/esphome/const.py @@ -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' diff --git a/esphome/core.py b/esphome/core.py index 814b92802e..b1fd866c76 100644 --- a/esphome/core.py +++ b/esphome/core.py @@ -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 diff --git a/esphome/core_config.py b/esphome/core_config.py index 573094db5c..7654544379 100644 --- a/esphome/core_config.py +++ b/esphome/core_config.py @@ -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({ diff --git a/esphome/dashboard/dashboard.py b/esphome/dashboard/dashboard.py index cc89fbd881..0927fe2dfe 100644 --- a/esphome/dashboard/dashboard.py +++ b/esphome/dashboard/dashboard.py @@ -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: diff --git a/esphome/dashboard/static/esphome.css b/esphome/dashboard/static/esphome.css index 183cfbed39..fddfb5cf86 100644 --- a/esphome/dashboard/static/esphome.css +++ b/esphome/dashboard/static/esphome.css @@ -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; +} diff --git a/esphome/dashboard/templates/index.html b/esphome/dashboard/templates/index.html index 1539632e78..2d713c8ef3 100644 --- a/esphome/dashboard/templates/index.html +++ b/esphome/dashboard/templates/index.html @@ -79,6 +79,11 @@ {% end %} more_vert + {% if entry.comment %} +
+ {{ escape(entry.comment) }} +
+ {% end %}

diff --git a/esphome/storage_json.py b/esphome/storage_json.py index b04f056f11..a7431d0c56 100644 --- a/esphome/storage_json.py +++ b/esphome/storage_json.py @@ -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) diff --git a/tests/test3.yaml b/tests/test3.yaml index 797153bb12..458021d0d3 100644 --- a/tests/test3.yaml +++ b/tests/test3.yaml @@ -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