From a71d4e70068e2fa299a182803fb1d9b828d8335b Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Mon, 24 Jul 2023 17:26:09 +0200 Subject: [PATCH] feat: add support for charging profiles relative to charging start MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- src/charging-station/ChargingStationUtils.ts | 17 ++++++++++++++--- .../ocpp/1.6/OCPP16ResponseService.ts | 2 ++ src/types/ConnectorStatus.ts | 1 + 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/charging-station/ChargingStationUtils.ts b/src/charging-station/ChargingStationUtils.ts index 33d259af..e0a68e53 100644 --- a/src/charging-station/ChargingStationUtils.ts +++ b/src/charging-station/ChargingStationUtils.ts @@ -302,9 +302,10 @@ export const resetConnectorStatus = (connectorStatus: ConnectorStatus): void => connectorStatus.idTagAuthorized = false; connectorStatus.transactionRemoteStarted = false; connectorStatus.transactionStarted = false; + delete connectorStatus?.transactionStart; + delete connectorStatus?.transactionId; delete connectorStatus?.localAuthorizeIdTag; delete connectorStatus?.authorizeIdTag; - delete connectorStatus?.transactionId; delete connectorStatus?.transactionIdTag; connectorStatus.transactionEnergyActiveImportRegisterValue = 0; delete connectorStatus?.transactionBeginMeterValue; @@ -481,7 +482,12 @@ export const getChargingStationConnectorChargingProfilesPowerLimit = ( ); } if (isNotEmptyArray(chargingProfiles)) { - const result = getLimitFromChargingProfiles(chargingProfiles, chargingStation.logPrefix()); + const result = getLimitFromChargingProfiles( + chargingStation, + connectorId, + chargingProfiles, + chargingStation.logPrefix(), + ); if (!isNullOrUndefined(result)) { limit = result?.limit; matchingChargingProfile = result?.matchingChargingProfile; @@ -667,6 +673,8 @@ const convertDeprecatedTemplateKey = ( * @returns */ const getLimitFromChargingProfiles = ( + chargingStation: ChargingStation, + connectorId: number, chargingProfiles: ChargingProfile[], logPrefix: string, ): @@ -682,8 +690,11 @@ const getLimitFromChargingProfiles = ( const chargingSchedule = chargingProfile.chargingSchedule; if (!chargingSchedule?.startSchedule) { logger.warn( - `${logPrefix} ${moduleName}.getLimitFromChargingProfiles: startSchedule is not defined in charging profile id ${chargingProfile.chargingProfileId}`, + `${logPrefix} ${moduleName}.getLimitFromChargingProfiles: startSchedule is not defined in charging profile id ${chargingProfile.chargingProfileId}. Trying to set it to the connector transaction start date`, ); + // OCPP specifies that if startSchedule is not defined, it should be relative to start of the connector transaction + chargingSchedule.startSchedule = + chargingStation.getConnectorStatus(connectorId)?.transactionStart; } if (!(chargingSchedule?.startSchedule instanceof Date)) { logger.warn( diff --git a/src/charging-station/ocpp/1.6/OCPP16ResponseService.ts b/src/charging-station/ocpp/1.6/OCPP16ResponseService.ts index 78c2cedb..3e718285 100644 --- a/src/charging-station/ocpp/1.6/OCPP16ResponseService.ts +++ b/src/charging-station/ocpp/1.6/OCPP16ResponseService.ts @@ -619,6 +619,8 @@ export class OCPP16ResponseService extends OCPPResponseService { if (payload.idTagInfo?.status === OCPP16AuthorizationStatus.ACCEPTED) { chargingStation.getConnectorStatus(transactionConnectorId)!.transactionStarted = true; + chargingStation.getConnectorStatus(transactionConnectorId)!.transactionStart = + requestPayload.timestamp; chargingStation.getConnectorStatus(transactionConnectorId)!.transactionId = payload.transactionId; chargingStation.getConnectorStatus(transactionConnectorId)!.transactionIdTag = diff --git a/src/types/ConnectorStatus.ts b/src/types/ConnectorStatus.ts index 45ac6807..c1783eb4 100644 --- a/src/types/ConnectorStatus.ts +++ b/src/types/ConnectorStatus.ts @@ -16,6 +16,7 @@ export interface ConnectorStatus { idTagLocalAuthorized?: boolean; transactionRemoteStarted?: boolean; transactionStarted?: boolean; + transactionStart?: Date; transactionId?: number; transactionSetInterval?: NodeJS.Timeout; transactionIdTag?: string; -- 2.34.1