Factor out some common code between OCPP 1.6 and 2.0.1 stack
authorJérôme Benoit <jerome.benoit@sap.com>
Mon, 9 Jan 2023 21:03:39 +0000 (22:03 +0100)
committerJérôme Benoit <jerome.benoit@sap.com>
Mon, 9 Jan 2023 21:03:39 +0000 (22:03 +0100)
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts
src/charging-station/ocpp/1.6/OCPP16RequestService.ts
src/charging-station/ocpp/2.0/OCPP20IncomingRequestService.ts
src/charging-station/ocpp/OCPPIncomingRequestService.ts
src/types/ocpp/Responses.ts

index 0df0954feede6f3d681f6dce3eaa151109d38835..9e0849e987080be00f57f931e62fcfc9f3b8a3d9 100644 (file)
@@ -438,13 +438,6 @@ export default class OCPP16IncomingRequestService extends OCPPIncomingRequestSer
     return OCPPConstants.OCPP_RESPONSE_ACCEPTED;
   }
 
-  private handleRequestClearCache(chargingStation: ChargingStation): DefaultResponse {
-    chargingStation.authorizedTagsCache.deleteAuthorizedTags(
-      ChargingStationUtils.getAuthorizationFile(chargingStation.stationInfo)
-    );
-    return OCPPConstants.OCPP_RESPONSE_ACCEPTED;
-  }
-
   private async handleRequestUnlockConnector(
     chargingStation: ChargingStation,
     commandPayload: UnlockConnectorRequest
index 3c72faf223eea8f8dca3adf78327cc7d432a7126..3a38f02aa1879f38f03cfedabb6e9929c71eae79 100644 (file)
@@ -235,6 +235,7 @@ export default class OCPP16RequestService extends OCPPRequestService {
           }),
         } as unknown as Request;
       case OCPP16RequestCommand.DIAGNOSTICS_STATUS_NOTIFICATION:
+      case OCPP16RequestCommand.FIRMWARE_STATUS_NOTIFICATION:
         return {
           status: commandParams?.status,
         } as unknown as Request;
@@ -294,10 +295,6 @@ export default class OCPP16RequestService extends OCPPRequestService {
         } as unknown as Request;
       case OCPP16RequestCommand.DATA_TRANSFER:
         return commandParams as unknown as Request;
-      case OCPP16RequestCommand.FIRMWARE_STATUS_NOTIFICATION:
-        return {
-          status: commandParams?.status,
-        } as unknown as Request;
       default:
         // OCPPError usage here is debatable: it's an error in the OCPP stack but not targeted to sendError().
         throw new OCPPError(
index c3a241d4874b170addeb60dc9d992c4eda5f5817..ed4f1fe1cf53a51e5ae2ed985dcf700c93967bc1 100644 (file)
@@ -12,14 +12,11 @@ import {
   OCPP20ClearCacheRequest,
   OCPP20IncomingRequestCommand,
 } from '../../../types/ocpp/2.0/Requests';
-import type { OCPP20ClearCacheResponse } from '../../../types/ocpp/2.0/Responses';
 import { ErrorType } from '../../../types/ocpp/ErrorType';
 import { OCPPVersion } from '../../../types/ocpp/OCPPVersion';
 import type { IncomingRequestHandler } from '../../../types/ocpp/Requests';
 import logger from '../../../utils/Logger';
 import type ChargingStation from '../../ChargingStation';
-import { ChargingStationUtils } from '../../ChargingStationUtils';
-import OCPPConstants from '../OCPPConstants';
 import OCPPIncomingRequestService from '../OCPPIncomingRequestService';
 import { OCPP20ServiceUtils } from './OCPP20ServiceUtils';
 
@@ -154,11 +151,4 @@ export default class OCPP20IncomingRequestService extends OCPPIncomingRequestSer
     );
     return false;
   }
-
-  private handleRequestClearCache(chargingStation: ChargingStation): OCPP20ClearCacheResponse {
-    chargingStation.authorizedTagsCache.deleteAuthorizedTags(
-      ChargingStationUtils.getAuthorizationFile(chargingStation.stationInfo)
-    );
-    return OCPPConstants.OCPP_RESPONSE_ACCEPTED;
-  }
 }
index 4b8c40f806b6c5482cb418ec71368c125df3c2d2..876e71d8483dd83f313a48f26af9e0ec00cbd102 100644 (file)
@@ -8,8 +8,11 @@ import type { HandleErrorParams } from '../../types/Error';
 import type { JsonObject, JsonType } from '../../types/JsonType';
 import type { OCPPVersion } from '../../types/ocpp/OCPPVersion';
 import type { IncomingRequestCommand } from '../../types/ocpp/Requests';
+import type { ClearCacheResponse } from '../../types/ocpp/Responses';
 import logger from '../../utils/Logger';
 import type ChargingStation from '../ChargingStation';
+import { ChargingStationUtils } from '../ChargingStationUtils';
+import OCPPConstants from './OCPPConstants';
 import { OCPPServiceUtils } from './OCPPServiceUtils';
 
 const moduleName = 'OCPPIncomingRequestService';
@@ -86,6 +89,13 @@ export default abstract class OCPPIncomingRequestService {
     );
   }
 
+  protected handleRequestClearCache(chargingStation: ChargingStation): ClearCacheResponse {
+    chargingStation.authorizedTagsCache.deleteAuthorizedTags(
+      ChargingStationUtils.getAuthorizationFile(chargingStation.stationInfo)
+    );
+    return OCPPConstants.OCPP_RESPONSE_ACCEPTED;
+  }
+
   public abstract incomingRequestHandler(
     chargingStation: ChargingStation,
     messageId: string,
index c2b1f53a55a71cf39029238a417d691fb1612070..90c5f1ea99272c09caefa093cd91f4bc036fe090 100644 (file)
@@ -16,7 +16,7 @@ import {
   OCPP16TriggerMessageStatus,
   OCPP16UnlockStatus,
 } from './1.6/Responses';
-import type { OCPP20BootNotificationResponse } from './2.0/Responses';
+import type { OCPP20BootNotificationResponse, OCPP20ClearCacheResponse } from './2.0/Responses';
 import type { ErrorType } from './ErrorType';
 import type { MessageType } from './MessageType';
 
@@ -36,6 +36,8 @@ export type BootNotificationResponse =
 
 export type HeartbeatResponse = OCPP16HeartbeatResponse;
 
+export type ClearCacheResponse = DefaultResponse | OCPP20ClearCacheResponse;
+
 export type StatusNotificationResponse = OCPP16StatusNotificationResponse;
 
 export type MeterValuesResponse = OCPP16MeterValuesResponse;