Fix blueprint editor behavior for number and text with defaults (#17646)

This commit is contained in:
karwosts 2023-08-21 06:48:10 -07:00 committed by GitHub
parent 693c77ce1c
commit e764076b1a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 68 deletions

View File

@ -9,7 +9,6 @@ import "../../../components/ha-circular-progress";
import "../../../components/ha-markdown";
import "../../../components/ha-selector/ha-selector";
import "../../../components/ha-settings-row";
import "../../../components/ha-textfield";
import "../../../components/ha-alert";
import { BlueprintAutomationConfig } from "../../../data/automation";
import {
@ -129,27 +128,19 @@ export class HaBlueprintAutomationEditor extends LitElement {
breaks
.content=${value?.description}
></ha-markdown>
${value?.selector
? html`<ha-selector
.hass=${this.hass}
.selector=${value.selector}
.key=${key}
.value=${(this.config.use_blueprint.input &&
this.config.use_blueprint.input[key]) ??
value?.default}
.disabled=${this.disabled}
.required=${value?.default === undefined}
@value-changed=${this._inputChanged}
></ha-selector>`
: html`<ha-textfield
.key=${key}
.required=${value?.default === undefined}
.value=${(this.config.use_blueprint.input &&
this.config.use_blueprint.input[key]) ??
value?.default}
.disabled=${this.disabled}
@input=${this._inputChanged}
></ha-textfield>`}
${html`<ha-selector
.hass=${this.hass}
.selector=${value?.selector ?? { text: undefined }}
.key=${key}
.disabled=${this.disabled}
.required=${value?.default === undefined}
.placeholder=${value?.default}
.value=${this.config.use_blueprint.input &&
key in this.config.use_blueprint.input
? this.config.use_blueprint.input[key]
: value?.default}
@value-changed=${this._inputChanged}
></ha-selector>`}
</ha-settings-row>`
)
: html`<p class="padding">
@ -173,7 +164,7 @@ export class HaBlueprintAutomationEditor extends LitElement {
}
fireEvent(this, "value-changed", {
value: {
...this.config!,
...this.config,
use_blueprint: {
path: ev.detail.value,
},
@ -195,20 +186,9 @@ export class HaBlueprintAutomationEditor extends LitElement {
}
const input = { ...this.config.use_blueprint.input, [key]: value };
const blueprint = this._blueprint;
const metaValue =
!blueprint || "error" in blueprint
? undefined
: blueprint?.metadata.input && blueprint?.metadata?.input[key];
const keyDefault = metaValue && metaValue.default;
if ((value === "" && !keyDefault) || value === undefined) {
delete input[key];
}
fireEvent(this, "value-changed", {
value: {
...this.config!,
...this.config,
use_blueprint: {
...this.config.use_blueprint,
input,

View File

@ -5,7 +5,6 @@ import "../../../components/ha-blueprint-picker";
import "../../../components/ha-card";
import "../../../components/ha-circular-progress";
import "../../../components/ha-markdown";
import "../../../components/ha-textfield";
import "../../../components/ha-selector/ha-selector";
import "../../../components/ha-settings-row";
@ -108,27 +107,19 @@ export class HaBlueprintScriptEditor extends LitElement {
breaks
.content=${value?.description}
></ha-markdown>
${value?.selector
? html`<ha-selector
.hass=${this.hass}
.selector=${value.selector}
.key=${key}
.disabled=${this.disabled}
.required=${value?.default === undefined}
.value=${(this.config.use_blueprint.input &&
this.config.use_blueprint.input[key]) ??
value?.default}
@value-changed=${this._inputChanged}
></ha-selector>`
: html`<ha-textfield
.key=${key}
.required=${value?.default === undefined}
.disabled=${this.disabled}
.value=${(this.config.use_blueprint.input &&
this.config.use_blueprint.input[key]) ??
value?.default}
@change=${this._inputChanged}
></ha-textfield>`}
${html`<ha-selector
.hass=${this.hass}
.selector=${value?.selector ?? { text: undefined }}
.key=${key}
.disabled=${this.disabled}
.required=${value?.default === undefined}
.placeholder=${value?.default}
.value=${this.config.use_blueprint.input &&
key in this.config.use_blueprint.input
? this.config.use_blueprint.input[key]
: value?.default}
@value-changed=${this._inputChanged}
></ha-selector>`}
</ha-settings-row>`
)
: html`<p class="padding">
@ -174,17 +165,6 @@ export class HaBlueprintScriptEditor extends LitElement {
}
const input = { ...this.config.use_blueprint.input, [key]: value };
const blueprint = this._blueprint;
const metaValue =
!blueprint || "error" in blueprint
? undefined
: blueprint?.metadata.input && blueprint?.metadata?.input[key];
const keyDefault = metaValue && metaValue.default;
if ((value === "" && !keyDefault) || value === undefined) {
delete input[key];
}
fireEvent(this, "value-changed", {
value: {
...this.config,