From 2aec877310e894d437d19a8f94ee0e00bd01a5a2 Mon Sep 17 00:00:00 2001 From: Ian Richardson Date: Fri, 15 Mar 2019 11:24:10 -0500 Subject: [PATCH] Set entity-button defaults (#2897) * Set entity-button defaults tap_action: toggle hold_action: more-info * Address review comment, but unsure about lint * Address review comments --- .../lovelace/cards/hui-entity-button-card.ts | 28 +++++++++++++++++-- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/src/panels/lovelace/cards/hui-entity-button-card.ts b/src/panels/lovelace/cards/hui-entity-button-card.ts index 16455b2642..cc0b7fdfbe 100644 --- a/src/panels/lovelace/cards/hui-entity-button-card.ts +++ b/src/panels/lovelace/cards/hui-entity-button-card.ts @@ -20,11 +20,13 @@ import stateIcon from "../../../common/entity/state_icon"; import computeStateDomain from "../../../common/entity/compute_state_domain"; import computeStateName from "../../../common/entity/compute_state_name"; import applyThemesOnElement from "../../../common/dom/apply_themes_on_element"; +import computeDomain from "../../../common/entity/compute_domain"; import { HomeAssistant, LightEntity } from "../../../types"; import { LovelaceCard, LovelaceCardEditor } from "../types"; import { LovelaceCardConfig, ActionConfig } from "../../../data/lovelace"; import { longPress } from "../common/directives/long-press-directive"; import { handleClick } from "../common/handle-click"; +import { DOMAINS_TOGGLE } from "../../../common/const"; export interface Config extends LovelaceCardConfig { entity: string; @@ -44,8 +46,8 @@ 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" }, }; } @@ -62,7 +64,27 @@ class HuiEntityButtonCard extends LitElement implements LovelaceCard { throw new Error("Invalid Entity"); } - this._config = { theme: "default", ...config }; + this._config = { + theme: "default", + hold_action: { action: "more-info" }, + ...config, + }; + + if (DOMAINS_TOGGLE.has(computeDomain(config.entity))) { + this._config = { + tap_action: { + action: "toggle", + }, + ...this._config, + }; + } else { + this._config = { + tap_action: { + action: "more-info", + }, + ...this._config, + }; + } } protected shouldUpdate(changedProps: PropertyValues): boolean {