From 89efcb6e6405133fe4c6ab2e05acaa7ff7ee49aa Mon Sep 17 00:00:00 2001 From: andig Date: Wed, 2 Mar 2022 11:30:35 +0100 Subject: [PATCH] Use maximum possible phases for scale-up calculation (#2753) --- core/loadpoint.go | 2 +- core/loadpoint_phases_test.go | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/core/loadpoint.go b/core/loadpoint.go index 219db3cf7..ac91119ee 100644 --- a/core/loadpoint.go +++ b/core/loadpoint.go @@ -1079,7 +1079,7 @@ func (lp *LoadPoint) pvScalePhases(availablePower, minCurrent, maxCurrent float6 scalable := maxPhases > 1 && phases < maxPhases // scale up phases - if min3pCurrent := powerToCurrent(availablePower, 3); min3pCurrent >= minCurrent && scalable { + if min3pCurrent := powerToCurrent(availablePower, maxPhases); min3pCurrent >= minCurrent && scalable { lp.log.DEBUG.Printf("available power %.0fW > %.0fW min %dp threshold", availablePower, 3*Voltage*minCurrent, maxPhases) if lp.phaseTimer.IsZero() { diff --git a/core/loadpoint_phases_test.go b/core/loadpoint_phases_test.go index d98eb1ee9..ac764126c 100644 --- a/core/loadpoint_phases_test.go +++ b/core/loadpoint_phases_test.go @@ -162,9 +162,12 @@ func TestPvScalePhases(t *testing.T) { ctrl.Finish() // scale up - min3p := 3 * minA * Voltage + min3p := float64(tc.maxExpected) * minA * Voltage lp.phaseTimer = time.Time{} - lp.Phases = tc.physical // reset to initial state + + // reset to initial state + lp.Phases = tc.physical + lp.measuredPhases = tc.measuredPhases plainCharger.EXPECT().Enable(false).Return(nil).MaxTimes(1) phaseCharger.EXPECT().Phases1p3p(3).Return(nil).MaxTimes(1)