X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fcharging-station%2FHelpers.ts;h=068bc6c970afeaa9e402cc4f69086ccafae59ded;hb=2af834a91b2ed3ca95de2af7cbb86c59f13c1c0f;hp=0384da3e3026f0f0ce6b006f2b2a640183a7d8a9;hpb=dc347546238a2a8c5cf9f5e1c60dac29913e3948;p=e-mobility-charging-stations-simulator.git diff --git a/src/charging-station/Helpers.ts b/src/charging-station/Helpers.ts index 0384da3e..068bc6c9 100644 --- a/src/charging-station/Helpers.ts +++ b/src/charging-station/Helpers.ts @@ -262,7 +262,7 @@ export const checkConnectorsConfiguration = ( checkConfiguredMaxConnectors(configuredMaxConnectors, logPrefix, templateFile); const templateMaxConnectors = getMaxNumberOfConnectors(stationTemplate.Connectors!); checkTemplateMaxConnectors(templateMaxConnectors, logPrefix, templateFile); - const templateMaxAvailableConnectors = stationTemplate.Connectors![0] + const templateMaxAvailableConnectors = stationTemplate.Connectors?.[0] ? templateMaxConnectors - 1 : templateMaxConnectors; if ( @@ -339,11 +339,12 @@ export const initializeConnectorsMapStatus = ( }; export const resetConnectorStatus = (connectorStatus: ConnectorStatus): void => { - connectorStatus.chargingProfiles = isNotEmptyArray(connectorStatus.chargingProfiles) - ? connectorStatus.chargingProfiles?.filter( - (chargingProfile) => chargingProfile.transactionId !== connectorStatus?.transactionId, - ) - : []; + connectorStatus.chargingProfiles = + connectorStatus.transactionId && isNotEmptyArray(connectorStatus.chargingProfiles) + ? connectorStatus.chargingProfiles?.filter( + (chargingProfile) => chargingProfile.transactionId !== connectorStatus.transactionId, + ) + : []; connectorStatus.idTagLocalAuthorized = false; connectorStatus.idTagAuthorized = false; connectorStatus.transactionRemoteStarted = false; @@ -451,12 +452,9 @@ export const stationTemplateToStationInfo = ( export const createSerialNumber = ( stationTemplate: ChargingStationTemplate, stationInfo: ChargingStationInfo, - params: { + params?: { randomSerialNumberUpperCase?: boolean; randomSerialNumber?: boolean; - } = { - randomSerialNumberUpperCase: true, - randomSerialNumber: true, }, ): void => { params = { ...{ randomSerialNumberUpperCase: true, randomSerialNumber: true }, ...params }; @@ -647,7 +645,7 @@ const getConfiguredMaxNumberOfConnectors = (stationTemplate: ChargingStationTemp } else if (isUndefined(stationTemplate.numberOfConnectors) === false) { configuredMaxNumberOfConnectors = stationTemplate.numberOfConnectors as number; } else if (stationTemplate.Connectors && !stationTemplate.Evses) { - configuredMaxNumberOfConnectors = stationTemplate.Connectors[0] + configuredMaxNumberOfConnectors = stationTemplate.Connectors?.[0] ? getMaxNumberOfConnectors(stationTemplate.Connectors) - 1 : getMaxNumberOfConnectors(stationTemplate.Connectors); } else if (stationTemplate.Evses && !stationTemplate.Connectors) { @@ -711,7 +709,7 @@ const warnDeprecatedTemplateKey = ( templateFile: string, logMsgToAppend = '', ): void => { - if (!isUndefined(template[key as keyof ChargingStationTemplate])) { + if (!isUndefined(template?.[key as keyof ChargingStationTemplate])) { const logMsg = `Deprecated template key '${key}' usage in file '${templateFile}'${ isNotEmptyString(logMsgToAppend) ? `. ${logMsgToAppend}` : '' }`; @@ -725,7 +723,7 @@ const convertDeprecatedTemplateKey = ( deprecatedKey: string, key?: string, ): void => { - if (!isUndefined(template[deprecatedKey as keyof ChargingStationTemplate])) { + if (!isUndefined(template?.[deprecatedKey as keyof ChargingStationTemplate])) { if (!isUndefined(key)) { (template as unknown as Record)[key!] = template[deprecatedKey as keyof ChargingStationTemplate]; @@ -966,7 +964,10 @@ const canProceedRecurringChargingProfile = ( ); return false; } - if (isNullOrUndefined(chargingProfile.chargingSchedule.startSchedule)) { + if ( + chargingProfile.chargingProfileKind === ChargingProfileKindType.RECURRING && + isNullOrUndefined(chargingProfile.chargingSchedule.startSchedule) + ) { logger.error( `${logPrefix} ${moduleName}.canProceedRecurringChargingProfile: Recurring charging profile id ${chargingProfile.chargingProfileId} has no startSchedule defined`, );