Skip to content

Commit afa3c9f

Browse files
committed
Add common component/variable types
Signed-off-by: Lorenzo Donini <[email protected]>
1 parent d367704 commit afa3c9f

File tree

2 files changed

+51
-1
lines changed

2 files changed

+51
-1
lines changed

ocpp2.0/common.go

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,10 +320,36 @@ type IdTokenInfo struct {
320320
PersonalMessage *MessageContent `json:"personalMessage,omitempty"`
321321
}
322322

323+
// NewIdTokenInfo creates an IdTokenInfo. Optional parameters may be set afterwards on the initialized struct.
323324
func NewIdTokenInfo(status AuthorizationStatus) *IdTokenInfo {
324325
return &IdTokenInfo{Status: status}
325326
}
326327

328+
// EVSE represents the Electric Vehicle Supply Equipment, formerly referred to as connector(s).
329+
type EVSE struct {
330+
ID int `json:"id" validate:"gte=0"` // The EVSE Identifier. When 0, the ID references the Charging Station as a whole.
331+
ConnectorID *int `json:"connectorId,omitempty" validate:"omitempty,gte=0"` // An id to designate a specific connector (on an EVSE) by connector index number.
332+
}
333+
334+
// Component represents a physical or logical component.
335+
type Component struct {
336+
Name string `json:"name" validate:"required,max=50"` // Name of the component. Name should be taken from the list of standardized component names whenever possible. Case Insensitive. strongly advised to use Camel Case.
337+
Instance string `json:"instance,omitempty" validate:"omitempty,max=50"` // Name of instance in case the component exists as multiple instances. Case Insensitive. strongly advised to use Camel Case.
338+
EVSE *EVSE `json:"evse,omitempty" validate:"omitempty"` // Specifies the EVSE when component is located at EVSE level, also specifies the connector when component is located at Connector level.
339+
}
340+
341+
// Variable is a reference key to a component-variable.
342+
type Variable struct {
343+
Name string `json:"name" validate:"required,max=50"` // Name of the variable. Name should be taken from the list of standardized variable names whenever possible. Case Insensitive. strongly advised to use Camel Case.
344+
Instance string `json:"instance,omitempty" validate:"omitempty,max=50"` // Name of instance in case the variable exists as multiple instances. Case Insensitive. strongly advised to use Camel Case.
345+
}
346+
347+
// ComponentVariable is used to report components, variables and variable attributes and characteristics.
348+
type ComponentVariable struct {
349+
Component Component `json:"component" validate:"required"` // Component for which a report of Variable is requested.
350+
Variable Variable `json:"variable" validate:"required"` // Variable for which report is requested.
351+
}
352+
327353
// Charging Profiles
328354
type ChargingProfilePurposeType string
329355
type ChargingProfileKindType string
@@ -622,7 +648,8 @@ func validateDateTimeLt(dateTime DateTime, than time.Time) bool {
622648
return dateTime.Before(than)
623649
}
624650

625-
// Initialize validator
651+
// Validator used for validating all OCPP 2.0 messages.
652+
// Any additional custom validations must be added to this object for automatic validation.
626653
var Validate = ocppj.Validate
627654

628655
func init() {

ocpp2.0_test/common_test.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,29 @@ func (suite *OcppV2TestSuite) TestChargingScheduleValidation() {
7676
ExecuteGenericTestTable(t, testTable)
7777
}
7878

79+
func (suite *OcppV2TestSuite) TestComponentVariableValidation() {
80+
t := suite.T()
81+
var testTable = []GenericTestEntry{
82+
{ocpp2.ComponentVariable{Component: ocpp2.Component{ Name: "component1", Instance: "instance1", EVSE: &ocpp2.EVSE{ID: 2, ConnectorID: newInt(2)}}, Variable: ocpp2.Variable{ Name: "variable1", Instance: "instance1"}}, true},
83+
{ocpp2.ComponentVariable{Component: ocpp2.Component{ Name: "component1", Instance: "instance1", EVSE: &ocpp2.EVSE{ID: 2}}, Variable: ocpp2.Variable{ Name: "variable1", Instance: "instance1"}}, true},
84+
{ocpp2.ComponentVariable{Component: ocpp2.Component{ Name: "component1", EVSE: &ocpp2.EVSE{ID: 2}}, Variable: ocpp2.Variable{ Name: "variable1", Instance: "instance1"}}, true},
85+
{ocpp2.ComponentVariable{Component: ocpp2.Component{ Name: "component1", EVSE: &ocpp2.EVSE{ID: 2}}, Variable: ocpp2.Variable{ Name: "variable1"}}, true},
86+
{ocpp2.ComponentVariable{Component: ocpp2.Component{ Name: "component1", EVSE: &ocpp2.EVSE{}}, Variable: ocpp2.Variable{ Name: "variable1"}}, true},
87+
{ocpp2.ComponentVariable{Component: ocpp2.Component{ Name: "component1"}, Variable: ocpp2.Variable{ Name: "variable1"}}, true},
88+
{ocpp2.ComponentVariable{Component: ocpp2.Component{ Name: "component1"}, Variable: ocpp2.Variable{}}, false},
89+
{ocpp2.ComponentVariable{Component: ocpp2.Component{}, Variable: ocpp2.Variable{ Name: "variable1"}}, false},
90+
{ocpp2.ComponentVariable{Variable: ocpp2.Variable{ Name: "variable1"}}, false},
91+
{ocpp2.ComponentVariable{Component: ocpp2.Component{ Name: "component1"}}, false},
92+
{ocpp2.ComponentVariable{Component: ocpp2.Component{ Name: ">50................................................", Instance: "instance1", EVSE: &ocpp2.EVSE{ID: 2, ConnectorID: newInt(2)}}, Variable: ocpp2.Variable{ Name: "variable1", Instance: "instance1"}}, false},
93+
{ocpp2.ComponentVariable{Component: ocpp2.Component{ Name: "component1", Instance: ">50................................................", EVSE: &ocpp2.EVSE{ID: 2, ConnectorID: newInt(2)}}, Variable: ocpp2.Variable{ Name: "variable1", Instance: "instance1"}}, false},
94+
{ocpp2.ComponentVariable{Component: ocpp2.Component{ Name: "component1", Instance: "instance1", EVSE: &ocpp2.EVSE{ID: 2, ConnectorID: newInt(2)}}, Variable: ocpp2.Variable{ Name: ">50................................................", Instance: "instance1"}}, false},
95+
{ocpp2.ComponentVariable{Component: ocpp2.Component{ Name: "component1", Instance: "instance1", EVSE: &ocpp2.EVSE{ID: 2, ConnectorID: newInt(2)}}, Variable: ocpp2.Variable{ Name: "variable1", Instance: ">50................................................"}}, false},
96+
{ocpp2.ComponentVariable{Component: ocpp2.Component{ Name: "component1", Instance: "instance1", EVSE: &ocpp2.EVSE{ID: 2, ConnectorID: newInt(-2)}}, Variable: ocpp2.Variable{ Name: "variable1", Instance: "instance1"}}, false},
97+
{ocpp2.ComponentVariable{Component: ocpp2.Component{ Name: "component1", Instance: "instance1", EVSE: &ocpp2.EVSE{ID: -2, ConnectorID: newInt(2)}}, Variable: ocpp2.Variable{ Name: "variable1", Instance: "instance1"}}, false},
98+
}
99+
ExecuteGenericTestTable(t, testTable)
100+
}
101+
79102
func (suite *OcppV2TestSuite) TestChargingProfileValidation() {
80103
t := suite.T()
81104
chargingSchedule := ocpp2.NewChargingSchedule(ocpp2.ChargingRateUnitWatts, ocpp2.NewChargingSchedulePeriod(0, 10.0), ocpp2.NewChargingSchedulePeriod(100, 8.0))

0 commit comments

Comments
 (0)