mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-23 17:26:42 +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 { 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) {
|
||||||
|
@ -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`
|
||||||
|
Loading…
x
Reference in New Issue
Block a user