From 1feac591544c625c56086abe1f14dbdc706280fb Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Sat, 10 Feb 2024 13:19:52 +0100 Subject: [PATCH] refactor: consolidate default values handling MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- README.md | 3 +- package.json | 12 +-- pnpm-lock.yaml | 74 ++++++++-------- src/charging-station/Bootstrap.ts | 11 +-- src/charging-station/ChargingStation.ts | 42 +++++----- src/charging-station/Helpers.ts | 8 -- .../ocpp/2.0/OCPP20IncomingRequestService.ts | 2 +- .../ocpp/2.0/OCPP20RequestService.ts | 2 +- .../ocpp/2.0/OCPP20ResponseService.ts | 2 +- .../ocpp/2.0/OCPP20ServiceUtils.ts | 2 +- src/exception/OCPPError.ts | 2 +- src/types/ChargingStationWorker.ts | 1 + src/utils/Constants.ts | 20 +++-- ui/web/pnpm-lock.yaml | 84 +++++++++---------- 14 files changed, 132 insertions(+), 133 deletions(-) diff --git a/README.md b/README.md index 3ee86b24..2234043f 100644 --- a/README.md +++ b/README.md @@ -577,7 +577,8 @@ Set the Websocket header _Sec-Websocket-Protocol_ to `ui0.0.1`. `autoStart?`: boolean, `autoRegister?`: boolean, `enableStatistics?`: boolean, - `ocppStrictCompliance?`: boolean + `ocppStrictCompliance?`: boolean, + `stopTransactionsOnStopped?`: boolean } } diff --git a/package.json b/package.json index 5cafe50f..40521799 100644 --- a/package.json +++ b/package.json @@ -92,10 +92,10 @@ } }, "dependencies": { - "@mikro-orm/core": "^6.1.0", - "@mikro-orm/mariadb": "^6.1.0", - "@mikro-orm/reflection": "^6.1.0", - "@mikro-orm/sqlite": "^6.1.0", + "@mikro-orm/core": "^6.1.1", + "@mikro-orm/mariadb": "^6.1.1", + "@mikro-orm/reflection": "^6.1.1", + "@mikro-orm/sqlite": "^6.1.1", "ajv": "^8.12.0", "ajv-formats": "^2.1.1", "basic-ftp": "^5.0.4", @@ -119,7 +119,7 @@ "devDependencies": { "@commitlint/cli": "^18.6.0", "@commitlint/config-conventional": "^18.6.0", - "@mikro-orm/cli": "^6.1.0", + "@mikro-orm/cli": "^6.1.1", "@release-it/bumper": "^6.0.1", "@types/node": "^20.11.17", "@types/tar": "^6.1.11", @@ -151,7 +151,7 @@ "rimraf": "^5.0.5", "semver": "^7.6.0", "ts-node": "^10.9.2", - "tsx": "^4.7.0", + "tsx": "^4.7.1", "typescript": "~5.3.3" } } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 727d0e9e..e476785f 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -15,17 +15,17 @@ overrides: dependencies: '@mikro-orm/core': - specifier: ^6.1.0 - version: 6.1.0 + specifier: ^6.1.1 + version: 6.1.1 '@mikro-orm/mariadb': - specifier: ^6.1.0 - version: 6.1.0(@mikro-orm/core@6.1.0) + specifier: ^6.1.1 + version: 6.1.1(@mikro-orm/core@6.1.1) '@mikro-orm/reflection': - specifier: ^6.1.0 - version: 6.1.0(@mikro-orm/core@6.1.0) + specifier: ^6.1.1 + version: 6.1.1(@mikro-orm/core@6.1.1) '@mikro-orm/sqlite': - specifier: ^6.1.0 - version: 6.1.0(@mikro-orm/core@6.1.0) + specifier: ^6.1.1 + version: 6.1.1(@mikro-orm/core@6.1.1) ajv: specifier: ^8.12.0 version: 8.12.0 @@ -88,8 +88,8 @@ devDependencies: specifier: ^18.6.0 version: 18.6.0 '@mikro-orm/cli': - specifier: ^6.1.0 - version: 6.1.0 + specifier: ^6.1.1 + version: 6.1.1 '@release-it/bumper': specifier: ^6.0.1 version: 6.0.1(release-it@17.0.3) @@ -184,8 +184,8 @@ devDependencies: specifier: ^10.9.2 version: 10.9.2(@types/node@20.11.17)(typescript@5.3.3) tsx: - specifier: ^4.7.0 - version: 4.7.0 + specifier: ^4.7.1 + version: 4.7.1 typescript: specifier: ~5.3.3 version: 5.3.3 @@ -1171,14 +1171,14 @@ packages: resolution: {integrity: sha512-9b8mPpKrfeGRuhFH5iO1iwCLeIIsV6+H1sRfxbkoGXIyQE2BTsPd9zqSqQJ+pv5sJ/hT5M1zvOFL02MnEezFug==} dev: true - /@mikro-orm/cli@6.1.0: - resolution: {integrity: sha512-uUbbSGPN9fuJEjtfQJ8RiTIAcf+kLgEinkvp7ywycsX02gXYtOpTqtvXm5Mj4Zju7XXpXcqJDlxav++GNR0gmg==} + /@mikro-orm/cli@6.1.1: + resolution: {integrity: sha512-1wh2dB60ScaOdQgyn6Zt7QJkk3r70ryiSC6vJ+uCuGzhjK5tnloGTzmYL/u/nIzCcLZhZKU113bcdShPsCx7/w==} engines: {node: '>= 18.12.0'} hasBin: true dependencies: '@jercle/yargonaut': 1.1.5 - '@mikro-orm/core': 6.1.0 - '@mikro-orm/knex': 6.1.0(@mikro-orm/core@6.1.0)(sqlite3@5.1.7) + '@mikro-orm/core': 6.1.1 + '@mikro-orm/knex': 6.1.1(@mikro-orm/core@6.1.1)(sqlite3@5.1.7) fs-extra: 11.2.0 tsconfig-paths: 4.2.0 yargs: 17.7.2 @@ -1193,8 +1193,8 @@ packages: - tedious dev: true - /@mikro-orm/core@6.1.0: - resolution: {integrity: sha512-jP0UzzpyWuE/jxXMesix16SLCsg8nBbogSuKKx3HQOnjd1xafPo4cCjaNFLlmSQbllbEbgTgsvy8Zh354A0X2g==} + /@mikro-orm/core@6.1.1: + resolution: {integrity: sha512-djnTurlUqjF/dwC2C9Xjyj3TqfvzBpF3T8EbYNWivwhvwphCCQSL30txHxaGLn8TA0B220y5L+K3813PnNKsog==} engines: {node: '>= 18.12.0'} dependencies: dataloader: 2.2.2 @@ -1202,16 +1202,16 @@ packages: esprima: 4.0.1 fs-extra: 11.2.0 globby: 11.1.0 - mikro-orm: 6.1.0 + mikro-orm: 6.1.1 reflect-metadata: 0.2.1 - /@mikro-orm/knex@6.1.0(@mikro-orm/core@6.1.0)(sqlite3@5.1.7): - resolution: {integrity: sha512-GEY/ywUxfo/te+1STi8yVXRNUqqS76QC0doDwrh2JHC73iq5tuuq7Nfw7VdLU6QGbarzUIhJOQHclfwTdZuHlQ==} + /@mikro-orm/knex@6.1.1(@mikro-orm/core@6.1.1)(sqlite3@5.1.7): + resolution: {integrity: sha512-FwYf1s+VC2GzE0Bg0aasuelfu4NKhO+HDwPanr4L2ixP78aURPrSihKuX7m9SRh38GDm/XtmywHXyW7UANX3SQ==} engines: {node: '>= 18.12.0'} peerDependencies: '@mikro-orm/core': ^6.0.0 dependencies: - '@mikro-orm/core': 6.1.0 + '@mikro-orm/core': 6.1.1 fs-extra: 11.2.0 knex: 3.1.0(sqlite3@5.1.7) sqlstring: 2.3.3 @@ -1225,14 +1225,14 @@ packages: - supports-color - tedious - /@mikro-orm/mariadb@6.1.0(@mikro-orm/core@6.1.0): - resolution: {integrity: sha512-bMR2keGwVgstbWo+c6Dee5oPuoG3/8AlheUtq6D1SbD1PiQT4EoJ48knejLyxcqc/uBW35uIXZ0xnE0l3rsuCA==} + /@mikro-orm/mariadb@6.1.1(@mikro-orm/core@6.1.1): + resolution: {integrity: sha512-SJiBi0a5gVWtbPyxmQDizQdOM6Gt91Lp17okhLxEhsJ+oMcPPcqCl6SeRcZO2CXAQXixwgzq9lfaKBb0iMttaA==} engines: {node: '>= 18.12.0'} peerDependencies: '@mikro-orm/core': ^6.0.0 dependencies: - '@mikro-orm/core': 6.1.0 - '@mikro-orm/knex': 6.1.0(@mikro-orm/core@6.1.0)(sqlite3@5.1.7) + '@mikro-orm/core': 6.1.1 + '@mikro-orm/knex': 6.1.1(@mikro-orm/core@6.1.1)(sqlite3@5.1.7) mariadb: 2.5.6 transitivePeerDependencies: - better-sqlite3 @@ -1245,25 +1245,25 @@ packages: - tedious dev: false - /@mikro-orm/reflection@6.1.0(@mikro-orm/core@6.1.0): - resolution: {integrity: sha512-AzYt/l5FTNjc5seYPNBAeJUg3UoJHFxvwXwU0//BnEstn4b0c3/nnVYJeEO+1LgyPNQi/v/j5kT0w3Q2WExlbA==} + /@mikro-orm/reflection@6.1.1(@mikro-orm/core@6.1.1): + resolution: {integrity: sha512-NngKD3RAQEKWqIXxkqTfcnOoUWSQy4AcjqziEXHAzwiYhQlCz5nL1nM+Nr06et0oxEakW87eciRZOpfEpPmgNQ==} engines: {node: '>= 18.12.0'} peerDependencies: '@mikro-orm/core': ^6.0.0 dependencies: - '@mikro-orm/core': 6.1.0 + '@mikro-orm/core': 6.1.1 globby: 11.1.0 ts-morph: 21.0.1 dev: false - /@mikro-orm/sqlite@6.1.0(@mikro-orm/core@6.1.0): - resolution: {integrity: sha512-JGc8/Xae6o6LZswKQuRvk5/zMS50l53a0iHG4TMX/QCXYYnuuvEfhcPfRObHVzyBCjBGPXbt9t5ZDUmRYbe7pw==} + /@mikro-orm/sqlite@6.1.1(@mikro-orm/core@6.1.1): + resolution: {integrity: sha512-e+Y7fkLkG2GyMpvoboPKgUIP8MrQsqaazDMosOb220vgEWVQ8u7ouBK20LBX2JENXXv5ok9e4xOMKX/dLgkElg==} engines: {node: '>= 18.12.0'} peerDependencies: '@mikro-orm/core': ^6.0.0 dependencies: - '@mikro-orm/core': 6.1.0 - '@mikro-orm/knex': 6.1.0(@mikro-orm/core@6.1.0)(sqlite3@5.1.7) + '@mikro-orm/core': 6.1.1 + '@mikro-orm/knex': 6.1.1(@mikro-orm/core@6.1.1)(sqlite3@5.1.7) fs-extra: 11.2.0 sqlite3: 5.1.7 sqlstring-sqlite: 0.1.1 @@ -6621,8 +6621,8 @@ packages: braces: 3.0.2 picomatch: 2.3.1 - /mikro-orm@6.1.0: - resolution: {integrity: sha512-NLdDdAE6rAj3886am2GSz7E7ntSXVTNDLGdU349q4PfkRFZniZBmc16bWW0JNBhZYZYkBVqfdm2Y2h39iqmI4g==} + /mikro-orm@6.1.1: + resolution: {integrity: sha512-Qadd/5c86+IFd+vHhimxlu1j5436FbiGGYP5+7a3PO+PKWXfHs4dAQ7wYEl0jjN1VGzQnuzEDHXsbnUPQSPETA==} engines: {node: '>= 18.12.0'} /miller-rabin@4.0.1: @@ -9310,8 +9310,8 @@ packages: resolution: {integrity: sha512-AEYxH93jGFPn/a2iVAwW87VuUIkR1FVUKB77NwMF7nBTDkDrrT/Hpt/IrCJ0QXhW27jTBDcf5ZY7w6RiqTMw2Q==} dev: true - /tsx@4.7.0: - resolution: {integrity: sha512-I+t79RYPlEYlHn9a+KzwrvEwhJg35h/1zHsLC2JXvhC2mdynMv6Zxzvhv5EMV6VF5qJlLlkSnMVvdZV3PSIGcg==} + /tsx@4.7.1: + resolution: {integrity: sha512-8d6VuibXHtlN5E3zFkgY8u4DX7Y3Z27zvvPKVmLon/D4AjuKzarkUBTLDBgj9iTQ0hg5xM7c/mYiRVM+HETf0g==} engines: {node: '>=18.0.0'} hasBin: true dependencies: diff --git a/src/charging-station/Bootstrap.ts b/src/charging-station/Bootstrap.ts index acd8e73c..ddf8ee70 100644 --- a/src/charging-station/Bootstrap.ts +++ b/src/charging-station/Bootstrap.ts @@ -300,17 +300,18 @@ export class Bootstrap extends EventEmitter { if (!isMainThread) { return } - let elementsPerWorker: number | undefined + let elementsPerWorker: number switch (workerConfiguration.elementsPerWorker) { + case 'all': + elementsPerWorker = this.numberOfConfiguredChargingStations + break case 'auto': + default: elementsPerWorker = this.numberOfConfiguredChargingStations > availableParallelism() ? Math.round(this.numberOfConfiguredChargingStations / (availableParallelism() * 1.5)) : 1 break - case 'all': - elementsPerWorker = this.numberOfConfiguredChargingStations - break } this.workerImplementation = WorkerFactory.getWorkerImplementation( join( @@ -326,7 +327,7 @@ export class Bootstrap extends EventEmitter { poolMaxSize: workerConfiguration.poolMaxSize!, // eslint-disable-next-line @typescript-eslint/no-non-null-assertion poolMinSize: workerConfiguration.poolMinSize!, - elementsPerWorker: elementsPerWorker ?? (workerConfiguration.elementsPerWorker as number), + elementsPerWorker, poolOptions: { messageHandler: this.messageHandler.bind(this) as MessageHandler, workerOptions: { resourceLimits: workerConfiguration.resourceLimits } diff --git a/src/charging-station/ChargingStation.ts b/src/charging-station/ChargingStation.ts index c9c8208a..4ef9ab5d 100644 --- a/src/charging-station/ChargingStation.ts +++ b/src/charging-station/ChargingStation.ts @@ -1147,10 +1147,8 @@ export class ChargingStation extends EventEmitter { } const stationInfo = stationTemplateToStationInfo(stationTemplate) stationInfo.hashId = getHashId(this.index, stationTemplate) - stationInfo.autoStart = stationTemplate.autoStart ?? true stationInfo.templateName = parse(this.templateFile).name stationInfo.chargingStationId = getChargingStationId(this.index, stationTemplate) - stationInfo.ocppVersion = stationTemplate.ocppVersion ?? OCPPVersion.VERSION_16 createSerialNumber(stationTemplate, stationInfo) stationInfo.voltageOut = this.getVoltageOut(stationInfo) if (isNotEmptyArray(stationTemplate.power)) { @@ -1167,9 +1165,8 @@ export class ChargingStation extends EventEmitter { : stationTemplate.power } stationInfo.maximumAmperage = this.getMaximumAmperage(stationInfo) - stationInfo.firmwareVersionPattern = - stationTemplate.firmwareVersionPattern ?? Constants.SEMVER_PATTERN if ( + isNotEmptyString(stationInfo.firmwareVersionPattern) && isNotEmptyString(stationInfo.firmwareVersion) && !new RegExp(stationInfo.firmwareVersionPattern).test(stationInfo.firmwareVersion) ) { @@ -1188,10 +1185,9 @@ export class ChargingStation extends EventEmitter { }, stationTemplate.firmwareUpgrade ?? {} ) - stationInfo.resetTime = - stationTemplate.resetTime != null - ? secondsToMilliseconds(stationTemplate.resetTime) - : Constants.DEFAULT_CHARGING_STATION_RESET_TIME + if (stationTemplate.resetTime != null) { + stationInfo.resetTime = secondsToMilliseconds(stationTemplate.resetTime) + } return stationInfo } @@ -1208,9 +1204,6 @@ export class ChargingStation extends EventEmitter { if (stationInfo.templateName == null) { stationInfo.templateName = parse(this.templateFile).name } - if (stationInfo.autoStart == null) { - stationInfo.autoStart = true - } } } return stationInfo @@ -1275,8 +1268,6 @@ export class ChargingStation extends EventEmitter { this.stationInfo = this.getStationInfo(options?.persistentConfiguration) if (options?.persistentConfiguration != null) { this.stationInfo.ocppPersistentConfiguration = options.persistentConfiguration - } - if (options?.persistentConfiguration != null) { this.stationInfo.automaticTransactionGeneratorPersistentConfiguration = options.persistentConfiguration } @@ -1289,10 +1280,13 @@ export class ChargingStation extends EventEmitter { if (options?.ocppStrictCompliance != null) { this.stationInfo.ocppStrictCompliance = options.ocppStrictCompliance } + if (options?.stopTransactionsOnStopped != null) { + this.stationInfo.stopTransactionsOnStopped = options.stopTransactionsOnStopped + } if ( this.stationInfo.firmwareStatus === FirmwareStatus.Installing && - isNotEmptyString(this.stationInfo.firmwareVersion) && - isNotEmptyString(this.stationInfo.firmwareVersionPattern) + isNotEmptyString(this.stationInfo.firmwareVersionPattern) && + isNotEmptyString(this.stationInfo.firmwareVersion) ) { const patternGroup = this.stationInfo.firmwareUpgrade?.versionUpgrade?.patternGroup ?? @@ -1809,8 +1803,7 @@ export class ChargingStation extends EventEmitter { } private getOcppConfiguration ( - ocppPersistentConfiguration: boolean | undefined = Constants.DEFAULT_STATION_INFO - .ocppPersistentConfiguration + ocppPersistentConfiguration: boolean | undefined = this.stationInfo?.ocppPersistentConfiguration ): ChargingStationOcppConfiguration | undefined { let ocppConfiguration: ChargingStationOcppConfiguration | undefined = this.getOcppConfigurationFromFile(ocppPersistentConfiguration) @@ -2066,7 +2059,7 @@ export class ChargingStation extends EventEmitter { if (!(error instanceof OCPPError)) { logger.warn( `${this.logPrefix()} Error thrown at incoming OCPP command '${ - commandName ?? requestCommandName ?? Constants.UNKNOWN_COMMAND + commandName ?? requestCommandName ?? Constants.UNKNOWN_OCPP_COMMAND // eslint-disable-next-line @typescript-eslint/no-base-to-string }' message '${data.toString()}' handling is not an OCPPError:`, error @@ -2074,7 +2067,7 @@ export class ChargingStation extends EventEmitter { } logger.error( `${this.logPrefix()} Incoming OCPP command '${ - commandName ?? requestCommandName ?? Constants.UNKNOWN_COMMAND + commandName ?? requestCommandName ?? Constants.UNKNOWN_OCPP_COMMAND // eslint-disable-next-line @typescript-eslint/no-base-to-string }' message '${data.toString()}'${ this.requests.has(messageId) @@ -2122,7 +2115,8 @@ export class ChargingStation extends EventEmitter { } private getUseConnectorId0 (stationTemplate?: ChargingStationTemplate): boolean { - return stationTemplate?.useConnectorId0 ?? true + // eslint-disable-next-line @typescript-eslint/no-non-null-assertion + return stationTemplate?.useConnectorId0 ?? Constants.DEFAULT_STATION_INFO.useConnectorId0! } private async stopRunningTransactions (reason?: StopTransactionReason): Promise { @@ -2181,8 +2175,12 @@ export class ChargingStation extends EventEmitter { } private getCurrentOutType (stationInfo?: ChargingStationInfo): CurrentType { - // eslint-disable-next-line @typescript-eslint/no-non-null-assertion - return (stationInfo ?? this.stationInfo!).currentOutType ?? CurrentType.AC + return ( + // eslint-disable-next-line @typescript-eslint/no-non-null-assertion + (stationInfo ?? this.stationInfo!).currentOutType ?? + // eslint-disable-next-line @typescript-eslint/no-non-null-assertion + Constants.DEFAULT_STATION_INFO.currentOutType! + ) } private getVoltageOut (stationInfo?: ChargingStationInfo): Voltage { diff --git a/src/charging-station/Helpers.ts b/src/charging-station/Helpers.ts index 8be89fe1..df3d0308 100644 --- a/src/charging-station/Helpers.ts +++ b/src/charging-station/Helpers.ts @@ -247,14 +247,6 @@ export const checkTemplate = ( logger.error(`${logPrefix} ${errorMsg}`) throw new BaseError(errorMsg) } - // eslint-disable-next-line @typescript-eslint/no-non-null-assertion - if (isEmptyObject(stationTemplate.AutomaticTransactionGenerator!)) { - stationTemplate.AutomaticTransactionGenerator = Constants.DEFAULT_ATG_CONFIGURATION - logger.warn( - `${logPrefix} Empty automatic transaction generator configuration from template file ${templateFile}, set to default: %j`, - Constants.DEFAULT_ATG_CONFIGURATION - ) - } if (stationTemplate.idTagsFile == null || isEmptyString(stationTemplate.idTagsFile)) { logger.warn( `${logPrefix} Missing id tags file in template file ${templateFile}. That can lead to issues with the Automatic Transaction Generator` diff --git a/src/charging-station/ocpp/2.0/OCPP20IncomingRequestService.ts b/src/charging-station/ocpp/2.0/OCPP20IncomingRequestService.ts index b45345a6..32843895 100644 --- a/src/charging-station/ocpp/2.0/OCPP20IncomingRequestService.ts +++ b/src/charging-station/ocpp/2.0/OCPP20IncomingRequestService.ts @@ -30,7 +30,7 @@ export class OCPP20IncomingRequestService extends OCPPIncomingRequestService { // if (new.target.name === moduleName) { // throw new TypeError(`Cannot construct ${new.target.name} instances directly`) // } - super(OCPPVersion.VERSION_20) + super(OCPPVersion.VERSION_201) this.incomingRequestHandlers = new Map([ [OCPP20IncomingRequestCommand.CLEAR_CACHE, this.handleRequestClearCache.bind(this)] ]) diff --git a/src/charging-station/ocpp/2.0/OCPP20RequestService.ts b/src/charging-station/ocpp/2.0/OCPP20RequestService.ts index a61fc2ae..03921891 100644 --- a/src/charging-station/ocpp/2.0/OCPP20RequestService.ts +++ b/src/charging-station/ocpp/2.0/OCPP20RequestService.ts @@ -30,7 +30,7 @@ export class OCPP20RequestService extends OCPPRequestService { // if (new.target.name === moduleName) { // throw new TypeError(`Cannot construct ${new.target.name} instances directly`) // } - super(OCPPVersion.VERSION_20, ocppResponseService) + super(OCPPVersion.VERSION_201, ocppResponseService) this.payloadValidateFunctions = new Map>([ [ OCPP20RequestCommand.BOOT_NOTIFICATION, diff --git a/src/charging-station/ocpp/2.0/OCPP20ResponseService.ts b/src/charging-station/ocpp/2.0/OCPP20ResponseService.ts index ef0a0360..09b319c9 100644 --- a/src/charging-station/ocpp/2.0/OCPP20ResponseService.ts +++ b/src/charging-station/ocpp/2.0/OCPP20ResponseService.ts @@ -37,7 +37,7 @@ export class OCPP20ResponseService extends OCPPResponseService { // if (new.target.name === moduleName) { // throw new TypeError(`Cannot construct ${new.target.name} instances directly`) // } - super(OCPPVersion.VERSION_20) + super(OCPPVersion.VERSION_201) this.responseHandlers = new Map([ [ OCPP20RequestCommand.BOOT_NOTIFICATION, diff --git a/src/charging-station/ocpp/2.0/OCPP20ServiceUtils.ts b/src/charging-station/ocpp/2.0/OCPP20ServiceUtils.ts index 38110e6f..75d61731 100644 --- a/src/charging-station/ocpp/2.0/OCPP20ServiceUtils.ts +++ b/src/charging-station/ocpp/2.0/OCPP20ServiceUtils.ts @@ -13,7 +13,7 @@ export class OCPP20ServiceUtils extends OCPPServiceUtils { ): JSONSchemaType { return super.parseJsonSchemaFile( relativePath, - OCPPVersion.VERSION_20, + OCPPVersion.VERSION_201, moduleName, methodName ) diff --git a/src/exception/OCPPError.ts b/src/exception/OCPPError.ts index 41414fe9..27876dad 100644 --- a/src/exception/OCPPError.ts +++ b/src/exception/OCPPError.ts @@ -18,7 +18,7 @@ export class OCPPError extends BaseError { super(message) this.code = code - this.command = command ?? Constants.UNKNOWN_COMMAND + this.command = command ?? Constants.UNKNOWN_OCPP_COMMAND this.details = details } } diff --git a/src/types/ChargingStationWorker.ts b/src/types/ChargingStationWorker.ts index e6e34a89..6dbd8793 100644 --- a/src/types/ChargingStationWorker.ts +++ b/src/types/ChargingStationWorker.ts @@ -17,6 +17,7 @@ export interface ChargingStationOptions extends JsonObject { autoRegister?: boolean enableStatistics?: boolean ocppStrictCompliance?: boolean + stopTransactionsOnStopped?: boolean } export interface ChargingStationWorkerData extends WorkerData { diff --git a/src/utils/Constants.ts b/src/utils/Constants.ts index 38890575..c467df73 100644 --- a/src/utils/Constants.ts +++ b/src/utils/Constants.ts @@ -10,8 +10,15 @@ import { // eslint-disable-next-line @typescript-eslint/no-extraneous-class export class Constants { + // See https://semver.org/#is-there-a-suggested-regular-expression-regex-to-check-a-semver-string + private static readonly SEMVER_PATTERN = + '^(0|[1-9]\\d*)\\.(0|[1-9]\\d*)\\.(0|[1-9]\\d*)(?:-((?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\\.(?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\\+([0-9a-zA-Z-]+(?:\\.[0-9a-zA-Z-]+)*))?$' + + private static readonly DEFAULT_CHARGING_STATION_RESET_TIME = 60000 // Ms + static readonly DEFAULT_STATION_INFO: Partial = Object.freeze({ enableStatistics: false, + autoStart: true, remoteAuthorization: true, currentOutType: CurrentType.AC, mainVoltageMeterValues: true, @@ -24,10 +31,13 @@ export class Constants { transactionDataMeterValues: false, supervisionUrlOcppConfiguration: false, supervisionUrlOcppKey: VendorParametersKey.ConnectionUrl, + useConnectorId0: true, ocppVersion: OCPPVersion.VERSION_16, + firmwareVersionPattern: Constants.SEMVER_PATTERN, ocppPersistentConfiguration: true, stationInfoPersistentConfiguration: true, automaticTransactionGeneratorPersistentConfiguration: true, + resetTime: Constants.DEFAULT_CHARGING_STATION_RESET_TIME, autoReconnectMaxRetries: -1, registrationMaxRetries: -1, reconnectExponentialDelay: false, @@ -38,8 +48,6 @@ export class Constants { static readonly DEFAULT_HEARTBEAT_INTERVAL = 60000 // Ms static readonly DEFAULT_METER_VALUES_INTERVAL = 60000 // Ms - static readonly DEFAULT_CHARGING_STATION_RESET_TIME = 60000 // Ms - static readonly DEFAULT_ATG_WAIT_TIME = 1000 // Ms static readonly DEFAULT_ATG_CONFIGURATION: AutomaticTransactionGeneratorConfiguration = Object.freeze({ @@ -53,10 +61,6 @@ export class Constants { stopAbsoluteDuration: false }) - // See https://semver.org/#is-there-a-suggested-regular-expression-regex-to-check-a-semver-string - static readonly SEMVER_PATTERN = - '^(0|[1-9]\\d*)\\.(0|[1-9]\\d*)\\.(0|[1-9]\\d*)(?:-((?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\\.(?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\\+([0-9a-zA-Z-]+(?:\\.[0-9a-zA-Z-]+)*))?$' - static readonly DEFAULT_CIRCULAR_BUFFER_CAPACITY = 4096 static readonly DEFAULT_HASH_ALGORITHM = 'sha384' @@ -77,7 +81,9 @@ export class Constants { static readonly DEFAULT_UI_SERVER_HOST = 'localhost' static readonly DEFAULT_UI_SERVER_PORT = 8080 - static readonly UNKNOWN_COMMAND = 'unknown command' as RequestCommand | IncomingRequestCommand + static readonly UNKNOWN_OCPP_COMMAND = 'unknown OCPP command' as + | RequestCommand + | IncomingRequestCommand static readonly MAX_RANDOM_INTEGER = 281474976710654 diff --git a/ui/web/pnpm-lock.yaml b/ui/web/pnpm-lock.yaml index 4b8be6ee..07bfbb1a 100644 --- a/ui/web/pnpm-lock.yaml +++ b/ui/web/pnpm-lock.yaml @@ -754,104 +754,104 @@ packages: engines: {node: ^12.20.0 || ^14.18.0 || >=16.0.0} dev: true - /@rollup/rollup-android-arm-eabi@4.9.6: - resolution: {integrity: sha512-MVNXSSYN6QXOulbHpLMKYi60ppyO13W9my1qogeiAqtjb2yR4LSmfU2+POvDkLzhjYLXz9Rf9+9a3zFHW1Lecg==} + /@rollup/rollup-android-arm-eabi@4.10.0: + resolution: {integrity: sha512-/MeDQmcD96nVoRumKUljsYOLqfv1YFJps+0pTrb2Z9Nl/w5qNUysMaWQsrd1mvAlNT4yza1iVyIu4Q4AgF6V3A==} cpu: [arm] os: [android] requiresBuild: true dev: true optional: true - /@rollup/rollup-android-arm64@4.9.6: - resolution: {integrity: sha512-T14aNLpqJ5wzKNf5jEDpv5zgyIqcpn1MlwCrUXLrwoADr2RkWA0vOWP4XxbO9aiO3dvMCQICZdKeDrFl7UMClw==} + /@rollup/rollup-android-arm64@4.10.0: + resolution: {integrity: sha512-lvu0jK97mZDJdpZKDnZI93I0Om8lSDaiPx3OiCk0RXn3E8CMPJNS/wxjAvSJJzhhZpfjXsjLWL8LnS6qET4VNQ==} cpu: [arm64] os: [android] requiresBuild: true dev: true optional: true - /@rollup/rollup-darwin-arm64@4.9.6: - resolution: {integrity: sha512-CqNNAyhRkTbo8VVZ5R85X73H3R5NX9ONnKbXuHisGWC0qRbTTxnF1U4V9NafzJbgGM0sHZpdO83pLPzq8uOZFw==} + /@rollup/rollup-darwin-arm64@4.10.0: + resolution: {integrity: sha512-uFpayx8I8tyOvDkD7X6n0PriDRWxcqEjqgtlxnUA/G9oS93ur9aZ8c8BEpzFmsed1TH5WZNG5IONB8IiW90TQg==} cpu: [arm64] os: [darwin] requiresBuild: true dev: true optional: true - /@rollup/rollup-darwin-x64@4.9.6: - resolution: {integrity: sha512-zRDtdJuRvA1dc9Mp6BWYqAsU5oeLixdfUvkTHuiYOHwqYuQ4YgSmi6+/lPvSsqc/I0Omw3DdICx4Tfacdzmhog==} + /@rollup/rollup-darwin-x64@4.10.0: + resolution: {integrity: sha512-nIdCX03qFKoR/MwQegQBK+qZoSpO3LESurVAC6s6jazLA1Mpmgzo3Nj3H1vydXp/JM29bkCiuF7tDuToj4+U9Q==} cpu: [x64] os: [darwin] requiresBuild: true dev: true optional: true - /@rollup/rollup-linux-arm-gnueabihf@4.9.6: - resolution: {integrity: sha512-oNk8YXDDnNyG4qlNb6is1ojTOGL/tRhbbKeE/YuccItzerEZT68Z9gHrY3ROh7axDc974+zYAPxK5SH0j/G+QQ==} + /@rollup/rollup-linux-arm-gnueabihf@4.10.0: + resolution: {integrity: sha512-Fz7a+y5sYhYZMQFRkOyCs4PLhICAnxRX/GnWYReaAoruUzuRtcf+Qnw+T0CoAWbHCuz2gBUwmWnUgQ67fb3FYw==} cpu: [arm] os: [linux] requiresBuild: true dev: true optional: true - /@rollup/rollup-linux-arm64-gnu@4.9.6: - resolution: {integrity: sha512-Z3O60yxPtuCYobrtzjo0wlmvDdx2qZfeAWTyfOjEDqd08kthDKexLpV97KfAeUXPosENKd8uyJMRDfFMxcYkDQ==} + /@rollup/rollup-linux-arm64-gnu@4.10.0: + resolution: {integrity: sha512-yPtF9jIix88orwfTi0lJiqINnlWo6p93MtZEoaehZnmCzEmLL0eqjA3eGVeyQhMtxdV+Mlsgfwhh0+M/k1/V7Q==} cpu: [arm64] os: [linux] requiresBuild: true dev: true optional: true - /@rollup/rollup-linux-arm64-musl@4.9.6: - resolution: {integrity: sha512-gpiG0qQJNdYEVad+1iAsGAbgAnZ8j07FapmnIAQgODKcOTjLEWM9sRb+MbQyVsYCnA0Im6M6QIq6ax7liws6eQ==} + /@rollup/rollup-linux-arm64-musl@4.10.0: + resolution: {integrity: sha512-9GW9yA30ib+vfFiwjX+N7PnjTnCMiUffhWj4vkG4ukYv1kJ4T9gHNg8zw+ChsOccM27G9yXrEtMScf1LaCuoWQ==} cpu: [arm64] os: [linux] requiresBuild: true dev: true optional: true - /@rollup/rollup-linux-riscv64-gnu@4.9.6: - resolution: {integrity: sha512-+uCOcvVmFUYvVDr27aiyun9WgZk0tXe7ThuzoUTAukZJOwS5MrGbmSlNOhx1j80GdpqbOty05XqSl5w4dQvcOA==} + /@rollup/rollup-linux-riscv64-gnu@4.10.0: + resolution: {integrity: sha512-X1ES+V4bMq2ws5fF4zHornxebNxMXye0ZZjUrzOrf7UMx1d6wMQtfcchZ8SqUnQPPHdOyOLW6fTcUiFgHFadRA==} cpu: [riscv64] os: [linux] requiresBuild: true dev: true optional: true - /@rollup/rollup-linux-x64-gnu@4.9.6: - resolution: {integrity: sha512-HUNqM32dGzfBKuaDUBqFB7tP6VMN74eLZ33Q9Y1TBqRDn+qDonkAUyKWwF9BR9unV7QUzffLnz9GrnKvMqC/fw==} + /@rollup/rollup-linux-x64-gnu@4.10.0: + resolution: {integrity: sha512-w/5OpT2EnI/Xvypw4FIhV34jmNqU5PZjZue2l2Y3ty1Ootm3SqhI+AmfhlUYGBTd9JnpneZCDnt3uNOiOBkMyw==} cpu: [x64] os: [linux] requiresBuild: true dev: true optional: true - /@rollup/rollup-linux-x64-musl@4.9.6: - resolution: {integrity: sha512-ch7M+9Tr5R4FK40FHQk8VnML0Szi2KRujUgHXd/HjuH9ifH72GUmw6lStZBo3c3GB82vHa0ZoUfjfcM7JiiMrQ==} + /@rollup/rollup-linux-x64-musl@4.10.0: + resolution: {integrity: sha512-q/meftEe3QlwQiGYxD9rWwB21DoKQ9Q8wA40of/of6yGHhZuGfZO0c3WYkN9dNlopHlNT3mf5BPsUSxoPuVQaw==} cpu: [x64] os: [linux] requiresBuild: true dev: true optional: true - /@rollup/rollup-win32-arm64-msvc@4.9.6: - resolution: {integrity: sha512-VD6qnR99dhmTQ1mJhIzXsRcTBvTjbfbGGwKAHcu+52cVl15AC/kplkhxzW/uT0Xl62Y/meBKDZvoJSJN+vTeGA==} + /@rollup/rollup-win32-arm64-msvc@4.10.0: + resolution: {integrity: sha512-NrR6667wlUfP0BHaEIKgYM/2va+Oj+RjZSASbBMnszM9k+1AmliRjHc3lJIiOehtSSjqYiO7R6KLNrWOX+YNSQ==} cpu: [arm64] os: [win32] requiresBuild: true dev: true optional: true - /@rollup/rollup-win32-ia32-msvc@4.9.6: - resolution: {integrity: sha512-J9AFDq/xiRI58eR2NIDfyVmTYGyIZmRcvcAoJ48oDld/NTR8wyiPUu2X/v1navJ+N/FGg68LEbX3Ejd6l8B7MQ==} + /@rollup/rollup-win32-ia32-msvc@4.10.0: + resolution: {integrity: sha512-FV0Tpt84LPYDduIDcXvEC7HKtyXxdvhdAOvOeWMWbQNulxViH2O07QXkT/FffX4FqEI02jEbCJbr+YcuKdyyMg==} cpu: [ia32] os: [win32] requiresBuild: true dev: true optional: true - /@rollup/rollup-win32-x64-msvc@4.9.6: - resolution: {integrity: sha512-jqzNLhNDvIZOrt69Ce4UjGRpXJBzhUBzawMwnaDAwyHriki3XollsewxWzOzz+4yOFDkuJHtTsZFwMxhYJWmLQ==} + /@rollup/rollup-win32-x64-msvc@4.10.0: + resolution: {integrity: sha512-OZoJd+o5TaTSQeFFQ6WjFCiltiYVjIdsXxwu/XZ8qRpsvMQr4UsVrE5UyT9RIvsnuF47DqkJKhhVZ2Q9YW9IpQ==} cpu: [x64] os: [win32] requiresBuild: true @@ -3410,26 +3410,26 @@ packages: glob: 10.3.10 dev: true - /rollup@4.9.6: - resolution: {integrity: sha512-05lzkCS2uASX0CiLFybYfVkwNbKZG5NFQ6Go0VWyogFTXXbR039UVsegViTntkk4OglHBdF54ccApXRRuXRbsg==} + /rollup@4.10.0: + resolution: {integrity: sha512-t2v9G2AKxcQ8yrG+WGxctBes1AomT0M4ND7jTFBCVPXQ/WFTvNSefIrNSmLKhIKBrvN8SG+CZslimJcT3W2u2g==} engines: {node: '>=18.0.0', npm: '>=8.0.0'} hasBin: true dependencies: '@types/estree': 1.0.5 optionalDependencies: - '@rollup/rollup-android-arm-eabi': 4.9.6 - '@rollup/rollup-android-arm64': 4.9.6 - '@rollup/rollup-darwin-arm64': 4.9.6 - '@rollup/rollup-darwin-x64': 4.9.6 - '@rollup/rollup-linux-arm-gnueabihf': 4.9.6 - '@rollup/rollup-linux-arm64-gnu': 4.9.6 - '@rollup/rollup-linux-arm64-musl': 4.9.6 - '@rollup/rollup-linux-riscv64-gnu': 4.9.6 - '@rollup/rollup-linux-x64-gnu': 4.9.6 - '@rollup/rollup-linux-x64-musl': 4.9.6 - '@rollup/rollup-win32-arm64-msvc': 4.9.6 - '@rollup/rollup-win32-ia32-msvc': 4.9.6 - '@rollup/rollup-win32-x64-msvc': 4.9.6 + '@rollup/rollup-android-arm-eabi': 4.10.0 + '@rollup/rollup-android-arm64': 4.10.0 + '@rollup/rollup-darwin-arm64': 4.10.0 + '@rollup/rollup-darwin-x64': 4.10.0 + '@rollup/rollup-linux-arm-gnueabihf': 4.10.0 + '@rollup/rollup-linux-arm64-gnu': 4.10.0 + '@rollup/rollup-linux-arm64-musl': 4.10.0 + '@rollup/rollup-linux-riscv64-gnu': 4.10.0 + '@rollup/rollup-linux-x64-gnu': 4.10.0 + '@rollup/rollup-linux-x64-musl': 4.10.0 + '@rollup/rollup-win32-arm64-msvc': 4.10.0 + '@rollup/rollup-win32-ia32-msvc': 4.10.0 + '@rollup/rollup-win32-x64-msvc': 4.10.0 fsevents: 2.3.3 dev: true @@ -3973,7 +3973,7 @@ packages: '@types/node': 20.11.17 esbuild: 0.19.12 postcss: 8.4.35 - rollup: 4.9.6 + rollup: 4.10.0 optionalDependencies: fsevents: 2.3.3 dev: true -- 2.34.1