Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/dev' into feat/ohpcf
Browse files Browse the repository at this point in the history
  • Loading branch information
heavyweight87 committed Oct 16, 2024
2 parents 7dcecb4 + ad27b3c commit 46a1a1f
Show file tree
Hide file tree
Showing 15 changed files with 628 additions and 181 deletions.
79 changes: 62 additions & 17 deletions api/featuresserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,17 @@ type DeviceDiagnosisServerInterface interface {
SetLocalOperatingState(operatingState model.DeviceDiagnosisOperatingStateType)
}

type ElectricalConnectionPermittedValueSetForID struct {
Data model.ElectricalConnectionPermittedValueSetDataType
ElectricalConnectionId model.ElectricalConnectionIdType
ParameterId model.ElectricalConnectionParameterIdType
}

type ElectricalConnectionPermittedValueSetForFilter struct {
Data model.ElectricalConnectionPermittedValueSetDataType
Filter model.ElectricalConnectionParameterDescriptionDataType
}

type ElectricalConnectionServerInterface interface {
ElectricalConnectionCommonInterface

Expand Down Expand Up @@ -80,6 +91,34 @@ type ElectricalConnectionServerInterface interface {
data model.ElectricalConnectionCharacteristicDataType,
deleteElements *model.ElectricalConnectionCharacteristicDataElementsType,
) error

// Set or update data set for a parameterId
//
// Will return an error if the data set could not be updated
UpdatePermittedValueSetForIds(
data []ElectricalConnectionPermittedValueSetForID,
) error

// Set or update data set for a filter
// deleteSelector will trigger removal of matching items from the data set before the update
// deleteElement will limit the fields to be removed using Id
//
// Will return an error if the data set could not be updated
UpdatePermittedValueSetForFilters(
data []ElectricalConnectionPermittedValueSetForFilter,
deleteSelector *model.ElectricalConnectionPermittedValueSetListDataSelectorsType,
deleteElements *model.ElectricalConnectionPermittedValueSetDataElementsType,
) error
}

type LoadControlLimitDataForID struct {
Data model.LoadControlLimitDataType
Id model.LoadControlLimitIdType
}

type LoadControlLimitDataForFilter struct {
Data model.LoadControlLimitDataType
Filter model.LoadControlLimitDescriptionDataType
}

type LoadControlServerInterface interface {
Expand All @@ -93,26 +132,34 @@ type LoadControlServerInterface interface {
) *model.LoadControlLimitIdType

// Set or update data set for a limitId
// Elements provided in deleteElements will be removed from the data set before the update
//
// Will return an error if the data set could not be updated
UpdateLimitDataForId(
data model.LoadControlLimitDataType,
deleteElements *model.LoadControlLimitDataElementsType,
limitId model.LoadControlLimitIdType,
UpdateLimitDataForIds(
data []LoadControlLimitDataForID,
) error

// Set or update data set for a filter
// Elements provided in deleteElements will be removed from the data set before the update
// deleteSelector will trigger removal of matching items from the data set before the update
// deleteElement will limit the fields to be removed using Id
//
// Will return an error if the data set could not be updated
UpdateLimitDataForFilter(
data model.LoadControlLimitDataType,
data []LoadControlLimitDataForFilter,
deleteSelector *model.LoadControlLimitListDataSelectorsType,
deleteElements *model.LoadControlLimitDataElementsType,
filter model.LoadControlLimitDescriptionDataType,
) error
}

type MeasurementDataForID struct {
Data model.MeasurementDataType
Id model.MeasurementIdType
}

type MeasurementDataForFilter struct {
Data model.MeasurementDataType
Filter model.MeasurementDescriptionDataType
}

type MeasurementServerInterface interface {
// Add a new parameter description data sett and return the measurementId
//
Expand All @@ -124,23 +171,21 @@ type MeasurementServerInterface interface {
) *model.MeasurementIdType

// Set or update data set for a measurementId
// Elements provided in deleteElements will be removed from the data set before the update
//
// Will return an error if the data set could not be updated
UpdateDataForId(
data model.MeasurementDataType,
deleteElements *model.MeasurementDataElementsType,
measurementId model.MeasurementIdType,
UpdateDataForIds(
data []MeasurementDataForID,
) error

// Set or update data set for a filter
// Elements provided in deleteElements will be removed from the data set before the update
// deleteSelector will trigger removal of matching items from the data set before the update
// deleteElement will limit the fields to be removed using Id
//
// Will return an error if the data set could not be updated
UpdateDataForFilter(
data model.MeasurementDataType,
UpdateDataForFilters(
data []MeasurementDataForFilter,
deleteSelector *model.MeasurementListDataSelectorsType,
deleteElements *model.MeasurementDataElementsType,
filter model.MeasurementDescriptionDataType,
) error
}

Expand Down
74 changes: 74 additions & 0 deletions features/server/electricalconnection.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package server
import (
"errors"

"github.com/enbility/eebus-go/api"
"github.com/enbility/eebus-go/features/internal"
spineapi "github.com/enbility/spine-go/api"
"github.com/enbility/spine-go/model"
Expand Down Expand Up @@ -183,3 +184,76 @@ func (e *ElectricalConnection) UpdateCharacteristic(

return nil
}

// Set or update data set for a electricalConnectiontId
// Id provided in deleteId will trigger removal of matching items from the data set before the update
// Elements provided in deleteElement will limit the fields to be removed using Id
//
// Will return an error if the data set could not be updated
func (e *ElectricalConnection) UpdatePermittedValueSetForIds(
data []api.ElectricalConnectionPermittedValueSetForID,
) (resultErr error) {
var filterData []api.ElectricalConnectionPermittedValueSetForFilter
for index, item := range data {
filterData = append(filterData, api.ElectricalConnectionPermittedValueSetForFilter{
Data: item.Data,
Filter: model.ElectricalConnectionParameterDescriptionDataType{
ElectricalConnectionId: &data[index].ElectricalConnectionId,
ParameterId: &data[index].ParameterId,
},
})
}

return e.UpdatePermittedValueSetForFilters(filterData, nil, nil)
}

// Set or update data set for a filter
// deleteSelector will trigger removal of matching items from the data set before the update
// deleteElement will limit the fields to be removed using Id
//
// Will return an error if the data set could not be updated
func (e *ElectricalConnection) UpdatePermittedValueSetForFilters(
data []api.ElectricalConnectionPermittedValueSetForFilter,
deleteSelector *model.ElectricalConnectionPermittedValueSetListDataSelectorsType,
deleteElements *model.ElectricalConnectionPermittedValueSetDataElementsType,
) (resultErr error) {
resultErr = api.ErrDataNotAvailable

var permittedData []model.ElectricalConnectionPermittedValueSetDataType

for _, item := range data {
descriptions, err := e.GetParameterDescriptionsForFilter(item.Filter)
if err != nil || descriptions == nil || len(descriptions) != 1 {
return
}

description := descriptions[0]
item.Data.ElectricalConnectionId = description.ElectricalConnectionId
item.Data.ParameterId = description.ParameterId

permittedData = append(permittedData, item.Data)
}

partial := model.NewFilterTypePartial()

datalist := &model.ElectricalConnectionPermittedValueSetListDataType{
ElectricalConnectionPermittedValueSetData: permittedData,
}

var deleteFilter *model.FilterType
if deleteSelector != nil {
deleteFilter = &model.FilterType{
ElectricalConnectionPermittedValueSetListDataSelectors: deleteSelector,
}

if deleteElements != nil {
deleteFilter.ElectricalConnectionPermittedValueSetDataElements = deleteElements
}
}

if err := e.featureLocal.UpdateData(model.FunctionTypeElectricalConnectionPermittedValueSetListData, datalist, partial, deleteFilter); err != nil {
return errors.New(err.String())
}

return nil
}
116 changes: 116 additions & 0 deletions features/server/electricalconnection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,3 +256,119 @@ func (s *ElectricalConnectionSuite) Test_UpdateCharacteristic() {
assert.Equal(s.T(), 1, len(data))
assert.Nil(s.T(), data[0].Value)
}

func (s *ElectricalConnectionSuite) Test_PermittedData() {
ids := []api.ElectricalConnectionPermittedValueSetForID{
{
ElectricalConnectionId: model.ElectricalConnectionIdType(0),
ParameterId: model.ElectricalConnectionParameterIdType(0),
Data: model.ElectricalConnectionPermittedValueSetDataType{
PermittedValueSet: []model.ScaledNumberSetType{
{
Value: []model.ScaledNumberType{
*model.NewScaledNumberType(10),
},
Range: []model.ScaledNumberRangeType{
{
Min: model.NewScaledNumberType(0),
Max: model.NewScaledNumberType(100),
},
},
},
},
},
},
}

err := s.sut.UpdatePermittedValueSetForIds(ids)
assert.NotNil(s.T(), err)

filter := model.ElectricalConnectionParameterDescriptionDataType{
ElectricalConnectionId: util.Ptr(model.ElectricalConnectionIdType(0)),
MeasurementId: util.Ptr(model.MeasurementIdType(0)),
ScopeType: util.Ptr(model.ScopeTypeTypeACPowerTotal),
}

data := []api.ElectricalConnectionPermittedValueSetForFilter{
{
Filter: filter,
},
}
err = s.sut.UpdatePermittedValueSetForFilters(data, nil, nil)
assert.NotNil(s.T(), err)

data = []api.ElectricalConnectionPermittedValueSetForFilter{
{
Data: model.ElectricalConnectionPermittedValueSetDataType{
ParameterId: util.Ptr(model.ElectricalConnectionParameterIdType(0)),
},
Filter: filter,
},
}
err = s.sut.UpdatePermittedValueSetForFilters(data, nil, nil)
assert.NotNil(s.T(), err)

pdId := s.sut.AddParameterDescription(filter)
assert.NotNil(s.T(), pdId)

filter.ParameterId = pdId

vsFilter := model.ElectricalConnectionPermittedValueSetDataType{
ElectricalConnectionId: util.Ptr(model.ElectricalConnectionIdType(0)),
ParameterId: pdId,
}
result, err := s.sut.GetPermittedValueSetForFilter(vsFilter)
assert.NotNil(s.T(), err)
assert.Nil(s.T(), result)

data = []api.ElectricalConnectionPermittedValueSetForFilter{
{
Data: model.ElectricalConnectionPermittedValueSetDataType{
PermittedValueSet: []model.ScaledNumberSetType{
{
Value: []model.ScaledNumberType{
*model.NewScaledNumberType(10),
},
Range: []model.ScaledNumberRangeType{
{
Min: model.NewScaledNumberType(0),
Max: model.NewScaledNumberType(100),
},
},
},
},
},
Filter: filter,
},
}
err = s.sut.UpdatePermittedValueSetForFilters(data, nil, nil)
assert.Nil(s.T(), err)

result, err = s.sut.GetPermittedValueSetForFilter(vsFilter)
assert.Nil(s.T(), err)
assert.NotNil(s.T(), result)

vsFilter2 := model.ElectricalConnectionPermittedValueSetDataType{
ElectricalConnectionId: util.Ptr(model.ElectricalConnectionIdType(101)),
ParameterId: pdId,
}
result, err = s.sut.GetPermittedValueSetForFilter(vsFilter2)
assert.Nil(s.T(), err)
assert.Nil(s.T(), result)

dataFilter := []api.ElectricalConnectionPermittedValueSetForFilter{}
deleteSelectors := &model.ElectricalConnectionPermittedValueSetListDataSelectorsType{
ElectricalConnectionId: util.Ptr(model.ElectricalConnectionIdType(0)),
ParameterId: pdId,
}
deleteElements := &model.ElectricalConnectionPermittedValueSetDataElementsType{
PermittedValueSet: &model.ElementTagType{},
}
err = s.sut.UpdatePermittedValueSetForFilters(dataFilter, deleteSelectors, deleteElements)
assert.Nil(s.T(), err)

result, err = s.sut.GetPermittedValueSetForFilter(vsFilter)
assert.Nil(s.T(), err)
assert.NotNil(s.T(), result)
assert.Nil(s.T(), result[0].PermittedValueSet)
}
Loading

0 comments on commit 46a1a1f

Please sign in to comment.