Add types to OCPP configuration key handling code
authorJérôme Benoit <jerome.benoit@sap.com>
Mon, 5 Sep 2022 23:48:33 +0000 (01:48 +0200)
committerJérôme Benoit <jerome.benoit@sap.com>
Mon, 5 Sep 2022 23:48:33 +0000 (01:48 +0200)
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
src/charging-station/ChargingStationConfigurationUtils.ts
src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts

index 004b95fc5083c0440909daf317d39bd239a88c10..f79a7375ea72dc2ea0816d2a723cca26267b1860 100644 (file)
@@ -3,6 +3,10 @@ import type { StandardParametersKey } from '../types/ocpp/Configuration';
 import logger from '../utils/Logger';
 import type ChargingStation from './ChargingStation';
 
+type ConfigurationKeyOptions = { readonly?: boolean; visible?: boolean; reboot?: boolean };
+type DeleteConfigurationKeyParams = { save?: boolean; caseInsensitive?: boolean };
+type AddConfigurationKeyParams = { overwrite?: boolean; save?: boolean };
+
 export class ChargingStationConfigurationUtils {
   private constructor() {
     // This is intentional
@@ -25,14 +29,14 @@ export class ChargingStationConfigurationUtils {
     chargingStation: ChargingStation,
     key: string | StandardParametersKey,
     value: string,
-    options: { readonly?: boolean; visible?: boolean; reboot?: boolean } = {
+    options: ConfigurationKeyOptions = {
       readonly: false,
       visible: true,
       reboot: false,
     },
-    params: { overwrite?: boolean; save?: boolean } = { overwrite: false, save: false }
+    params: AddConfigurationKeyParams = { overwrite: false, save: false }
   ): void {
-    options = options ?? ({} as { readonly?: boolean; visible?: boolean; reboot?: boolean });
+    options = options ?? ({} as ConfigurationKeyOptions);
     options.readonly = options?.readonly ?? false;
     options.visible = options?.visible ?? true;
     options.reboot = options?.reboot ?? false;
@@ -87,7 +91,7 @@ export class ChargingStationConfigurationUtils {
   public static deleteConfigurationKey(
     chargingStation: ChargingStation,
     key: string | StandardParametersKey,
-    params: { save?: boolean; caseInsensitive?: boolean } = { save: true, caseInsensitive: false }
+    params: DeleteConfigurationKeyParams = { save: true, caseInsensitive: false }
   ): ConfigurationKey[] {
     const keyFound = ChargingStationConfigurationUtils.getConfigurationKey(
       chargingStation,
index 6c11ad57c4a8e11d8cb581e5feb0745bed231bdf..d09e69a1576b64412154e71df2778d157b2315d4 100644 (file)
@@ -435,9 +435,9 @@ export default class OCPP16IncomingRequestService extends OCPPIncomingRequestSer
   ): GetConfigurationResponse {
     const configurationKey: OCPPConfigurationKey[] = [];
     const unknownKey: string[] = [];
-    if (Utils.isEmptyArray(commandPayload.key)) {
+    if (Utils.isEmptyArray(commandPayload.key) === true) {
       for (const configuration of chargingStation.ocppConfiguration.configurationKey) {
-        if (Utils.isUndefined(configuration.visible)) {
+        if (Utils.isUndefined(configuration.visible) === true) {
           configuration.visible = true;
         }
         if (!configuration.visible) {
@@ -456,10 +456,10 @@ export default class OCPP16IncomingRequestService extends OCPPIncomingRequestSer
           key
         );
         if (keyFound) {
-          if (Utils.isUndefined(keyFound.visible)) {
+          if (Utils.isUndefined(keyFound.visible) === true) {
             keyFound.visible = true;
           }
-          if (!keyFound.visible) {
+          if (keyFound.visible === false) {
             continue;
           }
           configurationKey.push({