From 901f9a371ee59ff361bc1b5261d9ebe2311220e3 Mon Sep 17 00:00:00 2001 From: Max Chodorowski Date: Mon, 8 Jan 2024 05:51:21 +0000 Subject: [PATCH 1/2] Fixed equals filter operator --- src/filter.ts | 4 ++-- test/other/filter.test.ts | 4 +++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/filter.ts b/src/filter.ts index ae03c87..60747fd 100644 --- a/src/filter.ts +++ b/src/filter.ts @@ -1,4 +1,4 @@ -import { getRegexFromString, log, toNumber } from "./utils"; +import { getRegexFromString, isNumber, log, toNumber } from "./utils"; /** * Functions to check if filter condition is met @@ -7,7 +7,7 @@ const operatorHandlers: { [key in FilterOperator]: (val: string | number | undef "exists": val => val !== undefined, "not_exists": val => val === undefined, "contains": (val, searchString) => val !== undefined && val.toString().indexOf(searchString!.toString()) != -1, - "=": (val, expectedVal) => toNumber(val) == toNumber(expectedVal), + "=": (val, expectedVal) => isNumber(val) || isNumber(expectedVal) ? toNumber(val) == toNumber(expectedVal) : val == expectedVal, ">": (val, expectedVal) => toNumber(val) > toNumber(expectedVal), "<": (val, expectedVal) => toNumber(val) < toNumber(expectedVal), ">=": (val, expectedVal) => toNumber(val) >= toNumber(expectedVal), diff --git a/test/other/filter.test.ts b/test/other/filter.test.ts index c04f17c..e376e06 100644 --- a/test/other/filter.test.ts +++ b/test/other/filter.test.ts @@ -85,7 +85,9 @@ describe("Filter", () => { ["45", "matches", "55", false], [undefined, "matches", "55", false], ["45", "=", "45", true], - ["45", "=", "55", false], + ["45", "=", "45", true], + ["string test", "=", "string", false], + ["string test", "=", "string test", true], ["45", ">", "44", true], ["45", ">", "45", false], ["45", ">=", "45", true], From 85683890e970a3b586f59eaf754acf93a2d24f15 Mon Sep 17 00:00:00 2001 From: Max Chodorowski Date: Mon, 8 Jan 2024 05:53:40 +0000 Subject: [PATCH 2/2] Bumped version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 4d8f433..ac78538 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "battery-state-card", - "version": "3.1.1", + "version": "3.1.2", "description": "Battery State card for Home Assistant", "main": "dist/battery-state-card.js", "author": "Max Chodorowski",