mirror of
https://github.com/home-assistant/frontend.git
synced 2025-08-09 01:17:48 +00:00
review: states are string
This commit is contained in:
parent
263efc35a7
commit
e20bf741a4
@ -52,8 +52,8 @@ export interface NumericStateCondition extends BaseCondition {
|
|||||||
export interface StateCondition extends BaseCondition {
|
export interface StateCondition extends BaseCondition {
|
||||||
condition: "state";
|
condition: "state";
|
||||||
entity?: string;
|
entity?: string;
|
||||||
state?: string | number | string[];
|
state?: string | string[];
|
||||||
state_not?: string | number | string[];
|
state_not?: string | string[];
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ScreenCondition extends BaseCondition {
|
export interface ScreenCondition extends BaseCondition {
|
||||||
@ -101,8 +101,9 @@ function checkLegacyFilterCondition(
|
|||||||
if (!entity) {
|
if (!entity) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
let value = condition.value;
|
let value = condition.value;
|
||||||
let state = condition.attribute
|
let state: string | number = condition.attribute
|
||||||
? entity.attributes[condition.attribute]
|
? entity.attributes[condition.attribute]
|
||||||
: entity.state;
|
: entity.state;
|
||||||
|
|
||||||
@ -113,10 +114,10 @@ function checkLegacyFilterCondition(
|
|||||||
if (condition.operator === "==" || condition.operator === "!=") {
|
if (condition.operator === "==" || condition.operator === "!=") {
|
||||||
const valueIsNumeric =
|
const valueIsNumeric =
|
||||||
typeof value === "number" ||
|
typeof value === "number" ||
|
||||||
(typeof value === "string" && value.trim() && !isNaN(Number(value)));
|
(typeof value === "string" && !isNaN(Number(value.trim())));
|
||||||
const stateIsNumeric =
|
const stateIsNumeric =
|
||||||
typeof state === "number" ||
|
typeof state === "number" ||
|
||||||
(typeof state === "string" && state.trim() && !isNaN(Number(state)));
|
(typeof state === "string" && !isNaN(Number(state.trim())));
|
||||||
if (valueIsNumeric && stateIsNumeric) {
|
if (valueIsNumeric && stateIsNumeric) {
|
||||||
value = Number(value);
|
value = Number(value);
|
||||||
state = Number(state);
|
state = Number(state);
|
||||||
@ -249,8 +250,8 @@ export function buildConditionForFilter(
|
|||||||
if (typeof condition === "string" || typeof condition === "number") {
|
if (typeof condition === "string" || typeof condition === "number") {
|
||||||
newCondition = {
|
newCondition = {
|
||||||
condition: "state",
|
condition: "state",
|
||||||
state: condition,
|
state: `${condition}`,
|
||||||
} as StateCondition;
|
};
|
||||||
} else {
|
} else {
|
||||||
newCondition = condition;
|
newCondition = condition;
|
||||||
}
|
}
|
||||||
|
@ -21,7 +21,7 @@ type StateConditionData = {
|
|||||||
condition: "state";
|
condition: "state";
|
||||||
entity?: string;
|
entity?: string;
|
||||||
invert: "true" | "false";
|
invert: "true" | "false";
|
||||||
state?: string | number | string[];
|
state?: string | string[];
|
||||||
};
|
};
|
||||||
|
|
||||||
@customElement("ha-card-condition-state")
|
@customElement("ha-card-condition-state")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user