Modbus: handle NaN values (#31011)

This commit is contained in:
premultiply 2026-07-19 12:44:32 +02:00 • committed by GitHub
parent 2a86cc44b1
commit cc6bef6b82
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 26 additions and 9 deletions

View file

@ -9,6 +9,7 @@ import (
"strings"
"time"
"github.com/evcc-io/evcc/api"
"github.com/evcc-io/evcc/util"
"github.com/evcc-io/evcc/util/modbus"
gridx "github.com/grid-x/modbus"
@ -156,7 +157,12 @@ func (m *Modbus) FloatGetter() (func() (f float64, err error), error) {
return 0, fmt.Errorf("read failed: %w", err)
}
return m.scale * decode(bytes), nil
// a "*nan" sentinel decodes to NaN - the device reports no valid value
if res := m.scale * decode(bytes); !math.IsNaN(res) {
return res, nil
}
return 0, api.ErrNotAvailable
}, nil
}