Charger (Plugchoice): trim whitespace before parsing values (#30559)

This commit is contained in:
andig 2026-06-06 10:25:35 +02:00 • committed by GitHub
parent 4648f01fad
commit a0383838c4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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
}