EEBus: await control-write results across all use cases (#31350)

This commit is contained in:
andig 2026-06-30 14:14:32 +02:00 • committed by GitHub
parent 2ac2fae0a3
commit 258dcb41b5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 68 additions and 96 deletions

View file

@ -2,9 +2,12 @@ package eebus
import (
"errors"
"fmt"
"log"
"time"
eebusapi "github.com/enbility/eebus-go/api"
"github.com/enbility/spine-go/model"
"github.com/evcc-io/evcc/api"
)
@ -15,6 +18,33 @@ func WrapError(err error) error {
return err
}
// WriteTimeout bounds how long an awaited eebus write waits for its result.
const WriteTimeout = 10 * time.Second
// Await runs a control write and waits for the remote device's result, returning
// an error if the write is rejected or no result arrives within WriteTimeout.
func Await(write func(func(model.ResultDataType)) (*model.MsgCounterType, error)) error {
res := make(chan model.ResultDataType, 1)
if _, err := write(func(r model.ResultDataType) { res <- r }); err != nil {
return err
}
select {
case r := <-res:
if r.ErrorNumber != nil && *r.ErrorNumber != 0 {
err := fmt.Errorf("write rejected: %d", *r.ErrorNumber)
if r.Description != nil {
err = fmt.Errorf("%w (%s)", err, *r.Description)
}
return err
}
return nil
case <-time.After(WriteTimeout):
return errors.New("write result timeout")
}
}
func LogEntities(log *log.Logger, actor string, uc eebusapi.UseCaseInterface) {
ss := uc.RemoteEntitiesScenarios()
if len(ss) > 0 {