Fix automation/script conditions editor (#13465)

This commit is contained in:
Franck Nijhof 2022-08-24 10:59:27 +02:00 committed by GitHub
parent a1bc748bc1
commit 5ce81232b5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 15 additions and 6 deletions

View File

@ -66,7 +66,10 @@ export class HaStateCondition extends LitElement implements ConditionElement {
},
{
name: "state",
selector: { state: { entity_id: entityId, attribute: attribute } },
required: true,
selector: {
state: { entity_id: entityId, attribute: attribute },
},
},
{ name: "for", selector: { duration: {} } },
] as const
@ -105,15 +108,21 @@ export class HaStateCondition extends LitElement implements ConditionElement {
private _valueChanged(ev: CustomEvent): void {
ev.stopPropagation();
const newTrigger = ev.detail.value;
const newCondition = ev.detail.value;
Object.keys(newTrigger).forEach((key) =>
newTrigger[key] === undefined || newTrigger[key] === ""
? delete newTrigger[key]
Object.keys(newCondition).forEach((key) =>
newCondition[key] === undefined || newCondition[key] === ""
? delete newCondition[key]
: {}
);
fireEvent(this, "value-changed", { value: newTrigger });
// We should not cleanup state in the above, as it is required.
// Set it to empty string if it is undefined.
if (!newCondition.state) {
newCondition.state = "";
}
fireEvent(this, "value-changed", { value: newCondition });
}
private _computeLabelCallback = (