From 9de1ec2aba98f05a122034dace074f834e69aaad Mon Sep 17 00:00:00 2001 From: andig Date: Wed, 26 Feb 2025 16:18:11 +0100 Subject: [PATCH] chore: minor --- core/circuit/circuit.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/core/circuit/circuit.go b/core/circuit/circuit.go index 4acd1fa95..83dc5f4f6 100644 --- a/core/circuit/circuit.go +++ b/core/circuit/circuit.go @@ -315,10 +315,10 @@ func (c *Circuit) GetMaxPhaseCurrent() float64 { // ValidatePower validates power request func (c *Circuit) ValidatePower(old, new float64) float64 { - delta := max(0, new-old) - if maxPower := c.GetMaxPower(); maxPower != 0 { + delta := max(0, new-old) potential := maxPower - c.power + if delta > potential { capped := max(0, old+potential) c.log.DEBUG.Printf("validate power: %.5gW + (%.5gW -> %.5gW) > %.5gW capped at %.5gW", c.power, old, new, maxPower, capped) @@ -337,10 +337,10 @@ func (c *Circuit) ValidatePower(old, new float64) float64 { // ValidateCurrent validates current request func (c *Circuit) ValidateCurrent(old, new float64) float64 { - delta := max(0, new-old) - if maxCurrent := c.GetMaxCurrent(); maxCurrent != 0 { + delta := max(0, new-old) potential := maxCurrent - c.current + if delta > potential { capped := max(0, old+potential) c.log.DEBUG.Printf("validate current: %.3gA + (%.3gA -> %.3gA) > %.3gA capped at %.3gA", c.current, old, new, maxCurrent, capped)