feat: add support for charging profiles relative to charging start
authorJérôme Benoit <jerome.benoit@sap.com>
Mon, 24 Jul 2023 15:26:09 +0000 (17:26 +0200)
committerJérôme Benoit <jerome.benoit@sap.com>
Mon, 24 Jul 2023 15:26:09 +0000 (17:26 +0200)
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
src/charging-station/ChargingStationUtils.ts
src/charging-station/ocpp/1.6/OCPP16ResponseService.ts
src/types/ConnectorStatus.ts

index 33d259afe43bf5437a30f173d142089aa55d2dde..e0a68e531a197930626af3fcc336ae57dc79f63f 100644 (file)
@@ -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(
index 78c2cedb8eb0f03e86daae5be1709c252a98f984..3e718285d9ce4eccbc890267c70bebb303761022 100644 (file)
@@ -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 =
index 45ac6807f7251ebd033cf37b97f8d32a204235f5..c1783eb43c159afaa9238655bca4b305e6207301 100644 (file)
@@ -16,6 +16,7 @@ export interface ConnectorStatus {
   idTagLocalAuthorized?: boolean;
   transactionRemoteStarted?: boolean;
   transactionStarted?: boolean;
+  transactionStart?: Date;
   transactionId?: number;
   transactionSetInterval?: NodeJS.Timeout;
   transactionIdTag?: string;