From: Jérôme Benoit Date: Mon, 8 Jan 2024 11:48:33 +0000 (+0100) Subject: fix: fix ATG connector statuses date handling X-Git-Tag: v1.2.32~50 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=6dde6c5f02a9123001bafabbf3fa299d9d3b7797;p=e-mobility-charging-stations-simulator.git fix: fix ATG connector statuses date handling Signed-off-by: Jérôme Benoit --- diff --git a/src/charging-station/AutomaticTransactionGenerator.ts b/src/charging-station/AutomaticTransactionGenerator.ts index d056d8ec..3b27f247 100644 --- a/src/charging-station/AutomaticTransactionGenerator.ts +++ b/src/charging-station/AutomaticTransactionGenerator.ts @@ -20,6 +20,7 @@ import { import { Constants, cloneObject, + convertToDate, formatDurationMilliSeconds, getRandomInteger, isValidTime, @@ -261,7 +262,11 @@ export class AutomaticTransactionGenerator { private setStartConnectorStatus (connectorId: number): void { const previousRunDuration = isValidTime(this.connectorsStatus.get(connectorId)?.startDate) && - isValidTime(this.connectorsStatus.get(connectorId)?.lastRunDate) + isValidTime(this.connectorsStatus.get(connectorId)?.lastRunDate) && + // eslint-disable-next-line @typescript-eslint/no-non-null-assertion + this.connectorsStatus.get(connectorId)!.lastRunDate! > + // eslint-disable-next-line @typescript-eslint/no-non-null-assertion + this.connectorsStatus.get(connectorId)!.startDate! ? // eslint-disable-next-line @typescript-eslint/no-non-null-assertion this.connectorsStatus.get(connectorId)!.lastRunDate!.getTime() - // eslint-disable-next-line @typescript-eslint/no-non-null-assertion @@ -379,7 +384,23 @@ export class AutomaticTransactionGenerator { this.chargingStation.getAutomaticTransactionGeneratorStatuses()![connectorId - 1] ) : undefined - this.resetConnectorStatus(connectorStatus) + if (connectorStatus != null) { + // eslint-disable-next-line @typescript-eslint/no-non-null-assertion + connectorStatus.startDate = convertToDate(connectorStatus.startDate)! + // eslint-disable-next-line @typescript-eslint/no-non-null-assertion + connectorStatus.lastRunDate = convertToDate(connectorStatus.lastRunDate)! + // eslint-disable-next-line @typescript-eslint/no-non-null-assertion + connectorStatus.stopDate = convertToDate(connectorStatus.stopDate)! + // eslint-disable-next-line @typescript-eslint/no-non-null-assertion + connectorStatus.stoppedDate = convertToDate(connectorStatus.stoppedDate)! + if ( + !this.started && + (connectorStatus.start || + this.chargingStation.getAutomaticTransactionGeneratorConfiguration()?.enable !== true) + ) { + connectorStatus.start = false + } + } return ( connectorStatus ?? { start: false, @@ -398,19 +419,6 @@ export class AutomaticTransactionGenerator { ) } - private resetConnectorStatus (connectorStatus: Status | undefined): void { - if (connectorStatus == null) { - return - } - if ( - !this.started && - (connectorStatus.start || - this.chargingStation.getAutomaticTransactionGeneratorConfiguration()?.enable !== true) - ) { - connectorStatus.start = false - } - } - private async startTransaction ( connectorId: number ): Promise { diff --git a/src/charging-station/Helpers.ts b/src/charging-station/Helpers.ts index ab3a6f6a..d8ef4a32 100644 --- a/src/charging-station/Helpers.ts +++ b/src/charging-station/Helpers.ts @@ -917,7 +917,7 @@ const getLimitFromChargingProfiles = ( export const prepareChargingProfileKind = ( connectorStatus: ConnectorStatus, chargingProfile: ChargingProfile, - currentDate: Date, + currentDate: string | number | Date, logPrefix: string ): boolean => { switch (chargingProfile.chargingProfileKind) { @@ -945,7 +945,7 @@ export const prepareChargingProfileKind = ( export const canProceedChargingProfile = ( chargingProfile: ChargingProfile, - currentDate: Date, + currentDate: string | number | Date, logPrefix: string ): boolean => { if ( @@ -957,7 +957,9 @@ export const canProceedChargingProfile = ( logger.debug( `${logPrefix} ${moduleName}.canProceedChargingProfile: Charging profile id ${ chargingProfile.chargingProfileId - } is not valid for the current date ${currentDate.toISOString()}` + } is not valid for the current date ${ + currentDate instanceof Date ? currentDate.toISOString() : currentDate + }` ) return false } @@ -1019,7 +1021,7 @@ const canProceedRecurringChargingProfile = ( */ const prepareRecurringChargingProfile = ( chargingProfile: ChargingProfile, - currentDate: Date, + currentDate: string | number | Date, logPrefix: string ): boolean => { const chargingSchedule = chargingProfile.chargingSchedule @@ -1088,7 +1090,9 @@ const prepareRecurringChargingProfile = ( ).toISOString()}, ${toDate( // eslint-disable-next-line @typescript-eslint/no-non-null-assertion recurringInterval!.end - ).toISOString()}] has not been properly translated to current date ${currentDate.toISOString()} ` + ).toISOString()}] has not been properly translated to current date ${ + currentDate instanceof Date ? currentDate.toISOString() : currentDate + } ` ) } return recurringIntervalTranslated diff --git a/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts b/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts index e0785d43..64d836d5 100644 --- a/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts +++ b/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts @@ -748,7 +748,7 @@ export class OCPP16IncomingRequestService extends OCPPIncomingRequestService { !prepareChargingProfileKind( connectorStatus, chargingProfile, - compositeScheduleInterval.start as Date, + compositeScheduleInterval.start, chargingStation.logPrefix() ) ) { @@ -757,7 +757,7 @@ export class OCPP16IncomingRequestService extends OCPPIncomingRequestService { if ( !canProceedChargingProfile( chargingProfile, - compositeScheduleInterval.start as Date, + compositeScheduleInterval.start, chargingStation.logPrefix() ) ) {