Planner: fix preconditioning creating empty slots (#26448)

This commit is contained in:
andig 2026-01-05 14:51:03 +01:00 • committed by GitHub
parent 0ba228d0a3
commit 8ef3cce10f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 10 additions and 1 deletions

View file

@ -9,9 +9,18 @@ import (
"github.com/evcc-io/evcc/api"
"github.com/evcc-io/evcc/tariff"
"github.com/samber/lo"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestSlitPrecondition(t *testing.T) {
clock := clock.NewMock()
rr := rates([]float64{1, 2, 3, 4}, clock.Now(), tariff.SlotDuration)
rates, precond := splitPreconditionSlots(rr, clock.Now().Add(3*tariff.SlotDuration))
assert.Equal(t, rr[0:3], rates, "rates")
assert.Equal(t, rr[3:], precond, "precond")
}
func TestSlotHasSuccessor(t *testing.T) {
plan := rates([]float64{20, 60, 10, 80, 40, 90}, time.Now(), time.Hour)

View file

@ -208,7 +208,7 @@ func splitPreconditionSlots(rates api.Rates, preCondStart time.Time) (api.Rates,
}
// split slot
if !r.Start.After(preCondStart) {
if r.Start.Before(preCondStart) {
// keep the first part of the slot
res = append(res, api.Rate{
Start: r.Start,