From 4ed03b6ec8110ad11b67ead121145c80995f69df Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Sat, 30 Sep 2023 12:17:29 +0200 Subject: [PATCH] refactor: null -> undefined where appropriate MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- src/charging-station/Bootstrap.ts | 4 ++-- src/charging-station/ChargingStation.ts | 5 +++-- src/charging-station/ChargingStationWorker.ts | 2 +- .../ocpp/1.6/OCPP16IncomingRequestService.ts | 8 ++++---- src/charging-station/ocpp/1.6/OCPP16ResponseService.ts | 4 ++-- src/charging-station/ocpp/1.6/OCPP16ServiceUtils.ts | 6 +++--- .../ocpp/2.0/OCPP20IncomingRequestService.ts | 6 +++--- src/charging-station/ocpp/2.0/OCPP20ResponseService.ts | 4 ++-- src/charging-station/ocpp/OCPPIncomingRequestService.ts | 2 +- src/charging-station/ocpp/OCPPRequestService.ts | 4 ++-- src/charging-station/ocpp/OCPPResponseService.ts | 2 +- .../ui-server/ui-services/AbstractUIService.ts | 2 +- ui/web/src/composables/UIClient.ts | 4 ++-- 13 files changed, 27 insertions(+), 26 deletions(-) diff --git a/src/charging-station/Bootstrap.ts b/src/charging-station/Bootstrap.ts index 0cd15055..33b482b1 100644 --- a/src/charging-station/Bootstrap.ts +++ b/src/charging-station/Bootstrap.ts @@ -259,7 +259,7 @@ export class Bootstrap extends EventEmitter { // logger.debug( // `${this.logPrefix()} ${moduleName}.messageHandler: Worker channel message received: ${JSON.stringify( // msg, - // null, + // undefined, // 2, // )}`, // ); @@ -297,7 +297,7 @@ export class Bootstrap extends EventEmitter { throw new BaseError( `Unknown charging station worker event: '${ msg.event - }' received with data: ${JSON.stringify(msg.data, null, 2)}`, + }' received with data: ${JSON.stringify(msg.data, undefined, 2)}`, ); } } catch (error) { diff --git a/src/charging-station/ChargingStation.ts b/src/charging-station/ChargingStation.ts index beefcf45..c6a5278e 100644 --- a/src/charging-station/ChargingStation.ts +++ b/src/charging-station/ChargingStation.ts @@ -161,7 +161,7 @@ export class ChargingStation { public idTagsCache: IdTagsCache; public automaticTransactionGenerator!: AutomaticTransactionGenerator | undefined; public ocppConfiguration!: ChargingStationOcppConfiguration | undefined; - public wsConnection!: WebSocket | null; + public wsConnection: WebSocket | null; public readonly connectors: Map; public readonly evses: Map; public readonly requests: Map; @@ -193,6 +193,7 @@ export class ChargingStation { this.started = false; this.starting = false; this.stopping = false; + this.wsConnection = null; this.wsConnectionRestarted = false; this.autoReconnectRetryCount = 0; this.index = index; @@ -1699,7 +1700,7 @@ export class ChargingStation { const beginId = PerformanceStatistics.beginMeasure(measureId); writeFileSync( this.configurationFile, - JSON.stringify(configurationData, null, 2), + JSON.stringify(configurationData, undefined, 2), 'utf8', ); PerformanceStatistics.endMeasure(measureId, beginId); diff --git a/src/charging-station/ChargingStationWorker.ts b/src/charging-station/ChargingStationWorker.ts index 003d9fea..6201bf07 100644 --- a/src/charging-station/ChargingStationWorker.ts +++ b/src/charging-station/ChargingStationWorker.ts @@ -52,7 +52,7 @@ class ChargingStationWorker extends AsyncResource { throw new BaseError( `Unknown worker event: '${message.event}' received with data: '${JSON.stringify( message.data, - null, + undefined, 2, )}'`, ); diff --git a/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts b/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts index 90b7d1fc..4b565eb9 100644 --- a/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts +++ b/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts @@ -349,7 +349,7 @@ export class OCPP16IncomingRequestService extends OCPPIncomingRequestService { ErrorType.SECURITY_ERROR, `${commandName} cannot be issued to handle request PDU ${JSON.stringify( commandPayload, - null, + undefined, 2, )} while the charging station is in pending state on the central server`, commandName, @@ -386,7 +386,7 @@ export class OCPP16IncomingRequestService extends OCPPIncomingRequestService { ErrorType.NOT_IMPLEMENTED, `${commandName} is not implemented to handle request PDU ${JSON.stringify( commandPayload, - null, + undefined, 2, )}`, commandName, @@ -398,7 +398,7 @@ export class OCPP16IncomingRequestService extends OCPPIncomingRequestService { ErrorType.SECURITY_ERROR, `${commandName} cannot be issued to handle request PDU ${JSON.stringify( commandPayload, - null, + undefined, 2, )} while the charging station is not registered on the central server.`, commandName, @@ -1456,7 +1456,7 @@ export class OCPP16IncomingRequestService extends OCPPIncomingRequestService { .requestHandler( chargingStation, OCPP16RequestCommand.HEARTBEAT, - null, + undefined, { triggerMessage: true, }, diff --git a/src/charging-station/ocpp/1.6/OCPP16ResponseService.ts b/src/charging-station/ocpp/1.6/OCPP16ResponseService.ts index 6dcc5d5d..b634562b 100644 --- a/src/charging-station/ocpp/1.6/OCPP16ResponseService.ts +++ b/src/charging-station/ocpp/1.6/OCPP16ResponseService.ts @@ -366,7 +366,7 @@ export class OCPP16ResponseService extends OCPPResponseService { ErrorType.NOT_IMPLEMENTED, `${commandName} is not implemented to handle response PDU ${JSON.stringify( payload, - null, + undefined, 2, )}`, commandName, @@ -378,7 +378,7 @@ export class OCPP16ResponseService extends OCPPResponseService { ErrorType.SECURITY_ERROR, `${commandName} cannot be issued to handle response PDU ${JSON.stringify( payload, - null, + undefined, 2, )} while the charging station is not registered on the central server.`, commandName, diff --git a/src/charging-station/ocpp/1.6/OCPP16ServiceUtils.ts b/src/charging-station/ocpp/1.6/OCPP16ServiceUtils.ts index 7ccd3dcd..17da98c0 100644 --- a/src/charging-station/ocpp/1.6/OCPP16ServiceUtils.ts +++ b/src/charging-station/ocpp/1.6/OCPP16ServiceUtils.ts @@ -1244,12 +1244,12 @@ export class OCPP16ServiceUtils extends OCPPServiceUtils { context?: MeterValueContext, phase?: OCPP16MeterValuePhase, ): OCPP16SampledValue { - const sampledValueValue = value ?? sampledValueTemplate?.value ?? null; - const sampledValueContext = context ?? sampledValueTemplate?.context ?? null; + const sampledValueValue = value ?? sampledValueTemplate?.value; + const sampledValueContext = context ?? sampledValueTemplate?.context; const sampledValueLocation = sampledValueTemplate?.location ?? OCPP16ServiceUtils.getMeasurandDefaultLocation(sampledValueTemplate.measurand!); - const sampledValuePhase = phase ?? sampledValueTemplate?.phase ?? null; + const sampledValuePhase = phase ?? sampledValueTemplate?.phase; return { ...(!isNullOrUndefined(sampledValueTemplate.unit) && { unit: sampledValueTemplate.unit, diff --git a/src/charging-station/ocpp/2.0/OCPP20IncomingRequestService.ts b/src/charging-station/ocpp/2.0/OCPP20IncomingRequestService.ts index bda78d54..b5790b56 100644 --- a/src/charging-station/ocpp/2.0/OCPP20IncomingRequestService.ts +++ b/src/charging-station/ocpp/2.0/OCPP20IncomingRequestService.ts @@ -65,7 +65,7 @@ export class OCPP20IncomingRequestService extends OCPPIncomingRequestService { ErrorType.SECURITY_ERROR, `${commandName} cannot be issued to handle request PDU ${JSON.stringify( commandPayload, - null, + undefined, 2, )} while the charging station is in pending state on the central server`, commandName, @@ -102,7 +102,7 @@ export class OCPP20IncomingRequestService extends OCPPIncomingRequestService { ErrorType.NOT_IMPLEMENTED, `${commandName} is not implemented to handle request PDU ${JSON.stringify( commandPayload, - null, + undefined, 2, )}`, commandName, @@ -114,7 +114,7 @@ export class OCPP20IncomingRequestService extends OCPPIncomingRequestService { ErrorType.SECURITY_ERROR, `${commandName} cannot be issued to handle request PDU ${JSON.stringify( commandPayload, - null, + undefined, 2, )} while the charging station is not registered on the central server.`, commandName, diff --git a/src/charging-station/ocpp/2.0/OCPP20ResponseService.ts b/src/charging-station/ocpp/2.0/OCPP20ResponseService.ts index 81dca3a4..cc4370e8 100644 --- a/src/charging-station/ocpp/2.0/OCPP20ResponseService.ts +++ b/src/charging-station/ocpp/2.0/OCPP20ResponseService.ts @@ -123,7 +123,7 @@ export class OCPP20ResponseService extends OCPPResponseService { ErrorType.NOT_IMPLEMENTED, `${commandName} is not implemented to handle response PDU ${JSON.stringify( payload, - null, + undefined, 2, )}`, commandName, @@ -135,7 +135,7 @@ export class OCPP20ResponseService extends OCPPResponseService { ErrorType.SECURITY_ERROR, `${commandName} cannot be issued to handle response PDU ${JSON.stringify( payload, - null, + undefined, 2, )} while the charging station is not registered on the central server.`, commandName, diff --git a/src/charging-station/ocpp/OCPPIncomingRequestService.ts b/src/charging-station/ocpp/OCPPIncomingRequestService.ts index b7ab8ef6..85fd88e7 100644 --- a/src/charging-station/ocpp/OCPPIncomingRequestService.ts +++ b/src/charging-station/ocpp/OCPPIncomingRequestService.ts @@ -103,7 +103,7 @@ export abstract class OCPPIncomingRequestService extends AsyncResource { OCPPServiceUtils.ajvErrorsToErrorType(validate.errors!), 'Incoming request PDU is invalid', commandName, - JSON.stringify(validate.errors, null, 2), + JSON.stringify(validate.errors, undefined, 2), ); } diff --git a/src/charging-station/ocpp/OCPPRequestService.ts b/src/charging-station/ocpp/OCPPRequestService.ts index b489bf08..18aa5ffd 100644 --- a/src/charging-station/ocpp/OCPPRequestService.ts +++ b/src/charging-station/ocpp/OCPPRequestService.ts @@ -225,7 +225,7 @@ export abstract class OCPPRequestService { OCPPServiceUtils.ajvErrorsToErrorType(validate.errors!), 'Request PDU is invalid', commandName, - JSON.stringify(validate.errors, null, 2), + JSON.stringify(validate.errors, undefined, 2), ); } @@ -266,7 +266,7 @@ export abstract class OCPPRequestService { OCPPServiceUtils.ajvErrorsToErrorType(validate.errors!), 'Response PDU is invalid', commandName, - JSON.stringify(validate.errors, null, 2), + JSON.stringify(validate.errors, undefined, 2), ); } diff --git a/src/charging-station/ocpp/OCPPResponseService.ts b/src/charging-station/ocpp/OCPPResponseService.ts index 7934500e..9daa991c 100644 --- a/src/charging-station/ocpp/OCPPResponseService.ts +++ b/src/charging-station/ocpp/OCPPResponseService.ts @@ -76,7 +76,7 @@ export abstract class OCPPResponseService { OCPPServiceUtils.ajvErrorsToErrorType(validate.errors!), 'Response PDU is invalid', commandName, - JSON.stringify(validate.errors, null, 2), + JSON.stringify(validate.errors, undefined, 2), ); } diff --git a/src/charging-station/ui-server/ui-services/AbstractUIService.ts b/src/charging-station/ui-server/ui-services/AbstractUIService.ts index 6fd59b86..20531c6f 100644 --- a/src/charging-station/ui-server/ui-services/AbstractUIService.ts +++ b/src/charging-station/ui-server/ui-services/AbstractUIService.ts @@ -84,7 +84,7 @@ export abstract class AbstractUIService { throw new BaseError( `${command} is not implemented to handle message payload ${JSON.stringify( requestPayload, - null, + undefined, 2, )}`, ); diff --git a/ui/web/src/composables/UIClient.ts b/ui/web/src/composables/UIClient.ts index a474c8db..bbb4a449 100644 --- a/ui/web/src/composables/UIClient.ts +++ b/ui/web/src/composables/UIClient.ts @@ -174,7 +174,7 @@ export class UIClient { const response = JSON.parse(messageEvent.data) as ProtocolResponse; if (Array.isArray(response) === false) { - throw new Error(`Response not an array: ${JSON.stringify(response, null, 2)}`); + throw new Error(`Response not an array: ${JSON.stringify(response, undefined, 2)}`); } const [uuid, responsePayload] = response; @@ -192,7 +192,7 @@ export class UIClient { } this.deleteResponseHandler(uuid); } else { - throw new Error(`Not a response to a request: ${JSON.stringify(response, null, 2)}`); + throw new Error(`Not a response to a request: ${JSON.stringify(response, undefined, 2)}`); } } } -- 2.34.1