From: Jérôme Benoit Date: Wed, 4 Jan 2023 21:23:49 +0000 (+0100) Subject: Hook the OCPP 2.0 stack into the main code X-Git-Tag: v1.1.89~32 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=edd134392e237a3242dc2093341df70244c51472;p=e-mobility-charging-stations-simulator.git Hook the OCPP 2.0 stack into the main code Signed-off-by: Jérôme Benoit --- diff --git a/src/charging-station/AutomaticTransactionGenerator.ts b/src/charging-station/AutomaticTransactionGenerator.ts index e29ad4b8..80c9a517 100644 --- a/src/charging-station/AutomaticTransactionGenerator.ts +++ b/src/charging-station/AutomaticTransactionGenerator.ts @@ -1,4 +1,4 @@ -// Partial Copyright Jerome Benoit. 2021. All Rights Reserved. +// Partial Copyright Jerome Benoit. 2021-2023. All Rights Reserved. import { AsyncResource } from 'async_hooks'; diff --git a/src/charging-station/Bootstrap.ts b/src/charging-station/Bootstrap.ts index 0115cfe3..89721197 100644 --- a/src/charging-station/Bootstrap.ts +++ b/src/charging-station/Bootstrap.ts @@ -1,4 +1,4 @@ -// Partial Copyright Jerome Benoit. 2021. All Rights Reserved. +// Partial Copyright Jerome Benoit. 2021-2023. All Rights Reserved. import path from 'path'; import { fileURLToPath } from 'url'; diff --git a/src/charging-station/ChargingStation.ts b/src/charging-station/ChargingStation.ts index 6e35d864..689fe2d9 100644 --- a/src/charging-station/ChargingStation.ts +++ b/src/charging-station/ChargingStation.ts @@ -1,4 +1,4 @@ -// Partial Copyright Jerome Benoit. 2021. All Rights Reserved. +// Partial Copyright Jerome Benoit. 2021-2023. All Rights Reserved. import crypto from 'crypto'; import fs from 'fs'; @@ -82,6 +82,9 @@ import OCPP16IncomingRequestService from './ocpp/1.6/OCPP16IncomingRequestServic import OCPP16RequestService from './ocpp/1.6/OCPP16RequestService'; import OCPP16ResponseService from './ocpp/1.6/OCPP16ResponseService'; import { OCPP16ServiceUtils } from './ocpp/1.6/OCPP16ServiceUtils'; +import OCPP20IncomingRequestService from './ocpp/2.0/OCPP20IncomingRequestService'; +import OCPP20RequestService from './ocpp/2.0/OCPP20RequestService'; +import OCPP20ResponseService from './ocpp/2.0/OCPP20ResponseService'; import type OCPPIncomingRequestService from './ocpp/OCPPIncomingRequestService'; import type OCPPRequestService from './ocpp/OCPPRequestService'; import SharedLRUCache from './SharedLRUCache'; @@ -626,13 +629,16 @@ export default class ChargingStation { if (params?.terminateOpened) { this.terminateWSConnection(); } + const ocppVersion = this.getOcppVersion(); let protocol: string; - switch (this.getOcppVersion()) { + switch (ocppVersion) { case OCPPVersion.VERSION_16: - protocol = 'ocpp' + OCPPVersion.VERSION_16; + case OCPPVersion.VERSION_20: + case OCPPVersion.VERSION_201: + protocol = 'ocpp' + ocppVersion; break; default: - this.handleUnsupportedVersion(this.getOcppVersion()); + this.handleUnsupportedVersion(ocppVersion); break; } @@ -974,6 +980,14 @@ export default class ChargingStation { OCPP16ResponseService.getInstance() ); break; + case OCPPVersion.VERSION_20: + case OCPPVersion.VERSION_201: + this.ocppIncomingRequestService = + OCPP20IncomingRequestService.getInstance(); + this.ocppRequestService = OCPP20RequestService.getInstance( + OCPP20ResponseService.getInstance() + ); + break; default: this.handleUnsupportedVersion(this.getOcppVersion()); break; diff --git a/src/charging-station/ChargingStationWorker.ts b/src/charging-station/ChargingStationWorker.ts index d0324075..62bad35f 100644 --- a/src/charging-station/ChargingStationWorker.ts +++ b/src/charging-station/ChargingStationWorker.ts @@ -1,4 +1,4 @@ -// Partial Copyright Jerome Benoit. 2021. All Rights Reserved. +// Partial Copyright Jerome Benoit. 2021-2023. All Rights Reserved. import { parentPort, workerData } from 'worker_threads'; diff --git a/src/charging-station/ChargingStationWorkerBroadcastChannel.ts b/src/charging-station/ChargingStationWorkerBroadcastChannel.ts index 0eecb7b1..63b261d5 100644 --- a/src/charging-station/ChargingStationWorkerBroadcastChannel.ts +++ b/src/charging-station/ChargingStationWorkerBroadcastChannel.ts @@ -213,7 +213,7 @@ export default class ChargingStationWorkerBroadcastChannel extends WorkerBroadca } if (requestPayload?.hashId !== undefined) { logger.error( - `${this.chargingStation.logPrefix()} ${moduleName}.requestHandler: 'hashId' field usage in PDU is deprecated, use 'hashIds' instead` + `${this.chargingStation.logPrefix()} ${moduleName}.requestHandler: 'hashId' field usage in PDU is deprecated, use 'hashIds' array instead` ); return; } diff --git a/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts b/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts index dc14d006..420edf86 100644 --- a/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts +++ b/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts @@ -1,4 +1,4 @@ -// Partial Copyright Jerome Benoit. 2021. All Rights Reserved. +// Partial Copyright Jerome Benoit. 2021-2023. All Rights Reserved. import fs from 'fs'; import path from 'path'; diff --git a/src/charging-station/ocpp/1.6/OCPP16RequestService.ts b/src/charging-station/ocpp/1.6/OCPP16RequestService.ts index ffbc15d7..dce1e44a 100644 --- a/src/charging-station/ocpp/1.6/OCPP16RequestService.ts +++ b/src/charging-station/ocpp/1.6/OCPP16RequestService.ts @@ -1,4 +1,4 @@ -// Partial Copyright Jerome Benoit. 2021. All Rights Reserved. +// Partial Copyright Jerome Benoit. 2021-2023. All Rights Reserved. import fs from 'fs'; import path from 'path'; diff --git a/src/charging-station/ocpp/1.6/OCPP16ResponseService.ts b/src/charging-station/ocpp/1.6/OCPP16ResponseService.ts index 5cb69c7c..9300e44a 100644 --- a/src/charging-station/ocpp/1.6/OCPP16ResponseService.ts +++ b/src/charging-station/ocpp/1.6/OCPP16ResponseService.ts @@ -1,4 +1,4 @@ -// Partial Copyright Jerome Benoit. 2021. All Rights Reserved. +// Partial Copyright Jerome Benoit. 2021-2023. All Rights Reserved. import fs from 'fs'; import path from 'path'; diff --git a/src/charging-station/ocpp/1.6/OCPP16ServiceUtils.ts b/src/charging-station/ocpp/1.6/OCPP16ServiceUtils.ts index f3f22e45..089ecc76 100644 --- a/src/charging-station/ocpp/1.6/OCPP16ServiceUtils.ts +++ b/src/charging-station/ocpp/1.6/OCPP16ServiceUtils.ts @@ -1,4 +1,4 @@ -// Partial Copyright Jerome Benoit. 2021. All Rights Reserved. +// Partial Copyright Jerome Benoit. 2021-2023. All Rights Reserved. import OCPPError from '../../../exception/OCPPError'; import { CurrentType, Voltage } from '../../../types/ChargingStationTemplate'; diff --git a/src/charging-station/ocpp/2.0/OCPP20IncomingRequestService.ts b/src/charging-station/ocpp/2.0/OCPP20IncomingRequestService.ts index 076832af..04715d5a 100644 --- a/src/charging-station/ocpp/2.0/OCPP20IncomingRequestService.ts +++ b/src/charging-station/ocpp/2.0/OCPP20IncomingRequestService.ts @@ -1,4 +1,4 @@ -// Partial Copyright Jerome Benoit. 2021. All Rights Reserved. +// Partial Copyright Jerome Benoit. 2021-2023. All Rights Reserved. import type { JSONSchemaType } from 'ajv'; diff --git a/src/charging-station/ocpp/2.0/OCPP20RequestService.ts b/src/charging-station/ocpp/2.0/OCPP20RequestService.ts index 8dfdce68..3b1e2695 100644 --- a/src/charging-station/ocpp/2.0/OCPP20RequestService.ts +++ b/src/charging-station/ocpp/2.0/OCPP20RequestService.ts @@ -1,4 +1,4 @@ -// Partial Copyright Jerome Benoit. 2021. All Rights Reserved. +// Partial Copyright Jerome Benoit. 2021-2023. All Rights Reserved. import type { JSONSchemaType } from 'ajv'; diff --git a/src/charging-station/ocpp/2.0/OCPP20ResponseService.ts b/src/charging-station/ocpp/2.0/OCPP20ResponseService.ts index db320f61..39baa0e5 100644 --- a/src/charging-station/ocpp/2.0/OCPP20ResponseService.ts +++ b/src/charging-station/ocpp/2.0/OCPP20ResponseService.ts @@ -1,4 +1,4 @@ -// Partial Copyright Jerome Benoit. 2021. All Rights Reserved. +// Partial Copyright Jerome Benoit. 2021-2023. All Rights Reserved. import type { JSONSchemaType } from 'ajv'; diff --git a/src/charging-station/ocpp/2.0/OCPP20ServiceUtils.ts b/src/charging-station/ocpp/2.0/OCPP20ServiceUtils.ts index 7ff58444..63e43115 100644 --- a/src/charging-station/ocpp/2.0/OCPP20ServiceUtils.ts +++ b/src/charging-station/ocpp/2.0/OCPP20ServiceUtils.ts @@ -1,4 +1,4 @@ -// Partial Copyright Jerome Benoit. 2021. All Rights Reserved. +// Partial Copyright Jerome Benoit. 2021-2023. All Rights Reserved. import { OCPPServiceUtils } from '../OCPPServiceUtils'; diff --git a/src/charging-station/ocpp/OCPPRequestService.ts b/src/charging-station/ocpp/OCPPRequestService.ts index f1a05dd5..125baf40 100644 --- a/src/charging-station/ocpp/OCPPRequestService.ts +++ b/src/charging-station/ocpp/OCPPRequestService.ts @@ -189,10 +189,10 @@ export default abstract class OCPPRequestService { // Check if wsConnection opened if (chargingStation.isWebSocketConnectionOpened() === true) { // Yes: Send Message - const beginId = PerformanceStatistics.beginMeasure(commandName); + const beginId = PerformanceStatistics.beginMeasure(commandName as string); // FIXME: Handle sending error chargingStation.wsConnection.send(messageToSend); - PerformanceStatistics.endMeasure(commandName, beginId); + PerformanceStatistics.endMeasure(commandName as string, beginId); logger.debug( `${chargingStation.logPrefix()} >> Command '${commandName}' sent ${this.getMessageTypeString( messageType diff --git a/src/charging-station/ocpp/OCPPServiceUtils.ts b/src/charging-station/ocpp/OCPPServiceUtils.ts index 6b7f709f..33637c65 100644 --- a/src/charging-station/ocpp/OCPPServiceUtils.ts +++ b/src/charging-station/ocpp/OCPPServiceUtils.ts @@ -37,7 +37,7 @@ export class OCPPServiceUtils { chargingStation: ChargingStation, command: RequestCommand ): boolean { - const isRequestCommand = Object.values(RequestCommand).includes(command); + const isRequestCommand = Object.values(RequestCommand).includes(command); if ( isRequestCommand === true && !chargingStation.stationInfo?.commandsSupport?.outgoingCommands @@ -57,7 +57,8 @@ export class OCPPServiceUtils { chargingStation: ChargingStation, command: IncomingRequestCommand ): boolean { - const isIncomingRequestCommand = Object.values(IncomingRequestCommand).includes(command); + const isIncomingRequestCommand = + Object.values(IncomingRequestCommand).includes(command); if ( isIncomingRequestCommand === true && !chargingStation.stationInfo?.commandsSupport?.incomingCommands diff --git a/src/exception/OCPPError.ts b/src/exception/OCPPError.ts index 90817649..e3c127fd 100644 --- a/src/exception/OCPPError.ts +++ b/src/exception/OCPPError.ts @@ -1,4 +1,4 @@ -// Partial Copyright Jerome Benoit. 2021. All Rights Reserved. +// Partial Copyright Jerome Benoit. 2021-2023. All Rights Reserved. import type { JsonType } from '../types/JsonType'; import { ErrorType } from '../types/ocpp/ErrorType'; diff --git a/src/performance/PerformanceStatistics.ts b/src/performance/PerformanceStatistics.ts index 5f036805..6383887a 100644 --- a/src/performance/PerformanceStatistics.ts +++ b/src/performance/PerformanceStatistics.ts @@ -1,4 +1,4 @@ -// Partial Copyright Jerome Benoit. 2021. All Rights Reserved. +// Partial Copyright Jerome Benoit. 2021-2023. All Rights Reserved. import { PerformanceEntry, PerformanceObserver, performance } from 'perf_hooks'; import type { URL } from 'url'; diff --git a/src/performance/storage/JsonFileStorage.ts b/src/performance/storage/JsonFileStorage.ts index 84652903..2f90fc46 100644 --- a/src/performance/storage/JsonFileStorage.ts +++ b/src/performance/storage/JsonFileStorage.ts @@ -1,4 +1,4 @@ -// Copyright Jerome Benoit. 2021. All Rights Reserved. +// Copyright Jerome Benoit. 2021-2023. All Rights Reserved. import fs from 'fs'; diff --git a/src/performance/storage/MikroOrmStorage.ts b/src/performance/storage/MikroOrmStorage.ts index 0c2b28ad..f9c21290 100644 --- a/src/performance/storage/MikroOrmStorage.ts +++ b/src/performance/storage/MikroOrmStorage.ts @@ -1,4 +1,4 @@ -// Copyright Jerome Benoit. 2021. All Rights Reserved. +// Copyright Jerome Benoit. 2021-2023. All Rights Reserved. import { Configuration, Connection, IDatabaseDriver, MikroORM, Options } from '@mikro-orm/core'; import { TsMorphMetadataProvider } from '@mikro-orm/reflection'; diff --git a/src/performance/storage/MongoDBStorage.ts b/src/performance/storage/MongoDBStorage.ts index 71179908..153f32ae 100644 --- a/src/performance/storage/MongoDBStorage.ts +++ b/src/performance/storage/MongoDBStorage.ts @@ -1,4 +1,4 @@ -// Copyright Jerome Benoit. 2021. All Rights Reserved. +// Copyright Jerome Benoit. 2021-2023. All Rights Reserved. import { MongoClient } from 'mongodb'; diff --git a/src/performance/storage/Storage.ts b/src/performance/storage/Storage.ts index 66bbc5f5..9c4696fa 100644 --- a/src/performance/storage/Storage.ts +++ b/src/performance/storage/Storage.ts @@ -1,4 +1,4 @@ -// Copyright Jerome Benoit. 2021. All Rights Reserved. +// Copyright Jerome Benoit. 2021-2023. All Rights Reserved. import { URL } from 'url'; diff --git a/src/performance/storage/StorageFactory.ts b/src/performance/storage/StorageFactory.ts index b0f9da58..741b1631 100644 --- a/src/performance/storage/StorageFactory.ts +++ b/src/performance/storage/StorageFactory.ts @@ -1,4 +1,4 @@ -// Copyright Jerome Benoit. 2021. All Rights Reserved. +// Copyright Jerome Benoit. 2021-2023. All Rights Reserved. import { StorageType } from '../../types/Storage'; import { JsonFileStorage } from './JsonFileStorage'; diff --git a/src/start.ts b/src/start.ts index 09ddf202..8eca3a4a 100644 --- a/src/start.ts +++ b/src/start.ts @@ -1,4 +1,4 @@ -// Partial Copyright Jerome Benoit. 2021. All Rights Reserved. +// Partial Copyright Jerome Benoit. 2021-2023. All Rights Reserved. import chalk from 'chalk'; diff --git a/src/types/ChargingStationWorker.ts b/src/types/ChargingStationWorker.ts index ac13f441..c27ec6eb 100644 --- a/src/types/ChargingStationWorker.ts +++ b/src/types/ChargingStationWorker.ts @@ -38,12 +38,11 @@ enum ChargingStationMessageEvents { PERFORMANCE_STATISTICS = 'performanceStatistics', } -export type ChargingStationWorkerMessageEvents = WorkerMessageEvents | ChargingStationMessageEvents; - export const ChargingStationWorkerMessageEvents = { ...WorkerMessageEvents, ...ChargingStationMessageEvents, -}; +} as const; +export type ChargingStationWorkerMessageEvents = WorkerMessageEvents | ChargingStationMessageEvents; export type ChargingStationWorkerMessageData = ChargingStationData | Statistics; diff --git a/src/types/ConfigurationData.ts b/src/types/ConfigurationData.ts index 8ab9bcfd..b629dd3b 100644 --- a/src/types/ConfigurationData.ts +++ b/src/types/ConfigurationData.ts @@ -55,19 +55,19 @@ export type ConfigurationData = { performanceStorage?: StorageConfiguration; worker?: WorkerConfiguration; autoReconnectMaxRetries?: number; - // deprecated + /** @deprecated Moved to worker configuration section. */ workerProcess?: WorkerProcessType; - // deprecated + /** @deprecated Moved to worker configuration section. */ workerStartDelay?: number; - // deprecated + /** @deprecated Moved to worker configuration section. */ elementStartDelay?: number; - // deprecated + /** @deprecated Moved to worker configuration section. */ workerPoolMinSize?: number; - // deprecated + /** @deprecated Moved to worker configuration section. */ workerPoolMaxSize?: number; - // deprecated + /** @deprecated Moved to worker configuration section. */ workerPoolStrategy?: WorkerChoiceStrategy; - // deprecated + /** @deprecated Moved to worker configuration section. */ chargingStationsPerWorker?: number; logStatisticsInterval?: number; logFormat?: string; diff --git a/src/types/Statistics.ts b/src/types/Statistics.ts index 37460aee..f5a13ebb 100644 --- a/src/types/Statistics.ts +++ b/src/types/Statistics.ts @@ -29,5 +29,5 @@ export type Statistics = WorkerData & { uri: string; createdAt: Date; updatedAt?: Date; - statisticsData: Map>; + statisticsData: Map>; }; diff --git a/src/types/ocpp/ChargePointErrorCode.ts b/src/types/ocpp/ChargePointErrorCode.ts index 75c5c482..d08f17a0 100644 --- a/src/types/ocpp/ChargePointErrorCode.ts +++ b/src/types/ocpp/ChargePointErrorCode.ts @@ -1,7 +1,6 @@ import { OCPP16ChargePointErrorCode } from './1.6/ChargePointErrorCode'; -export type ChargePointErrorCode = OCPP16ChargePointErrorCode; - export const ChargePointErrorCode = { ...OCPP16ChargePointErrorCode, -}; +} as const; +export type ChargePointErrorCode = OCPP16ChargePointErrorCode; diff --git a/src/types/ocpp/ChargePointStatus.ts b/src/types/ocpp/ChargePointStatus.ts index c28fd6ef..a8ae442f 100644 --- a/src/types/ocpp/ChargePointStatus.ts +++ b/src/types/ocpp/ChargePointStatus.ts @@ -1,7 +1,6 @@ import { OCPP16ChargePointStatus } from './1.6/ChargePointStatus'; -export type ChargePointStatus = OCPP16ChargePointStatus; - export const ChargePointStatus = { ...OCPP16ChargePointStatus, -}; +} as const; +export type ChargePointStatus = OCPP16ChargePointStatus; diff --git a/src/types/ocpp/ChargingProfile.ts b/src/types/ocpp/ChargingProfile.ts index d2c36d7d..a8b73a24 100644 --- a/src/types/ocpp/ChargingProfile.ts +++ b/src/types/ocpp/ChargingProfile.ts @@ -8,8 +8,7 @@ export type ChargingProfile = OCPP16ChargingProfile; export type ChargingSchedulePeriod = OCPP16ChargingSchedulePeriod; -export type ChargingRateUnitType = OCPP16ChargingRateUnitType; - export const ChargingRateUnitType = { ...OCPP16ChargingRateUnitType, -}; +} as const; +export type ChargingRateUnitType = OCPP16ChargingRateUnitType; diff --git a/src/types/ocpp/Configuration.ts b/src/types/ocpp/Configuration.ts index f60c4f1c..aa50c752 100644 --- a/src/types/ocpp/Configuration.ts +++ b/src/types/ocpp/Configuration.ts @@ -5,23 +5,20 @@ import { OCPP16VendorDefaultParametersKey, } from './1.6/Configuration'; -export type StandardParametersKey = OCPP16StandardParametersKey; - export const StandardParametersKey = { ...OCPP16StandardParametersKey, -}; - -export type VendorDefaultParametersKey = OCPP16VendorDefaultParametersKey; +} as const; +export type StandardParametersKey = OCPP16StandardParametersKey; export const VendorDefaultParametersKey = { ...OCPP16VendorDefaultParametersKey, -}; - -export type SupportedFeatureProfiles = OCPP16SupportedFeatureProfiles; +} as const; +export type VendorDefaultParametersKey = OCPP16VendorDefaultParametersKey; export const SupportedFeatureProfiles = { ...OCPP16SupportedFeatureProfiles, -}; +} as const; +export type SupportedFeatureProfiles = OCPP16SupportedFeatureProfiles; export enum ConnectorPhaseRotation { NotApplicable = 'NotApplicable', diff --git a/src/types/ocpp/MeterValues.ts b/src/types/ocpp/MeterValues.ts index 2172ec1f..f34a8c17 100644 --- a/src/types/ocpp/MeterValues.ts +++ b/src/types/ocpp/MeterValues.ts @@ -1,21 +1,19 @@ import { - OCPP16MeterValue, + type OCPP16MeterValue, OCPP16MeterValueMeasurand, OCPP16MeterValuePhase, - OCPP16SampledValue, + type OCPP16SampledValue, } from './1.6/MeterValues'; -export type MeterValueMeasurand = OCPP16MeterValueMeasurand; - export const MeterValueMeasurand = { ...OCPP16MeterValueMeasurand, -}; - -export type MeterValuePhase = OCPP16MeterValuePhase; +} as const; +export type MeterValueMeasurand = OCPP16MeterValueMeasurand; export const MeterValuePhase = { ...OCPP16MeterValuePhase, -}; +} as const; +export type MeterValuePhase = OCPP16MeterValuePhase; export type SampledValue = OCPP16SampledValue; diff --git a/src/types/ocpp/OCPPVersion.ts b/src/types/ocpp/OCPPVersion.ts index 328ba2b4..a19fc280 100644 --- a/src/types/ocpp/OCPPVersion.ts +++ b/src/types/ocpp/OCPPVersion.ts @@ -1,4 +1,5 @@ export enum OCPPVersion { VERSION_16 = '1.6', VERSION_20 = '2.0', + VERSION_201 = '2.0.1', } diff --git a/src/types/ocpp/Requests.ts b/src/types/ocpp/Requests.ts index 871015b6..38596bfd 100644 --- a/src/types/ocpp/Requests.ts +++ b/src/types/ocpp/Requests.ts @@ -16,12 +16,11 @@ import { import { OCPP20IncomingRequestCommand, OCPP20RequestCommand } from './2.0/Requests'; import type { MessageType } from './MessageType'; -export type RequestCommand = OCPP16RequestCommand; - export const RequestCommand = { ...OCPP16RequestCommand, ...OCPP20RequestCommand, -}; +} as const; +export type RequestCommand = OCPP16RequestCommand | OCPP20RequestCommand; export type OutgoingRequest = [MessageType.CALL_MESSAGE, string, RequestCommand, JsonType]; @@ -30,12 +29,11 @@ export type RequestParams = { triggerMessage?: boolean; }; -export type IncomingRequestCommand = OCPP16IncomingRequestCommand; - export const IncomingRequestCommand = { ...OCPP16IncomingRequestCommand, ...OCPP20IncomingRequestCommand, -}; +} as const; +export type IncomingRequestCommand = OCPP16IncomingRequestCommand | OCPP20IncomingRequestCommand; export type IncomingRequest = [MessageType.CALL_MESSAGE, string, IncomingRequestCommand, JsonType]; @@ -50,11 +48,10 @@ export type CachedRequest = [ JsonType ]; -export type MessageTrigger = OCPP16MessageTrigger; - export const MessageTrigger = { ...OCPP16MessageTrigger, -}; +} as const; +export type MessageTrigger = OCPP16MessageTrigger; export type BootNotificationRequest = OCPP16BootNotificationRequest; @@ -71,16 +68,14 @@ export type IncomingRequestHandler = ( commandPayload: JsonType ) => JsonType | Promise; -export type AvailabilityType = OCPP16AvailabilityType; - export const AvailabilityType = { ...OCPP16AvailabilityType, -}; - -export type DiagnosticsStatus = OCPP16DiagnosticsStatus; +} as const; +export type AvailabilityType = OCPP16AvailabilityType; export const DiagnosticsStatus = { ...OCPP16DiagnosticsStatus, -}; +} as const; +export type DiagnosticsStatus = OCPP16DiagnosticsStatus; export type ResponseType = JsonType | OCPPError; diff --git a/src/types/ocpp/Responses.ts b/src/types/ocpp/Responses.ts index 2ddb98f2..59884dfd 100644 --- a/src/types/ocpp/Responses.ts +++ b/src/types/ocpp/Responses.ts @@ -3,15 +3,15 @@ import type { JsonType } from '../JsonType'; import type { OCPP16MeterValuesResponse } from './1.6/MeterValues'; import { OCPP16AvailabilityStatus, - OCPP16BootNotificationResponse, + type OCPP16BootNotificationResponse, OCPP16ChargingProfileStatus, OCPP16ClearChargingProfileStatus, OCPP16ConfigurationStatus, - OCPP16DataTransferResponse, + type OCPP16DataTransferResponse, OCPP16DataTransferStatus, - OCPP16HeartbeatResponse, + type OCPP16HeartbeatResponse, OCPP16RegistrationStatus, - OCPP16StatusNotificationResponse, + type OCPP16StatusNotificationResponse, OCPP16TriggerMessageStatus, OCPP16UnlockStatus, } from './1.6/Responses'; @@ -47,50 +47,42 @@ export type DefaultResponse = { status: DefaultStatus; }; -export type RegistrationStatus = OCPP16RegistrationStatus; - export const RegistrationStatus = { ...OCPP16RegistrationStatus, -}; - -export type AvailabilityStatus = OCPP16AvailabilityStatus; +} as const; +export type RegistrationStatus = OCPP16RegistrationStatus; export const AvailabilityStatus = { ...OCPP16AvailabilityStatus, -}; - -export type ChargingProfileStatus = OCPP16ChargingProfileStatus; +} as const; +export type AvailabilityStatus = OCPP16AvailabilityStatus; export const ChargingProfileStatus = { ...OCPP16ChargingProfileStatus, -}; - -export type ClearChargingProfileStatus = OCPP16ClearChargingProfileStatus; +} as const; +export type ChargingProfileStatus = OCPP16ChargingProfileStatus; export const ClearChargingProfileStatus = { ...OCPP16ClearChargingProfileStatus, -}; - -export type ConfigurationStatus = OCPP16ConfigurationStatus; +} as const; +export type ClearChargingProfileStatus = OCPP16ClearChargingProfileStatus; export const ConfigurationStatus = { ...OCPP16ConfigurationStatus, -}; - -export type UnlockStatus = OCPP16UnlockStatus; +} as const; +export type ConfigurationStatus = OCPP16ConfigurationStatus; export const UnlockStatus = { ...OCPP16UnlockStatus, -}; - -export type TriggerMessageStatus = OCPP16TriggerMessageStatus; +} as const; +export type UnlockStatus = OCPP16UnlockStatus; export const TriggerMessageStatus = { ...OCPP16TriggerMessageStatus, -}; - -export type DataTransferStatus = OCPP16DataTransferStatus; +} as const; +export type TriggerMessageStatus = OCPP16TriggerMessageStatus; export const DataTransferStatus = { ...OCPP16DataTransferStatus, -}; +} as const; +export type DataTransferStatus = OCPP16DataTransferStatus; diff --git a/src/types/ocpp/Transaction.ts b/src/types/ocpp/Transaction.ts index 3dd499c9..2a8a0ad4 100644 --- a/src/types/ocpp/Transaction.ts +++ b/src/types/ocpp/Transaction.ts @@ -1,29 +1,27 @@ import { OCPP16AuthorizationStatus, - OCPP16AuthorizeRequest, - OCPP16AuthorizeResponse, - OCPP16StartTransactionRequest, - OCPP16StartTransactionResponse, + type OCPP16AuthorizeRequest, + type OCPP16AuthorizeResponse, + type OCPP16StartTransactionRequest, + type OCPP16StartTransactionResponse, OCPP16StopTransactionReason, - OCPP16StopTransactionRequest, - OCPP16StopTransactionResponse, + type OCPP16StopTransactionRequest, + type OCPP16StopTransactionResponse, } from './1.6/Transaction'; -export type AuthorizationStatus = OCPP16AuthorizationStatus; - export const AuthorizationStatus = { ...OCPP16AuthorizationStatus, -}; +} as const; +export type AuthorizationStatus = OCPP16AuthorizationStatus; export type AuthorizeRequest = OCPP16AuthorizeRequest; export type AuthorizeResponse = OCPP16AuthorizeResponse; -export type StopTransactionReason = OCPP16StopTransactionReason; - export const StopTransactionReason = { ...OCPP16StopTransactionReason, -}; +} as const; +export type StopTransactionReason = OCPP16StopTransactionReason; export type StartTransactionRequest = OCPP16StartTransactionRequest; diff --git a/src/utils/CircularArray.ts b/src/utils/CircularArray.ts index 08a37220..d4e965e7 100644 --- a/src/utils/CircularArray.ts +++ b/src/utils/CircularArray.ts @@ -1,4 +1,4 @@ -// Copyright Jerome Benoit. 2021. All Rights Reserved. +// Copyright Jerome Benoit. 2021-2023. All Rights Reserved. export const DEFAULT_CIRCULAR_ARRAY_SIZE = Number.MAX_SAFE_INTEGER; diff --git a/src/utils/ElectricUtils.ts b/src/utils/ElectricUtils.ts index b779bf1d..7b913442 100644 --- a/src/utils/ElectricUtils.ts +++ b/src/utils/ElectricUtils.ts @@ -1,4 +1,4 @@ -// Copyright Jerome Benoit. 2021. All Rights Reserved. +// Copyright Jerome Benoit. 2021-2023. All Rights Reserved. /** * Rationale: https://wiki.piment-noir.org/doku.php/en:cs:modelling_multi-phased_electrical_system_interconnexion diff --git a/src/utils/Utils.ts b/src/utils/Utils.ts index 94fa3d18..0da6289c 100644 --- a/src/utils/Utils.ts +++ b/src/utils/Utils.ts @@ -267,7 +267,7 @@ export default class Utils { } public static JSONStringifyWithMapSupport( - obj: Record | Record[] | Map, + obj: Record | Record[] | Map, space?: number ): string { return JSON.stringify( diff --git a/src/worker/WorkerSet.ts b/src/worker/WorkerSet.ts index fba3516a..8a1aeb30 100644 --- a/src/worker/WorkerSet.ts +++ b/src/worker/WorkerSet.ts @@ -1,4 +1,4 @@ -// Partial Copyright Jerome Benoit. 2021. All Rights Reserved. +// Partial Copyright Jerome Benoit. 2021-2023. All Rights Reserved. import { Worker } from 'worker_threads'; diff --git a/ui/web/src/types/ChargingStationType.ts b/ui/web/src/types/ChargingStationType.ts index 3aa76983..80499a9f 100644 --- a/ui/web/src/types/ChargingStationType.ts +++ b/ui/web/src/types/ChargingStationType.ts @@ -86,11 +86,10 @@ export enum OCPP16IncomingRequestCommand { TRIGGER_MESSAGE = 'TriggerMessage', } -export type IncomingRequestCommand = OCPP16IncomingRequestCommand; - export const IncomingRequestCommand = { ...OCPP16IncomingRequestCommand, -}; +} as const; +export type IncomingRequestCommand = OCPP16IncomingRequestCommand; export enum OCPP16RequestCommand { BOOT_NOTIFICATION = 'BootNotification', @@ -103,11 +102,10 @@ export enum OCPP16RequestCommand { DIAGNOSTICS_STATUS_NOTIFICATION = 'DiagnosticsStatusNotification', } -export type RequestCommand = OCPP16RequestCommand; - export const RequestCommand = { ...OCPP16RequestCommand, -}; +} as const; +export type RequestCommand = OCPP16RequestCommand; export type BootNotificationResponse = OCPP16BootNotificationResponse; @@ -132,11 +130,10 @@ export enum OCPP16MessageTrigger { StatusNotification = 'StatusNotification', } -export type MessageTrigger = OCPP16MessageTrigger; - export const MessageTrigger = { ...OCPP16MessageTrigger, -}; +} as const; +export type MessageTrigger = OCPP16MessageTrigger; type CommandsSupport = { incomingCommands: Record;