Skip to content

Commit

Permalink
Zendure: fix meter updates (#18116)
Browse files Browse the repository at this point in the history
  • Loading branch information
andig authored Jan 7, 2025
1 parent a24b8b8 commit 91c0ab2
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
4 changes: 1 addition & 3 deletions meter/zendure/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,10 @@ func (c *Connection) handler(data string) {
}

c.data.SetFunc(func(v Data) Data {
if err := mergo.Merge(&v, res.Data); err != nil {
if err := mergo.Merge(&v, res.Data, mergo.WithOverride); err != nil {
c.log.ERROR.Println(err)
}

c.log.TRACE.Printf("!! data: %+v", v)

return v
})
}
Expand Down
31 changes: 31 additions & 0 deletions meter/zendure/connection_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package zendure

import (
"testing"
"time"

"github.com/evcc-io/evcc/util"
"github.com/stretchr/testify/assert"
)

func TestHandler(t *testing.T) {
conn := &Connection{
log: util.NewLogger("test"),
data: util.NewMonitor[Data](time.Minute),
}

{
conn.handler(`{"solarInputPower":113,"sn":"serial"}`)
res, err := conn.data.Get()
assert.NoError(t, err)

assert.Equal(t, Data{SolarInputPower: 113, Sn: "serial"}, res)
}
{
conn.handler(`{"solarInputPower":125,"sn":"serial"}`)
res, err := conn.data.Get()
assert.NoError(t, err)

assert.Equal(t, Data{SolarInputPower: 125, Sn: "serial"}, res)
}
}

0 comments on commit 91c0ab2

Please sign in to comment.