Zendure: fix meter updates (#18116)

This commit is contained in:
andig 2025-01-07 16:54:21 +01:00 • committed by GitHub
parent a24b8b89f5
commit 91c0ab20be
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 32 additions and 3 deletions

View file

@ -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
})
}

View file

@ -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)
}
}