Permit to run code in async scope in the OCPP stack
[e-mobility-charging-stations-simulator.git] / src / charging-station / ocpp / 1.6 / OCPP16IncomingRequestService.ts
index ceaea14e607aebb0d0c9be9c8354a0ccb429188f..52751b4bac994ddfc9e2bc0f68746093b7c2bb55 100644 (file)
@@ -378,10 +378,14 @@ export default class OCPP16IncomingRequestService extends OCPPIncomingRequestSer
     chargingStation: ChargingStation,
     commandPayload: ResetRequest
   ): DefaultResponse {
-    // eslint-disable-next-line @typescript-eslint/no-misused-promises
-    setImmediate(async (): Promise<void> => {
-      await chargingStation.reset((commandPayload.type + 'Reset') as OCPP16StopTransactionReason);
-    });
+    this.asyncResource.runInAsyncScope(
+      chargingStation.reset.bind(chargingStation) as (
+        this: ChargingStation,
+        ...args: any[]
+      ) => void,
+      chargingStation,
+      (commandPayload.type + 'Reset') as OCPP16StopTransactionReason
+    );
     logger.info(
       `${chargingStation.logPrefix()} ${
         commandPayload.type
@@ -392,7 +396,10 @@ export default class OCPP16IncomingRequestService extends OCPPIncomingRequestSer
     return Constants.OCPP_RESPONSE_ACCEPTED;
   }
 
-  private handleRequestClearCache(): DefaultResponse {
+  private handleRequestClearCache(chargingStation: ChargingStation): DefaultResponse {
+    chargingStation.authorizedTagsCache.deleteAuthorizedTags(
+      ChargingStationUtils.getAuthorizationFile(chargingStation.stationInfo)
+    );
     return Constants.OCPP_RESPONSE_ACCEPTED;
   }
 
@@ -588,11 +595,11 @@ export default class OCPP16IncomingRequestService extends OCPPIncomingRequestSer
     commandPayload: ClearChargingProfileRequest
   ): ClearChargingProfileResponse {
     if (
-      !OCPP16ServiceUtils.checkFeatureProfile(
+      OCPP16ServiceUtils.checkFeatureProfile(
         chargingStation,
         OCPP16SupportedFeatureProfiles.SmartCharging,
         OCPP16IncomingRequestCommand.CLEAR_CHARGING_PROFILE
-      )
+      ) === false
     ) {
       return Constants.OCPP_CLEAR_CHARGING_PROFILE_RESPONSE_UNKNOWN;
     }