Loadpoint: expose active phases api (#11345)

This commit is contained in:
andig 2023-12-30 13:49:12 +01:00 • committed by GitHub
parent b8871310f2
commit a131678739
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 26 additions and 10 deletions

View file

@ -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() {
@ -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)
@ -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
@ -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)

View file

@ -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

View file

@ -35,6 +35,20 @@ func (m *MockAPI) EXPECT() *MockAPIMockRecorder {
return m.recorder
}
// ActivePhases mocks base method.
func (m *MockAPI) ActivePhases() int {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "ActivePhases")
ret0, _ := ret[0].(int)
return ret0
}
// ActivePhases indicates an expected call of ActivePhases.
func (mr *MockAPIMockRecorder) ActivePhases() *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ActivePhases", reflect.TypeOf((*MockAPI)(nil).ActivePhases))
}
// EffectiveMaxPower mocks base method.
func (m *MockAPI) EffectiveMaxPower() float64 {
m.ctrl.T.Helper()

View file

@ -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
@ -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()

View file

@ -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
@ -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 {

View file

@ -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