Battery control: hold battery while min soc not reached (#11941)

This commit is contained in:
rivengh 2024-02-03 13:39:58 +01:00 • committed by GitHub
parent 589da6fa57
commit ed6bd89387
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 37 additions and 37 deletions

View file

@ -120,8 +120,8 @@ type API interface {
// charge progress
//
// GetPlanActive returns the active state of the planner
GetPlanActive() bool
// IsFastChargingActive indicates if fast charging with maximum power is active
IsFastChargingActive() bool
// GetRemainingDuration is the estimated remaining charging duration
GetRemainingDuration() time.Duration
// GetRemainingEnergy is the remaining charge energy in Wh

View file

@ -265,20 +265,6 @@ func (mr *MockAPIMockRecorder) GetPlan(arg0, arg1 any) *gomock.Call {
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetPlan", reflect.TypeOf((*MockAPI)(nil).GetPlan), arg0, arg1)
}
// GetPlanActive mocks base method.
func (m *MockAPI) GetPlanActive() bool {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "GetPlanActive")
ret0, _ := ret[0].(bool)
return ret0
}
// GetPlanActive indicates an expected call of GetPlanActive.
func (mr *MockAPIMockRecorder) GetPlanActive() *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetPlanActive", reflect.TypeOf((*MockAPI)(nil).GetPlanActive))
}
// GetPlanEnergy mocks base method.
func (m *MockAPI) GetPlanEnergy() (time.Time, float64) {
m.ctrl.T.Helper()
@ -407,6 +393,20 @@ func (mr *MockAPIMockRecorder) HasChargeMeter() *gomock.Call {
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "HasChargeMeter", reflect.TypeOf((*MockAPI)(nil).HasChargeMeter))
}
// IsFastChargingActive mocks base method.
func (m *MockAPI) IsFastChargingActive() bool {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "IsFastChargingActive")
ret0, _ := ret[0].(bool)
return ret0
}
// IsFastChargingActive indicates an expected call of IsFastChargingActive.
func (mr *MockAPIMockRecorder) IsFastChargingActive() *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "IsFastChargingActive", reflect.TypeOf((*MockAPI)(nil).IsFastChargingActive))
}
// PublishEffectiveValues mocks base method.
func (m *MockAPI) PublishEffectiveValues() {
m.ctrl.T.Helper()

View file

@ -395,11 +395,12 @@ func (lp *Loadpoint) GetMaxPower() float64 {
return Voltage * lp.effectiveMaxCurrent() * float64(lp.maxActivePhases())
}
// GetPlanActive returns the active state of the planner
func (lp *Loadpoint) GetPlanActive() bool {
lp.Lock()
defer lp.Unlock()
return lp.planActive
// IsFastChargingActive indicates if fast charging with maximum power is active
func (lp *Loadpoint) IsFastChargingActive() bool {
lp.RLock()
defer lp.RUnlock()
return lp.mode == api.ModeNow || lp.planActive || lp.minSocNotReached()
}
// GetRemainingDuration is the estimated remaining charging duration

View file

@ -32,7 +32,7 @@ func (site *Site) SetBatteryMode(batMode api.BatteryMode) {
func (site *Site) determineBatteryMode(loadpoints []loadpoint.API, smartCostActive bool) api.BatteryMode {
for _, lp := range loadpoints {
if lp.GetStatus() == api.StatusC && (smartCostActive || lp.GetMode() == api.ModeNow || lp.GetPlanActive()) {
if lp.GetStatus() == api.StatusC && (smartCostActive || lp.IsFastChargingActive()) {
return api.BatteryHold
}
}

View file

@ -15,19 +15,19 @@ func TestDetermineBatteryMode(t *testing.T) {
ctrl := gomock.NewController(t)
tcs := []struct {
chargeStatus api.ChargeStatus
planActive bool
expBatMode api.BatteryMode
mode api.ChargeMode
chargeStatus api.ChargeStatus
fastChargingActive bool
smartCostActive bool
expBatMode api.BatteryMode
}{
{api.StatusB, false, api.BatteryNormal, api.ModeOff}, // mode off -> bat normal
{api.StatusB, false, api.BatteryNormal, api.ModeNow}, // mode now, not charging -> bat normal
{api.StatusC, false, api.BatteryHold, api.ModeNow}, // mode now, charging -> bat hold
{api.StatusB, false, api.BatteryNormal, api.ModeMinPV}, // mode minPV, not charging -> bat normal
{api.StatusC, false, api.BatteryNormal, api.ModeMinPV}, // mode minPV, charging -> bat normal
{api.StatusB, false, api.BatteryNormal, api.ModePV}, // mode PV, not charging -> bat normal
{api.StatusC, false, api.BatteryNormal, api.ModePV}, // mode PV, charging, no planner -> bat normal
{api.StatusC, true, api.BatteryHold, api.ModePV}, // mode PV, charging, planner active -> bat hold
{api.StatusB, false, false, api.BatteryNormal}, // not charging | fast charge not active | smart cost not active -> bat normal
{api.StatusB, true, false, api.BatteryNormal}, // not charging | fast charge active | smart cost not active -> bat normal
{api.StatusC, false, false, api.BatteryNormal}, // charging | fast charge not active | smart cost not active -> bat normal
{api.StatusC, true, false, api.BatteryHold}, // charging | fast charge active | smart cost not active -> bat hold
{api.StatusB, false, true, api.BatteryNormal}, // not charging | fast charge not active | smart cost active -> bat normal
{api.StatusB, true, true, api.BatteryNormal}, // not charging | fast charge active | smart cost active -> bat normal
{api.StatusC, false, true, api.BatteryHold}, // charging | fast charge not active | smart cost active -> bat hold
{api.StatusC, true, true, api.BatteryHold}, // charging | fast charge active | smart cost active -> bat hold
}
log := util.NewLogger("foo")
@ -39,12 +39,11 @@ func TestDetermineBatteryMode(t *testing.T) {
lp := loadpoint.NewMockAPI(ctrl)
lp.EXPECT().GetStatus().Return(tc.chargeStatus).AnyTimes()
lp.EXPECT().GetMode().Return(tc.mode).AnyTimes()
lp.EXPECT().GetPlanActive().Return(tc.planActive).AnyTimes()
lp.EXPECT().IsFastChargingActive().Return(tc.fastChargingActive).AnyTimes()
loadpoints := []loadpoint.API{lp}
mode := s.determineBatteryMode(loadpoints, false)
mode := s.determineBatteryMode(loadpoints, tc.smartCostActive)
assert.Equal(t, tc.expBatMode, mode, tc)
}
}