Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add default values for script fields in more-info dialog #20747

Closed
wants to merge 8 commits into from
10 changes: 9 additions & 1 deletion src/dialogs/more-info/controls/more-info-script.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,15 @@ class MoreInfoScript extends LitElement {
const newState = this.stateObj;

if (newState && (!oldState || oldState.entity_id !== newState.entity_id)) {
this._scriptData = { service: newState.entity_id, data: {} };
const fields =
this.hass.services.script[computeObjectId(newState.entity_id)]?.fields;
const defaultValues = {};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should use computeInitialHaFormData here.

Object.keys(fields).forEach((field) => {
if (fields[field].default) {
defaultValues[field] = fields[field].default;
}
});
this._scriptData = { service: newState.entity_id, data: defaultValues };
}
}

Expand Down
Loading