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 {