Sungrow: add heartbeat (#27388)

This commit is contained in:
mfuchs1984 2026-02-13 14:38:29 +01:00 • committed by GitHub
parent 5738399a49
commit 0c1dcfc69a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -21,6 +21,7 @@ import (
"context"
"encoding/binary"
"fmt"
"time"
"github.com/evcc-io/evcc/api"
"github.com/evcc-io/evcc/util"
@ -95,9 +96,24 @@ func NewSungrow(ctx context.Context, uri, device, comset string, baudrate int, p
curr: 60,
}
go wb.heartbeat(ctx)
return wb, nil
}
func (wb *Sungrow) heartbeat(ctx context.Context) {
for tick := time.Tick(30 * time.Second); ; {
select {
case <-tick:
case <-ctx.Done():
return
}
if _, err := wb.conn.ReadInputRegisters(sgRegState, 1); err != nil {
wb.log.ERROR.Println("heartbeat:", err)
}
}
}
// getPhaseValues returns 3 non-sequential register values
func (wb *Sungrow) getPhaseValues(regs []uint16, divider float64) (float64, float64, float64, error) {
var res [3]float64