chore: simplify setting limit (#12631)

This commit is contained in:
andig 2024-03-03 14:27:26 +01:00 • committed by GitHub
parent 53bb069197
commit 0ece8c6e20
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -639,7 +639,7 @@ func (lp *Loadpoint) Prepare(uiChan chan<- util.Param, pushChan chan<- push.Even
if enabled, err := lp.charger.Enabled(); err == nil {
if lp.enabled = enabled; enabled {
// set defined current for use by pv mode
_ = lp.setLimit(lp.effectiveMinCurrent(), false)
_ = lp.setLimit(lp.effectiveMinCurrent())
}
} else {
lp.log.ERROR.Printf("charger: %v", err)
@ -708,7 +708,7 @@ func (lp *Loadpoint) syncCharger() error {
}
// setLimit applies charger current limits and enables/disables accordingly
func (lp *Loadpoint) setLimit(chargeCurrent float64, force bool) error {
func (lp *Loadpoint) setLimit(chargeCurrent float64) error {
// full amps only?
if _, ok := lp.charger.(api.ChargerEx); !ok || lp.vehicleHasFeature(api.CoarseCurrent) {
chargeCurrent = math.Trunc(chargeCurrent)
@ -856,7 +856,7 @@ func (lp *Loadpoint) disableUnlessClimater() error {
current = lp.effectiveMinCurrent()
}
return lp.setLimit(current, true)
return lp.setLimit(current)
}
// remoteControlled returns true if remote control status is active
@ -1028,7 +1028,7 @@ func (lp *Loadpoint) scalePhases(phases int) error {
func (lp *Loadpoint) fastCharging() error {
err := lp.scalePhasesIfAvailable(3)
if err == nil {
err = lp.setLimit(lp.effectiveMaxCurrent(), true)
err = lp.setLimit(lp.effectiveMaxCurrent())
}
return err
}
@ -1564,7 +1564,7 @@ func (lp *Loadpoint) Update(sitePower float64, autoCharge, batteryBuffered, batt
case !lp.connected():
// always disable charger if not connected
// https://github.com/evcc-io/evcc/issues/105
err = lp.setLimit(0, false)
err = lp.setLimit(0)
case lp.scalePhasesRequired():
err = lp.scalePhases(lp.configuredPhases)
@ -1574,7 +1574,7 @@ func (lp *Loadpoint) Update(sitePower float64, autoCharge, batteryBuffered, batt
fallthrough
case mode == api.ModeOff:
err = lp.setLimit(0, true)
err = lp.setLimit(0)
// minimum or target charging
case lp.minSocNotReached() || plannerActive:
@ -1605,20 +1605,17 @@ func (lp *Loadpoint) Update(sitePower float64, autoCharge, batteryBuffered, batt
targetCurrent := lp.pvMaxCurrent(mode, sitePower, batteryBuffered, batteryStart)
var required bool // false
if targetCurrent == 0 && lp.vehicleClimateActive() {
targetCurrent = lp.effectiveMinCurrent()
required = true
}
// Sunny Home Manager
if lp.remoteControlled(loadpoint.RemoteSoftDisable) {
remoteDisabled = loadpoint.RemoteSoftDisable
targetCurrent = 0
required = true
}
err = lp.setLimit(targetCurrent, required)
err = lp.setLimit(targetCurrent)
}
// Wake-up checks