Skip to content

Commit

Permalink
refactor: lowered battery warning threshold
Browse files Browse the repository at this point in the history
  • Loading branch information
SublimePotato committed Dec 6, 2024
1 parent 7fe0c7b commit 32761d7
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
2 changes: 1 addition & 1 deletion dist/better-thermostat-ui-card.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions src/better-thermostat-ui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -685,9 +685,10 @@ export class BetterThermostatUi extends LitElement implements LovelaceCard {
this.summer = !attributes.call_for_heat
}
if (attributes?.batteries !== undefined && !this?._config?.disable_battery_warning) {
const showLowBatteryWarningWhenPercentageLowerThan = 5; // this is really preference based - an option would be neat
const batteries = Object.entries(JSON.parse(attributes.batteries) as Record<string, BatteryState>);
const parsedBatteries = batteries.map((data) => ({ "name": data[0], "battery": data[1].battery === "on" ? 5 : data[1].battery === "off" ? 100 : parseFloat(data[1].battery) }));
const lowBatteries = parsedBatteries.filter((entity) => entity.battery < 10);
const parsedBatteries = batteries.map((data) => ({ "name": data[0], "battery": data[1].battery === "on" ? showLowBatteryWarningWhenPercentageLowerThan - 1 : data[1].battery === "off" ? 100 : parseFloat(data[1].battery) }));
const lowBatteries = parsedBatteries.filter((entity) => entity.battery < showLowBatteryWarningWhenPercentageLowerThan);
this.lowBattery = lowBatteries[0];
} else {
this.lowBattery = undefined;
Expand Down

0 comments on commit 32761d7

Please sign in to comment.