Compare commits

..

3 Commits

Author SHA1 Message Date
Zack Arnett
42f720496b this kind of works :) 2020-09-14 15:06:34 -05:00
Zack Arnett
c64d88d8b5 fix action default 2020-09-14 14:43:16 -05:00
Bram Kragten
3030b8d476 Fix input number helper (#6988) 2020-09-14 17:00:56 +02:00
3 changed files with 194 additions and 284 deletions

View File

@@ -6,9 +6,9 @@ import {
CSSResult,
customElement,
html,
internalProperty,
LitElement,
property,
internalProperty,
TemplateResult,
} from "lit-element";
import { fireEvent } from "../../../../common/dom/fire_event";
@@ -48,12 +48,12 @@ class HaInputNumberForm extends LitElement {
this._max = item.max ?? 100;
this._min = item.min ?? 0;
this._mode = item.mode || "slider";
this._step = item.step || 1;
this._step = item.step ?? 1;
this._unit_of_measurement = item.unit_of_measurement;
} else {
this._item = {
min: 0,
max: 0,
max: 100,
};
this._name = "";
this._icon = "";
@@ -176,8 +176,10 @@ class HaInputNumberForm extends LitElement {
return;
}
ev.stopPropagation();
const configValue = (ev.target as any).configValue;
const value = ev.detail.value;
const target = ev.target as any;
const configValue = target.configValue;
const value =
target.type === "number" ? Number(ev.detail.value) : ev.detail.value;
if (this[`_${configValue}`] === value) {
return;
}

View File

@@ -1,10 +1,7 @@
import "@polymer/app-layout/app-header/app-header";
import "@polymer/paper-dropdown-menu/paper-dropdown-menu-light";
import "@polymer/app-layout/app-toolbar/app-toolbar";
import { ActionDetail } from "@material/mwc-list/mwc-list-foundation";
import "@material/mwc-list/mwc-list-item";
import "../../../components/ha-icon-button";
import "../../../components/ha-button-menu";
import {
css,
CSSResult,
@@ -41,7 +38,7 @@ import { HaDeviceAction } from "../automation/action/types/ha-automation-action-
import "../ha-config-section";
import { configSections } from "../ha-panel-config";
import "../../../components/ha-svg-icon";
import { mdiContentSave, mdiDotsVertical } from "@mdi/js";
import { mdiContentSave } from "@mdi/js";
import { PaperListboxElement } from "@polymer/paper-listbox";
import { slugify } from "../../../common/string/slugify";
@@ -66,8 +63,6 @@ export class HaScriptEditor extends LitElement {
@internalProperty() private _errors?: string;
@internalProperty() private _yamlMode = false;
protected render(): TemplateResult {
return html`
<hass-tabs-subpage
@@ -77,46 +72,19 @@ export class HaScriptEditor extends LitElement {
.backCallback=${() => this._backTapped()}
.tabs=${configSections.automation}
>
<ha-button-menu
corner="BOTTOM_START"
slot="toolbar-icon"
@action=${this._handleAction}
>
<mwc-icon-button
slot="trigger"
.title=${this.hass.localize("ui.common.menu")}
.label=${this.hass.localize("ui.common.overflow_menu")}
><ha-svg-icon path=${mdiDotsVertical}></ha-svg-icon>
</mwc-icon-button>
<mwc-list-item
aria-label=${this._yamlMode
? this.hass.localize("ui.panel.config.automation.editor.edit_ui")
: this.hass.localize(
"ui.panel.config.automation.editor.edit_yaml"
)}
>
${this._yamlMode
? this.hass.localize("ui.panel.config.automation.editor.edit_ui")
: this.hass.localize(
"ui.panel.config.automation.editor.edit_yaml"
)}
</mwc-list-item>
${!this.scriptEntityId
? ""
: html`
<mwc-list-item
<ha-icon-button
class="warning"
aria-label=${this.hass.localize(
slot="toolbar-icon"
title="${this.hass.localize(
"ui.panel.config.script.editor.delete_script"
)}
>
${this.hass.localize(
"ui.panel.config.script.editor.delete_script"
)}
</mwc-list-item>
)}"
icon="hass:delete"
@click=${this._deleteConfirm}
></ha-icon-button>
`}
</ha-button-menu>
${this.narrow
? html` <span slot="header">${this._config?.alias}</span> `
: ""}
@@ -130,50 +98,10 @@ export class HaScriptEditor extends LitElement {
})}"
>
${this._config
? this._yamlMode
? html`
<ha-config-section .isWide=${false}>
${!this.narrow
? html`
<span slot="header">${this._config.alias}</span>
`
: ""}
<ha-card>
<div class="card-content">
<ha-yaml-editor
.defaultValue=${this._config}
@value-changed=${this._onYamlChange}
></ha-yaml-editor>
</div>
${this.scriptEntityId
? html`
<div
class="card-actions layout horizontal justified center"
>
<span></span>
<mwc-button
@click=${this._runScript}
title="${this.hass.localize(
"ui.panel.config.script.picker.activate_script"
)}"
?disabled=${this._dirty}
>
${this.hass.localize(
"ui.card.script.execute"
)}
</mwc-button>
</div>
`
: ``}
</ha-card>
</ha-config-section>
`
: html`
<ha-config-section .isWide=${this.isWide}>
${!this.narrow
? html`
<span slot="header">${this._config.alias}</span>
`
? html` <span slot="header">${this._config.alias}</span> `
: ""}
<span slot="introduction">
${this.hass.localize(
@@ -269,9 +197,7 @@ export class HaScriptEditor extends LitElement {
</div>
${this.scriptEntityId
? html`
<div
class="card-actions layout horizontal justified center"
>
<div class="card-actions layout horizontal justified center">
<span></span>
<mwc-button
@click=${this._runScript}
@@ -280,9 +206,7 @@ export class HaScriptEditor extends LitElement {
)}"
?disabled=${this._dirty}
>
${this.hass.localize(
"ui.card.script.execute"
)}
${this.hass.localize("ui.card.script.execute")}
</mwc-button>
</div>
`
@@ -395,7 +319,7 @@ export class HaScriptEditor extends LitElement {
}
}
private async _runScript(ev: Event) {
private async _runScript(ev) {
ev.stopPropagation();
await triggerScript(this.hass, this.scriptEntityId);
showToast(this, {
@@ -407,21 +331,6 @@ export class HaScriptEditor extends LitElement {
});
}
private _handleAction(ev: CustomEvent<ActionDetail>) {
switch (ev.detail.index) {
case 0:
this._switchYamlMode();
break;
case 1:
this._deleteConfirm();
break;
}
}
private _switchYamlMode() {
this._yamlMode = !this._yamlMode;
}
private _modeChanged(ev: CustomEvent) {
const mode = ((ev.target as PaperListboxElement)?.selectedItem as any)
?.mode;
@@ -461,15 +370,6 @@ export class HaScriptEditor extends LitElement {
}
}
private _onYamlChange(ev: CustomEvent) {
ev.stopPropagation();
if (!ev.detail.isValid) {
return;
}
this._config = ev.detail.value;
this._dirty = true;
}
private _valueChanged(ev: CustomEvent) {
ev.stopPropagation();
const target = ev.target as any;

View File

@@ -23,13 +23,13 @@ import { EditorTarget } from "../editor/types";
@customElement("hui-action-editor")
export class HuiActionEditor extends LitElement {
@property() public config?: ActionConfig;
@property({ attribute: false }) public config?: ActionConfig;
@property() public label?: string;
@property({ attribute: false }) public label?: string;
@property() public actions?: string[];
@property({ attribute: false }) public actions?: string[];
@property() protected hass?: HomeAssistant;
@property({ attribute: false }) protected hass?: HomeAssistant;
get _action(): string {
return this.config?.action || "";
@@ -55,17 +55,19 @@ export class HuiActionEditor extends LitElement {
return html``;
}
return html`
<paper-dropdown-menu
.label="${this.label}"
.configValue="${"action"}"
@value-changed="${this._valueChanged}"
>
<paper-dropdown-menu .label=${this.label}>
<paper-listbox
slot="dropdown-content"
.selected="${this.actions.indexOf(this._action)}"
attr-for-selected="item-value"
.configValue=${"action"}
.selected=${this._action}
@iron-select=${this._valueChanged}
>
<paper-item></paper-item>
${this.actions.map((action) => {
return html` <paper-item>${action}</paper-item> `;
return html`
<paper-item .itemValue=${action}>${action}</paper-item>
`;
})}
</paper-listbox>
</paper-dropdown-menu>
@@ -73,9 +75,9 @@ export class HuiActionEditor extends LitElement {
? html`
<paper-input
label="Navigation Path"
.value="${this._navigation_path}"
.configValue="${"navigation_path"}"
@value-changed="${this._valueChanged}"
.value=${this._navigation_path}
.configValue=${"navigation_path"}
@value-changed=${this._valueChanged}
></paper-input>
`
: ""}
@@ -83,9 +85,9 @@ export class HuiActionEditor extends LitElement {
? html`
<paper-input
label="Url Path"
.value="${this._url_path}"
.configValue="${"url_path"}"
@value-changed="${this._valueChanged}"
.value=${this._url_path}
.configValue=${"url_path"}
@value-changed=${this._valueChanged}
></paper-input>
`
: ""}
@@ -93,9 +95,9 @@ export class HuiActionEditor extends LitElement {
? html`
<ha-service-picker
.hass=${this.hass}
.value="${this._service}"
.configValue="${"service"}"
@value-changed="${this._valueChanged}"
.value=${this._service}
.configValue=${"service"}
@value-changed=${this._valueChanged}
></ha-service-picker>
<b>Service data can only be entered in the code editor</b>
`
@@ -103,20 +105,26 @@ export class HuiActionEditor extends LitElement {
`;
}
private _valueChanged(ev: Event): void {
private _valueChanged(ev: CustomEvent): void {
ev.stopPropagation();
if (!this.hass) {
if (!this.hass || !ev.detail.item?.itemValue) {
return;
}
const target = ev.target! as EditorTarget;
if (this[`_${target.configValue}`] === target.value) {
if (this[`_${target.configValue}`] === ev.detail.item.itemValue) {
return;
}
if (target.configValue) {
const newConfig =
target.configValue === "action"
? { action: target.value }
: { ...this.config!, [target.configValue!]: target.value };
? { action: ev.detail.item.itemValue }
: {
...this.config!,
[target.configValue!]: ev.detail.item.itemValue,
};
fireEvent(this, "value-changed", { value: newConfig });
}
}