Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions features/client/deviceconfiguration.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,14 @@ func (d *DeviceConfiguration) WriteKeyValues(data []model.DeviceConfigurationKey

filters := []model.FilterType{*model.NewFilterTypePartial()}

// does the remote server feature not support partials?
// the remote server feature must advertise write support
operation := d.featureRemote.Operations()[model.FunctionTypeDeviceConfigurationKeyValueListData]
if operation == nil || !operation.WritePartial() {
if operation == nil || !operation.Write() {
return nil, api.ErrNotSupported
}

// does the remote server feature not support partials?
if !operation.WritePartial() {
filters = nil
// we need to send all data
updateData := &model.DeviceConfigurationKeyValueListDataType{
Expand Down
17 changes: 17 additions & 0 deletions features/client/deviceconfiguration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package client
import (
"testing"

"github.com/enbility/eebus-go/api"
shipmocks "github.com/enbility/ship-go/mocks"
spineapi "github.com/enbility/spine-go/api"
"github.com/enbility/spine-go/mocks"
Expand Down Expand Up @@ -167,6 +168,22 @@ func (s *DeviceConfigurationSuite) Test_WriteValues() {
counter, err = s.deviceConfiguration.WriteKeyValues(data)
assert.Nil(s.T(), err)
assert.NotNil(s.T(), counter)

// remote does not advertise write support -> ErrNotSupported
mockWriter := shipmocks.NewShipConnectionDataWriterInterface(s.T())
mockWriter.EXPECT().WriteShipMessageWithPayload(mock.Anything).Return().Maybe()
localRO, remoteRO := setupFeatures(s.T(), mockWriter, []featureFunctions{
{
featureType: model.FeatureTypeTypeDeviceConfiguration,
functions: []model.FunctionType{model.FunctionTypeDeviceConfigurationKeyValueListData},
readOnly: true,
},
})
roDeviceConfiguration, err := NewDeviceConfiguration(localRO, remoteRO)
assert.Nil(s.T(), err)
counter, err = roDeviceConfiguration.WriteKeyValues(data)
assert.ErrorIs(s.T(), err, api.ErrNotSupported)
assert.Nil(s.T(), counter)
}

// test with partial support
Expand Down
5 changes: 5 additions & 0 deletions features/client/helper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ type featureFunctions struct {
featureType model.FeatureTypeType
functions []model.FunctionType
partial bool
readOnly bool
}

type WriteMessageHandler struct {
Expand Down Expand Up @@ -162,6 +163,10 @@ func setupFeatures(
}
}

if item.readOnly {
write = nil
}

supportedFct := model.FunctionPropertyType{
Function: util.Ptr(function),
PossibleOperations: &model.PossibleOperationsType{
Expand Down
9 changes: 7 additions & 2 deletions features/client/loadcontrol.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,14 @@ func (l *LoadControl) WriteLimitData(
}
filters = append(filters, *partialFilter)

// does the remote server feature not support partials?
// the remote server feature must advertise write support
operation := l.featureRemote.Operations()[model.FunctionTypeLoadControlLimitListData]
if operation == nil || !operation.WritePartial() {
if operation == nil || !operation.Write() {
return nil, api.ErrNotSupported
}

// does the remote server feature not support partials?
if !operation.WritePartial() {
filters = nil
// we need to send all data
updateData := &model.LoadControlLimitListDataType{
Expand Down
15 changes: 15 additions & 0 deletions features/client/loadcontrol_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"testing"
"time"

"github.com/enbility/eebus-go/api"
shipapi "github.com/enbility/ship-go/api"
spineapi "github.com/enbility/spine-go/api"
"github.com/enbility/spine-go/model"
Expand Down Expand Up @@ -173,6 +174,20 @@ func (s *LoadControlSuite) Test_WriteLimitValues() {
counter, err = s.loadControl.WriteLimitData(data, nil, nil)
assert.Nil(s.T(), err)
assert.NotNil(s.T(), counter)

// remote does not advertise write support -> ErrNotSupported
localRO, remoteRO := setupFeatures(s.T(), s, []featureFunctions{
{
featureType: model.FeatureTypeTypeLoadControl,
functions: []model.FunctionType{model.FunctionTypeLoadControlLimitListData},
readOnly: true,
},
})
roLoadControl, err := NewLoadControl(localRO, remoteRO)
assert.Nil(s.T(), err)
counter, err = roLoadControl.WriteLimitData(data, nil, nil)
assert.ErrorIs(s.T(), err, api.ErrNotSupported)
assert.Nil(s.T(), counter)
}

// test with partial support
Expand Down
6 changes: 6 additions & 0 deletions features/client/smartenergymanagementps.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ func (l *SmartEnergyManagementPs) WriteData(data *model.SmartEnergyManagementPsD
return nil, api.ErrMissingData
}

// the remote server feature must advertise write support
operation := l.featureRemote.Operations()[model.FunctionTypeSmartEnergyManagementPsData]
if operation == nil || !operation.Write() {
return nil, api.ErrNotSupported
}

cmd := model.CmdType{
Function: util.Ptr(model.FunctionTypeSmartEnergyManagementPsData),
Filter: []model.FilterType{*model.NewFilterTypePartial()},
Expand Down
15 changes: 15 additions & 0 deletions features/client/smartenergymanagementps_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"testing"
"time"

"github.com/enbility/eebus-go/api"
shipapi "github.com/enbility/ship-go/api"
spineapi "github.com/enbility/spine-go/api"
"github.com/enbility/spine-go/model"
Expand Down Expand Up @@ -109,4 +110,18 @@ func (s *SmartEnergyManagementPsSuite) Test_WriteData() {
counter, err = s.smartenergymgmtps.WriteData(data)
assert.Nil(s.T(), err)
assert.NotNil(s.T(), counter)

// remote does not advertise write support -> ErrNotSupported
localRO, remoteRO := setupFeatures(s.T(), s, []featureFunctions{
{
featureType: model.FeatureTypeTypeSmartEnergyManagementPs,
functions: []model.FunctionType{model.FunctionTypeSmartEnergyManagementPsData},
readOnly: true,
},
})
roSmartEnergyManagementPs, err := NewSmartEnergyManagementPs(localRO, remoteRO)
assert.Nil(s.T(), err)
counter, err = roSmartEnergyManagementPs.WriteData(data)
assert.ErrorIs(s.T(), err, api.ErrNotSupported)
assert.Nil(s.T(), counter)
}
6 changes: 6 additions & 0 deletions features/client/timeseries.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@ func (t *TimeSeries) WriteData(data []model.TimeSeriesDataType) (*model.MsgCount
return nil, api.ErrMissingData
}

// the remote server feature must advertise write support
operation := t.featureRemote.Operations()[model.FunctionTypeTimeSeriesListData]
if operation == nil || !operation.Write() {
return nil, api.ErrNotSupported
}

cmd := model.CmdType{
TimeSeriesListData: &model.TimeSeriesListDataType{
TimeSeriesData: data,
Expand Down
15 changes: 15 additions & 0 deletions features/client/timeseries_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package client
import (
"testing"

"github.com/enbility/eebus-go/api"
shipapi "github.com/enbility/ship-go/api"
spineapi "github.com/enbility/spine-go/api"
"github.com/enbility/spine-go/model"
Expand Down Expand Up @@ -114,4 +115,18 @@ func (s *TimeSeriesSuite) Test_WriteData() {
counter, err = s.timeSeries.WriteData(data)
assert.Nil(s.T(), err)
assert.NotNil(s.T(), counter)

// remote does not advertise write support -> ErrNotSupported
localRO, remoteRO := setupFeatures(s.T(), s, []featureFunctions{
{
featureType: model.FeatureTypeTypeTimeSeries,
functions: []model.FunctionType{model.FunctionTypeTimeSeriesListData},
readOnly: true,
},
})
roTimeSeries, err := NewTimeSeries(localRO, remoteRO)
assert.Nil(s.T(), err)
counter, err = roTimeSeries.WriteData(data)
assert.ErrorIs(s.T(), err, api.ErrNotSupported)
assert.Nil(s.T(), counter)
}
3 changes: 2 additions & 1 deletion usecases/cem/cevc/testhelper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,8 @@ func setupDevices(
supportedFct := model.FunctionPropertyType{
Function: util.Ptr(fct),
PossibleOperations: &model.PossibleOperationsType{
Read: &model.PossibleOperationsReadType{},
Read: &model.PossibleOperationsReadType{},
Write: &model.PossibleOperationsWriteType{},
},
}
supportedFcts = append(supportedFcts, supportedFct)
Expand Down
3 changes: 2 additions & 1 deletion usecases/cem/ohpcf/testhelper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,8 @@ func setupDevices(
supportedFct := model.FunctionPropertyType{
Function: util.Ptr(fct),
PossibleOperations: &model.PossibleOperationsType{
Read: &model.PossibleOperationsReadType{},
Read: &model.PossibleOperationsReadType{},
Write: &model.PossibleOperationsWriteType{},
},
}
supportedFcts = append(supportedFcts, supportedFct)
Expand Down
3 changes: 2 additions & 1 deletion usecases/eg/lpc/testhelper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,8 @@ func setupDevices(
supportedFct := model.FunctionPropertyType{
Function: util.Ptr(fct),
PossibleOperations: &model.PossibleOperationsType{
Read: &model.PossibleOperationsReadType{},
Read: &model.PossibleOperationsReadType{},
Write: &model.PossibleOperationsWriteType{},
},
}
supportedFcts = append(supportedFcts, supportedFct)
Expand Down
3 changes: 2 additions & 1 deletion usecases/eg/lpp/testhelper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,8 @@ func setupDevices(
supportedFct := model.FunctionPropertyType{
Function: util.Ptr(fct),
PossibleOperations: &model.PossibleOperationsType{
Read: &model.PossibleOperationsReadType{},
Read: &model.PossibleOperationsReadType{},
Write: &model.PossibleOperationsWriteType{},
},
}
supportedFcts = append(supportedFcts, supportedFct)
Expand Down
3 changes: 2 additions & 1 deletion usecases/internal/testhelper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,8 @@ func setupDevices(
supportedFct := model.FunctionPropertyType{
Function: util.Ptr(fct),
PossibleOperations: &model.PossibleOperationsType{
Read: &model.PossibleOperationsReadType{},
Read: &model.PossibleOperationsReadType{},
Write: &model.PossibleOperationsWriteType{},
},
}
supportedFcts = append(supportedFcts, supportedFct)
Expand Down
Loading