Charger (Plugchoice): trim whitespace before parsing values (#30559)
This commit is contained in:
parent
4648f01fad
commit
a0383838c4
1 changed files with 7 additions and 2 deletions
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue