Skip to content

Commit

Permalink
Merge pull request #634 from maxwroc/FixEqualsOperator
Browse files Browse the repository at this point in the history
Fixed equals filter operator
  • Loading branch information
maxwroc authored Jan 8, 2024
2 parents 6ce1720 + 8568389 commit 67b09e6
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
4 changes: 2 additions & 2 deletions src/filter.ts
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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),
Expand Down
4 changes: 3 additions & 1 deletion test/other/filter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,9 @@ describe("Filter", () => {
["45", <FilterOperator>"matches", "55", false],
[undefined, <FilterOperator>"matches", "55", false],
["45", <FilterOperator>"=", "45", true],
["45", <FilterOperator>"=", "55", false],
["45", <FilterOperator>"=", "45", true],
["string test", <FilterOperator>"=", "string", false],
["string test", <FilterOperator>"=", "string test", true],
["45", <FilterOperator>">", "44", true],
["45", <FilterOperator>">", "45", false],
["45", <FilterOperator>">=", "45", true],
Expand Down

0 comments on commit 67b09e6

Please sign in to comment.