Skip to content

Commit f635e34

Browse files
Properly support CS LPC & LPP for all device types (#100)
Depending on the devices type (Energy Management System or not), the nominal max values for LPC and LPP as a controllable systems have a different type. This change now uses the local entities associated devices devicetype and uses the proper associated CharacteristicType value.
2 parents 80409c9 + 9e0291a commit f635e34

File tree

10 files changed

+214
-162
lines changed

10 files changed

+214
-162
lines changed

usecases/api/cs_lpc.go

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -81,14 +81,18 @@ type CsLPCInterface interface {
8181

8282
// Scenario 4
8383

84-
// return nominal maximum active (real) power the Controllable System is
85-
// allowed to consume due to the customer's contract.
86-
ContractualConsumptionNominalMax() (float64, error)
84+
// return nominal maximum active (real) power the Controllable System is allowed to consume.
85+
//
86+
// If the local device type is an EnergyManagementSystem, the contractual consumption
87+
// nominal max is returned, otherwise the power consumption nominal max is returned.
88+
ConsumptionNominalMax() (float64, error)
8789

88-
// set nominal maximum active (real) power the Controllable System is
89-
// allowed to consume due to the customer's contract.
90+
// set power nominal maximum active (real) power the Controllable System is allowed to consume.
91+
//
92+
// If the local device type is an EnergyManagementSystem, the contractual consumption
93+
// nominal max is set, otherwise the power consumption nominal max is set.
9094
//
9195
// parameters:
92-
// - value: contractual nominal max power consumption in W
93-
SetContractualConsumptionNominalMax(value float64) (resultErr error)
96+
// - value: nominal max power consumption in W
97+
SetConsumptionNominalMax(value float64) (resultErr error)
9498
}

usecases/api/cs_lpp.go

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -81,14 +81,18 @@ type CsLPPInterface interface {
8181

8282
// Scenario 4
8383

84-
// return nominal maximum active (real) power the Controllable System is
85-
// allowed to produce due to the customer's contract.
86-
ContractualProductionNominalMax() (float64, error)
84+
// return nominal maximum active (real) power the Controllable System is allowed to produce.
85+
//
86+
// If the local device type is an EnergyManagementSystem, the contractual production
87+
// nominal max is returned, otherwise the power production nominal max is returned.
88+
ProductionNominalMax() (float64, error)
8789

88-
// set nominal maximum active (real) power the Controllable System is
89-
// allowed to produce due to the customer's contract.
90+
// set power nominal maximum active (real) power the Controllable System is allowed to produce.
91+
//
92+
// If the local device type is an EnergyManagementSystem, the contractual production
93+
// nominal max is set, otherwise the power production nominal max is set.
9094
//
9195
// parameters:
92-
// - value: contractual nominal max power production in W
93-
SetContractualProductionNominalMax(value float64) (resultErr error)
96+
// - value: nominal max power production in W
97+
SetProductionNominalMax(value float64) (resultErr error)
9498
}

usecases/cs/lpc/public.go

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -285,9 +285,11 @@ func (e *LPC) IsHeartbeatWithinDuration() bool {
285285

286286
// Scenario 4
287287

288-
// return nominal maximum active (real) power the Controllable System is
289-
// allowed to consume due to the customer's contract.
290-
func (e *LPC) ContractualConsumptionNominalMax() (value float64, resultErr error) {
288+
// return nominal maximum active (real) power the Controllable System is allowed to consume.
289+
//
290+
// If the local device type is an EnergyManagementSystem, the contractual consumption
291+
// nominal max is returned, otherwise the power consumption nominal max is returned.
292+
func (e *LPC) ConsumptionNominalMax() (value float64, resultErr error) {
291293
value = 0
292294
resultErr = api.ErrDataNotAvailable
293295

@@ -301,7 +303,7 @@ func (e *LPC) ContractualConsumptionNominalMax() (value float64, resultErr error
301303
ElectricalConnectionId: util.Ptr(model.ElectricalConnectionIdType(0)),
302304
ParameterId: util.Ptr(model.ElectricalConnectionParameterIdType(0)),
303305
CharacteristicContext: util.Ptr(model.ElectricalConnectionCharacteristicContextTypeEntity),
304-
CharacteristicType: util.Ptr(model.ElectricalConnectionCharacteristicTypeTypeContractualConsumptionNominalMax),
306+
CharacteristicType: util.Ptr(e.characteristicType()),
305307
}
306308
charData, err := ec.GetCharacteristicsForFilter(filter)
307309
if err != nil || len(charData) == 0 ||
@@ -313,9 +315,14 @@ func (e *LPC) ContractualConsumptionNominalMax() (value float64, resultErr error
313315
return charData[0].Value.GetValue(), nil
314316
}
315317

316-
// set nominal maximum active (real) power the Controllable System is
317-
// allowed to consume due to the customer's contract.
318-
func (e *LPC) SetContractualConsumptionNominalMax(value float64) error {
318+
// set nominal maximum active (real) power the Controllable System is allowed to consume.
319+
//
320+
// If the local device type is an EnergyManagementSystem, the contractual consumption
321+
// nominal max is set, otherwise the power consumption nominal max is set.
322+
//
323+
// parameters:
324+
// - value: nominal max power consumption in W
325+
func (e *LPC) SetConsumptionNominalMax(value float64) error {
319326
ec, err := server.NewElectricalConnection(e.LocalEntity)
320327
if err != nil {
321328
return err
@@ -327,7 +334,7 @@ func (e *LPC) SetContractualConsumptionNominalMax(value float64) error {
327334
ElectricalConnectionId: electricalConnectionid,
328335
ParameterId: parameterId,
329336
CharacteristicContext: util.Ptr(model.ElectricalConnectionCharacteristicContextTypeEntity),
330-
CharacteristicType: util.Ptr(model.ElectricalConnectionCharacteristicTypeTypeContractualConsumptionNominalMax),
337+
CharacteristicType: util.Ptr(e.characteristicType()),
331338
})
332339
if err != nil || len(charList) == 0 {
333340
return api.ErrDataNotAvailable
@@ -341,3 +348,18 @@ func (e *LPC) SetContractualConsumptionNominalMax(value float64) error {
341348
}
342349
return ec.UpdateCharacteristic(data, nil)
343350
}
351+
352+
// returns the characteristictype depending on the local entities device devicetype
353+
func (e *LPC) characteristicType() model.ElectricalConnectionCharacteristicTypeType {
354+
deviceType := e.LocalEntity.Device().DeviceType()
355+
356+
// According to LPC V1.0 2.2, lines 400ff:
357+
// - a HEMS provides contractual consumption nominal max
358+
// - any other devices provides power consupmtion nominal max
359+
characteristic := model.ElectricalConnectionCharacteristicTypeTypePowerConsumptionNominalMax
360+
if deviceType == nil || *deviceType == model.DeviceTypeTypeEnergyManagementSystem {
361+
characteristic = model.ElectricalConnectionCharacteristicTypeTypeContractualConsumptionNominalMax
362+
}
363+
364+
return characteristic
365+
}

usecases/cs/lpc/public_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -152,15 +152,15 @@ func (s *CsLPCSuite) Test_IsHeartbeatWithinDuration() {
152152
assert.True(s.T(), value)
153153
}
154154

155-
func (s *CsLPCSuite) Test_ContractualConsumptionNominalMax() {
156-
value, err := s.sut.ContractualConsumptionNominalMax()
155+
func (s *CsLPCSuite) Test_ConsumptionNominalMax() {
156+
value, err := s.sut.ConsumptionNominalMax()
157157
assert.Equal(s.T(), 0.0, value)
158158
assert.NotNil(s.T(), err)
159159

160-
err = s.sut.SetContractualConsumptionNominalMax(10)
160+
err = s.sut.SetConsumptionNominalMax(10)
161161
assert.Nil(s.T(), err)
162162

163-
value, err = s.sut.ContractualConsumptionNominalMax()
163+
value, err = s.sut.ConsumptionNominalMax()
164164
assert.Equal(s.T(), 10.0, value)
165165
assert.Nil(s.T(), err)
166166
}

usecases/cs/lpc/usecase.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ func (e *LPC) AddFeatures() {
245245
ElectricalConnectionId: util.Ptr(model.ElectricalConnectionIdType(0)),
246246
ParameterId: util.Ptr(model.ElectricalConnectionParameterIdType(0)),
247247
CharacteristicContext: util.Ptr(model.ElectricalConnectionCharacteristicContextTypeEntity),
248-
CharacteristicType: util.Ptr(model.ElectricalConnectionCharacteristicTypeTypeContractualConsumptionNominalMax),
248+
CharacteristicType: util.Ptr(e.characteristicType()),
249249
Unit: util.Ptr(model.UnitOfMeasurementTypeW),
250250
}
251251
_, _ = ec.AddCharacteristic(newCharData)

usecases/cs/lpp/public.go

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -285,9 +285,11 @@ func (e *LPP) IsHeartbeatWithinDuration() bool {
285285

286286
// Scenario 4
287287

288-
// return nominal maximum active (real) power the Controllable System is
289-
// allowed to produce due to the customer's contract.
290-
func (e *LPP) ContractualProductionNominalMax() (value float64, resultErr error) {
288+
// return nominal maximum active (real) power the Controllable System is allowed to produce.
289+
//
290+
// If the local device type is an EnergyManagementSystem, the contractual production
291+
// nominal max is returned, otherwise the power production nominal max is returned.
292+
func (e *LPP) ProductionNominalMax() (value float64, resultErr error) {
291293
value = 0
292294
resultErr = api.ErrDataNotAvailable
293295

@@ -301,7 +303,7 @@ func (e *LPP) ContractualProductionNominalMax() (value float64, resultErr error)
301303
ElectricalConnectionId: util.Ptr(model.ElectricalConnectionIdType(0)),
302304
ParameterId: util.Ptr(model.ElectricalConnectionParameterIdType(0)),
303305
CharacteristicContext: util.Ptr(model.ElectricalConnectionCharacteristicContextTypeEntity),
304-
CharacteristicType: util.Ptr(model.ElectricalConnectionCharacteristicTypeTypeContractualProductionNominalMax),
306+
CharacteristicType: util.Ptr(e.characteristicType()),
305307
}
306308
charData, err := ec.GetCharacteristicsForFilter(filter)
307309
if err != nil || len(charData) == 0 ||
@@ -313,9 +315,14 @@ func (e *LPP) ContractualProductionNominalMax() (value float64, resultErr error)
313315
return charData[0].Value.GetValue(), nil
314316
}
315317

316-
// set nominal maximum active (real) power the Controllable System is
317-
// allowed to produce due to the customer's contract.
318-
func (e *LPP) SetContractualProductionNominalMax(value float64) error {
318+
// set nominal maximum active (real) power the Controllable System is allowed to produce.
319+
//
320+
// If the local device type is an EnergyManagementSystem, the contractual production
321+
// nominal max is set, otherwise the power production nominal max is set.
322+
//
323+
// parameters:
324+
// - value: nominal max power production in W
325+
func (e *LPP) SetProductionNominalMax(value float64) error {
319326
ec, err := server.NewElectricalConnection(e.LocalEntity)
320327
if err != nil {
321328
return err
@@ -327,7 +334,7 @@ func (e *LPP) SetContractualProductionNominalMax(value float64) error {
327334
ElectricalConnectionId: electricalConnectionid,
328335
ParameterId: parameterId,
329336
CharacteristicContext: util.Ptr(model.ElectricalConnectionCharacteristicContextTypeEntity),
330-
CharacteristicType: util.Ptr(model.ElectricalConnectionCharacteristicTypeTypeContractualProductionNominalMax),
337+
CharacteristicType: util.Ptr(e.characteristicType()),
331338
})
332339
if err != nil || len(charList) == 0 {
333340
return api.ErrDataNotAvailable
@@ -341,3 +348,18 @@ func (e *LPP) SetContractualProductionNominalMax(value float64) error {
341348
}
342349
return ec.UpdateCharacteristic(data, nil)
343350
}
351+
352+
// returns the characteristictype depending on the local entities device devicetype
353+
func (e *LPP) characteristicType() model.ElectricalConnectionCharacteristicTypeType {
354+
deviceType := e.LocalEntity.Device().DeviceType()
355+
356+
// According to LPP V1.0 2.2, lines 420ff:
357+
// - a HEMS provides contractual production nominal max
358+
// - any other devices provides power production nominal max
359+
characteristic := model.ElectricalConnectionCharacteristicTypeTypePowerProductionNominalMax
360+
if deviceType == nil || *deviceType == model.DeviceTypeTypeEnergyManagementSystem {
361+
characteristic = model.ElectricalConnectionCharacteristicTypeTypeContractualProductionNominalMax
362+
}
363+
364+
return characteristic
365+
}

usecases/cs/lpp/public_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -152,14 +152,14 @@ func (s *CsLPPSuite) Test_IsHeartbeatWithinDuration() {
152152
}
153153

154154
func (s *CsLPPSuite) Test_ContractualProductionNominalMax() {
155-
value, err := s.sut.ContractualProductionNominalMax()
155+
value, err := s.sut.ProductionNominalMax()
156156
assert.Equal(s.T(), 0.0, value)
157157
assert.NotNil(s.T(), err)
158158

159-
err = s.sut.SetContractualProductionNominalMax(10)
159+
err = s.sut.SetProductionNominalMax(10)
160160
assert.Nil(s.T(), err)
161161

162-
value, err = s.sut.ContractualProductionNominalMax()
162+
value, err = s.sut.ProductionNominalMax()
163163
assert.Equal(s.T(), 10.0, value)
164164
assert.Nil(s.T(), err)
165165
}

usecases/cs/lpp/usecase.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ func (e *LPP) AddFeatures() {
245245
ElectricalConnectionId: util.Ptr(model.ElectricalConnectionIdType(0)),
246246
ParameterId: util.Ptr(model.ElectricalConnectionParameterIdType(0)),
247247
CharacteristicContext: util.Ptr(model.ElectricalConnectionCharacteristicContextTypeEntity),
248-
CharacteristicType: util.Ptr(model.ElectricalConnectionCharacteristicTypeTypeContractualProductionNominalMax),
248+
CharacteristicType: util.Ptr(e.characteristicType()),
249249
Unit: util.Ptr(model.UnitOfMeasurementTypeW),
250250
}
251251
_, _ = ec.AddCharacteristic(newCharData)

usecases/mocks/CsLPCInterface.go

Lines changed: 22 additions & 22 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)