Skip to content

Commit

Permalink
Fix LoadControl for 1 phase connected EVSE
Browse files Browse the repository at this point in the history
- If an EVSE is connected via 1 phase, `LoadControlLimits` should not add empty data for non existing phases, otherwise this will lead to invalid data for consumers. E.g. checking if any phase is active will always fail, as these are always returning false
- Add more tests for Audi Mobile Connect setup with 1 phase
- Add more tests for Elli Connect/Pro Gen 1 with 1 phase setup
  • Loading branch information
DerAndereAndi committed Sep 5, 2024
1 parent 8544b35 commit 2cd13fc
Show file tree
Hide file tree
Showing 4 changed files with 301 additions and 14 deletions.
122 changes: 118 additions & 4 deletions features/internal/electricalconnection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -549,25 +549,77 @@ func (s *ElectricalConnectionSuite) Test_GetLimitsForParameterId() {
assert.Equal(s.T(), defaultV, 0.1)
}

func (s *ElectricalConnectionSuite) Test_GetLimitsForParameterId_Elli_1Phase() {
filter := model.ElectricalConnectionPermittedValueSetDataType{
ParameterId: util.Ptr(model.ElectricalConnectionParameterIdType(0)),
}
minV, maxV, defaultV, err := s.localSut.GetPermittedValueDataForFilter(filter)
assert.NotNil(s.T(), err)
assert.Equal(s.T(), minV, 0.0)
assert.Equal(s.T(), maxV, 0.0)
assert.Equal(s.T(), defaultV, 0.0)
minV, maxV, defaultV, err = s.remoteSut.GetPermittedValueDataForFilter(filter)
assert.NotNil(s.T(), err)
assert.Equal(s.T(), minV, 0.0)
assert.Equal(s.T(), maxV, 0.0)
assert.Equal(s.T(), defaultV, 0.0)

s.addParamDescription_Elli_1Phase()
s.addPermittedValueSetEmptyElli()

minV, maxV, defaultV, err = s.localSut.GetPermittedValueDataForFilter(filter)
assert.Nil(s.T(), err)
assert.Equal(s.T(), minV, 0.0)
assert.Equal(s.T(), maxV, 0.0)
assert.Equal(s.T(), defaultV, 0.0)
minV, maxV, defaultV, err = s.remoteSut.GetPermittedValueDataForFilter(filter)
assert.Nil(s.T(), err)
assert.Equal(s.T(), minV, 0.0)
assert.Equal(s.T(), maxV, 0.0)
assert.Equal(s.T(), defaultV, 0.0)
}

func (s *ElectricalConnectionSuite) Test_AdjustValueToBeWithinPermittedValuesForParameter() {
parameterId := model.ElectricalConnectionParameterIdType(1)
s.addPermittedValueSet()
s.addParamDescriptionCurrents()

value := s.localSut.AdjustValueToBeWithinPermittedValuesForParameterId(20, parameterId)
assert.Equal(s.T(), value, 16.0)
assert.Equal(s.T(), 16.0, value)
value = s.remoteSut.AdjustValueToBeWithinPermittedValuesForParameterId(20, parameterId)
assert.Equal(s.T(), 16.0, value)

value = s.localSut.AdjustValueToBeWithinPermittedValuesForParameterId(2, parameterId)
assert.Equal(s.T(), 2.0, value)
value = s.remoteSut.AdjustValueToBeWithinPermittedValuesForParameterId(2, parameterId)
assert.Equal(s.T(), 2.0, value)

value = s.localSut.AdjustValueToBeWithinPermittedValuesForParameterId(1, parameterId)
assert.Equal(s.T(), 0.1, value)
value = s.remoteSut.AdjustValueToBeWithinPermittedValuesForParameterId(1, parameterId)
assert.Equal(s.T(), 0.1, value)
}

func (s *ElectricalConnectionSuite) Test_AdjustValueToBeWithinPermittedValuesForParameter_Elli_1Phase() {
parameterId := model.ElectricalConnectionParameterIdType(1)

s.addPermittedValueSetEmptyElli()
s.addParamDescription_Elli_1Phase()

value := s.localSut.AdjustValueToBeWithinPermittedValuesForParameterId(20, parameterId)
assert.Equal(s.T(), value, 20.0)
value = s.remoteSut.AdjustValueToBeWithinPermittedValuesForParameterId(20, parameterId)
assert.Equal(s.T(), value, 16.0)
assert.Equal(s.T(), value, 20.0)

value = s.localSut.AdjustValueToBeWithinPermittedValuesForParameterId(2, parameterId)
assert.Equal(s.T(), value, 2.0)
value = s.remoteSut.AdjustValueToBeWithinPermittedValuesForParameterId(2, parameterId)
assert.Equal(s.T(), value, 2.0)

value = s.localSut.AdjustValueToBeWithinPermittedValuesForParameterId(1, parameterId)
assert.Equal(s.T(), value, 0.1)
assert.Equal(s.T(), value, 1.0)
value = s.remoteSut.AdjustValueToBeWithinPermittedValuesForParameterId(1, parameterId)
assert.Equal(s.T(), value, 0.1)
assert.Equal(s.T(), value, 1.0)
}

func (s *ElectricalConnectionSuite) Test_GetCharacteristics() {
Expand Down Expand Up @@ -972,6 +1024,68 @@ func (s *ElectricalConnectionSuite) addParamDescriptionPower() {
_, _ = s.remoteFeature.UpdateData(true, model.FunctionTypeElectricalConnectionParameterDescriptionListData, fData, nil, nil)
}

func (s *ElectricalConnectionSuite) addParamDescription_Elli_1Phase() {
fData := &model.ElectricalConnectionParameterDescriptionListDataType{
ElectricalConnectionParameterDescriptionData: []model.ElectricalConnectionParameterDescriptionDataType{
{
ElectricalConnectionId: util.Ptr(model.ElectricalConnectionIdType(0)),
ParameterId: util.Ptr(model.ElectricalConnectionParameterIdType(0)),
AcMeasuredPhases: util.Ptr(model.ElectricalConnectionPhaseNameTypeAbc),
ScopeType: util.Ptr(model.ScopeTypeTypeACPowerTotal),
},
{
ElectricalConnectionId: util.Ptr(model.ElectricalConnectionIdType(0)),
ParameterId: util.Ptr(model.ElectricalConnectionParameterIdType(1)),
MeasurementId: util.Ptr(model.MeasurementIdType(0)),
AcMeasuredPhases: util.Ptr(model.ElectricalConnectionPhaseNameTypeA),
AcMeasurementVariant: util.Ptr(model.ElectricalConnectionMeasurandVariantTypeRms),
},
{
ElectricalConnectionId: util.Ptr(model.ElectricalConnectionIdType(0)),
ParameterId: util.Ptr(model.ElectricalConnectionParameterIdType(2)),
MeasurementId: util.Ptr(model.MeasurementIdType(1)),
AcMeasuredPhases: util.Ptr(model.ElectricalConnectionPhaseNameTypeB),
AcMeasurementVariant: util.Ptr(model.ElectricalConnectionMeasurandVariantTypeRms),
},
{
ElectricalConnectionId: util.Ptr(model.ElectricalConnectionIdType(0)),
ParameterId: util.Ptr(model.ElectricalConnectionParameterIdType(3)),
MeasurementId: util.Ptr(model.MeasurementIdType(2)),
AcMeasuredPhases: util.Ptr(model.ElectricalConnectionPhaseNameTypeC),
AcMeasurementVariant: util.Ptr(model.ElectricalConnectionMeasurandVariantTypeRms),
},
{
ElectricalConnectionId: util.Ptr(model.ElectricalConnectionIdType(0)),
ParameterId: util.Ptr(model.ElectricalConnectionParameterIdType(4)),
MeasurementId: util.Ptr(model.MeasurementIdType(3)),
AcMeasuredPhases: util.Ptr(model.ElectricalConnectionPhaseNameTypeA),
},
{
ElectricalConnectionId: util.Ptr(model.ElectricalConnectionIdType(0)),
ParameterId: util.Ptr(model.ElectricalConnectionParameterIdType(5)),
MeasurementId: util.Ptr(model.MeasurementIdType(4)),
AcMeasuredPhases: util.Ptr(model.ElectricalConnectionPhaseNameTypeB),
},
{
ElectricalConnectionId: util.Ptr(model.ElectricalConnectionIdType(0)),
ParameterId: util.Ptr(model.ElectricalConnectionParameterIdType(6)),
MeasurementId: util.Ptr(model.MeasurementIdType(5)),
AcMeasuredPhases: util.Ptr(model.ElectricalConnectionPhaseNameTypeC),
},
{
ElectricalConnectionId: util.Ptr(model.ElectricalConnectionIdType(0)),
ParameterId: util.Ptr(model.ElectricalConnectionParameterIdType(7)),
MeasurementId: util.Ptr(model.MeasurementIdType(6)),
VoltageType: util.Ptr(model.ElectricalConnectionVoltageTypeTypeAc),
AcMeasuredPhases: util.Ptr(model.ElectricalConnectionPhaseNameTypeAbc),
AcMeasurementType: util.Ptr(model.ElectricalConnectionAcMeasurementTypeTypeReal),
},
},
}
_ = s.localFeature.UpdateData(model.FunctionTypeElectricalConnectionParameterDescriptionListData, fData, nil, nil)
_, _ = s.remoteFeature.UpdateData(true, model.FunctionTypeElectricalConnectionParameterDescriptionListData, fData, nil, nil)
}

func (s *ElectricalConnectionSuite) addPermittedValueSet() {
fData := &model.ElectricalConnectionPermittedValueSetListDataType{
ElectricalConnectionPermittedValueSetData: []model.ElectricalConnectionPermittedValueSetDataType{
Expand Down
1 change: 1 addition & 0 deletions usecases/cem/evcem/public_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,7 @@ func (s *CemEVCEMSuite) Test_EVCurrentPerPhase_AudiConnect() {

data, err = s.sut.CurrentPerPhase(s.evEntity)
assert.Nil(s.T(), err)
assert.Equal(s.T(), 1, len(data))
assert.Equal(s.T(), 10.0, data[0])
}

Expand Down
2 changes: 1 addition & 1 deletion usecases/internal/loadcontrol.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func LoadControlLimits(
elParamDesc, err := evElectricalConnection.GetParameterDescriptionsForFilter(filter)
if err != nil || len(elParamDesc) == 0 || elParamDesc[0].MeasurementId == nil {
// there is no data for this phase, the phase may not exist
result = append(result, ucapi.LoadLimitsPhase{Phase: phaseName})
// so do not add id to the result
continue
}

Expand Down
Loading

0 comments on commit 2cd13fc

Please sign in to comment.