Silence NaN reading errors by treating NaN as zero (#261)

This commit is contained in:
andig 2020-08-03 07:23:54 +02:00 • committed by GitHub
parent d7082ee954
commit 58177f60c1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 17 additions and 1 deletions

2
go.mod
View file

@ -33,7 +33,7 @@ require (
github.com/spf13/jwalterweatherman v1.1.0
github.com/spf13/viper v1.7.0
github.com/tcnksm/go-latest v0.0.0-20170313132115-e3007ae9052e
github.com/volkszaehler/mbmd v0.0.0-20200717102329-c4d965bd1eac
github.com/volkszaehler/mbmd v0.0.0-20200802164800-51eb643c23c6
github.com/yuin/goldmark v1.1.32
golang.org/x/net v0.0.0-20200707034311-ab3426394381
golang.org/x/tools v0.0.0-20200717024301-6ddee64345a6

2
go.sum
View file

@ -348,6 +348,8 @@ github.com/valyala/fasttemplate v1.0.1/go.mod h1:UQGH1tvbgY+Nz5t2n7tXsz52dQxojPU
github.com/valyala/fasttemplate v1.1.0/go.mod h1:UQGH1tvbgY+Nz5t2n7tXsz52dQxojPUpymEIMZ47gx8=
github.com/volkszaehler/mbmd v0.0.0-20200717102329-c4d965bd1eac h1:LnvR04M0HuzjTbRzMpE5jRHcNu46CvG1FOtMcZAX8C4=
github.com/volkszaehler/mbmd v0.0.0-20200717102329-c4d965bd1eac/go.mod h1:sldLyJCKVO9GQkit55U5WPNr9U4KmUn1SCdqFN9Gjb4=
github.com/volkszaehler/mbmd v0.0.0-20200802164800-51eb643c23c6 h1:cs1lwT44CyqStjTmYe0vGDhQHEaBpYZh0dgXPQLeEpY=
github.com/volkszaehler/mbmd v0.0.0-20200802164800-51eb643c23c6/go.mod h1:sldLyJCKVO9GQkit55U5WPNr9U4KmUn1SCdqFN9Gjb4=
github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU=
github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q=
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=

View file

@ -1,6 +1,8 @@
package meter
import (
"errors"
"github.com/andig/evcc/api"
"github.com/andig/evcc/util"
"github.com/andig/evcc/util/modbus"
@ -113,6 +115,12 @@ func (m *Modbus) floatGetter(op modbus.Operation) (float64, error) {
}
}
// silence NaN reading errors by assuming zero
if err != nil && errors.Is(err, meters.ErrNaN) {
res.Value = 0
err = nil
}
if err != nil {
m.conn.Close() // close connection in case of modbus error
} else {

View file

@ -156,6 +156,12 @@ func (m *Modbus) FloatGetter() (float64, error) {
}
}
// silence NaN reading errors by assuming zero
if err != nil && errors.Is(err, meters.ErrNaN) {
res.Value = 0
err = nil
}
if err != nil {
m.conn.Close() // close connection in case of modbus error
} else {