From: Jérôme Benoit Date: Tue, 1 Aug 2023 18:38:02 +0000 (+0200) Subject: refactor: cleanup import X-Git-Tag: v1.2.20~46 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=491dad29ded66644b4bca576cbd1edc0f84508df;p=e-mobility-charging-stations-simulator.git refactor: cleanup import Signed-off-by: Jérôme Benoit --- diff --git a/src/charging-station/ChargingStation.ts b/src/charging-station/ChargingStation.ts index d08079c8..6adbd74d 100644 --- a/src/charging-station/ChargingStation.ts +++ b/src/charging-station/ChargingStation.ts @@ -1569,6 +1569,13 @@ export class ChargingStation { } with evse id 0 with no connector id 0 configuration`, ); } + if (Object.keys(stationTemplate?.Evses?.[0]?.Connectors as object).length > 1) { + logger.warn( + `${this.logPrefix()} Charging station information from template ${ + this.templateFile + } with evse id 0 with more than one connector configuration, only connector id 0 configuration will be used`, + ); + } if (stationTemplate?.Evses) { const evsesConfigHash = createHash(Constants.DEFAULT_HASH_ALGORITHM) .update(JSON.stringify(stationTemplate?.Evses)) diff --git a/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts b/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts index fbb76bec..f4c0e6ad 100644 --- a/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts +++ b/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts @@ -31,7 +31,6 @@ import { OCPPError } from '../../../exception'; import { type ChangeConfigurationRequest, type ChangeConfigurationResponse, - ChargingRateUnitType, type ClearChargingProfileRequest, type ClearChargingProfileResponse, ErrorType, @@ -55,7 +54,9 @@ import { OCPP16ChargePointStatus, type OCPP16ChargingProfile, OCPP16ChargingProfilePurposeType, + OCPP16ChargingRateUnitType, type OCPP16ChargingSchedule, + type OCPP16ChargingSchedulePeriod, type OCPP16ClearCacheRequest, type OCPP16DataTransferRequest, type OCPP16DataTransferResponse, @@ -754,36 +755,39 @@ export class OCPP16IncomingRequestService extends OCPPIncomingRequestService { chargingProfiles.push(chargingProfile); } } - const compositeSchedule: OCPP16ChargingSchedule = { - startSchedule: min( - chargingProfiles.map( - (chargingProfile) => chargingProfile.chargingSchedule.startSchedule ?? maxTime, - ), + const compositeScheduleStart: Date = min( + chargingProfiles.map( + (chargingProfile) => chargingProfile.chargingSchedule.startSchedule ?? maxTime, ), - duration: Math.max( - ...chargingProfiles.map( - (chargingProfile) => chargingProfile.chargingSchedule.duration ?? -Infinity, - ), + ); + const compositeScheduleDuration: number = Math.max( + ...chargingProfiles.map( + (chargingProfile) => chargingProfile.chargingSchedule.duration ?? -Infinity, ), + ); + // FIXME: remove overlapping charging schedule periods + const compositeSchedulePeriods: OCPP16ChargingSchedulePeriod[] = chargingProfiles + .map((chargingProfile) => chargingProfile.chargingSchedule.chargingSchedulePeriod) + .reduce( + (accumulator, value) => + accumulator.concat(value).sort((a, b) => a.startPeriod - b.startPeriod), + [], + ); + const compositeSchedule: OCPP16ChargingSchedule = { + startSchedule: compositeScheduleStart, + duration: compositeScheduleDuration, chargingRateUnit: chargingProfiles.every( (chargingProfile) => - chargingProfile.chargingSchedule.chargingRateUnit === ChargingRateUnitType.AMPERE, + chargingProfile.chargingSchedule.chargingRateUnit === OCPP16ChargingRateUnitType.AMPERE, ) - ? ChargingRateUnitType.AMPERE + ? OCPP16ChargingRateUnitType.AMPERE : chargingProfiles.every( (chargingProfile) => - chargingProfile.chargingSchedule.chargingRateUnit === ChargingRateUnitType.WATT, + chargingProfile.chargingSchedule.chargingRateUnit === OCPP16ChargingRateUnitType.WATT, ) - ? ChargingRateUnitType.WATT - : ChargingRateUnitType.AMPERE, - // FIXME: remove overlapping charging schedule periods - chargingSchedulePeriod: chargingProfiles - .map((chargingProfile) => chargingProfile.chargingSchedule.chargingSchedulePeriod) - .reduce( - (accumulator, value) => - accumulator.concat(value).sort((a, b) => a.startPeriod - b.startPeriod), - [], - ), + ? OCPP16ChargingRateUnitType.WATT + : OCPP16ChargingRateUnitType.AMPERE, + chargingSchedulePeriod: compositeSchedulePeriods, minChargeRate: Math.min( ...chargingProfiles.map( (chargingProfile) => chargingProfile.chargingSchedule.minChargeRate ?? Infinity, diff --git a/src/types/index.ts b/src/types/index.ts index 57437830..66a96822 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -44,11 +44,11 @@ export { AvailabilityStatus, type BootNotificationResponse, ChargingProfileStatus, - ClearChargingProfileStatus, type ClearCacheResponse, + ClearChargingProfileStatus, ConfigurationStatus, - DataTransferStatus, type DataTransferResponse, + DataTransferStatus, type DiagnosticsStatusNotificationResponse, type ErrorResponse, type FirmwareStatusNotificationResponse, @@ -80,13 +80,14 @@ export { type MessageEvent, } from './WorkerBroadcastChannel'; export { - type OCPP16ChangeAvailabilityRequest, type ChangeConfigurationRequest, type ClearChargingProfileRequest, type GetConfigurationRequest, type GetDiagnosticsRequest, OCPP16AvailabilityType, type OCPP16BootNotificationRequest, + type OCPP16CancelReservationRequest, + type OCPP16ChangeAvailabilityRequest, type OCPP16ClearCacheRequest, type OCPP16DataTransferRequest, OCPP16DataTransferVendorId, @@ -98,6 +99,7 @@ export { OCPP16IncomingRequestCommand, OCPP16MessageTrigger, OCPP16RequestCommand, + type OCPP16ReserveNowRequest, type OCPP16StatusNotificationRequest, type OCPP16TriggerMessageRequest, type OCPP16UpdateFirmwareRequest, @@ -106,28 +108,26 @@ export { type ResetRequest, type SetChargingProfileRequest, type UnlockConnectorRequest, - type OCPP16ReserveNowRequest, - type OCPP16CancelReservationRequest, } from './ocpp/1.6/Requests'; export { - type OCPP16ChangeAvailabilityResponse, type ChangeConfigurationResponse, type ClearChargingProfileResponse, type GetConfigurationResponse, type GetDiagnosticsResponse, type OCPP16BootNotificationResponse, + type OCPP16ChangeAvailabilityResponse, type OCPP16DataTransferResponse, OCPP16DataTransferStatus, type OCPP16DiagnosticsStatusNotificationResponse, type OCPP16FirmwareStatusNotificationResponse, type OCPP16GetCompositeScheduleResponse, type OCPP16HeartbeatResponse, + type OCPP16ReserveNowResponse, type OCPP16StatusNotificationResponse, type OCPP16TriggerMessageResponse, type OCPP16UpdateFirmwareResponse, type SetChargingProfileResponse, type UnlockConnectorResponse, - type OCPP16ReserveNowResponse, } from './ocpp/1.6/Responses'; export { ChargePointErrorCode } from './ocpp/ChargePointErrorCode'; export { @@ -224,7 +224,9 @@ export { OCPP16ChargePointStatus } from './ocpp/1.6/ChargePointStatus'; export { type OCPP16ChargingProfile, OCPP16ChargingProfilePurposeType, + OCPP16ChargingRateUnitType, type OCPP16ChargingSchedule, + type OCPP16ChargingSchedulePeriod, } from './ocpp/1.6/ChargingProfile'; export { OCPP16StandardParametersKey, diff --git a/src/types/ocpp/Reservation.ts b/src/types/ocpp/Reservation.ts index cddc3169..61ef6474 100644 --- a/src/types/ocpp/Reservation.ts +++ b/src/types/ocpp/Reservation.ts @@ -2,6 +2,8 @@ import type { OCPP16ReserveNowRequest } from './1.6/Requests'; export type Reservation = OCPP16ReserveNowRequest; +export type ReservationKey = keyof Reservation; + export enum ReservationTerminationReason { EXPIRED = 'Expired', TRANSACTION_STARTED = 'TransactionStarted', @@ -9,5 +11,3 @@ export enum ReservationTerminationReason { RESERVATION_CANCELED = 'ReservationCanceled', REPLACE_EXISTING = 'ReplaceExisting', } - -export type ReservationKey = keyof OCPP16ReserveNowRequest;