Always treat charger as enabled when charging (#9570)
This commit is contained in:
parent
8095a7c7d7
commit
b28c7b516b
2 changed files with 54 additions and 8 deletions
|
|
@ -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
|
||||
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
|||
45
core/loadpoint_sync_test.go
Normal file
45
core/loadpoint_sync_test.go
Normal file
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue