Skip to content

Commit

Permalink
Add method to get all functions of a feature
Browse files Browse the repository at this point in the history
  • Loading branch information
DerAndereAndi committed Feb 24, 2024
1 parent 7c2bdbe commit 10705c6
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
3 changes: 3 additions & 0 deletions api/feature.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ type FeatureLocalInterface interface {
// Add a callback function to be invoked when SPINE message comes in with a given msgCounterReference value
AddResultCallback(msgCounterReference model.MsgCounterType, function func(msg ResultMessage))

// return all functions
Functions() []model.FunctionType

// Get a copy of the features data for a given function type
DataCopy(function model.FunctionType) any
// Set the features data for a given function type
Expand Down
10 changes: 10 additions & 0 deletions spine/feature_local.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,16 @@ func (r *FeatureLocal) AddResultCallback(msgCounterReference model.MsgCounterTyp
r.resultCallback[msgCounterReference] = function
}

func (r *FeatureLocal) Functions() []model.FunctionType {
var fcts []model.FunctionType

for key := range r.operations {
fcts = append(fcts, key)
}

return fcts
}

func (r *FeatureLocal) processResultCallbacks(msgCounterReference model.MsgCounterType, msg api.ResultMessage) {
r.muxResultCB.Lock()
defer r.muxResultCB.Unlock()
Expand Down
9 changes: 8 additions & 1 deletion spine/feature_local_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,13 @@ func (suite *DeviceClassificationTestSuite) BeforeTest(suiteName, testName strin
suite.remoteSubFeature, _ = createRemoteEntityAndFeature(suite.localDevice, remoteDevice, 2, suite.subFeatureType)
}

func (suite *DeviceClassificationTestSuite) TestDeviceClassification_Functions() {
fcts := suite.localServerFeatureWrite.Functions()
assert.NotNil(suite.T(), fcts)
assert.Equal(suite.T(), 1, len(fcts))
assert.Equal(suite.T(), suite.serverWriteFunction, fcts[0])
}

func (suite *DeviceClassificationTestSuite) TestDeviceClassification_Request_Reply() {
dummyAddress := &model.FeatureAddressType{
Device: util.Ptr(model.AddressDeviceType("")),
Expand Down Expand Up @@ -161,7 +168,7 @@ func (suite *DeviceClassificationTestSuite) TestDeviceClassification_Request_Err
assert.Equal(suite.T(), errorDescription, string(*err.Description))
}

func (suite *DeviceClassificationTestSuite) TestDeviceClassification_Subscribiptions() {
func (suite *DeviceClassificationTestSuite) TestDeviceClassification_Subscriptions() {
suite.senderMock.On("Subscribe", mock.Anything, mock.Anything, mock.Anything).Return(&suite.msgCounter, nil)
suite.senderMock.On("Unsubscribe", mock.Anything, mock.Anything, mock.Anything).Return(&suite.msgCounter, nil)

Expand Down

0 comments on commit 10705c6

Please sign in to comment.