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

Commit 2705031

Browse files
committed
UCLPCServer fixes
- Properly update DeviceConfiguration values and don’t overwrite everything with one value - Remove initial LoadControl limit setting, this should be done by the application using the public methods
1 parent c92c5da commit 2705031

File tree

3 files changed

+20
-21
lines changed

3 files changed

+20
-21
lines changed

uclpcserver/public_test.go

+6-3
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ func (s *UCLPCServerSuite) Test_LoadControlLimit() {
2626
assert.Nil(s.T(), err)
2727
}
2828

29-
func (s *UCLPCServerSuite) Test_FailsafeConsumptionActivePowerLimit() {
29+
func (s *UCLPCServerSuite) Test_Failsafe() {
3030
limit, changeable, err := s.sut.FailsafeConsumptionActivePowerLimit()
3131
assert.Equal(s.T(), 0.0, limit)
3232
assert.Equal(s.T(), false, changeable)
@@ -39,9 +39,7 @@ func (s *UCLPCServerSuite) Test_FailsafeConsumptionActivePowerLimit() {
3939
assert.Equal(s.T(), 10.0, limit)
4040
assert.Equal(s.T(), true, changeable)
4141
assert.Nil(s.T(), err)
42-
}
4342

44-
func (s *UCLPCServerSuite) Test_FailsafeDurationMinimum() {
4543
// The actual tests of the functionality is located in the util package
4644
duration, changeable, err := s.sut.FailsafeDurationMinimum()
4745
assert.Equal(s.T(), time.Duration(0), duration)
@@ -54,6 +52,11 @@ func (s *UCLPCServerSuite) Test_FailsafeDurationMinimum() {
5452
err = s.sut.SetFailsafeDurationMinimum(time.Duration(time.Hour*2), true)
5553
assert.Nil(s.T(), err)
5654

55+
limit, changeable, err = s.sut.FailsafeConsumptionActivePowerLimit()
56+
assert.Equal(s.T(), 10.0, limit)
57+
assert.Equal(s.T(), true, changeable)
58+
assert.Nil(s.T(), err)
59+
5760
duration, changeable, err = s.sut.FailsafeDurationMinimum()
5861
assert.Equal(s.T(), time.Duration(time.Hour*2), duration)
5962
assert.Equal(s.T(), true, changeable)

uclpcserver/uclpc.go

-11
Original file line numberDiff line numberDiff line change
@@ -78,17 +78,6 @@ func (e *UCLPCServer) AddFeatures() {
7878
}
7979
f.SetData(model.FunctionTypeLoadControlLimitDescriptionListData, loadControlDesc)
8080

81-
loadControl := &model.LoadControlLimitListDataType{
82-
LoadControlLimitData: []model.LoadControlLimitDataType{
83-
{
84-
LimitId: eebusutil.Ptr(model.LoadControlLimitIdType(limitId)),
85-
IsLimitChangeable: eebusutil.Ptr(true),
86-
IsLimitActive: eebusutil.Ptr(false),
87-
},
88-
},
89-
}
90-
f.SetData(model.FunctionTypeLoadControlLimitListData, loadControl)
91-
9281
f = localEntity.GetOrAddFeature(model.FeatureTypeTypeDeviceConfiguration, model.RoleTypeServer)
9382
f.AddFunctionType(model.FunctionTypeDeviceConfigurationKeyValueDescriptionListData, true, false)
9483
f.AddFunctionType(model.FunctionTypeDeviceConfigurationKeyValueListData, true, true)

util/deviceconfiguration.go

+14-7
Original file line numberDiff line numberDiff line change
@@ -90,16 +90,23 @@ func SetLocalDeviceConfigurationKeyValue(
9090
return
9191
}
9292

93-
keyData := model.DeviceConfigurationKeyValueDataType{
94-
KeyId: eebusutil.Ptr(*description.KeyId),
95-
IsValueChangeable: eebusutil.Ptr(changeable),
96-
Value: eebusutil.Ptr(value),
93+
data, err := spine.LocalFeatureDataCopyOfType[*model.DeviceConfigurationKeyValueListDataType](deviceConfiguration, model.FunctionTypeDeviceConfigurationKeyValueListData)
94+
if err != nil {
95+
data = &model.DeviceConfigurationKeyValueListDataType{}
9796
}
98-
keysData := &model.DeviceConfigurationKeyValueListDataType{
99-
DeviceConfigurationKeyValueData: []model.DeviceConfigurationKeyValueDataType{keyData},
97+
98+
for index, item := range data.DeviceConfigurationKeyValueData {
99+
if item.KeyId == nil || *item.KeyId != *description.KeyId {
100+
continue
101+
}
102+
103+
item.IsValueChangeable = eebusutil.Ptr(changeable)
104+
item.Value = eebusutil.Ptr(value)
105+
106+
data.DeviceConfigurationKeyValueData[index] = item
100107
}
101108

102-
deviceConfiguration.SetData(model.FunctionTypeDeviceConfigurationKeyValueListData, keysData)
109+
deviceConfiguration.SetData(model.FunctionTypeDeviceConfigurationKeyValueListData, data)
103110

104111
return nil
105112
}

0 commit comments

Comments
 (0)