From d96afa3f88c01ccb02f830d2f4c176a88c46c3ca Mon Sep 17 00:00:00 2001 From: andig Date: Tue, 15 Apr 2025 15:49:09 +0200 Subject: [PATCH] Zendure: fix panic --- meter/zendure/connection.go | 2 +- meter/zendure/connection_test.go | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/meter/zendure/connection.go b/meter/zendure/connection.go index ff8cb372d..eab1797f3 100644 --- a/meter/zendure/connection.go +++ b/meter/zendure/connection.go @@ -70,7 +70,7 @@ func (c *Connection) handler(data string) { return } - if res.Sn != c.serial || res.Data == nil { + if res.Data == nil || res.Sn != c.serial { return } diff --git a/meter/zendure/connection_test.go b/meter/zendure/connection_test.go index f5ea4cb28..4a4b471ea 100644 --- a/meter/zendure/connection_test.go +++ b/meter/zendure/connection_test.go @@ -11,10 +11,16 @@ import ( func TestHandler(t *testing.T) { conn := &Connection{ log: util.NewLogger("test"), - data: util.NewMonitor[Data](time.Minute), + data: util.NewMonitor[Data](time.Millisecond), serial: "serial", } + { + // command + conn.handler(`{"name":"foo"}`) + _, err := conn.data.Get() + assert.Error(t, err) + } { conn.handler(`{"solarInputPower":113,"sn":"serial"}`) res, err := conn.data.Get()