X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fcharging-station%2Focpp%2F1.6%2FOCPP16ServiceUtils.ts;h=d9144064003fb5bf07e0443720e17ac2af084501;hb=8f46463be058ed68cc4cc962c51722f7e3b55c54;hp=51cbbd168699708acc6903565f9698bd42863a30;hpb=95dab6cfb3e2de1f775f0a8648bccbc62c4a9214;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 51cbbd16..d9144064 100644 --- a/src/charging-station/ocpp/1.6/OCPP16ServiceUtils.ts +++ b/src/charging-station/ocpp/1.6/OCPP16ServiceUtils.ts @@ -1,17 +1,16 @@ -// Partial Copyright Jerome Benoit. 2021-2023. All Rights Reserved. +// Partial Copyright Jerome Benoit. 2021-2024. All Rights Reserved. import type { JSONSchemaType } from 'ajv' import { - type Interval, addSeconds, areIntervalsOverlapping, differenceInSeconds, + type Interval, isAfter, isBefore, isWithinInterval } from 'date-fns' -import { OCPP16Constants } from './OCPP16Constants.js' import { type ChargingStation, hasFeatureProfile, @@ -40,6 +39,7 @@ import { } from '../../../types/index.js' import { convertToDate, isNotEmptyArray, logger, roundTo } from '../../../utils/index.js' import { OCPPServiceUtils } from '../OCPPServiceUtils.js' +import { OCPP16Constants } from './OCPP16Constants.js' export class OCPP16ServiceUtils extends OCPPServiceUtils { public static checkFeatureProfile ( @@ -164,10 +164,9 @@ 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.validFrom = convertToDate(cp.validFrom)! - // eslint-disable-next-line @typescript-eslint/no-non-null-assertion - cp.validTo = convertToDate(cp.validTo)! + cp.chargingSchedule.startSchedule = convertToDate(cp.chargingSchedule.startSchedule) + cp.validFrom = convertToDate(cp.validFrom) + cp.validTo = convertToDate(cp.validTo) let cpReplaced = false if (isNotEmptyArray(chargingStation.getConnectorStatus(connectorId)?.chargingProfiles)) { // eslint-disable-next-line @typescript-eslint/no-non-null-assertion @@ -196,7 +195,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 @@ -508,8 +507,7 @@ export class OCPP16ServiceUtils extends OCPPServiceUtils { .filter((schedulePeriod, index) => { if ( isWithinInterval( - // eslint-disable-next-line @typescript-eslint/no-non-null-assertion - addSeconds(chargingScheduleInterval.start, schedulePeriod.startPeriod)!, + addSeconds(chargingScheduleInterval.start, schedulePeriod.startPeriod), compositeInterval ) ) { @@ -550,8 +548,7 @@ export class OCPP16ServiceUtils extends OCPPServiceUtils { ), chargingSchedulePeriod: chargingSchedule.chargingSchedulePeriod.filter(schedulePeriod => isWithinInterval( - // eslint-disable-next-line @typescript-eslint/no-non-null-assertion - addSeconds(chargingScheduleInterval.start, schedulePeriod.startPeriod)!, + addSeconds(chargingScheduleInterval.start, schedulePeriod.startPeriod), compositeInterval ) )