diff --git a/features/internal/electricalconnection.go b/features/internal/electricalconnection.go index a6c3d5dd..f106c3d5 100644 --- a/features/internal/electricalconnection.go +++ b/features/internal/electricalconnection.go @@ -60,6 +60,39 @@ func (e *ElectricalConnectionCommon) CheckEventPayloadDataForFilter(payloadData return false } +// check if spine.EventPayload Data contains data for a given filter +// +// data type will be checked for model.ElectricalConnectionCharacteristicListDataType, +// filter type will be checked for model.ElectricalConnectionCharacteristicDataType +func (e *ElectricalConnectionCommon) CheckEventPayloadDataForFilterDescriptionList(payloadData any, filter any) bool { + if payloadData == nil { + return false + } + + data, ok := payloadData.(*model.ElectricalConnectionCharacteristicListDataType) + filterData, ok2 := filter.(model.ElectricalConnectionCharacteristicDataType) + if !ok || !ok2 { + return false + } + + descs, err := e.GetCharacteristicsForFilter(filterData) + if err != nil { + return false + } + + for _, desc := range descs { + for _, item := range data.ElectricalConnectionCharacteristicData { + if item.ParameterId != nil && + desc.ParameterId != nil && + *item.ParameterId == *desc.ParameterId { + return true + } + } + } + + return false +} + // Get the description for a given filter // // Returns an error if no matching description is found diff --git a/usecases/eg/lpc/events.go b/usecases/eg/lpc/events.go index ef2a89bb..1a3dbb16 100644 --- a/usecases/eg/lpc/events.go +++ b/usecases/eg/lpc/events.go @@ -41,6 +41,9 @@ func (e *LPC) HandleEvent(payload spineapi.EventPayload) { case *model.DeviceConfigurationKeyValueListDataType: e.configurationDataUpdate(payload) + + case *model.ElectricalConnectionCharacteristicListDataType: + e.electricalConnectionCharacteristicDataUpdate(payload) } } @@ -102,6 +105,39 @@ func (e *LPC) connected(entity spineapi.EntityRemoteInterface) { logging.Log().Debug(err) } } + + if electricalConnection, err := client.NewElectricalConnection(e.LocalEntity, entity); err == nil { + if !electricalConnection.HasSubscription() { + if _, err := electricalConnection.Subscribe(); err != nil { + logging.Log().Debug(err) + } + } + + // get characteristics + selector := &model.ElectricalConnectionCharacteristicListDataSelectorsType{ + CharacteristicContext: util.Ptr(model.ElectricalConnectionCharacteristicContextTypeEntity), + CharacteristicType: util.Ptr(e.characteristicType(entity)), + } + if _, err := electricalConnection.RequestCharacteristics(selector, nil); err != nil { + logging.Log().Debug(err) + } + } +} + +// the electrical connection power consumption nominal max was updated +func (e *LPC) electricalConnectionCharacteristicDataUpdate(payload spineapi.EventPayload) { + if electricalConnection, err := client.NewElectricalConnection(e.LocalEntity, payload.Entity); err == nil { + filter := model.ElectricalConnectionCharacteristicDataType{ + ElectricalConnectionId: util.Ptr(model.ElectricalConnectionIdType(0)), + ParameterId: util.Ptr(model.ElectricalConnectionParameterIdType(0)), + CharacteristicType: util.Ptr(e.characteristicType(payload.Entity)), + CharacteristicContext: util.Ptr(model.ElectricalConnectionCharacteristicContextTypeEntity), + } + + if electricalConnection.CheckEventPayloadDataForFilterDescriptionList(payload.Data, filter) && e.EventCB != nil { + e.EventCB(payload.Ski, payload.Device, payload.Entity, DataUpdatePowerConsumptionNominalMax) + } + } } // the load control limit description data was updated diff --git a/usecases/eg/lpc/testhelper_test.go b/usecases/eg/lpc/testhelper_test.go index b8531828..e784d330 100644 --- a/usecases/eg/lpc/testhelper_test.go +++ b/usecases/eg/lpc/testhelper_test.go @@ -63,6 +63,7 @@ func (s *EgLPCSuite) BeforeTest(suiteName, testName string) { mockRemoteFeature := spinemocks.NewFeatureRemoteInterface(s.T()) mockRemoteDevice.EXPECT().FeatureByEntityTypeAndRole(mock.Anything, mock.Anything, mock.Anything).Return(mockRemoteFeature).Maybe() mockRemoteDevice.EXPECT().Ski().Return(remoteSki).Maybe() + mockRemoteDevice.EXPECT().DeviceType().Return(util.Ptr(model.DeviceTypeTypeChargingStation)).Maybe() s.mockRemoteEntity.EXPECT().Device().Return(mockRemoteDevice).Maybe() s.mockRemoteEntity.EXPECT().EntityType().Return(mock.Anything).Maybe() entityAddress := &model.EntityAddressType{} diff --git a/usecases/eg/lpc/types.go b/usecases/eg/lpc/types.go index e2a507f9..bbf11f0d 100644 --- a/usecases/eg/lpc/types.go +++ b/usecases/eg/lpc/types.go @@ -36,4 +36,11 @@ const ( // // Use Case LPC, Scenario 3 DataUpdateHeartbeat api.EventType = "eg-lpc-DataUpdateHeartbeat" + + //Electrical connection power consumption nominal max updated + // + //Use 'ProductionNominalMax' to get the current data + // + // Use Case LPP, Scenario 4 + DataUpdatePowerConsumptionNominalMax api.EventType = "eg-lpc-DataUpdatePowerConsumptionNominalMax" ) diff --git a/usecases/eg/lpp/events.go b/usecases/eg/lpp/events.go index bb91cd9c..47bcfdb2 100644 --- a/usecases/eg/lpp/events.go +++ b/usecases/eg/lpp/events.go @@ -42,6 +42,9 @@ func (e *LPP) HandleEvent(payload spineapi.EventPayload) { case *model.DeviceConfigurationKeyValueListDataType: e.configurationDataUpdate(payload) + + case *model.ElectricalConnectionCharacteristicListDataType: + e.electricalConnectionCharacteristicDataUpdate(payload) } } @@ -103,6 +106,39 @@ func (e *LPP) connected(entity spineapi.EntityRemoteInterface) { logging.Log().Debug(err) } } + + if electricalConnection, err := client.NewElectricalConnection(e.LocalEntity, entity); err == nil { + if !electricalConnection.HasSubscription() { + if _, err := electricalConnection.Subscribe(); err != nil { + logging.Log().Debug(err) + } + } + + // get characteristics + selector := &model.ElectricalConnectionCharacteristicListDataSelectorsType{ + CharacteristicContext: util.Ptr(model.ElectricalConnectionCharacteristicContextTypeEntity), + CharacteristicType: util.Ptr(e.characteristicType(entity)), + } + if _, err := electricalConnection.RequestCharacteristics(selector, nil); err != nil { + logging.Log().Debug(err) + } + } +} + +// the electrical connection power production nominal max was updated +func (e *LPP) electricalConnectionCharacteristicDataUpdate(payload spineapi.EventPayload) { + if electricalConnection, err := client.NewElectricalConnection(e.LocalEntity, payload.Entity); err == nil { + filter := model.ElectricalConnectionCharacteristicDataType{ + ElectricalConnectionId: util.Ptr(model.ElectricalConnectionIdType(0)), + ParameterId: util.Ptr(model.ElectricalConnectionParameterIdType(0)), + CharacteristicType: util.Ptr(e.characteristicType(payload.Entity)), + CharacteristicContext: util.Ptr(model.ElectricalConnectionCharacteristicContextTypeEntity), + } + + if electricalConnection.CheckEventPayloadDataForFilterDescriptionList(payload.Data, filter) && e.EventCB != nil { + e.EventCB(payload.Ski, payload.Device, payload.Entity, DataUpdatePowerProductionNominalMax) + } + } } // the load control limit description data was updated diff --git a/usecases/eg/lpp/testhelper_test.go b/usecases/eg/lpp/testhelper_test.go index 2d3b1285..1513982a 100644 --- a/usecases/eg/lpp/testhelper_test.go +++ b/usecases/eg/lpp/testhelper_test.go @@ -63,6 +63,7 @@ func (s *EgLPPSuite) BeforeTest(suiteName, testName string) { mockRemoteFeature := spinemocks.NewFeatureRemoteInterface(s.T()) mockRemoteDevice.EXPECT().FeatureByEntityTypeAndRole(mock.Anything, mock.Anything, mock.Anything).Return(mockRemoteFeature).Maybe() mockRemoteDevice.EXPECT().Ski().Return(remoteSki).Maybe() + mockRemoteDevice.EXPECT().DeviceType().Return(util.Ptr(model.DeviceTypeTypeChargingStation)).Maybe() s.mockRemoteEntity.EXPECT().Device().Return(mockRemoteDevice).Maybe() s.mockRemoteEntity.EXPECT().EntityType().Return(mock.Anything).Maybe() entityAddress := &model.EntityAddressType{} diff --git a/usecases/eg/lpp/types.go b/usecases/eg/lpp/types.go index d2ed9452..fe48703a 100644 --- a/usecases/eg/lpp/types.go +++ b/usecases/eg/lpp/types.go @@ -36,4 +36,11 @@ const ( // // Use Case LPP, Scenario 3 DataUpdateHeartbeat api.EventType = "eg-lpp-DataUpdateHeartbeat" + + //Electrical connection power production nominal max updated + // + //Use 'ConsumptionNominalMax' to get the current data + // + // Use Case LPP, Scenario 4 + DataUpdatePowerProductionNominalMax api.EventType = "eg-lpp-DataUpdatePowerProductionNominalMax" )