Planner: skip any reached plans (#20414)

This commit is contained in:
andig 2025-04-05 18:40:28 +02:00 • committed by GitHub
parent bdd83d9d88
commit c91bc6240c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 30 additions and 7 deletions

View file

@ -49,8 +49,10 @@ func (lp *Loadpoint) nextActivePlan(maxPower float64, plans []plan) *plan {
return i.Start.Compare(j.Start)
})
if len(plans) > 0 {
return &plans[0]
for _, p := range plans {
if lp.vehicleSoc == 0 || lp.vehicleSoc < float64(p.Soc) {
return &p
}
}
return nil

View file

@ -81,27 +81,48 @@ func TestNextPlan(t *testing.T) {
for _, tc := range []struct {
planId int
soc int
plans []plan
}{
{1, []plan{
{1, 0, []plan{
{Id: 1, End: clock.Now().Add(8 * time.Hour), Soc: 10},
{Id: 2, End: clock.Now().Add(10 * time.Hour), Soc: 10},
}},
{1, []plan{
{0, 20, []plan{
{Id: 1, End: clock.Now().Add(8 * time.Hour), Soc: 10},
{Id: 2, End: clock.Now().Add(10 * time.Hour), Soc: 10},
}},
{1, 0, []plan{
{Id: 1, End: clock.Now().Add(8 * time.Hour), Soc: 20},
{Id: 2, End: clock.Now().Add(9 * time.Hour), Soc: 20},
}},
{2, []plan{
{2, 0, []plan{
{Id: 2, End: clock.Now().Add(8 * time.Hour), Soc: 20},
{Id: 1, End: clock.Now().Add(9 * time.Hour), Soc: 20},
}},
{2, []plan{
{2, 0, []plan{
{Id: 1, End: clock.Now().Add(8 * time.Hour), Soc: 10},
{Id: 2, End: clock.Now().Add(10 * time.Hour), Soc: 60},
}},
{1, 5, []plan{
{Id: 1, End: clock.Now().Add(8 * time.Hour), Soc: 10},
{Id: 2, End: clock.Now().Add(10 * time.Hour), Soc: 20},
}},
{2, 15, []plan{
{Id: 1, End: clock.Now().Add(8 * time.Hour), Soc: 10},
{Id: 2, End: clock.Now().Add(10 * time.Hour), Soc: 20},
}},
} {
lp.vehicleSoc = float64(tc.soc)
res := lp.nextActivePlan(1e4, tc.plans)
require.NotNil(t, res)
if tc.planId == 0 {
require.Nil(t, res, tc)
continue
}
require.NotNil(t, res, tc)
assert.Equal(t, tc.planId, res.Id)
}
}