Reset MinSoC Before Vehicle Change (#4321)

This commit is contained in:
Michael Geers 2022-09-08 09:06:15 +02:00 • committed by GitHub
parent df1e52f41b
commit 48926cfc30
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 3 deletions

View file

@ -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{}

View file

@ -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()
}
}