Skip to content

Commit 9356607

Browse files
xBlaz3kxlorenzodonini
authored andcommitted
fix: GetCompositeScheduleResponse not up to spec
1 parent d291e8c commit 9356607

File tree

2 files changed

+15
-14
lines changed

2 files changed

+15
-14
lines changed

ocpp2.0.1/smartcharging/get_composite_schedule.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@ type GetCompositeScheduleRequest struct {
4444
// This field definition of the GetCompositeSchedule response payload, sent by the Charging System to the CSMS in response to a GetCompositeScheduleRequest.
4545
// In case the request was invalid, or couldn't be processed, an error will be sent instead.
4646
type GetCompositeScheduleResponse struct {
47-
Status GetCompositeScheduleStatus `json:"status" validate:"required,getCompositeScheduleStatus"`
48-
EvseID int `json:"evseId" validate:"gte=0"`
49-
Schedule *CompositeSchedule `json:"schedule,omitempty" validate:"omitempty"`
47+
Status GetCompositeScheduleStatus `json:"status" validate:"required,getCompositeScheduleStatus"`
48+
StatusInfo *types.StatusInfo `json:"statusInfo,omitempty" validate:"omitempty"`
49+
Schedule *CompositeSchedule `json:"schedule,omitempty" validate:"omitempty"`
5050
}
5151

5252
// The CSMS MAY request the Charging System to report the Composite Charging Schedule by sending a GetCompositeScheduleRequest.
@@ -82,8 +82,8 @@ func NewGetCompositeScheduleRequest(duration int, evseId int) *GetCompositeSched
8282
}
8383

8484
// Creates a new GetCompositeScheduleResponse, containing all required fields. Optional fields may be set afterwards.
85-
func NewGetCompositeScheduleResponse(status GetCompositeScheduleStatus, evseId int) *GetCompositeScheduleResponse {
86-
return &GetCompositeScheduleResponse{Status: status, EvseID: evseId}
85+
func NewGetCompositeScheduleResponse(status GetCompositeScheduleStatus) *GetCompositeScheduleResponse {
86+
return &GetCompositeScheduleResponse{Status: status}
8787
}
8888

8989
func init() {

ocpp2.0.1_test/get_composite_schedule_test.go

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,14 @@ func (suite *OcppV2TestSuite) TestGetCompositeScheduleConfirmationValidation() {
3838
ChargingSchedule: chargingSchedule,
3939
}
4040
var confirmationTable = []GenericTestEntry{
41-
{smartcharging.GetCompositeScheduleResponse{Status: smartcharging.GetCompositeScheduleStatusAccepted, EvseID: 1, Schedule: &compositeSchedule}, true},
42-
{smartcharging.GetCompositeScheduleResponse{Status: smartcharging.GetCompositeScheduleStatusAccepted, EvseID: 1, Schedule: &smartcharging.CompositeSchedule{}}, true},
43-
{smartcharging.GetCompositeScheduleResponse{Status: smartcharging.GetCompositeScheduleStatusAccepted, EvseID: 1}, true},
41+
{smartcharging.GetCompositeScheduleResponse{Status: smartcharging.GetCompositeScheduleStatusAccepted, StatusInfo: types.NewStatusInfo("reasoncode", ""), Schedule: &compositeSchedule}, true},
42+
{smartcharging.GetCompositeScheduleResponse{Status: smartcharging.GetCompositeScheduleStatusAccepted, StatusInfo: types.NewStatusInfo("reasoncode", ""), Schedule: &smartcharging.CompositeSchedule{}}, true},
43+
{smartcharging.GetCompositeScheduleResponse{Status: smartcharging.GetCompositeScheduleStatusAccepted, StatusInfo: types.NewStatusInfo("reasoncode", "")}, true},
4444
{smartcharging.GetCompositeScheduleResponse{Status: smartcharging.GetCompositeScheduleStatusAccepted}, true},
4545
{smartcharging.GetCompositeScheduleResponse{}, false},
4646
{smartcharging.GetCompositeScheduleResponse{Status: "invalidGetCompositeScheduleStatus"}, false},
47-
{smartcharging.GetCompositeScheduleResponse{Status: smartcharging.GetCompositeScheduleStatusAccepted, EvseID: -1}, false},
48-
{smartcharging.GetCompositeScheduleResponse{Status: smartcharging.GetCompositeScheduleStatusAccepted, EvseID: 1, Schedule: &smartcharging.CompositeSchedule{StartDateTime: types.NewDateTime(time.Now()), ChargingSchedule: types.NewChargingSchedule(1, "invalidChargingRateUnit")}}, false},
47+
{smartcharging.GetCompositeScheduleResponse{Status: smartcharging.GetCompositeScheduleStatusAccepted, StatusInfo: types.NewStatusInfo("invalidreasoncodeasitslongerthan20", "")}, false},
48+
{smartcharging.GetCompositeScheduleResponse{Status: smartcharging.GetCompositeScheduleStatusAccepted, StatusInfo: types.NewStatusInfo("", ""), Schedule: &smartcharging.CompositeSchedule{StartDateTime: types.NewDateTime(time.Now()), ChargingSchedule: types.NewChargingSchedule(1, "invalidChargingRateUnit")}}, false},
4949
}
5050
ExecuteGenericTestTable(t, confirmationTable)
5151
}
@@ -66,12 +66,13 @@ func (suite *OcppV2TestSuite) TestGetCompositeScheduleE2EMocked() {
6666
chargingSchedule.Duration = newInt(600)
6767
chargingSchedule.StartSchedule = types.NewDateTime(time.Now())
6868
chargingSchedule.MinChargingRate = newFloat(6.0)
69+
statusInfo := types.NewStatusInfo("reasonCode", "")
6970
compositeSchedule := smartcharging.CompositeSchedule{StartDateTime: scheduleStart, ChargingSchedule: chargingSchedule}
7071
requestJson := fmt.Sprintf(`[2,"%v","%v",{"duration":%v,"chargingRateUnit":"%v","evseId":%v}]`,
7172
messageId, smartcharging.GetCompositeScheduleFeatureName, duration, chargingRateUnit, evseID)
72-
responseJson := fmt.Sprintf(`[3,"%v",{"status":"%v","evseId":%v,"schedule":{"startDateTime":"%v","chargingSchedule":{"id":%v,"startSchedule":"%v","duration":%v,"chargingRateUnit":"%v","minChargingRate":%v,"chargingSchedulePeriod":[{"startPeriod":%v,"limit":%v,"numberPhases":%v}]}}}]`,
73-
messageId, status, evseID, compositeSchedule.StartDateTime.FormatTimestamp(), chargingSchedule.ID, chargingSchedule.StartSchedule.FormatTimestamp(), *chargingSchedule.Duration, chargingSchedule.ChargingRateUnit, *chargingSchedule.MinChargingRate, chargingSchedulePeriod.StartPeriod, chargingSchedulePeriod.Limit, *chargingSchedulePeriod.NumberPhases)
74-
getCompositeScheduleConfirmation := smartcharging.NewGetCompositeScheduleResponse(status, evseID)
73+
responseJson := fmt.Sprintf(`[3,"%v",{"status":"%v","statusInfo":{"reasonCode":"%v"},"schedule":{"startDateTime":"%v","chargingSchedule":{"id":%v,"startSchedule":"%v","duration":%v,"chargingRateUnit":"%v","minChargingRate":%v,"chargingSchedulePeriod":[{"startPeriod":%v,"limit":%v,"numberPhases":%v}]}}}]`,
74+
messageId, status, statusInfo.ReasonCode, compositeSchedule.StartDateTime.FormatTimestamp(), chargingSchedule.ID, chargingSchedule.StartSchedule.FormatTimestamp(), *chargingSchedule.Duration, chargingSchedule.ChargingRateUnit, *chargingSchedule.MinChargingRate, chargingSchedulePeriod.StartPeriod, chargingSchedulePeriod.Limit, *chargingSchedulePeriod.NumberPhases)
75+
getCompositeScheduleConfirmation := smartcharging.NewGetCompositeScheduleResponse(status)
7576
getCompositeScheduleConfirmation.Schedule = &compositeSchedule
7677
channel := NewMockWebSocket(wsId)
7778

@@ -95,7 +96,7 @@ func (suite *OcppV2TestSuite) TestGetCompositeScheduleE2EMocked() {
9596
require.Nil(t, err)
9697
require.NotNil(t, confirmation)
9798
assert.Equal(t, status, confirmation.Status)
98-
assert.Equal(t, evseID, confirmation.EvseID)
99+
assert.Equal(t, statusInfo.ReasonCode, confirmation.StatusInfo.ReasonCode)
99100
require.NotNil(t, confirmation.Schedule)
100101
require.NotNil(t, confirmation.Schedule.StartDateTime)
101102
assert.Equal(t, compositeSchedule.StartDateTime.FormatTimestamp(), confirmation.Schedule.StartDateTime.FormatTimestamp())

0 commit comments

Comments
 (0)