Fix config update handling for map card editor (#8115)

This commit is contained in:
Philip Allgaier 2021-01-14 12:52:58 +01:00 committed by GitHub
parent 1aa40cb6df
commit ef7d2aea8d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 45 additions and 40 deletions

View File

@ -31,17 +31,17 @@ export class HuiInputListEditor extends LitElement {
return html` return html`
<paper-input <paper-input
label="${this.inputLabel}" label="${this.inputLabel}"
.value="${listEntry}" .value=${listEntry}
.configValue="${"entry"}" .configValue=${"entry"}
.index="${index}" .index=${index}
@value-changed="${this._valueChanged}" @value-changed=${this._valueChanged}
@blur="${this._consolidateEntries}" @blur=${this._consolidateEntries}
><ha-icon-button ><ha-icon-button
slot="suffix" slot="suffix"
class="clear-button" class="clear-button"
icon="hass:close" icon="hass:close"
no-ripple no-ripple
@click="${this._removeEntry}" @click=${this._removeEntry}
>Clear</ha-icon-button >Clear</ha-icon-button
></paper-input ></paper-input
> >
@ -49,7 +49,7 @@ export class HuiInputListEditor extends LitElement {
})} })}
<paper-input <paper-input
label="${this.inputLabel}" label="${this.inputLabel}"
@change="${this._addEntry}" @change=${this._addEntry}
></paper-input> ></paper-input>
`; `;
} }

View File

@ -96,36 +96,39 @@ export class HuiMapCardEditor extends LitElement implements LovelaceCardEditor {
return html` return html`
<div class="card-config"> <div class="card-config">
<paper-input <paper-input
.label="${this.hass.localize( .label=${this.hass.localize(
"ui.panel.lovelace.editor.card.generic.title" "ui.panel.lovelace.editor.card.generic.title"
)} (${this.hass.localize( )}
(${this.hass.localize(
"ui.panel.lovelace.editor.card.config.optional" "ui.panel.lovelace.editor.card.config.optional"
)})" )})
.value="${this._title}" .value=${this._title}
.configValue="${"title"}" .configValue=${"title"}
@value-changed="${this._valueChanged}" @value-changed=${this._valueChanged}
></paper-input> ></paper-input>
<div class="side-by-side"> <div class="side-by-side">
<paper-input <paper-input
.label="${this.hass.localize( .label=${this.hass.localize(
"ui.panel.lovelace.editor.card.generic.aspect_ratio" "ui.panel.lovelace.editor.card.generic.aspect_ratio"
)} (${this.hass.localize( )}
(${this.hass.localize(
"ui.panel.lovelace.editor.card.config.optional" "ui.panel.lovelace.editor.card.config.optional"
)})" )})
.value="${this._aspect_ratio}" .value=${this._aspect_ratio}
.configValue="${"aspect_ratio"}" .configValue=${"aspect_ratio"}
@value-changed="${this._valueChanged}" @value-changed=${this._valueChanged}
></paper-input> ></paper-input>
<paper-input <paper-input
.label="${this.hass.localize( .label=${this.hass.localize(
"ui.panel.lovelace.editor.card.map.default_zoom" "ui.panel.lovelace.editor.card.map.default_zoom"
)} (${this.hass.localize( )}
(${this.hass.localize(
"ui.panel.lovelace.editor.card.config.optional" "ui.panel.lovelace.editor.card.config.optional"
)})" )})
type="number" type="number"
.value="${this._default_zoom}" .value="${this._default_zoom}"
.configValue="${"default_zoom"}" .configValue=${"default_zoom"}
@value-changed="${this._valueChanged}" @value-changed=${this._valueChanged}
></paper-input> ></paper-input>
</div> </div>
<div class="side-by-side"> <div class="side-by-side">
@ -136,27 +139,28 @@ export class HuiMapCardEditor extends LitElement implements LovelaceCardEditor {
.dir=${computeRTLDirection(this.hass)} .dir=${computeRTLDirection(this.hass)}
> >
<ha-switch <ha-switch
.checked="${this._dark_mode}" .checked=${this._dark_mode}
.configValue="${"dark_mode"}" .configValue=${"dark_mode"}
@change="${this._valueChanged}" @change=${this._valueChanged}
></ha-switch ></ha-switch
></ha-formfield> ></ha-formfield>
<paper-input <paper-input
.label="${this.hass.localize( .label=${this.hass.localize(
"ui.panel.lovelace.editor.card.map.hours_to_show" "ui.panel.lovelace.editor.card.map.hours_to_show"
)} (${this.hass.localize( )}
(${this.hass.localize(
"ui.panel.lovelace.editor.card.config.optional" "ui.panel.lovelace.editor.card.config.optional"
)})" )})
type="number" type="number"
.value="${this._hours_to_show}" .value="${this._hours_to_show}"
.configValue="${"hours_to_show"}" .configValue=${"hours_to_show"}
@value-changed="${this._valueChanged}" @value-changed=${this._valueChanged}
></paper-input> ></paper-input>
</div> </div>
<hui-entity-editor <hui-entity-editor
.hass=${this.hass} .hass=${this.hass}
.entities="${this._configEntities}" .entities=${this._configEntities}
@entities-changed="${this._entitiesValueChanged}" @entities-changed=${this._entitiesValueChanged}
></hui-entity-editor> ></hui-entity-editor>
<h3> <h3>
${this.hass.localize( ${this.hass.localize(
@ -169,9 +173,9 @@ export class HuiMapCardEditor extends LitElement implements LovelaceCardEditor {
"ui.panel.lovelace.editor.card.map.source" "ui.panel.lovelace.editor.card.map.source"
)} )}
.hass=${this.hass} .hass=${this.hass}
.value="${this._geo_location_sources}" .value=${this._geo_location_sources}
.configValue="${"geo_location_sources"}" .configValue=${"geo_location_sources"}
@value-changed="${this._valueChanged}" @value-changed=${this._valueChanged}
></hui-input-list-editor> ></hui-input-list-editor>
</div> </div>
</div> </div>
@ -195,14 +199,15 @@ export class HuiMapCardEditor extends LitElement implements LovelaceCardEditor {
return; return;
} }
const target = ev.target! as EditorTarget; const target = ev.target! as EditorTarget;
if (target.configValue && this[`_${target.configValue}`] === target.value) { let value = ev.detail.value;
if (target.configValue && this[`_${target.configValue}`] === value) {
return; return;
} }
let value: any = target.value;
if (target.type === "number") { if (target.type === "number") {
value = Number(value); value = Number(value);
} }
if (target.value === "" || (target.type === "number" && isNaN(value))) { if (value === "" || (target.type === "number" && isNaN(value))) {
this._config = { ...this._config }; this._config = { ...this._config };
delete this._config[target.configValue!]; delete this._config[target.configValue!];
} else if (target.configValue) { } else if (target.configValue) {