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
This commit is contained in:
Ian Richardson 2019-03-15 11:24:10 -05:00 committed by Paulus Schoutsen
parent 1e291e80b7
commit 2aec877310

View File

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