mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-24 09:46:36 +00:00
Fix entity-filter handling of numeric states for == and != operators. (#14726)
Co-authored-by: Bram Kragten <mail@bramkragten.nl> fixes undefined
This commit is contained in:
parent
77b8152c55
commit
25a5bd568a
@ -2,11 +2,24 @@ import { HassEntity } from "home-assistant-js-websocket";
|
||||
|
||||
export const evaluateFilter = (stateObj: HassEntity, filter: any): boolean => {
|
||||
const operator = filter.operator || "==";
|
||||
const value = filter.value ?? filter;
|
||||
const state = filter.attribute
|
||||
let value = filter.value ?? filter;
|
||||
let state = filter.attribute
|
||||
? stateObj.attributes[filter.attribute]
|
||||
: stateObj.state;
|
||||
|
||||
if (operator === "==" || operator === "!=") {
|
||||
const valueIsNumeric =
|
||||
typeof value === "number" ||
|
||||
(typeof value === "string" && value.trim() && !isNaN(Number(value)));
|
||||
const stateIsNumeric =
|
||||
typeof state === "number" ||
|
||||
(typeof state === "string" && state.trim() && !isNaN(Number(state)));
|
||||
if (valueIsNumeric && stateIsNumeric) {
|
||||
value = Number(value);
|
||||
state = Number(state);
|
||||
}
|
||||
}
|
||||
|
||||
switch (operator) {
|
||||
case "==":
|
||||
return state === value;
|
||||
|
Loading…
x
Reference in New Issue
Block a user