From 2cdc8340e67742250447a9e3c31f5d3dd6f69add Mon Sep 17 00:00:00 2001 From: andig Date: Fri, 29 Jan 2021 17:03:39 +0100 Subject: [PATCH] Fix soc not updated once when car connected (#621) --- core/loadpoint.go | 12 ++++++------ core/loadpoint_test.go | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/core/loadpoint.go b/core/loadpoint.go index b3864166d..aae2c653e 100644 --- a/core/loadpoint.go +++ b/core/loadpoint.go @@ -285,7 +285,7 @@ func (lp *LoadPoint) evChargeStartHandler() { lp.log.INFO.Println("start charging ->") lp.triggerEvent(evChargeStart) - // soc estimation reset + // soc update reset lp.socUpdated = time.Time{} } @@ -294,7 +294,7 @@ func (lp *LoadPoint) evChargeStopHandler() { lp.log.INFO.Println("stop charging <-") lp.triggerEvent(evChargeStop) - // soc estimation reset + // soc update reset lp.socUpdated = time.Time{} } @@ -310,10 +310,10 @@ func (lp *LoadPoint) evVehicleConnectHandler() { lp.connectedTime = lp.clock.Now() lp.publish("connectedDuration", time.Duration(0)) - // soc estimation reset + // soc update reset lp.socUpdated = time.Time{} - // soc estimation reset on car change + // soc update reset on car change if lp.socEstimator != nil { lp.socEstimator.Reset() } @@ -339,7 +339,7 @@ func (lp *LoadPoint) evVehicleDisconnectHandler() { _ = lp.SetTargetSoC(lp.OnDisconnect.TargetSoC) } - // soc estimation reset + // soc update reset lp.socUpdated = time.Time{} } @@ -817,7 +817,7 @@ func (lp *LoadPoint) socPollAllowed() bool { lp.log.DEBUG.Printf("next soc poll remaining time: %v", remaining.Truncate(time.Second)) } - res := lp.charging() || honourUpdateInterval && (lp.socUpdated.IsZero() || remaining <= 0) + res := lp.charging() || honourUpdateInterval && (remaining <= 0) || lp.connected() && lp.socUpdated.IsZero() if res { lp.socUpdated = lp.clock.Now() } diff --git a/core/loadpoint_test.go b/core/loadpoint_test.go index 2324f5ff2..5424c64b8 100644 --- a/core/loadpoint_test.go +++ b/core/loadpoint_test.go @@ -644,7 +644,7 @@ func TestSoCPoll(t *testing.T) { {pollCharging, api.StatusA, -1, false}, {pollCharging, api.StatusA, 0, false}, {pollCharging, api.StatusA, tRefresh, false}, - {pollCharging, api.StatusB, -1, false}, + {pollCharging, api.StatusB, -1, true}, // poll once when car connected {pollCharging, api.StatusB, 0, false}, {pollCharging, api.StatusB, tRefresh, false}, {pollCharging, api.StatusC, -1, true},