Skip to content

Commit

Permalink
Merge branch 'release/v0.6.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
DerAndereAndi committed Jul 16, 2024
2 parents 0939b60 + 8db2c88 commit 105fc17
Show file tree
Hide file tree
Showing 36 changed files with 281 additions and 110 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
4 changes: 3 additions & 1 deletion features/client/feature.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package client

import (
"errors"
"fmt"

"github.com/enbility/eebus-go/api"
spineapi "github.com/enbility/spine-go/api"
Expand Down Expand Up @@ -135,7 +136,8 @@ func (f *Feature) requestData(function model.FunctionType, selectors any, elemen
fTypes := f.featureRemote.Operations()
op, exists := fTypes[function]
if !exists || !op.Read() {
return nil, api.ErrOperationOnFunctionNotSupported
errWithFunction := fmt.Sprintf("%s %s", api.ErrOperationOnFunctionNotSupported.Error(), function)
return nil, errors.New(errWithFunction)
}

// remove the selectors if the remote does not allow partial reads
Expand Down
8 changes: 8 additions & 0 deletions features/client/feature_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,14 @@ func (s *FeatureSuite) Test_requestData() {
assert.Nil(s.T(), err)
assert.NotNil(s.T(), counter)

counter, err = s.testFeature2.requestData(model.FunctionTypeMeasurementDescriptionListData, nil, nil)
assert.NotNil(s.T(), err)
assert.Nil(s.T(), counter)

counter, err = s.testFeature2.requestData(model.FunctionTypeLoadControlLimitListData, nil, nil)
assert.Nil(s.T(), err)
assert.NotNil(s.T(), counter)

selectors2 := &model.LoadControlLimitListDataSelectorsType{
LimitId: util.Ptr(model.LoadControlLimitIdType(0)),
}
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
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ module github.com/enbility/eebus-go
go 1.21.1

require (
github.com/enbility/ship-go v0.5.1
github.com/enbility/spine-go v0.6.0
github.com/enbility/ship-go v0.5.2
github.com/enbility/spine-go v0.6.1
github.com/stretchr/testify v1.9.0
)

Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ github.com/ahmetb/go-linq/v3 v3.2.0 h1:BEuMfp+b59io8g5wYzNoFe9pWPalRklhlhbiU3hYZ
github.com/ahmetb/go-linq/v3 v3.2.0/go.mod h1:haQ3JfOeWK8HpVxMtHHEMPVgBKiYyQ+f1/kLZh/cj9U=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/enbility/ship-go v0.5.1 h1:8Vax1MpyI/C+kQlMFAzQ7/h/xJ7fuumSLJy9FYgEkcE=
github.com/enbility/ship-go v0.5.1/go.mod h1:jewJWYQ10jNhsnhS1C4jESx3CNmDa5HNWZjBhkTug5Y=
github.com/enbility/spine-go v0.6.0 h1:sd5x9ZckvhI9b07HrdxKEZAcpF1Jt+xMC46o3VpuwoY=
github.com/enbility/spine-go v0.6.0/go.mod h1:1SJ6+ihCkjzVALXXbB3xdjDGp2ITqq9gnJQiPsF3fb0=
github.com/enbility/ship-go v0.5.2 h1:T9+YuP5ZpofKd463PLKq78fAaPAcGMnRAcv8c8aD5yU=
github.com/enbility/ship-go v0.5.2/go.mod h1:jewJWYQ10jNhsnhS1C4jESx3CNmDa5HNWZjBhkTug5Y=
github.com/enbility/spine-go v0.6.1 h1:6NAPE7PmCQsmfiZy/dLpnFZXEw8RK9H4USGniIw9r+Q=
github.com/enbility/spine-go v0.6.1/go.mod h1:pRGS+C5rZ5rhxTAA1whU8fC9p7lH5ixyut++yEZe470=
github.com/enbility/zeroconf/v2 v2.0.0-20240210101930-d0004078577b h1:sg3c6LJ4eWffwtt9SW0lgcIX4Oh274vwdJnNFNNrDco=
github.com/enbility/zeroconf/v2 v2.0.0-20240210101930-d0004078577b/go.mod h1:BjzRRiYX6mWdOgku1xxDE+NsV8PijTby7Q7BkYVdfDU=
github.com/godbus/dbus/v5 v5.1.0 h1:4KLkAxT3aOY8Li4FRJe/KvhoNFFxo0m6fNuFUO8QJUk=
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
6 changes: 1 addition & 5 deletions usecases/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,8 @@ Actors:
- `lpc`: Limitation of Power Consumption
- `lpp`: Limitation of Power Production

- `gcp`: Grid Connection Point

Use Cases:
- `mgcp`: Monitoring of Grid Connection Point

- `ma`: Monitoring Appliance

Use Cases:
- `mpc`: Monitoring of Power Consumption
- `mgcp`: Monitoring of Grid Connection Point
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
45 changes: 3 additions & 42 deletions usecases/cem/evcem/public.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package evcem

import (
"time"

"github.com/enbility/eebus-go/api"
"github.com/enbility/eebus-go/features/client"
ucapi "github.com/enbility/eebus-go/usecases/api"
Expand Down Expand Up @@ -64,8 +62,6 @@ func (e *EVCEM) CurrentPerPhase(entity spineapi.EntityRemoteInterface) ([]float6
}

var result []float64
refetch := true
compare := time.Now().UTC().Add(-1 * time.Minute)

for _, phase := range ucapi.PhaseNameMapping {
for _, item := range data {
Expand All @@ -84,32 +80,9 @@ func (e *EVCEM) CurrentPerPhase(entity spineapi.EntityRemoteInterface) ([]float6

phaseValue := item.Value.GetValue()
result = append(result, phaseValue)

if item.Timestamp == nil {
continue
}

if timestamp, err := item.Timestamp.GetTime(); err == nil {
refetch = timestamp.Before(compare)
}

// the MEB cars report the wrong NTP time by 1 or 2 hours (depending on DST)
// and PMCC uses NTP from the EV, so check these cases as well
for i := 0; i < 2 && refetch; i++ {
compare = compare.Add(-1 * time.Hour)
if timestamp, err := item.Timestamp.GetTime(); err == nil {
refetch = timestamp.Before(compare)
}
}
}
}

// if there was no timestamp provided or the time for the last value
// is older than 1 minute, send a read request
if refetch {
_, _ = evMeasurement.RequestData(nil, nil)
}

return result, nil
}

Expand All @@ -131,23 +104,15 @@ 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),
ScopeType: util.Ptr(model.ScopeTypeTypeACPower),
}
data, err = evMeasurement.GetDataForFilter(filter)
if err != nil || len(data) == 0 {
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
}
// Elli Charger Connect/Pro (Gen1) returns power descriptions, but only measurements without actual values, see test case Test_EVPowerPerPhase_Current
if err != nil || len(data) == 0 || data[0].Value == nil {
return nil, api.ErrDataNotAvailable
}

var result []float64
Expand All @@ -168,10 +133,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
Loading

0 comments on commit 105fc17

Please sign in to comment.