Improve supported OCPP commands filtering
[e-mobility-charging-stations-simulator.git] / src / charging-station / ChargingStationUtils.ts
index c216ed6bec8bae64bb3f2ae84bab9db91ba16d3b..ad145f0b0f8b2cd3be8eb07ae087044484a9a7f1 100644 (file)
@@ -536,24 +536,38 @@ export class ChargingStationUtils {
 
   public static isCommandSupported(
     command: RequestCommand | IncomingRequestCommand,
-    stationInfo: ChargingStationInfo
+    chargingStation: ChargingStation
   ): boolean {
+    const isIncomingRequestCommand = Object.values(IncomingRequestCommand).includes(
+      command as IncomingRequestCommand
+    );
+    const isRequestCommand = Object.values(RequestCommand).includes(command as RequestCommand);
     if (
-      Object.values(IncomingRequestCommand).includes(command as IncomingRequestCommand) &&
-      !stationInfo?.commandsSupport?.incomingCommands
+      isIncomingRequestCommand &&
+      !chargingStation.stationInfo?.commandsSupport?.incomingCommands
     ) {
       return true;
-    }
-    if (
-      Object.values(RequestCommand).includes(command as RequestCommand) &&
-      !stationInfo?.commandsSupport?.outgoingCommands
+    } else if (
+      isIncomingRequestCommand &&
+      chargingStation.stationInfo?.commandsSupport?.incomingCommands
+    ) {
+      return (
+        (chargingStation.stationInfo?.commandsSupport?.incomingCommands[command] as boolean) ??
+        false
+      );
+    } else if (
+      isRequestCommand &&
+      !chargingStation.stationInfo?.commandsSupport?.outgoingCommands
     ) {
       return true;
+    } else if (isRequestCommand && chargingStation.stationInfo?.commandsSupport?.outgoingCommands) {
+      return (
+        (chargingStation.stationInfo?.commandsSupport?.outgoingCommands[command] as boolean) ??
+        false
+      );
     }
-    return (
-      ((stationInfo?.commandsSupport?.incomingCommands[command] as boolean) ?? false) ||
-      ((stationInfo?.commandsSupport?.outgoingCommands[command] as boolean) ?? false)
-    );
+    logger.error(`${chargingStation.logPrefix()} Unknown OCPP command '${command}'`);
+    return false;
   }
 
   private static getRandomSerialNumberSuffix(params?: {