X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fcharging-station%2FChargingStationUtils.ts;h=aa590b7819b197cf59d4bf2150288eada03b4d2c;hb=6c8d3332b2a189a435cfeb00c942a09071c8c1df;hp=1dffb0377949d4dc72dff8d84e2ec1235ff7161e;hpb=497588ef4a25784044c3ffb0e92e0c7fa6874e5f;p=e-mobility-charging-stations-simulator.git diff --git a/src/charging-station/ChargingStationUtils.ts b/src/charging-station/ChargingStationUtils.ts index 1dffb037..aa590b78 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( @@ -700,6 +711,18 @@ const getLimitFromChargingProfiles = ( chargingSchedule.startSchedule, differenceInDays(chargingSchedule.startSchedule, endOfDay(currentDate)), ); + if ( + isBefore(chargingSchedule.startSchedule, startOfDay(currentDate)) || + isAfter(chargingSchedule.startSchedule, endOfDay(currentDate)) + ) { + logger.error( + `${logPrefix} ${moduleName}.getLimitFromChargingProfiles: Recurring ${ + chargingProfile.recurrencyKind + } charging profile id ${ + chargingProfile.chargingProfileId + } startSchedule ${chargingSchedule.startSchedule.toISOString()} is not properly translated to the current day`, + ); + } } break; case RecurrencyKindType.WEEKLY: @@ -708,6 +731,18 @@ const getLimitFromChargingProfiles = ( chargingSchedule.startSchedule, differenceInWeeks(chargingSchedule.startSchedule, endOfWeek(currentDate)), ); + if ( + isBefore(chargingSchedule.startSchedule, startOfWeek(currentDate)) || + isAfter(chargingSchedule.startSchedule, endOfWeek(currentDate)) + ) { + logger.error( + `${logPrefix} ${moduleName}.getLimitFromChargingProfiles: Recurring ${ + chargingProfile.recurrencyKind + } charging profile id ${ + chargingProfile.chargingProfileId + } startSchedule ${chargingSchedule.startSchedule.toISOString()} is not properly translated to the current week`, + ); + } } break; }