Skip to content

Commit

Permalink
Fix: have CurrentLimits method in opev and oscev filter for LoadContr…
Browse files Browse the repository at this point in the history
…olLimitDescription instead of MeasurementDescription (#144)

Since the "ScopeType" field in the LoadControlLimitDescription is more relevant (with a value of "overloadProtection" and "selfConsumption" for OPEV and OSCEV, respectively), it shall be used as the filter for
obtaining the relevant ElectricalConnectionPermittedValueSetListData items in the CurrentLimits getters for
[OPEV](https://github.com/enbility/eebus-go/blob/59e7016a7018364d209f72331685b0ef0ba97b67/usecases/cem/opev/public.go#L19) and [OSCEV](https://github.com/enbility/eebus-go/blob/59e7016a7018364d209f72331685b0ef0ba97b67/usecases/cem/oscev/public.go#L19).
From the relevant LoadControlLimitDescriptionData items, one can get their corresponding measurement IDs and use them to filter for relevant parameter description items.
  • Loading branch information
AhmedMagdyCoretech authored Nov 28, 2024
1 parent 59e7016 commit 82f4b31
Show file tree
Hide file tree
Showing 4 changed files with 122 additions and 32 deletions.
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
}
md := model.MeasurementDescriptionDataType{
MeasurementId: measId,
}
measDescs = append(measDescs, md)
}
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
}
md := model.MeasurementDescriptionDataType{
MeasurementId: measId,
}
measDescs = append(measDescs, md)
}
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

0 comments on commit 82f4b31

Please sign in to comment.