Skip to content

Commit 872eb58

Browse files
authored
Fix charge current not published when charge meter configured (#285)
1 parent c8e1d25 commit 872eb58

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

core/loadpoint.go

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ func (lp *LoadPoint) configureChargerType(charger api.Charger) {
217217
lp.chargeMeter = mt
218218
} else {
219219
mt := &wrapper.ChargeMeter{}
220-
_ = lp.bus.Subscribe(evChargeCurrent, lp.evChargeCurrentHandler)
220+
_ = lp.bus.Subscribe(evChargeCurrent, lp.evChargeCurrentWrappedMeterHandler)
221221
_ = lp.bus.Subscribe(evChargeStop, func() {
222222
mt.SetPower(0)
223223
})
@@ -304,9 +304,16 @@ func (lp *LoadPoint) evVehicleDisconnectHandler() {
304304
}
305305

306306
// evChargeCurrentHandler updates the dummy charge meter's charge power. This simplifies the main flow
307-
// where the charge meter can always be treated as present. It assumes that the charge meter cannot consume
308-
// more than total household consumption. If physical charge meter is present this handler is not used.
309307
func (lp *LoadPoint) evChargeCurrentHandler(current int64) {
308+
lp.publish("chargeCurrent", current)
309+
}
310+
311+
// evChargeCurrentWrappedMeterHandler updates the dummy charge meter's charge power.
312+
// This simplifies the main flow where the charge meter can always be treated as present.
313+
// It assumes that the charge meter cannot consume more than total household consumption.
314+
// If physical charge meter is present this handler is not used.
315+
// The actual value is published by the evChargeCurrentHandler
316+
func (lp *LoadPoint) evChargeCurrentWrappedMeterHandler(current int64) {
310317
power := float64(current*lp.Phases) * Voltage
311318

312319
if !lp.handler.Enabled() || lp.status != api.StatusC {
@@ -324,9 +331,6 @@ func (lp *LoadPoint) evChargeCurrentHandler(current int64) {
324331

325332
// handler only called if charge meter was replaced by dummy
326333
lp.chargeMeter.(*wrapper.ChargeMeter).SetPower(power)
327-
328-
// expose for UI
329-
lp.publish("chargeCurrent", current)
330334
}
331335

332336
// Name returns the human-readable loadpoint title
@@ -345,6 +349,7 @@ func (lp *LoadPoint) Prepare(uiChan chan<- util.Param, pushChan chan<- push.Even
345349
_ = lp.bus.Subscribe(evChargeStop, lp.evChargeStopHandler)
346350
_ = lp.bus.Subscribe(evVehicleConnect, lp.evVehicleConnectHandler)
347351
_ = lp.bus.Subscribe(evVehicleDisconnect, lp.evVehicleDisconnectHandler)
352+
_ = lp.bus.Subscribe(evChargeCurrent, lp.evChargeCurrentHandler)
348353

349354
// publish initial values
350355
lp.Lock()

0 commit comments

Comments
 (0)