Always round down for current calculation
This commit is contained in:
parent
cdf2cb6b2f
commit
85b47cbe70
2 changed files with 12 additions and 2 deletions
|
|
@ -1,6 +1,10 @@
|
|||
package core
|
||||
|
||||
import "github.com/avast/retry-go"
|
||||
import (
|
||||
"math"
|
||||
|
||||
"github.com/avast/retry-go"
|
||||
)
|
||||
|
||||
var (
|
||||
status = map[bool]string{false: "disable", true: "enable"}
|
||||
|
|
@ -15,7 +19,7 @@ var (
|
|||
|
||||
// powerToCurrent is a helper function to convert power to per-phase current
|
||||
func powerToCurrent(power float64, phases int64) int64 {
|
||||
return int64(power / (float64(phases) * Voltage))
|
||||
return int64(math.Floor(power / (float64(phases) * Voltage)))
|
||||
}
|
||||
|
||||
// consumedPower estimates how much power the charger might have consumed given it was the only load
|
||||
|
|
|
|||
|
|
@ -83,6 +83,10 @@ func NewLoadPointFromConfig(log *util.Logger, cp configProvider, other map[strin
|
|||
charger := cp.Charger(lp.ChargerRef)
|
||||
lp.configureChargerType(charger)
|
||||
|
||||
if lp.Enable.Threshold > lp.Disable.Threshold {
|
||||
log.WARN.Printf("PV mode enable threshold (%.0fW) is larger than disable threshold (%.0fW)", lp.Enable.Threshold, lp.Disable.Threshold)
|
||||
}
|
||||
|
||||
lp.handler = &ChargerHandler{
|
||||
log: lp.log,
|
||||
clock: lp.clock,
|
||||
|
|
@ -296,6 +300,8 @@ func (lp *LoadPoint) maxCurrent(mode api.ChargeMode, sitePower float64) int64 {
|
|||
deltaCurrent := powerToCurrent(-sitePower, lp.Phases)
|
||||
targetCurrent := clamp(lp.handler.TargetCurrent()+deltaCurrent, 0, lp.MaxCurrent)
|
||||
|
||||
lp.log.DEBUG.Printf("max charge current: %dA = %dA + %dA (%.0fW @ %dp)", targetCurrent, lp.handler.TargetCurrent(), deltaCurrent, sitePower, lp.Phases)
|
||||
|
||||
// in MinPV mode return at least minCurrent
|
||||
if mode == api.ModeMinPV && targetCurrent < lp.MinCurrent {
|
||||
return lp.MinCurrent
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue