Skip to content

Commit

Permalink
Remove voltage configuration
Browse files Browse the repository at this point in the history
- No need to setup default voltage
- EVCem `PowerPerPhase` returns an error if power is not available instead of using currents and static voltage value
  • Loading branch information
DerAndereAndi committed Jul 5, 2024
1 parent aef0f7b commit 605b8c5
Show file tree
Hide file tree
Showing 31 changed files with 148 additions and 70 deletions.
12 changes: 0 additions & 12 deletions api/configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,6 @@ type Configuration struct {
// The certificate used for the service and its connections, required
certificate tls.Certificate

// The sites grid voltage
// This is useful when e.g. power values are not available and therefor
// need to be calculated using the current values
voltage float64

// The timeout to be used for sending heartbeats
heartbeatTimeout time.Duration

Expand All @@ -86,13 +81,11 @@ func NewConfiguration(
entityTypes []model.EntityTypeType,
port int,
certificate tls.Certificate,
voltage float64,
heartbeatTimeout time.Duration,
) (*Configuration, error) {
configuration := &Configuration{
certificate: certificate,
port: port,
voltage: voltage,
heartbeatTimeout: heartbeatTimeout,
mdnsProviderSelection: mdns.MdnsProviderSelectionGoZeroConfOnly,
}
Expand Down Expand Up @@ -242,11 +235,6 @@ func (s *Configuration) SetCertificate(cert tls.Certificate) {
s.certificate = cert
}

// return the sites predefined grid voltage
func (s *Configuration) Voltage() float64 {
return s.voltage
}

func (s *Configuration) HeartbeatTimeout() time.Duration {
return s.heartbeatTimeout
}
20 changes: 8 additions & 12 deletions api/configuration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,54 +27,53 @@ func (s *ConfigurationSuite) Test_Configuration() {
model := "model"
serial := "serial"
port := 4567
volt := 230.0
heartbeatTimeout := time.Second * 4
entityTypes := []spinemodel.EntityTypeType{spinemodel.EntityTypeTypeCEM}

config, err := NewConfiguration("", brand, model, serial, spinemodel.DeviceTypeTypeEnergyManagementSystem,
entityTypes, 0, certificate, volt, heartbeatTimeout)
entityTypes, 0, certificate, heartbeatTimeout)

assert.Nil(s.T(), config)
assert.NotNil(s.T(), err)

config, err = NewConfiguration("", brand, model, serial, spinemodel.DeviceTypeTypeEnergyManagementSystem,
entityTypes, port, certificate, volt, heartbeatTimeout)
entityTypes, port, certificate, heartbeatTimeout)

assert.Nil(s.T(), config)
assert.NotNil(s.T(), err)

config, err = NewConfiguration(vendor, "", model, serial, spinemodel.DeviceTypeTypeEnergyManagementSystem,
entityTypes, port, certificate, 230, heartbeatTimeout)
entityTypes, port, certificate, heartbeatTimeout)

assert.Nil(s.T(), config)
assert.NotNil(s.T(), err)

config, err = NewConfiguration(vendor, brand, "", serial, spinemodel.DeviceTypeTypeEnergyManagementSystem,
entityTypes, port, certificate, 230, heartbeatTimeout)
entityTypes, port, certificate, heartbeatTimeout)

assert.Nil(s.T(), config)
assert.NotNil(s.T(), err)

config, err = NewConfiguration(vendor, brand, model, "", spinemodel.DeviceTypeTypeEnergyManagementSystem,
entityTypes, port, certificate, 230, heartbeatTimeout)
entityTypes, port, certificate, heartbeatTimeout)

assert.Nil(s.T(), config)
assert.NotNil(s.T(), err)

config, err = NewConfiguration(vendor, brand, model, serial, "",
entityTypes, port, certificate, 230, heartbeatTimeout)
entityTypes, port, certificate, heartbeatTimeout)

assert.Nil(s.T(), config)
assert.NotNil(s.T(), err)

config, err = NewConfiguration(vendor, brand, model, serial, spinemodel.DeviceTypeTypeEnergyManagementSystem,
[]spinemodel.EntityTypeType{}, port, certificate, 230, heartbeatTimeout)
[]spinemodel.EntityTypeType{}, port, certificate, heartbeatTimeout)

assert.Nil(s.T(), config)
assert.NotNil(s.T(), err)

config, err = NewConfiguration(vendor, brand, model, serial, spinemodel.DeviceTypeTypeEnergyManagementSystem,
entityTypes, port, certificate, 230, heartbeatTimeout)
entityTypes, port, certificate, heartbeatTimeout)

assert.NotNil(s.T(), config)
assert.Nil(s.T(), err)
Expand Down Expand Up @@ -110,9 +109,6 @@ func (s *ConfigurationSuite) Test_Configuration() {
id = config.MdnsServiceName()
assert.Equal(s.T(), alternate, id)

voltage := config.Voltage()
assert.Equal(s.T(), volt, voltage)

portValue := config.Port()
assert.Equal(s.T(), port, portValue)

Expand Down
2 changes: 1 addition & 1 deletion cmd/controlbox/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func (h *controlbox) run() {
"Demo", "Demo", "ControlBox", "123456789",
model.DeviceTypeTypeElectricitySupplySystem,
[]model.EntityTypeType{model.EntityTypeTypeGridGuard},
port, certificate, 230, time.Second*60)
port, certificate, time.Second*60)
if err != nil {
log.Fatal(err)
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/evse/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func (h *evse) run() {
"Demo", "Demo", "EVSE", "234567890",
model.DeviceTypeTypeChargingStation,
[]model.EntityTypeType{model.EntityTypeTypeEVSE},
port, certificate, 230, time.Second*4)
port, certificate, time.Second*4)
if err != nil {
log.Fatal(err)
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/hems/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func (h *hems) run() {
"Demo", "Demo", "HEMS", "123456789",
model.DeviceTypeTypeEnergyManagementSystem,
[]model.EntityTypeType{model.EntityTypeTypeCEM},
port, certificate, 230, time.Second*4)
port, certificate, time.Second*4)
if err != nil {
log.Fatal(err)
}
Expand Down
2 changes: 1 addition & 1 deletion features/server/deviceconfiguration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func (s *DeviceConfigurationSuite) BeforeTest(suiteName, testName string) {
"test", "test", "test", "test",
model.DeviceTypeTypeEnergyManagementSystem,
[]model.EntityTypeType{model.EntityTypeTypeCEM},
9999, cert, 230.0, time.Second*4)
9999, cert, time.Second*4)

serviceHandler := mocks.NewServiceReaderInterface(s.T())
serviceHandler.EXPECT().ServicePairingDetailUpdate(mock.Anything, mock.Anything).Return().Maybe()
Expand Down
2 changes: 1 addition & 1 deletion features/server/devicediagnosis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func (s *DeviceDiagnosisSuite) BeforeTest(suiteName, testName string) {
"test", "test", "test", "test",
model.DeviceTypeTypeEnergyManagementSystem,
[]model.EntityTypeType{model.EntityTypeTypeCEM},
9999, cert, 230.0, time.Second*4)
9999, cert, time.Second*4)

serviceHandler := mocks.NewServiceReaderInterface(s.T())
serviceHandler.EXPECT().ServicePairingDetailUpdate(mock.Anything, mock.Anything).Return().Maybe()
Expand Down
2 changes: 1 addition & 1 deletion features/server/electricalconnection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func (s *ElectricalConnectionSuite) BeforeTest(suiteName, testName string) {
"test", "test", "test", "test",
model.DeviceTypeTypeEnergyManagementSystem,
[]model.EntityTypeType{model.EntityTypeTypeCEM},
9999, cert, 230.0, time.Second*4)
9999, cert, time.Second*4)

serviceHandler := mocks.NewServiceReaderInterface(s.T())
serviceHandler.EXPECT().ServicePairingDetailUpdate(mock.Anything, mock.Anything).Return().Maybe()
Expand Down
2 changes: 1 addition & 1 deletion features/server/feature_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func (s *FeatureSuite) BeforeTest(suiteName, testName string) {
"test", "test", "test", "test",
model.DeviceTypeTypeEnergyManagementSystem,
[]model.EntityTypeType{model.EntityTypeTypeCEM},
9999, cert, 230.0, time.Second*4)
9999, cert, time.Second*4)

serviceHandler := mocks.NewServiceReaderInterface(s.T())
serviceHandler.EXPECT().ServicePairingDetailUpdate(mock.Anything, mock.Anything).Return().Maybe()
Expand Down
2 changes: 1 addition & 1 deletion features/server/loadcontrol_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func (s *LoadControlSuite) BeforeTest(suiteName, testName string) {
"test", "test", "test", "test",
model.DeviceTypeTypeEnergyManagementSystem,
[]model.EntityTypeType{model.EntityTypeTypeCEM},
9999, cert, 230.0, time.Second*4)
9999, cert, time.Second*4)

serviceHandler := mocks.NewServiceReaderInterface(s.T())
serviceHandler.EXPECT().ServicePairingDetailUpdate(mock.Anything, mock.Anything).Return().Maybe()
Expand Down
2 changes: 1 addition & 1 deletion features/server/measurement_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func (s *MeasurementSuite) BeforeTest(suiteName, testName string) {
"test", "test", "test", "test",
model.DeviceTypeTypeEnergyManagementSystem,
[]model.EntityTypeType{model.EntityTypeTypeCEM},
9999, cert, 230.0, time.Second*4)
9999, cert, time.Second*4)

serviceHandler := mocks.NewServiceReaderInterface(s.T())
serviceHandler.EXPECT().ServicePairingDetailUpdate(mock.Anything, mock.Anything).Return().Maybe()
Expand Down
6 changes: 3 additions & 3 deletions service/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func (s *ServiceSuite) BeforeTest(suiteName, testName string) {
var err error
s.config, err = api.NewConfiguration(
"vendor", "brand", "model", "serial", model.DeviceTypeTypeEnergyManagementSystem,
[]model.EntityTypeType{model.EntityTypeTypeCEM}, 4729, certificate, 230.0, time.Second*4)
[]model.EntityTypeType{model.EntityTypeTypeCEM}, 4729, certificate, time.Second*4)
assert.Nil(s.T(), nil, err)

s.sut = NewService(s.config, s.serviceReader)
Expand Down Expand Up @@ -179,7 +179,7 @@ func (s *ServiceSuite) Test_Setup_IANA() {
certificate := tls.Certificate{}
s.config, err = api.NewConfiguration(
"12345", "brand", "model", "serial", model.DeviceTypeTypeEnergyManagementSystem,
[]model.EntityTypeType{model.EntityTypeTypeCEM}, 4729, certificate, 230.0, time.Second*4)
[]model.EntityTypeType{model.EntityTypeTypeCEM}, 4729, certificate, time.Second*4)
assert.Nil(s.T(), nil, err)

s.sut = NewService(s.config, s.serviceReader)
Expand Down Expand Up @@ -219,7 +219,7 @@ func (s *ServiceSuite) Test_Setup_Error_DeviceName() {
"modelmodelmodelmodelmodelmodelmodelmodelmodelmodelmodelmodelmodelmodelmodelmodelmodelmodelmodelmodel",
"serialserialserialserialserialserialserialserialserialserialserialserialserialserialserialserialserial",
model.DeviceTypeTypeEnergyManagementSystem,
[]model.EntityTypeType{model.EntityTypeTypeCEM}, 4729, certificate, 230.0, time.Second*4)
[]model.EntityTypeType{model.EntityTypeTypeCEM}, 4729, certificate, time.Second*4)
assert.Nil(s.T(), nil, err)

s.sut = NewService(s.config, s.serviceReader)
Expand Down
2 changes: 1 addition & 1 deletion usecases/cem/cevc/testhelper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func (s *CemCEVCSuite) BeforeTest(suiteName, testName string) {
"test", "test", "test", "test",
model.DeviceTypeTypeEnergyManagementSystem,
[]model.EntityTypeType{model.EntityTypeTypeCEM},
9999, cert, 230.0, time.Second*4)
9999, cert, time.Second*4)

serviceHandler := mocks.NewServiceReaderInterface(s.T())
serviceHandler.EXPECT().ServicePairingDetailUpdate(mock.Anything, mock.Anything).Return().Maybe()
Expand Down
2 changes: 1 addition & 1 deletion usecases/cem/evcc/testhelper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func (s *CemEVCCSuite) BeforeTest(suiteName, testName string) {
"test", "test", "test", "test",
model.DeviceTypeTypeEnergyManagementSystem,
[]model.EntityTypeType{model.EntityTypeTypeCEM},
9999, cert, 230.0, time.Second*4)
9999, cert, time.Second*4)

serviceHandler := mocks.NewServiceReaderInterface(s.T())
serviceHandler.EXPECT().ServicePairingDetailUpdate(mock.Anything, mock.Anything).Return().Maybe()
Expand Down
15 changes: 1 addition & 14 deletions usecases/cem/evcem/public.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,6 @@ func (e *EVCEM) PowerPerPhase(entity spineapi.EntityRemoteInterface) ([]float64,

var data []model.MeasurementDataType

powerAvailable := true
filter := model.MeasurementDescriptionDataType{
MeasurementType: util.Ptr(model.MeasurementTypeTypePower),
CommodityType: util.Ptr(model.CommodityTypeTypeElectricity),
Expand All @@ -140,15 +139,7 @@ func (e *EVCEM) PowerPerPhase(entity spineapi.EntityRemoteInterface) ([]float64,
data, err = evMeasurement.GetDataForFilter(filter)
// 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
filter.MeasurementType = util.Ptr(model.MeasurementTypeTypeCurrent)
filter.ScopeType = util.Ptr(model.ScopeTypeTypeACCurrent)
data, err = evMeasurement.GetDataForFilter(filter)
if err != nil || len(data) == 0 {
return nil, api.ErrDataNotAvailable
}
return nil, api.ErrDataNotAvailable
}

var result []float64
Expand All @@ -169,10 +160,6 @@ func (e *EVCEM) PowerPerPhase(entity spineapi.EntityRemoteInterface) ([]float64,
}

phaseValue := item.Value.GetValue()
if !powerAvailable {
phaseValue *= e.service.Configuration().Voltage()
}

result = append(result, phaseValue)
}
}
Expand Down
113 changes: 110 additions & 3 deletions usecases/cem/evcem/public_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -408,9 +408,8 @@ func (s *CemEVCEMSuite) Test_EVPowerPerPhase_Current() {
assert.Nil(s.T(), fErr)

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

func (s *CemEVCEMSuite) Test_EVChargedEnergy() {
Expand Down Expand Up @@ -457,3 +456,111 @@ func (s *CemEVCEMSuite) Test_EVChargedEnergy() {
assert.Nil(s.T(), err)
assert.Equal(s.T(), 80.0, data)
}

func (s *CemEVCEMSuite) Test_EVChargedEnergy_ElliGen1() {
data, err := s.sut.EnergyCharged(s.mockRemoteEntity)
assert.NotNil(s.T(), err)
assert.Equal(s.T(), 0.0, data)

data, err = s.sut.EnergyCharged(s.evEntity)
assert.NotNil(s.T(), err)
assert.Equal(s.T(), 0.0, data)

measDesc := &model.MeasurementDescriptionListDataType{
MeasurementDescriptionData: []model.MeasurementDescriptionDataType{
{
MeasurementId: util.Ptr(model.MeasurementIdType(0)),
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),
},
},
}

rFeature := s.remoteDevice.FeatureByEntityTypeAndRole(s.evEntity, model.FeatureTypeTypeMeasurement, model.RoleTypeServer)
fErr := rFeature.UpdateData(model.FunctionTypeMeasurementDescriptionListData, measDesc, nil, nil)
assert.Nil(s.T(), fErr)

data, err = s.sut.EnergyCharged(s.evEntity)
assert.NotNil(s.T(), err)
assert.Equal(s.T(), 0.0, data)

measData := &model.MeasurementListDataType{
MeasurementData: []model.MeasurementDataType{
{
MeasurementId: util.Ptr(model.MeasurementIdType(0)),
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)),
},
},
}

fErr = rFeature.UpdateData(model.FunctionTypeMeasurementListData, measData, nil, nil)
assert.Nil(s.T(), fErr)

data, err = s.sut.EnergyCharged(s.evEntity)
assert.NotNil(s.T(), err)
assert.Equal(s.T(), 0.0, data)
}
Loading

0 comments on commit 605b8c5

Please sign in to comment.