Skip to content
This repository has been archived by the owner on Jun 29, 2024. It is now read-only.

Commit

Permalink
Change from Event interface to callback
Browse files Browse the repository at this point in the history
  • Loading branch information
DerAndereAndi committed Feb 25, 2024
1 parent 16d35a2 commit 54bd8cf
Show file tree
Hide file tree
Showing 41 changed files with 136 additions and 124 deletions.
15 changes: 5 additions & 10 deletions api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ import (

//go:generate mockery

// Event handler callback
//
// Used by Cem and Use Case implementations
type EventHandlerCB func(ski string, device spineapi.DeviceRemoteInterface, entity spineapi.EntityRemoteInterface, event EventType)

// Implemented by CEM
type CemInterface interface {
// Setup the EEBUS service
Expand Down Expand Up @@ -40,13 +45,3 @@ type UseCaseInterface interface {
// - and others
IsUseCaseSupported(remoteEntity spineapi.EntityRemoteInterface) (bool, error)
}

// interface for informing the HEMS about specific events
//
// implemented by the actual HEMS
type EventReaderInterface interface {
// Inform about a new cem or usecase specific event
//
// used by use case implementations
Event(ski string, device spineapi.DeviceRemoteInterface, entity spineapi.EntityRemoteInterface, event EventType)
}
23 changes: 23 additions & 0 deletions api/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,29 @@ const (
// Note: the referred data may be updated together with all other measurement items of this use case
UCEVSOCActualRangeMeasurementDataUpdate EventType = "ucEVSOCActualRangeMeasurementDataUpdate"

// LPC

// Load control obligation limit data updated
//
// Use Case LPC, Scenario 1
UCLPCLoadControlLimitDataUpdate EventType = "ucLPCLoadControlLimitDataUpdate"

// Failsafe limit for the consumed active (real) power of the
// Controllable System data updated
//
// Use Case LPC, Scenario 2
//
// Note: the referred data may be updated together with all other configuration items of this use case
UCLPCFailSafeConsumptionActivePowerLimitDataUpdate EventType = "ucLPCFailSafeConsumptionActivePowerLimitDataUpdate"

// Minimum time the Controllable System remains in "failsafe state" unless conditions
// specified in this Use Case permit leaving the "failsafe state" data updated
//
// Use Case LPC, Scenario 2
//
// Note: the referred data may be updated together with all other configuration items of this use case
UCLPCFailsafeDurationMinimumDataUpdate EventType = "ucLPCFailsafeDurationMinimumDataUpdate"

// MGCP

// Grid maximum allowed feed-in power as percentage value of the cumulated
Expand Down
6 changes: 3 additions & 3 deletions cem/cem.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,20 @@ type Cem struct {

Currency model.CurrencyType

reader api.EventReaderInterface
eventCB api.EventHandlerCB

usecases []api.UseCaseInterface
}

func NewCEM(
serviceDescription *eebusapi.Configuration,
serviceHandler eebusapi.ServiceReaderInterface,
reader api.EventReaderInterface,
eventCB api.EventHandlerCB,
log logging.LoggingInterface) *Cem {
cem := &Cem{
Service: service.NewService(serviceDescription, serviceHandler),
Currency: model.CurrencyTypeEur,
reader: reader,
eventCB: eventCB,
}

cem.Service.SetLogging(log)
Expand Down
6 changes: 3 additions & 3 deletions cem/cem_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,22 +48,22 @@ func (s *CemSuite) BeforeTest(suiteName, testName string) {
assert.Nil(s.T(), err)

noLogging := &logging.NoLogging{}
s.sut = NewCEM(configuration, s, s, noLogging)
s.sut = NewCEM(configuration, s, s.eventCB, noLogging)
assert.NotNil(s.T(), s.sut)
}
func (s *CemSuite) Test_CEM() {
err := s.sut.Setup()
assert.Nil(s.T(), err)

ucEvseCC := ucevsecc.NewUCEVSECC(s.sut.Service, s)
ucEvseCC := ucevsecc.NewUCEVSECC(s.sut.Service, s.eventCB)
s.sut.AddUseCase(ucEvseCC)

s.sut.Start()
s.sut.Shutdown()
}

// ReaderInterface
func (d *CemSuite) Event(ski string, device spineapi.DeviceRemoteInterface, entity spineapi.EntityRemoteInterface, event api.EventType) {
func (d *CemSuite) eventCB(ski string, device spineapi.DeviceRemoteInterface, entity spineapi.EntityRemoteInterface, event api.EventType) {
}

// eebusapi.ServiceReaderInterface
Expand Down
4 changes: 2 additions & 2 deletions cem/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ import (
func (h *Cem) HandleEvent(payload spineapi.EventPayload) {

if util.IsDeviceConnected(payload) {
h.reader.Event(payload.Ski, payload.Device, nil, api.DeviceConnected)
h.eventCB(payload.Ski, payload.Device, nil, api.DeviceConnected)
return
}

if util.IsDeviceDisconnected(payload) {
h.reader.Event(payload.Ski, payload.Device, nil, api.DeviceDisconnected)
h.eventCB(payload.Ski, payload.Device, nil, api.DeviceDisconnected)
return
}
}
4 changes: 2 additions & 2 deletions cmd/democem/democem.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func NewDemoCem(configuration *eebusapi.Configuration) *DemoCem {
demo := &DemoCem{}

noLogging := &logging.NoLogging{}
demo.cem = cem.NewCEM(configuration, demo, demo, noLogging)
demo.cem = cem.NewCEM(configuration, demo, demo.eventCB, noLogging)

Check failure on line 18 in cmd/democem/democem.go

View workflow job for this annotation

GitHub Actions / Build

demo.eventCB undefined (type *DemoCem has no field or method eventCB)

return demo
}
Expand All @@ -25,7 +25,7 @@ func (d *DemoCem) Setup() error {
return err
}

evsecc := ucevsecc.NewUCEVSECC(d.cem.Service, d)
evsecc := ucevsecc.NewUCEVSECC(d.cem.Service, d.eventCB)

Check failure on line 28 in cmd/democem/democem.go

View workflow job for this annotation

GitHub Actions / Build

d.eventCB undefined (type *DemoCem has no field or method eventCB)
d.cem.AddUseCase(evsecc)

d.cem.Start()
Expand Down
12 changes: 0 additions & 12 deletions cmd/democem/eventreader.go

This file was deleted.

6 changes: 6 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,9 @@ require (
golang.org/x/tools v0.17.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)

// replace github.com/enbility/eebus-go => ../eebus-go

// replace github.com/enbility/ship-go => ../ship-go

// replace github.com/enbility/spine-go => ../spine-go
14 changes: 7 additions & 7 deletions uccevc/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ func (e *UCCEVC) evTimeSeriesDescriptionDataUpdate(ski string, entity spineapi.E
return
}

e.reader.Event(ski, entity.Device(), entity, api.UCCEVCEnergyDemandProvided)
e.eventCB(ski, entity.Device(), entity, api.UCCEVCEnergyDemandProvided)

_, err = e.TimeSlotConstraints(entity)
if err != nil {
Expand All @@ -127,18 +127,18 @@ func (e *UCCEVC) evTimeSeriesDescriptionDataUpdate(ski string, entity spineapi.E
return
}

e.reader.Event(ski, entity.Device(), entity, api.UCCEVPowerLimitsRequested)
e.reader.Event(ski, entity.Device(), entity, api.UCCEVCIncentivesRequested)
e.eventCB(ski, entity.Device(), entity, api.UCCEVPowerLimitsRequested)
e.eventCB(ski, entity.Device(), entity, api.UCCEVCIncentivesRequested)
}

// the load control limit data of an EV was updated
func (e *UCCEVC) evTimeSeriesDataUpdate(ski string, entity spineapi.EntityRemoteInterface) {
if _, err := e.ChargePlan(entity); err == nil {
e.reader.Event(ski, entity.Device(), entity, api.UCCEVCChargePlanProvided)
e.eventCB(ski, entity.Device(), entity, api.UCCEVCChargePlanProvided)
}

if _, err := e.ChargePlanConstraints(entity); err == nil {
e.reader.Event(ski, entity.Device(), entity, api.UCCEVCChargePlanConstraintsProvided)
e.eventCB(ski, entity.Device(), entity, api.UCCEVCChargePlanConstraintsProvided)
}
}

Expand All @@ -156,12 +156,12 @@ func (e *UCCEVC) evIncentiveTableDescriptionDataUpdate(ski string, entity spinea
return
}

e.reader.Event(ski, entity.Device(), entity, api.UCCEVCIncentiveDescriptionsRequired)
e.eventCB(ski, entity.Device(), entity, api.UCCEVCIncentiveDescriptionsRequired)
}

// the load control limit data of an EV was updated
func (e *UCCEVC) evIncentiveTableDataUpdate(ski string, entity spineapi.EntityRemoteInterface) {
e.reader.Event(ski, entity.Device(), entity, api.UCCEVCIncentiveTableDataUpdate)
e.eventCB(ski, entity.Device(), entity, api.UCCEVCIncentiveTableDataUpdate)
}

// check timeSeries descriptions if constraints element has updateRequired set to true
Expand Down
2 changes: 1 addition & 1 deletion uccevc/testhelper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func (s *UCCEVCSuite) BeforeTest(suiteName, testName string) {
mockRemoteFeature.EXPECT().Operations().Return(ops).Maybe()
mockRemoteFeature.EXPECT().DataCopy(mock.Anything).Return(mock.Anything).Maybe()

s.sut = NewUCCEVC(s.service, s)
s.sut = NewUCCEVC(s.service, s.Event)
s.sut.AddFeatures()
s.sut.AddUseCase()

Expand Down
6 changes: 3 additions & 3 deletions uccevc/uccevc.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,17 @@ import (
type UCCEVC struct {
service serviceapi.ServiceInterface

reader api.EventReaderInterface
eventCB api.EventHandlerCB

validEntityTypes []model.EntityTypeType
}

var _ UCCEVCInterface = (*UCCEVC)(nil)

func NewUCCEVC(service serviceapi.ServiceInterface, reader api.EventReaderInterface) *UCCEVC {
func NewUCCEVC(service serviceapi.ServiceInterface, eventCB api.EventHandlerCB) *UCCEVC {
uc := &UCCEVC{
service: service,
reader: reader,
eventCB: eventCB,
}

uc.validEntityTypes = []model.EntityTypeType{
Expand Down
14 changes: 7 additions & 7 deletions ucevcc/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,12 +112,12 @@ func (e *UCEVCC) evConnected(ski string, entity spineapi.EntityRemoteInterface)
}
}

e.reader.Event(ski, entity.Device(), entity, api.UCEVCCEventConnected)
e.eventCB(ski, entity.Device(), entity, api.UCEVCCEventConnected)
}

// an EV was disconnected
func (e *UCEVCC) evDisconnected(ski string, entity spineapi.EntityRemoteInterface) {
e.reader.Event(ski, entity.Device(), entity, api.UCEVCCEventDisconnected)
e.eventCB(ski, entity.Device(), entity, api.UCEVCCEventDisconnected)
}

// the configuration key description data of an EV was updated
Expand All @@ -139,12 +139,12 @@ func (e *UCEVCC) evConfigurationDataUpdate(ski string, entity spineapi.EntityRem

// Scenario 2
if _, err := evDeviceConfiguration.GetKeyValueForKeyName(model.DeviceConfigurationKeyNameTypeCommunicationsStandard, model.DeviceConfigurationKeyValueTypeTypeString); err == nil {
e.reader.Event(ski, entity.Device(), entity, api.UCEVCCCommunicationStandardConfigurationDataUpdate)
e.eventCB(ski, entity.Device(), entity, api.UCEVCCCommunicationStandardConfigurationDataUpdate)
}

// Scenario 3
if _, err := evDeviceConfiguration.GetKeyValueForKeyName(model.DeviceConfigurationKeyNameTypeAsymmetricChargingSupported, model.DeviceConfigurationKeyValueTypeTypeString); err == nil {
e.reader.Event(ski, entity.Device(), entity, api.UCEVCCAsymmetricChargingConfigurationDataUpdate)
e.eventCB(ski, entity.Device(), entity, api.UCEVCCAsymmetricChargingConfigurationDataUpdate)
}
}

Expand All @@ -162,7 +162,7 @@ func (e *UCEVCC) evIdentificationDataUpdate(ski string, entity spineapi.EntityRe
continue
}

e.reader.Event(ski, entity.Device(), entity, api.UCEVCCIdentificationDataUpdate)
e.eventCB(ski, entity.Device(), entity, api.UCEVCCIdentificationDataUpdate)
return
}
}
Expand All @@ -177,7 +177,7 @@ func (e *UCEVCC) evManufacturerDataUpdate(ski string, entity spineapi.EntityRemo

// Scenario 5
if _, err := evDeviceClassification.GetManufacturerDetails(); err == nil {
e.reader.Event(ski, entity.Device(), entity, api.UCEVCCManufacturerDataUpdate)
e.eventCB(ski, entity.Device(), entity, api.UCEVCCManufacturerDataUpdate)
}

}
Expand Down Expand Up @@ -209,5 +209,5 @@ func (e *UCEVCC) evElectricalPermittedValuesUpdate(ski string, entity spineapi.E
}

// Scenario 6
e.reader.Event(ski, entity.Device(), entity, api.UCEVCCChargingPowerLimitsDataUpdate)
e.eventCB(ski, entity.Device(), entity, api.UCEVCCChargingPowerLimitsDataUpdate)
}
2 changes: 1 addition & 1 deletion ucevcc/testhelper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func (s *UCEVCCSuite) BeforeTest(suiteName, testName string) {
s.mockRemoteEntity.EXPECT().Address().Return(entityAddress).Maybe()
mockRemoteFeature.EXPECT().DataCopy(mock.Anything).Return(mock.Anything).Maybe()

s.sut = NewUCEVCC(s.service, s)
s.sut = NewUCEVCC(s.service, s.Event)
s.sut.AddFeatures()
s.sut.AddUseCase()

Expand Down
6 changes: 3 additions & 3 deletions ucevcc/ucevcc.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,17 @@ import (
type UCEVCC struct {
service serviceapi.ServiceInterface

reader api.EventReaderInterface
eventCB api.EventHandlerCB

validEntityTypes []model.EntityTypeType
}

var _ UCEVCCInterface = (*UCEVCC)(nil)

func NewUCEVCC(service serviceapi.ServiceInterface, reader api.EventReaderInterface) *UCEVCC {
func NewUCEVCC(service serviceapi.ServiceInterface, eventCB api.EventHandlerCB) *UCEVCC {
uc := &UCEVCC{
service: service,
reader: reader,
eventCB: eventCB,
}

uc.validEntityTypes = []model.EntityTypeType{
Expand Down
8 changes: 4 additions & 4 deletions ucevcem/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func (e *UCEVCEM) evElectricalConnectionDescriptionDataUpdate(ski string, entity
return
}

e.reader.Event(ski, entity.Device(), entity, api.UCEVCEMNumberOfConnectedPhasesDataUpdate)
e.eventCB(ski, entity.Device(), entity, api.UCEVCEMNumberOfConnectedPhasesDataUpdate)
}

// the measurement description data of an EV was updated
Expand All @@ -78,16 +78,16 @@ func (e *UCEVCEM) evMeasurementDescriptionDataUpdate(entity spineapi.EntityRemot
func (e *UCEVCEM) evMeasurementDataUpdate(ski string, entity spineapi.EntityRemoteInterface) {
// Scenario 1
if _, err := util.MeasurementValueForScope(e.service, entity, model.ScopeTypeTypeACCurrent); err == nil {
e.reader.Event(ski, entity.Device(), entity, api.UCEVCEMCurrentMeasurementDataUpdate)
e.eventCB(ski, entity.Device(), entity, api.UCEVCEMCurrentMeasurementDataUpdate)
}

// Scenario 2
if _, err := util.MeasurementValueForScope(e.service, entity, model.ScopeTypeTypeACPower); err == nil {
e.reader.Event(ski, entity.Device(), entity, api.UCEVCEMPowerMeasurementDataUpdate)
e.eventCB(ski, entity.Device(), entity, api.UCEVCEMPowerMeasurementDataUpdate)
}

// Scenario 3
if _, err := util.MeasurementValueForScope(e.service, entity, model.ScopeTypeTypeCharge); err == nil {
e.reader.Event(ski, entity.Device(), entity, api.UCEVCEMChargingEnergyMeasurementDataUpdate)
e.eventCB(ski, entity.Device(), entity, api.UCEVCEMChargingEnergyMeasurementDataUpdate)
}
}
2 changes: 1 addition & 1 deletion ucevcem/testhelper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func (s *UCEVCEMSuite) BeforeTest(suiteName, testName string) {
s.mockRemoteEntity.EXPECT().EntityType().Return(mock.Anything).Maybe()
mockRemoteFeature.EXPECT().DataCopy(mock.Anything).Return(mock.Anything).Maybe()

s.sut = NewUCEVCEM(s.service, s)
s.sut = NewUCEVCEM(s.service, s.Event)
s.sut.AddFeatures()
s.sut.AddUseCase()

Expand Down
6 changes: 3 additions & 3 deletions ucevcem/ucevcem.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,17 @@ import (
type UCEVCEM struct {
service serviceapi.ServiceInterface

reader api.EventReaderInterface
eventCB api.EventHandlerCB

validEntityTypes []model.EntityTypeType
}

var _ UCEVCEMInterface = (*UCEVCEM)(nil)

func NewUCEVCEM(service serviceapi.ServiceInterface, reader api.EventReaderInterface) *UCEVCEM {
func NewUCEVCEM(service serviceapi.ServiceInterface, eventCB api.EventHandlerCB) *UCEVCEM {
uc := &UCEVCEM{
service: service,
reader: reader,
eventCB: eventCB,
}

uc.validEntityTypes = []model.EntityTypeType{
Expand Down
Loading

0 comments on commit 54bd8cf

Please sign in to comment.