Allow multiple states in conditional card (#18273)

* Allow multiple states in conditional card

* Update src/panels/lovelace/editor/conditions/types/ha-card-condition-state.ts

Co-authored-by: Bram Kragten <mail@bramkragten.nl>

---------

Co-authored-by: Bram Kragten <mail@bramkragten.nl>
This commit is contained in:
Paul Bottein 2023-10-23 15:49:43 +02:00 committed by GitHub
parent eedb42b2f3
commit 9bafbdd989
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 8 deletions

View File

@ -1,3 +1,4 @@
import { ensureArray } from "../../../common/array/ensure-array";
import { UNAVAILABLE } from "../../../data/entity"; import { UNAVAILABLE } from "../../../data/entity";
import { HomeAssistant } from "../../../types"; import { HomeAssistant } from "../../../types";
@ -5,15 +6,15 @@ export type Condition = StateCondition | ScreenCondition | UserCondition;
export type LegacyCondition = { export type LegacyCondition = {
entity?: string; entity?: string;
state?: string; state?: string | string[];
state_not?: string; state_not?: string | string[];
}; };
export type StateCondition = { export type StateCondition = {
condition: "state"; condition: "state";
entity?: string; entity?: string;
state?: string; state?: string | string[];
state_not?: string; state_not?: string | string[];
}; };
export type ScreenCondition = { export type ScreenCondition = {
@ -36,8 +37,8 @@ function checkStateCondition(
: UNAVAILABLE; : UNAVAILABLE;
return condition.state != null return condition.state != null
? state === condition.state ? ensureArray(condition.state).includes(state)
: state !== condition.state_not; : ensureArray(condition.state_not).includes(state);
} }
function checkScreenCondition(condition: ScreenCondition, _: HomeAssistant) { function checkScreenCondition(condition: ScreenCondition, _: HomeAssistant) {

View File

@ -21,7 +21,7 @@ type StateConditionData = {
condition: "state"; condition: "state";
entity: string; entity: string;
invert: "true" | "false"; invert: "true" | "false";
state?: string; state?: string | string[];
}; };
@customElement("ha-card-condition-state") @customElement("ha-card-condition-state")
@ -103,7 +103,10 @@ export class HaCardConditionState extends LitElement {
...content, ...content,
entity: this.condition.entity ?? "", entity: this.condition.entity ?? "",
invert: this.condition.state_not ? "true" : "false", invert: this.condition.state_not ? "true" : "false",
state: this.condition.state_not ?? this.condition.state ?? "", state:
(this.condition.state_not as string | string[] | undefined) ??
(this.condition.state as string | string[] | undefined) ??
"",
}; };
return html` return html`