Compare commits

...

2 Commits

Author SHA1 Message Date
Bram Kragten
785f07d37a revert unneeded 2026-04-03 11:13:11 +02:00
Bram Kragten
9d3a2e15c0 Always add options object 2026-04-03 10:38:21 +02:00
2 changed files with 20 additions and 26 deletions

View File

@@ -73,12 +73,13 @@ export class HaPlatformCondition extends LitElement {
}
if (
oldValue?.condition !== this.condition?.condition &&
this.condition &&
oldValue?.condition !== this.condition.condition &&
this.description?.fields
) {
let updatedDefaultValue = false;
const updatedOptions = {};
const updatedOptions = this.condition.options
? { ...this.condition.options }
: {};
const loadDefaults = !("options" in this.condition);
// Set mandatory bools without a default value to false
Object.entries(this.description.fields).forEach(([key, field]) => {
@@ -89,7 +90,6 @@ export class HaPlatformCondition extends LitElement {
"boolean" in field.selector &&
updatedOptions[key] === undefined
) {
updatedDefaultValue = true;
updatedOptions[key] = false;
} else if (
loadDefaults &&
@@ -102,18 +102,15 @@ export class HaPlatformCondition extends LitElement {
!this.condition?.target
)
) {
updatedDefaultValue = true;
updatedOptions[key] = field.default;
}
});
if (updatedDefaultValue) {
fireEvent(this, "value-changed", {
value: {
...this.condition,
options: updatedOptions,
},
});
}
fireEvent(this, "value-changed", {
value: {
...this.condition,
options: updatedOptions,
},
});
}
if (oldValue?.target !== this.condition?.target) {

View File

@@ -108,12 +108,13 @@ export class HaPlatformTrigger extends LitElement {
}
if (
oldValue?.trigger !== this.trigger?.trigger &&
this.trigger &&
oldValue?.trigger !== this.trigger.trigger &&
this.description?.fields
) {
let updatedDefaultValue = false;
const updatedOptions = {};
const updatedOptions = this.trigger.options
? { ...this.trigger.options }
: {};
const loadDefaults = !("options" in this.trigger);
// Set mandatory bools without a default value to false
Object.entries(this.description.fields).forEach(([key, field]) => {
@@ -124,7 +125,6 @@ export class HaPlatformTrigger extends LitElement {
"boolean" in field.selector &&
updatedOptions[key] === undefined
) {
updatedDefaultValue = true;
updatedOptions[key] = false;
} else if (
loadDefaults &&
@@ -137,19 +137,16 @@ export class HaPlatformTrigger extends LitElement {
!this.trigger?.target
)
) {
updatedDefaultValue = true;
updatedOptions[key] = field.default;
}
});
if (updatedDefaultValue) {
fireEvent(this, "value-changed", {
value: {
...this.trigger,
options: updatedOptions,
},
});
}
fireEvent(this, "value-changed", {
value: {
...this.trigger,
options: updatedOptions,
},
});
}
if (oldValue?.target !== this.trigger?.target) {