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,
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 {