Skip to content

Commit

Permalink
1p3p: fix switching and add more tests (evcc-io#1624)
Browse files Browse the repository at this point in the history
  • Loading branch information
andig authored Sep 23, 2021
1 parent 9fca67b commit 658b879
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 11 deletions.
21 changes: 11 additions & 10 deletions core/loadpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -803,16 +803,16 @@ func (lp *LoadPoint) updateChargerStatus() error {

// effectiveCurrent returns the currently effective charging current
func (lp *LoadPoint) effectiveCurrent() float64 {
if lp.GetStatus() != api.StatusC {
return 0
}

// adjust actual current for vehicles like Zoe where it remains below target
if lp.chargeCurrents != nil {
cur := lp.chargeCurrents[0]
return math.Min(cur+2.0, lp.chargeCurrent)
}

if lp.GetStatus() != api.StatusC {
return 0
}

return lp.chargeCurrent
}

Expand Down Expand Up @@ -880,16 +880,17 @@ func (lp *LoadPoint) scalePhases(phases int) error {

// pvScalePhases switches phases if necessary and returns if switch occurred
func (lp *LoadPoint) pvScalePhases(availablePower, minCurrent, maxCurrent float64) bool {
var waiting bool

// correct charger state inconsistency (https://github.com/evcc-io/evcc/issues/1572)
phases := lp.GetPhases()
targetCurrent := availablePower / Voltage / float64(lp.activePhases)

// ignore charger state inconsistency if switchable (https://github.com/evcc-io/evcc/issues/1572)
if _, ok := lp.charger.(api.ChargePhases); !ok && phases < lp.activePhases {
lp.log.WARN.Printf("charger out of sync: %dp active @ %dp configured", lp.activePhases, phases)
if phases < lp.activePhases {
phases = 3
lp.setPhases(3)
}

var waiting bool
targetCurrent := availablePower / Voltage / float64(lp.activePhases)

// scale down phases
if targetCurrent < minCurrent && phases > 1 && lp.activePhases > 1 {
lp.log.DEBUG.Printf("available power below %dp min threshold of %.0fW", lp.activePhases, float64(lp.activePhases)*Voltage*minCurrent)
Expand Down
11 changes: 10 additions & 1 deletion core/loadpoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -882,7 +882,16 @@ func TestScalePhases(t *testing.T) {
{"3/3->1, timer elapsed", 3, 3, 1 * Voltage * maxA, 1, true, func(lp *LoadPoint) {
lp.phaseTimer = lp.clock.Now().Add(-dt)
}},
{"3/3->1, switch executed", 1, 3, 1 * Voltage * maxA, 1, false, func(lp *LoadPoint) {

// error states from 1p/3p misconfig
{"1/3->1, enough power", 1, 3, 1 * Voltage * maxA, 3, false, nil},
{"1/3->1, kickoff, correct phase setting", 1, 3, 1 * Voltage * maxA, 3, false, func(lp *LoadPoint) {
lp.phaseTimer = time.Time{}
}},
{"1/3->1, timer running, correct phase setting", 1, 3, 1 * Voltage * maxA, 3, false, func(lp *LoadPoint) {
lp.phaseTimer = lp.clock.Now()
}},
{"1/3->1, switch executed", 1, 3, 1 * Voltage * maxA, 1, true, func(lp *LoadPoint) {
lp.phaseTimer = lp.clock.Now().Add(-dt)
}},
}
Expand Down

0 comments on commit 658b879

Please sign in to comment.