X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fcharging-station%2Focpp%2F1.6%2FOCPP16ServiceUtils.ts;h=04cf899f2cd01437a89592b0c4dc7de63fb72bfa;hb=9ff486f4329a4902e8bcd280c0649a74cb31e4df;hp=914886bd4d680ba15b9095dc5cc80200266341a7;hpb=0e14e1d42f7fbe28955be2cb77e6ad3f7277e9a2;p=e-mobility-charging-stations-simulator.git diff --git a/src/charging-station/ocpp/1.6/OCPP16ServiceUtils.ts b/src/charging-station/ocpp/1.6/OCPP16ServiceUtils.ts index 914886bd..04cf899f 100644 --- a/src/charging-station/ocpp/1.6/OCPP16ServiceUtils.ts +++ b/src/charging-station/ocpp/1.6/OCPP16ServiceUtils.ts @@ -123,7 +123,7 @@ export class OCPP16ServiceUtils extends OCPPServiceUtils { OCPP16MeterValueMeasurand.ENERGY_ACTIVE_IMPORT_REGISTER }: connector id ${connectorId}, transaction id ${connector?.transactionId}, value: ${socMinimumValue}/${ meterValue.sampledValue[sampledValuesIndex].value - }/${socMaximumValue}}`, + }/${socMaximumValue}`, ); } } @@ -935,21 +935,21 @@ export class OCPP16ServiceUtils extends OCPPServiceUtils { public static composeChargingSchedules = ( chargingScheduleHigher: OCPP16ChargingSchedule | undefined, chargingScheduleLower: OCPP16ChargingSchedule | undefined, - targetInterval: Interval, + compositeInterval: Interval, ): OCPP16ChargingSchedule | undefined => { if (!chargingScheduleHigher && !chargingScheduleLower) { return undefined; } if (chargingScheduleHigher && !chargingScheduleLower) { - return OCPP16ServiceUtils.composeChargingSchedule(chargingScheduleHigher, targetInterval); + return OCPP16ServiceUtils.composeChargingSchedule(chargingScheduleHigher, compositeInterval); } if (!chargingScheduleHigher && chargingScheduleLower) { - return OCPP16ServiceUtils.composeChargingSchedule(chargingScheduleLower, targetInterval); + return OCPP16ServiceUtils.composeChargingSchedule(chargingScheduleLower, compositeInterval); } const compositeChargingScheduleHigher: OCPP16ChargingSchedule | undefined = - OCPP16ServiceUtils.composeChargingSchedule(chargingScheduleHigher!, targetInterval); + OCPP16ServiceUtils.composeChargingSchedule(chargingScheduleHigher!, compositeInterval); const compositeChargingScheduleLower: OCPP16ChargingSchedule | undefined = - OCPP16ServiceUtils.composeChargingSchedule(chargingScheduleLower!, targetInterval); + OCPP16ServiceUtils.composeChargingSchedule(chargingScheduleLower!, compositeInterval); const compositeChargingScheduleHigherInterval: Interval = { start: compositeChargingScheduleHigher!.startSchedule!, end: addSeconds( @@ -1167,25 +1167,28 @@ export class OCPP16ServiceUtils extends OCPPServiceUtils { private static composeChargingSchedule = ( chargingSchedule: OCPP16ChargingSchedule, - targetInterval: Interval, + compositeInterval: Interval, ): OCPP16ChargingSchedule | undefined => { const chargingScheduleInterval: Interval = { start: chargingSchedule.startSchedule!, end: addSeconds(chargingSchedule.startSchedule!, chargingSchedule.duration!), }; - if (areIntervalsOverlapping(chargingScheduleInterval, targetInterval)) { + if (areIntervalsOverlapping(chargingScheduleInterval, compositeInterval)) { chargingSchedule.chargingSchedulePeriod.sort((a, b) => a.startPeriod - b.startPeriod); - if (isBefore(chargingScheduleInterval.start, targetInterval.start)) { + if (isBefore(chargingScheduleInterval.start, compositeInterval.start)) { return { ...chargingSchedule, - startSchedule: targetInterval.start as Date, - duration: differenceInSeconds(chargingScheduleInterval.end, targetInterval.start as Date), + startSchedule: compositeInterval.start as Date, + duration: differenceInSeconds( + chargingScheduleInterval.end, + compositeInterval.start as Date, + ), chargingSchedulePeriod: chargingSchedule.chargingSchedulePeriod .filter((schedulePeriod, index) => { if ( isWithinInterval( addSeconds(chargingScheduleInterval.start, schedulePeriod.startPeriod)!, - targetInterval, + compositeInterval, ) ) { return true; @@ -1194,14 +1197,14 @@ export class OCPP16ServiceUtils extends OCPPServiceUtils { index < chargingSchedule.chargingSchedulePeriod.length - 1 && !isWithinInterval( addSeconds(chargingScheduleInterval.start, schedulePeriod.startPeriod), - targetInterval, + compositeInterval, ) && isWithinInterval( addSeconds( chargingScheduleInterval.start, chargingSchedule.chargingSchedulePeriod[index + 1].startPeriod, ), - targetInterval, + compositeInterval, ) ) { return true; @@ -1216,14 +1219,17 @@ export class OCPP16ServiceUtils extends OCPPServiceUtils { }), }; } - if (isAfter(chargingScheduleInterval.end, targetInterval.end)) { + if (isAfter(chargingScheduleInterval.end, compositeInterval.end)) { return { ...chargingSchedule, - duration: differenceInSeconds(targetInterval.end as Date, chargingScheduleInterval.start), + duration: differenceInSeconds( + compositeInterval.end as Date, + chargingScheduleInterval.start, + ), chargingSchedulePeriod: chargingSchedule.chargingSchedulePeriod.filter((schedulePeriod) => isWithinInterval( addSeconds(chargingScheduleInterval.start, schedulePeriod.startPeriod)!, - targetInterval, + compositeInterval, ), ), }; @@ -1238,12 +1244,12 @@ export class OCPP16ServiceUtils extends OCPPServiceUtils { context?: MeterValueContext, phase?: OCPP16MeterValuePhase, ): OCPP16SampledValue { - const sampledValueValue = value ?? sampledValueTemplate?.value ?? null; - const sampledValueContext = context ?? sampledValueTemplate?.context ?? null; + const sampledValueValue = value ?? sampledValueTemplate?.value; + const sampledValueContext = context ?? sampledValueTemplate?.context; const sampledValueLocation = sampledValueTemplate?.location ?? OCPP16ServiceUtils.getMeasurandDefaultLocation(sampledValueTemplate.measurand!); - const sampledValuePhase = phase ?? sampledValueTemplate?.phase ?? null; + const sampledValuePhase = phase ?? sampledValueTemplate?.phase; return { ...(!isNullOrUndefined(sampledValueTemplate.unit) && { unit: sampledValueTemplate.unit,