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

Commit

Permalink
Update UCEVSECC and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
DerAndereAndi committed Feb 23, 2024
1 parent e379a8e commit 8456a98
Show file tree
Hide file tree
Showing 5 changed files with 148 additions and 20 deletions.
40 changes: 26 additions & 14 deletions ucevsecc/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,16 @@ func (e *UCEVSECC) HandleEvent(payload spineapi.EventPayload) {
return
}

switch payload.EventType {
case spineapi.EventTypeDataChange:
if payload.ChangeType != spineapi.ElementChangeUpdate {
return
}

switch payload.Data.(type) {
case *model.DeviceClassificationManufacturerDataType:
e.evseManufacturerDataUpdate(payload.Ski, payload.Entity)
case *model.DeviceDiagnosisStateDataType:
e.evseStateUpdate(payload.Ski, payload.Entity)
}
if payload.EventType != spineapi.EventTypeDataChange ||
payload.ChangeType != spineapi.ElementChangeUpdate {
return
}

switch payload.Data.(type) {
case *model.DeviceClassificationManufacturerDataType:
e.evseManufacturerDataUpdate(payload.Ski, payload.Entity)
case *model.DeviceDiagnosisStateDataType:
e.evseStateUpdate(payload.Ski, payload.Entity)
}
}

Expand All @@ -67,10 +65,24 @@ func (e *UCEVSECC) evseDisconnected(ski string, entity spineapi.EntityRemoteInte

// the manufacturer Data of an EVSE was updated
func (e *UCEVSECC) evseManufacturerDataUpdate(ski string, entity spineapi.EntityRemoteInterface) {
e.reader.SpineEvent(ski, entity, api.UCEVSECCEventManufacturerUpdate)
evDeviceClassification, err := util.DeviceClassification(e.service, entity)
if err != nil {
return
}

if _, err := evDeviceClassification.GetManufacturerDetails(); err == nil {
e.reader.SpineEvent(ski, entity, api.UCEVSECCEventManufacturerUpdate)
}
}

// the operating State of an EVSE was updated
func (e *UCEVSECC) evseStateUpdate(ski string, entity spineapi.EntityRemoteInterface) {
e.reader.SpineEvent(ski, entity, api.UCEVSECCEventOperationStateUpdate)
evDeviceDiagnosis, err := util.DeviceDiagnosis(e.service, entity)
if err != nil {
return
}

if _, err := evDeviceDiagnosis.GetState(); err == nil {
e.reader.SpineEvent(ski, entity, api.UCEVSECCEventOperationStateUpdate)
}
}
74 changes: 74 additions & 0 deletions ucevsecc/events_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package ucevsecc

import (
eebusutil "github.com/enbility/eebus-go/util"
spineapi "github.com/enbility/spine-go/api"
"github.com/enbility/spine-go/model"
"github.com/stretchr/testify/assert"
)

func (s *UCEVSECCSuite) Test_Events() {
payload := spineapi.EventPayload{
Entity: s.mockRemoteEntity,
}
s.sut.HandleEvent(payload)

payload.Entity = s.evseEntity
s.sut.HandleEvent(payload)

payload.EventType = spineapi.EventTypeDeviceChange
payload.ChangeType = spineapi.ElementChangeRemove
s.sut.HandleEvent(payload)

payload.EventType = spineapi.EventTypeEntityChange
payload.ChangeType = spineapi.ElementChangeAdd
s.sut.HandleEvent(payload)

payload.EventType = spineapi.EventTypeEntityChange
payload.ChangeType = spineapi.ElementChangeRemove
s.sut.HandleEvent(payload)

payload.EventType = spineapi.EventTypeDataChange
payload.ChangeType = spineapi.ElementChangeAdd
s.sut.HandleEvent(payload)

payload.EventType = spineapi.EventTypeDataChange
payload.ChangeType = spineapi.ElementChangeUpdate
payload.Data = eebusutil.Ptr(model.DeviceClassificationManufacturerDataType{})
s.sut.HandleEvent(payload)

payload.Data = eebusutil.Ptr(model.DeviceDiagnosisStateDataType{})
s.sut.HandleEvent(payload)
}

func (s *UCEVSECCSuite) Test_evseManufacturerDataUpdate() {
s.sut.evseManufacturerDataUpdate(remoteSki, s.mockRemoteEntity)

s.sut.evseManufacturerDataUpdate(remoteSki, s.evseEntity)

data := &model.DeviceClassificationManufacturerDataType{
BrandName: eebusutil.Ptr(model.DeviceClassificationStringType("test")),
}

rFeature := s.remoteDevice.FeatureByEntityTypeAndRole(s.evseEntity, model.FeatureTypeTypeDeviceClassification, model.RoleTypeServer)
fErr := rFeature.UpdateData(model.FunctionTypeDeviceClassificationManufacturerData, data, nil, nil)
assert.Nil(s.T(), fErr)

s.sut.evseManufacturerDataUpdate(remoteSki, s.evseEntity)
}

func (s *UCEVSECCSuite) Test_evseStateUpdate() {
s.sut.evseStateUpdate(remoteSki, s.mockRemoteEntity)

s.sut.evseStateUpdate(remoteSki, s.evseEntity)

data := &model.DeviceDiagnosisStateDataType{
OperatingState: eebusutil.Ptr(model.DeviceDiagnosisOperatingStateTypeNormalOperation),
}

rFeature := s.remoteDevice.FeatureByEntityTypeAndRole(s.evseEntity, model.FeatureTypeTypeDeviceDiagnosis, model.RoleTypeServer)
fErr := rFeature.UpdateData(model.FunctionTypeDeviceDiagnosisStateData, data, nil, nil)
assert.Nil(s.T(), fErr)

s.sut.evseStateUpdate(remoteSki, s.evseEntity)
}
4 changes: 2 additions & 2 deletions ucevsecc/public_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"github.com/stretchr/testify/assert"
)

func (s *EVSECCSuite) Test_EVSEManufacturerData() {
func (s *UCEVSECCSuite) Test_EVSEManufacturerData() {
device, serial, err := s.sut.ManufacturerData(nil)
assert.NotNil(s.T(), err)
assert.Equal(s.T(), "", device)
Expand Down Expand Up @@ -47,7 +47,7 @@ func (s *EVSECCSuite) Test_EVSEManufacturerData() {
assert.Equal(s.T(), "12345", serial)
}

func (s *EVSECCSuite) Test_EVSEOperatingState() {
func (s *UCEVSECCSuite) Test_EVSEOperatingState() {
data, errCode, err := s.sut.OperatingState(nil)
assert.Equal(s.T(), model.DeviceDiagnosisOperatingStateTypeNormalOperation, data)
assert.Equal(s.T(), "", errCode)
Expand Down
9 changes: 5 additions & 4 deletions ucevsecc/testhelper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ import (
)

func TestEVSECCSuite(t *testing.T) {
suite.Run(t, new(EVSECCSuite))
suite.Run(t, new(UCEVSECCSuite))
}

type EVSECCSuite struct {
type UCEVSECCSuite struct {
suite.Suite

sut *UCEVSECC
Expand All @@ -36,10 +36,10 @@ type EVSECCSuite struct {
evseEntity spineapi.EntityRemoteInterface
}

func (s *EVSECCSuite) SpineEvent(ski string, entity spineapi.EntityRemoteInterface, event api.UseCaseEventType) {
func (s *UCEVSECCSuite) SpineEvent(ski string, entity spineapi.EntityRemoteInterface, event api.UseCaseEventType) {
}

func (s *EVSECCSuite) BeforeTest(suiteName, testName string) {
func (s *UCEVSECCSuite) BeforeTest(suiteName, testName string) {
cert, _ := cert.CreateCertificate("test", "test", "DE", "test")
configuration, _ := eebusapi.NewConfiguration(
"test", "test", "test", "test",
Expand All @@ -62,6 +62,7 @@ func (s *EVSECCSuite) BeforeTest(suiteName, testName string) {
s.mockRemoteEntity.EXPECT().EntityType().Return(mock.Anything).Maybe()
entityAddress := &model.EntityAddressType{}
s.mockRemoteEntity.EXPECT().Address().Return(entityAddress).Maybe()
mockRemoteFeature.EXPECT().DataCopy(mock.Anything).Return(mock.Anything).Maybe()

var entities []spineapi.EntityRemoteInterface

Expand Down
41 changes: 41 additions & 0 deletions ucevsecc/ucevsecc_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package ucevsecc

import (
eebusutil "github.com/enbility/eebus-go/util"
"github.com/enbility/spine-go/model"
"github.com/stretchr/testify/assert"
)

func (s *UCEVSECCSuite) Test_IsUseCaseSupported() {
data, err := s.sut.IsUseCaseSupported(s.mockRemoteEntity)
assert.NotNil(s.T(), err)
assert.Equal(s.T(), false, data)

data, err = s.sut.IsUseCaseSupported(s.evseEntity)
assert.Nil(s.T(), err)
assert.Equal(s.T(), false, data)

ucData := &model.NodeManagementUseCaseDataType{
UseCaseInformation: []model.UseCaseInformationDataType{
{
Actor: eebusutil.Ptr(model.UseCaseActorTypeEV),
UseCaseSupport: []model.UseCaseSupportType{
{
UseCaseName: eebusutil.Ptr(model.UseCaseNameTypeEVSECommissioningAndConfiguration),
UseCaseAvailable: eebusutil.Ptr(true),
ScenarioSupport: []model.UseCaseScenarioSupportType{2},
},
},
},
},
}

nodemgmtEntity := s.remoteDevice.Entity([]model.AddressEntityType{0})
nodeFeature := s.remoteDevice.FeatureByEntityTypeAndRole(nodemgmtEntity, model.FeatureTypeTypeNodeManagement, model.RoleTypeSpecial)
fErr := nodeFeature.UpdateData(model.FunctionTypeNodeManagementUseCaseData, ucData, nil, nil)
assert.Nil(s.T(), fErr)

data, err = s.sut.IsUseCaseSupported(s.evseEntity)
assert.Nil(s.T(), err)
assert.Equal(s.T(), true, data)
}

0 comments on commit 8456a98

Please sign in to comment.