From 91e146dd0e15ee6293aaafe3029b0478c32c1bc1 Mon Sep 17 00:00:00 2001 From: andig Date: Mon, 6 May 2024 21:16:51 +0200 Subject: [PATCH] chore: simplify --- core/circuit.go | 39 ++++++--------------------------------- 1 file changed, 6 insertions(+), 33 deletions(-) diff --git a/core/circuit.go b/core/circuit.go index cab7c12e4..8abda96eb 100644 --- a/core/circuit.go +++ b/core/circuit.go @@ -252,15 +252,11 @@ func (c *Circuit) ValidatePower(old, new float64) float64 { } } - if c.parent != nil { - res := c.parent.ValidatePower(old, new) - if res != new { - c.log.TRACE.Printf("validate power: %gW -> %gW at %gW: capped by parent at %gW", old, new, c.power, res) - } - return res + if c.parent == nil { + return new } - return new + return c.parent.ValidatePower(old, new) } // ValidateCurrent validates current request @@ -277,32 +273,9 @@ func (c *Circuit) ValidateCurrent(old, new float64) float64 { } } - if c.parent != nil { - res := c.parent.ValidateCurrent(old, new) - if res != new { - c.log.TRACE.Printf("validate current: %gA -> %gA at %gA: capped by parent at %gA", old, new, c.current, res) - } - return res + if c.parent == nil { + return new } - return new + return c.parent.ValidateCurrent(old, new) } - -// func (c *Circuit) validate(typ string, current, old, new float64, parentFunc func(o, n float64) float64) float64 { -// delta := max(0, new-old) - -// if c.maxPower != 0 { -// if c.power+delta > c.maxPower { -// new = max(0, c.maxPower-c.power) -// c.log.TRACE.Printf("validate power: %g -> %g <= %g at %g: capped at %g", old, new, c.maxPower, c.power, new) -// } else { -// c.log.TRACE.Printf("validate power: %g -> %g <= %g at %g: ok", old, new, c.maxPower, c.power) -// } -// } - -// if c.parent != nil { -// return c.parent.ValidatePower(c.power, new) -// } - -// return new -// }