Skip to content

Commit 09682b9

Browse files
LucaRoth-EnQSsthelen-enqs
authored andcommitted
Add config's full description to the PendingDeviceConfiguration return
This allows to more easily check for what a new value is trying to be set and what kind of value is being set (i.e. a duration, a bool, string etc.)
1 parent bde7de7 commit 09682b9

File tree

6 files changed

+56
-47
lines changed

6 files changed

+56
-47
lines changed

examples/hems/main.go

Lines changed: 6 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import (
1414
"time"
1515

1616
"github.com/enbility/eebus-go/api"
17-
"github.com/enbility/eebus-go/features/server"
1817
"github.com/enbility/eebus-go/service"
1918
ucapi "github.com/enbility/eebus-go/usecases/api"
2019
"github.com/enbility/eebus-go/usecases/cem/vabd"
@@ -94,7 +93,7 @@ func (h *hems) run() {
9493
configuration.SetAlternateIdentifier("Demo-HEMS-123456789")
9594

9695
h.myService = service.NewService(configuration, h)
97-
h.myService.SetLogging(h)
96+
//h.myService.SetLogging(h)
9897

9998
if err = h.myService.Setup(); err != nil {
10099
fmt.Println(err)
@@ -161,22 +160,9 @@ func (h *hems) OnLPCEvent(ski string, device spineapi.DeviceRemoteInterface, ent
161160
h.uccslpc.ApproveOrDenyConsumptionLimit(msgCounter, true, "")
162161
}
163162
for msgCounter, configs := range pendingDeviceConfigWrites {
164-
localEntity := h.myService.LocalDevice().EntityForType(model.EntityTypeTypeCEM)
165-
dc, err := server.NewDeviceConfiguration(localEntity)
166-
if err != nil {
167-
fmt.Println("Not approving LPC device configuration writes because of error:")
168-
fmt.Println(err)
169-
return
170-
}
171-
fmt.Printf("Approving LPC device config write with msgCounter %d ", msgCounter)
163+
fmt.Printf("Approving LPC device config write with msgCounter %d for features: ", msgCounter)
172164
for _, config := range(configs) {
173-
description, err := dc.GetKeyValueDescriptionFoKeyId(*config.KeyId)
174-
if description == nil || err != nil {
175-
fmt.Printf("LPC approving device configuation writes: no device configuration for KeyID %d found\n", *config.KeyId)
176-
continue
177-
}
178-
179-
fmt.Printf("including %s ", *description.KeyName)
165+
fmt.Printf("%s ", *config.Description.KeyName)
180166
}
181167
fmt.Print("\n")
182168
h.uccslpc.ApproveOrDenyDeviceConfiguration(msgCounter, true, "")
@@ -203,25 +189,12 @@ func (h *hems) OnLPPEvent(ski string, device spineapi.DeviceRemoteInterface, ent
203189
h.uccslpp.ApproveOrDenyProductionLimit(msgCounter, true, "")
204190
}
205191
for msgCounter, configs := range pendingDeviceConfigWrites {
206-
localEntity := h.myService.LocalDevice().EntityForType(model.EntityTypeTypeCEM)
207-
dc, err := server.NewDeviceConfiguration(localEntity)
208-
if err != nil {
209-
fmt.Println("Not approving LPC device configuration writes because of error:")
210-
fmt.Println(err)
211-
return
212-
}
213-
214-
fmt.Printf("Approving LPP device config write with msgCounter %d ", msgCounter)
192+
fmt.Printf("Approving LPP device config write with msgCounter %d for features: ", msgCounter)
215193
for _, config := range(configs) {
216-
description, err := dc.GetKeyValueDescriptionFoKeyId(*config.KeyId)
217-
if description == nil || err != nil {
218-
fmt.Printf("LPP approving device configuation writes: no device configuration for KeyID %d found\n", *config.KeyId)
219-
continue
220-
}
221-
fmt.Printf("including %s ", *description.KeyName)
194+
fmt.Printf("%s ", *config.Description.KeyName)
222195
}
223196
fmt.Print("\n")
224-
h.uccslpc.ApproveOrDenyDeviceConfiguration(msgCounter, true, "")
197+
h.uccslpp.ApproveOrDenyDeviceConfiguration(msgCounter, true, "")
225198
}
226199
case cslpp.DataUpdateLimit:
227200
if currentLimit, err := h.uccslpp.ProductionLimit(); err != nil {

usecases/api/cs_lpc.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ type CsLPCInterface interface {
7373
SetFailsafeDurationMinimum(duration time.Duration, changeable bool) (resultErr error)
7474

7575
// return the currently pending incoming device configuration writes
76-
PendingDeviceConfigurations() map[model.MsgCounterType][]model.DeviceConfigurationKeyValueDataType
76+
PendingDeviceConfigurations() map[model.MsgCounterType][]PendingDeviceConfiguration
7777

7878
// accept or deny an incoming device configuration writes
7979
//

usecases/api/cs_lpp.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ type CsLPPInterface interface {
7373
SetFailsafeDurationMinimum(duration time.Duration, changeable bool) (resultErr error)
7474

7575
// return the currently pending incoming device configuration writes
76-
PendingDeviceConfigurations() map[model.MsgCounterType][]model.DeviceConfigurationKeyValueDataType
76+
PendingDeviceConfigurations() map[model.MsgCounterType][]PendingDeviceConfiguration
7777

7878
// accept or deny an incoming device configuration writes
7979
//

usecases/api/types.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,4 +165,10 @@ type IncentiveTariffDescription struct {
165165
type DurationSlotValue struct {
166166
Duration time.Duration // Duration of this slot
167167
Value float64 // Energy Cost or Power Limit
168+
}
169+
170+
type PendingDeviceConfiguration struct {
171+
Description *model.DeviceConfigurationKeyValueDescriptionDataType `json:"description,omitempty"`
172+
Value *model.DeviceConfigurationKeyValueValueType `json:"value,omitempty"`
173+
IsValueChangeable *bool `json:"isValueChangeable,omitempty" eebus:"writecheck"`
168174
}

usecases/cs/lpc/public.go

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -267,23 +267,38 @@ func (e *LPC) SetFailsafeDurationMinimum(duration time.Duration, changeable bool
267267
}
268268

269269
// return the currently pending incoming failsafe consumption limit writes
270-
func (e *LPC) PendingDeviceConfigurations() map[model.MsgCounterType][]model.DeviceConfigurationKeyValueDataType {
271-
result := make(map[model.MsgCounterType][]model.DeviceConfigurationKeyValueDataType)
270+
func (e *LPC) PendingDeviceConfigurations() map[model.MsgCounterType][]ucapi.PendingDeviceConfiguration {
271+
result := make(map[model.MsgCounterType][]ucapi.PendingDeviceConfiguration)
272272

273273
e.pendingDeviceConfigMux.Lock()
274274
defer e.pendingDeviceConfigMux.Unlock()
275275

276+
dc, err := server.NewDeviceConfiguration(e.LocalEntity)
277+
if err != nil {
278+
return result
279+
}
280+
276281
for msgCounter, msg := range e.pendingDeviceConfigs {
277282
data := msg.Cmd.DeviceConfigurationKeyValueListData
278283
for _, configKeyValueData := range data.DeviceConfigurationKeyValueData {
279-
if _, exists := result[msgCounter]; exists {
280-
result[msgCounter] = append(result[msgCounter], configKeyValueData)
284+
description, err := dc.GetKeyValueDescriptionFoKeyId(*configKeyValueData.KeyId)
285+
if err != nil {
286+
continue
287+
}
288+
289+
pendingConfigData := ucapi.PendingDeviceConfiguration{
290+
Description: description,
291+
Value: configKeyValueData.Value,
292+
IsValueChangeable: configKeyValueData.IsValueChangeable,
293+
}
294+
295+
if _, exists := result[msgCounter]; !exists {
296+
result[msgCounter] = []ucapi.PendingDeviceConfiguration{pendingConfigData}
281297
} else {
282-
result[msgCounter] = []model.DeviceConfigurationKeyValueDataType{configKeyValueData}
298+
result[msgCounter] = append(result[msgCounter], pendingConfigData)
283299
}
284300
}
285301
}
286-
287302
return result
288303
}
289304

usecases/cs/lpp/public.go

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -268,23 +268,38 @@ func (e *LPP) SetFailsafeDurationMinimum(duration time.Duration, changeable bool
268268
}
269269

270270
// return the currently pending incoming failsafe consumption limit writes
271-
func (e *LPP) PendingDeviceConfigurations() map[model.MsgCounterType][]model.DeviceConfigurationKeyValueDataType {
272-
result := make(map[model.MsgCounterType][]model.DeviceConfigurationKeyValueDataType)
271+
func (e *LPP) PendingDeviceConfigurations() map[model.MsgCounterType][]ucapi.PendingDeviceConfiguration {
272+
result := make(map[model.MsgCounterType][]ucapi.PendingDeviceConfiguration)
273273

274274
e.pendingDeviceConfigMux.Lock()
275275
defer e.pendingDeviceConfigMux.Unlock()
276276

277+
dc, err := server.NewDeviceConfiguration(e.LocalEntity)
278+
if err != nil {
279+
return result
280+
}
281+
277282
for msgCounter, msg := range e.pendingDeviceConfigs {
278283
data := msg.Cmd.DeviceConfigurationKeyValueListData
279284
for _, configKeyValueData := range data.DeviceConfigurationKeyValueData {
280-
if _, exists := result[msgCounter]; exists {
281-
result[msgCounter] = append(result[msgCounter], configKeyValueData)
285+
description, err := dc.GetKeyValueDescriptionFoKeyId(*configKeyValueData.KeyId)
286+
if err != nil {
287+
continue
288+
}
289+
290+
pendingConfigData := ucapi.PendingDeviceConfiguration{
291+
Description: description,
292+
Value: configKeyValueData.Value,
293+
IsValueChangeable: configKeyValueData.IsValueChangeable,
294+
}
295+
296+
if _, exists := result[msgCounter]; !exists {
297+
result[msgCounter] = []ucapi.PendingDeviceConfiguration{pendingConfigData}
282298
} else {
283-
result[msgCounter] = []model.DeviceConfigurationKeyValueDataType{configKeyValueData}
299+
result[msgCounter] = append(result[msgCounter], pendingConfigData)
284300
}
285301
}
286302
}
287-
288303
return result
289304
}
290305

0 commit comments

Comments
 (0)