Cleanups.
authorJérôme Benoit <jerome.benoit@sap.com>
Sat, 2 Jan 2021 00:58:02 +0000 (01:58 +0100)
committerJérôme Benoit <jerome.benoit@sap.com>
Sat, 2 Jan 2021 00:58:02 +0000 (01:58 +0100)
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
src/charging-station/ChargingStation.ts
src/types/ocpp/1.6/RequestResponses.ts
src/types/ocpp/1.6/Requests.ts
src/utils/CircularArray.ts

index 63a011ddfd151abe82521f5b58b342c29496a442..6797515f076fc40385f53ca2c6baf1e7de516a38 100644 (file)
@@ -688,6 +688,10 @@ export default class ChargingStation {
 
   async onMessage(messageEvent: MessageEvent): Promise<void> {
     let [messageType, messageId, commandName, commandPayload, errorDetails]: IncomingRequest = [0, '', '' as IncomingRequestCommand, '', ''];
+    let responseCallback: (payload?, requestPayload?) => void;
+    let rejectCallback: (error: OCPPError) => void;
+    let requestPayload: Record<string, unknown>;
+    let errMsg: string;
     try {
       // Parse the message
       [messageType, messageId, commandName, commandPayload, errorDetails] = JSON.parse(messageEvent.toString()) as IncomingRequest;
@@ -697,16 +701,14 @@ export default class ChargingStation {
         // Incoming Message
         case MessageType.CALL_MESSAGE:
           if (this.getEnableStatistics()) {
-            this._statistics.addMessage(commandName , messageType);
+            this._statistics.addMessage(commandName, messageType);
           }
           // Process the call
-          await this.handleRequest(messageId, commandName , commandPayload);
+          await this.handleRequest(messageId, commandName, commandPayload);
           break;
         // Outcome Message
         case MessageType.CALL_RESULT_MESSAGE:
           // Respond
-          // eslint-disable-next-line no-case-declarations
-          let responseCallback; let requestPayload;
           if (Utils.isIterable(this._requests[messageId])) {
             [responseCallback, , requestPayload] = this._requests[messageId];
           } else {
@@ -725,8 +727,6 @@ export default class ChargingStation {
             // Error
             throw new Error(`Error request for unknown message id ${messageId}`);
           }
-          // eslint-disable-next-line no-case-declarations
-          let rejectCallback;
           if (Utils.isIterable(this._requests[messageId])) {
             [, rejectCallback] = this._requests[messageId];
           } else {
@@ -737,8 +737,7 @@ export default class ChargingStation {
           break;
         // Error
         default:
-          // eslint-disable-next-line no-case-declarations
-          const errMsg = `${this._logPrefix()} Wrong message type ${messageType}`;
+          errMsg = `${this._logPrefix()} Wrong message type ${messageType}`;
           logger.error(errMsg);
           throw new Error(errMsg);
       }
index baf66c159a390d8ba6c095d643d82d63e618e42f..b737ed9797e0217315b62038874ec49f50dcefdf 100644 (file)
@@ -47,7 +47,7 @@ export interface BootNotificationResponse {
 }
 
 // eslint-disable-next-line @typescript-eslint/no-empty-interface
-export interface StatusNotificationResponse {}
+export interface StatusNotificationResponse { }
 
 export interface GetConfigurationResponse {
   configurationKey: ConfigurationKey[];
index d318dafb28ad43f824c4fa07001f2a6f3cd78089..71f8384f475d1e61b57880c3d061e5b5d62df135 100644 (file)
@@ -34,7 +34,7 @@ export enum IncomingRequestCommand {
 }
 
 // eslint-disable-next-line @typescript-eslint/no-empty-interface
-export interface HeartbeatRequest {}
+export interface HeartbeatRequest { }
 
 export interface BootNotificationRequest {
   chargeBoxSerialNumber?: string;
index e7edb3dd13e1a895883f0a24600dc774df540451..ba3eba19231ab7b7dff4eef88e27461ecc29c7f5 100644 (file)
@@ -22,7 +22,7 @@ export default class CircularArray<T> extends Array<T> {
     return super.unshift(...items);
   }
 
-  concat(...items: (T|ConcatArray<T>)[]): T[] {
+  concat(...items: (T | ConcatArray<T>)[]): T[] {
     if (this.length + items.length > this.size) {
       super.splice(0, (this.length + items.length) - this.size);
     }