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

Commit 74909dd

Browse files
committed
Update events to use actual provided data
Before data update events where triggered, whenever the data type was sent and the actual data item existed in the data storage. Which means that only updating a current measurement also triggered an update event for SoC if that was present in the store from an earlier update. This is now changed and only considers the data elements that are actually provided in the payload. Note: This does NOT consider if a datapoint has been deleted and not updated!
1 parent d84105b commit 74909dd

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+827
-288
lines changed

ucevcc/events.go

+2-7
Original file line numberDiff line numberDiff line change
@@ -128,18 +128,13 @@ func (e *UCEVCC) evConfigurationDescriptionDataUpdate(entity spineapi.EntityRemo
128128

129129
// the configuration key data of an EV was updated
130130
func (e *UCEVCC) evConfigurationDataUpdate(payload spineapi.EventPayload) {
131-
evDeviceConfiguration, err := util.DeviceConfiguration(e.service, payload.Entity)
132-
if err != nil {
133-
return
134-
}
135-
136131
// Scenario 2
137-
if _, err := evDeviceConfiguration.GetKeyValueForKeyName(model.DeviceConfigurationKeyNameTypeCommunicationsStandard, model.DeviceConfigurationKeyValueTypeTypeString); err == nil {
132+
if util.DeviceConfigurationCheckDataPayloadForKeyName(false, e.service, payload, model.DeviceConfigurationKeyNameTypeCommunicationsStandard) {
138133
e.eventCB(payload.Ski, payload.Device, payload.Entity, DataUpdateCommunicationStandard)
139134
}
140135

141136
// Scenario 3
142-
if _, err := evDeviceConfiguration.GetKeyValueForKeyName(model.DeviceConfigurationKeyNameTypeAsymmetricChargingSupported, model.DeviceConfigurationKeyValueTypeTypeString); err == nil {
137+
if util.DeviceConfigurationCheckDataPayloadForKeyName(false, e.service, payload, model.DeviceConfigurationKeyNameTypeAsymmetricChargingSupported) {
143138
e.eventCB(payload.Ski, payload.Device, payload.Entity, DataUpdateAsymmetricChargingSupport)
144139
}
145140
}

ucevcc/events_test.go

+17-5
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,11 @@ func (s *UCEVCCSuite) Test_evConfigurationDataUpdate() {
8484
descData := &model.DeviceConfigurationKeyValueDescriptionListDataType{
8585
DeviceConfigurationKeyValueDescriptionData: []model.DeviceConfigurationKeyValueDescriptionDataType{
8686
{
87-
KeyId: eebusutil.Ptr(model.DeviceConfigurationKeyIdType(0)),
87+
KeyId: eebusutil.Ptr(model.DeviceConfigurationKeyIdType(1)),
8888
KeyName: eebusutil.Ptr(model.DeviceConfigurationKeyNameTypeCommunicationsStandard),
8989
},
9090
{
91-
KeyId: eebusutil.Ptr(model.DeviceConfigurationKeyIdType(1)),
91+
KeyId: eebusutil.Ptr(model.DeviceConfigurationKeyIdType(2)),
9292
KeyName: eebusutil.Ptr(model.DeviceConfigurationKeyNameTypeAsymmetricChargingSupported),
9393
},
9494
},
@@ -102,24 +102,36 @@ func (s *UCEVCCSuite) Test_evConfigurationDataUpdate() {
102102
assert.False(s.T(), s.eventCBInvoked)
103103

104104
data := &model.DeviceConfigurationKeyValueListDataType{
105+
DeviceConfigurationKeyValueData: []model.DeviceConfigurationKeyValueDataType{},
106+
}
107+
108+
payload.Data = data
109+
110+
s.sut.evConfigurationDataUpdate(payload)
111+
assert.False(s.T(), s.eventCBInvoked)
112+
113+
data = &model.DeviceConfigurationKeyValueListDataType{
105114
DeviceConfigurationKeyValueData: []model.DeviceConfigurationKeyValueDataType{
106115
{
107116
KeyId: eebusutil.Ptr(model.DeviceConfigurationKeyIdType(0)),
117+
Value: eebusutil.Ptr(model.DeviceConfigurationKeyValueValueType{}),
118+
},
119+
{
120+
KeyId: eebusutil.Ptr(model.DeviceConfigurationKeyIdType(1)),
108121
Value: eebusutil.Ptr(model.DeviceConfigurationKeyValueValueType{
109122
String: eebusutil.Ptr(model.DeviceConfigurationKeyValueStringTypeISO151182ED2),
110123
}),
111124
},
112125
{
113-
KeyId: eebusutil.Ptr(model.DeviceConfigurationKeyIdType(1)),
126+
KeyId: eebusutil.Ptr(model.DeviceConfigurationKeyIdType(2)),
114127
Value: eebusutil.Ptr(model.DeviceConfigurationKeyValueValueType{
115128
Boolean: eebusutil.Ptr(false),
116129
}),
117130
},
118131
},
119132
}
120133

121-
fErr = rFeature.UpdateData(model.FunctionTypeDeviceConfigurationKeyValueListData, data, nil, nil)
122-
assert.Nil(s.T(), fErr)
134+
payload.Data = data
123135

124136
s.sut.evConfigurationDataUpdate(payload)
125137
assert.True(s.T(), s.eventCBInvoked)

ucevcc/types.go

-3
Original file line numberDiff line numberDiff line change
@@ -46,16 +46,13 @@ const (
4646
// - the entity of the EV
4747
//
4848
// Use Case EVCC, Scenario 2
49-
// Note: the referred data may be updated together with all other configuration items of this use case
5049
DataUpdateCommunicationStandard api.EventType = "DataUpdateCommunicationStandard"
5150

5251
// EV asymmetric charging data was updated
5352
//
5453
// The callback with this message provides:
5554
// - the device of the EVSE the EV is connected to
5655
// - the entity of the EV
57-
//
58-
// Note: the referred data may be updated together with all other configuration items of this use case
5956
DataUpdateAsymmetricChargingSupport api.EventType = "DataUpdateAsymmetricChargingSupport"
6057

6158
// EV identificationdata was updated

ucevcem/events.go

+12-5
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,18 @@ func (e *UCEVCEM) evConnected(entity spineapi.EntityRemoteInterface) {
7373

7474
// the electrical connection description data of an EV was updated
7575
func (e *UCEVCEM) evElectricalConnectionDescriptionDataUpdate(payload spineapi.EventPayload) {
76-
if _, err := e.PhasesConnected(payload.Entity); err != nil {
76+
if payload.Data == nil {
7777
return
7878
}
7979

80-
e.eventCB(payload.Ski, payload.Device, payload.Entity, DataUpdatePhasesConnected)
80+
data := payload.Data.(*model.ElectricalConnectionDescriptionListDataType)
81+
82+
for _, item := range data.ElectricalConnectionDescriptionData {
83+
if item.ElectricalConnectionId != nil && item.AcConnectedPhases != nil {
84+
e.eventCB(payload.Ski, payload.Device, payload.Entity, DataUpdatePhasesConnected)
85+
return
86+
}
87+
}
8188
}
8289

8390
// the measurement description data of an EV was updated
@@ -93,17 +100,17 @@ func (e *UCEVCEM) evMeasurementDescriptionDataUpdate(entity spineapi.EntityRemot
93100
// the measurement data of an EV was updated
94101
func (e *UCEVCEM) evMeasurementDataUpdate(payload spineapi.EventPayload) {
95102
// Scenario 1
96-
if _, err := util.MeasurementValueForScope(e.service, payload.Entity, model.ScopeTypeTypeACCurrent); err == nil {
103+
if util.MeasurementCheckPayloadDataForScope(e.service, payload, model.ScopeTypeTypeACCurrent) {
97104
e.eventCB(payload.Ski, payload.Device, payload.Entity, DataUpdateCurrentPerPhase)
98105
}
99106

100107
// Scenario 2
101-
if _, err := util.MeasurementValueForScope(e.service, payload.Entity, model.ScopeTypeTypeACPower); err == nil {
108+
if util.MeasurementCheckPayloadDataForScope(e.service, payload, model.ScopeTypeTypeACPower) {
102109
e.eventCB(payload.Ski, payload.Device, payload.Entity, DataUpdatePowerPerPhase)
103110
}
104111

105112
// Scenario 3
106-
if _, err := util.MeasurementValueForScope(e.service, payload.Entity, model.ScopeTypeTypeCharge); err == nil {
113+
if util.MeasurementCheckPayloadDataForScope(e.service, payload, model.ScopeTypeTypeCharge) {
107114
e.eventCB(payload.Ski, payload.Device, payload.Entity, DataUpdateEnergyCharged)
108115
}
109116
}

ucevcem/events_test.go

+10-6
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,14 @@ func (s *UCEVCEMSuite) Test_evElectricalConnectionDescriptionDataUpdate() {
5454
s.sut.evElectricalConnectionDescriptionDataUpdate(payload)
5555

5656
descData := &model.ElectricalConnectionDescriptionListDataType{
57+
ElectricalConnectionDescriptionData: []model.ElectricalConnectionDescriptionDataType{},
58+
}
59+
60+
payload.Data = descData
61+
62+
s.sut.evElectricalConnectionDescriptionDataUpdate(payload)
63+
64+
descData = &model.ElectricalConnectionDescriptionListDataType{
5765
ElectricalConnectionDescriptionData: []model.ElectricalConnectionDescriptionDataType{
5866
{
5967
ElectricalConnectionId: eebusutil.Ptr(model.ElectricalConnectionIdType(0)),
@@ -62,9 +70,7 @@ func (s *UCEVCEMSuite) Test_evElectricalConnectionDescriptionDataUpdate() {
6270
},
6371
}
6472

65-
rFeature := s.remoteDevice.FeatureByEntityTypeAndRole(s.evEntity, model.FeatureTypeTypeElectricalConnection, model.RoleTypeServer)
66-
fErr := rFeature.UpdateData(model.FunctionTypeElectricalConnectionDescriptionListData, descData, nil, nil)
67-
assert.Nil(s.T(), fErr)
73+
payload.Data = descData
6874

6975
s.sut.evElectricalConnectionDescriptionDataUpdate(payload)
7076
}
@@ -119,9 +125,7 @@ func (s *UCEVCEMSuite) Test_evMeasurementDataUpdate() {
119125
},
120126
},
121127
}
122-
123-
fErr = rFeature.UpdateData(model.FunctionTypeMeasurementListData, data, nil, nil)
124-
assert.Nil(s.T(), fErr)
128+
payload.Data = data
125129

126130
s.sut.evMeasurementDataUpdate(payload)
127131
}

ucevcem/types.go

-8
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ const (
1010
// - the entity of the EV
1111
//
1212
// Use Case EVCEM, Scenario 1
13-
//
14-
// Note: the referred data may be updated together with all other measurement items of this use case
1513
DataUpdatePhasesConnected api.EventType = "DataUpdatePhasesConnected"
1614

1715
// EV current measurement data updated
@@ -21,8 +19,6 @@ const (
2119
// - the entity of the EV
2220
//
2321
// Use Case EVCEM, Scenario 1
24-
//
25-
// Note: the referred data may be updated together with all other measurement items of this use case
2622
DataUpdateCurrentPerPhase api.EventType = "DataUpdateCurrentPerPhase"
2723

2824
// EV power measurement data updated
@@ -32,8 +28,6 @@ const (
3228
// - the entity of the EV
3329
//
3430
// Use Case EVCEM, Scenario 2
35-
//
36-
// Note: the referred data may be updated together with all other measurement items of this use case
3731
DataUpdatePowerPerPhase api.EventType = "DataUpdatePowerPerPhase"
3832

3933
// EV charging energy measurement data updated
@@ -43,7 +37,5 @@ const (
4337
// - the entity of the EV
4438
//
4539
// Use Case EVCEM, Scenario 3
46-
//
47-
// Note: the referred data may be updated together with all other measurement items of this use case
4840
DataUpdateEnergyCharged api.EventType = "DataUpdateEnergyCharged"
4941
)

ucevsoc/events.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ func (e *UCEVSOC) evConnected(entity spineapi.EntityRemoteInterface) {
5656
// the measurement data of an EV was updated
5757
func (e *UCEVSOC) evMeasurementDataUpdate(payload spineapi.EventPayload) {
5858
// Scenario 1
59-
if _, err := util.MeasurementValueForScope(e.service, payload.Entity, model.ScopeTypeTypeStateOfCharge); err == nil {
59+
if util.MeasurementCheckPayloadDataForScope(e.service, payload, model.ScopeTypeTypeStateOfCharge) {
6060
e.eventCB(payload.Ski, payload.Device, payload.Entity, DataUpdateStateOfCharge)
6161
}
6262
}

ucevsoc/events_test.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,7 @@ func (s *UCEVSOCSuite) Test_evMeasurementDataUpdate() {
8585
},
8686
}
8787

88-
fErr = rFeature.UpdateData(model.FunctionTypeMeasurementListData, data, nil, nil)
89-
assert.Nil(s.T(), fErr)
88+
payload.Data = data
9089

9190
s.sut.evMeasurementDataUpdate(payload)
9291
}

ucevsoc/types.go

-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,5 @@ const (
1010
// - the entity of the EV
1111
//
1212
// Use Case EVSOC, Scenario 1
13-
//
14-
// Note: the referred data may be updated together with all other measurement items of this use case
1513
DataUpdateStateOfCharge api.EventType = "DataUpdateStateOfCharge"
1614
)

uclpc/events.go

+8-23
Original file line numberDiff line numberDiff line change
@@ -68,28 +68,13 @@ func (e *UCLPC) loadControlLimitDescriptionDataUpdate(entity spineapi.EntityRemo
6868

6969
// the load control limit data was updated
7070
func (e *UCLPC) loadControlLimitDataUpdate(payload spineapi.EventPayload) {
71-
loadControl, err := util.LoadControl(e.service, payload.Entity)
72-
if err != nil {
73-
return
74-
}
75-
76-
data, err := loadControl.GetLimitDescriptionsForCategory(model.LoadControlCategoryTypeObligation)
77-
if err != nil {
78-
return
79-
}
80-
81-
for _, item := range data {
82-
if item.LimitId == nil {
83-
continue
84-
}
85-
86-
_, err := loadControl.GetLimitValueForLimitId(*item.LimitId)
87-
if err != nil {
88-
continue
89-
}
90-
71+
if util.LoadControlLimitsCheckPayloadDataForTypeCategoryDirectionScope(
72+
false, e.service, payload,
73+
model.LoadControlLimitTypeTypeSignDependentAbsValueLimit,
74+
model.LoadControlCategoryTypeObligation,
75+
model.EnergyDirectionTypeConsume,
76+
model.ScopeTypeTypeActivePowerLimit) {
9177
e.eventCB(payload.Ski, payload.Device, payload.Entity, DataUpdateLimit)
92-
return
9378
}
9479
}
9580

@@ -105,10 +90,10 @@ func (e *UCLPC) configurationDescriptionDataUpdate(entity spineapi.EntityRemoteI
10590

10691
// the configuration key data was updated
10792
func (e *UCLPC) configurationDataUpdate(payload spineapi.EventPayload) {
108-
if _, err := e.FailsafeConsumptionActivePowerLimit(payload.Entity); err != nil {
93+
if util.DeviceConfigurationCheckDataPayloadForKeyName(false, e.service, payload, model.DeviceConfigurationKeyNameTypeFailsafeConsumptionActivePowerLimit) {
10994
e.eventCB(payload.Ski, payload.Device, payload.Entity, DataUpdateFailsafeConsumptionActivePowerLimit)
11095
}
111-
if _, err := e.FailsafeDurationMinimum(payload.Entity); err != nil {
96+
if util.DeviceConfigurationCheckDataPayloadForKeyName(false, e.service, payload, model.DeviceConfigurationKeyNameTypeFailsafeDurationMinimum) {
11297
e.eventCB(payload.Ski, payload.Device, payload.Entity, DataUpdateFailsafeDurationMinimum)
11398
}
11499
}

uclpc/events_test.go

+67-4
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,11 @@ func (s *UCLPCSuite) Test_loadControlLimitDataUpdate() {
5656
descData := &model.LoadControlLimitDescriptionListDataType{
5757
LoadControlLimitDescriptionData: []model.LoadControlLimitDescriptionDataType{
5858
{
59-
LimitId: eebusutil.Ptr(model.LoadControlLimitIdType(0)),
60-
LimitCategory: eebusutil.Ptr(model.LoadControlCategoryTypeObligation),
59+
LimitId: eebusutil.Ptr(model.LoadControlLimitIdType(0)),
60+
LimitType: eebusutil.Ptr(model.LoadControlLimitTypeTypeSignDependentAbsValueLimit),
61+
LimitCategory: eebusutil.Ptr(model.LoadControlCategoryTypeObligation),
62+
LimitDirection: eebusutil.Ptr(model.EnergyDirectionTypeConsume),
63+
ScopeType: eebusutil.Ptr(model.ScopeTypeTypeActivePowerLimit),
6164
},
6265
},
6366
}
@@ -69,6 +72,14 @@ func (s *UCLPCSuite) Test_loadControlLimitDataUpdate() {
6972
s.sut.loadControlLimitDataUpdate(payload)
7073

7174
data := &model.LoadControlLimitListDataType{
75+
LoadControlLimitData: []model.LoadControlLimitDataType{},
76+
}
77+
78+
payload.Data = data
79+
80+
s.sut.loadControlLimitDataUpdate(payload)
81+
82+
data = &model.LoadControlLimitListDataType{
7283
LoadControlLimitData: []model.LoadControlLimitDataType{
7384
{
7485
LimitId: eebusutil.Ptr(model.LoadControlLimitIdType(0)),
@@ -77,8 +88,60 @@ func (s *UCLPCSuite) Test_loadControlLimitDataUpdate() {
7788
},
7889
}
7990

80-
fErr = rFeature.UpdateData(model.FunctionTypeLoadControlLimitListData, data, nil, nil)
81-
assert.Nil(s.T(), fErr)
91+
payload.Data = data
8292

8393
s.sut.loadControlLimitDataUpdate(payload)
8494
}
95+
96+
func (s *UCLPCSuite) Test_configurationDataUpdate() {
97+
payload := spineapi.EventPayload{
98+
Ski: remoteSki,
99+
Device: s.remoteDevice,
100+
Entity: s.monitoredEntity,
101+
}
102+
s.sut.configurationDataUpdate(payload)
103+
104+
descData := &model.DeviceConfigurationKeyValueDescriptionListDataType{
105+
DeviceConfigurationKeyValueDescriptionData: []model.DeviceConfigurationKeyValueDescriptionDataType{
106+
{
107+
KeyId: eebusutil.Ptr(model.DeviceConfigurationKeyIdType(1)),
108+
KeyName: eebusutil.Ptr(model.DeviceConfigurationKeyNameTypeFailsafeConsumptionActivePowerLimit),
109+
},
110+
{
111+
KeyId: eebusutil.Ptr(model.DeviceConfigurationKeyIdType(2)),
112+
KeyName: eebusutil.Ptr(model.DeviceConfigurationKeyNameTypeFailsafeDurationMinimum),
113+
},
114+
},
115+
}
116+
117+
rFeature := s.remoteDevice.FeatureByEntityTypeAndRole(s.monitoredEntity, model.FeatureTypeTypeDeviceConfiguration, model.RoleTypeServer)
118+
fErr := rFeature.UpdateData(model.FunctionTypeDeviceConfigurationKeyValueDescriptionListData, descData, nil, nil)
119+
assert.Nil(s.T(), fErr)
120+
121+
s.sut.configurationDataUpdate(payload)
122+
123+
data := &model.DeviceConfigurationKeyValueListDataType{
124+
DeviceConfigurationKeyValueData: []model.DeviceConfigurationKeyValueDataType{},
125+
}
126+
127+
payload.Data = data
128+
129+
s.sut.configurationDataUpdate(payload)
130+
131+
data = &model.DeviceConfigurationKeyValueListDataType{
132+
DeviceConfigurationKeyValueData: []model.DeviceConfigurationKeyValueDataType{
133+
{
134+
KeyId: eebusutil.Ptr(model.DeviceConfigurationKeyIdType(1)),
135+
Value: &model.DeviceConfigurationKeyValueValueType{},
136+
},
137+
{
138+
KeyId: eebusutil.Ptr(model.DeviceConfigurationKeyIdType(2)),
139+
Value: &model.DeviceConfigurationKeyValueValueType{},
140+
},
141+
},
142+
}
143+
144+
payload.Data = data
145+
146+
s.sut.configurationDataUpdate(payload)
147+
}

uclpc/types.go

-4
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@ const (
2020
// - the entity of the e.g. EVSE
2121
//
2222
// Use Case LPC, Scenario 2
23-
//
24-
// Note: the referred data may be updated together with all other configuration items of this use case
2523
DataUpdateFailsafeConsumptionActivePowerLimit api.EventType = "DataUpdateFailsafeConsumptionActivePowerLimit"
2624

2725
// Minimum time the Controllable System remains in "failsafe state" unless conditions
@@ -32,7 +30,5 @@ const (
3230
// - the entity of the e.g. EVSE
3331
//
3432
// Use Case LPC, Scenario 2
35-
//
36-
// Note: the referred data may be updated together with all other configuration items of this use case
3733
DataUpdateFailsafeDurationMinimum api.EventType = "DataUpdateFailsafeDurationMinimum"
3834
)

0 commit comments

Comments
 (0)