add action_name option for scene/script rows (#4571)

*  add action_name option for scene/script rows

* address review comments
This commit is contained in:
Ian Richardson 2020-01-24 16:01:01 -06:00 committed by Bram Kragten
parent ef6e468a7f
commit 1f38d13b3b
5 changed files with 20 additions and 10 deletions

View File

@ -14,7 +14,7 @@ import "../../../components/entity/ha-entity-toggle";
import "../components/hui-warning";
import { HomeAssistant } from "../../../types";
import { LovelaceRow, EntityConfig } from "./types";
import { LovelaceRow, ActionRowConfig } from "./types";
import { hasConfigOrEntityChanged } from "../common/has-changed";
import { activateScene } from "../../../data/scene";
@ -22,9 +22,9 @@ import { activateScene } from "../../../data/scene";
class HuiSceneEntityRow extends LitElement implements LovelaceRow {
@property() public hass!: HomeAssistant;
@property() private _config?: EntityConfig;
@property() private _config?: ActionRowConfig;
public setConfig(config: EntityConfig): void {
public setConfig(config: ActionRowConfig): void {
if (!config) {
throw new Error("Configuration error");
}
@ -65,7 +65,8 @@ class HuiSceneEntityRow extends LitElement implements LovelaceRow {
`
: html`
<mwc-button @click="${this._callService}">
${this.hass!.localize("ui.card.scene.activate")}
${this._config.action_name ||
this.hass!.localize("ui.card.scene.activate")}
</mwc-button>
`}
</hui-generic-entity-row>

View File

@ -14,16 +14,16 @@ import "../../../components/entity/ha-entity-toggle";
import "../components/hui-warning";
import { HomeAssistant } from "../../../types";
import { LovelaceRow, EntityConfig } from "./types";
import { LovelaceRow, ActionRowConfig } from "./types";
import { hasConfigOrEntityChanged } from "../common/has-changed";
@customElement("hui-script-entity-row")
class HuiScriptEntityRow extends LitElement implements LovelaceRow {
public hass?: HomeAssistant;
@property() private _config?: EntityConfig;
@property() private _config?: ActionRowConfig;
public setConfig(config: EntityConfig): void {
public setConfig(config: ActionRowConfig): void {
if (!config) {
throw new Error("Configuration error");
}
@ -64,7 +64,8 @@ class HuiScriptEntityRow extends LitElement implements LovelaceRow {
`
: html`
<mwc-button @click="${this._callService}">
${this.hass!.localize("ui.card.script.execute")}
${this._config.action_name ||
this.hass!.localize("ui.card.script.execute")}
</mwc-button>
`}
</hui-generic-entity-row>

View File

@ -8,6 +8,9 @@ export interface EntityConfig {
icon?: string;
image?: string;
}
export interface ActionRowConfig extends EntityConfig {
action_name?: string;
}
export interface EntityFilterEntityConfig extends EntityConfig {
state_filter?: Array<{ key: string } | string>;
}

View File

@ -26,7 +26,7 @@ class HuiCallServiceRow extends LitElement implements LovelaceRow {
throw new Error("Error in card configuration.");
}
this._config = { icon: "hass:remote", action_name: "Run", ...config };
this._config = { icon: "hass:remote", ...config };
}
protected render(): TemplateResult | void {
@ -39,7 +39,9 @@ class HuiCallServiceRow extends LitElement implements LovelaceRow {
<div class="flex">
<div>${this._config.name}</div>
<mwc-button @click="${this._callService}"
>${this._config.action_name}</mwc-button
>${this._config.action_name
? this._config.action_name
: this.hass!.localize("ui.card.service.run")}</mwc-button
>
</div>
`;

View File

@ -460,6 +460,9 @@
"script": {
"execute": "Execute"
},
"service": {
"run": "Run"
},
"timer": {
"actions": {
"start": "start",