Skip to content

Commit

Permalink
Add and use allEntityTypesValid boolean instead of nil validEntityTypes
Browse files Browse the repository at this point in the history
This modifies the logic for entity selection when all entity types
should be valid to using an allEntityTypesValid boolean stored in the
UseCaseBase instead of checking for validEntityTypes == nil.
  • Loading branch information
sthelen-enqs committed Aug 29, 2024
1 parent 83d3c15 commit 47947ab
Show file tree
Hide file tree
Showing 19 changed files with 39 additions and 12 deletions.
1 change: 1 addition & 0 deletions usecases/cem/cevc/usecase.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ func NewCEVC(localEntity spineapi.EntityLocalInterface, eventCB api.EntityEventC
UseCaseSupportUpdate,
validActorTypes,
validEntityTypes,
false,
)

uc := &CEVC{
Expand Down
1 change: 1 addition & 0 deletions usecases/cem/evcc/usecase.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ func NewEVCC(
UseCaseSupportUpdate,
validActorTypes,
validEntityTypes,
false,
)

uc := &EVCC{
Expand Down
4 changes: 3 additions & 1 deletion usecases/cem/evcem/usecase.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ func NewEVCEM(service api.ServiceInterface, localEntity spineapi.EntityLocalInte
eventCB,
UseCaseSupportUpdate,
validActorTypes,
validEntityTypes)
validEntityTypes,
false,
)

uc := &EVCEM{
UseCaseBase: usecase,
Expand Down
4 changes: 3 additions & 1 deletion usecases/cem/evsecc/usecase.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ func NewEVSECC(localEntity spineapi.EntityLocalInterface, eventCB api.EntityEven
eventCB,
UseCaseSupportUpdate,
validActorTypes,
validEntityTypes)
validEntityTypes,
false,
)

uc := &EVSECC{
UseCaseBase: usecase,
Expand Down
1 change: 1 addition & 0 deletions usecases/cem/evsoc/usecase.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ func NewEVSOC(localEntity spineapi.EntityLocalInterface, eventCB api.EntityEvent
UseCaseSupportUpdate,
validActorTypes,
validEntityTypes,
false,
)

uc := &EVSOC{
Expand Down
1 change: 1 addition & 0 deletions usecases/cem/opev/usecase.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ func NewOPEV(localEntity spineapi.EntityLocalInterface, eventCB api.EntityEventC
UseCaseSupportUpdate,
validActorTypes,
validEntityTypes,
false,
)

uc := &OPEV{
Expand Down
1 change: 1 addition & 0 deletions usecases/cem/oscev/usecase.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ func NewOSCEV(localEntity spineapi.EntityLocalInterface, eventCB api.EntityEvent
UseCaseSupportUpdate,
validActorTypes,
validEntityTypes,
false,
)

uc := &OSCEV{
Expand Down
1 change: 1 addition & 0 deletions usecases/cem/vabd/usecase.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ func NewVABD(localEntity spineapi.EntityLocalInterface, eventCB api.EntityEventC
UseCaseSupportUpdate,
validActorTypes,
validEntityTypes,
false,
)

uc := &VABD{
Expand Down
1 change: 1 addition & 0 deletions usecases/cem/vapd/usecase.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ func NewVAPD(localEntity spineapi.EntityLocalInterface, eventCB api.EntityEventC
UseCaseSupportUpdate,
validActorTypes,
validEntityTypes,
false,
)

uc := &VAPD{
Expand Down
1 change: 1 addition & 0 deletions usecases/cs/lpc/usecase.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ func NewLPC(localEntity spineapi.EntityLocalInterface, eventCB api.EntityEventCa
UseCaseSupportUpdate,
validActorTypes,
validEntityTypes,
false,
)

uc := &LPC{
Expand Down
1 change: 1 addition & 0 deletions usecases/cs/lpp/usecase.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ func NewLPP(localEntity spineapi.EntityLocalInterface, eventCB api.EntityEventCa
UseCaseSupportUpdate,
validActorTypes,
validEntityTypes,
false,
)

uc := &LPP{
Expand Down
1 change: 1 addition & 0 deletions usecases/eg/lpc/usecase.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ func NewLPC(localEntity spineapi.EntityLocalInterface, eventCB api.EntityEventCa
UseCaseSupportUpdate,
validActorTypes,
validEntityTypes,
false,
)

uc := &LPC{
Expand Down
4 changes: 3 additions & 1 deletion usecases/eg/lpp/usecase.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ func NewLPP(localEntity spineapi.EntityLocalInterface, eventCB api.EntityEventCa
eventCB,
UseCaseSupportUpdate,
validActorTypes,
validEntityTypes)
validEntityTypes,
false,
)

uc := &LPP{
UseCaseBase: usecase,
Expand Down
4 changes: 3 additions & 1 deletion usecases/ma/mgcp/usecase.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,9 @@ func NewMGCP(localEntity spineapi.EntityLocalInterface, eventCB api.EntityEventC
eventCB,
UseCaseSupportUpdate,
validActorTypes,
validEntityTypes)
validEntityTypes,
false,
)

uc := &MGCP{
UseCaseBase: usecase,
Expand Down
4 changes: 3 additions & 1 deletion usecases/ma/mpc/usecase.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,9 @@ func NewMPC(localEntity spineapi.EntityLocalInterface, eventCB api.EntityEventCa
eventCB,
UseCaseSupportUpdate,
validActorTypes,
validEntityTypes)
validEntityTypes,
false,
)

uc := &MPC{
UseCaseBase: usecase,
Expand Down
9 changes: 6 additions & 3 deletions usecases/mu/mpc/usecase.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package mpc

import (
"time"

"github.com/enbility/eebus-go/api"
"github.com/enbility/eebus-go/features/server"
ucapi "github.com/enbility/eebus-go/usecases/api"
Expand All @@ -9,7 +11,6 @@ import (
"github.com/enbility/spine-go/model"
"github.com/enbility/spine-go/spine"
"github.com/enbility/spine-go/util"
"time"
)

type MPC struct {
Expand All @@ -29,7 +30,7 @@ var _ ucapi.MuMPCInterface = (*MPC)(nil)
// At the moment the MPC use case configures itself as a 3-phase meter by default (ABC).
func NewMPC(localEntity spineapi.EntityLocalInterface, eventCB api.EntityEventCallback) *MPC {
validActorTypes := []model.UseCaseActorType{model.UseCaseActorTypeMonitoringAppliance}
var validEntityTypes []model.EntityTypeType = nil // all entity types are valid
allEntityTypesValid := true
useCaseScenarios := []api.UseCaseScenario{
{
Scenario: model.UseCaseScenarioSupportType(1),
Expand Down Expand Up @@ -83,7 +84,9 @@ func NewMPC(localEntity spineapi.EntityLocalInterface, eventCB api.EntityEventCa
eventCB,
UseCaseSupportUpdate,
validActorTypes,
validEntityTypes)
nil,
allEntityTypesValid,
)

uc := &MPC{
UseCaseBase: u,
Expand Down
2 changes: 1 addition & 1 deletion usecases/usecase/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func (u *UseCaseBase) useCaseDataUpdate(
}

for _, entity := range entitiesToCheck {
if u.validEntityTypes != nil && !slices.Contains(u.validEntityTypes, entity.EntityType()) {
if !u.allEntityTypesValid && !slices.Contains(u.validEntityTypes, entity.EntityType()) {
continue
}

Expand Down
1 change: 1 addition & 0 deletions usecases/usecase/testhelper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ func (s *UseCaseSuite) BeforeTest(suiteName, testName string) {
useCaseUpdateEvent,
validActorTypes,
validEntityTypes,
false,
)
}

Expand Down
9 changes: 6 additions & 3 deletions usecases/usecase/usecase.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ type UseCaseBase struct {

availableEntityScenarios []api.RemoteEntityScenarios // map of scenarios and their availability for each compatible remote entity

validActorTypes []model.UseCaseActorType // valid remote actor types for this use case
validEntityTypes []model.EntityTypeType // valid remote entity types for this use case (if nil all are valid)
validActorTypes []model.UseCaseActorType // valid remote actor types for this use case
validEntityTypes []model.EntityTypeType // valid remote entity types for this use case
allEntityTypesValid bool

mux sync.Mutex
}
Expand All @@ -44,6 +45,7 @@ func NewUseCaseBase(
useCaseUpdateEvent api.EventType,
validActorTypes []model.UseCaseActorType,
validEntityTypes []model.EntityTypeType,
allEntityTypesValid bool,
) *UseCaseBase {
ucb := &UseCaseBase{
LocalEntity: localEntity,
Expand All @@ -56,6 +58,7 @@ func NewUseCaseBase(
useCaseUpdateEvent: useCaseUpdateEvent,
validActorTypes: validActorTypes,
validEntityTypes: validEntityTypes,
allEntityTypesValid: allEntityTypesValid,
}

_ = spine.Events.Subscribe(ucb)
Expand Down Expand Up @@ -91,7 +94,7 @@ func (u *UseCaseBase) IsCompatibleEntityType(entity spineapi.EntityRemoteInterfa
return false
}

if u.validEntityTypes == nil {
if u.allEntityTypesValid {
return true
}

Expand Down

0 comments on commit 47947ab

Please sign in to comment.