From 54bd8cf67ef661687e0875faec982e3ed48a74be Mon Sep 17 00:00:00 2001 From: Andreas Linde Date: Sun, 25 Feb 2024 19:09:31 +0100 Subject: [PATCH] Change from Event interface to callback --- api/api.go | 15 +++++---------- api/types.go | 23 +++++++++++++++++++++++ cem/cem.go | 6 +++--- cem/cem_test.go | 6 +++--- cem/events.go | 4 ++-- cmd/democem/democem.go | 4 ++-- cmd/democem/eventreader.go | 12 ------------ go.mod | 6 ++++++ uccevc/events.go | 14 +++++++------- uccevc/testhelper_test.go | 2 +- uccevc/uccevc.go | 6 +++--- ucevcc/events.go | 14 +++++++------- ucevcc/testhelper_test.go | 2 +- ucevcc/ucevcc.go | 6 +++--- ucevcem/events.go | 8 ++++---- ucevcem/testhelper_test.go | 2 +- ucevcem/ucevcem.go | 6 +++--- ucevsecc/events.go | 8 ++++---- ucevsecc/testhelper_test.go | 2 +- ucevsecc/ucevsecc.go | 6 +++--- ucevsoc/events.go | 6 +++--- ucevsoc/testhelper_test.go | 2 +- ucevsoc/ucevsoc.go | 6 +++--- ucmgcp/events.go | 14 +++++++------- ucmgcp/testhelper_test.go | 2 +- ucmgcp/ucmgcp.go | 6 +++--- ucmpc/events.go | 14 +++++++------- ucmpc/testhelper_test.go | 2 +- ucmpc/ucmcp.go | 6 +++--- ucopev/events.go | 2 +- ucopev/testhelper_test.go | 2 +- ucopev/ucopev.go | 6 +++--- ucoscev/events.go | 2 +- ucoscev/testhelper_test.go | 2 +- ucoscev/ucoscev.go | 6 +++--- ucvabd/events.go | 8 ++++---- ucvabd/testhelper_test.go | 2 +- ucvabd/ucvabd.go | 6 +++--- ucvapd/events.go | 6 +++--- ucvapd/testhelper_test.go | 2 +- ucvapd/ucvapd.go | 6 +++--- 41 files changed, 136 insertions(+), 124 deletions(-) delete mode 100644 cmd/democem/eventreader.go diff --git a/api/api.go b/api/api.go index e7ecf80..785ac65 100644 --- a/api/api.go +++ b/api/api.go @@ -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 @@ -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) -} diff --git a/api/types.go b/api/types.go index b3a2a98..f06268d 100644 --- a/api/types.go +++ b/api/types.go @@ -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 diff --git a/cem/cem.go b/cem/cem.go index 21a9f59..5b6b4e2 100644 --- a/cem/cem.go +++ b/cem/cem.go @@ -14,7 +14,7 @@ type Cem struct { Currency model.CurrencyType - reader api.EventReaderInterface + eventCB api.EventHandlerCB usecases []api.UseCaseInterface } @@ -22,12 +22,12 @@ type Cem struct { 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) diff --git a/cem/cem_test.go b/cem/cem_test.go index fec2cbc..cd51a70 100644 --- a/cem/cem_test.go +++ b/cem/cem_test.go @@ -48,14 +48,14 @@ 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() @@ -63,7 +63,7 @@ func (s *CemSuite) Test_CEM() { } // 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 diff --git a/cem/events.go b/cem/events.go index 21cd5c3..1f1b6fd 100644 --- a/cem/events.go +++ b/cem/events.go @@ -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 } } diff --git a/cmd/democem/democem.go b/cmd/democem/democem.go index bd917de..7055675 100644 --- a/cmd/democem/democem.go +++ b/cmd/democem/democem.go @@ -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) return demo } @@ -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) d.cem.AddUseCase(evsecc) d.cem.Start() diff --git a/cmd/democem/eventreader.go b/cmd/democem/eventreader.go deleted file mode 100644 index 6e66307..0000000 --- a/cmd/democem/eventreader.go +++ /dev/null @@ -1,12 +0,0 @@ -package democem - -import ( - "github.com/enbility/cemd/api" - spineapi "github.com/enbility/spine-go/api" -) - -var _ api.EventReaderInterface = (*DemoCem)(nil) - -// Handle incoming usecase specific events -func (h *DemoCem) Event(ski string, device spineapi.DeviceRemoteInterface, entity spineapi.EntityRemoteInterface, event api.EventType) { -} diff --git a/go.mod b/go.mod index 3ef4931..833a302 100644 --- a/go.mod +++ b/go.mod @@ -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 diff --git a/uccevc/events.go b/uccevc/events.go index d891edc..f2fdcf3 100644 --- a/uccevc/events.go +++ b/uccevc/events.go @@ -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 { @@ -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) } } @@ -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 diff --git a/uccevc/testhelper_test.go b/uccevc/testhelper_test.go index afc296f..00385a8 100644 --- a/uccevc/testhelper_test.go +++ b/uccevc/testhelper_test.go @@ -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() diff --git a/uccevc/uccevc.go b/uccevc/uccevc.go index f6b538c..045a001 100644 --- a/uccevc/uccevc.go +++ b/uccevc/uccevc.go @@ -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{ diff --git a/ucevcc/events.go b/ucevcc/events.go index 81c34a8..6c0c8e8 100644 --- a/ucevcc/events.go +++ b/ucevcc/events.go @@ -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 @@ -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) } } @@ -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 } } @@ -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) } } @@ -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) } diff --git a/ucevcc/testhelper_test.go b/ucevcc/testhelper_test.go index 660399b..8f84e19 100644 --- a/ucevcc/testhelper_test.go +++ b/ucevcc/testhelper_test.go @@ -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() diff --git a/ucevcc/ucevcc.go b/ucevcc/ucevcc.go index 0aecd16..7fe722f 100644 --- a/ucevcc/ucevcc.go +++ b/ucevcc/ucevcc.go @@ -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{ diff --git a/ucevcem/events.go b/ucevcem/events.go index c0c8d03..a3ff29a 100644 --- a/ucevcem/events.go +++ b/ucevcem/events.go @@ -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 @@ -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) } } diff --git a/ucevcem/testhelper_test.go b/ucevcem/testhelper_test.go index 986e6c5..1b9f52e 100644 --- a/ucevcem/testhelper_test.go +++ b/ucevcem/testhelper_test.go @@ -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() diff --git a/ucevcem/ucevcem.go b/ucevcem/ucevcem.go index ba05393..b0d54ba 100644 --- a/ucevcem/ucevcem.go +++ b/ucevcem/ucevcem.go @@ -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{ diff --git a/ucevsecc/events.go b/ucevsecc/events.go index 940e360..c94dfd9 100644 --- a/ucevsecc/events.go +++ b/ucevsecc/events.go @@ -55,12 +55,12 @@ func (e *UCEVSECC) evseConnected(ski string, entity spineapi.EntityRemoteInterfa _, _ = evseDeviceDiagnosis.RequestState() } - e.reader.Event(ski, entity.Device(), entity, api.UCEVSECCEventConnected) + e.eventCB(ski, entity.Device(), entity, api.UCEVSECCEventConnected) } // an EVSE was disconnected func (e *UCEVSECC) evseDisconnected(ski string, entity spineapi.EntityRemoteInterface) { - e.reader.Event(ski, entity.Device(), entity, api.UCEVSECCEventDisconnected) + e.eventCB(ski, entity.Device(), entity, api.UCEVSECCEventDisconnected) } // the manufacturer Data of an EVSE was updated @@ -71,7 +71,7 @@ func (e *UCEVSECC) evseManufacturerDataUpdate(ski string, entity spineapi.Entity } if _, err := evDeviceClassification.GetManufacturerDetails(); err == nil { - e.reader.Event(ski, entity.Device(), entity, api.UCEVSECCEventManufacturerUpdate) + e.eventCB(ski, entity.Device(), entity, api.UCEVSECCEventManufacturerUpdate) } } @@ -83,6 +83,6 @@ func (e *UCEVSECC) evseStateUpdate(ski string, entity spineapi.EntityRemoteInter } if _, err := evDeviceDiagnosis.GetState(); err == nil { - e.reader.Event(ski, entity.Device(), entity, api.UCEVSECCEventOperationStateUpdate) + e.eventCB(ski, entity.Device(), entity, api.UCEVSECCEventOperationStateUpdate) } } diff --git a/ucevsecc/testhelper_test.go b/ucevsecc/testhelper_test.go index 19dbe26..951c4f0 100644 --- a/ucevsecc/testhelper_test.go +++ b/ucevsecc/testhelper_test.go @@ -64,7 +64,7 @@ func (s *UCEVSECCSuite) BeforeTest(suiteName, testName string) { s.mockRemoteEntity.EXPECT().Address().Return(entityAddress).Maybe() mockRemoteFeature.EXPECT().DataCopy(mock.Anything).Return(mock.Anything).Maybe() - s.sut = NewUCEVSECC(s.service, s) + s.sut = NewUCEVSECC(s.service, s.Event) s.sut.AddFeatures() s.sut.AddUseCase() diff --git a/ucevsecc/ucevsecc.go b/ucevsecc/ucevsecc.go index 6397b85..90c6233 100644 --- a/ucevsecc/ucevsecc.go +++ b/ucevsecc/ucevsecc.go @@ -12,17 +12,17 @@ import ( type UCEVSECC struct { service serviceapi.ServiceInterface - reader api.EventReaderInterface + eventCB api.EventHandlerCB validEntityTypes []model.EntityTypeType } var _ UCEVSECCInterface = (*UCEVSECC)(nil) -func NewUCEVSECC(service serviceapi.ServiceInterface, reader api.EventReaderInterface) *UCEVSECC { +func NewUCEVSECC(service serviceapi.ServiceInterface, eventCB api.EventHandlerCB) *UCEVSECC { uc := &UCEVSECC{ service: service, - reader: reader, + eventCB: eventCB, } uc.validEntityTypes = []model.EntityTypeType{ diff --git a/ucevsoc/events.go b/ucevsoc/events.go index 4c6c665..ef8eff6 100644 --- a/ucevsoc/events.go +++ b/ucevsoc/events.go @@ -58,16 +58,16 @@ func (e *UCEVSOC) evConnected(entity spineapi.EntityRemoteInterface) { func (e *UCEVSOC) evMeasurementDataUpdate(ski string, entity spineapi.EntityRemoteInterface) { // Scenario 1 if _, err := util.MeasurementValueForScope(e.service, entity, model.ScopeTypeTypeStateOfCharge); err == nil { - e.reader.Event(ski, entity.Device(), entity, api.UCEVSOCStateOfChargeMeasurementDataUpdate) + e.eventCB(ski, entity.Device(), entity, api.UCEVSOCStateOfChargeMeasurementDataUpdate) } // Scenario 3 if _, err := util.MeasurementValueForScope(e.service, entity, model.ScopeTypeTypeStateOfHealth); err == nil { - e.reader.Event(ski, entity.Device(), entity, api.EVSOCStateOfHealthMeasurementDataUpdate) + e.eventCB(ski, entity.Device(), entity, api.EVSOCStateOfHealthMeasurementDataUpdate) } // Scenario 4 if _, err := util.MeasurementValueForScope(e.service, entity, model.ScopeTypeTypeTravelRange); err == nil { - e.reader.Event(ski, entity.Device(), entity, api.UCEVSOCActualRangeMeasurementDataUpdate) + e.eventCB(ski, entity.Device(), entity, api.UCEVSOCActualRangeMeasurementDataUpdate) } } diff --git a/ucevsoc/testhelper_test.go b/ucevsoc/testhelper_test.go index 9ad2ed8..6918e8c 100644 --- a/ucevsoc/testhelper_test.go +++ b/ucevsoc/testhelper_test.go @@ -64,7 +64,7 @@ func (s *UCEVSOCSuite) BeforeTest(suiteName, testName string) { s.mockRemoteEntity.EXPECT().Address().Return(entityAddress).Maybe() mockRemoteFeature.EXPECT().DataCopy(mock.Anything).Return(mock.Anything).Maybe() - s.sut = NewUCEVSOC(s.service, s) + s.sut = NewUCEVSOC(s.service, s.Event) s.sut.AddFeatures() s.sut.AddUseCase() diff --git a/ucevsoc/ucevsoc.go b/ucevsoc/ucevsoc.go index 5b5e129..cd72d2b 100644 --- a/ucevsoc/ucevsoc.go +++ b/ucevsoc/ucevsoc.go @@ -13,17 +13,17 @@ import ( type UCEVSOC struct { service serviceapi.ServiceInterface - reader api.EventReaderInterface + eventCB api.EventHandlerCB validEntityTypes []model.EntityTypeType } var _ UCEVSOCInterface = (*UCEVSOC)(nil) -func NewUCEVSOC(service serviceapi.ServiceInterface, reader api.EventReaderInterface) *UCEVSOC { +func NewUCEVSOC(service serviceapi.ServiceInterface, eventCB api.EventHandlerCB) *UCEVSOC { uc := &UCEVSOC{ service: service, - reader: reader, + eventCB: eventCB, } uc.validEntityTypes = []model.EntityTypeType{ diff --git a/ucmgcp/events.go b/ucmgcp/events.go index 300a9b1..d29738d 100644 --- a/ucmgcp/events.go +++ b/ucmgcp/events.go @@ -95,7 +95,7 @@ func (e *UCMGCP) gridConfigurationDescriptionDataUpdate(entity spineapi.EntityRe // the configuration key data of an SMGW was updated func (e *UCMGCP) gridConfigurationDataUpdate(ski string, entity spineapi.EntityRemoteInterface) { if _, err := e.PowerLimitationFactor(entity); err == nil { - e.reader.Event(ski, entity.Device(), entity, api.UCMGCPPVFeedInPowerLimitationFactorDataUpdate) + e.eventCB(ski, entity.Device(), entity, api.UCMGCPPVFeedInPowerLimitationFactorDataUpdate) } } @@ -113,32 +113,32 @@ func (e *UCMGCP) gridMeasurementDescriptionDataUpdate(entity spineapi.EntityRemo func (e *UCMGCP) gridMeasurementDataUpdate(ski string, entity spineapi.EntityRemoteInterface) { // Scenario 2 if _, err := util.MeasurementValueForScope(e.service, entity, model.ScopeTypeTypeACPowerTotal); err == nil { - e.reader.Event(ski, entity.Device(), entity, api.UCMGCPPowerTotalMeasurementDataUpdate) + e.eventCB(ski, entity.Device(), entity, api.UCMGCPPowerTotalMeasurementDataUpdate) } // Scenario 3 if _, err := util.MeasurementValueForScope(e.service, entity, model.ScopeTypeTypeGridFeedIn); err == nil { - e.reader.Event(ski, entity.Device(), entity, api.UCMGCPGridFeedInMeasurementDataUpdate) + e.eventCB(ski, entity.Device(), entity, api.UCMGCPGridFeedInMeasurementDataUpdate) } // Scenario 4 if _, err := util.MeasurementValueForScope(e.service, entity, model.ScopeTypeTypeGridConsumption); err == nil { - e.reader.Event(ski, entity.Device(), entity, api.UCMGCPGridConsumptionMeasurementDataUpdate) + e.eventCB(ski, entity.Device(), entity, api.UCMGCPGridConsumptionMeasurementDataUpdate) } // Scenario 5 if _, err := util.MeasurementValueForScope(e.service, entity, model.ScopeTypeTypeACCurrent); err == nil { - e.reader.Event(ski, entity.Device(), entity, api.UCMGCPCurrentsMeasurementDataUpdate) + e.eventCB(ski, entity.Device(), entity, api.UCMGCPCurrentsMeasurementDataUpdate) } // Scenario 6 if _, err := util.MeasurementValueForScope(e.service, entity, model.ScopeTypeTypeACVoltage); err == nil { - e.reader.Event(ski, entity.Device(), entity, api.UCMGCPVoltagesMeasurementDataUpdate) + e.eventCB(ski, entity.Device(), entity, api.UCMGCPVoltagesMeasurementDataUpdate) } // Scenario 7 if _, err := util.MeasurementValueForScope(e.service, entity, model.ScopeTypeTypeACFrequency); err == nil { - e.reader.Event(ski, entity.Device(), entity, api.UCMGCPFrequencyMeasurementDataUpdate) + e.eventCB(ski, entity.Device(), entity, api.UCMGCPFrequencyMeasurementDataUpdate) } } diff --git a/ucmgcp/testhelper_test.go b/ucmgcp/testhelper_test.go index 1e5352b..ccef3e4 100644 --- a/ucmgcp/testhelper_test.go +++ b/ucmgcp/testhelper_test.go @@ -64,7 +64,7 @@ func (s *UCMGCPSuite) BeforeTest(suiteName, testName string) { s.mockRemoteEntity.EXPECT().Address().Return(entityAddress).Maybe() mockRemoteFeature.EXPECT().DataCopy(mock.Anything).Return(mock.Anything).Maybe() - s.sut = NewUCMGCP(s.service, s) + s.sut = NewUCMGCP(s.service, s.Event) s.sut.AddFeatures() s.sut.AddUseCase() diff --git a/ucmgcp/ucmgcp.go b/ucmgcp/ucmgcp.go index b05aec6..02f9d4b 100644 --- a/ucmgcp/ucmgcp.go +++ b/ucmgcp/ucmgcp.go @@ -13,17 +13,17 @@ import ( type UCMGCP struct { service serviceapi.ServiceInterface - reader api.EventReaderInterface + eventCB api.EventHandlerCB validEntityTypes []model.EntityTypeType } var _ UCMGCPInterface = (*UCMGCP)(nil) -func NewUCMGCP(service serviceapi.ServiceInterface, reader api.EventReaderInterface) *UCMGCP { +func NewUCMGCP(service serviceapi.ServiceInterface, eventCB api.EventHandlerCB) *UCMGCP { uc := &UCMGCP{ service: service, - reader: reader, + eventCB: eventCB, } uc.validEntityTypes = []model.EntityTypeType{ diff --git a/ucmpc/events.go b/ucmpc/events.go index 3debfe7..b488bd6 100644 --- a/ucmpc/events.go +++ b/ucmpc/events.go @@ -81,35 +81,35 @@ func (e *UCMPC) deviceMeasurementDescriptionDataUpdate(entity spineapi.EntityRem func (e *UCMPC) deviceMeasurementDataUpdate(ski string, entity spineapi.EntityRemoteInterface) { // Scenario 1 if _, err := util.MeasurementValueForScope(e.service, entity, model.ScopeTypeTypeACPowerTotal); err == nil { - e.reader.Event(ski, entity.Device(), entity, api.UCMPCPowerTotalMeasurementDataUpdate) + e.eventCB(ski, entity.Device(), entity, api.UCMPCPowerTotalMeasurementDataUpdate) } if _, err := util.MeasurementValueForScope(e.service, entity, model.ScopeTypeTypeACPower); err == nil { - e.reader.Event(ski, entity.Device(), entity, api.UCMPCPowerPerPhaseMeasurementDataUpdate) + e.eventCB(ski, entity.Device(), entity, api.UCMPCPowerPerPhaseMeasurementDataUpdate) } // Scenario 2 if _, err := util.MeasurementValueForScope(e.service, entity, model.ScopeTypeTypeACEnergyConsumed); err == nil { - e.reader.Event(ski, entity.Device(), entity, api.UCMPCEnergyConsumedMeasurementDataUpdate) + e.eventCB(ski, entity.Device(), entity, api.UCMPCEnergyConsumedMeasurementDataUpdate) } if _, err := util.MeasurementValueForScope(e.service, entity, model.ScopeTypeTypeACEnergyProduced); err == nil { - e.reader.Event(ski, entity.Device(), entity, api.UCMPCEnergyProcudedMeasurementDataUpdate) + e.eventCB(ski, entity.Device(), entity, api.UCMPCEnergyProcudedMeasurementDataUpdate) } // Scenario 3 if _, err := util.MeasurementValueForScope(e.service, entity, model.ScopeTypeTypeACCurrent); err == nil { - e.reader.Event(ski, entity.Device(), entity, api.UCMPCCurrentsMeasurementDataUpdate) + e.eventCB(ski, entity.Device(), entity, api.UCMPCCurrentsMeasurementDataUpdate) } // Scenario 4 if _, err := util.MeasurementValueForScope(e.service, entity, model.ScopeTypeTypeACVoltage); err == nil { - e.reader.Event(ski, entity.Device(), entity, api.UCMPCVoltagesMeasurementDataUpdate) + e.eventCB(ski, entity.Device(), entity, api.UCMPCVoltagesMeasurementDataUpdate) } // Scenario 5 if _, err := util.MeasurementValueForScope(e.service, entity, model.ScopeTypeTypeACFrequency); err == nil { - e.reader.Event(ski, entity.Device(), entity, api.UCMPCFrequencyMeasurementDataUpdate) + e.eventCB(ski, entity.Device(), entity, api.UCMPCFrequencyMeasurementDataUpdate) } } diff --git a/ucmpc/testhelper_test.go b/ucmpc/testhelper_test.go index 7fd0ce1..57a1d3f 100644 --- a/ucmpc/testhelper_test.go +++ b/ucmpc/testhelper_test.go @@ -64,7 +64,7 @@ func (s *UCMPCSuite) BeforeTest(suiteName, testName string) { s.mockRemoteEntity.EXPECT().Address().Return(entityAddress).Maybe() mockRemoteFeature.EXPECT().DataCopy(mock.Anything).Return(mock.Anything).Maybe() - s.sut = NewUCMPC(s.service, s) + s.sut = NewUCMPC(s.service, s.Event) s.sut.AddFeatures() s.sut.AddUseCase() diff --git a/ucmpc/ucmcp.go b/ucmpc/ucmcp.go index a47fe04..b0e4abe 100644 --- a/ucmpc/ucmcp.go +++ b/ucmpc/ucmcp.go @@ -13,17 +13,17 @@ import ( type UCMPC struct { service serviceapi.ServiceInterface - reader api.EventReaderInterface + eventCB api.EventHandlerCB validEntityTypes []model.EntityTypeType } var _ UCMCPInterface = (*UCMPC)(nil) -func NewUCMPC(service serviceapi.ServiceInterface, reader api.EventReaderInterface) *UCMPC { +func NewUCMPC(service serviceapi.ServiceInterface, eventCB api.EventHandlerCB) *UCMPC { uc := &UCMPC{ service: service, - reader: reader, + eventCB: eventCB, } uc.validEntityTypes = []model.EntityTypeType{ diff --git a/ucopev/events.go b/ucopev/events.go index ee335d8..42e9b37 100644 --- a/ucopev/events.go +++ b/ucopev/events.go @@ -86,7 +86,7 @@ func (e *UCOPEV) evLoadControlLimitDataUpdate(ski string, entity spineapi.Entity continue } - e.reader.Event(ski, entity.Device(), entity, api.UCOPEVLoadControlLimitDataUpdate) + e.eventCB(ski, entity.Device(), entity, api.UCOPEVLoadControlLimitDataUpdate) return } diff --git a/ucopev/testhelper_test.go b/ucopev/testhelper_test.go index b9040ec..5c73af2 100644 --- a/ucopev/testhelper_test.go +++ b/ucopev/testhelper_test.go @@ -64,7 +64,7 @@ func (s *UCOPEVSuite) BeforeTest(suiteName, testName string) { s.mockRemoteEntity.EXPECT().Address().Return(entityAddress).Maybe() mockRemoteFeature.EXPECT().DataCopy(mock.Anything).Return(mock.Anything).Maybe() - s.sut = NewUCOPEV(s.service, s) + s.sut = NewUCOPEV(s.service, s.Event) s.sut.AddFeatures() s.sut.AddUseCase() diff --git a/ucopev/ucopev.go b/ucopev/ucopev.go index 7cc5795..cbb9b14 100644 --- a/ucopev/ucopev.go +++ b/ucopev/ucopev.go @@ -13,17 +13,17 @@ import ( type UCOPEV struct { service serviceapi.ServiceInterface - reader api.EventReaderInterface + eventCB api.EventHandlerCB validEntityTypes []model.EntityTypeType } var _ UCOPEVInterface = (*UCOPEV)(nil) -func NewUCOPEV(service serviceapi.ServiceInterface, reader api.EventReaderInterface) *UCOPEV { +func NewUCOPEV(service serviceapi.ServiceInterface, eventCB api.EventHandlerCB) *UCOPEV { uc := &UCOPEV{ service: service, - reader: reader, + eventCB: eventCB, } uc.validEntityTypes = []model.EntityTypeType{ diff --git a/ucoscev/events.go b/ucoscev/events.go index 62cbb58..2aae367 100644 --- a/ucoscev/events.go +++ b/ucoscev/events.go @@ -51,7 +51,7 @@ func (e *UCOSCEV) evLoadControlLimitDataUpdate(ski string, entity spineapi.Entit continue } - e.reader.Event(ski, entity.Device(), entity, api.UCOPEVLoadControlLimitDataUpdate) + e.eventCB(ski, entity.Device(), entity, api.UCOPEVLoadControlLimitDataUpdate) return } diff --git a/ucoscev/testhelper_test.go b/ucoscev/testhelper_test.go index 26780be..a89256a 100644 --- a/ucoscev/testhelper_test.go +++ b/ucoscev/testhelper_test.go @@ -64,7 +64,7 @@ func (s *UCOSCEVSuite) BeforeTest(suiteName, testName string) { s.mockRemoteEntity.EXPECT().Address().Return(entityAddress).Maybe() mockRemoteFeature.EXPECT().DataCopy(mock.Anything).Return(mock.Anything).Maybe() - s.sut = NewUCOSCEV(s.service, s) + s.sut = NewUCOSCEV(s.service, s.Event) s.sut.AddFeatures() s.sut.AddUseCase() diff --git a/ucoscev/ucoscev.go b/ucoscev/ucoscev.go index 07eaac0..e0c7cac 100644 --- a/ucoscev/ucoscev.go +++ b/ucoscev/ucoscev.go @@ -13,17 +13,17 @@ import ( type UCOSCEV struct { service serviceapi.ServiceInterface - reader api.EventReaderInterface + eventCB api.EventHandlerCB validEntityTypes []model.EntityTypeType } var _ UCOSCEVInterface = (*UCOSCEV)(nil) -func NewUCOSCEV(service serviceapi.ServiceInterface, reader api.EventReaderInterface) *UCOSCEV { +func NewUCOSCEV(service serviceapi.ServiceInterface, eventCB api.EventHandlerCB) *UCOSCEV { uc := &UCOSCEV{ service: service, - reader: reader, + eventCB: eventCB, } uc.validEntityTypes = []model.EntityTypeType{ diff --git a/ucvabd/events.go b/ucvabd/events.go index 26e5bc2..a0903d0 100644 --- a/ucvabd/events.go +++ b/ucvabd/events.go @@ -81,21 +81,21 @@ func (e *UCVABD) inverterMeasurementDescriptionDataUpdate(entity spineapi.Entity func (e *UCVABD) inverterMeasurementDataUpdate(ski string, entity spineapi.EntityRemoteInterface) { // Scenario 1 if _, err := util.MeasurementValueForScope(e.service, entity, model.ScopeTypeTypeACPowerTotal); err == nil { - e.reader.Event(ski, entity.Device(), entity, api.UCVABDPowerTotalMeasurementDataUpdate) + e.eventCB(ski, entity.Device(), entity, api.UCVABDPowerTotalMeasurementDataUpdate) } // Scenario 2 if _, err := util.MeasurementValueForScope(e.service, entity, model.ScopeTypeTypeCharge); err == nil { - e.reader.Event(ski, entity.Device(), entity, api.UCVABDChargeMeasurementDataUpdate) + e.eventCB(ski, entity.Device(), entity, api.UCVABDChargeMeasurementDataUpdate) } // Scenario 3 if _, err := util.MeasurementValueForScope(e.service, entity, model.ScopeTypeTypeDischarge); err == nil { - e.reader.Event(ski, entity.Device(), entity, api.UCVABDDischargeMeasurementDataUpdate) + e.eventCB(ski, entity.Device(), entity, api.UCVABDDischargeMeasurementDataUpdate) } // Scenario 4 if _, err := util.MeasurementValueForScope(e.service, entity, model.ScopeTypeTypeStateOfCharge); err == nil { - e.reader.Event(ski, entity.Device(), entity, api.UCVABDStateOfChargeMeasurementDataUpdate) + e.eventCB(ski, entity.Device(), entity, api.UCVABDStateOfChargeMeasurementDataUpdate) } } diff --git a/ucvabd/testhelper_test.go b/ucvabd/testhelper_test.go index c435b80..f26937b 100644 --- a/ucvabd/testhelper_test.go +++ b/ucvabd/testhelper_test.go @@ -64,7 +64,7 @@ func (s *UCVABDSuite) BeforeTest(suiteName, testName string) { s.mockRemoteEntity.EXPECT().Address().Return(entityAddress).Maybe() mockRemoteFeature.EXPECT().DataCopy(mock.Anything).Return(mock.Anything).Maybe() - s.sut = NewUCVABD(s.service, s) + s.sut = NewUCVABD(s.service, s.Event) s.sut.AddFeatures() s.sut.AddUseCase() diff --git a/ucvabd/ucvabd.go b/ucvabd/ucvabd.go index 362475c..aa27331 100644 --- a/ucvabd/ucvabd.go +++ b/ucvabd/ucvabd.go @@ -13,17 +13,17 @@ import ( type UCVABD struct { service serviceapi.ServiceInterface - reader api.EventReaderInterface + eventCB api.EventHandlerCB validEntityTypes []model.EntityTypeType } var _ UCVABDInterface = (*UCVABD)(nil) -func NewUCVABD(service serviceapi.ServiceInterface, reader api.EventReaderInterface) *UCVABD { +func NewUCVABD(service serviceapi.ServiceInterface, eventCB api.EventHandlerCB) *UCVABD { uc := &UCVABD{ service: service, - reader: reader, + eventCB: eventCB, } uc.validEntityTypes = []model.EntityTypeType{ diff --git a/ucvapd/events.go b/ucvapd/events.go index ac3467f..b820069 100644 --- a/ucvapd/events.go +++ b/ucvapd/events.go @@ -97,7 +97,7 @@ func (e *UCVAPD) inverterConfigurationDataUpdate(ski string, entity spineapi.Ent // Scenario 1 if deviceConfiguration, err := util.DeviceConfiguration(e.service, entity); err == nil { if _, err := deviceConfiguration.GetKeyValueForKeyName(model.DeviceConfigurationKeyNameTypePeakPowerOfPVSystem, model.DeviceConfigurationKeyValueTypeTypeScaledNumber); err == nil { - e.reader.Event(ski, entity.Device(), entity, api.UCVAPDPeakPowerDataUpdate) + e.eventCB(ski, entity.Device(), entity, api.UCVAPDPeakPowerDataUpdate) } } } @@ -116,11 +116,11 @@ func (e *UCVAPD) inverterMeasurementDescriptionDataUpdate(entity spineapi.Entity func (e *UCVAPD) inverterMeasurementDataUpdate(ski string, entity spineapi.EntityRemoteInterface) { // Scenario 2 if _, err := util.MeasurementValueForScope(e.service, entity, model.ScopeTypeTypeACPowerTotal); err == nil { - e.reader.Event(ski, entity.Device(), entity, api.UCVAPDPowerTotalMeasurementDataUpdate) + e.eventCB(ski, entity.Device(), entity, api.UCVAPDPowerTotalMeasurementDataUpdate) } // Scenario 3 if _, err := util.MeasurementValueForScope(e.service, entity, model.ScopeTypeTypeACYieldTotal); err == nil { - e.reader.Event(ski, entity.Device(), entity, api.UCVAPDYieldTotalMeasurementDataUpdate) + e.eventCB(ski, entity.Device(), entity, api.UCVAPDYieldTotalMeasurementDataUpdate) } } diff --git a/ucvapd/testhelper_test.go b/ucvapd/testhelper_test.go index 9b3e9e3..7ad9022 100644 --- a/ucvapd/testhelper_test.go +++ b/ucvapd/testhelper_test.go @@ -64,7 +64,7 @@ func (s *UCVAPDSuite) BeforeTest(suiteName, testName string) { s.mockRemoteEntity.EXPECT().Address().Return(entityAddress).Maybe() mockRemoteFeature.EXPECT().DataCopy(mock.Anything).Return(mock.Anything).Maybe() - s.sut = NewUCVAPD(s.service, s) + s.sut = NewUCVAPD(s.service, s.Event) s.sut.AddFeatures() s.sut.AddUseCase() diff --git a/ucvapd/ucvapd.go b/ucvapd/ucvapd.go index 0e33a95..6db5ba7 100644 --- a/ucvapd/ucvapd.go +++ b/ucvapd/ucvapd.go @@ -13,17 +13,17 @@ import ( type UCVAPD struct { service serviceapi.ServiceInterface - reader api.EventReaderInterface + eventCB api.EventHandlerCB validEntityTypes []model.EntityTypeType } var _ UCVAPDInterface = (*UCVAPD)(nil) -func NewUCVAPD(service serviceapi.ServiceInterface, reader api.EventReaderInterface) *UCVAPD { +func NewUCVAPD(service serviceapi.ServiceInterface, eventCB api.EventHandlerCB) *UCVAPD { uc := &UCVAPD{ service: service, - reader: reader, + eventCB: eventCB, } uc.validEntityTypes = []model.EntityTypeType{