Add default actions to button row (#7026)

This commit is contained in:
Bram Kragten 2020-09-16 21:38:08 +02:00 committed by GitHub
parent a8a1563586
commit ad34f98e6d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -4,10 +4,12 @@ import {
CSSResult, CSSResult,
customElement, customElement,
html, html,
LitElement,
internalProperty, internalProperty,
LitElement,
TemplateResult, TemplateResult,
} from "lit-element"; } from "lit-element";
import { DOMAINS_TOGGLE } from "../../../common/const";
import { computeDomain } from "../../../common/entity/compute_domain";
import "../../../components/ha-icon"; import "../../../components/ha-icon";
import { ActionHandlerEvent } from "../../../data/lovelace"; import { ActionHandlerEvent } from "../../../data/lovelace";
import { HomeAssistant } from "../../../types"; 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."); throw new Error("Error in card configuration. No name specified.");
} }
if (!config.tap_action) { this._config = {
throw new Error("Error in card configuration. No action specified."); tap_action: {
} action:
config.entity && DOMAINS_TOGGLE.has(computeDomain(config.entity))
this._config = config; ? "toggle"
: "more-info",
},
hold_action: { action: "more-info" },
...config,
};
} }
protected render(): TemplateResult { protected render(): TemplateResult {