Skip to content
Merged
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
5 changes: 3 additions & 2 deletions go/test/site/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ car on them. FTW talks to it over Modbus and OCPP as on a real site. Each
scenario starts a fresh house and a fresh `state.db`, drives the house and
FTW, and judges the run against fixed criteria from what flowed through the
fuse (the house's record) and what FTW said (its API, once a second). FTW
runs what a beta box runs: Energyplan in `planner_passive_arbitrage`. Its
runs what a beta box runs: Energyplan in `planner_passive_arbitrage`, or in
`planner_self` where a scenario needs PV surplus to charge the battery. Its
prices are pinned: the test serves 24 h of fixed prices from the quarter the
run starts in ([`prices_test.go`](prices_test.go)) through `price.base_url`,
so a run does not depend on the day or the internet.
Expand Down Expand Up @@ -99,7 +100,7 @@ tick as 2 s more.
| `s13-25` Socket reconnect | Charge now 16 A, the charger's connection gone for 10 s | Charge now goes on after the charger returns; no unplug seen | |
| `s15-25` One-phase charger, Charge now | 25 A, 3 A per phase, an Easee wired on L1 (6-16 A, steps to 3 680 W, no phase mode); Charge now on the phases `/api/loadpoints` reports, as the app sends it, 180 s | 16 A on L1 within 60 s; held 95 %; fuse holds; no `fuse_limit` | yes |
| `s15b-25`, `s15c-25` | as s15, phase mode `1p` and `auto` | as s15 | |
| `s15bat-16` One-phase charger, battery rising | 16 A, 3 A per phase, the s15 charger, battery at 50 % following its EMS 8 s late; PV 2.1 kW rising every 30 s (+2.5 kW, then 1.5 kW) so Core charges the battery in steps; Charge now 6 s after the second step, while the raise is on its way | the battery order rose over 1 150 W in the 20 s before (setup check); car charging within 10 s; fuse holds; over the limit at most 3 s | |
| `s15bat-16` One-phase charger, battery rising | 16 A, 3 A per phase, the s15 charger, battery at 50 % following its EMS 8 s late, `planner_self`; PV 2.1 kW rising every 30 s (+2.5 kW, then 1.5 kW) so Core charges the battery in steps; Charge now 6 s after the second step, while the raise is on its way | the battery order rose over 1 150 W in the 20 s before (setup check); car charging within 10 s; fuse holds; over the limit at most 3 s | |
| `s15p-25` One-phase charger, planned | as s15, a plan for 600 Wh by the first quarter hour 15 min out | fuse holds; 90 % of the plan by the ready time; never called not following | |
| `s14-25` One-phase car | an 11 kW charger with a one-phase car, a plan it cannot meet, 20 min | 3.4–3.8 kW over the last 10 min; never called not following | |
| `s16-25` Import ceiling | 25 A, house 1.3 kW, battery idle at its floor, `peak_import_ceiling_w` 4 500, Charge now 16 A: house and the car's 4 140 W minimum are above the ceiling. Starts in an hour's first minutes or waits for :56, then runs one whole clock hour and 3 min | the car starts on the hour's room before :45; every clock hour's recorded import averages at most the ceiling + 1 %; the next hour stops the car within 60 s; while held it says `import_limit` 90 % of the time and never `fuse_limit`; fuse holds | |
Expand Down
36 changes: 36 additions & 0 deletions go/test/site/rig_unit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ package site

import (
"encoding/json"
"os"
"testing"
"time"
)

// These run in every go test, without a simulator.
Expand Down Expand Up @@ -139,3 +141,37 @@ func TestInvariantsTellStepsFromOwnRaises(t *testing.T) {
t.Fatalf("without a step: %v", f)
}
}

// A run that selects planner_self plans in self_consumption; any other run
// selects planner_passive_arbitrage and plans in passive_arbitrage. s15bat
// needs Self, where PV surplus charges the battery (#1875).
func TestRigModeMatchesItsPlannerConfig(t *testing.T) {
for _, tc := range []struct{ spec, mode, planner string }{
{"", "planner_passive_arbitrage", "passive_arbitrage"},
{"planner_self", "planner_self", "self_consumption"},
} {
st := newStack(nil, lane(21700), t.TempDir(), stackSpec{fuseA: 16, mode: tc.spec})
st.prices = newPriceServer(time.Now())
path, err := st.ftwConfig()
st.prices.close()
if err != nil {
t.Fatal(err)
}
b, err := os.ReadFile(path)
if err != nil {
t.Fatal(err)
}
var cfg struct {
Planner struct {
Mode string `json:"mode"`
} `json:"planner"`
}
if err := json.Unmarshal(b, &cfg); err != nil {
t.Fatal(err)
}
if st.mode() != tc.mode || cfg.Planner.Mode != tc.planner {
t.Errorf("spec mode %q: selects %q and plans in %q, want %q and %q",
tc.spec, st.mode(), cfg.Planner.Mode, tc.mode, tc.planner)
}
}
}
4 changes: 3 additions & 1 deletion go/test/site/scenarios_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -960,9 +960,11 @@ func judgeS15p(d *runData) (metrics, []criterion) {
// (15 - 3) x 230 - (1 380 + 230) = 1 150 W on its way once kept the car from
// starting at all (#1805). With the battery's 2 s the car started 25 s late
// when Charge now caught a raise in flight, and at once when it did not.
// The run plans in Self: in passive arbitrage the plan may keep the battery
// idle and export the PV, and then no raise is on its way (#1875).
func s15bat(c *runCtx, fuse float64) (map[string]any, error) {
err := with(c, stackSpec{fuseA: fuse, loadsW: houseA(3), socPct: 50, chargers: []charger{onePhaseCharger},
lpExtra: onePhaseExtra, batteryDelayS: 8}, func(st *stack) error {
lpExtra: onePhaseExtra, batteryDelayS: 8, mode: "planner_self"}, func(st *stack) error {
if err := st.plug(0); err != nil {
return err
}
Expand Down
23 changes: 21 additions & 2 deletions go/test/site/stack_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,9 @@ type stackSpec struct {
// engine is the planner's: core or energyplan. Empty takes
// FTW_SITE_ENGINE, else energyplan, as a beta or stable box runs.
engine string
// mode is the control mode the run selects: planner_self or empty for
// planner_passive_arbitrage, as the web app chooses.
mode string
// horizonH is the planner's horizon_hours; 0 leaves Core's 48 h.
horizonH int
}
Expand Down Expand Up @@ -393,7 +396,7 @@ func (st *stack) up() error {
if err := st.startFTW(); err != nil {
return err
}
if _, err := call("POST", st.ftw+"/api/mode", map[string]any{"mode": "planner_passive_arbitrage"}, nil); err != nil {
if _, err := call("POST", st.ftw+"/api/mode", map[string]any{"mode": st.mode()}, nil); err != nil {
return err
}
st.rec = &recorder{ftw: st.ftw, path: filepath.Join(st.rundir, "ftw.jsonl")}
Expand Down Expand Up @@ -524,6 +527,22 @@ func (st *stack) engine() string {
return "energyplan"
}

// mode is the control mode this run selects, and plannerMode the planner
// mode in its config that matches it.
func (st *stack) mode() string {
if st.spec.mode != "" {
return st.spec.mode
}
return "planner_passive_arbitrage"
}

func (st *stack) plannerMode() string {
if st.mode() == "planner_self" {
return "self_consumption"
}
return "passive_arbitrage"
}

func (st *stack) ftwConfig() (string, error) {
var lps []map[string]any
for i := range st.spec.chargers {
Expand Down Expand Up @@ -566,7 +585,7 @@ func (st *stack) ftwConfig() (string, error) {
// battery chases the raw meter and covers the car (dispatch.go),
// which hides the stress on the fuse. Passive arbitrage is the
// mode the web app and a Charge restart return to.
"planner": map[string]any{"enabled": true, "engine": st.engine(), "mode": "passive_arbitrage"},
"planner": map[string]any{"enabled": true, "engine": st.engine(), "mode": st.plannerMode()},
"price": map[string]any{"provider": "elprisetjustnu", "zone": "SE3", "base_url": st.prices.url()},
}
if st.spec.horizonH > 0 {
Expand Down
Loading