Skip to content

Commit

Permalink
Update notify cmd to have empty function on pure delete
Browse files Browse the repository at this point in the history
  • Loading branch information
DerAndereAndi committed Jan 24, 2024
1 parent 7df066d commit 66bcc82
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
10 changes: 9 additions & 1 deletion spine/function_data_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,15 @@ func (r *FunctionDataCmd[T]) ReplyCmdType(partial bool) model.CmdType {
func (r *FunctionDataCmd[T]) NotifyCmdType(deleteSelector, partialSelector any, partialWithoutSelector bool, deleteElements any) model.CmdType {
data := r.DataCopy()
cmd := createCmd(r.functionType, data)
cmd.Function = util.Ptr(model.FunctionType(r.functionType))

// SPINE 1.3.0 5.3.4.4: on pure delete function should be presnt but empty
if (deleteSelector != nil || deleteElements != nil) &&
partialSelector == nil &&
!partialWithoutSelector {
cmd.Function = util.Ptr(model.FunctionType(""))
} else {
cmd.Function = util.Ptr(model.FunctionType(r.functionType))
}

if partialWithoutSelector {
cmd.Filter = filterEmptyPartial()
Expand Down
6 changes: 6 additions & 0 deletions spine/function_data_cmd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,21 @@ func (suite *FctDataCmdSuite) TestFunctionDataCmd_NotifyCmd() {
readCmd := suite.sut.NotifyCmdType(nil, nil, false, nil)
assert.NotNil(suite.T(), readCmd.DeviceClassificationManufacturerData)
assert.Equal(suite.T(), suite.data.DeviceName, readCmd.DeviceClassificationManufacturerData.DeviceName)
assert.NotNil(suite.T(), readCmd.Function)
assert.NotEqual(suite.T(), 0, len(string(*readCmd.Function)))

readCmd = suite.sut.NotifyCmdType(nil, nil, true, nil)
assert.NotNil(suite.T(), readCmd.DeviceClassificationManufacturerData)
assert.Equal(suite.T(), suite.data.DeviceName, readCmd.DeviceClassificationManufacturerData.DeviceName)
assert.NotNil(suite.T(), readCmd.Function)
assert.NotEqual(suite.T(), 0, len(string(*readCmd.Function)))

deleteS := model.NewFilterTypePartial()
readCmd = suite.sut.NotifyCmdType(deleteS, nil, false, nil)
assert.NotNil(suite.T(), readCmd.DeviceClassificationManufacturerData)
assert.Equal(suite.T(), suite.data.DeviceName, readCmd.DeviceClassificationManufacturerData.DeviceName)
assert.NotNil(suite.T(), readCmd.Function)
assert.Equal(suite.T(), 0, len(string(*readCmd.Function)))
}

func (suite *FctDataCmdSuite) TestFunctionDataCmd_WriteCmd() {
Expand Down

0 comments on commit 66bcc82

Please sign in to comment.