From 4626513ba5314569c1f68f74f51dfda495edd6c5 Mon Sep 17 00:00:00 2001 From: andig Date: Sun, 20 Apr 2025 12:40:26 +0200 Subject: [PATCH] Revert "chore: follow-up to #20183" This reverts commit 45082c8b3feafa113a6c8e16559b3ad4390bb7e6. --- 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 3e801e053..cf38a849e 100644 --- a/core/circuit/circuit.go +++ b/core/circuit/circuit.go @@ -327,9 +327,9 @@ func (c *Circuit) ValidatePower(old, new float64, charging bool) float64 { var capped float64 if charging { - capped = min(new, maxPower, max(0, potential+old)) + capped = min(maxPower, new, max(0, potential+old)) } else { - capped = min(new, max(0, potential)) + capped = max(0, min(new, potential)) } if new > capped { c.log.DEBUG.Printf("validate power: %.5gW + (%.5gW -> %.5gW) > %.5gW capped at %.5gW", c.power, old, new, maxPower, capped) @@ -351,9 +351,9 @@ func (c *Circuit) ValidateCurrent(old, new float64, charging bool) float64 { var capped float64 if charging { - capped = min(new, maxCurrent, max(0, potential+old)) + capped = min(maxCurrent, new, max(0, potential+old)) } else { - capped = min(new, max(0, potential)) + capped = max(0, min(new, potential)) } if new > capped { c.log.DEBUG.Printf("validate current: %.3gA + (%.3gA -> %.3gA) > %.3gA capped at %.3gA", c.current, old, new, maxCurrent, capped)