Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Various updates #111

Merged
merged 3 commits into from
Sep 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ jobs:
file: coverage.out

- name: Run Gosec Security Scanner
uses: securego/gosec@11d69032b0856c96afd4c493967ab7a30e20ff5e
uses: securego/gosec@v2.20.0
with:
# we let the report trigger content trigger a failure using the GitHub Security features.
args: '-no-fail -fmt sarif -out results.sarif ./...'
Expand Down
8 changes: 2 additions & 6 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.3
github.com/enbility/spine-go v0.6.2
github.com/enbility/ship-go v0.0.0-20240904104254-04d944c4f825
github.com/enbility/spine-go v0.0.0-20240907194637-0024041a4f36
github.com/stretchr/testify v1.9.0
)

Expand Down Expand Up @@ -35,7 +35,3 @@ retract (
v0.2.2 // Contains retractions only.
v0.2.1 // Published accidentally.
)

replace github.com/enbility/ship-go => github.com/enbility/ship-go v0.0.0-20240904104254-04d944c4f825

replace github.com/enbility/spine-go => github.com/enbility/spine-go v0.0.0-20240903070433-dd8261993071
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ github.com/enbility/go-avahi v0.0.0-20240829083637-9ae2ef5f5ed2 h1:voP4zFVNvVWxl
github.com/enbility/go-avahi v0.0.0-20240829083637-9ae2ef5f5ed2/go.mod h1:KJXUEgg/b4XZzS+OFfqnykHREsinuNSL/IzJ+nU43P8=
github.com/enbility/ship-go v0.0.0-20240904104254-04d944c4f825 h1:i/n9UFYf660TyC8Y48P3MDxLaWWKRNW3pFjEOVzPzto=
github.com/enbility/ship-go v0.0.0-20240904104254-04d944c4f825/go.mod h1:dzymc1D7BDZUTLVHVt9JRRkFLlBrlUmRKyLJvAe07Mc=
github.com/enbility/spine-go v0.0.0-20240903070433-dd8261993071 h1:rjvpnD3xTrSPdU6AQK4miwl/gZQ84CJ6gv/kEEguBME=
github.com/enbility/spine-go v0.0.0-20240903070433-dd8261993071/go.mod h1:6AbRXzd0fLVGFJdT60YQACe1WskwdjiznCfljQ+Ud6s=
github.com/enbility/spine-go v0.0.0-20240907194637-0024041a4f36 h1:Y44hzp5uIYSEyBMe/zwFzlXKokgZHQ9cv2NiIF1NkZs=
github.com/enbility/spine-go v0.0.0-20240907194637-0024041a4f36/go.mod h1:BDvhbs+XsWDGYwd8eQOzPXc8w/avVFmWKLlSKV/gx9k=
github.com/enbility/zeroconf/v2 v2.0.0-20240827101515-f3956627c450 h1:39tnpfiV5OVfYb9sOqYmoivBzTHyNLWSYIxd9Qng1eg=
github.com/enbility/zeroconf/v2 v2.0.0-20240827101515-f3956627c450/go.mod h1:1sUbJ+VE7yLNyRzGoCMjoDWtdZ+bW4aYBKx2+Rw+9hs=
github.com/godbus/dbus/v5 v5.1.0 h1:4KLkAxT3aOY8Li4FRJe/KvhoNFFxo0m6fNuFUO8QJUk=
Expand Down
30 changes: 20 additions & 10 deletions usecases/cem/cevc/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,10 @@ func (e *CEVC) HandleEvent(payload spineapi.EventPayload) {
func (e *CEVC) evConnected(entity spineapi.EntityRemoteInterface) {
// initialise features, e.g. subscriptions, descriptions
if evDeviceConfiguration, err := client.NewDeviceConfiguration(e.LocalEntity, entity); err == nil {
if _, err := evDeviceConfiguration.Subscribe(); err != nil {
logging.Log().Debug(err)
if !evDeviceConfiguration.HasSubscription() {
if _, err := evDeviceConfiguration.Subscribe(); err != nil {
logging.Log().Debug(err)
}
}

// get device configuration descriptions
Expand All @@ -60,12 +62,16 @@ func (e *CEVC) evConnected(entity spineapi.EntityRemoteInterface) {
}

if evTimeSeries, err := client.NewTimeSeries(e.LocalEntity, entity); err == nil {
if _, err := evTimeSeries.Subscribe(); err != nil {
logging.Log().Debug(err)
if !evTimeSeries.HasSubscription() {
if _, err := evTimeSeries.Subscribe(); err != nil {
logging.Log().Debug(err)
}
}

if _, err := evTimeSeries.Bind(); err != nil {
logging.Log().Debug(err)
if !evTimeSeries.HasBinding() {
if _, err := evTimeSeries.Bind(); err != nil {
logging.Log().Debug(err)
}
}

// get time series descriptions
Expand All @@ -80,12 +86,16 @@ func (e *CEVC) evConnected(entity spineapi.EntityRemoteInterface) {
}

if evIncentiveTable, err := client.NewIncentiveTable(e.LocalEntity, entity); err == nil {
if _, err := evIncentiveTable.Subscribe(); err != nil {
logging.Log().Debug(err)
if !evIncentiveTable.HasSubscription() {
if _, err := evIncentiveTable.Subscribe(); err != nil {
logging.Log().Debug(err)
}
}

if _, err := evIncentiveTable.Bind(); err != nil {
logging.Log().Debug(err)
if !evIncentiveTable.HasBinding() {
if _, err := evIncentiveTable.Bind(); err != nil {
logging.Log().Debug(err)
}
}

// get incentivetable descriptions
Expand Down
31 changes: 21 additions & 10 deletions usecases/cem/evcc/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,10 @@ func (e *EVCC) HandleEvent(payload spineapi.EventPayload) {
func (e *EVCC) evConnected(payload spineapi.EventPayload) {
// initialise features, e.g. subscriptions, descriptions
if evDeviceClassification, err := client.NewDeviceClassification(e.LocalEntity, payload.Entity); err == nil {
if _, err := evDeviceClassification.Subscribe(); err != nil {
logging.Log().Debug(err)
if !evDeviceClassification.HasSubscription() {
if _, err := evDeviceClassification.Subscribe(); err != nil {
logging.Log().Debug(err)
}
}

// get manufacturer details
Expand All @@ -69,18 +71,23 @@ func (e *EVCC) evConnected(payload spineapi.EventPayload) {
}

if evDeviceConfiguration, err := client.NewDeviceConfiguration(e.LocalEntity, payload.Entity); err == nil {
if _, err := evDeviceConfiguration.Subscribe(); err != nil {
logging.Log().Debug(err)
if !evDeviceConfiguration.HasSubscription() {
if _, err := evDeviceConfiguration.Subscribe(); err != nil {
logging.Log().Debug(err)
}
}

// get ev configuration data
if _, err := evDeviceConfiguration.RequestKeyValueDescriptions(nil, nil); err != nil {
logging.Log().Debug(err)
}
}

if evDeviceDiagnosis, err := client.NewDeviceDiagnosis(e.LocalEntity, payload.Entity); err == nil {
if _, err := evDeviceDiagnosis.Subscribe(); err != nil {
logging.Log().Debug(err)
if !evDeviceDiagnosis.HasSubscription() {
if _, err := evDeviceDiagnosis.Subscribe(); err != nil {
logging.Log().Debug(err)
}
}

// get device diagnosis state
Expand All @@ -90,8 +97,10 @@ func (e *EVCC) evConnected(payload spineapi.EventPayload) {
}

if evElectricalConnection, err := client.NewElectricalConnection(e.LocalEntity, payload.Entity); err == nil {
if _, err := evElectricalConnection.Subscribe(); err != nil {
logging.Log().Debug(err)
if !evElectricalConnection.HasSubscription() {
if _, err := evElectricalConnection.Subscribe(); err != nil {
logging.Log().Debug(err)
}
}

// get electrical connection parameter descriptions
Expand All @@ -106,8 +115,10 @@ func (e *EVCC) evConnected(payload spineapi.EventPayload) {
}

if evIdentification, err := client.NewIdentification(e.LocalEntity, payload.Entity); err == nil {
if _, err := evIdentification.Subscribe(); err != nil {
logging.Log().Debug(err)
if !evIdentification.HasSubscription() {
if _, err := evIdentification.Subscribe(); err != nil {
logging.Log().Debug(err)
}
}

// get identification
Expand Down
12 changes: 8 additions & 4 deletions usecases/cem/evcem/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,10 @@ func (e *EVCEM) evConnected(entity spineapi.EntityRemoteInterface) {
// initialise features, e.g. subscriptions, descriptions

if evElectricalConnection, err := client.NewElectricalConnection(e.LocalEntity, entity); err == nil {
if _, err := evElectricalConnection.Subscribe(); err != nil {
logging.Log().Debug(err)
if !evElectricalConnection.HasSubscription() {
if _, err := evElectricalConnection.Subscribe(); err != nil {
logging.Log().Debug(err)
}
}

// get electrical connection descriptions
Expand All @@ -59,8 +61,10 @@ func (e *EVCEM) evConnected(entity spineapi.EntityRemoteInterface) {
}

if evMeasurement, err := client.NewMeasurement(e.LocalEntity, entity); err == nil {
if _, err := evMeasurement.Subscribe(); err != nil {
logging.Log().Debug(err)
if !evMeasurement.HasSubscription() {
if _, err := evMeasurement.Subscribe(); err != nil {
logging.Log().Debug(err)
}
}

// get measurement descriptions
Expand Down
12 changes: 8 additions & 4 deletions usecases/cem/opev/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,16 @@ func (e *OPEV) HandleEvent(payload spineapi.EventPayload) {
func (e *OPEV) evConnected(entity spineapi.EntityRemoteInterface) {
// initialise features, e.g. subscriptions, descriptions
if evLoadControl, err := client.NewLoadControl(e.LocalEntity, entity); err == nil {
if _, err := evLoadControl.Subscribe(); err != nil {
logging.Log().Debug(err)
if !evLoadControl.HasSubscription() {
if _, err := evLoadControl.Subscribe(); err != nil {
logging.Log().Debug(err)
}
}

if _, err := evLoadControl.Bind(); err != nil {
logging.Log().Debug(err)
if !evLoadControl.HasBinding() {
if _, err := evLoadControl.Bind(); err != nil {
logging.Log().Debug(err)
}
}

// get descriptions
Expand Down
12 changes: 8 additions & 4 deletions usecases/cem/vabd/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,10 @@ func (e *VABD) HandleEvent(payload spineapi.EventPayload) {
// process required steps when a grid device is connected
func (e *VABD) inverterConnected(entity spineapi.EntityRemoteInterface) {
if electricalConnection, err := client.NewElectricalConnection(e.LocalEntity, entity); err == nil {
if _, err := electricalConnection.Subscribe(); err != nil {
logging.Log().Error(err)
if !electricalConnection.HasSubscription() {
if _, err := electricalConnection.Subscribe(); err != nil {
logging.Log().Error(err)
}
}

// get electrical connection parameter
Expand All @@ -54,8 +56,10 @@ func (e *VABD) inverterConnected(entity spineapi.EntityRemoteInterface) {
}

if measurement, err := client.NewMeasurement(e.LocalEntity, entity); err == nil {
if _, err := measurement.Subscribe(); err != nil {
logging.Log().Error(err)
if !measurement.HasSubscription() {
if _, err := measurement.Subscribe(); err != nil {
logging.Log().Error(err)
}
}

// get measurement parameters
Expand Down
18 changes: 12 additions & 6 deletions usecases/cem/vapd/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,10 @@ func (e *VAPD) HandleEvent(payload spineapi.EventPayload) {
// process required steps when a grid device is connected
func (e *VAPD) inverterConnected(entity spineapi.EntityRemoteInterface) {
if deviceConfiguration, err := client.NewDeviceConfiguration(e.LocalEntity, entity); err == nil {
if _, err := deviceConfiguration.Subscribe(); err != nil {
logging.Log().Error(err)
if !deviceConfiguration.HasSubscription() {
if _, err := deviceConfiguration.Subscribe(); err != nil {
logging.Log().Error(err)
}
}

// get configuration data
Expand All @@ -56,8 +58,10 @@ func (e *VAPD) inverterConnected(entity spineapi.EntityRemoteInterface) {
}

if electricalConnection, err := client.NewElectricalConnection(e.LocalEntity, entity); err == nil {
if _, err := electricalConnection.Subscribe(); err != nil {
logging.Log().Error(err)
if !electricalConnection.HasSubscription() {
if _, err := electricalConnection.Subscribe(); err != nil {
logging.Log().Error(err)
}
}

// get electrical connection parameter
Expand All @@ -71,8 +75,10 @@ func (e *VAPD) inverterConnected(entity spineapi.EntityRemoteInterface) {
}

if measurement, err := client.NewMeasurement(e.LocalEntity, entity); err == nil {
if _, err := measurement.Subscribe(); err != nil {
logging.Log().Error(err)
if !measurement.HasSubscription() {
if _, err := measurement.Subscribe(); err != nil {
logging.Log().Error(err)
}
}

// get measurement parameters
Expand Down
12 changes: 8 additions & 4 deletions usecases/cs/lpc/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,10 @@ func (e *LPC) deviceConnected(payload spineapi.EventPayload) {
if len(deviceDiagEntities) == 1 {
if localDeviceDiag, err := client.NewDeviceDiagnosis(e.LocalEntity, deviceDiagEntities[0]); err == nil {
e.heartbeatDiag = localDeviceDiag
if _, err := localDeviceDiag.Subscribe(); err != nil {
logging.Log().Debug(err)
if !localDeviceDiag.HasSubscription() {
if _, err := localDeviceDiag.Subscribe(); err != nil {
logging.Log().Debug(err)
}
}

if _, err := localDeviceDiag.RequestHeartbeat(); err != nil {
Expand All @@ -126,8 +128,10 @@ func (e *LPC) subscribeHeartbeatWorkaround(payload spineapi.EventPayload) {
if e.heartbeatKeoWorkaround {
if localDeviceDiag, err := client.NewDeviceDiagnosis(e.LocalEntity, payload.Entity); err == nil {
e.heartbeatDiag = localDeviceDiag
if _, err := localDeviceDiag.Subscribe(); err != nil {
logging.Log().Debug(err)
if !localDeviceDiag.HasSubscription() {
if _, err := localDeviceDiag.Subscribe(); err != nil {
logging.Log().Debug(err)
}
}

if _, err := localDeviceDiag.RequestHeartbeat(); err != nil {
Expand Down
11 changes: 7 additions & 4 deletions usecases/cs/lpc/public_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,21 +81,21 @@ func (s *CsLPCSuite) Test_PendingConsumptionLimits() {
func (s *CsLPCSuite) Test_Failsafe() {
limit, changeable, err := s.sut.FailsafeConsumptionActivePowerLimit()
assert.Equal(s.T(), 0.0, limit)
assert.Equal(s.T(), false, changeable)
assert.Equal(s.T(), true, changeable)
assert.Nil(s.T(), err)

err = s.sut.SetFailsafeConsumptionActivePowerLimit(10, true)
err = s.sut.SetFailsafeConsumptionActivePowerLimit(10, false)
assert.Nil(s.T(), err)

limit, changeable, err = s.sut.FailsafeConsumptionActivePowerLimit()
assert.Equal(s.T(), 10.0, limit)
assert.Equal(s.T(), true, changeable)
assert.Equal(s.T(), false, changeable)
assert.Nil(s.T(), err)

// The actual tests of the functionality is located in the util package
duration, changeable, err := s.sut.FailsafeDurationMinimum()
assert.Equal(s.T(), time.Duration(0), duration)
assert.Equal(s.T(), false, changeable)
assert.Equal(s.T(), true, changeable)
assert.Nil(s.T(), err)

err = s.sut.SetFailsafeDurationMinimum(time.Duration(time.Hour*1), true)
Expand All @@ -104,6 +104,9 @@ func (s *CsLPCSuite) Test_Failsafe() {
err = s.sut.SetFailsafeDurationMinimum(time.Duration(time.Hour*2), true)
assert.Nil(s.T(), err)

err = s.sut.SetFailsafeConsumptionActivePowerLimit(10, true)
assert.Nil(s.T(), err)

limit, changeable, err = s.sut.FailsafeConsumptionActivePowerLimit()
assert.Equal(s.T(), 10.0, limit)
assert.Equal(s.T(), true, changeable)
Expand Down
8 changes: 6 additions & 2 deletions usecases/cs/lpc/usecase.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/enbility/eebus-go/features/server"
ucapi "github.com/enbility/eebus-go/usecases/api"
"github.com/enbility/eebus-go/usecases/usecase"
"github.com/enbility/ship-go/logging"
spineapi "github.com/enbility/spine-go/api"
"github.com/enbility/spine-go/model"
"github.com/enbility/spine-go/spine"
Expand Down Expand Up @@ -124,11 +125,13 @@ func (e *LPC) approveOrDenyConsumptionLimit(msg *spineapi.Message, approve bool,
func (e *LPC) loadControlWriteCB(msg *spineapi.Message) {
if msg.RequestHeader == nil || msg.RequestHeader.MsgCounter == nil ||
msg.Cmd.LoadControlLimitListData == nil {
logging.Log().Debug("LPC loadControlWriteCB: invalid message")
return
}

_, limitId, err := e.loadControlServerAndLimitId()
if err != nil {
logging.Log().Debug("LPC loadControlWriteCB: error getting limit id")
return
}

Expand All @@ -137,6 +140,7 @@ func (e *LPC) loadControlWriteCB(msg *spineapi.Message) {
// we assume there is always only one limit
if data == nil || data.LoadControlLimitData == nil ||
len(data.LoadControlLimitData) == 0 {
logging.Log().Debug("LPC loadControlWriteCB: no data")
return
}

Expand Down Expand Up @@ -223,7 +227,7 @@ func (e *LPC) AddFeatures() {
_ = dcs.UpdateKeyValueDataForFilter(
model.DeviceConfigurationKeyValueDataType{
Value: value,
IsValueChangeable: util.Ptr(false),
IsValueChangeable: util.Ptr(true),
},
nil,
model.DeviceConfigurationKeyValueDescriptionDataType{
Expand All @@ -237,7 +241,7 @@ func (e *LPC) AddFeatures() {
_ = dcs.UpdateKeyValueDataForFilter(
model.DeviceConfigurationKeyValueDataType{
Value: value,
IsValueChangeable: util.Ptr(false),
IsValueChangeable: util.Ptr(true),
},
nil,
model.DeviceConfigurationKeyValueDescriptionDataType{
Expand Down
Loading