mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-28 11:46:42 +00:00
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:
parent
1e291e80b7
commit
2aec877310
@ -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 {
|
||||
|
Loading…
x
Reference in New Issue
Block a user