mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-23 09:16:38 +00:00
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:
parent
eedb42b2f3
commit
9bafbdd989
@ -1,3 +1,4 @@
|
||||
import { ensureArray } from "../../../common/array/ensure-array";
|
||||
import { UNAVAILABLE } from "../../../data/entity";
|
||||
import { HomeAssistant } from "../../../types";
|
||||
|
||||
@ -5,15 +6,15 @@ export type Condition = StateCondition | ScreenCondition | UserCondition;
|
||||
|
||||
export type LegacyCondition = {
|
||||
entity?: string;
|
||||
state?: string;
|
||||
state_not?: string;
|
||||
state?: string | string[];
|
||||
state_not?: string | string[];
|
||||
};
|
||||
|
||||
export type StateCondition = {
|
||||
condition: "state";
|
||||
entity?: string;
|
||||
state?: string;
|
||||
state_not?: string;
|
||||
state?: string | string[];
|
||||
state_not?: string | string[];
|
||||
};
|
||||
|
||||
export type ScreenCondition = {
|
||||
@ -36,8 +37,8 @@ function checkStateCondition(
|
||||
: UNAVAILABLE;
|
||||
|
||||
return condition.state != null
|
||||
? state === condition.state
|
||||
: state !== condition.state_not;
|
||||
? ensureArray(condition.state).includes(state)
|
||||
: ensureArray(condition.state_not).includes(state);
|
||||
}
|
||||
|
||||
function checkScreenCondition(condition: ScreenCondition, _: HomeAssistant) {
|
||||
|
@ -21,7 +21,7 @@ type StateConditionData = {
|
||||
condition: "state";
|
||||
entity: string;
|
||||
invert: "true" | "false";
|
||||
state?: string;
|
||||
state?: string | string[];
|
||||
};
|
||||
|
||||
@customElement("ha-card-condition-state")
|
||||
@ -103,7 +103,10 @@ export class HaCardConditionState extends LitElement {
|
||||
...content,
|
||||
entity: this.condition.entity ?? "",
|
||||
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`
|
||||
|
Loading…
x
Reference in New Issue
Block a user