Added options to Lovelace evaluate filter (#5694)

This commit is contained in:
Jason Knott 2020-05-06 03:57:11 -07:00 committed by GitHub
parent db07eeb916
commit c631554eb0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -20,8 +20,21 @@ export const evaluateFilter = (stateObj: HassEntity, filter: any): boolean => {
return state > value;
case "!=":
return state !== value;
case "in":
if (Array.isArray(state) || typeof state === "string") {
return state.includes(value);
}
return false;
case "not in":
if (Array.isArray(state) || typeof state === "string") {
return !state.includes(value);
}
return false;
case "regex": {
return state.match(value);
if (state !== null && typeof state === "object") {
return RegExp(value).test(JSON.stringify(state));
}
return RegExp(value).test(state);
}
default:
return false;