diff --git a/src/panels/lovelace/cards/hui-entity-button-card.ts b/src/panels/lovelace/cards/hui-entity-button-card.ts index 16455b264235..0008a1fe17f2 100644 --- a/src/panels/lovelace/cards/hui-entity-button-card.ts +++ b/src/panels/lovelace/cards/hui-entity-button-card.ts @@ -29,7 +29,9 @@ import { handleClick } from "../common/handle-click"; export interface Config extends LovelaceCardConfig { entity: string; name?: string; + show_name?: boolean; icon?: string; + show_icon?: boolean; theme?: string; tap_action?: ActionConfig; hold_action?: ActionConfig; @@ -44,8 +46,10 @@ class HuiEntityButtonCard extends LitElement implements LovelaceCard { public static getStubConfig(): object { return { - tap_action: { action: "more-info" }, - hold_action: { action: "none" }, + tap_action: { action: "toggle" }, + hold_action: { action: "more-info" }, + show_icon: true, + show_name: true, }; } @@ -62,7 +66,14 @@ class HuiEntityButtonCard extends LitElement implements LovelaceCard { throw new Error("Invalid Entity"); } - this._config = { theme: "default", ...config }; + this._config = { + theme: "default", + tap_action: { action: "toggle" }, + hold_action: { action: "more-info" }, + show_icon: true, + show_name: true, + ...config, + }; } protected shouldUpdate(changedProps: PropertyValues): boolean { @@ -104,18 +115,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 7318a1f27020..93ecd9498a06 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? +