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

@ -4,7 +4,6 @@ import (
"context"
"errors"
"fmt"
"strings"
"sync"
"time"
@ -250,18 +249,16 @@ func (c *EEBus) Dim(dim bool) error {
}
c.mu.Lock()
defer c.mu.Unlock()
entity := c.egLpcEntity
c.mu.Unlock()
if c.egLpcEntity == nil || !c.eg.EgLPCInterface.IsScenarioAvailableAtEntity(c.egLpcEntity, eebus.LPCLimit) {
if entity == nil || !c.eg.EgLPCInterface.IsScenarioAvailableAtEntity(entity, eebus.LPCLimit) {
return api.ErrNotAvailable
}
_, err := c.eg.EgLPCInterface.WriteConsumptionLimit(c.egLpcEntity, ucapi.LoadLimit{
Value: value,
IsActive: dim,
}, c.callbackResult("consumption limit"))
return err
return eebus.Await(func(cb func(model.ResultDataType)) (*model.MsgCounterType, error) {
return c.eg.EgLPCInterface.WriteConsumptionLimit(entity, ucapi.LoadLimit{Value: value, IsActive: dim}, cb)
})
}
var _ api.Curtailer = (*EEBus)(nil)
@ -294,35 +291,14 @@ func (c *EEBus) Curtail(curtail bool) error {
}
c.mu.Lock()
defer c.mu.Unlock()
entity := c.egLppEntity
c.mu.Unlock()
if c.egLppEntity == nil || !c.eg.EgLPPInterface.IsScenarioAvailableAtEntity(c.egLppEntity, eebus.LPPLimit) {
if entity == nil || !c.eg.EgLPPInterface.IsScenarioAvailableAtEntity(entity, eebus.LPPLimit) {
return api.ErrNotAvailable
}
_, err := c.eg.EgLPPInterface.WriteProductionLimit(c.egLppEntity, ucapi.LoadLimit{
Value: value,
IsActive: curtail,
}, c.callbackResult("production limit"))
return err
}
func (c *EEBus) callbackResult(typ string) func(result model.ResultDataType) {
return func(result model.ResultDataType) {
sb := new(strings.Builder)
if result.ErrorNumber != nil {
fmt.Fprint(sb, *result.ErrorNumber)
}
if result.Description != nil {
if sb.Len() > 0 {
fmt.Print(sb, ":")
}
fmt.Print(sb, *result.Description)
}
if sb.Len() > 0 {
c.log.ERROR.Printf("%s: %s", typ, sb.String())
}
}
return eebus.Await(func(cb func(model.ResultDataType)) (*model.MsgCounterType, error) {
return c.eg.EgLPPInterface.WriteProductionLimit(entity, ucapi.LoadLimit{Value: value, IsActive: curtail}, cb)
})
}