Ocpp: add optional support for profileKind "relative" (#22139)
This commit is contained in:
parent
da6e506c0b
commit
858deaa294
2 changed files with 26 additions and 17 deletions
|
|
@ -44,8 +44,9 @@ type OCPP struct {
|
|||
enabled bool
|
||||
current float64
|
||||
|
||||
stackLevelZero bool
|
||||
lp loadpoint.API
|
||||
stackLevelZero bool
|
||||
profileKindRelative bool
|
||||
lp loadpoint.API
|
||||
}
|
||||
|
||||
const defaultIdTag = "evcc" // RemoteStartTransaction only
|
||||
|
|
@ -71,9 +72,10 @@ func NewOCPPFromConfig(ctx context.Context, other map[string]interface{}) (api.C
|
|||
AutoStart bool // TODO deprecated
|
||||
NoStop bool // TODO deprecated
|
||||
|
||||
ForcePowerCtrl bool
|
||||
StackLevelZero *bool
|
||||
RemoteStart bool
|
||||
ForcePowerCtrl bool
|
||||
StackLevelZero *bool
|
||||
ProfileKindRelative bool
|
||||
RemoteStart bool
|
||||
}{
|
||||
Connector: 1,
|
||||
MeterInterval: 10 * time.Second,
|
||||
|
|
@ -85,11 +87,12 @@ func NewOCPPFromConfig(ctx context.Context, other map[string]interface{}) (api.C
|
|||
}
|
||||
|
||||
stackLevelZero := cc.StackLevelZero != nil && *cc.StackLevelZero
|
||||
profileKindRelative := cc.ProfileKindRelative
|
||||
|
||||
c, err := NewOCPP(ctx,
|
||||
cc.StationId, cc.Connector, cc.IdTag,
|
||||
cc.MeterValues, cc.MeterInterval,
|
||||
cc.ForcePowerCtrl, stackLevelZero, cc.RemoteStart,
|
||||
cc.ForcePowerCtrl, stackLevelZero, profileKindRelative, cc.RemoteStart,
|
||||
cc.ConnectTimeout)
|
||||
if err != nil {
|
||||
return c, err
|
||||
|
|
@ -143,7 +146,7 @@ func NewOCPPFromConfig(ctx context.Context, other map[string]interface{}) (api.C
|
|||
func NewOCPP(ctx context.Context,
|
||||
id string, connector int, idTag string,
|
||||
meterValues string, meterInterval time.Duration,
|
||||
forcePowerCtrl, stackLevelZero, remoteStart bool,
|
||||
forcePowerCtrl, stackLevelZero, profileKindRelative, remoteStart bool,
|
||||
connectTimeout time.Duration,
|
||||
) (*OCPP, error) {
|
||||
log := util.NewLogger(fmt.Sprintf("%s-%d", lo.CoalesceOrEmpty(id, "ocpp"), connector))
|
||||
|
|
@ -184,10 +187,11 @@ func NewOCPP(ctx context.Context,
|
|||
}
|
||||
|
||||
c := &OCPP{
|
||||
log: log,
|
||||
cp: cp,
|
||||
conn: conn,
|
||||
stackLevelZero: stackLevelZero,
|
||||
log: log,
|
||||
cp: cp,
|
||||
conn: conn,
|
||||
stackLevelZero: stackLevelZero,
|
||||
profileKindRelative: profileKindRelative,
|
||||
}
|
||||
|
||||
if cp.HasRemoteTriggerFeature {
|
||||
|
|
@ -328,14 +332,19 @@ func (c *OCPP) createTxDefaultChargingProfile(current float64) *types.ChargingPr
|
|||
res := &types.ChargingProfile{
|
||||
ChargingProfileId: c.cp.ChargingProfileId,
|
||||
ChargingProfilePurpose: types.ChargingProfilePurposeTxDefaultProfile,
|
||||
ChargingProfileKind: types.ChargingProfileKindAbsolute,
|
||||
ChargingSchedule: &types.ChargingSchedule{
|
||||
StartSchedule: types.NewDateTime(time.Now().Add(-time.Minute)),
|
||||
ChargingRateUnit: c.cp.ChargingRateUnit,
|
||||
ChargingSchedulePeriod: []types.ChargingSchedulePeriod{period},
|
||||
},
|
||||
}
|
||||
|
||||
if c.profileKindRelative {
|
||||
res.ChargingProfileKind = types.ChargingProfileKindRelative
|
||||
} else {
|
||||
res.ChargingProfileKind = types.ChargingProfileKindAbsolute
|
||||
res.ChargingSchedule.StartSchedule = types.NewDateTime(time.Now().Add(-time.Minute))
|
||||
}
|
||||
|
||||
if !c.stackLevelZero {
|
||||
res.StackLevel = c.cp.StackLevel
|
||||
}
|
||||
|
|
|
|||
|
|
@ -113,7 +113,7 @@ func (suite *ocppTestSuite) TestConnect() {
|
|||
suite.Require().True(cp1.IsConnected())
|
||||
|
||||
// 1st charge point- local
|
||||
c1, err := NewOCPP(context.TODO(), "test-1", 1, "", "", 0, false, false, true, ocppTestConnectTimeout)
|
||||
c1, err := NewOCPP(context.TODO(), "test-1", 1, "", "", 0, false, false, false, true, ocppTestConnectTimeout)
|
||||
suite.Require().NoError(err)
|
||||
|
||||
// status and meter values
|
||||
|
|
@ -162,7 +162,7 @@ func (suite *ocppTestSuite) TestConnect() {
|
|||
suite.Require().True(cp2.IsConnected())
|
||||
|
||||
// 2nd charge point - local
|
||||
c2, err := NewOCPP(context.TODO(), "test-2", 1, "", "", 0, false, false, true, ocppTestConnectTimeout)
|
||||
c2, err := NewOCPP(context.TODO(), "test-2", 1, "", "", 0, false, false, false, true, ocppTestConnectTimeout)
|
||||
suite.Require().NoError(err)
|
||||
|
||||
{
|
||||
|
|
@ -204,7 +204,7 @@ func (suite *ocppTestSuite) TestAutoStart() {
|
|||
suite.Require().True(cp1.IsConnected())
|
||||
|
||||
// 1st charge point- local
|
||||
c1, err := NewOCPP(context.TODO(), "test-3", 1, "", "", 0, false, false, false, ocppTestConnectTimeout)
|
||||
c1, err := NewOCPP(context.TODO(), "test-3", 1, "", "", 0, false, false, false, false, ocppTestConnectTimeout)
|
||||
suite.Require().NoError(err)
|
||||
|
||||
// status and meter values
|
||||
|
|
@ -251,7 +251,7 @@ func (suite *ocppTestSuite) TestTimeout() {
|
|||
})
|
||||
|
||||
// 1st charge point- local
|
||||
_, err := NewOCPP(context.TODO(), "test-4", 1, "", "", 0, false, false, false, ocppTestConnectTimeout)
|
||||
_, err := NewOCPP(context.TODO(), "test-4", 1, "", "", 0, false, false, false, false, ocppTestConnectTimeout)
|
||||
|
||||
suite.Require().NoError(err)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue