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

View File

@ -66,7 +66,10 @@ export class HaStateCondition extends LitElement implements ConditionElement {
}, },
{ {
name: "state", name: "state",
selector: { state: { entity_id: entityId, attribute: attribute } }, required: true,
selector: {
state: { entity_id: entityId, attribute: attribute },
},
}, },
{ name: "for", selector: { duration: {} } }, { name: "for", selector: { duration: {} } },
] as const ] as const
@ -105,15 +108,21 @@ export class HaStateCondition extends LitElement implements ConditionElement {
private _valueChanged(ev: CustomEvent): void { private _valueChanged(ev: CustomEvent): void {
ev.stopPropagation(); ev.stopPropagation();
const newTrigger = ev.detail.value; const newCondition = ev.detail.value;
Object.keys(newTrigger).forEach((key) => Object.keys(newCondition).forEach((key) =>
newTrigger[key] === undefined || newTrigger[key] === "" newCondition[key] === undefined || newCondition[key] === ""
? delete newTrigger[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 = ( private _computeLabelCallback = (