diff --git a/package.json b/package.json index c96a15c..4d8f433 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "battery-state-card", - "version": "3.1.0", + "version": "3.1.1", "description": "Battery State card for Home Assistant", "main": "dist/battery-state-card.js", "author": "Max Chodorowski", diff --git a/src/sorting.ts b/src/sorting.ts index 754280b..9376854 100644 --- a/src/sorting.ts +++ b/src/sorting.ts @@ -25,8 +25,10 @@ import { isNumber, log, safeGetConfigArrayOfObjects } from "./utils"; valB = batteries[idB].name; break; case "state": - valA = batteries[idA].state; - valB = batteries[idB].state; + // not a perfect solution but we try to fix numer formatting in some countries/langs + // where decimals are separated by comma + valA = batteries[idA].state?.replace(",", "."); + valB = batteries[idB].state?.replace(",", "."); break; default: if ((o.by).startsWith("entity.")) { diff --git a/test/other/sorting.test.ts b/test/other/sorting.test.ts index b123bd3..50eba19 100644 --- a/test/other/sorting.test.ts +++ b/test/other/sorting.test.ts @@ -78,6 +78,24 @@ describe("Entity sorting", () => { expect(sortedIds).toStrictEqual(expectedOrder); }); + + test.each([ + ["state", "38", "38,5", "38,4", ["a_sensor", "c_sensor", "b_sensor"]], + ["state", "38", "99,5", "99,4", ["a_sensor", "c_sensor", "b_sensor"]], + ["state", "38", "99,4", "99,44", ["a_sensor", "b_sensor", "c_sensor"]], + ["state", "38", "99.4", "99.44", ["a_sensor", "b_sensor", "c_sensor"]], + ])("Decimals separated by comma", (sort: string, stateA: string | undefined, stateB: string | undefined, stateC: string | undefined, expectedOrder: string[]) => { + + let testBatteries = [ + createBattery("a Sensor", stateA), + createBattery("b Sensor", stateB), + createBattery("c Sensor", stateC), + ]; + + const sortedIds = getIdsOfSortedBatteries({ entities: [], sort }, convertToCollection(testBatteries)); + + expect(sortedIds).toStrictEqual(expectedOrder); + }); }); const createBattery = (name: string, state: string | undefined, last_changed?: string | undefined) => {