Restore vehicle onIdentify behavior for targetSoc from yaml (#9685)
Some checks failed
Some checks failed
* Fix vehicle onIdentify for targetSoc * fix onDisconnect behavior if config exists; update tests * deprecated config-based minsoc; api/ui only setting * fix tests
This commit is contained in:
parent
b5b490fbca
commit
5cc4c146ee
4 changed files with 13 additions and 17 deletions
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,10 +18,8 @@ func TestMerge(t *testing.T) {
|
|||
|
||||
now := ModeNow
|
||||
two := 2
|
||||
three := 3
|
||||
new := ActionConfig{
|
||||
Mode: &now,
|
||||
MinSoc: &three,
|
||||
Priority: &two,
|
||||
}
|
||||
|
||||
|
|
@ -38,7 +36,6 @@ func TestMerge(t *testing.T) {
|
|||
assert.Equal(t, dst, ActionConfig{
|
||||
Mode: &now,
|
||||
MinCurrent: &six,
|
||||
MinSoc: &three,
|
||||
Priority: &two,
|
||||
}, "new wrong")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
@ -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)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -148,7 +148,6 @@ func TestDefaultVehicle(t *testing.T) {
|
|||
ctrl := gomock.NewController(t)
|
||||
|
||||
mode := api.ModePV
|
||||
minsoc := 20
|
||||
targetsoc := 80
|
||||
|
||||
dflt := mock.NewMockVehicle(ctrl)
|
||||
|
|
@ -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()
|
||||
|
||||
|
|
@ -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,
|
||||
}
|
||||
|
||||
|
|
@ -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,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -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()
|
||||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue