From 599dd81e3c8184b744faf13fdaaa0d3b426206d0 Mon Sep 17 00:00:00 2001 From: Philip Allgaier Date: Thu, 21 Jan 2021 20:03:53 +0100 Subject: [PATCH] Make "button row" name optional to be consistent with "button card" and "buttons row" (#8189) --- .../lovelace/special-rows/hui-button-row.ts | 21 +++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/src/panels/lovelace/special-rows/hui-button-row.ts b/src/panels/lovelace/special-rows/hui-button-row.ts index 91e905c846..8622503329 100644 --- a/src/panels/lovelace/special-rows/hui-button-row.ts +++ b/src/panels/lovelace/special-rows/hui-button-row.ts @@ -10,6 +10,8 @@ import { } from "lit-element"; import { DOMAINS_TOGGLE } from "../../../common/const"; import { computeDomain } from "../../../common/entity/compute_domain"; +import { computeStateName } from "../../../common/entity/compute_state_name"; +import { stateIcon } from "../../../common/entity/state_icon"; import "../../../components/ha-icon"; import { ActionHandlerEvent } from "../../../data/lovelace"; import { HomeAssistant } from "../../../types"; @@ -29,8 +31,8 @@ export class HuiButtonRow extends LitElement implements LovelaceRow { throw new Error("Invalid configuration"); } - if (!config.name) { - throw new Error("No name specified"); + if (!config.name && !config.entity) { + throw new Error("No name and no entity specified"); } this._config = { @@ -50,10 +52,21 @@ export class HuiButtonRow extends LitElement implements LovelaceRow { return html``; } + const stateObj = + this._config.entity && this.hass + ? this.hass.states[this._config.entity] + : undefined; + return html` - + +
-
${this._config.name}
+
+ ${this._config.name || (stateObj ? computeStateName(stateObj) : "")} +