Skip to content

Commit

Permalink
Merge pull request #327 from flixlix/321-v016x-zero-lines-are-not-com…
Browse files Browse the repository at this point in the history
…pletely-hidden-bug

fix: 🐛 reset values if below tolerance
  • Loading branch information
flixlix authored Jul 20, 2023
2 parents c92ad97 + 16a09fc commit 6f8c543
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/power-flow-card-plus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -552,6 +552,7 @@ export class PowerFlowCardPlus extends LitElement {
if (solar.has) {
solar.state.toHome = (solar.state.total ?? 0) - (grid.state.toGrid ?? 0) - (battery.state.toBattery ?? 0);
}
const largestGridBatteryTolerance = Math.max(entities.grid?.display_zero_tolerance ?? 0, entities.battery?.display_zero_tolerance ?? 0);

if (solar.state.toHome !== null && solar.state.toHome < 0) {
// What we returned to the grid and what went in to the battery is more
Expand All @@ -568,6 +569,7 @@ export class PowerFlowCardPlus extends LitElement {
} else if (!solar.has && battery.state.toBattery && battery.state.toBattery > 0) {
grid.state.toBattery = battery.state.toBattery;
}
grid.state.toBattery = (grid.state.toBattery ?? 0) > largestGridBatteryTolerance ? grid.state.toBattery : 0;

if (battery.has) {
if (solar.has) {
Expand All @@ -581,6 +583,7 @@ export class PowerFlowCardPlus extends LitElement {
} else {
battery.state.toGrid = grid.state.toGrid || 0;
}
battery.state.toGrid = (battery.state.toGrid || 0) > largestGridBatteryTolerance ? grid.state.toGrid || 0 : 0;
battery.state.toHome = (battery.state.fromBattery ?? 0) - (battery.state.toGrid ?? 0);
}

Expand Down

0 comments on commit 6f8c543

Please sign in to comment.