Skip to content

Commit 68c6bcc

Browse files
committed
Merge branch 'release/v0.6.1'
2 parents e1b596b + bbf4b98 commit 68c6bcc

File tree

7 files changed

+41
-14
lines changed

7 files changed

+41
-14
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ go 1.21.1
44

55
require (
66
github.com/ahmetb/go-linq/v3 v3.2.0
7-
github.com/enbility/ship-go v0.5.1
7+
github.com/enbility/ship-go v0.5.2
88
github.com/golanguzb70/lrucache v1.2.0
99
github.com/google/go-cmp v0.6.0
1010
github.com/rickb777/date v1.20.6

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ github.com/ahmetb/go-linq/v3 v3.2.0 h1:BEuMfp+b59io8g5wYzNoFe9pWPalRklhlhbiU3hYZ
22
github.com/ahmetb/go-linq/v3 v3.2.0/go.mod h1:haQ3JfOeWK8HpVxMtHHEMPVgBKiYyQ+f1/kLZh/cj9U=
33
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
44
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
5-
github.com/enbility/ship-go v0.5.1 h1:8Vax1MpyI/C+kQlMFAzQ7/h/xJ7fuumSLJy9FYgEkcE=
6-
github.com/enbility/ship-go v0.5.1/go.mod h1:jewJWYQ10jNhsnhS1C4jESx3CNmDa5HNWZjBhkTug5Y=
5+
github.com/enbility/ship-go v0.5.2 h1:T9+YuP5ZpofKd463PLKq78fAaPAcGMnRAcv8c8aD5yU=
6+
github.com/enbility/ship-go v0.5.2/go.mod h1:jewJWYQ10jNhsnhS1C4jESx3CNmDa5HNWZjBhkTug5Y=
77
github.com/golanguzb70/lrucache v1.2.0 h1:VjpjmB4VTf9VXBtZTJGcgcN0CNFM5egDrrSjkGyQOlg=
88
github.com/golanguzb70/lrucache v1.2.0/go.mod h1:zc2GD26KwGEDdTHsCCTcJorv/11HyKwQVS9gqg2bizc=
99
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=

spine/feature_local_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ func (s *LocalFeatureTestSuite) BeforeTest(suiteName, testName string) {
4444
_, s.localServerFeatureWrite = createLocalFeatures(s.localEntity, s.subFeatureType, s.serverWriteFunction)
4545

4646
remoteDevice := createRemoteDevice(s.localDevice, s.senderMock)
47-
s.remoteFeature, s.remoteServerFeature = createRemoteEntityAndFeature(remoteDevice, 1, s.featureType)
48-
s.remoteSubFeature, _ = createRemoteEntityAndFeature(remoteDevice, 2, s.subFeatureType)
47+
s.remoteFeature, s.remoteServerFeature = createRemoteEntityAndFeature(remoteDevice, 1, s.featureType, s.function)
48+
s.remoteSubFeature, _ = createRemoteEntityAndFeature(remoteDevice, 2, s.subFeatureType, s.serverWriteFunction)
4949
}
5050

5151
func (s *LocalFeatureTestSuite) TestDeviceClassification_Functions() {

spine/function_data_cmd.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,23 +62,23 @@ func (r *FunctionDataCmd[T]) NotifyOrWriteCmdType(deleteSelector, partialSelecto
6262
}
6363

6464
func filtersForSelectorsElements(functionType model.FunctionType, filters []model.FilterType, deleteSelector, partialSelector any, deleteElements, readElements any) []model.FilterType {
65-
if deleteSelector != nil || deleteElements != nil {
65+
if !util.IsNil(deleteSelector) || !util.IsNil(deleteElements) {
6666
filter := model.FilterType{CmdControl: &model.CmdControlType{Delete: &model.ElementTagType{}}}
67-
if deleteSelector != nil {
67+
if !util.IsNil(deleteSelector) {
6868
filter = addSelectorToFilter(filter, functionType, &deleteSelector)
6969
}
70-
if deleteElements != nil {
70+
if !util.IsNil(deleteElements) {
7171
filter = addElementToFilter(filter, functionType, &deleteElements)
7272
}
7373
filters = append(filters, filter)
7474
}
7575

76-
if partialSelector != nil || readElements != nil {
76+
if !util.IsNil(partialSelector) || !util.IsNil(readElements) {
7777
filter := model.FilterType{CmdControl: &model.CmdControlType{Partial: &model.ElementTagType{}}}
78-
if partialSelector != nil {
78+
if !util.IsNil(partialSelector) {
7979
filter = addSelectorToFilter(filter, functionType, partialSelector)
8080
}
81-
if readElements != nil {
81+
if !util.IsNil(readElements != nil) {
8282
filter = addElementToFilter(filter, functionType, readElements)
8383
}
8484
filters = append(filters, filter)

spine/helper_test.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,12 +197,22 @@ func createRemoteDevice(localDevice *DeviceLocal, sender api.SenderInterface) *D
197197
return remoteDevice
198198
}
199199

200-
func createRemoteEntityAndFeature(remoteDevice *DeviceRemote, entityId uint, featureType model.FeatureTypeType) (api.FeatureRemoteInterface, api.FeatureRemoteInterface) {
200+
func createRemoteEntityAndFeature(remoteDevice *DeviceRemote, entityId uint, featureType model.FeatureTypeType, functionType model.FunctionType) (api.FeatureRemoteInterface, api.FeatureRemoteInterface) {
201201
remoteEntity := NewEntityRemote(remoteDevice, model.EntityTypeTypeEVSE, []model.AddressEntityType{model.AddressEntityType(entityId)})
202202
remoteDevice.AddEntity(remoteEntity)
203203
remoteFeature := NewFeatureRemote(remoteEntity.NextFeatureId(), remoteEntity, featureType, model.RoleTypeClient)
204204
remoteEntity.AddFeature(remoteFeature)
205205
remoteServerFeature := NewFeatureRemote(remoteEntity.NextFeatureId(), remoteEntity, featureType, model.RoleTypeServer)
206+
remoteServerFeature.SetOperations([]model.FunctionPropertyType{
207+
{
208+
Function: util.Ptr(functionType),
209+
PossibleOperations: &model.PossibleOperationsType{
210+
Read: &model.PossibleOperationsReadType{
211+
Partial: &model.ElementTagType{},
212+
},
213+
},
214+
},
215+
})
206216
remoteEntity.AddFeature(remoteServerFeature)
207217

208218
return remoteFeature, remoteServerFeature

spine/nodemanagement_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ func TestNodemanagement_BindingCalls(t *testing.T) {
2121
_, serverFeature := createLocalFeatures(localEntity, featureType, "")
2222

2323
remoteDevice := createRemoteDevice(localDevice, senderMock)
24-
clientFeature, _ := createRemoteEntityAndFeature(remoteDevice, bindingEntityId, featureType)
24+
clientFeature, _ := createRemoteEntityAndFeature(remoteDevice, bindingEntityId, featureType, "")
2525

2626
senderMock.On("Reply", mock.Anything, mock.Anything, mock.Anything).Run(func(args mock.Arguments) {
2727
cmd := args.Get(2).(model.CmdType)
@@ -94,7 +94,7 @@ func TestNodemanagement_SubscriptionCalls(t *testing.T) {
9494
_, serverFeature := createLocalFeatures(localEntity, featureType, "")
9595

9696
remoteDevice := createRemoteDevice(localDevice, senderMock)
97-
clientFeature, _ := createRemoteEntityAndFeature(remoteDevice, subscriptionEntityId, featureType)
97+
clientFeature, _ := createRemoteEntityAndFeature(remoteDevice, subscriptionEntityId, featureType, "")
9898

9999
senderMock.On("Reply", mock.Anything, mock.Anything, mock.Anything).Run(func(args mock.Arguments) {
100100
cmd := args.Get(2).(model.CmdType)

util/helper.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,27 @@ package util
22

33
import (
44
"encoding/json"
5+
"reflect"
56
)
67

78
// quick way to a struct into another
89
func DeepCopy[A any](source, dest A) {
910
byt, _ := json.Marshal(source)
1011
_ = json.Unmarshal(byt, dest)
1112
}
13+
14+
// checck if a value is nil for any type
15+
func IsNil(data any) bool {
16+
if data == nil {
17+
return true
18+
}
19+
switch reflect.TypeOf(data).Kind() {
20+
case reflect.Ptr,
21+
reflect.Map,
22+
reflect.Array,
23+
reflect.Chan,
24+
reflect.Slice:
25+
return reflect.ValueOf(data).IsNil()
26+
}
27+
return false
28+
}

0 commit comments

Comments
 (0)