diff --git a/charger/plugchoice.go b/charger/plugchoice.go index 2478f5414..862722016 100644 --- a/charger/plugchoice.go +++ b/charger/plugchoice.go @@ -247,12 +247,15 @@ func (c *Plugchoice) CurrentPower() (float64, error) { return 0, err } + // the API may return values with surrounding whitespace (e.g. " 0.0") + kwVal := strings.TrimSpace(res.KW) + // Handle the case where power value is "-" - if res.KW == "-" { + if kwVal == "-" { return 0, nil } - kw, err := strconv.ParseFloat(res.KW, 64) + kw, err := strconv.ParseFloat(kwVal, 64) if err != nil { return 0, err } @@ -271,6 +274,8 @@ func (c *Plugchoice) Currents() (float64, float64, float64, error) { // Helper function to parse current values, handling "-" as 0 parsePhaseValue := func(val string, phase string) (float64, error) { + // the API may return values with surrounding whitespace (e.g. " 0.0") + val = strings.TrimSpace(val) if val == "-" { return 0, nil }