Warn if charge power is negative

This commit is contained in:
andig 2021-10-10 13:20:47 +02:00
parent 5ea3c6ef39
commit f19c87b8ca

View file

@ -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...)