EEBus: state the limit to a controllable system on connect (#32491)

This commit is contained in:
andig 2026-08-03 18:13:37 +02:00 • committed by GitHub
parent dc1ac7c6dd
commit 4a878838e7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 175 additions and 13 deletions

View file

@ -43,6 +43,7 @@ type EEBusOHPCF struct {
egLpcEntity spineapi.EntityRemoteInterface
enabled bool
reboosting bool
dimmed bool // last limit written, re-stated on reconnect
connector *eebus.Connector
}
@ -186,6 +187,9 @@ func (c *EEBusOHPCF) UseCaseEvent(_ spineapi.DeviceRemoteInterface, entity spine
// use most specific selector
if c.egLpcEntity == nil || len(entity.Address().Entity) < len(c.egLpcEntity.Address().Entity) {
c.egLpcEntity = entity
// [LPC-913]: state the limit to the newly available CS
go eebus.AssertLimit(c.log, func() error { return c.Dim(c.lastDimmed()) })
}
c.mu.Unlock()
}
@ -212,6 +216,13 @@ func (c *EEBusOHPCF) lastEnabled() bool {
return c.enabled
}
func (c *EEBusOHPCF) lastDimmed() bool {
c.mu.RLock()
defer c.mu.RUnlock()
return c.dimmed
}
// ohpcfStatus maps the compressor process state to a charge status: running is
// consuming (C), any other connected state is standby (B). Disconnected (A) is handled in Status.
func ohpcfStatus(state ucapi.CompressorPowerConsumptionStateType) api.ChargeStatus {
@ -405,9 +416,17 @@ func (c *EEBusOHPCF) Dim(dim bool) error {
}
// TODO: change api.Dimmer to make the limit configurable; use a fixed 0W safe limit for now
return eebus.Await(func(cb func(model.ResultDataType, model.MsgCounterType)) (*model.MsgCounterType, error) {
if err := eebus.Await(func(cb func(model.ResultDataType, model.MsgCounterType)) (*model.MsgCounterType, error) {
return c.eg.EgLPCInterface.WriteConsumptionLimit(entity, ucapi.LoadLimit{Value: 0, IsActive: dim}, cb)
})
}); err != nil {
return err
}
c.mu.Lock()
c.dimmed = dim
c.mu.Unlock()
return nil
}
// apply issues the command to align the optional consumption with the on/off

View file

@ -5,9 +5,11 @@ package charger
import (
"testing"
"time"
eebusapi "github.com/enbility/eebus-go/api"
ucapi "github.com/enbility/eebus-go/usecases/api"
eglpc "github.com/enbility/eebus-go/usecases/eg/lpc"
egmocks "github.com/enbility/eebus-go/usecases/mocks"
spineapi "github.com/enbility/spine-go/api"
spinemocks "github.com/enbility/spine-go/mocks"
@ -61,6 +63,32 @@ func TestOHPCF_LPC_EGMessages_ConsumptionLimit(t *testing.T) {
}
}
// ATC_COM_PT_EGMessages_002 (LPC-913): after initial connection the EG states a
// limit to the CS - deactivated when nothing is being limited.
func TestOHPCF_LPC_InitialLimit(t *testing.T) {
c, lpc, entity := newOHPCFEGCharger(t)
c.egLpcEntity = nil
written := make(chan ucapi.LoadLimit, 1)
lpc.EXPECT().IsScenarioAvailableAtEntity(entity, eebus.LPCLimit).Return(true)
lpc.EXPECT().
WriteConsumptionLimit(entity, mock.Anything, mock.Anything).
Run(func(_ spineapi.EntityRemoteInterface, limit ucapi.LoadLimit, cb func(model.ResultDataType, model.MsgCounterType)) {
written <- limit
cb(model.ResultDataType{}, 0)
}).
Return(new(model.MsgCounterType), nil)
c.UseCaseEvent(nil, entity, eglpc.UseCaseSupportUpdate)
select {
case limit := <-written:
assert.Equal(t, ucapi.LoadLimit{Value: 0, IsActive: false}, limit)
case <-time.After(time.Second):
t.Fatal("no limit written after connect")
}
}
// A rejected write (NACK) must surface as an error, not silent success.
func TestOHPCF_LPC_Dim_WriteRejected(t *testing.T) {
c, lpc, entity := newOHPCFEGCharger(t)