|
| 1 | +package control |
| 2 | + |
| 3 | +import ( |
| 4 | + "fmt" |
| 5 | + "testing" |
| 6 | + "time" |
| 7 | + |
| 8 | + "github.com/srcfl/ftw/go/internal/loadpoint" |
| 9 | + "github.com/srcfl/ftw/go/internal/sitesim" |
| 10 | +) |
| 11 | + |
| 12 | +// A charger that declares a 180 s response time, as Easee Cloud does, and |
| 13 | +// takes delay to start, beside a planned 9.4 kW battery charge on a 25 A |
| 14 | +// site with 3 A of house load per phase. The car's 11 kW offer stays |
| 15 | +// unshown until the charger applies it, and the battery must not take that |
| 16 | +// room: when the car starts, no phase may pass the instant limit, and the |
| 17 | +// car must not sit idle with room. |
| 18 | +func TestSlowChargerUnshownOfferKeepsBatteryOut(t *testing.T) { |
| 19 | + for _, delay := range []time.Duration{5 * time.Second, 30 * time.Second, 40 * time.Second, 2 * time.Minute} { |
| 20 | + sc := simScenario{name: "slow charger", run: 15 * time.Minute, |
| 21 | + plant: func(p *sitesim.Plant) { |
| 22 | + p.HouseW, p.EVSE.Delay = houseA(3, 3, 3), delay |
| 23 | + p.Battery = &sitesim.Battery{Phases: 3, MaxChargeW: 9400, MaxDischargeW: 9400, CapacityWh: 20000, SoC: .3, Latency: 3 * time.Second} |
| 24 | + }, |
| 25 | + setup: func(s *simSite) { |
| 26 | + s.evMaxAge = evUnknownSettle |
| 27 | + planBatteryCharge(9400)(s) |
| 28 | + }} |
| 29 | + s := runSimScenario(sc, simStart) |
| 30 | + t.Logf("delay %v: peak phase %.1f A, %v over %.0f A, idle with room %v, car %.0f W, battery %.0f W", |
| 31 | + delay, s.peakA, s.overLimit, s.p.Fuse.RatingA-evPhaseMarginA, s.idleWithRoom, s.p.EVSE.DrawW, s.p.Battery.W) |
| 32 | + if s.failure != "" { |
| 33 | + t.Errorf("delay %v: %s", delay, s.failure) |
| 34 | + } |
| 35 | + if limitA := fuseInstantFactor * s.p.Fuse.RatingA; s.peakA > limitA { |
| 36 | + t.Errorf("delay %v: peak phase %.1f A above the instant limit %.1f A", delay, s.peakA, limitA) |
| 37 | + } |
| 38 | + } |
| 39 | +} |
| 40 | + |
| 41 | +// #1868's rig shape (s18): a 16 A site with 3 A of house load, a local |
| 42 | +// charger that declares no response time and draws within 2 s, a car that |
| 43 | +// takes only [0, 4140] W, and a 6000 W battery charge. Once the car draws, |
| 44 | +// the reading shows it, and the battery shares the rest of the fuse well |
| 45 | +// before evUnknownSettle; s18's judge needs it above 1000 W 100-120 s after |
| 46 | +// Charge now. |
| 47 | +func TestFastChargerYoungOfferLetsBatteryShare(t *testing.T) { |
| 48 | + for _, tc := range []struct { |
| 49 | + name string |
| 50 | + setup func(*simSite) |
| 51 | + }{ |
| 52 | + {"manual hold", func(s *simSite) { |
| 53 | + s.state.SetBatteryManualHold(BatteryManualHold{PowerW: 6000, ExpiresAt: s.p.Now.Add(time.Hour)}) |
| 54 | + }}, |
| 55 | + {"plan", planBatteryCharge(6000)}, |
| 56 | + } { |
| 57 | + t.Run(tc.name, func(t *testing.T) { |
| 58 | + var expect []simExpect |
| 59 | + for _, at := range []time.Duration{60 * time.Second, 100 * time.Second, 120 * time.Second, 170 * time.Second} { |
| 60 | + expect = append(expect, simExpect{at, func(s *simSite) error { |
| 61 | + if s.p.EVSE.DrawW < 4100 || s.p.Battery.W < 3000 { |
| 62 | + return fmt.Errorf("car %.0f W and battery %.0f W at %v; both should charge", s.p.EVSE.DrawW, s.p.Battery.W, at) |
| 63 | + } |
| 64 | + return nil |
| 65 | + }}) |
| 66 | + } |
| 67 | + sc := simScenario{name: "s18 " + tc.name, run: 4 * time.Minute, |
| 68 | + plant: func(p *sitesim.Plant) { |
| 69 | + p.Fuse.RatingA, p.HouseW, p.EVSE.Delay, p.EVSE.ReadbackLag = 16, houseA(3, 3, 3), 2*time.Second, 0 |
| 70 | + p.Battery = &sitesim.Battery{Phases: 3, MaxChargeW: 6000, MaxDischargeW: 6000, CapacityWh: 20000, SoC: .4, Latency: 2 * time.Second} |
| 71 | + }, |
| 72 | + lp: func(c *loadpoint.Config) { |
| 73 | + c.MinChargeW, c.MaxChargeW, c.AllowedStepsW = 4140, 4140, []float64{0, 4140} |
| 74 | + }, |
| 75 | + setup: tc.setup, |
| 76 | + expect: expect} |
| 77 | + s := runSimScenario(sc, simStart) |
| 78 | + if s.failure != "" { |
| 79 | + t.Error(s.failure) |
| 80 | + } |
| 81 | + if limitA := fuseInstantFactor * s.p.Fuse.RatingA; s.peakA > limitA { |
| 82 | + t.Errorf("peak phase %.1f A above the instant limit %.1f A", s.peakA, limitA) |
| 83 | + } |
| 84 | + }) |
| 85 | + } |
| 86 | +} |
0 commit comments