Skip to content
This repository has been archived by the owner on Jun 29, 2024. It is now read-only.

Commit

Permalink
Merge branch 'release/v0.2.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
DerAndereAndi committed Apr 25, 2023
2 parents bc63a7e + c87faf4 commit 0a984bb
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 64 deletions.
5 changes: 4 additions & 1 deletion emobility/emobility.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,10 @@ type EmobilityDataProvider interface {

// used by the CEM and implemented by emobility
type EmobilityI interface {
// return the current charge sate of the EV
// return if an EV is connected
EVConnected() bool

// return the current charge state of the EV
EVCurrentChargeState() (EVChargeStateType, error)

// return the number of ac connected phases of the EV or 0 if it is unknown
Expand Down
14 changes: 14 additions & 0 deletions emobility/mock_emobility.go

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

115 changes: 55 additions & 60 deletions emobility/public.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,49 @@ import (
eebusUtil "github.com/enbility/eebus-go/util"
)

// return the current charge sate of the EV
func (e *EMobilityImpl) EVCurrentChargeState() (EVChargeStateType, error) {
if e.evEntity == nil {
return EVChargeStateTypeUnplugged, nil
// return if an EV is connected
//
// this includes all required features and
// minimal data being available
func (e *EMobilityImpl) EVConnected() bool {
// To report an EV as being connected, also consider all required
// features to be available and assigned
if e.evEntity == nil ||
e.evDeviceDiagnosis == nil ||
e.evElectricalConnection == nil ||
e.evMeasurement == nil ||
e.evLoadControl == nil ||
e.evDeviceConfiguration == nil {
return false
}

if e.evDeviceDiagnosis == nil {
return EVChargeStateTypeUnknown, features.ErrDataNotAvailable
// getting current charge state should work
if _, err := e.EVCurrentChargeState(); err != nil {
return false
}

// the communication standard needs to be available
if _, err := e.EVCommunicationStandard(); err != nil {
return false
}

// getting currents measurements should work
if _, err := e.EVCurrentsPerPhase(); err != nil {
return false
}

// getting limits should work
if _, err := e.EVLoadControlObligationLimits(); err != nil {
return false
}

return true
}

// return the current charge state of the EV
func (e *EMobilityImpl) EVCurrentChargeState() (EVChargeStateType, error) {
if e.evEntity == nil || e.evDeviceDiagnosis == nil {
return EVChargeStateTypeUnplugged, nil
}

diagnosisState, err := e.evDeviceDiagnosis.GetState()
Expand Down Expand Up @@ -46,14 +81,10 @@ func (e *EMobilityImpl) EVCurrentChargeState() (EVChargeStateType, error) {

// return the number of ac connected phases of the EV or 0 if it is unknown
func (e *EMobilityImpl) EVConnectedPhases() (uint, error) {
if e.evEntity == nil {
if e.evEntity == nil || e.evElectricalConnection == nil {
return 0, ErrEVDisconnected
}

if e.evElectricalConnection == nil {
return 0, features.ErrDataNotAvailable
}

data, err := e.evElectricalConnection.GetDescriptions()
if err != nil {
return 0, features.ErrDataNotAvailable
Expand All @@ -79,14 +110,10 @@ func (e *EMobilityImpl) EVConnectedPhases() (uint, error) {
// - ErrDataNotAvailable if no such measurement is (yet) available
// - and others
func (e *EMobilityImpl) EVChargedEnergy() (float64, error) {
if e.evEntity == nil {
if e.evEntity == nil || e.evMeasurement == nil {
return 0, ErrEVDisconnected
}

if e.evMeasurement == nil {
return 0, features.ErrDataNotAvailable
}

measurement := model.MeasurementTypeTypeEnergy
commodity := model.CommodityTypeTypeElectricity
scope := model.ScopeTypeTypeCharge
Expand All @@ -110,14 +137,10 @@ func (e *EMobilityImpl) EVChargedEnergy() (float64, error) {
// - ErrDataNotAvailable if no such measurement is (yet) available
// - and others
func (e *EMobilityImpl) EVPowerPerPhase() ([]float64, error) {
if e.evEntity == nil {
if e.evEntity == nil || e.evMeasurement == nil {
return nil, ErrEVDisconnected
}

if e.evMeasurement == nil {
return nil, features.ErrDataNotAvailable
}

var data []model.MeasurementDataType

powerAvailable := true
Expand Down Expand Up @@ -168,14 +191,10 @@ func (e *EMobilityImpl) EVPowerPerPhase() ([]float64, error) {
// - ErrDataNotAvailable if no such measurement is (yet) available
// - and others
func (e *EMobilityImpl) EVCurrentsPerPhase() ([]float64, error) {
if e.evEntity == nil {
if e.evEntity == nil || e.evElectricalConnection == nil {
return nil, ErrEVDisconnected
}

if e.evMeasurement == nil {
return nil, features.ErrDataNotAvailable
}

measurement := model.MeasurementTypeTypeCurrent
commodity := model.CommodityTypeTypeElectricity
scope := model.ScopeTypeTypeACCurrent
Expand Down Expand Up @@ -211,14 +230,10 @@ func (e *EMobilityImpl) EVCurrentsPerPhase() ([]float64, error) {
// - ErrDataNotAvailable if no such measurement is (yet) available
// - and others
func (e *EMobilityImpl) EVCurrentLimits() ([]float64, []float64, []float64, error) {
if e.evEntity == nil {
if e.evEntity == nil || e.evElectricalConnection == nil {
return nil, nil, nil, ErrEVDisconnected
}

if e.evElectricalConnection == nil {
return nil, nil, nil, features.ErrDataNotAvailable
}

var resultMin, resultMax, resultDefault []float64

for _, phaseName := range util.PhaseNameMapping {
Expand Down Expand Up @@ -258,14 +273,10 @@ func (e *EMobilityImpl) EVCurrentLimits() ([]float64, []float64, []float64, erro
// - ErrDataNotAvailable if no such measurement is (yet) available
// - and others
func (e *EMobilityImpl) EVLoadControlObligationLimits() ([]float64, error) {
if e.evEntity == nil {
if e.evEntity == nil || e.evElectricalConnection == nil || e.evLoadControl == nil {
return nil, ErrEVDisconnected
}

if e.evElectricalConnection == nil || e.evLoadControl == nil {
return nil, features.ErrDataNotAvailable
}

// find out the appropriate limitId for each phase value
// limitDescription contains the measurementId for each limitId
limitDescriptions, err := e.evLoadControl.GetLimitDescriptionsForCategory(model.LoadControlCategoryTypeObligation)
Expand Down Expand Up @@ -430,14 +441,10 @@ func (e *EMobilityImpl) EVWriteLoadControlLimits(obligations, recommendations []
// - ErrNotSupported if getting the communication standard is not supported
// - and others
func (e *EMobilityImpl) EVCommunicationStandard() (EVCommunicationStandardType, error) {
if e.evEntity == nil {
if e.evEntity == nil || e.evDeviceConfiguration == nil {
return EVCommunicationStandardTypeUnknown, ErrEVDisconnected
}

if e.evDeviceConfiguration == nil {
return EVCommunicationStandardTypeUnknown, features.ErrDataNotAvailable
}

// check if device configuration descriptions has an communication standard key name
_, err := e.evDeviceConfiguration.GetDescriptionForKeyName(model.DeviceConfigurationKeyNameTypeCommunicationsStandard)
if err != nil {
Expand Down Expand Up @@ -493,14 +500,10 @@ func (e *EMobilityImpl) EVIdentification() (string, error) {
// - ErrDataNotAvailable if that information is not (yet) available
// - and others
func (e *EMobilityImpl) EVOptimizationOfSelfConsumptionSupported() (bool, error) {
if e.evEntity == nil {
if e.evEntity == nil || e.evLoadControl == nil {
return false, ErrEVDisconnected
}

if e.evLoadControl == nil {
return false, features.ErrDataNotAvailable
}

evEntity, err := util.EntityOfTypeForSki(e.service, model.EntityTypeTypeEV, e.ski)
if err != nil {
return false, err
Expand Down Expand Up @@ -529,14 +532,10 @@ func (e *EMobilityImpl) EVOptimizationOfSelfConsumptionSupported() (bool, error)
// - ErrDataNotAvailable if no such measurement is (yet) available
// - and others
func (e *EMobilityImpl) EVSoCSupported() (bool, error) {
if e.evEntity == nil {
if e.evEntity == nil || e.evMeasurement == nil {
return false, ErrEVDisconnected
}

if e.evMeasurement == nil {
return false, features.ErrDataNotAvailable
}

evEntity, err := util.EntityOfTypeForSki(e.service, model.EntityTypeTypeEV, e.ski)
if err != nil {
return false, err
Expand Down Expand Up @@ -570,14 +569,10 @@ func (e *EMobilityImpl) EVSoCSupported() (bool, error) {
// - ErrDataNotAvailable if no such measurement is (yet) available
// - and others
func (e *EMobilityImpl) EVSoC() (float64, error) {
if e.evEntity == nil {
if e.evEntity == nil || e.evMeasurement == nil {
return 0, ErrEVDisconnected
}

if e.evMeasurement == nil {
return 0, features.ErrDataNotAvailable
}

// check if the SoC is supported
support, err := e.EVSoCSupported()
if err != nil {
Expand Down Expand Up @@ -746,7 +741,7 @@ func (e *EMobilityImpl) EVEnergyDemand() (EVDemand, error) {
func (e *EMobilityImpl) EVGetPowerConstraints() EVTimeSlotConstraints {
result := EVTimeSlotConstraints{}

if e.evTimeSeries == nil {
if e.evEntity == nil || e.evTimeSeries == nil {
return result
}

Expand Down Expand Up @@ -785,7 +780,7 @@ func (e *EMobilityImpl) EVGetPowerConstraints() EVTimeSlotConstraints {

// send power limits to the EV
func (e *EMobilityImpl) EVWritePowerLimits(data []EVDurationSlotValue) error {
if e.evTimeSeries == nil {
if e.evEntity == nil || e.evTimeSeries == nil {
return ErrNotSupported
}

Expand Down Expand Up @@ -849,7 +844,7 @@ func (e *EMobilityImpl) EVWritePowerLimits(data []EVDurationSlotValue) error {
func (e *EMobilityImpl) EVGetIncentiveConstraints() EVIncentiveSlotConstraints {
result := EVIncentiveSlotConstraints{}

if e.evIncentiveTable == nil {
if e.evEntity == nil || e.evIncentiveTable == nil {
return result
}

Expand All @@ -873,7 +868,7 @@ func (e *EMobilityImpl) EVGetIncentiveConstraints() EVIncentiveSlotConstraints {

// send incentives to the EV
func (e *EMobilityImpl) EVWriteIncentives(data []EVDurationSlotValue) error {
if e.evIncentiveTable == nil {
if e.evEntity == nil || e.evIncentiveTable == nil {
return features.ErrDataNotAvailable
}

Expand Down
4 changes: 2 additions & 2 deletions emobility/public_EVCurrentChargeState_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ func Test_EVCurrentChargeState(t *testing.T) {
emobilty.evEntity = entites[1]

data, err = emobilty.EVCurrentChargeState()
assert.NotNil(t, err)
assert.Equal(t, EVChargeStateTypeUnknown, data)
assert.Nil(t, err)
assert.Equal(t, EVChargeStateTypeUnplugged, data)

emobilty.evDeviceDiagnosis = deviceDiagnosis(localDevice, emobilty.evEntity)

Expand Down
3 changes: 2 additions & 1 deletion emobility/scenario.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,9 @@ func (e *EmobilityScenarioImpl) AddUseCases() {
model.SpecificationVersionType("1.0.1b"),
[]model.UseCaseScenarioSupportType{1, 2, 3})

_ = spine.NewUseCase(
_ = spine.NewUseCaseWithActor(
localEntity,
model.UseCaseActorTypeMonitoringAppliance,
model.UseCaseNameTypeEVStateOfCharge,
model.SpecificationVersionType("1.0.0"),
[]model.UseCaseScenarioSupportType{1, 2, 3, 4})
Expand Down

0 comments on commit 0a984bb

Please sign in to comment.