Skip to content

Commit

Permalink
Restore vehicle onIdentify behavior for targetSoc from yaml (#9685)
Browse files Browse the repository at this point in the history
* Fix vehicle onIdentify for targetSoc

* fix onDisconnect behavior if config exists; update tests

* deprecated config-based minsoc; api/ui only setting

* fix tests
  • Loading branch information
naltatis authored Sep 3, 2023
1 parent b5b490f commit 5cc4c14
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 17 deletions.
2 changes: 1 addition & 1 deletion api/actionconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ type ActionConfig struct {
Mode *ChargeMode `mapstructure:"mode,omitempty"` // Charge Mode
MinCurrent *float64 `mapstructure:"minCurrent,omitempty"` // Minimum Current
MaxCurrent *float64 `mapstructure:"maxCurrent,omitempty"` // Maximum Current
MinSoc *int `mapstructure:"minSoc,omitempty"` // Minimum Soc
MinSoc_ *int `mapstructure:"minSoc,omitempty"` // Minimum Soc (deprecated)
TargetSoc *int `mapstructure:"targetSoc,omitempty"` // Target Soc
Priority *int `mapstructure:"priority,omitempty"` // Priority
}
Expand Down
3 changes: 0 additions & 3 deletions api/actionconfig_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,8 @@ func TestMerge(t *testing.T) {

now := ModeNow
two := 2
three := 3
new := ActionConfig{
Mode: &now,
MinSoc: &three,
Priority: &two,
}

Expand All @@ -38,7 +36,6 @@ func TestMerge(t *testing.T) {
assert.Equal(t, dst, ActionConfig{
Mode: &now,
MinCurrent: &six,
MinSoc: &three,
Priority: &two,
}, "new wrong")
}
8 changes: 6 additions & 2 deletions core/loadpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -317,12 +317,13 @@ func (lp *Loadpoint) collectDefaults() {
*actionCfg.Mode = lp.GetMode()
*actionCfg.MinCurrent = lp.GetMinCurrent()
*actionCfg.MaxCurrent = lp.GetMaxCurrent()
*actionCfg.MinSoc = lp.GetMinSoc()
*actionCfg.TargetSoc = lp.GetTargetSoc()
*actionCfg.Priority = lp.GetPriority()
} else {
lp.log.ERROR.Printf("error allocating action config: %v", err)
}
// deprecated: do not reapply deprecated lp config values
actionCfg.TargetSoc = nil
actionCfg.MinSoc_ = nil
}

// requestUpdate requests site to update this loadpoint
Expand Down Expand Up @@ -552,6 +553,9 @@ func (lp *Loadpoint) applyAction(actionCfg api.ActionConfig) {
if min := actionCfg.MinCurrent; min != nil && *min >= *lp.onDisconnect.MinCurrent {
lp.SetMinCurrent(*min)
}
if actionCfg.TargetSoc != nil {
lp.SetTargetSoc(*actionCfg.TargetSoc)
}
if max := actionCfg.MaxCurrent; max != nil && *max <= *lp.onDisconnect.MaxCurrent {
lp.SetMaxCurrent(*max)
}
Expand Down
17 changes: 6 additions & 11 deletions core/loadpoint_vehicle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,6 @@ func TestDefaultVehicle(t *testing.T) {
ctrl := gomock.NewController(t)

mode := api.ModePV
minsoc := 20
targetsoc := 80

dflt := mock.NewMockVehicle(ctrl)
Expand All @@ -158,7 +157,6 @@ func TestDefaultVehicle(t *testing.T) {
dflt.EXPECT().Phases().AnyTimes()
dflt.EXPECT().OnIdentified().Return(api.ActionConfig{
Mode: &mode,
MinSoc: &minsoc,
TargetSoc: &targetsoc,
}).AnyTimes()

Expand All @@ -175,13 +173,10 @@ func TestDefaultVehicle(t *testing.T) {
// ondisconnect
off := api.ModeOff
zero := 0
hundred := 100
onDisconnect := api.ActionConfig{
Mode: &off,
MinCurrent: &lp.MinCurrent,
MaxCurrent: &lp.MaxCurrent,
MinSoc: &zero,
TargetSoc: &hundred,
Priority: &zero,
}

Expand Down Expand Up @@ -227,13 +222,12 @@ func TestDefaultVehicle(t *testing.T) {
func TestApplyVehicleDefaults(t *testing.T) {
ctrl := gomock.NewController(t)

newConfig := func(mode api.ChargeMode, minCurrent, maxCurrent float64, minSoc, targetSoc int) api.ActionConfig {
newConfig := func(mode api.ChargeMode, minCurrent, maxCurrent float64, targetSoc *int) api.ActionConfig {
return api.ActionConfig{
Mode: &mode,
MinCurrent: &minCurrent,
MaxCurrent: &maxCurrent,
MinSoc: &minSoc,
TargetSoc: &targetSoc,
TargetSoc: targetSoc,
}
}

Expand All @@ -244,10 +238,11 @@ func TestApplyVehicleDefaults(t *testing.T) {
}

// onIdentified config
oi := newConfig(api.ModePV, 7, 15, 1, 99)
targetSoc := 99
oi := newConfig(api.ModePV, 7, 15, &targetSoc)

// onDefault config
od := newConfig(api.ModeOff, 6, 16, 2, 98)
od := newConfig(api.ModeOff, 6, 16, nil)

vehicle := mock.NewMockVehicle(ctrl)
vehicle.EXPECT().Title().Return("it's me").AnyTimes()
Expand All @@ -266,7 +261,7 @@ func TestApplyVehicleDefaults(t *testing.T) {
lp.ResetOnDisconnect = true

// check loadpoint default currents can't be violated
lp.applyAction(newConfig(*od.Mode, 5, 17, *od.MinSoc, *od.TargetSoc))
lp.applyAction(newConfig(*od.Mode, 5, 17, od.TargetSoc))
assertConfig(lp, od)

// vehicle identified
Expand Down

0 comments on commit 5cc4c14

Please sign in to comment.