Skip to content

Commit

Permalink
Fix EVCem Workaround for power not provided
Browse files Browse the repository at this point in the history
Add tests with real example data and fix workaround using currents to provide power values, if there are power descriptions but no values provided. (E.g. Elli Charger Connect/Pro Gen 1)
  • Loading branch information
DerAndereAndi committed Jul 5, 2024
1 parent fd92285 commit aef0f7b
Show file tree
Hide file tree
Showing 2 changed files with 117 additions and 3 deletions.
3 changes: 2 additions & 1 deletion usecases/cem/evcem/public.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,8 @@ func (e *EVCEM) PowerPerPhase(entity spineapi.EntityRemoteInterface) ([]float64,
ScopeType: util.Ptr(model.ScopeTypeTypeACPower),
}
data, err = evMeasurement.GetDataForFilter(filter)
if err != nil || len(data) == 0 {
// Elli Charger Connect/Pro (Gen1) returns power descriptions, but only measurements without actual values, see test caseTest_EVPowerPerPhase_Current
if err != nil || len(data) == 0 || data[0].Value == nil {
powerAvailable = false

// If power is not provided, fall back to power calculations via currents
Expand Down
117 changes: 115 additions & 2 deletions usecases/cem/evcem/public_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,9 +249,58 @@ func (s *CemEVCEMSuite) Test_EVPowerPerPhase_Current() {
{
ElectricalConnectionId: util.Ptr(model.ElectricalConnectionIdType(0)),
ParameterId: util.Ptr(model.ElectricalConnectionParameterIdType(0)),
ScopeType: util.Ptr(model.ScopeTypeTypeACPowerTotal),
AcMeasuredPhases: util.Ptr(model.ElectricalConnectionPhaseNameTypeAbc),
},
{
ElectricalConnectionId: util.Ptr(model.ElectricalConnectionIdType(0)),
ParameterId: util.Ptr(model.ElectricalConnectionParameterIdType(1)),
MeasurementId: util.Ptr(model.MeasurementIdType(0)),
ScopeType: util.Ptr(model.ScopeTypeTypeACCurrent),
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)),
ScopeType: util.Ptr(model.ScopeTypeTypeACCurrent),
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)),
ScopeType: util.Ptr(model.ScopeTypeTypeACCurrent),
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),
},
},
}
Expand All @@ -271,6 +320,49 @@ func (s *CemEVCEMSuite) Test_EVPowerPerPhase_Current() {
MeasurementType: util.Ptr(model.MeasurementTypeTypeCurrent),
CommodityType: util.Ptr(model.CommodityTypeTypeElectricity),
ScopeType: util.Ptr(model.ScopeTypeTypeACCurrent),
Unit: util.Ptr(model.UnitOfMeasurementTypeA),
},
{
MeasurementId: util.Ptr(model.MeasurementIdType(1)),
MeasurementType: util.Ptr(model.MeasurementTypeTypeCurrent),
CommodityType: util.Ptr(model.CommodityTypeTypeElectricity),
ScopeType: util.Ptr(model.ScopeTypeTypeACCurrent),
Unit: util.Ptr(model.UnitOfMeasurementTypeA),
},
{
MeasurementId: util.Ptr(model.MeasurementIdType(2)),
MeasurementType: util.Ptr(model.MeasurementTypeTypeCurrent),
CommodityType: util.Ptr(model.CommodityTypeTypeElectricity),
ScopeType: util.Ptr(model.ScopeTypeTypeACCurrent),
Unit: util.Ptr(model.UnitOfMeasurementTypeA),
},
{
MeasurementId: util.Ptr(model.MeasurementIdType(3)),
MeasurementType: util.Ptr(model.MeasurementTypeTypePower),
CommodityType: util.Ptr(model.CommodityTypeTypeElectricity),
ScopeType: util.Ptr(model.ScopeTypeTypeACPower),
Unit: util.Ptr(model.UnitOfMeasurementTypeW),
},
{
MeasurementId: util.Ptr(model.MeasurementIdType(4)),
MeasurementType: util.Ptr(model.MeasurementTypeTypePower),
CommodityType: util.Ptr(model.CommodityTypeTypeElectricity),
ScopeType: util.Ptr(model.ScopeTypeTypeACPower),
Unit: util.Ptr(model.UnitOfMeasurementTypeW),
},
{
MeasurementId: util.Ptr(model.MeasurementIdType(5)),
MeasurementType: util.Ptr(model.MeasurementTypeTypePower),
CommodityType: util.Ptr(model.CommodityTypeTypeElectricity),
ScopeType: util.Ptr(model.ScopeTypeTypeACPower),
Unit: util.Ptr(model.UnitOfMeasurementTypeW),
},
{
MeasurementId: util.Ptr(model.MeasurementIdType(6)),
MeasurementType: util.Ptr(model.MeasurementTypeTypeEnergy),
CommodityType: util.Ptr(model.CommodityTypeTypeElectricity),
ScopeType: util.Ptr(model.ScopeTypeTypeCharge),
Unit: util.Ptr(model.UnitOfMeasurementTypeWh),
},
},
}
Expand All @@ -287,7 +379,27 @@ func (s *CemEVCEMSuite) Test_EVPowerPerPhase_Current() {
MeasurementData: []model.MeasurementDataType{
{
MeasurementId: util.Ptr(model.MeasurementIdType(0)),
Value: model.NewScaledNumberType(10),
Value: model.NewScaledNumberType(5.09),
},
{
MeasurementId: util.Ptr(model.MeasurementIdType(1)),
Value: model.NewScaledNumberType(4.04),
},
{
MeasurementId: util.Ptr(model.MeasurementIdType(2)),
Value: model.NewScaledNumberType(5.09),
},
{
MeasurementId: util.Ptr(model.MeasurementIdType(3)),
},
{
MeasurementId: util.Ptr(model.MeasurementIdType(4)),
},
{
MeasurementId: util.Ptr(model.MeasurementIdType(5)),
},
{
MeasurementId: util.Ptr(model.MeasurementIdType(6)),
},
},
}
Expand All @@ -297,7 +409,8 @@ func (s *CemEVCEMSuite) Test_EVPowerPerPhase_Current() {

data, err = s.sut.PowerPerPhase(s.evEntity)
assert.Nil(s.T(), err)
assert.Equal(s.T(), 2300.0, data[0])
assert.Equal(s.T(), 3, len(data))
assert.Equal(s.T(), 1170.7, data[0])
}

func (s *CemEVCEMSuite) Test_EVChargedEnergy() {
Expand Down

0 comments on commit aef0f7b

Please sign in to comment.