Skip to content

Commit

Permalink
Fix SMA reporting negativ 0 value (#126)
Browse files Browse the repository at this point in the history
  • Loading branch information
Andreas Linde committed May 12, 2020
1 parent bb0a7e6 commit a44f424
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
5 changes: 4 additions & 1 deletion meter/sma.go
Expand Up @@ -109,7 +109,10 @@ func (sm *SMA) receive() {
sm.updated = time.Now()
}
} else if power, ok := msg.Values[sma.ExportPower]; ok {
sm.power = -power
sm.power = 0
if power > 0 {
sm.power = -power
}
sm.updated = time.Now()
} else if power, ok := msg.Values[sma.ImportPower]; ok {
sm.power = power
Expand Down
2 changes: 2 additions & 0 deletions meter/sma/listener.go
Expand Up @@ -157,6 +157,8 @@ func (l *Listener) processMessage(src *net.UDPAddr, b []byte) (Telegram, error)
Values: obisValues,
}

// l.log.TRACE.Printf("recv %v", msg.Values)

return msg, nil
}

Expand Down
6 changes: 5 additions & 1 deletion meter/sma/listener_test.go
Expand Up @@ -4,6 +4,8 @@ import (
"net"
"reflect"
"testing"

"github.com/andig/evcc/util"
)

func TestListenerProcessMessage(t *testing.T) {
Expand Down Expand Up @@ -186,7 +188,9 @@ func TestListenerProcessMessage(t *testing.T) {
}
for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
l := &Listener{}
l := &Listener{
log: util.NewLogger("sma "),
}

buffer := tc.response
read := len(buffer)
Expand Down

0 comments on commit a44f424

Please sign in to comment.