Skip to content

Commit 6363fd7

Browse files
committed
Address comments during code review
1 parent 05a6b42 commit 6363fd7

File tree

12 files changed

+390
-202
lines changed

12 files changed

+390
-202
lines changed

api/usecases.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,15 @@ type UseCaseBaseInterface interface {
5656
type UseCaseInterface interface {
5757
UseCaseBaseInterface
5858

59-
// add the features
59+
// add the features described by the Use Case
60+
//
61+
// returns an error if any Feature could not be added
62+
// - errors should not occur during normal usage of eebus-go, and should
63+
// generally be considered fatal implementation errors
64+
// - if an error occurs while adding features to a new Entity, that Entity
65+
// will be in an incomplete state and should not be added to the service
66+
//
67+
// No cleanup occurs on error, some features may end up partially
68+
// configured and unused
6069
AddFeatures() error
6170
}

service/service.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,13 @@ func (s *Service) IsRunning() bool {
193193
}
194194

195195
// add a use case to the service
196+
//
197+
// returns an error when adding features to the entity fails
198+
//
199+
// errors should not occur during normal usage of eebus-go, and should
200+
// generally be considered fatal implementation errors
201+
//
202+
// see usecase.AddFeatures() for more information
196203
func (s *Service) AddUseCase(useCase api.UseCaseInterface) error {
197204
s.usecases = append(s.usecases, useCase)
198205

usecases/api/api.go

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,34 @@
11
package api
22

3-
import "github.com/enbility/spine-go/model"
3+
import (
4+
"github.com/enbility/eebus-go/api"
5+
"github.com/enbility/spine-go/model"
6+
)
47

58
//go:generate mockery
69

710
var PhaseNameMapping = []model.ElectricalConnectionPhaseNameType{model.ElectricalConnectionPhaseNameTypeA, model.ElectricalConnectionPhaseNameTypeB, model.ElectricalConnectionPhaseNameTypeC}
11+
12+
// used to enable batch data updates for certain usecases
13+
//
14+
// a usecase that wants to provide batch update capabilities using this interface should
15+
//
16+
// 1. provide methods that return a type implementing this interface
17+
// 2. provide an Update method that accepts a list of this interface
18+
//
19+
// The Update method can then iterate over the provided UpdateData, ensure all
20+
// data points are supported, and then create a batched spine update request
21+
type UpdateData interface {
22+
Supported() bool
23+
NotSupportedError() error
24+
}
25+
26+
// used to enable batch data updates for MeaserumentData
27+
//
28+
// usecases can use this interface to provide batch update capabilities by
29+
// implementing a method that takes a list of this interface and passes a list
30+
// of MeasurementData to Measurement.UpdateDataForIds
31+
type UpdateMeasurementData interface {
32+
UpdateData
33+
MeasurementData() api.MeasurementDataForID
34+
}

usecases/api/mu_mpc.go

Lines changed: 19 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
package api
22

33
import (
4-
"github.com/enbility/eebus-go/api"
5-
"github.com/enbility/spine-go/model"
64
"time"
5+
6+
"github.com/enbility/spine-go/model"
77
)
88

99
// Actor: Monitoring Unit
@@ -91,29 +91,29 @@ type MuMPCInterface interface {
9191
// possible errors:
9292
// - ErrMissingData if the id is not available
9393
// - and others
94-
Update(data ...UpdateData) error
94+
Update(data ...UpdateMeasurementData) error
9595

9696
// Scenario 1
9797

9898
// use UpdateDataPowerTotal in Update to set the momentary active power consumption or production
9999
// The timestamp is optional and can be nil
100100
// The valueState shall be set if it differs from the normal valueState otherwise it can be nil
101-
UpdateDataPowerTotal(value float64, timestamp *time.Time, valueState *model.MeasurementValueStateType) UpdateData
101+
UpdateDataPowerTotal(value float64, timestamp *time.Time, valueState *model.MeasurementValueStateType) UpdateMeasurementData
102102

103103
// use UpdateDataPowerPhaseA in Update to set the momentary active power consumption or production per phase
104104
// The timestamp is optional and can be nil
105105
// The valueState shall be set if it differs from the normal valueState otherwise it can be nil
106-
UpdateDataPowerPhaseA(value float64, timestamp *time.Time, valueState *model.MeasurementValueStateType) UpdateData
106+
UpdateDataPowerPhaseA(value float64, timestamp *time.Time, valueState *model.MeasurementValueStateType) UpdateMeasurementData
107107

108108
// use UpdateDataPowerPhaseB in Update to set the momentary active power consumption or production per phase
109109
// The timestamp is optional and can be nil
110110
// The valueState shall be set if it differs from the normal valueState otherwise it can be nil
111-
UpdateDataPowerPhaseB(value float64, timestamp *time.Time, valueState *model.MeasurementValueStateType) UpdateData
111+
UpdateDataPowerPhaseB(value float64, timestamp *time.Time, valueState *model.MeasurementValueStateType) UpdateMeasurementData
112112

113113
// use UpdateDataPowerPhaseC in Update to set the momentary active power consumption or production per phase
114114
// The timestamp is optional and can be nil
115115
// The valueState shall be set if it differs from the normal valueState otherwise it can be nil
116-
UpdateDataPowerPhaseC(value float64, timestamp *time.Time, valueState *model.MeasurementValueStateType) UpdateData
116+
UpdateDataPowerPhaseC(value float64, timestamp *time.Time, valueState *model.MeasurementValueStateType) UpdateMeasurementData
117117

118118
// Scenario 2
119119

@@ -127,7 +127,7 @@ type MuMPCInterface interface {
127127
valueState *model.MeasurementValueStateType,
128128
evaluationStart *time.Time,
129129
evaluationEnd *time.Time,
130-
) UpdateData
130+
) UpdateMeasurementData
131131

132132
// use UpdateDataEnergyProduced in Update to set the total feed in energy
133133
// The timestamp is optional and can be nil
@@ -139,67 +139,61 @@ type MuMPCInterface interface {
139139
valueState *model.MeasurementValueStateType,
140140
evaluationStart *time.Time,
141141
evaluationEnd *time.Time,
142-
) UpdateData
142+
) UpdateMeasurementData
143143

144144
// Scenario 3
145145

146146
// use UpdateDataCurrentPhaseA in Update to set the momentary phase specific current consumption or production
147147
// The timestamp is optional and can be nil
148148
// The valueState shall be set if it differs from the normal valueState otherwise it can be nil
149-
UpdateDataCurrentPhaseA(value float64, timestamp *time.Time, valueState *model.MeasurementValueStateType) UpdateData
149+
UpdateDataCurrentPhaseA(value float64, timestamp *time.Time, valueState *model.MeasurementValueStateType) UpdateMeasurementData
150150

151151
// use UpdateDataCurrentPhaseB in Update to set the momentary phase specific current consumption or production
152152
// The timestamp is optional and can be nil
153153
// The valueState shall be set if it differs from the normal valueState otherwise it can be nil
154-
UpdateDataCurrentPhaseB(value float64, timestamp *time.Time, valueState *model.MeasurementValueStateType) UpdateData
154+
UpdateDataCurrentPhaseB(value float64, timestamp *time.Time, valueState *model.MeasurementValueStateType) UpdateMeasurementData
155155

156156
// use UpdateDataCurrentPhaseC in Update to set the momentary phase specific current consumption or production
157157
// The timestamp is optional and can be nil
158158
// The valueState shall be set if it differs from the normal valueState otherwise it can be nil
159-
UpdateDataCurrentPhaseC(value float64, timestamp *time.Time, valueState *model.MeasurementValueStateType) UpdateData
159+
UpdateDataCurrentPhaseC(value float64, timestamp *time.Time, valueState *model.MeasurementValueStateType) UpdateMeasurementData
160160

161161
// Scenario 4
162162

163163
// use UpdateDataVoltagePhaseA in Update to set the phase specific voltage details
164164
// The timestamp is optional and can be nil
165165
// The valueState shall be set if it differs from the normal valueState otherwise it can be nil
166-
UpdateDataVoltagePhaseA(value float64, timestamp *time.Time, valueState *model.MeasurementValueStateType) UpdateData
166+
UpdateDataVoltagePhaseA(value float64, timestamp *time.Time, valueState *model.MeasurementValueStateType) UpdateMeasurementData
167167

168168
// use UpdateDataVoltagePhaseB in Update to set the phase specific voltage details
169169
// The timestamp is optional and can be nil
170170
// The valueState shall be set if it differs from the normal valueState otherwise it can be nil
171-
UpdateDataVoltagePhaseB(value float64, timestamp *time.Time, valueState *model.MeasurementValueStateType) UpdateData
171+
UpdateDataVoltagePhaseB(value float64, timestamp *time.Time, valueState *model.MeasurementValueStateType) UpdateMeasurementData
172172

173173
// use UpdateDataVoltagePhaseC in Update to set the phase specific voltage details
174174
// The timestamp is optional and can be nil
175175
// The valueState shall be set if it differs from the normal valueState otherwise it can be nil
176-
UpdateDataVoltagePhaseC(value float64, timestamp *time.Time, valueState *model.MeasurementValueStateType) UpdateData
176+
UpdateDataVoltagePhaseC(value float64, timestamp *time.Time, valueState *model.MeasurementValueStateType) UpdateMeasurementData
177177

178178
// use UpdateDataVoltagePhaseAToB in Update to set the phase specific voltage details
179179
// The timestamp is optional and can be nil
180180
// The valueState shall be set if it differs from the normal valueState otherwise it can be nil
181-
UpdateDataVoltagePhaseAToB(value float64, timestamp *time.Time, valueState *model.MeasurementValueStateType) UpdateData
181+
UpdateDataVoltagePhaseAToB(value float64, timestamp *time.Time, valueState *model.MeasurementValueStateType) UpdateMeasurementData
182182

183183
// use UpdateDataVoltagePhaseBToC in Update to set the phase specific voltage details
184184
// The timestamp is optional and can be nil
185185
// The valueState shall be set if it differs from the normal valueState otherwise it can be nil
186-
UpdateDataVoltagePhaseBToC(value float64, timestamp *time.Time, valueState *model.MeasurementValueStateType) UpdateData
186+
UpdateDataVoltagePhaseBToC(value float64, timestamp *time.Time, valueState *model.MeasurementValueStateType) UpdateMeasurementData
187187

188188
// use UpdateDataVoltagePhaseCToA in Update to set the phase specific voltage details
189189
// The timestamp is optional and can be nil
190190
// The valueState shall be set if it differs from the normal valueState otherwise it can be nil
191-
UpdateDataVoltagePhaseCToA(value float64, timestamp *time.Time, valueState *model.MeasurementValueStateType) UpdateData
191+
UpdateDataVoltagePhaseCToA(value float64, timestamp *time.Time, valueState *model.MeasurementValueStateType) UpdateMeasurementData
192192

193193
// Scenario 5
194194

195195
// use AcFrequency in Update to set the frequency
196196
// The timestamp is optional and can be nil
197197
// The valueState shall be set if it differs from the normal valueState otherwise it can be nil
198-
UpdateDataFrequency(value float64, timestamp *time.Time, valueState *model.MeasurementValueStateType) UpdateData
199-
}
200-
201-
type UpdateData interface {
202-
Supported() bool
203-
NotSupportedError() error
204-
MeasurementData() api.MeasurementDataForID
198+
UpdateDataFrequency(value float64, timestamp *time.Time, valueState *model.MeasurementValueStateType) UpdateMeasurementData
205199
}

0 commit comments

Comments
 (0)