Skip to content

Commit

Permalink
Merge branch 'release/v0.6.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
DerAndereAndi committed Aug 12, 2024
2 parents 68c6bcc + 6c8360d commit 36970dd
Show file tree
Hide file tree
Showing 10 changed files with 146 additions and 14 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# spine-go

[![Build Status](https://github.com/enbility/spine-go/actions/workflows/default.yml/badge.svg?branch=main)](https://github.com/enbility/spine-go/actions/workflows/default.yml/badge.svg?branch=main)
[![Build Status](https://github.com/enbility/spine-go/actions/workflows/default.yml/badge.svg?branch=master)](https://github.com/enbility/spine-go/actions/workflows/default.yml/badge.svg?branch=master)
[![GoDoc](https://img.shields.io/badge/godoc-reference-5272B4)](https://godoc.org/github.com/enbility/spine-go)
[![Coverage Status](https://coveralls.io/repos/github/enbility/spine-go/badge.svg?branch=main)](https://coveralls.io/github/enbility/spine-go?branch=main)
[![Coverage Status](https://coveralls.io/repos/github/enbility/spine-go/badge.svg?branch=master)](https://coveralls.io/github/enbility/spine-go?branch=master)
[![Go report](https://goreportcard.com/badge/github.com/enbility/spine-go)](https://goreportcard.com/report/github.com/enbility/spine-go)
[![CodeFactor](https://www.codefactor.io/repository/github/enbility/spine-go/badge)](https://www.codefactor.io/repository/github/enbility/spine-go)

Expand Down
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.2
github.com/enbility/ship-go v0.5.3
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.2 h1:T9+YuP5ZpofKd463PLKq78fAaPAcGMnRAcv8c8aD5yU=
github.com/enbility/ship-go v0.5.2/go.mod h1:jewJWYQ10jNhsnhS1C4jESx3CNmDa5HNWZjBhkTug5Y=
github.com/enbility/ship-go v0.5.3 h1:P8eA/WDz3hq18zEKzqCB697OA1sVFiZkTF51Cx4tyGU=
github.com/enbility/ship-go v0.5.3/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
2 changes: 1 addition & 1 deletion spine/function_data_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func filtersForSelectorsElements(functionType model.FunctionType, filters []mode
if !util.IsNil(partialSelector) {
filter = addSelectorToFilter(filter, functionType, partialSelector)
}
if !util.IsNil(readElements != nil) {
if !util.IsNil(readElements) {
filter = addElementToFilter(filter, functionType, readElements)
}
filters = append(filters, filter)
Expand Down
8 changes: 8 additions & 0 deletions spine/heartbeat_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,14 @@ func (c *HeartbeatManager) heartbeatData(t time.Time, counter *uint64) *model.De
}

func (c *HeartbeatManager) updateHeartbeatData(stopC chan struct{}, d time.Duration) {
// Substract two seconds, because some devices (like Elli Connect/Pro) with OPEV/OSCEV interpret
// the heartbeat timeout (<= 4s) as the time within which a heartbeat should be received and otherwise
// will go into fallback mode.
// But other EVSE devices and in LPC (<= 60s), the heartbeat should be considered missing, if it is not
// received within twice the heartbeat timeout timeframe.
if d > 2*time.Second {
d -= 2 * time.Second
}
ticker := time.NewTicker(d)
for {
select {
Expand Down
5 changes: 3 additions & 2 deletions spine/helper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ import (
)

const (
wallbox_detaileddiscoverydata_recv_reply_file_path = "./testdata/wallbox_detaileddiscoverydata_recv_reply.json"
wallbox_detaileddiscoverydata_recv_notify_file_path = "./testdata/wallbox_detaileddiscoverydata_recv_notify.json"
wallbox_detaileddiscoverydata_recv_reply_file_path = "./testdata/wallbox_detaileddiscoverydata_recv_reply.json"
wallbox_detaileddiscoverydata_recv_notify_file_path = "./testdata/wallbox_detaileddiscoverydata_recv_notify.json"
wallbox_detaileddiscoverydata_recv_notify_remove_file_path = "./testdata/wallbox_detaileddiscoverydata_recv_notify_remove.json"
)

type WriteMessageHandler struct {
Expand Down
21 changes: 21 additions & 0 deletions spine/nodemanagement_detaileddiscovery_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,27 @@ func (s *NodeManagementSuite) TestDetailedDiscovery_RecvNotifyAdded() {
assert.Equal(s.T(), 10, len(ev.Features()))
}
}

// Act
msgCounter, _ = s.remoteDevice.HandleSpineMesssage(loadFileData(s.T(), wallbox_detaileddiscoverydata_recv_notify_remove_file_path))
waitForAck(s.T(), msgCounter, s.writeHandler)

// Assert
rEntities = remoteDevice.Entities()
if assert.Equal(s.T(), 2, len(rEntities)) {
{
di := rEntities[DeviceInformationEntityId]
assert.NotNil(s.T(), di)
assert.Equal(s.T(), model.EntityTypeTypeDeviceInformation, di.EntityType())
assert.Equal(s.T(), 2, len(di.Features()))
}
{
evse := rEntities[1]
assert.NotNil(s.T(), evse)
assert.Equal(s.T(), model.EntityTypeTypeEVSE, evse.EntityType())
assert.Equal(s.T(), 3, len(evse.Features()))
}
}
}

func (s *NodeManagementSuite) TestDetailedDiscovery_SendReplyWithAcknowledge() {
Expand Down
7 changes: 5 additions & 2 deletions spine/subscription_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,9 @@ func (c *SubscriptionManager) RemoveSubscription(data model.SubscriptionManageme
for _, item := range c.subscriptionEntries {
itemAddress := item.ClientFeature.Address()

if !reflect.DeepEqual(*itemAddress, clientAddress) &&
if !reflect.DeepEqual(itemAddress.Device, clientAddress.Device) ||
!reflect.DeepEqual(itemAddress.Entity, clientAddress.Entity) ||
!reflect.DeepEqual(itemAddress.Feature, clientAddress.Feature) ||
!reflect.DeepEqual(item.ServerFeature, serverFeature) {
newSubscriptionEntries = append(newSubscriptionEntries, item)
}
Expand Down Expand Up @@ -163,7 +165,8 @@ func (c *SubscriptionManager) RemoveSubscriptionsForEntity(remoteEntity api.Enti

var newSubscriptionEntries []*api.SubscriptionEntry
for _, item := range c.subscriptionEntries {
if !reflect.DeepEqual(item.ClientFeature.Address().Entity, remoteEntity.Address().Entity) {
if !reflect.DeepEqual(item.ClientFeature.Address().Device, remoteEntity.Address().Device) ||
!reflect.DeepEqual(item.ClientFeature.Address().Entity, remoteEntity.Address().Entity) {
newSubscriptionEntries = append(newSubscriptionEntries, item)
continue
}
Expand Down
46 changes: 42 additions & 4 deletions spine/subscription_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@ func TestSubscriptionManagerSuite(t *testing.T) {
type SubscriptionManagerSuite struct {
suite.Suite

localDevice api.DeviceLocalInterface
remoteDevice api.DeviceRemoteInterface
sut api.SubscriptionManagerInterface
localDevice api.DeviceLocalInterface
remoteDevice,
remoteDevice2 api.DeviceRemoteInterface
sut api.SubscriptionManagerInterface
}

func (suite *SubscriptionManagerSuite) WriteShipMessageWithPayload([]byte) {}
Expand All @@ -31,9 +32,12 @@ func (suite *SubscriptionManagerSuite) SetupSuite() {
ski := "test"
sender := NewSender(suite)
suite.remoteDevice = NewDeviceRemote(suite.localDevice, ski, sender)

_ = suite.localDevice.SetupRemoteDevice(ski, suite)

ski2 := "test2"
suite.remoteDevice2 = NewDeviceRemote(suite.localDevice, ski2, sender)
_ = suite.localDevice.SetupRemoteDevice(ski2, suite)

suite.sut = NewSubscriptionManager(suite.localDevice)
}

Expand All @@ -49,13 +53,28 @@ func (suite *SubscriptionManagerSuite) Test_Subscriptions() {
remoteFeature := NewFeatureRemote(remoteEntity.NextFeatureId(), remoteEntity, model.FeatureTypeTypeDeviceDiagnosis, model.RoleTypeClient)
remoteFeature.Address().Device = util.Ptr(model.AddressDeviceType("remoteDevice"))
remoteEntity.AddFeature(remoteFeature)
remoteEntity.Address().Device = util.Ptr(model.AddressDeviceType("remoteDevice"))

subscrRequest := model.SubscriptionManagementRequestCallType{
ClientAddress: remoteFeature.Address(),
ServerAddress: localFeature.Address(),
ServerFeatureType: util.Ptr(model.FeatureTypeTypeDeviceDiagnosis),
}

remoteEntity2 := NewEntityRemote(suite.remoteDevice2, model.EntityTypeTypeEVSE, []model.AddressEntityType{1})
suite.remoteDevice2.AddEntity(remoteEntity2)

remoteFeature2 := NewFeatureRemote(remoteEntity2.NextFeatureId(), remoteEntity2, model.FeatureTypeTypeDeviceDiagnosis, model.RoleTypeClient)
remoteFeature2.Address().Device = util.Ptr(model.AddressDeviceType("remoteDevice2"))
remoteEntity2.AddFeature(remoteFeature2)
remoteEntity2.Address().Device = util.Ptr(model.AddressDeviceType("remoteDevice2"))

subscrRequest2 := model.SubscriptionManagementRequestCallType{
ClientAddress: remoteFeature2.Address(),
ServerAddress: localFeature.Address(),
ServerFeatureType: util.Ptr(model.FeatureTypeTypeDeviceDiagnosis),
}

subMgr := suite.localDevice.SubscriptionManager()
err := subMgr.AddSubscription(suite.remoteDevice, subscrRequest)
assert.Nil(suite.T(), err)
Expand All @@ -69,6 +88,12 @@ func (suite *SubscriptionManagerSuite) Test_Subscriptions() {
subs = subMgr.Subscriptions(suite.remoteDevice)
assert.Equal(suite.T(), 1, len(subs))

err = subMgr.AddSubscription(suite.remoteDevice2, subscrRequest2)
assert.Nil(suite.T(), err)

subs = subMgr.Subscriptions(suite.remoteDevice2)
assert.Equal(suite.T(), 1, len(subs))

subscrDelete := model.SubscriptionManagementDeleteCallType{
ClientAddress: remoteFeature.Address(),
ServerAddress: localFeature.Address(),
Expand All @@ -90,8 +115,21 @@ func (suite *SubscriptionManagerSuite) Test_Subscriptions() {
subs = subMgr.Subscriptions(suite.remoteDevice)
assert.Equal(suite.T(), 1, len(subs))

subMgr.RemoveSubscriptionsForEntity(nil)

subs = subMgr.Subscriptions(suite.remoteDevice)
assert.Equal(suite.T(), 1, len(subs))

subMgr.RemoveSubscriptionsForDevice(nil)

subs = subMgr.Subscriptions(suite.remoteDevice)
assert.Equal(suite.T(), 1, len(subs))

subMgr.RemoveSubscriptionsForDevice(suite.remoteDevice)

subs = subMgr.Subscriptions(suite.remoteDevice)
assert.Equal(suite.T(), 0, len(subs))

subs = subMgr.Subscriptions(suite.remoteDevice2)
assert.Equal(suite.T(), 1, len(subs))
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
{
"datagram": {
"header": {
"specificationVersion": "1.3.0",
"addressSource": {
"device": "Wallbox",
"entity": [
0
],
"feature": 0
},
"addressDestination": {
"device": "HEMS",
"entity": [
0
],
"feature": 0
},
"msgCounter": 4,
"cmdClassifier": "notify",
"ackRequest":true
},
"payload": {
"cmd": [
{
"function": "nodeManagementDetailedDiscoveryData",
"filter": [
{
"cmdControl": {
"partial": {}
}
}
],
"nodeManagementDetailedDiscoveryData": {
"deviceInformation": {
"description": {
"deviceAddress": {
"device": "Wallbox"
}
}
},
"entityInformation": [
{
"description": {
"entityAddress": {
"entity": [
1,
1
]
},
"entityType": "EV",
"lastStateChange": "removed"
}
}
]
}
}
]
}
}
}

0 comments on commit 36970dd

Please sign in to comment.