Skip to content

Commit 58177f6

Browse files
authored
Silence NaN reading errors by treating NaN as zero (#261)
1 parent d7082ee commit 58177f6

File tree

4 files changed

+17
-1
lines changed

4 files changed

+17
-1
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ require (
3333
github.com/spf13/jwalterweatherman v1.1.0
3434
github.com/spf13/viper v1.7.0
3535
github.com/tcnksm/go-latest v0.0.0-20170313132115-e3007ae9052e
36-
github.com/volkszaehler/mbmd v0.0.0-20200717102329-c4d965bd1eac
36+
github.com/volkszaehler/mbmd v0.0.0-20200802164800-51eb643c23c6
3737
github.com/yuin/goldmark v1.1.32
3838
golang.org/x/net v0.0.0-20200707034311-ab3426394381
3939
golang.org/x/tools v0.0.0-20200717024301-6ddee64345a6

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,8 @@ github.com/valyala/fasttemplate v1.0.1/go.mod h1:UQGH1tvbgY+Nz5t2n7tXsz52dQxojPU
348348
github.com/valyala/fasttemplate v1.1.0/go.mod h1:UQGH1tvbgY+Nz5t2n7tXsz52dQxojPUpymEIMZ47gx8=
349349
github.com/volkszaehler/mbmd v0.0.0-20200717102329-c4d965bd1eac h1:LnvR04M0HuzjTbRzMpE5jRHcNu46CvG1FOtMcZAX8C4=
350350
github.com/volkszaehler/mbmd v0.0.0-20200717102329-c4d965bd1eac/go.mod h1:sldLyJCKVO9GQkit55U5WPNr9U4KmUn1SCdqFN9Gjb4=
351+
github.com/volkszaehler/mbmd v0.0.0-20200802164800-51eb643c23c6 h1:cs1lwT44CyqStjTmYe0vGDhQHEaBpYZh0dgXPQLeEpY=
352+
github.com/volkszaehler/mbmd v0.0.0-20200802164800-51eb643c23c6/go.mod h1:sldLyJCKVO9GQkit55U5WPNr9U4KmUn1SCdqFN9Gjb4=
351353
github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU=
352354
github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q=
353355
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=

meter/modbus.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package meter
22

33
import (
4+
"errors"
5+
46
"github.com/andig/evcc/api"
57
"github.com/andig/evcc/util"
68
"github.com/andig/evcc/util/modbus"
@@ -113,6 +115,12 @@ func (m *Modbus) floatGetter(op modbus.Operation) (float64, error) {
113115
}
114116
}
115117

118+
// silence NaN reading errors by assuming zero
119+
if err != nil && errors.Is(err, meters.ErrNaN) {
120+
res.Value = 0
121+
err = nil
122+
}
123+
116124
if err != nil {
117125
m.conn.Close() // close connection in case of modbus error
118126
} else {

provider/modbus.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,12 @@ func (m *Modbus) FloatGetter() (float64, error) {
156156
}
157157
}
158158

159+
// silence NaN reading errors by assuming zero
160+
if err != nil && errors.Is(err, meters.ErrNaN) {
161+
res.Value = 0
162+
err = nil
163+
}
164+
159165
if err != nil {
160166
m.conn.Close() // close connection in case of modbus error
161167
} else {

0 commit comments

Comments
 (0)