From 61cee08873d8a735d1b4188fb158bc3bfd2f6a52 Mon Sep 17 00:00:00 2001 From: Fredrik Ahlgren Date: Tue, 27 Oct 2026 19:36:30 +0100 Subject: [PATCH 1/3] fix(loadpoint): an idle 1p or auto pool starts on room for 6 A (C6) FuseConfigs named the tick's phase mode but kept the configured minimum, so EVFuseBudget made an idle 1p or auto pool wait for the three-phase minimum (4,140 W) of room on one phase. On a 16 A fuse that room never exists. FuseConfigs now applies fuseConfig, as freezeFuseBudget and applyFuseClamp already do. Co-Authored-By: Claude Opus 5.5 --- .changeset/c6-idle-one-phase-start.md | 5 ++ .../control/ev_fuse_one_phase_start_test.go | 63 +++++++++++++++++++ .../loadpoint/controller_fuse_budget.go | 9 ++- 3 files changed, 74 insertions(+), 3 deletions(-) create mode 100644 .changeset/c6-idle-one-phase-start.md create mode 100644 go/internal/control/ev_fuse_one_phase_start_test.go diff --git a/.changeset/c6-idle-one-phase-start.md b/.changeset/c6-idle-one-phase-start.md new file mode 100644 index 000000000..226e1249e --- /dev/null +++ b/.changeset/c6-idle-one-phase-start.md @@ -0,0 +1,5 @@ +--- +"ftw": patch +--- + +Start Charge now on one phase once there is room for 6 A on that phase. An idle charger set to `1p` or `auto` on a three-phase site waited for room for the three-phase minimum (4,140 W) on a single phase, so it never started on a 16 A fuse and rarely on 25 A. It now waits for room for its own least order, 1,380 W. diff --git a/go/internal/control/ev_fuse_one_phase_start_test.go b/go/internal/control/ev_fuse_one_phase_start_test.go new file mode 100644 index 000000000..0bfbbb92c --- /dev/null +++ b/go/internal/control/ev_fuse_one_phase_start_test.go @@ -0,0 +1,63 @@ +package control + +import ( + "testing" + "time" + + "github.com/srcfl/ftw/go/internal/loadpoint" +) + +// C6 (rig seeds 207534, 207536, 207537, 207531): an idle pool whose order +// lands on one phase needs room for 6 A on that phase, not for the +// configured three-phase minimum of 4,140 W. Without that, Charge now on 1p +// or auto never starts on a 16 A fuse ("below minimum step … fuse_cap_w=0 +// min_step_w=1380"). +func TestIdleOnePhasePoolStartsOnSixAmpsOfRoom(t *testing.T) { + steps := []float64{0, 1380, 1610, 1840, 2070, 2300, 2530, 2760, 2990, 3220, 3450, 3680, + 4140, 4830, 5520, 6210, 6900, 7590, 8280, 8970, 9660, 10350, 11040} + for _, tc := range []struct { + name string + fuseA float64 + houseA float64 + mode string + holdW float64 + }{ + {"16A 1p", 16, 4.5, "1p", 3680}, + {"25A 1p", 25, 13.7, "1p", 3680}, + {"16A auto", 16, 4.5, "auto", 3680}, + {"25A auto", 25, 13.7, "auto", 3680}, + } { + t.Run(tc.name, func(t *testing.T) { + cfg := loadpoint.Config{ID: "garage", DriverName: "easee", MinChargeW: 4140, MaxChargeW: 11040, + PhaseMode: "auto", AllowedStepsW: steps} + s := newPhaseSite(t, cfg, tc.houseA) + fuseW := tc.fuseA * 230 * 3 + s.state.SiteFuseAmps = tc.fuseA + s.ctrl.SetSiteFuse(loadpoint.SiteFuse{MaxAmps: tc.fuseA, Voltage: 230, PhaseCnt: 3}) + s.ctrl.SetFuseEVMax(func() (float64, bool) { + return EVFuseBudget(s.store, s.state, s.mgr.States(), s.ctrl.FuseConfigs(), fuseW) + }) + s.ctrl.SetManualHold(cfg.ID, loadpoint.ManualHold{PowerW: tc.holdW, PhaseMode: tc.mode, Persistent: true}) + start := s.now + deadline := start.Add(evRestartDwell + 5*time.Second) // the dwell plus one 5 s tick + for s.now.Before(deadline) && s.offerW < 1380 { + s.tick() + } + st, _ := s.mgr.State(cfg.ID) + if s.offerW < 1380 { + t.Fatalf("after %s: offer %.0f W, EV cap %.0f W, reason %q; want at least 1380 W", + s.now.Sub(start), s.offerW, s.state.evLimit.capW, st.CommandedReason) + } + t.Logf("started after %s at %.0f W on one phase", s.now.Sub(start), s.offerW) + if !s.offer1p { + t.Fatalf("offer %.0f W runs on three phases; want one", s.offerW) + } + for i := 0; i < 12; i++ { + s.tick() + if s.worstA() > tc.fuseA { + t.Fatalf("offer %.0f W puts %.1f A on a %.0f A fuse", s.offerW, s.worstA(), tc.fuseA) + } + } + }) + } +} diff --git a/go/internal/loadpoint/controller_fuse_budget.go b/go/internal/loadpoint/controller_fuse_budget.go index 9648db10c..477cc13f5 100644 --- a/go/internal/loadpoint/controller_fuse_budget.go +++ b/go/internal/loadpoint/controller_fuse_budget.go @@ -221,13 +221,16 @@ func (c *Controller) phaseRoomCapW(id, mode string, wantW, split, roomA float64) } // FuseConfigs returns the loadpoints with the phase mode each command names -// this tick. control.EVFuseBudget measures room on those phases, so an auto -// or 1p offer never gets three phases of room. Outside a tick, and for a -// loadpoint that gets no command, the configured mode stands. +// this tick, and the least each can order on those phases. +// control.EVFuseBudget measures room on those phases, so an auto or 1p offer +// never gets three phases of room, and an idle pool waits for room for that +// least order, not the configured three-phase minimum. Outside a tick, and +// for a loadpoint that gets no command, the configured mode stands. func (c *Controller) FuseConfigs() []Config { configs := c.manager.Configs() for i := range configs { if mode := c.tickChoices[configs[i].ID].phaseMode; mode != "" { + configs[i] = c.fuseConfig(configs[i], mode) configs[i].PhaseMode = mode } } From 39640d9c74b404f47f3fcfe957be559962e5f12e Mon Sep 17 00:00:00 2001 From: Fredrik Ahlgren Date: Tue, 27 Oct 2026 20:07:12 +0100 Subject: [PATCH 2/3] test(control): pin the one-phase idle start at 6 A of room (C6) On a 16 A fuse, an idle 1p or auto pool must start at exactly 1,380 W when the worst phase leaves 6.0 A of room under the working line, and wait at 5.7 A. The existing test left about 10 A of room, so a hidden margin on the one-phase minimum (7 A instead of 6 A) still passed it. The new cases are set from the working line, so they follow it when #1910 moves it. Co-Authored-By: Claude Opus 5.5 --- .../control/ev_fuse_one_phase_start_test.go | 52 +++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/go/internal/control/ev_fuse_one_phase_start_test.go b/go/internal/control/ev_fuse_one_phase_start_test.go index 0bfbbb92c..4e49aede5 100644 --- a/go/internal/control/ev_fuse_one_phase_start_test.go +++ b/go/internal/control/ev_fuse_one_phase_start_test.go @@ -61,3 +61,55 @@ func TestIdleOnePhasePoolStartsOnSixAmpsOfRoom(t *testing.T) { }) } } + +// The start point is exact: on a 16 A fuse an idle 1p or auto pool starts at +// 1,380 W, its least order, once the worst phase leaves 6 A of room under the +// working line, and waits while it leaves 5.7 A. A hidden margin on the +// one-phase minimum would move the start and fail here. The cases are set +// from the working line, so they follow it if the line moves. +func TestIdleOnePhasePoolStartBoundary(t *testing.T) { + steps := []float64{0, 1380, 1610, 1840, 2070, 2300, 2530, 2760, 2990, 3220, 3450, 3680, + 4140, 4830, 5520, 6210, 6900, 7590, 8280, 8970, 9660, 10350, 11040} + const fuseA = 16.0 + lineA := fuseA - evPhaseMarginA // the EV working line on each phase + site := func(t *testing.T, houseA float64, mode string) *phaseSite { + cfg := loadpoint.Config{ID: "garage", DriverName: "easee", MinChargeW: 4140, MaxChargeW: 11040, + PhaseMode: "auto", AllowedStepsW: steps} + s := newPhaseSite(t, cfg, houseA) + s.state.SiteFuseAmps = fuseA + s.ctrl.SetSiteFuse(loadpoint.SiteFuse{MaxAmps: fuseA, Voltage: 230, PhaseCnt: 3}) + s.ctrl.SetFuseEVMax(func() (float64, bool) { + return EVFuseBudget(s.store, s.state, s.mgr.States(), s.ctrl.FuseConfigs(), fuseA*230*3) + }) + s.ctrl.SetManualHold(cfg.ID, loadpoint.ManualHold{PowerW: 3680, PhaseMode: mode, Persistent: true}) + return s + } + for _, mode := range []string{"1p", "auto"} { + t.Run(mode+" 6.0 A of room starts", func(t *testing.T) { + s := site(t, lineA-6, mode) + start := s.now + for s.now.Sub(start) < evRestartDwell+5*time.Second && s.offerW == 0 { + s.tick() + } + if s.offerW != 1380 || !s.offer1p { + t.Fatalf("worst phase %.1f A: offer %.0f W, one phase %v; want 1380 W on one phase", + lineA-6, s.offerW, s.offer1p) + } + for i := 0; i < 60; i++ { + s.tick() + if s.worstA() > fuseA { + t.Fatalf("tick %d: %.2f A on a %.0f A fuse", i, s.worstA(), fuseA) + } + } + }) + t.Run(mode+" 5.7 A of room waits", func(t *testing.T) { + s := site(t, lineA-5.7, mode) + for i := 0; i < 40; i++ { + s.tick() + if s.offerW != 0 { + t.Fatalf("tick %d: offer %.0f W with 5.7 A of room; want 0", i, s.offerW) + } + } + }) + } +} From 78f357fe8aafdc40d6cf8a6017bc729df2b41b7e Mon Sep 17 00:00:00 2001 From: Fredrik Ahlgren Date: Wed, 28 Oct 2026 01:45:33 +0100 Subject: [PATCH 3/3] test(control): read the working line from the budget in the C6 boundary test The boundary test named evPhaseMarginA, which #1910 removes. The two PRs merge with no text conflict, so whichever landed second would break the control package's test build on master. The test now reads the line from EVFuseBudget's own report on an empty site, and the cases follow it on either side of #1910. Co-Authored-By: Claude Opus 5.5 --- go/internal/control/ev_fuse_one_phase_start_test.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/go/internal/control/ev_fuse_one_phase_start_test.go b/go/internal/control/ev_fuse_one_phase_start_test.go index 4e49aede5..49a39ab6b 100644 --- a/go/internal/control/ev_fuse_one_phase_start_test.go +++ b/go/internal/control/ev_fuse_one_phase_start_test.go @@ -66,12 +66,12 @@ func TestIdleOnePhasePoolStartsOnSixAmpsOfRoom(t *testing.T) { // 1,380 W, its least order, once the worst phase leaves 6 A of room under the // working line, and waits while it leaves 5.7 A. A hidden margin on the // one-phase minimum would move the start and fail here. The cases are set -// from the working line, so they follow it if the line moves. +// from the working line as EVFuseBudget reports it, not from the constant +// that sets it, so they follow the line if it moves. func TestIdleOnePhasePoolStartBoundary(t *testing.T) { steps := []float64{0, 1380, 1610, 1840, 2070, 2300, 2530, 2760, 2990, 3220, 3450, 3680, 4140, 4830, 5520, 6210, 6900, 7590, 8280, 8970, 9660, 10350, 11040} const fuseA = 16.0 - lineA := fuseA - evPhaseMarginA // the EV working line on each phase site := func(t *testing.T, houseA float64, mode string) *phaseSite { cfg := loadpoint.Config{ID: "garage", DriverName: "easee", MinChargeW: 4140, MaxChargeW: 11040, PhaseMode: "auto", AllowedStepsW: steps} @@ -84,6 +84,14 @@ func TestIdleOnePhasePoolStartBoundary(t *testing.T) { s.ctrl.SetManualHold(cfg.ID, loadpoint.ManualHold{PowerW: 3680, PhaseMode: mode, Persistent: true}) return s } + // With no house load, an idle pool's room on its busiest phase is the + // whole working line. + probe := site(t, 0, "1p") + probe.tick() + lineA := probe.state.evLimit.phaseRoomA + if !probe.state.evLimit.phaseRoomKnown || lineA <= 6 || lineA > fuseA { + t.Fatalf("working line %.2f A (known %v) on a %.0f A fuse", lineA, probe.state.evLimit.phaseRoomKnown, fuseA) + } for _, mode := range []string{"1p", "auto"} { t.Run(mode+" 6.0 A of room starts", func(t *testing.T) { s := site(t, lineA-6, mode)