From 5cc4c146ee13f52e2aa68f13d241343eae4c14f4 Mon Sep 17 00:00:00 2001 From: Michael Geers Date: Sun, 3 Sep 2023 16:29:13 +0200 Subject: [PATCH] Restore vehicle onIdentify behavior for targetSoc from yaml (#9685) * Fix vehicle onIdentify for targetSoc * fix onDisconnect behavior if config exists; update tests * deprecated config-based minsoc; api/ui only setting * fix tests --- api/actionconfig.go | 2 +- api/actionconfig_test.go | 3 --- core/loadpoint.go | 8 ++++++-- core/loadpoint_vehicle_test.go | 17 ++++++----------- 4 files changed, 13 insertions(+), 17 deletions(-) diff --git a/api/actionconfig.go b/api/actionconfig.go index 0080a7b6b..ea13b3246 100644 --- a/api/actionconfig.go +++ b/api/actionconfig.go @@ -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 } diff --git a/api/actionconfig_test.go b/api/actionconfig_test.go index 1286b8ef4..e2e401d65 100644 --- a/api/actionconfig_test.go +++ b/api/actionconfig_test.go @@ -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") } diff --git a/core/loadpoint.go b/core/loadpoint.go index 178ed9ab0..bec4bc3ea 100644 --- a/core/loadpoint.go +++ b/core/loadpoint.go @@ -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) } diff --git a/core/loadpoint_vehicle_test.go b/core/loadpoint_vehicle_test.go index 33b240bfd..9e7473d86 100644 --- a/core/loadpoint_vehicle_test.go +++ b/core/loadpoint_vehicle_test.go @@ -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