Skip to content

Commit

Permalink
Loadpoint: expose active phases api (#11345)
Browse files Browse the repository at this point in the history
  • Loading branch information
andig committed Dec 30, 2023
1 parent b887131 commit a131678
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 10 deletions.
8 changes: 4 additions & 4 deletions core/loadpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,7 @@ func (lp *Loadpoint) evChargeCurrentHandler(current float64) {
// If physical charge meter is present this handler is not used.
// The actual value is published by the evChargeCurrentHandler
func (lp *Loadpoint) evChargeCurrentWrappedMeterHandler(current float64) {
power := current * float64(lp.activePhases()) * Voltage
power := current * float64(lp.ActivePhases()) * Voltage

// if disabled we cannot be charging
if !lp.enabled || !lp.charging() {
Expand Down Expand Up @@ -582,7 +582,7 @@ func (lp *Loadpoint) Prepare(uiChan chan<- util.Param, pushChan chan<- push.Even

lp.setConfiguredPhases(lp.ConfiguredPhases)
lp.publish(keys.PhasesEnabled, lp.phases)
lp.publish(keys.PhasesActive, lp.activePhases())
lp.publish(keys.PhasesActive, lp.ActivePhases())
lp.publishTimer(phaseTimer, 0, timerInactive)
lp.publishTimer(pvTimer, 0, timerInactive)
lp.publishTimer(guardTimer, 0, timerInactive)
Expand Down Expand Up @@ -1052,7 +1052,7 @@ func (lp *Loadpoint) pvScalePhases(sitePower, minCurrent, maxCurrent float64) bo
}

var waiting bool
activePhases := lp.activePhases()
activePhases := lp.ActivePhases()
availablePower := lp.chargePower - sitePower
scalable := (sitePower > 0 || !lp.enabled) && activePhases > 1 && lp.ConfiguredPhases < 3

Expand Down Expand Up @@ -1156,7 +1156,7 @@ func (lp *Loadpoint) pvMaxCurrent(mode api.ChargeMode, sitePower float64, batter

// calculate target charge current from delta power and actual current
effectiveCurrent := lp.effectiveCurrent()
activePhases := lp.activePhases()
activePhases := lp.ActivePhases()
deltaCurrent := powerToCurrent(-sitePower, activePhases)
targetCurrent := max(effectiveCurrent+deltaCurrent, 0)

Expand Down
2 changes: 2 additions & 0 deletions core/loadpoint/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ type API interface {
GetPhases() int
// SetPhases sets the enabled phases
SetPhases(int) error
// ActivePhases returns the active phases for the current vehicle
ActivePhases() int

// GetLimitSoc returns the session limit soc
GetLimitSoc() int
Expand Down
14 changes: 14 additions & 0 deletions core/loadpoint/mock.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions core/loadpoint_phases.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func (lp *Loadpoint) resetMeasuredPhases() {
lp.measuredPhases = 0
lp.Unlock()

lp.publish(keys.PhasesActive, lp.activePhases())
lp.publish(keys.PhasesActive, lp.ActivePhases())
}

// getMeasuredPhases provides synchronized access to measuredPhases
Expand All @@ -64,9 +64,9 @@ func expect(phases int) int {
return unknownPhases
}

// activePhases returns the number of expectedly active phases for the meter.
// ActivePhases returns the number of expectedly active phases for the meter.
// If unknown for 1p3p chargers during startup it will assume 3p.
func (lp *Loadpoint) activePhases() int {
func (lp *Loadpoint) ActivePhases() int {
physical := lp.GetPhases()
vehicle := lp.getVehiclePhases()
measured := lp.getMeasuredPhases()
Expand Down
4 changes: 2 additions & 2 deletions core/loadpoint_phases_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ func TestMaxActivePhases(t *testing.T) {
func testScale(t *testing.T, lp *Loadpoint, sitePower float64, direction string, tc testCase) {
t.Helper()

act := lp.activePhases()
act := lp.ActivePhases()
max := lp.maxActivePhases()

testDirection := direction[0:1] // (d)own or (u)p
Expand Down Expand Up @@ -221,7 +221,7 @@ func TestPvScalePhases(t *testing.T) {
t.Error("wrong phases", lp.phases, tc.physical)
}

if phs := lp.activePhases(); phs != tc.actExpected {
if phs := lp.ActivePhases(); phs != tc.actExpected {
t.Errorf("expected active %d, got %d", tc.actExpected, phs)
}
if phs := lp.maxActivePhases(); phs != tc.maxExpected {
Expand Down
2 changes: 1 addition & 1 deletion core/loadpoint_vehicle.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ func (lp *Loadpoint) setActiveVehicle(v api.Vehicle) {
}

// re-publish vehicle settings
lp.publish(keys.PhasesActive, lp.activePhases())
lp.publish(keys.PhasesActive, lp.ActivePhases())
lp.unpublishVehicle()

// publish effective values
Expand Down

0 comments on commit a131678

Please sign in to comment.