Fix typo in energy calculation (#25259)

* New energy calculation

* more tests and stricter tests. change priority order

* more test and fix error
This commit is contained in:
karwosts 2025-04-30 21:27:11 -07:00 committed by Bram Kragten
parent 2b06742bb9
commit f24b6a4cb1
2 changed files with 24 additions and 1 deletions

View File

@ -1062,7 +1062,7 @@ export const computeConsumptionSingle = (data: {
// Grid_In -> Battery_In
grid_to_battery = Math.min(from_grid, to_battery);
from_grid -= grid_to_battery;
to_battery -= to_battery;
to_battery -= grid_to_battery;
// Solar -> Consumption
used_solar = Math.min(used_total_remaining, solar);

View File

@ -462,6 +462,8 @@ describe("Energy Usage Calculation Tests", () => {
used_total: 9,
}
);
});
it("Solar -> Battery -> Grid", () => {
assert.deepEqual(
checkConsumptionResult({
from_grid: 0,
@ -482,4 +484,25 @@ describe("Energy Usage Calculation Tests", () => {
}
);
});
it("Solar -> Grid && Grid -> Battery", () => {
assert.deepEqual(
checkConsumptionResult({
from_grid: 1,
to_grid: 1,
solar: 1,
to_battery: 1,
from_battery: 0,
}),
{
grid_to_battery: 1,
battery_to_grid: 0,
used_solar: 0,
used_grid: 0,
used_battery: 0,
solar_to_battery: 0,
solar_to_grid: 1,
used_total: 0,
}
);
});
});