diff --git a/usecases/cem/opev/public.go b/usecases/cem/opev/public.go index 15764008..188158ba 100644 --- a/usecases/cem/opev/public.go +++ b/usecases/cem/opev/public.go @@ -26,23 +26,38 @@ func (e *OPEV) CurrentLimits(entity spineapi.EntityRemoteInterface) ([]float64, return nil, nil, nil, err } - meas, err := client.NewMeasurement(e.LocalEntity, entity) + lc, err := client.NewLoadControl(e.LocalEntity, entity) if err != nil { return nil, nil, nil, err } - filter := model.MeasurementDescriptionDataType{ - MeasurementType: util.Ptr(model.MeasurementTypeTypeCurrent), - CommodityType: util.Ptr(model.CommodityTypeTypeElectricity), - Unit: util.Ptr(model.UnitOfMeasurementTypeA), - ScopeType: util.Ptr(model.ScopeTypeTypeACCurrent), + filter := model.LoadControlLimitDescriptionDataType { + LimitType: util.Ptr(model.LoadControlLimitTypeTypeMaxValueLimit), + LimitCategory: util.Ptr(model.LoadControlCategoryTypeObligation), + Unit: util.Ptr(model.UnitOfMeasurementTypeA), + ScopeType: util.Ptr(model.ScopeTypeTypeOverloadProtection), } - measDesc, err := meas.GetDescriptionsForFilter(filter) + + limitDescs, err := lc.GetLimitDescriptionsForFilter(filter) if err != nil { return nil, nil, nil, err } + if len(limitDescs) == 0 { + return nil, nil, nil, api.ErrDataNotAvailable + } - return ec.GetPhaseCurrentLimits(measDesc) + measDescs := make([]model.MeasurementDescriptionDataType, 0) + for _, ld := range limitDescs { + measId := ld.MeasurementId + if measId == nil { + return nil, nil, nil, api.ErrDataNotAvailable + } + md := model.MeasurementDescriptionDataType{ + MeasurementId: measId, + } + measDescs = append(measDescs, md) + } + return ec.GetPhaseCurrentLimits(measDescs) } // return the current loadcontrol obligation limits diff --git a/usecases/cem/opev/public_test.go b/usecases/cem/opev/public_test.go index 644e0f6a..c4263648 100644 --- a/usecases/cem/opev/public_test.go +++ b/usecases/cem/opev/public_test.go @@ -16,21 +16,51 @@ func (s *CemOPEVSuite) Test_Public() { _, _, _, err = s.sut.CurrentLimits(s.evEntity) assert.NotNil(s.T(), err) + lc := s.evEntity.FeatureOfTypeAndRole(model.FeatureTypeTypeLoadControl, model.RoleTypeServer) + assert.NotNil(s.T(), lc) + meas := s.evEntity.FeatureOfTypeAndRole(model.FeatureTypeTypeMeasurement, model.RoleTypeServer) assert.NotNil(s.T(), meas) - mData := &model.MeasurementDescriptionListDataType{ - MeasurementDescriptionData: []model.MeasurementDescriptionDataType{ + lData := &model.LoadControlLimitDescriptionListDataType{ + LoadControlLimitDescriptionData: []model.LoadControlLimitDescriptionDataType{ + }, + } + + _,errT := lc.UpdateData(true, model.FunctionTypeLoadControlLimitDescriptionListData, lData, nil, nil) + assert.Nil(s.T(), errT) + + _, _, _, err = s.sut.CurrentLimits(s.evEntity) + assert.NotNil(s.T(), err) + + lData = &model.LoadControlLimitDescriptionListDataType{ + LoadControlLimitDescriptionData: []model.LoadControlLimitDescriptionDataType{ + { + LimitId: util.Ptr(model.LoadControlLimitIdType(0)), + LimitCategory: util.Ptr(model.LoadControlCategoryTypeObligation), + LimitType: util.Ptr(model.LoadControlLimitTypeTypeMaxValueLimit), + Unit: util.Ptr(model.UnitOfMeasurementTypeA), + ScopeType: util.Ptr(model.ScopeTypeTypeOverloadProtection), + }, + }, + } + + _,errT = lc.UpdateData(true, model.FunctionTypeLoadControlLimitDescriptionListData, lData, nil, nil) + assert.Nil(s.T(), errT) + + _, _, _, err = s.sut.CurrentLimits(s.evEntity) + assert.NotNil(s.T(), err) + + lData = &model.LoadControlLimitDescriptionListDataType{ + LoadControlLimitDescriptionData: []model.LoadControlLimitDescriptionDataType{ { - MeasurementId: util.Ptr(model.MeasurementIdType(0)), - MeasurementType: util.Ptr(model.MeasurementTypeTypeCurrent), - CommodityType: util.Ptr(model.CommodityTypeTypeElectricity), - Unit: util.Ptr(model.UnitOfMeasurementTypeA), - ScopeType: util.Ptr(model.ScopeTypeTypeACCurrent), + LimitId: util.Ptr(model.LoadControlLimitIdType(0)), + MeasurementId: util.Ptr(model.MeasurementIdType(0)), }, }, } - _, errT := meas.UpdateData(true, model.FunctionTypeMeasurementDescriptionListData, mData, nil, nil) + + _,errT = lc.UpdateData(true, model.FunctionTypeLoadControlLimitDescriptionListData, lData, &model.FilterType{}, nil) assert.Nil(s.T(), errT) _, _, _, err = s.sut.CurrentLimits(s.evEntity) diff --git a/usecases/cem/oscev/public.go b/usecases/cem/oscev/public.go index 6e030e37..1a2a64c5 100644 --- a/usecases/cem/oscev/public.go +++ b/usecases/cem/oscev/public.go @@ -26,23 +26,38 @@ func (e *OSCEV) CurrentLimits(entity spineapi.EntityRemoteInterface) ([]float64, return nil, nil, nil, err } - meas, err := client.NewMeasurement(e.LocalEntity, entity) + lc, err := client.NewLoadControl(e.LocalEntity, entity) if err != nil { return nil, nil, nil, err } - filter := model.MeasurementDescriptionDataType{ - MeasurementType: util.Ptr(model.MeasurementTypeTypeCurrent), - CommodityType: util.Ptr(model.CommodityTypeTypeElectricity), - Unit: util.Ptr(model.UnitOfMeasurementTypeA), - ScopeType: util.Ptr(model.ScopeTypeTypeACCurrent), + filter := model.LoadControlLimitDescriptionDataType { + LimitType: util.Ptr(model.LoadControlLimitTypeTypeMaxValueLimit), + LimitCategory: util.Ptr(model.LoadControlCategoryTypeRecommendation), + Unit: util.Ptr(model.UnitOfMeasurementTypeA), + ScopeType: util.Ptr(model.ScopeTypeTypeSelfConsumption), } - measDesc, err := meas.GetDescriptionsForFilter(filter) + + limitDescs, err := lc.GetLimitDescriptionsForFilter(filter) if err != nil { return nil, nil, nil, err } + if len(limitDescs) == 0 { + return nil, nil, nil, api.ErrDataNotAvailable + } - return ec.GetPhaseCurrentLimits(measDesc) + measDescs := make([]model.MeasurementDescriptionDataType, 0) + for _, ld := range limitDescs { + measId := ld.MeasurementId + if measId == nil { + return nil, nil, nil, api.ErrDataNotAvailable + } + md := model.MeasurementDescriptionDataType{ + MeasurementId: measId, + } + measDescs = append(measDescs, md) + } + return ec.GetPhaseCurrentLimits(measDescs) } // return the current loadcontrol recommendation limits diff --git a/usecases/cem/oscev/public_test.go b/usecases/cem/oscev/public_test.go index 1f6d8ed5..047f1c19 100644 --- a/usecases/cem/oscev/public_test.go +++ b/usecases/cem/oscev/public_test.go @@ -16,21 +16,51 @@ func (s *CemOSCEVSuite) Test_Public() { _, _, _, err = s.sut.CurrentLimits(s.evEntity) assert.NotNil(s.T(), err) + lc := s.evEntity.FeatureOfTypeAndRole(model.FeatureTypeTypeLoadControl, model.RoleTypeServer) + assert.NotNil(s.T(), lc) + meas := s.evEntity.FeatureOfTypeAndRole(model.FeatureTypeTypeMeasurement, model.RoleTypeServer) assert.NotNil(s.T(), meas) - mData := &model.MeasurementDescriptionListDataType{ - MeasurementDescriptionData: []model.MeasurementDescriptionDataType{ + lData := &model.LoadControlLimitDescriptionListDataType{ + LoadControlLimitDescriptionData: []model.LoadControlLimitDescriptionDataType{ + }, + } + + _,errT := lc.UpdateData(true, model.FunctionTypeLoadControlLimitDescriptionListData, lData, nil, nil) + assert.Nil(s.T(), errT) + + _, _, _, err = s.sut.CurrentLimits(s.evEntity) + assert.NotNil(s.T(), err) + + lData = &model.LoadControlLimitDescriptionListDataType{ + LoadControlLimitDescriptionData: []model.LoadControlLimitDescriptionDataType{ + { + LimitId: util.Ptr(model.LoadControlLimitIdType(0)), + LimitCategory: util.Ptr(model.LoadControlCategoryTypeRecommendation), + LimitType: util.Ptr(model.LoadControlLimitTypeTypeMaxValueLimit), + Unit: util.Ptr(model.UnitOfMeasurementTypeA), + ScopeType: util.Ptr(model.ScopeTypeTypeSelfConsumption), + }, + }, + } + + _,errT = lc.UpdateData(true, model.FunctionTypeLoadControlLimitDescriptionListData, lData, nil, nil) + assert.Nil(s.T(), errT) + + _, _, _, err = s.sut.CurrentLimits(s.evEntity) + assert.NotNil(s.T(), err) + + lData = &model.LoadControlLimitDescriptionListDataType{ + LoadControlLimitDescriptionData: []model.LoadControlLimitDescriptionDataType{ { - MeasurementId: util.Ptr(model.MeasurementIdType(0)), - MeasurementType: util.Ptr(model.MeasurementTypeTypeCurrent), - CommodityType: util.Ptr(model.CommodityTypeTypeElectricity), - Unit: util.Ptr(model.UnitOfMeasurementTypeA), - ScopeType: util.Ptr(model.ScopeTypeTypeACCurrent), + LimitId: util.Ptr(model.LoadControlLimitIdType(0)), + MeasurementId: util.Ptr(model.MeasurementIdType(0)), }, }, } - _, errT := meas.UpdateData(true, model.FunctionTypeMeasurementDescriptionListData, mData, nil, nil) + + _,errT = lc.UpdateData(true, model.FunctionTypeLoadControlLimitDescriptionListData, lData, &model.FilterType{}, nil) assert.Nil(s.T(), errT) _, _, _, err = s.sut.CurrentLimits(s.evEntity)