Skip to content

Commit

Permalink
Restore persistence of limit soc and energy (#10979)
Browse files Browse the repository at this point in the history
  • Loading branch information
andig authored Dec 8, 2023
1 parent 219dacd commit ff38abf
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 8 deletions.
6 changes: 6 additions & 0 deletions core/loadpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,12 @@ func (lp *Loadpoint) restoreSettings() {
if v, err := lp.settings.Float(keys.PlanEnergy); err == nil {
lp.planEnergy = v
}
if v, err := lp.settings.Int(keys.LimitSoc); err == nil {
lp.limitSoc = int(v)
}
if v, err := lp.settings.Float(keys.LimitEnergy); err == nil {
lp.limitEnergy = v
}
}

// requestUpdate requests site to update this loadpoint
Expand Down
2 changes: 2 additions & 0 deletions core/loadpoint_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ func (lp *Loadpoint) GetLimitSoc() int {
func (lp *Loadpoint) setLimitSoc(soc int) {
lp.limitSoc = soc
lp.publish(keys.LimitSoc, soc)
lp.settings.SetInt(keys.LimitSoc, int64(soc))
}

// SetLimitSoc sets the session soc limit
Expand Down Expand Up @@ -163,6 +164,7 @@ func (lp *Loadpoint) GetLimitEnergy() float64 {
func (lp *Loadpoint) setLimitEnergy(energy float64) {
lp.limitEnergy = energy
lp.publish(keys.LimitEnergy, energy)
lp.settings.SetFloat(keys.LimitEnergy, energy)
}

// SetLimitEnergy sets the session energy limit
Expand Down
6 changes: 0 additions & 6 deletions core/loadpoint_vehicle.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,12 +121,6 @@ func (lp *Loadpoint) setActiveVehicle(v api.Vehicle) {
lp.log.INFO.Printf("vehicle updated: %s -> %s", from, to)
}

// reset session values
lp.Lock()
lp.setLimitSoc(0)
lp.setLimitEnergy(0)
lp.Unlock()

if v != nil {
lp.socUpdated = time.Time{}

Expand Down
4 changes: 2 additions & 2 deletions tests/limits.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ test.describe("limitEnergy", async () => {
await page.reload();
await expect(page.getByTestId("limit-energy-value")).toHaveText("10 kWh");
});
test("should be reset on vehicle change", async ({ page }) => {
test("should not be reset on vehicle change", async ({ page }) => {
await page.goto("/");

await page.getByRole("button", { name: "blauer e-Golf" }).click();
Expand All @@ -107,6 +107,6 @@ test.describe("limitEnergy", async () => {

await page.getByRole("button", { name: "grüner Honda e" }).click();
await page.getByRole("button", { name: "Guest vehicle" }).click();
await expect(page.getByTestId("limit-energy-value")).toHaveText("none");
await expect(page.getByTestId("limit-energy-value")).toHaveText("10 kWh");
});
});

0 comments on commit ff38abf

Please sign in to comment.