Signed-off-by: Thomas Klaehn <tkl@blackfinn.de>
This commit is contained in:
2026-04-30 09:15:01 +02:00
parent 62ffd06444
commit 3233593b08
2 changed files with 10 additions and 12 deletions
+9 -8
View File
@@ -54,12 +54,8 @@ type AlphaEss struct {
client *modbus.ModbusClient
}
func NewAlphaEss(cfg AlphaConf) (*AlphaEss, error) {
a := &AlphaEss{cfg: cfg}
if err := a.connect(); err != nil {
return nil, err
}
return a, nil
func NewAlphaEss(cfg AlphaConf) *AlphaEss {
return &AlphaEss{cfg: cfg} // connect lazily on first Poll
}
func (a *AlphaEss) connect() error {
@@ -100,9 +96,14 @@ func (a *AlphaEss) readReg(r alphaReg) (float32, error) {
return float32(raw) * r.factor, nil
}
// Poll reads all AlphaEss registers. On connection error it attempts one
// reconnect before returning the error.
// Poll reads all AlphaEss registers. Connects on first call; on error
// attempts one reconnect before returning.
func (a *AlphaEss) Poll() (*InverterData, error) {
if a.client == nil {
if err := a.connect(); err != nil {
return nil, err
}
}
data, err := a.poll()
if err != nil {
log.Printf("alphaess poll error, reconnecting: %v", err)