From 6bf9ea5699a63ec4b2ec3cd69e73deab9086bdd3 Mon Sep 17 00:00:00 2001 From: Ian Richardson Date: Fri, 22 Mar 2019 13:55:52 -0500 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20entity-button=20show/hide=20icon/na?= =?UTF-8?q?me=20(#2936)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../lovelace/cards/hui-entity-button-card.ts | 38 +++++++++++++------ .../hui-entity-button-card-editor.ts | 31 ++++++++++++++- 2 files changed, 56 insertions(+), 13 deletions(-) diff --git a/src/panels/lovelace/cards/hui-entity-button-card.ts b/src/panels/lovelace/cards/hui-entity-button-card.ts index cc0b7fdfbe..25b79be422 100644 --- a/src/panels/lovelace/cards/hui-entity-button-card.ts +++ b/src/panels/lovelace/cards/hui-entity-button-card.ts @@ -31,7 +31,9 @@ import { DOMAINS_TOGGLE } from "../../../common/const"; export interface Config extends LovelaceCardConfig { entity: string; name?: string; + snow_name?: boolean; icon?: string; + show_icon?: boolean; theme?: string; tap_action?: ActionConfig; hold_action?: ActionConfig; @@ -48,6 +50,8 @@ class HuiEntityButtonCard extends LitElement implements LovelaceCard { return { tap_action: { action: "toggle" }, hold_action: { action: "more-info" }, + show_icon: true, + show_name: true, }; } @@ -68,6 +72,8 @@ class HuiEntityButtonCard extends LitElement implements LovelaceCard { theme: "default", hold_action: { action: "more-info" }, ...config, + show_icon: true, + show_name: true, }; if (DOMAINS_TOGGLE.has(computeDomain(config.entity))) { @@ -126,18 +132,26 @@ class HuiEntityButtonCard extends LitElement implements LovelaceCard { @ha-hold="${this._handleHold}" .longPress="${longPress()}" > - - - ${this._config.name || computeStateName(stateObj)} - + ${this._config.show_icon + ? html` + + ` + : ""} + ${this._config.show_name + ? html` + + ${this._config.name || computeStateName(stateObj)} + + ` + : ""} `; diff --git a/src/panels/lovelace/editor/config-elements/hui-entity-button-card-editor.ts b/src/panels/lovelace/editor/config-elements/hui-entity-button-card-editor.ts index 7318a1f270..93ecd9498a 100644 --- a/src/panels/lovelace/editor/config-elements/hui-entity-button-card-editor.ts +++ b/src/panels/lovelace/editor/config-elements/hui-entity-button-card-editor.ts @@ -28,7 +28,9 @@ const cardConfigStruct = struct({ type: "string", entity: "string?", name: "string?", + show_name: "boolean?", icon: "string?", + show_icon: "boolean?", tap_action: struct.optional(actionConfigStruct), hold_action: struct.optional(actionConfigStruct), theme: "string?", @@ -54,10 +56,18 @@ export class HuiEntityButtonCardEditor extends LitElement return this._config!.name || ""; } + get _show_name(): boolean { + return this._config!.show_name || true; + } + get _icon(): string { return this._config!.icon || ""; } + get _show_icon(): boolean { + return this._config!.show_icon || true; + } + get _tap_action(): ActionConfig { return this._config!.tap_action || { action: "more-info" }; } @@ -101,6 +111,20 @@ export class HuiEntityButtonCardEditor extends LitElement @value-changed="${this._valueChanged}" > +
+ Show Name? + Show Icon? +