Skip to content

Commit

Permalink
Improve UseCase handling
Browse files Browse the repository at this point in the history
- Add support for checking if a usecase is set
- Fix removing all usecases for an entity
  • Loading branch information
DerAndereAndi committed Jan 24, 2024
1 parent 8c2ebf6 commit 7df066d
Show file tree
Hide file tree
Showing 6 changed files with 181 additions and 1 deletion.
3 changes: 3 additions & 0 deletions api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@ type EntityLocalInterface interface {
useCaseAvailable bool,
scenarios []model.UseCaseScenarioSupportType,
)
HasUseCaseSupport(
actor model.UseCaseActorType,
useCaseName model.UseCaseNameType) bool
RemoveUseCaseSupport(
actor model.UseCaseActorType,
useCaseName model.UseCaseNameType,
Expand Down
47 changes: 47 additions & 0 deletions mocks/EntityLocalInterface.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 29 additions & 0 deletions model/nodemanagement_additions.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,18 @@ func (n *NodeManagementUseCaseDataType) AddUseCaseSupport(
}
}

func (n *NodeManagementUseCaseDataType) HasUseCaseSupport(
address FeatureAddressType,
actor UseCaseActorType,
useCaseName UseCaseNameType) bool {
nmMux.Lock()
defer nmMux.Unlock()

// is there an entry for the entity address, actor and usecase name
_, ok := n.useCaseInformationIndex(address, actor, useCaseName)
return ok
}

// Remove a UseCaseSupportType with
// a provided FeatureAddressType, UseCaseActorType and UseCaseNameType
func (n *NodeManagementUseCaseDataType) RemoveUseCaseSupport(
Expand Down Expand Up @@ -141,3 +153,20 @@ func (n *NodeManagementUseCaseDataType) RemoveUseCaseSupport(

n.UseCaseInformation = usecaseInfo
}

// Remove all data for a given address type
func (n *NodeManagementUseCaseDataType) RemoveUseCaseDataForAddress(address FeatureAddressType) {
nmMux.Lock()
defer nmMux.Unlock()

var usecaseInfo []UseCaseInformationDataType

for _, item := range n.UseCaseInformation {
if !reflect.DeepEqual(item.Address, &address) {
usecaseInfo = append(usecaseInfo, item)
continue
}
}

n.UseCaseInformation = usecaseInfo
}
20 changes: 20 additions & 0 deletions model/nodemanagement_additions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ func (s *NodeManagementUseCaseDataTypeSuite) Test_AdditionsAndRemovals() {
assert.Equal(s.T(), 2, len(ucs.UseCaseInformation[0].UseCaseSupport))
assert.Equal(s.T(), 1, len(ucs.UseCaseInformation[1].UseCaseSupport))

hasUC := ucs.HasUseCaseSupport(address, UseCaseActorTypeCEM, UseCaseNameTypeEVChargingSummary)
assert.Equal(s.T(), false, hasUC)

ucs.RemoveUseCaseSupport(
address,
UseCaseActorTypeCEM,
Expand All @@ -87,6 +90,9 @@ func (s *NodeManagementUseCaseDataTypeSuite) Test_AdditionsAndRemovals() {
assert.Equal(s.T(), 2, len(ucs.UseCaseInformation))
assert.Equal(s.T(), 2, len(ucs.UseCaseInformation[0].UseCaseSupport))

hasUC = ucs.HasUseCaseSupport(address, UseCaseActorTypeCEM, UseCaseNameTypeControlOfBattery)
assert.Equal(s.T(), true, hasUC)

ucs.RemoveUseCaseSupport(
address,
UseCaseActorTypeCEM,
Expand Down Expand Up @@ -120,4 +126,18 @@ func (s *NodeManagementUseCaseDataTypeSuite) Test_AdditionsAndRemovals() {
)
assert.Equal(s.T(), 1, len(ucs.UseCaseInformation))

ucs.AddUseCaseSupport(
address,
UseCaseActorTypeEnergyGuard,
UseCaseNameTypeLimitationOfPowerConsumption,
SpecificationVersionType(""),
"",
true,
[]UseCaseScenarioSupportType{},
)
assert.Equal(s.T(), 1, len(ucs.UseCaseInformation))
assert.Equal(s.T(), 1, len(ucs.UseCaseInformation[0].UseCaseSupport))

ucs.RemoveUseCaseDataForAddress(address)
assert.Equal(s.T(), 0, len(ucs.UseCaseInformation))
}
32 changes: 31 additions & 1 deletion spine/entity_local.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,22 @@ func (r *EntityLocal) AddUseCaseSupport(
nodeMgmt.SetData(model.FunctionTypeNodeManagementUseCaseData, data)
}

func (r *EntityLocal) HasUseCaseSupport(actor model.UseCaseActorType, useCaseName model.UseCaseNameType) bool {
nodeMgmt := r.device.NodeManagement()

data := nodeMgmt.DataCopy(model.FunctionTypeNodeManagementUseCaseData).(*model.NodeManagementUseCaseDataType)
if data == nil {
return false
}

address := model.FeatureAddressType{
Device: r.address.Device,
Entity: r.address.Entity,
}

return data.HasUseCaseSupport(address, actor, useCaseName)
}

// Remove a usecase with a given actor ans usecase name
func (r *EntityLocal) RemoveUseCaseSupport(
actor model.UseCaseActorType,
Expand All @@ -147,7 +163,21 @@ func (r *EntityLocal) RemoveUseCaseSupport(

// Remove all usecases
func (r *EntityLocal) RemoveAllUseCaseSupports() {
r.RemoveUseCaseSupport("", "")
nodeMgmt := r.device.NodeManagement()

data := nodeMgmt.DataCopy(model.FunctionTypeNodeManagementUseCaseData).(*model.NodeManagementUseCaseDataType)
if data == nil {
return
}

address := model.FeatureAddressType{
Device: r.address.Device,
Entity: r.address.Entity,
}

data.RemoveUseCaseDataForAddress(address)

nodeMgmt.SetData(model.FunctionTypeNodeManagementUseCaseData, data)
}

// Remove all subscriptions
Expand Down
51 changes: 51 additions & 0 deletions spine/entity_local_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@ func (suite *EntityLocalTestSuite) Test_Entity() {

entity.RemoveAllUseCaseSupports()

hasUC := entity.HasUseCaseSupport(
model.UseCaseActorTypeCEM,
model.UseCaseNameTypeEVSECommissioningAndConfiguration,
)
assert.Equal(suite.T(), false, hasUC)

entity.AddUseCaseSupport(
model.UseCaseActorTypeCEM,
model.UseCaseNameTypeEVSECommissioningAndConfiguration,
Expand All @@ -65,6 +71,38 @@ func (suite *EntityLocalTestSuite) Test_Entity() {
[]model.UseCaseScenarioSupportType{1, 2},
)

hasUC = entity.HasUseCaseSupport(
model.UseCaseActorTypeCEM,
model.UseCaseNameTypeEVSECommissioningAndConfiguration,
)
assert.Equal(suite.T(), true, hasUC)

entity.AddUseCaseSupport(
model.UseCaseActorTypeCEM,
model.UseCaseNameTypeEVSECommissioningAndConfiguration,
model.SpecificationVersionType("1.0.0"),
"",
true,
[]model.UseCaseScenarioSupportType{1, 2},
)

hasUC = entity.HasUseCaseSupport(
model.UseCaseActorTypeCEM,
model.UseCaseNameTypeEVSECommissioningAndConfiguration,
)
assert.Equal(suite.T(), true, hasUC)

entity.RemoveUseCaseSupport(
model.UseCaseActorTypeCEM,
model.UseCaseNameTypeEVSECommissioningAndConfiguration,
)

hasUC = entity.HasUseCaseSupport(
model.UseCaseActorTypeCEM,
model.UseCaseNameTypeEVSECommissioningAndConfiguration,
)
assert.Equal(suite.T(), false, hasUC)

entity.AddUseCaseSupport(
model.UseCaseActorTypeCEM,
model.UseCaseNameTypeEVSECommissioningAndConfiguration,
Expand All @@ -74,7 +112,20 @@ func (suite *EntityLocalTestSuite) Test_Entity() {
[]model.UseCaseScenarioSupportType{1, 2},
)

hasUC = entity.HasUseCaseSupport(
model.UseCaseActorTypeCEM,
model.UseCaseNameTypeEVSECommissioningAndConfiguration,
)
assert.Equal(suite.T(), true, hasUC)

entity.RemoveAllUseCaseSupports()

hasUC = entity.HasUseCaseSupport(
model.UseCaseActorTypeCEM,
model.UseCaseNameTypeEVSECommissioningAndConfiguration,
)
assert.Equal(suite.T(), false, hasUC)

entity.RemoveAllBindings()
entity.RemoveAllSubscriptions()
}

0 comments on commit 7df066d

Please sign in to comment.