refactor: cleanup import
authorJérôme Benoit <jerome.benoit@sap.com>
Tue, 1 Aug 2023 18:38:02 +0000 (20:38 +0200)
committerJérôme Benoit <jerome.benoit@sap.com>
Tue, 1 Aug 2023 18:38:02 +0000 (20:38 +0200)
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
src/charging-station/ChargingStation.ts
src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts
src/types/index.ts
src/types/ocpp/Reservation.ts

index d08079c805760799b7e47d0f9c82dafc8bd7935a..6adbd74d2e20fb90331222be6f884a4ce942048a 100644 (file)
@@ -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))
index fbb76bec08790bb50126d4fb3557e3a8a7a194c9..f4c0e6ad657423ab86e563907850f5a9a6276813 100644 (file)
@@ -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,
index 57437830a2ace05f3236da9c4d00c8d62fb52c25..66a9682277abb2a637afa4c07f92a282232a12c3 100644 (file)
@@ -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,
index cddc316995e56651087d15fadd9d217db9ea3105..61ef6474a6beb364dd625c20af791e71978ff540 100644 (file)
@@ -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;