From 894d21081fa194cde0682f1804845478be862ab4 Mon Sep 17 00:00:00 2001 From: Max Chodorowski Date: Thu, 16 Nov 2023 22:06:59 +0000 Subject: [PATCH] Revert "Enable custom colors for all numeric values (also outside of 0-100 range)" --- src/colors.ts | 2 +- test/other/colors.test.ts | 22 ---------------------- 2 files changed, 1 insertion(+), 23 deletions(-) diff --git a/src/colors.ts b/src/colors.ts index eba00902..d2b98fdb 100644 --- a/src/colors.ts +++ b/src/colors.ts @@ -13,7 +13,7 @@ import { log, safeGetConfigArrayOfObjects } from "./utils"; return config.charging_state.color; } - if (batteryLevel === undefined || isNaN(batteryLevel)) { + if (batteryLevel === undefined || isNaN(batteryLevel) || batteryLevel > 100 || batteryLevel < 0) { return defaultColor; } diff --git a/test/other/colors.test.ts b/test/other/colors.test.ts index 7bab7f6f..8f857617 100644 --- a/test/other/colors.test.ts +++ b/test/other/colors.test.ts @@ -37,28 +37,6 @@ describe("Colors", () => { expect(result).toBe(expectedColor); }) - test.each([ - [-220, "red"], - [-80, "red"], - [-79.9999, "yellow"], - [-65, "yellow"], - [-50, "green"], - [0, "green"], - [100, "green"], - ])("custom steps config", (batteryLevel: number, expectedColor: string) => { - - const colorsConfig: IColorSettings = { - steps: [ - { value: -80, color: "red" }, - { value: -65, color: "yellow" }, - { value: 1000, color: "green" } - ] - } - const result = getColorForBatteryLevel({ entity: "", colors: colorsConfig }, batteryLevel, false); - - expect(result).toBe(expectedColor); - }) - test.each([ [0, "#ff0000"], [25, "#ff7f00"],