refactor: null -> undefined where appropriate
authorJérôme Benoit <jerome.benoit@sap.com>
Sat, 30 Sep 2023 10:17:29 +0000 (12:17 +0200)
committerJérôme Benoit <jerome.benoit@sap.com>
Sat, 30 Sep 2023 10:17:29 +0000 (12:17 +0200)
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
13 files changed:
src/charging-station/Bootstrap.ts
src/charging-station/ChargingStation.ts
src/charging-station/ChargingStationWorker.ts
src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts
src/charging-station/ocpp/1.6/OCPP16ResponseService.ts
src/charging-station/ocpp/1.6/OCPP16ServiceUtils.ts
src/charging-station/ocpp/2.0/OCPP20IncomingRequestService.ts
src/charging-station/ocpp/2.0/OCPP20ResponseService.ts
src/charging-station/ocpp/OCPPIncomingRequestService.ts
src/charging-station/ocpp/OCPPRequestService.ts
src/charging-station/ocpp/OCPPResponseService.ts
src/charging-station/ui-server/ui-services/AbstractUIService.ts
ui/web/src/composables/UIClient.ts

index 0cd15055871405fdf7441d89a362f260cd68269e..33b482b1682a4938137e442014237c2bd3ac6688 100644 (file)
@@ -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) {
index beefcf45025e334011d2f138267ec4eb85d2a05d..c6a5278edccc1b5f9e324fff5584f32c3e042fde 100644 (file)
@@ -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<number, ConnectorStatus>;
   public readonly evses: Map<number, EvseStatus>;
   public readonly requests: Map<string, CachedRequest>;
@@ -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);
index 003d9fea96fd718f42fa356683ab0b10f231c7fb..6201bf07e2b52fe7e6d1931412da74e89043717c 100644 (file)
@@ -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,
             )}'`,
           );
index 90b7d1fcaac7a25370aef76303517353b2fff198..4b565eb937d27728d7f98b02ab5f88ae3138d906 100644 (file)
@@ -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<OCPP16HeartbeatRequest, OCPP16HeartbeatResponse>(
                 chargingStation,
                 OCPP16RequestCommand.HEARTBEAT,
-                null,
+                undefined,
                 {
                   triggerMessage: true,
                 },
index 6dcc5d5d2cf5f916f68838321ecb940075fdd6d4..b634562b7da188abecf0d4daa354bd6524a743dc 100644 (file)
@@ -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,
index 7ccd3dcd00b74967b5e6f6ee8d776782df1a405a..17da98c08a6333c14a5fb83eba3725ad5321775a 100644 (file)
@@ -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,
index bda78d54f3147f5eb621ae5108836c34eea8ee6d..b5790b5697506c4ac3911894e052751d03659ad4 100644 (file)
@@ -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,
index 81dca3a4a29a46de3c54d85ad3b3b2324ccccaf6..cc4370e8ac5965ecdfa960aa26b1908819fdf3db 100644 (file)
@@ -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,
index b7ab8ef66382b1ac0e799294eccca7f676480855..85fd88e70ebaa624ef454a80493e52cc1dd8f748 100644 (file)
@@ -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),
     );
   }
 
index b489bf0841797d139b3b4f747e96951b17ef08de..18aa5ffdb3cdbeee1b033521128cfc7f161d4aab 100644 (file)
@@ -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),
     );
   }
 
index 7934500ed3ebd7612cfb05ad58b0c68699396dc1..9daa991c952c30ff184748099dfbe158544ed8c1 100644 (file)
@@ -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),
     );
   }
 
index 6fd59b862676ae6ebef88725b9c3b2b008fba04f..20531c6f37ce4002d48ac5fe255628086ab5c0e2 100644 (file)
@@ -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,
           )}`,
         );
index a474c8db5e66619f6e6d753a9241acfdfa9ed781..bbb4a4499b233a6aead4703eaf1b3de93004e32e 100644 (file)
@@ -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)}`);
     }
   }
 }