Skip to content

Commit

Permalink
Merge branch 'release/v0.6.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
DerAndereAndi committed Jul 16, 2024
2 parents e1b596b + bbf4b98 commit 68c6bcc
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 14 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.21.1

require (
github.com/ahmetb/go-linq/v3 v3.2.0
github.com/enbility/ship-go v0.5.1
github.com/enbility/ship-go v0.5.2
github.com/golanguzb70/lrucache v1.2.0
github.com/google/go-cmp v0.6.0
github.com/rickb777/date v1.20.6
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ github.com/ahmetb/go-linq/v3 v3.2.0 h1:BEuMfp+b59io8g5wYzNoFe9pWPalRklhlhbiU3hYZ
github.com/ahmetb/go-linq/v3 v3.2.0/go.mod h1:haQ3JfOeWK8HpVxMtHHEMPVgBKiYyQ+f1/kLZh/cj9U=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/enbility/ship-go v0.5.1 h1:8Vax1MpyI/C+kQlMFAzQ7/h/xJ7fuumSLJy9FYgEkcE=
github.com/enbility/ship-go v0.5.1/go.mod h1:jewJWYQ10jNhsnhS1C4jESx3CNmDa5HNWZjBhkTug5Y=
github.com/enbility/ship-go v0.5.2 h1:T9+YuP5ZpofKd463PLKq78fAaPAcGMnRAcv8c8aD5yU=
github.com/enbility/ship-go v0.5.2/go.mod h1:jewJWYQ10jNhsnhS1C4jESx3CNmDa5HNWZjBhkTug5Y=
github.com/golanguzb70/lrucache v1.2.0 h1:VjpjmB4VTf9VXBtZTJGcgcN0CNFM5egDrrSjkGyQOlg=
github.com/golanguzb70/lrucache v1.2.0/go.mod h1:zc2GD26KwGEDdTHsCCTcJorv/11HyKwQVS9gqg2bizc=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
Expand Down
4 changes: 2 additions & 2 deletions spine/feature_local_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ func (s *LocalFeatureTestSuite) BeforeTest(suiteName, testName string) {
_, s.localServerFeatureWrite = createLocalFeatures(s.localEntity, s.subFeatureType, s.serverWriteFunction)

remoteDevice := createRemoteDevice(s.localDevice, s.senderMock)
s.remoteFeature, s.remoteServerFeature = createRemoteEntityAndFeature(remoteDevice, 1, s.featureType)
s.remoteSubFeature, _ = createRemoteEntityAndFeature(remoteDevice, 2, s.subFeatureType)
s.remoteFeature, s.remoteServerFeature = createRemoteEntityAndFeature(remoteDevice, 1, s.featureType, s.function)
s.remoteSubFeature, _ = createRemoteEntityAndFeature(remoteDevice, 2, s.subFeatureType, s.serverWriteFunction)
}

func (s *LocalFeatureTestSuite) TestDeviceClassification_Functions() {
Expand Down
12 changes: 6 additions & 6 deletions spine/function_data_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,23 +62,23 @@ func (r *FunctionDataCmd[T]) NotifyOrWriteCmdType(deleteSelector, partialSelecto
}

func filtersForSelectorsElements(functionType model.FunctionType, filters []model.FilterType, deleteSelector, partialSelector any, deleteElements, readElements any) []model.FilterType {
if deleteSelector != nil || deleteElements != nil {
if !util.IsNil(deleteSelector) || !util.IsNil(deleteElements) {
filter := model.FilterType{CmdControl: &model.CmdControlType{Delete: &model.ElementTagType{}}}
if deleteSelector != nil {
if !util.IsNil(deleteSelector) {
filter = addSelectorToFilter(filter, functionType, &deleteSelector)
}
if deleteElements != nil {
if !util.IsNil(deleteElements) {
filter = addElementToFilter(filter, functionType, &deleteElements)
}
filters = append(filters, filter)
}

if partialSelector != nil || readElements != nil {
if !util.IsNil(partialSelector) || !util.IsNil(readElements) {
filter := model.FilterType{CmdControl: &model.CmdControlType{Partial: &model.ElementTagType{}}}
if partialSelector != nil {
if !util.IsNil(partialSelector) {
filter = addSelectorToFilter(filter, functionType, partialSelector)
}
if readElements != nil {
if !util.IsNil(readElements != nil) {
filter = addElementToFilter(filter, functionType, readElements)
}
filters = append(filters, filter)
Expand Down
12 changes: 11 additions & 1 deletion spine/helper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,12 +197,22 @@ func createRemoteDevice(localDevice *DeviceLocal, sender api.SenderInterface) *D
return remoteDevice
}

func createRemoteEntityAndFeature(remoteDevice *DeviceRemote, entityId uint, featureType model.FeatureTypeType) (api.FeatureRemoteInterface, api.FeatureRemoteInterface) {
func createRemoteEntityAndFeature(remoteDevice *DeviceRemote, entityId uint, featureType model.FeatureTypeType, functionType model.FunctionType) (api.FeatureRemoteInterface, api.FeatureRemoteInterface) {
remoteEntity := NewEntityRemote(remoteDevice, model.EntityTypeTypeEVSE, []model.AddressEntityType{model.AddressEntityType(entityId)})
remoteDevice.AddEntity(remoteEntity)
remoteFeature := NewFeatureRemote(remoteEntity.NextFeatureId(), remoteEntity, featureType, model.RoleTypeClient)
remoteEntity.AddFeature(remoteFeature)
remoteServerFeature := NewFeatureRemote(remoteEntity.NextFeatureId(), remoteEntity, featureType, model.RoleTypeServer)
remoteServerFeature.SetOperations([]model.FunctionPropertyType{
{
Function: util.Ptr(functionType),
PossibleOperations: &model.PossibleOperationsType{
Read: &model.PossibleOperationsReadType{
Partial: &model.ElementTagType{},
},
},
},
})
remoteEntity.AddFeature(remoteServerFeature)

return remoteFeature, remoteServerFeature
Expand Down
4 changes: 2 additions & 2 deletions spine/nodemanagement_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func TestNodemanagement_BindingCalls(t *testing.T) {
_, serverFeature := createLocalFeatures(localEntity, featureType, "")

remoteDevice := createRemoteDevice(localDevice, senderMock)
clientFeature, _ := createRemoteEntityAndFeature(remoteDevice, bindingEntityId, featureType)
clientFeature, _ := createRemoteEntityAndFeature(remoteDevice, bindingEntityId, featureType, "")

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

remoteDevice := createRemoteDevice(localDevice, senderMock)
clientFeature, _ := createRemoteEntityAndFeature(remoteDevice, subscriptionEntityId, featureType)
clientFeature, _ := createRemoteEntityAndFeature(remoteDevice, subscriptionEntityId, featureType, "")

senderMock.On("Reply", mock.Anything, mock.Anything, mock.Anything).Run(func(args mock.Arguments) {
cmd := args.Get(2).(model.CmdType)
Expand Down
17 changes: 17 additions & 0 deletions util/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,27 @@ package util

import (
"encoding/json"
"reflect"
)

// quick way to a struct into another
func DeepCopy[A any](source, dest A) {
byt, _ := json.Marshal(source)
_ = json.Unmarshal(byt, dest)
}

// checck if a value is nil for any type
func IsNil(data any) bool {
if data == nil {
return true
}
switch reflect.TypeOf(data).Kind() {
case reflect.Ptr,
reflect.Map,
reflect.Array,
reflect.Chan,
reflect.Slice:
return reflect.ValueOf(data).IsNil()
}
return false
}

0 comments on commit 68c6bcc

Please sign in to comment.