From bfef3a96c82dfb00ad959d7e26bbdc8fc7602b8f Mon Sep 17 00:00:00 2001 From: Bram Kragten Date: Wed, 5 Dec 2018 16:42:22 +0100 Subject: [PATCH] Catch errors in preview and fix entity picker (#2183) * Catch errors in preview and fix entity picker * Replace add button with entity-picker --- .../lovelace/components/hui-entity-editor.ts | 19 +++++++++++++------ .../lovelace/editor/hui-card-preview.ts | 6 +++++- src/panels/lovelace/editor/hui-edit-view.ts | 1 + 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/src/panels/lovelace/components/hui-entity-editor.ts b/src/panels/lovelace/components/hui-entity-editor.ts index 7c9212e3a1..d612d60bb7 100644 --- a/src/panels/lovelace/components/hui-entity-editor.ts +++ b/src/panels/lovelace/components/hui-entity-editor.ts @@ -42,16 +42,23 @@ export class HuiEntityEditor extends LitElement { `; }) } + - Add Entity `; } - private _addEntity() { - const newConfigEntities = this.entities!.concat({ entity: "" }); - + private _addEntity(ev: Event): void { + const target = ev.target! as EditorTarget; + if (target.value === "") { + return; + } + const newConfigEntities = this.entities!.concat({ + entity: target.value as string, + }); + target.value = ""; fireEvent(this, "entities-changed", { entities: newConfigEntities }); } diff --git a/src/panels/lovelace/editor/hui-card-preview.ts b/src/panels/lovelace/editor/hui-card-preview.ts index 4abeeb21a6..08933f84f5 100644 --- a/src/panels/lovelace/editor/hui-card-preview.ts +++ b/src/panels/lovelace/editor/hui-card-preview.ts @@ -41,7 +41,11 @@ export class HuiCardPreview extends HTMLElement { const tag = getCardElementTag(configValue.type); if (tag.toUpperCase() === this._element.tagName) { - this._element.setConfig(configValue); + try { + this._element.setConfig(configValue); + } catch (err) { + this._createCard(createErrorCardConfig(err.message, configValue)); + } } else { this._createCard(configValue); } diff --git a/src/panels/lovelace/editor/hui-edit-view.ts b/src/panels/lovelace/editor/hui-edit-view.ts index 85502fe22c..273df58052 100644 --- a/src/panels/lovelace/editor/hui-edit-view.ts +++ b/src/panels/lovelace/editor/hui-edit-view.ts @@ -160,6 +160,7 @@ export class HuiEditView extends hassLocalizeLitMixin(LitElement) { paper-tabs { --paper-tabs-selection-bar-color: var(--primary-color); text-transform: uppercase; + border-bottom: 1px solid rgba(0, 0, 0, 0.1); } paper-button paper-spinner { width: 14px;