From ad34f98e6d7da021baad8ef506c0a274fb386eb6 Mon Sep 17 00:00:00 2001 From: Bram Kragten Date: Wed, 16 Sep 2020 21:38:08 +0200 Subject: [PATCH] Add default actions to button row (#7026) --- .../lovelace/special-rows/hui-button-row.ts | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/panels/lovelace/special-rows/hui-button-row.ts b/src/panels/lovelace/special-rows/hui-button-row.ts index 5e55e125e5..1a74621dd9 100644 --- a/src/panels/lovelace/special-rows/hui-button-row.ts +++ b/src/panels/lovelace/special-rows/hui-button-row.ts @@ -4,10 +4,12 @@ import { CSSResult, customElement, html, - LitElement, internalProperty, + LitElement, TemplateResult, } from "lit-element"; +import { DOMAINS_TOGGLE } from "../../../common/const"; +import { computeDomain } from "../../../common/entity/compute_domain"; import "../../../components/ha-icon"; import { ActionHandlerEvent } from "../../../data/lovelace"; import { HomeAssistant } from "../../../types"; @@ -31,11 +33,16 @@ export class HuiButtonRow extends LitElement implements LovelaceRow { throw new Error("Error in card configuration. No name specified."); } - if (!config.tap_action) { - throw new Error("Error in card configuration. No action specified."); - } - - this._config = config; + this._config = { + tap_action: { + action: + config.entity && DOMAINS_TOGGLE.has(computeDomain(config.entity)) + ? "toggle" + : "more-info", + }, + hold_action: { action: "more-info" }, + ...config, + }; } protected render(): TemplateResult {