Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: have CurrentLimits method in opev and oscev filter for LoadControlLimitDescription instead of MeasurementDescription #144

Merged
31 changes: 23 additions & 8 deletions usecases/cem/opev/public.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
filter := model.MeasurementDescriptionDataType{
AhmedMagdyCoretech marked this conversation as resolved.
Show resolved Hide resolved
MeasurementId: measId,
}
measDescs = append(measDescs, filter)
}
return ec.GetPhaseCurrentLimits(measDescs)
}

// return the current loadcontrol obligation limits
Expand Down
46 changes: 38 additions & 8 deletions usecases/cem/opev/public_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
31 changes: 23 additions & 8 deletions usecases/cem/oscev/public.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
filter := model.MeasurementDescriptionDataType{
AhmedMagdyCoretech marked this conversation as resolved.
Show resolved Hide resolved
MeasurementId: measId,
}
measDescs = append(measDescs, filter)
}
return ec.GetPhaseCurrentLimits(measDescs)
}

// return the current loadcontrol recommendation limits
Expand Down
46 changes: 38 additions & 8 deletions usecases/cem/oscev/public_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down