Skip to content

Commit

Permalink
Clean entity data
Browse files Browse the repository at this point in the history
  • Loading branch information
piitaya committed Oct 23, 2023
1 parent 4bec4b2 commit ddc9a73
Showing 1 changed file with 4 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const stateConditionStruct = object({

type StateConditionData = {
condition: "state";
entity: string;
entity?: string;
invert: "true" | "false";
state?: string | string[];
};
Expand Down Expand Up @@ -101,12 +101,9 @@ export class HaCardConditionState extends LitElement {

const data: StateConditionData = {
...content,
entity: this.condition.entity ?? "",
entity: this.condition.entity,
invert: this.condition.state_not ? "true" : "false",
state:
(this.condition.state_not as string | string[] | undefined) ??
(this.condition.state as string | string[] | undefined) ??
"",
state: this.condition.state_not ?? this.condition.state,
};

return html`
Expand All @@ -125,12 +122,11 @@ export class HaCardConditionState extends LitElement {
ev.stopPropagation();
const data = ev.detail.value as StateConditionData;

const { invert, state, entity, condition: _, ...content } = data;
const { invert, state, condition: _, ...content } = data;

const condition: StateCondition = {
condition: "state",
...content,
entity: entity ?? "",
state: invert === "false" ? state ?? "" : undefined,
state_not: invert === "true" ? state ?? "" : undefined,
};
Expand Down

0 comments on commit ddc9a73

Please sign in to comment.