From f7d5cb138d98018b8910862f4c33e667c41d8e78 Mon Sep 17 00:00:00 2001 From: Bram Kragten Date: Wed, 5 Dec 2018 15:08:36 +0100 Subject: [PATCH 1/2] Catch errors in preview and fix entity picker --- src/panels/lovelace/components/hui-entity-editor.ts | 4 +--- src/panels/lovelace/editor/hui-card-preview.ts | 6 +++++- src/panels/lovelace/editor/hui-edit-view.ts | 1 + 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/panels/lovelace/components/hui-entity-editor.ts b/src/panels/lovelace/components/hui-entity-editor.ts index 7c9212e3a1b4..d05b79c631b5 100644 --- a/src/panels/lovelace/components/hui-entity-editor.ts +++ b/src/panels/lovelace/components/hui-entity-editor.ts @@ -50,9 +50,7 @@ export class HuiEntityEditor extends LitElement { } private _addEntity() { - const newConfigEntities = this.entities!.concat({ entity: "" }); - - fireEvent(this, "entities-changed", { entities: newConfigEntities }); + this.entities = this.entities!.concat({ entity: "" }); } private _valueChanged(ev: Event): void { diff --git a/src/panels/lovelace/editor/hui-card-preview.ts b/src/panels/lovelace/editor/hui-card-preview.ts index 4abeeb21a650..08933f84f590 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 85502fe22cb6..273df5805201 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; From ebe7379c5a9231ea756873a9e4144a7e162c71d4 Mon Sep 17 00:00:00 2001 From: Bram Kragten Date: Wed, 5 Dec 2018 15:26:48 +0100 Subject: [PATCH 2/2] Replace add button with entity-picker --- .../lovelace/components/hui-entity-editor.ts | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/panels/lovelace/components/hui-entity-editor.ts b/src/panels/lovelace/components/hui-entity-editor.ts index d05b79c631b5..d612d60bb7a4 100644 --- a/src/panels/lovelace/components/hui-entity-editor.ts +++ b/src/panels/lovelace/components/hui-entity-editor.ts @@ -42,15 +42,24 @@ export class HuiEntityEditor extends LitElement { `; }) } + - Add Entity `; } - private _addEntity() { - this.entities = 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 }); } private _valueChanged(ev: Event): void {