Normalize automation config (#13938)

* Normalize automation config

* gen

* Update ha-automation-action-choose.ts
This commit is contained in:
Bram Kragten
2022-10-02 00:02:24 +02:00
committed by GitHub
parent 6393944a1b
commit 4f4a95c04e
4 changed files with 34 additions and 23 deletions

View File

@@ -469,15 +469,9 @@ export class HaScriptEditor extends KeyboardShortcutMixin(LitElement) {
) {
fetchScriptFileConfig(this.hass, this.scriptId).then(
(config) => {
// Normalize data: ensure sequence is a list
// Happens when people copy paste their scripts into the config
const value = config.sequence;
if (value && !Array.isArray(value)) {
config.sequence = [value];
}
this._dirty = false;
this._readOnly = false;
this._config = config;
this._config = this._normalizeConfig(config);
},
(resp) => {
const entity = Object.values(this.hass.entities).find(
@@ -524,7 +518,7 @@ export class HaScriptEditor extends KeyboardShortcutMixin(LitElement) {
if (changedProps.has("entityId") && this.entityId) {
getScriptStateConfig(this.hass, this.entityId).then((c) => {
this._config = c.config;
this._config = this._normalizeConfig(c.config);
});
const regEntry = this.hass.entities[this.entityId];
if (regEntry?.unique_id) {
@@ -536,6 +530,16 @@ export class HaScriptEditor extends KeyboardShortcutMixin(LitElement) {
}
}
private _normalizeConfig(config: ScriptConfig): ScriptConfig {
// Normalize data: ensure sequence is a list
// Happens when people copy paste their scripts into the config
const value = config.sequence;
if (value && !Array.isArray(value)) {
config.sequence = [value];
}
return config;
}
private _computeLabelCallback = (
schema: SchemaUnion<ReturnType<typeof this._schema>>,
data: HaFormDataContainer