From f19c87b8caae081afd49c0f2d029391e92eda4fa Mon Sep 17 00:00:00 2001 From: andig Date: Sun, 10 Oct 2021 13:20:47 +0200 Subject: [PATCH] Warn if charge power is negative --- core/loadpoint.go | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/core/loadpoint.go b/core/loadpoint.go index 00d7019d0..d5bfc6c67 100644 --- a/core/loadpoint.go +++ b/core/loadpoint.go @@ -151,10 +151,10 @@ func NewLoadPointFromConfig(log *util.Logger, cp configProvider, other map[strin switch lp.SoC.Poll.Mode = strings.ToLower(lp.SoC.Poll.Mode); lp.SoC.Poll.Mode { case pollCharging: case pollConnected, pollAlways: - log.WARN.Printf("poll mode '%s' may deplete your battery or lead to API misuse. USE AT YOUR OWN RISK.", lp.SoC.Poll) + lp.log.WARN.Printf("poll mode '%s' may deplete your battery or lead to API misuse. USE AT YOUR OWN RISK.", lp.SoC.Poll) default: if lp.SoC.Poll.Mode != "" { - log.WARN.Printf("invalid poll mode: %s", lp.SoC.Poll.Mode) + lp.log.WARN.Printf("invalid poll mode: %s", lp.SoC.Poll.Mode) } lp.SoC.Poll.Mode = pollConnected } @@ -164,7 +164,7 @@ func NewLoadPointFromConfig(log *util.Logger, cp configProvider, other map[strin if lp.SoC.Poll.Interval == 0 { lp.SoC.Poll.Interval = pollInterval } else { - log.WARN.Printf("poll interval '%v' is lower than %v and may deplete your battery or lead to API misuse. USE AT YOUR OWN RISK.", lp.SoC.Poll.Interval, pollInterval) + lp.log.WARN.Printf("poll interval '%v' is lower than %v and may deplete your battery or lead to API misuse. USE AT YOUR OWN RISK.", lp.SoC.Poll.Interval, pollInterval) } } @@ -176,11 +176,11 @@ func NewLoadPointFromConfig(log *util.Logger, cp configProvider, other map[strin } if lp.MinCurrent == 0 { - log.WARN.Println("minCurrent must not be zero") + lp.log.WARN.Println("minCurrent must not be zero") } if lp.MaxCurrent <= lp.MinCurrent { - log.WARN.Println("maxCurrent must be larger than minCurrent") + lp.log.WARN.Println("maxCurrent must be larger than minCurrent") } if lp.Meters.ChargeMeterRef != "" { @@ -216,9 +216,9 @@ func NewLoadPointFromConfig(log *util.Logger, cp configProvider, other map[strin // allow target charge handler to access loadpoint lp.socTimer = soc.NewTimer(lp.log, &adapter{LoadPoint: lp}) 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.log.WARN.Printf("PV mode enable threshold (%.0fW) is larger than disable threshold (%.0fW)", lp.Enable.Threshold, lp.Disable.Threshold) } else if lp.Enable.Threshold > 0 { - log.WARN.Printf("PV mode enable threshold %.0fW > 0 will start PV charging on grid power consumption. Did you mean -%.0f?", lp.Enable.Threshold, lp.Enable.Threshold) + lp.log.WARN.Printf("PV mode enable threshold %.0fW > 0 will start PV charging on grid power consumption. Did you mean -%.0f?", lp.Enable.Threshold, lp.Enable.Threshold) } return lp, nil @@ -1061,6 +1061,10 @@ func (lp *LoadPoint) updateChargePower() { lp.log.DEBUG.Printf("charge power: %.0fW", value) lp.publish("chargePower", value) + if lp.chargePower < 0 { + lp.log.WARN.Printf("charge power must not be negative: %.0f", lp.chargePower) + } + return nil }, retryOptions...)