From b3f9e2c8c7988e659a2fd2c61b68ca985a9e3195 Mon Sep 17 00:00:00 2001 From: "ahmed.magdy" Date: Tue, 26 Nov 2024 12:31:08 +0200 Subject: [PATCH] have CurrentLimits method in opev and oscev filter for LoadControlLimitDescriptionData instead of MeasurementDescriptionData --- usecases/cem/opev/public.go | 37 +++++++++++++++++++++++++++++------- usecases/cem/oscev/public.go | 37 +++++++++++++++++++++++++++++------- 2 files changed, 60 insertions(+), 14 deletions(-) diff --git a/usecases/cem/opev/public.go b/usecases/cem/opev/public.go index 15764008..f7b3d10c 100644 --- a/usecases/cem/opev/public.go +++ b/usecases/cem/opev/public.go @@ -26,23 +26,46 @@ func (e *OPEV) CurrentLimits(entity spineapi.EntityRemoteInterface) ([]float64, return nil, nil, nil, err } + lc, err := client.NewLoadControl(e.LocalEntity, entity) + if err != nil { + return nil, nil, nil, err + } + meas, err := client.NewMeasurement(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) != 3 { + return nil, nil, nil, api.ErrDataNotAvailable + } - return ec.GetPhaseCurrentLimits(measDesc) + measDescs := make([]model.MeasurementDescriptionDataType, 0) + for _, ld := range limitDescs { + filter := model.MeasurementDescriptionDataType{ + MeasurementId: ld.MeasurementId, + } + mds, err := meas.GetDescriptionsForFilter(filter) + if err != nil { + return nil, nil, nil, err + } + if len(mds) != 1 { + return nil, nil, nil, api.ErrDataNotAvailable + } + measDescs = append(measDescs, mds[0]) + } + return ec.GetPhaseCurrentLimits(measDescs) } // return the current loadcontrol obligation limits diff --git a/usecases/cem/oscev/public.go b/usecases/cem/oscev/public.go index 6e030e37..655b3bb2 100644 --- a/usecases/cem/oscev/public.go +++ b/usecases/cem/oscev/public.go @@ -26,23 +26,46 @@ func (e *OSCEV) CurrentLimits(entity spineapi.EntityRemoteInterface) ([]float64, return nil, nil, nil, err } + lc, err := client.NewLoadControl(e.LocalEntity, entity) + if err != nil { + return nil, nil, nil, err + } + meas, err := client.NewMeasurement(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) != 3 { + return nil, nil, nil, api.ErrDataNotAvailable + } - return ec.GetPhaseCurrentLimits(measDesc) + measDescs := make([]model.MeasurementDescriptionDataType, 0) + for _, ld := range limitDescs { + filter := model.MeasurementDescriptionDataType{ + MeasurementId: ld.MeasurementId, + } + mds, err := meas.GetDescriptionsForFilter(filter) + if err != nil { + return nil, nil, nil, err + } + if len(mds) != 1 { + return nil, nil, nil, api.ErrDataNotAvailable + } + measDescs = append(measDescs, mds[0]) + } + return ec.GetPhaseCurrentLimits(measDescs) } // return the current loadcontrol recommendation limits