Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 34 additions & 15 deletions src/panels/lovelace/cards/hui-entity-button-card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ import { handleClick } from "../common/handle-click";
export interface Config extends LovelaceCardConfig {
entity: string;
name?: string;
show_name?: boolean;
icon?: string;
show_icon?: boolean;
theme?: string;
tap_action?: ActionConfig;
hold_action?: ActionConfig;
Expand All @@ -44,8 +46,10 @@ 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" },
show_icon: true,
show_name: true,
};
}

Expand All @@ -62,7 +66,14 @@ class HuiEntityButtonCard extends LitElement implements LovelaceCard {
throw new Error("Invalid Entity");
}

this._config = { theme: "default", ...config };
this._config = {
theme: "default",
tap_action: { action: "toggle" },
hold_action: { action: "more-info" },
show_icon: true,
show_name: true,
...config,
};
}

protected shouldUpdate(changedProps: PropertyValues): boolean {
Expand Down Expand Up @@ -104,18 +115,26 @@ class HuiEntityButtonCard extends LitElement implements LovelaceCard {
@ha-hold="${this._handleHold}"
.longPress="${longPress()}"
>
<ha-icon
data-domain="${computeStateDomain(stateObj)}"
data-state="${stateObj.state}"
.icon="${this._config.icon || stateIcon(stateObj)}"
style="${styleMap({
filter: this._computeBrightness(stateObj),
color: this._computeColor(stateObj),
})}"
></ha-icon>
<span>
${this._config.name || computeStateName(stateObj)}
</span>
${this._config.show_icon
? html`
<ha-icon
data-domain="${computeStateDomain(stateObj)}"
data-state="${stateObj.state}"
.icon="${this._config.icon || stateIcon(stateObj)}"
style="${styleMap({
filter: this._computeBrightness(stateObj),
color: this._computeColor(stateObj),
})}"
></ha-icon>
`
: ""}
${this._config.show_name
? html`
<span>
${this._config.name || computeStateName(stateObj)}
</span>
`
: ""}
<mwc-ripple></mwc-ripple>
</ha-card>
`;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ const cardConfigStruct = struct({
type: "string",
entity: "string?",
name: "string?",
show_name: "boolean?",
icon: "string?",
show_icon: "boolean?",
tap_action: struct.optional(actionConfigStruct),
hold_action: struct.optional(actionConfigStruct),
theme: "string?",
Expand All @@ -54,10 +56,18 @@ export class HuiEntityButtonCardEditor extends LitElement
return this._config!.name || "";
}

get _show_name(): boolean {
return this._config!.show_name || true;
}

get _icon(): string {
return this._config!.icon || "";
}

get _show_icon(): boolean {
return this._config!.show_icon || true;
}

get _tap_action(): ActionConfig {
return this._config!.tap_action || { action: "more-info" };
}
Expand Down Expand Up @@ -101,6 +111,20 @@ export class HuiEntityButtonCardEditor extends LitElement
@value-changed="${this._valueChanged}"
></paper-input>
</div>
<div class="side-by-side">
<paper-toggle-button
?checked="${this._config!.show_name !== false}"
.configValue="${"show_name"}"
@change="${this._valueChanged}"
>Show Name?</paper-toggle-button
>
<paper-toggle-button
?checked="${this._config!.show_icon !== false}"
.configValue="${"show_icon"}"
@change="${this._valueChanged}"
>Show Icon?</paper-toggle-button
>
</div>
<hui-theme-select-editor
.hass="${this.hass}"
.value="${this._theme}"
Expand Down Expand Up @@ -147,7 +171,12 @@ export class HuiEntityButtonCardEditor extends LitElement
} else {
this._config = {
...this._config,
[target.configValue!]: target.value ? target.value : target.config,
[target.configValue!]:
target.checked !== undefined
? target.checked
: target.value
? target.value
: target.config,
};
}
}
Expand Down