X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fcharging-station%2Focpp%2F1.6%2FOCPP16ServiceUtils.ts;h=b8048927ccb824f4ff8e20320cfd356c33af6f0f;hb=5dc7c990eff43659bd48589cfc5afe09f9ec6664;hp=bbdf2e51a8eac5b5d08d18252eb939f22c66724d;hpb=d0ed7db96b4aedd5b1aa41953637a9361001f6f7;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 bbdf2e51..b8048927 100644 --- a/src/charging-station/ocpp/1.6/OCPP16ServiceUtils.ts +++ b/src/charging-station/ocpp/1.6/OCPP16ServiceUtils.ts @@ -38,7 +38,7 @@ import { type OCPP16SupportedFeatureProfiles, OCPPVersion } from '../../../types/index.js' -import { isNotEmptyArray, logger, roundTo } from '../../../utils/index.js' +import { convertToDate, isNotEmptyArray, logger, roundTo } from '../../../utils/index.js' import { OCPPServiceUtils } from '../OCPPServiceUtils.js' export class OCPP16ServiceUtils extends OCPPServiceUtils { @@ -61,7 +61,7 @@ export class OCPP16ServiceUtils extends OCPPServiceUtils { public static buildTransactionBeginMeterValue ( chargingStation: ChargingStation, connectorId: number, - meterStart: number + meterStart: number | undefined ): OCPP16MeterValue { const meterValue: OCPP16MeterValue = { timestamp: new Date(), @@ -126,7 +126,7 @@ export class OCPP16ServiceUtils extends OCPPServiceUtils { OCPP16Constants.OCPP_AVAILABILITY_RESPONSE_ACCEPTED // eslint-disable-next-line @typescript-eslint/no-non-null-assertion const connectorStatus = chargingStation.getConnectorStatus(connectorId)! - if (connectorStatus?.transactionStarted === true) { + if (connectorStatus.transactionStarted === true) { response = OCPP16Constants.OCPP_AVAILABILITY_RESPONSE_SCHEDULED } connectorStatus.availability = availabilityType @@ -164,21 +164,28 @@ export class OCPP16ServiceUtils extends OCPPServiceUtils { // eslint-disable-next-line @typescript-eslint/no-non-null-assertion chargingStation.getConnectorStatus(connectorId)!.chargingProfiles = [] } + // eslint-disable-next-line @typescript-eslint/no-non-null-assertion + cp.chargingSchedule.startSchedule = convertToDate(cp.chargingSchedule.startSchedule)! + // eslint-disable-next-line @typescript-eslint/no-non-null-assertion + cp.validFrom = convertToDate(cp.validFrom)! + // eslint-disable-next-line @typescript-eslint/no-non-null-assertion + cp.validTo = convertToDate(cp.validTo)! let cpReplaced = false if (isNotEmptyArray(chargingStation.getConnectorStatus(connectorId)?.chargingProfiles)) { - chargingStation - .getConnectorStatus(connectorId) - ?.chargingProfiles?.forEach((chargingProfile: OCPP16ChargingProfile, index: number) => { - if ( - chargingProfile.chargingProfileId === cp.chargingProfileId || - (chargingProfile.stackLevel === cp.stackLevel && - chargingProfile.chargingProfilePurpose === cp.chargingProfilePurpose) - ) { - // eslint-disable-next-line @typescript-eslint/no-non-null-assertion - chargingStation.getConnectorStatus(connectorId)!.chargingProfiles![index] = cp - cpReplaced = true - } - }) + // eslint-disable-next-line @typescript-eslint/no-non-null-assertion + for (const [index, chargingProfile] of chargingStation + .getConnectorStatus(connectorId)! + .chargingProfiles!.entries()) { + if ( + chargingProfile.chargingProfileId === cp.chargingProfileId || + (chargingProfile.stackLevel === cp.stackLevel && + chargingProfile.chargingProfilePurpose === cp.chargingProfilePurpose) + ) { + // eslint-disable-next-line @typescript-eslint/no-non-null-assertion + chargingStation.getConnectorStatus(connectorId)!.chargingProfiles![index] = cp + cpReplaced = true + } + } } !cpReplaced && chargingStation.getConnectorStatus(connectorId)?.chargingProfiles?.push(cp) } @@ -191,7 +198,7 @@ export class OCPP16ServiceUtils extends OCPPServiceUtils { const { id, chargingProfilePurpose, stackLevel } = commandPayload let clearedCP = false if (isNotEmptyArray(chargingProfiles)) { - chargingProfiles?.forEach((chargingProfile: OCPP16ChargingProfile, index: number) => { + chargingProfiles.forEach((chargingProfile: OCPP16ChargingProfile, index: number) => { let clearCurrentCP = false if (chargingProfile.chargingProfileId === id) { clearCurrentCP = true @@ -292,7 +299,7 @@ export class OCPP16ServiceUtils extends OCPPServiceUtils { ), chargingSchedulePeriod: [ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion - ...compositeChargingScheduleHigher!.chargingSchedulePeriod.map((schedulePeriod) => { + ...compositeChargingScheduleHigher!.chargingSchedulePeriod.map(schedulePeriod => { return { ...schedulePeriod, startPeriod: higherFirst @@ -305,7 +312,7 @@ export class OCPP16ServiceUtils extends OCPPServiceUtils { } }), // eslint-disable-next-line @typescript-eslint/no-non-null-assertion - ...compositeChargingScheduleLower!.chargingSchedulePeriod.map((schedulePeriod) => { + ...compositeChargingScheduleLower!.chargingSchedulePeriod.map(schedulePeriod => { return { ...schedulePeriod, startPeriod: higherFirst @@ -338,7 +345,7 @@ export class OCPP16ServiceUtils extends OCPPServiceUtils { ), chargingSchedulePeriod: [ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion - ...compositeChargingScheduleHigher!.chargingSchedulePeriod.map((schedulePeriod) => { + ...compositeChargingScheduleHigher!.chargingSchedulePeriod.map(schedulePeriod => { return { ...schedulePeriod, startPeriod: higherFirst @@ -451,11 +458,11 @@ export class OCPP16ServiceUtils extends OCPPServiceUtils { OCPP16ChargePointStatus.Reserved && connectorReservation != null && !hasReservationExpired(connectorReservation) && - connectorReservation?.idTag === idTag) || + connectorReservation.idTag === idTag) || (chargingStation.getConnectorStatus(0)?.status === OCPP16ChargePointStatus.Reserved && chargingStationReservation != null && !hasReservationExpired(chargingStationReservation) && - chargingStationReservation?.idTag === idTag) + chargingStationReservation.idTag === idTag) ) { logger.debug( `${chargingStation.logPrefix()} Connector id ${connectorId} has a valid reservation for idTag ${idTag}: %j`, @@ -543,7 +550,7 @@ export class OCPP16ServiceUtils extends OCPPServiceUtils { compositeInterval.end as Date, chargingScheduleInterval.start ), - chargingSchedulePeriod: chargingSchedule.chargingSchedulePeriod.filter((schedulePeriod) => + chargingSchedulePeriod: chargingSchedule.chargingSchedulePeriod.filter(schedulePeriod => isWithinInterval( // eslint-disable-next-line @typescript-eslint/no-non-null-assertion addSeconds(chargingScheduleInterval.start, schedulePeriod.startPeriod)!,