Skip to content

Commit

Permalink
Merge pull request #602 from maxwroc/revert-599-Enable-custom-colors-…
Browse files Browse the repository at this point in the history
…for-all-numeric-values

Revert "Enable custom colors for all numeric values (also outside of 0-100 range)"
  • Loading branch information
maxwroc authored Nov 16, 2023
2 parents 3bae17c + 894d210 commit 48b1049
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 23 deletions.
2 changes: 1 addition & 1 deletion src/colors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
22 changes: 0 additions & 22 deletions test/other/colors.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
Expand Down

0 comments on commit 48b1049

Please sign in to comment.