Skip to content
This repository was archived by the owner on Jun 29, 2024. It is now read-only.

Commit 6e5928b

Browse files
committed
Add item if keyId was not found
1 parent 2705031 commit 6e5928b

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

util/deviceconfiguration.go

+11
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ func SetLocalDeviceConfigurationKeyValue(
9595
data = &model.DeviceConfigurationKeyValueListDataType{}
9696
}
9797

98+
found := false
9899
for index, item := range data.DeviceConfigurationKeyValueData {
99100
if item.KeyId == nil || *item.KeyId != *description.KeyId {
100101
continue
@@ -104,6 +105,16 @@ func SetLocalDeviceConfigurationKeyValue(
104105
item.Value = eebusutil.Ptr(value)
105106

106107
data.DeviceConfigurationKeyValueData[index] = item
108+
found = true
109+
}
110+
111+
if !found {
112+
item := model.DeviceConfigurationKeyValueDataType{
113+
KeyId: eebusutil.Ptr(*description.KeyId),
114+
IsValueChangeable: eebusutil.Ptr(changeable),
115+
Value: eebusutil.Ptr(value),
116+
}
117+
data.DeviceConfigurationKeyValueData = append(data.DeviceConfigurationKeyValueData, item)
107118
}
108119

109120
deviceConfiguration.SetData(model.FunctionTypeDeviceConfigurationKeyValueListData, data)

util/deviceconfiguration_test.go

+3
Original file line numberDiff line numberDiff line change
@@ -97,4 +97,7 @@ func (s *UtilSuite) Test_SetLocalDeviceConfigurationKeyValue() {
9797
assert.NotNil(s.T(), data.Value)
9898
assert.NotNil(s.T(), data.Value.ScaledNumber)
9999
assert.Equal(s.T(), 10.0, data.Value.ScaledNumber.GetValue())
100+
101+
err = SetLocalDeviceConfigurationKeyValue(s.service, keyName, true, value)
102+
assert.Nil(s.T(), err)
100103
}

0 commit comments

Comments
 (0)