Skip to content

Commit

Permalink
Merge branch 'lorenzodonini:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
alessioerosferri authored Apr 3, 2024
2 parents 6d7b7fa + 9b48003 commit 7ba485e
Show file tree
Hide file tree
Showing 25 changed files with 166 additions and 128 deletions.
2 changes: 1 addition & 1 deletion ocpp1.6/core/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ type ChargePointHandler interface {
}

// THe profile name
var ProfileName = "core"
var ProfileName = "Core"

// Provides support for Basic Charge Point functionality comparable with OCPP 1.5.
var Profile = ocpp.NewProfile(
Expand Down
2 changes: 1 addition & 1 deletion ocpp1.6/firmware/firmware.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ type ChargePointHandler interface {
}

// The profile name
const ProfileName = "firmwareManagement"
const ProfileName = "FirmwareManagement"

// Provides support for firmware update management and diagnostic log file download.
var Profile = ocpp.NewProfile(
Expand Down
2 changes: 1 addition & 1 deletion ocpp1.6/localauth/local_auth_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ type ChargePointHandler interface {
}

// The profile name
const ProfileName = "localAuthList"
const ProfileName = "LocalAuthListManagement"

// Provides support for managing the local authorization list in Charge Points.
var Profile = ocpp.NewProfile(
Expand Down
5 changes: 3 additions & 2 deletions ocpp1.6/remotetrigger/trigger_message.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package remotetrigger

import (
"reflect"

"github.com/lorenzodonini/ocpp-go/ocpp1.6/core"
"github.com/lorenzodonini/ocpp-go/ocpp1.6/firmware"
"github.com/lorenzodonini/ocpp-go/ocpp1.6/types"
"gopkg.in/go-playground/validator.v9"
"reflect"
)

// -------------------- Trigger Message (CS -> CP) --------------------
Expand Down Expand Up @@ -47,7 +48,7 @@ func isValidMessageTrigger(fl validator.FieldLevel) bool {
// The field definition of the TriggerMessage request payload sent by the Central System to the Charge Point.
type TriggerMessageRequest struct {
RequestedMessage MessageTrigger `json:"requestedMessage" validate:"required,messageTrigger16"`
ConnectorId *int `json:"connectorId,omitempty" validate:"omitempty,gt=0"`
ConnectorId *int `json:"connectorId,omitempty" validate:"omitempty,gte=0"`
}

// This field definition of the TriggerMessage confirmation payload, sent by the Charge Point to the Central System in response to a TriggerMessageRequest.
Expand Down
2 changes: 1 addition & 1 deletion ocpp1.6/reservation/reservation.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ type ChargePointHandler interface {
}

// The profile name
const ProfileName = "reservation"
const ProfileName = "Reservation"

// Provides support for for reservation of a Charge Point.
var Profile = ocpp.NewProfile(
Expand Down
7 changes: 4 additions & 3 deletions ocpp1.6_test/cancel_reservation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package ocpp16_test

import (
"fmt"

"github.com/lorenzodonini/ocpp-go/ocpp1.6/reservation"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
Expand All @@ -11,7 +12,7 @@ import (
// Test
func (suite *OcppV16TestSuite) TestCancelReservationRequestValidation() {
t := suite.T()
var requestTable = []GenericTestEntry{
requestTable := []GenericTestEntry{
{reservation.CancelReservationRequest{ReservationId: 42}, true},
{reservation.CancelReservationRequest{}, true},
{reservation.CancelReservationRequest{ReservationId: -1}, true},
Expand All @@ -21,7 +22,7 @@ func (suite *OcppV16TestSuite) TestCancelReservationRequestValidation() {

func (suite *OcppV16TestSuite) TestCancelReservationConfirmationValidation() {
t := suite.T()
var confirmationTable = []GenericTestEntry{
confirmationTable := []GenericTestEntry{
{reservation.CancelReservationConfirmation{Status: reservation.CancelReservationStatusAccepted}, true},
{reservation.CancelReservationConfirmation{Status: "invalidCancelReservationStatus"}, false},
{reservation.CancelReservationConfirmation{}, false},
Expand Down Expand Up @@ -50,7 +51,7 @@ func (suite *OcppV16TestSuite) TestCancelReservationE2EMocked() {
})
setupDefaultCentralSystemHandlers(suite, nil, expectedCentralSystemOptions{clientId: wsId, rawWrittenMessage: []byte(requestJson), forwardWrittenMessage: true})
setupDefaultChargePointHandlers(suite, nil, expectedChargePointOptions{serverUrl: wsUrl, clientId: wsId, createChannelOnStart: true, channel: channel, rawWrittenMessage: []byte(responseJson), forwardWrittenMessage: true})
suite.chargePoint.SetReservationHandler(reservationListener)
suite.chargePoint.SetReservationHandler(&reservationListener)
// Run Test
suite.centralSystem.Start(8887, "somePath")
err := suite.chargePoint.Start(wsUrl)
Expand Down
7 changes: 4 additions & 3 deletions ocpp1.6_test/clear_charging_profile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package ocpp16_test

import (
"fmt"

"github.com/lorenzodonini/ocpp-go/ocpp1.6/smartcharging"
"github.com/lorenzodonini/ocpp-go/ocpp1.6/types"
"github.com/stretchr/testify/assert"
Expand All @@ -12,7 +13,7 @@ import (
// Test
func (suite *OcppV16TestSuite) TestClearChargingProfileRequestValidation() {
t := suite.T()
var requestTable = []GenericTestEntry{
requestTable := []GenericTestEntry{
{smartcharging.ClearChargingProfileRequest{Id: newInt(1), ConnectorId: newInt(1), ChargingProfilePurpose: types.ChargingProfilePurposeChargePointMaxProfile, StackLevel: newInt(1)}, true},
{smartcharging.ClearChargingProfileRequest{Id: newInt(1), ConnectorId: newInt(1), ChargingProfilePurpose: types.ChargingProfilePurposeChargePointMaxProfile}, true},
{smartcharging.ClearChargingProfileRequest{Id: newInt(1), ConnectorId: newInt(1)}, true},
Expand All @@ -28,7 +29,7 @@ func (suite *OcppV16TestSuite) TestClearChargingProfileRequestValidation() {

func (suite *OcppV16TestSuite) TestClearChargingProfileConfirmationValidation() {
t := suite.T()
var confirmationTable = []GenericTestEntry{
confirmationTable := []GenericTestEntry{
{smartcharging.ClearChargingProfileConfirmation{Status: smartcharging.ClearChargingProfileStatusAccepted}, true},
{smartcharging.ClearChargingProfileConfirmation{Status: "invalidClearChargingProfileStatus"}, false},
{smartcharging.ClearChargingProfileConfirmation{}, false},
Expand Down Expand Up @@ -64,7 +65,7 @@ func (suite *OcppV16TestSuite) TestClearChargingProfileE2EMocked() {
})
setupDefaultCentralSystemHandlers(suite, nil, expectedCentralSystemOptions{clientId: wsId, rawWrittenMessage: []byte(requestJson), forwardWrittenMessage: true})
setupDefaultChargePointHandlers(suite, nil, expectedChargePointOptions{serverUrl: wsUrl, clientId: wsId, createChannelOnStart: true, channel: channel, rawWrittenMessage: []byte(responseJson), forwardWrittenMessage: true})
suite.chargePoint.SetSmartChargingHandler(smartChargingListener)
suite.chargePoint.SetSmartChargingHandler(&smartChargingListener)
// Run Test
suite.centralSystem.Start(8887, "somePath")
err := suite.chargePoint.Start(wsUrl)
Expand Down
14 changes: 7 additions & 7 deletions ocpp1.6_test/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func newFloat(f float64) *float64 {

// Test
func (suite *OcppV16TestSuite) TestIdTagInfoValidation() {
var testTable = []GenericTestEntry{
testTable := []GenericTestEntry{
{types.IdTagInfo{ExpiryDate: types.NewDateTime(time.Now()), ParentIdTag: "00000", Status: types.AuthorizationStatusAccepted}, true},
{types.IdTagInfo{ExpiryDate: types.NewDateTime(time.Now()), Status: types.AuthorizationStatusAccepted}, true},
{types.IdTagInfo{Status: types.AuthorizationStatusAccepted}, true},
Expand All @@ -38,7 +38,7 @@ func (suite *OcppV16TestSuite) TestIdTagInfoValidation() {

func (suite *OcppV16TestSuite) TestChargingSchedulePeriodValidation() {
t := suite.T()
var testTable = []GenericTestEntry{
testTable := []GenericTestEntry{
{types.ChargingSchedulePeriod{StartPeriod: 0, Limit: 10.0, NumberPhases: newInt(3)}, true},
{types.ChargingSchedulePeriod{StartPeriod: 0, Limit: 10.0}, true},
{types.ChargingSchedulePeriod{StartPeriod: 0}, true},
Expand All @@ -55,7 +55,7 @@ func (suite *OcppV16TestSuite) TestChargingScheduleValidation() {
chargingSchedulePeriods := make([]types.ChargingSchedulePeriod, 2)
chargingSchedulePeriods[0] = types.NewChargingSchedulePeriod(0, 10.0)
chargingSchedulePeriods[1] = types.NewChargingSchedulePeriod(100, 8.0)
var testTable = []GenericTestEntry{
testTable := []GenericTestEntry{
{types.ChargingSchedule{Duration: newInt(0), StartSchedule: types.NewDateTime(time.Now()), ChargingRateUnit: types.ChargingRateUnitWatts, ChargingSchedulePeriod: chargingSchedulePeriods, MinChargingRate: newFloat(1.0)}, true},
{types.ChargingSchedule{Duration: newInt(0), ChargingRateUnit: types.ChargingRateUnitWatts, ChargingSchedulePeriod: chargingSchedulePeriods, MinChargingRate: newFloat(1.0)}, true},
{types.ChargingSchedule{Duration: newInt(0), ChargingRateUnit: types.ChargingRateUnitWatts, ChargingSchedulePeriod: chargingSchedulePeriods}, true},
Expand All @@ -72,7 +72,7 @@ func (suite *OcppV16TestSuite) TestChargingScheduleValidation() {
func (suite *OcppV16TestSuite) TestChargingProfileValidation() {
t := suite.T()
chargingSchedule := types.NewChargingSchedule(types.ChargingRateUnitWatts, types.NewChargingSchedulePeriod(0, 10.0), types.NewChargingSchedulePeriod(100, 8.0))
var testTable = []GenericTestEntry{
testTable := []GenericTestEntry{
{types.ChargingProfile{ChargingProfileId: 1, TransactionId: 1, StackLevel: 1, ChargingProfilePurpose: types.ChargingProfilePurposeChargePointMaxProfile, ChargingProfileKind: types.ChargingProfileKindAbsolute, RecurrencyKind: types.RecurrencyKindDaily, ValidFrom: types.NewDateTime(time.Now()), ValidTo: types.NewDateTime(time.Now().Add(8 * time.Hour)), ChargingSchedule: chargingSchedule}, true},
{types.ChargingProfile{ChargingProfileId: 1, StackLevel: 1, ChargingProfilePurpose: types.ChargingProfilePurposeChargePointMaxProfile, ChargingProfileKind: types.ChargingProfileKindAbsolute, ChargingSchedule: chargingSchedule}, true},
{types.ChargingProfile{ChargingProfileId: 1, StackLevel: 1, ChargingProfilePurpose: types.ChargingProfilePurposeChargePointMaxProfile, ChargingProfileKind: types.ChargingProfileKindAbsolute}, false},
Expand All @@ -91,7 +91,7 @@ func (suite *OcppV16TestSuite) TestChargingProfileValidation() {

func (suite *OcppV16TestSuite) TestSampledValueValidation() {
t := suite.T()
var testTable = []GenericTestEntry{
testTable := []GenericTestEntry{
{types.SampledValue{Value: "value", Context: types.ReadingContextTransactionEnd, Format: types.ValueFormatRaw, Measurand: types.MeasurandPowerActiveExport, Phase: types.PhaseL2, Location: types.LocationBody, Unit: types.UnitOfMeasureKW}, true},
{types.SampledValue{Value: "value", Context: types.ReadingContextTransactionEnd, Format: types.ValueFormatRaw, Measurand: types.MeasurandPowerActiveExport, Phase: types.PhaseL2, Location: types.LocationBody}, true},
{types.SampledValue{Value: "value", Context: types.ReadingContextTransactionEnd, Format: types.ValueFormatRaw, Measurand: types.MeasurandPowerActiveExport, Phase: types.PhaseL2}, true},
Expand All @@ -110,7 +110,7 @@ func (suite *OcppV16TestSuite) TestSampledValueValidation() {
}

func (suite *OcppV16TestSuite) TestMeterValueValidation() {
var testTable = []GenericTestEntry{
testTable := []GenericTestEntry{
{types.MeterValue{Timestamp: types.NewDateTime(time.Now()), SampledValue: []types.SampledValue{{Value: "value"}, {Value: "value2", Unit: types.UnitOfMeasureKW}}}, true},
{types.MeterValue{Timestamp: types.NewDateTime(time.Now()), SampledValue: []types.SampledValue{{Value: "value"}}}, true},
{types.MeterValue{Timestamp: types.NewDateTime(time.Now()), SampledValue: []types.SampledValue{}}, false},
Expand Down Expand Up @@ -180,5 +180,5 @@ func (suite *OcppV16TestSuite) TestMarshalDateTime() {
func (suite *OcppV16TestSuite) TestNowDateTime() {
now := types.Now()
suite.NotNil(now)
suite.True(time.Now().Sub(now.Time) < 1*time.Second)
suite.True(time.Since(now.Time) < 1*time.Second)
}
7 changes: 4 additions & 3 deletions ocpp1.6_test/diagnostics_status_notification_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package ocpp16_test

import (
"fmt"

"github.com/lorenzodonini/ocpp-go/ocpp1.6/firmware"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
Expand All @@ -11,7 +12,7 @@ import (
// Test
func (suite *OcppV16TestSuite) TestDiagnosticsStatusNotificationRequestValidation() {
t := suite.T()
var requestTable = []GenericTestEntry{
requestTable := []GenericTestEntry{
{firmware.DiagnosticsStatusNotificationRequest{Status: firmware.DiagnosticsStatusUploaded}, true},
{firmware.DiagnosticsStatusNotificationRequest{}, false},
{firmware.DiagnosticsStatusNotificationRequest{Status: "invalidDiagnosticsStatus"}, false},
Expand All @@ -21,7 +22,7 @@ func (suite *OcppV16TestSuite) TestDiagnosticsStatusNotificationRequestValidatio

func (suite *OcppV16TestSuite) TestDiagnosticsStatusNotificationConfirmationValidation() {
t := suite.T()
var confirmationTable = []GenericTestEntry{
confirmationTable := []GenericTestEntry{
{firmware.DiagnosticsStatusNotificationConfirmation{}, true},
}
ExecuteGenericTestTable(t, confirmationTable)
Expand All @@ -46,7 +47,7 @@ func (suite *OcppV16TestSuite) TestDiagnosticsStatusNotificationE2EMocked() {
assert.Equal(t, status, request.Status)
})
setupDefaultCentralSystemHandlers(suite, nil, expectedCentralSystemOptions{clientId: wsId, rawWrittenMessage: []byte(responseJson), forwardWrittenMessage: true})
suite.centralSystem.SetFirmwareManagementHandler(firmwareListener)
suite.centralSystem.SetFirmwareManagementHandler(&firmwareListener)
setupDefaultChargePointHandlers(suite, nil, expectedChargePointOptions{serverUrl: wsUrl, clientId: wsId, createChannelOnStart: true, channel: channel, rawWrittenMessage: []byte(requestJson), forwardWrittenMessage: true})
// Run Test
suite.centralSystem.Start(8887, "somePath")
Expand Down
7 changes: 4 additions & 3 deletions ocpp1.6_test/firmware_status_notification_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package ocpp16_test

import (
"fmt"

"github.com/lorenzodonini/ocpp-go/ocpp1.6/firmware"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
Expand All @@ -11,7 +12,7 @@ import (
// Test
func (suite *OcppV16TestSuite) TestFirmwareStatusNotificationRequestValidation() {
t := suite.T()
var requestTable = []GenericTestEntry{
requestTable := []GenericTestEntry{
{firmware.FirmwareStatusNotificationRequest{Status: firmware.FirmwareStatusDownloaded}, true},
{firmware.FirmwareStatusNotificationRequest{}, false},
{firmware.FirmwareStatusNotificationRequest{Status: "invalidFirmwareStatus"}, false},
Expand All @@ -21,7 +22,7 @@ func (suite *OcppV16TestSuite) TestFirmwareStatusNotificationRequestValidation()

func (suite *OcppV16TestSuite) TestFirmwareStatusNotificationConfirmationValidation() {
t := suite.T()
var confirmationTable = []GenericTestEntry{
confirmationTable := []GenericTestEntry{
{firmware.FirmwareStatusNotificationConfirmation{}, true},
}
ExecuteGenericTestTable(t, confirmationTable)
Expand All @@ -46,7 +47,7 @@ func (suite *OcppV16TestSuite) TestFirmwareStatusNotificationE2EMocked() {
assert.Equal(t, status, request.Status)
})
setupDefaultCentralSystemHandlers(suite, nil, expectedCentralSystemOptions{clientId: wsId, rawWrittenMessage: []byte(responseJson), forwardWrittenMessage: true})
suite.centralSystem.SetFirmwareManagementHandler(firmwareListener)
suite.centralSystem.SetFirmwareManagementHandler(&firmwareListener)
setupDefaultChargePointHandlers(suite, nil, expectedChargePointOptions{serverUrl: wsUrl, clientId: wsId, createChannelOnStart: true, channel: channel, rawWrittenMessage: []byte(requestJson), forwardWrittenMessage: true})
// Run Test
suite.centralSystem.Start(8887, "somePath")
Expand Down
9 changes: 5 additions & 4 deletions ocpp1.6_test/get_composite_schedule_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,19 @@ package ocpp16_test

import (
"fmt"
"time"

"github.com/lorenzodonini/ocpp-go/ocpp1.6/smartcharging"
"github.com/lorenzodonini/ocpp-go/ocpp1.6/types"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/require"
"time"
)

// Test
func (suite *OcppV16TestSuite) TestGetCompositeScheduleRequestValidation() {
t := suite.T()
var requestTable = []GenericTestEntry{
requestTable := []GenericTestEntry{
{smartcharging.GetCompositeScheduleRequest{ConnectorId: 1, Duration: 600, ChargingRateUnit: types.ChargingRateUnitWatts}, true},
{smartcharging.GetCompositeScheduleRequest{ConnectorId: 1, Duration: 600}, true},
{smartcharging.GetCompositeScheduleRequest{ConnectorId: 1}, true},
Expand All @@ -28,7 +29,7 @@ func (suite *OcppV16TestSuite) TestGetCompositeScheduleRequestValidation() {
func (suite *OcppV16TestSuite) TestGetCompositeScheduleConfirmationValidation() {
t := suite.T()
chargingSchedule := types.NewChargingSchedule(types.ChargingRateUnitWatts, types.NewChargingSchedulePeriod(0, 10.0))
var confirmationTable = []GenericTestEntry{
confirmationTable := []GenericTestEntry{
{smartcharging.GetCompositeScheduleConfirmation{Status: smartcharging.GetCompositeScheduleStatusAccepted, ConnectorId: newInt(1), ScheduleStart: types.NewDateTime(time.Now()), ChargingSchedule: chargingSchedule}, true},
{smartcharging.GetCompositeScheduleConfirmation{Status: smartcharging.GetCompositeScheduleStatusAccepted, ConnectorId: newInt(1), ScheduleStart: types.NewDateTime(time.Now())}, true},
{smartcharging.GetCompositeScheduleConfirmation{Status: smartcharging.GetCompositeScheduleStatusAccepted, ConnectorId: newInt(1)}, true},
Expand Down Expand Up @@ -75,7 +76,7 @@ func (suite *OcppV16TestSuite) TestGetCompositeScheduleE2EMocked() {
})
setupDefaultCentralSystemHandlers(suite, nil, expectedCentralSystemOptions{clientId: wsId, rawWrittenMessage: []byte(requestJson), forwardWrittenMessage: true})
setupDefaultChargePointHandlers(suite, nil, expectedChargePointOptions{serverUrl: wsUrl, clientId: wsId, createChannelOnStart: true, channel: channel, rawWrittenMessage: []byte(responseJson), forwardWrittenMessage: true})
suite.chargePoint.SetSmartChargingHandler(smartChargingListener)
suite.chargePoint.SetSmartChargingHandler(&smartChargingListener)
// Run Test
suite.centralSystem.Start(8887, "somePath")
err := suite.chargePoint.Start(wsUrl)
Expand Down
6 changes: 3 additions & 3 deletions ocpp1.6_test/get_diagnostics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
// Test
func (suite *OcppV16TestSuite) TestGetDiagnosticsRequestValidation() {
t := suite.T()
var requestTable = []GenericTestEntry{
requestTable := []GenericTestEntry{
{firmware.GetDiagnosticsRequest{Location: "ftp:some/path", Retries: newInt(10), RetryInterval: newInt(10), StartTime: types.NewDateTime(time.Now()), StopTime: types.NewDateTime(time.Now())}, true},
{firmware.GetDiagnosticsRequest{Location: "ftp:some/path", Retries: newInt(10), RetryInterval: newInt(10), StartTime: types.NewDateTime(time.Now())}, true},
{firmware.GetDiagnosticsRequest{Location: "ftp:some/path", Retries: newInt(10), RetryInterval: newInt(10)}, true},
Expand All @@ -30,7 +30,7 @@ func (suite *OcppV16TestSuite) TestGetDiagnosticsRequestValidation() {

func (suite *OcppV16TestSuite) TestGetDiagnosticsConfirmationValidation() {
t := suite.T()
var confirmationTable = []GenericTestEntry{
confirmationTable := []GenericTestEntry{
{firmware.GetDiagnosticsConfirmation{FileName: "someFileName"}, true},
{firmware.GetDiagnosticsConfirmation{FileName: ""}, true},
{firmware.GetDiagnosticsConfirmation{}, true},
Expand Down Expand Up @@ -71,7 +71,7 @@ func (suite *OcppV16TestSuite) TestGetDiagnosticsE2EMocked() {
assertDateTimeEquality(t, *stopTime, *request.StopTime)
})
setupDefaultCentralSystemHandlers(suite, nil, expectedCentralSystemOptions{clientId: wsId, rawWrittenMessage: []byte(requestJson), forwardWrittenMessage: true})
suite.chargePoint.SetFirmwareManagementHandler(firmwareListener)
suite.chargePoint.SetFirmwareManagementHandler(&firmwareListener)
setupDefaultChargePointHandlers(suite, nil, expectedChargePointOptions{serverUrl: wsUrl, clientId: wsId, createChannelOnStart: true, channel: channel, rawWrittenMessage: []byte(responseJson), forwardWrittenMessage: true})
// Run Test
suite.centralSystem.Start(8887, "somePath")
Expand Down
Loading

0 comments on commit 7ba485e

Please sign in to comment.