Skip to content

Commit

Permalink
Always treat charger as enabled when charging (#9570)
Browse files Browse the repository at this point in the history
  • Loading branch information
GrimmiMeloni authored Aug 29, 2023
1 parent 8095a7c commit b28c7b5
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 8 deletions.
17 changes: 9 additions & 8 deletions core/loadpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -640,6 +640,15 @@ func (lp *Loadpoint) syncCharger() error {
lp.publish("enabled", lp.enabled)
}()

if !enabled && lp.charging() {
if lp.guardGracePeriodElapsed() {
lp.log.WARN.Println("charger logic error: disabled but charging")
}
enabled = true // treat as enabled when charging
lp.elapseGuard()
return nil
}

// status in sync
if enabled == lp.enabled {
// sync max current
Expand Down Expand Up @@ -671,14 +680,6 @@ func (lp *Loadpoint) syncCharger() error {
return nil
}

if !enabled && lp.charging() {
if lp.guardGracePeriodElapsed() {
lp.log.WARN.Println("charger logic error: disabled but charging")
}
lp.elapseGuard()
return nil
}

return nil
}

Expand Down
45 changes: 45 additions & 0 deletions core/loadpoint_sync_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package core

import (
"testing"

"github.com/benbjohnson/clock"
"github.com/evcc-io/evcc/api"
"github.com/evcc-io/evcc/mock"
"github.com/evcc-io/evcc/util"
"github.com/golang/mock/gomock"
"github.com/stretchr/testify/assert"
)

func TestSyncCharger(t *testing.T) {
tc := []struct {
status api.ChargeStatus
expected, actual, corrected bool
}{
{api.StatusA, false, false, false},
{api.StatusC, false, false, true}, // disabled but charging
{api.StatusA, false, true, true},
{api.StatusA, true, false, false},
{api.StatusA, true, true, true},
}

ctrl := gomock.NewController(t)

for _, tc := range tc {
t.Logf("%+v", tc)

charger := mock.NewMockCharger(ctrl)
charger.EXPECT().Enabled().Return(tc.actual, nil).AnyTimes()

lp := &Loadpoint{
log: util.NewLogger("foo"),
clock: clock.New(),
charger: charger,
status: tc.status,
enabled: tc.expected,
}

assert.NoError(t, lp.syncCharger())
assert.Equal(t, tc.corrected, lp.enabled)
}
}

0 comments on commit b28c7b5

Please sign in to comment.