From a0383838c4a0f6521ca458c869d35213860308bd Mon Sep 17 00:00:00 2001 From: andig Date: Sat, 6 Jun 2026 10:25:35 +0200 Subject: [PATCH] Charger (Plugchoice): trim whitespace before parsing values (#30559) --- charger/plugchoice.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) 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 }