Set mandatory bool service data without a default value to false (#11094)

This commit is contained in:
Erik Montnemery 2022-01-24 10:27:38 +01:00 committed by GitHub
parent abeaa63005
commit b0b953bfac
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -130,6 +130,33 @@ export class HaServiceControl extends LitElement {
this._value = this.value;
}
if (oldValue?.service !== this.value?.service) {
let updatedDefaultValue = false;
if (this._value && serviceData) {
// Set mandatory bools without a default value to false
this._value.data ??= {};
serviceData.fields.forEach((field) => {
if (
field.selector &&
field.required &&
field.default === undefined &&
"boolean" in field.selector &&
this._value!.data![field.key] === undefined
) {
updatedDefaultValue = true;
this._value!.data![field.key] = false;
}
});
}
if (updatedDefaultValue) {
fireEvent(this, "value-changed", {
value: {
...this._value,
},
});
}
}
if (this._value?.data) {
const yamlEditor = this._yamlEditor;
if (yamlEditor && yamlEditor.value !== this._value.data) {