From 65251e0dbfde8d64da207bf39d60dd552086d8d6 Mon Sep 17 00:00:00 2001 From: Paola Persico Date: Mon, 6 May 2024 20:04:58 +0200 Subject: [PATCH 1/3] Add default values for script fields in more-info dialog --- src/dialogs/more-info/controls/more-info-script.ts | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/dialogs/more-info/controls/more-info-script.ts b/src/dialogs/more-info/controls/more-info-script.ts index c530f05cf553..9e4769b1f9db 100644 --- a/src/dialogs/more-info/controls/more-info-script.ts +++ b/src/dialogs/more-info/controls/more-info-script.ts @@ -147,8 +147,18 @@ class MoreInfoScript extends LitElement { | undefined; const newState = this.stateObj; + const fields = + this.hass.services.script[computeObjectId(newState.entity_id)]?.fields; + + const defaultValues = {}; + Object.keys(fields).forEach((field) => { + if (fields[field].default) { + defaultValues[field] = fields[field].default; + } + }); + if (newState && (!oldState || oldState.entity_id !== newState.entity_id)) { - this._scriptData = { service: newState.entity_id, data: {} }; + this._scriptData = { service: newState.entity_id, data: defaultValues }; } } From fbd60126ce0174a487af79b1c198ff30c6cd2c69 Mon Sep 17 00:00:00 2001 From: Paola Persico <32850381+paolapersico1@users.noreply.github.com> Date: Mon, 6 May 2024 21:55:00 +0200 Subject: [PATCH 2/3] Update more-info-script.ts --- .../more-info/controls/more-info-script.ts | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/src/dialogs/more-info/controls/more-info-script.ts b/src/dialogs/more-info/controls/more-info-script.ts index 9e4769b1f9db..8e020ec88490 100644 --- a/src/dialogs/more-info/controls/more-info-script.ts +++ b/src/dialogs/more-info/controls/more-info-script.ts @@ -147,17 +147,16 @@ class MoreInfoScript extends LitElement { | undefined; const newState = this.stateObj; - const fields = - this.hass.services.script[computeObjectId(newState.entity_id)]?.fields; - - const defaultValues = {}; - Object.keys(fields).forEach((field) => { - if (fields[field].default) { - defaultValues[field] = fields[field].default; - } - }); - if (newState && (!oldState || oldState.entity_id !== newState.entity_id)) { + const fields = + this.hass.services.script[computeObjectId(newState.entity_id)]?.fields; + + const defaultValues = {}; + Object.keys(fields).forEach((field) => { + if (fields[field].default) { + defaultValues[field] = fields[field].default; + } + }); this._scriptData = { service: newState.entity_id, data: defaultValues }; } } From bb2cdc8982f7209ee579a3d4e8cdddfce745238b Mon Sep 17 00:00:00 2001 From: paolapersico1 Date: Mon, 6 May 2024 23:23:24 +0200 Subject: [PATCH 3/3] Run prettier --- src/dialogs/more-info/controls/more-info-script.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/dialogs/more-info/controls/more-info-script.ts b/src/dialogs/more-info/controls/more-info-script.ts index 8e020ec88490..b435eb30136d 100644 --- a/src/dialogs/more-info/controls/more-info-script.ts +++ b/src/dialogs/more-info/controls/more-info-script.ts @@ -150,7 +150,6 @@ class MoreInfoScript extends LitElement { if (newState && (!oldState || oldState.entity_id !== newState.entity_id)) { const fields = this.hass.services.script[computeObjectId(newState.entity_id)]?.fields; - const defaultValues = {}; Object.keys(fields).forEach((field) => { if (fields[field].default) {