Fix determining required battery mode (#15255)
This commit is contained in:
parent
f0117ce2a3
commit
b1293cdf3f
2 changed files with 32 additions and 2 deletions
|
|
@ -41,8 +41,8 @@ func (site *Site) requiredBatteryMode(batteryGridChargeActive bool, rate api.Rat
|
|||
batMode := site.GetBatteryMode()
|
||||
|
||||
switch {
|
||||
case batteryGridChargeActive && batMode != api.BatteryCharge:
|
||||
res = api.BatteryCharge
|
||||
case batteryGridChargeActive:
|
||||
res = map[bool]api.BatteryMode{false: api.BatteryCharge, true: api.BatteryUnknown}[batMode == api.BatteryCharge]
|
||||
case !batteryGridChargeActive && site.dischargeControlActive(rate) && batMode != api.BatteryHold:
|
||||
res = api.BatteryHold
|
||||
case batteryModeModified(batMode):
|
||||
|
|
|
|||
|
|
@ -3,7 +3,9 @@ package core
|
|||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/evcc-io/evcc/api"
|
||||
"github.com/evcc-io/evcc/util"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestSitePower(t *testing.T) {
|
||||
|
|
@ -143,3 +145,31 @@ func TestGreenShare(t *testing.T) {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestRequiredBatteryMode(t *testing.T) {
|
||||
tc := []struct {
|
||||
gridChargeActive bool
|
||||
mode, res api.BatteryMode
|
||||
}{
|
||||
{false, api.BatteryUnknown, api.BatteryUnknown}, // ignore
|
||||
{false, api.BatteryNormal, api.BatteryUnknown}, // ignore
|
||||
{false, api.BatteryHold, api.BatteryNormal},
|
||||
{false, api.BatteryCharge, api.BatteryNormal},
|
||||
|
||||
{true, api.BatteryUnknown, api.BatteryCharge},
|
||||
{true, api.BatteryNormal, api.BatteryCharge},
|
||||
{true, api.BatteryHold, api.BatteryCharge},
|
||||
{true, api.BatteryCharge, api.BatteryUnknown}, // ignore
|
||||
}
|
||||
|
||||
for _, tc := range tc {
|
||||
t.Logf("%+vv", tc)
|
||||
|
||||
s := &Site{
|
||||
batteryMode: tc.mode,
|
||||
}
|
||||
|
||||
res := s.requiredBatteryMode(tc.gridChargeActive, api.Rate{})
|
||||
assert.Equal(t, tc.res, res, "expected %s, got %s", tc.res, res)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue