From 48926cfc30f0a0e197fa0594e745ef3072697797 Mon Sep 17 00:00:00 2001 From: Michael Geers Date: Thu, 8 Sep 2022 09:06:15 +0200 Subject: [PATCH] Reset MinSoC Before Vehicle Change (#4321) --- core/loadpoint.go | 4 ++++ core/loadpoint_api.go | 15 ++++++++++++--- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/core/loadpoint.go b/core/loadpoint.go index bb4a05df6..b83fd2903 100644 --- a/core/loadpoint.go +++ b/core/loadpoint.go @@ -817,6 +817,10 @@ func (lp *LoadPoint) setActiveVehicle(vehicle api.Vehicle) { } lp.log.INFO.Printf("vehicle updated: %s -> %s", from, to) + // reset minSoC and targetSoC before change + lp.setMinSoC(0) + lp.setTargetSoC(0) + if lp.vehicle = vehicle; vehicle != nil { lp.socUpdated = time.Time{} diff --git a/core/loadpoint_api.go b/core/loadpoint_api.go index 4f9a879da..d68e76ef5 100644 --- a/core/loadpoint_api.go +++ b/core/loadpoint_api.go @@ -56,9 +56,13 @@ func (lp *LoadPoint) GetTargetSoC() int { return lp.SoC.target } +// setTargetSoC sets loadpoint charge target soc (no mutex) func (lp *LoadPoint) setTargetSoC(soc int) { lp.SoC.target = soc - lp.socTimer.SoC = soc + // test guard + if lp.socTimer != nil { + lp.socTimer.SoC = soc + } lp.publish("targetSoC", soc) } @@ -83,6 +87,12 @@ func (lp *LoadPoint) GetMinSoC() int { return lp.SoC.min } +// setMinSoC sets loadpoint charge min soc (no mutex) +func (lp *LoadPoint) setMinSoC(soc int) { + lp.SoC.min = soc + lp.publish("minSoC", soc) +} + // SetMinSoC sets loadpoint charge minimum soc func (lp *LoadPoint) SetMinSoC(soc int) { lp.Lock() @@ -92,8 +102,7 @@ func (lp *LoadPoint) SetMinSoC(soc int) { // apply immediately if lp.SoC.min != soc { - lp.SoC.min = soc - lp.publish("minSoC", soc) + lp.setMinSoC(soc) lp.requestUpdate() } }