Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .changeset/declined-car-not-empty-plan.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
"ftw": patch
---

A car that stopped asking for charge while FTW offered it now reads "Car not
taking power" instead of "Waiting for the plan". The plan leaves such a car
out for the rest of the session, so the old text blamed an empty plan for a
stop the car made. Nothing else changes: unplugging, a higher goal, Charge
now, measured charging, or a car on a finish-at-limit goal reporting that it
is charging still lets FTW offer current again, and the battery level is never
guessed from the stop.
22 changes: 13 additions & 9 deletions go/internal/api/api_vehicle_stopped_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,16 +105,20 @@ func TestVehicleStopBlipKeepsFailedStartVerdict(t *testing.T) {
}

// Core's own 0 W stop for a car that stopped asking is Core in control.
// Under that 0 A an Easee reports the car as asking again (srcfl/ftw#2080);
// the verdict stays Core's stop either way.
func TestCoreStopForANotRequestingCarIsFollowing(t *testing.T) {
synctest.Test(t, func(t *testing.T) {
e := &vehicleStopTrace{evTrace: newEVTrace(0), stopped: true}
for range 60 / 5 {
e.tick(0, "vehicle_not_requesting")
}
if f := e.verdict(t); f.Reason != "vehicle_not_requesting" || f.Status != "following" || f.Evidence != "measured" {
t.Fatalf("Core's own stop: %+v", f)
}
})
for _, stopped := range []bool{true, false} {
synctest.Test(t, func(t *testing.T) {
e := &vehicleStopTrace{evTrace: newEVTrace(0), stopped: stopped}
for range 60 / 5 {
e.tick(0, "vehicle_not_requesting")
}
if f := e.verdict(t); f.Reason != "vehicle_not_requesting" || f.Status != "following" || f.Evidence != "measured" {
t.Fatalf("Core's own stop, charger says stopped=%v: %+v", stopped, f)
}
})
}
}

func TestVehicleStopNeverOverridesStaleFailedOrContradictoryEvidence(t *testing.T) {
Expand Down
7 changes: 7 additions & 0 deletions go/internal/loadpoint/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -1554,6 +1554,13 @@ func (c *Controller) tickOne(ctx context.Context, now time.Time, lpCfg Config, s
// 0 W standdown so the charger pauses cleanly.
cmdW = 0
cmdReason = "no_plan_budget"
// No budget for a car that declined current this session
// (Manager.observe latches it): the planner leaves it out, and
// with no plan or no directive the reason holds as well. The
// stop is Core's, for that car, not an empty plan.
if st, ok := c.manager.State(lpCfg.ID); ok && st.ChargingDeclined {
cmdReason = "vehicle_not_requesting"
}
}
finishW, finishing := c.vehicleCompletionOffer(lpCfg, now)
if finishing {
Expand Down
48 changes: 48 additions & 0 deletions go/internal/loadpoint/controller_commanded_reason_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,54 @@ func TestCommandedReasonNoPlanBudget(t *testing.T) {
}
}

// srcfl/ftw#2080: a car with a goal and a deadline stopped asking for current
// while the plan offered it. Once that lasts SessionCompletionTimeout the
// planner leaves the car out for the session, so its slots carry no energy.
// Easee then reports request_active again, because Core's own 0 A is what it
// sees. The stop is Core's, for a car that declined; "no_plan_budget" says
// the plan simply chose not to charge, which is not why.
func TestCommandedReasonDeclinedCarIsNotAnEmptyPlan(t *testing.T) {
base := time.Date(2026, 11, 24, 22, 0, 0, 0, time.UTC)
clock := base
sender := &fakeSender{}
cfg := reasonLoadpoint()
dir := &Directive{
SlotStart: base.Add(-time.Second),
SlotEnd: base.Add(15 * time.Minute),
LoadpointEnergyWh: map[string]float64{cfg.ID: 2750},
}
samples := map[string]EVSample{cfg.DriverName: {Connected: true, PowerW: 11000, RequestActive: true}}
c := newTestController(t, []Config{cfg}, dir, samples, sender)
c.manager.SetNowFn(func() time.Time { return clock })
c.manager.SetTarget(cfg.ID, 1, base.Add(9*time.Hour))

c.Tick(context.Background(), clock)
if w, r := commandedReason(t, c, cfg.ID); w <= 0 || r != "plan" {
t.Fatalf("charging to plan: got (%.0f, %q)", w, r)
}

// The car stops asking while the plan still offers current.
samples[cfg.DriverName] = EVSample{Connected: true, PowerW: 0, RequestActive: false}
for clock.Sub(base) <= SessionCompletionTimeout+10*time.Second {
clock = clock.Add(5 * time.Second)
c.Tick(context.Background(), clock)
}
if st, _ := c.manager.State(cfg.ID); !st.ChargingDeclined {
t.Fatalf("lasting refusal under a live offer did not latch: %+v", st)
}

// The next plan leaves the car out. Core holds 0 A and the charger
// reports the car as asking again.
dir.LoadpointEnergyWh = map[string]float64{}
samples[cfg.DriverName] = EVSample{Connected: true, PowerW: 0, RequestActive: true}
clock = clock.Add(5 * time.Second)
c.Tick(context.Background(), clock)

if w, r := commandedReason(t, c, cfg.ID); w != 0 || r != "vehicle_not_requesting" {
t.Errorf("declined car left out of the plan: want (0, vehicle_not_requesting), got (%.0f, %q)", w, r)
}
}

func TestCommandedReasonPlan(t *testing.T) {
base := time.Date(2026, 8, 30, 12, 0, 0, 0, time.UTC)
sender := &fakeSender{}
Expand Down
Loading