Refine autoRegister CS template tunable handling
authorJérôme Benoit <jerome.benoit@sap.com>
Mon, 20 Dec 2021 16:05:18 +0000 (17:05 +0100)
committerJérôme Benoit <jerome.benoit@sap.com>
Mon, 20 Dec 2021 16:05:18 +0000 (17:05 +0100)
Signed-off-by: Jérôme Benoit <jerome.benoit@piment-noir.org>
package-lock.json
package.json
src/charging-station/ChargingStation.ts
src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts
src/charging-station/ocpp/1.6/OCPP16RequestService.ts
src/charging-station/ocpp/1.6/OCPP16ResponseService.ts
src/charging-station/ocpp/1.6/OCPP16ServiceUtils.ts
src/charging-station/ocpp/OCPPRequestService.ts
src/exception/OCPPError.ts [moved from src/charging-station/ocpp/OCPPError.ts with 74% similarity]
src/types/ocpp/Requests.ts
test/robohydra/messages.txt

index 1ae7230732769980eefa515c3c83424e8a0a34b5..3e93f33dfa77d2bd9ebf2e627a1769198c3cce3c 100644 (file)
@@ -44,7 +44,7 @@
         "cross-env": "^7.0.3",
         "eslint": "^8.5.0",
         "eslint-plugin-import": "^2.25.3",
-        "eslint-plugin-jsdoc": "^37.3.0",
+        "eslint-plugin-jsdoc": "^37.4.0",
         "eslint-plugin-node": "^11.1.0",
         "expect": "^27.4.2",
         "mocha": "^9.1.3",
       }
     },
     "node_modules/eslint-plugin-jsdoc": {
-      "version": "37.3.0",
-      "resolved": "https://registry.npmjs.org/eslint-plugin-jsdoc/-/eslint-plugin-jsdoc-37.3.0.tgz",
-      "integrity": "sha512-76fXAjqrfcqLpa3JjnDIXYHM8zlrNJYEXv6xvTyMcgbQ/gl0OmoEmPAGV9HxbhbJ9hhcW5fTVemRIwhGUwqJcw==",
+      "version": "37.4.0",
+      "resolved": "https://registry.npmjs.org/eslint-plugin-jsdoc/-/eslint-plugin-jsdoc-37.4.0.tgz",
+      "integrity": "sha512-XWKMMHFq7eUdC8XMzuQSskevJvlHTDSAJm/2qtEZ7+qhZTZ0YjeqWaUn7KGdrmxLNqtWwtJ67LdIPgrYUZ5EoA==",
       "dev": true,
       "dependencies": {
         "@es-joy/jsdoccomment": "0.13.0",
       }
     },
     "eslint-plugin-jsdoc": {
-      "version": "37.3.0",
-      "resolved": "https://registry.npmjs.org/eslint-plugin-jsdoc/-/eslint-plugin-jsdoc-37.3.0.tgz",
-      "integrity": "sha512-76fXAjqrfcqLpa3JjnDIXYHM8zlrNJYEXv6xvTyMcgbQ/gl0OmoEmPAGV9HxbhbJ9hhcW5fTVemRIwhGUwqJcw==",
+      "version": "37.4.0",
+      "resolved": "https://registry.npmjs.org/eslint-plugin-jsdoc/-/eslint-plugin-jsdoc-37.4.0.tgz",
+      "integrity": "sha512-XWKMMHFq7eUdC8XMzuQSskevJvlHTDSAJm/2qtEZ7+qhZTZ0YjeqWaUn7KGdrmxLNqtWwtJ67LdIPgrYUZ5EoA==",
       "dev": true,
       "requires": {
         "@es-joy/jsdoccomment": "0.13.0",
index 60f994f78a27d7f223ed6df4c6566a06b8567cc9..c23697869f6a4d7484a5095e4cc4b634447229e9 100644 (file)
     "cross-env": "^7.0.3",
     "eslint": "^8.5.0",
     "eslint-plugin-import": "^2.25.3",
-    "eslint-plugin-jsdoc": "^37.3.0",
+    "eslint-plugin-jsdoc": "^37.4.0",
     "eslint-plugin-node": "^11.1.0",
     "expect": "^27.4.2",
     "mocha": "^9.1.3",
index 8b5b1ac2a2120616250873f203d5d2e1e1e458b2..00cfce9f96f00014a251284a02494abe9be7d5bc 100644 (file)
@@ -24,7 +24,7 @@ import { MessageType } from '../types/ocpp/MessageType';
 import OCPP16IncomingRequestService from './ocpp/1.6/OCPP16IncomingRequestService';
 import OCPP16RequestService from './ocpp/1.6/OCPP16RequestService';
 import OCPP16ResponseService from './ocpp/1.6/OCPP16ResponseService';
-import OCPPError from './ocpp/OCPPError';
+import OCPPError from '../exception/OCPPError';
 import OCPPIncomingRequestService from './ocpp/OCPPIncomingRequestService';
 import OCPPRequestService from './ocpp/OCPPRequestService';
 import { OCPPVersion } from '../types/ocpp/OCPPVersion';
@@ -117,11 +117,11 @@ export default class ChargingStation {
   }
 
   public isWebSocketConnectionOpened(): boolean {
-    return this.wsConnection?.readyState === OPEN;
+    return this?.wsConnection?.readyState === OPEN;
   }
 
   public isRegistered(): boolean {
-    return this.bootNotificationResponse?.status === RegistrationStatus.ACCEPTED;
+    return this?.bootNotificationResponse?.status === RegistrationStatus.ACCEPTED;
   }
 
   public isChargingStationAvailable(): boolean {
@@ -634,6 +634,10 @@ export default class ChargingStation {
         }
       } while (!this.isRegistered() && (registrationRetryCount <= this.getRegistrationMaxRetries() || this.getRegistrationMaxRetries() === -1));
     }
+    if (this.isRegistered() && this.stationInfo.autoRegister) {
+      await this.ocppRequestService.sendBootNotification(this.bootNotificationRequest.chargePointModel,
+        this.bootNotificationRequest.chargePointVendor, this.bootNotificationRequest.chargeBoxSerialNumber, this.bootNotificationRequest.firmwareVersion);
+    }
     if (this.isRegistered()) {
       await this.startMessageSequence();
       this.stopped && (this.stopped = false);
@@ -829,7 +833,7 @@ export default class ChargingStation {
   }
 
   private getMaxNumberOfConnectors(): number {
-    let maxConnectors = 0;
+    let maxConnectors: number;
     if (!Utils.isEmptyArray(this.stationInfo.numberOfConnectors)) {
       const numberOfConnectors = this.stationInfo.numberOfConnectors as number[];
       // Distribute evenly the number of connectors
index c4a0989e24d9fc0e078097f48f6ec47bc91c631c..fa03c535e64dcb87ce08e5ea1c8ee308d2060b7b 100644 (file)
@@ -15,7 +15,7 @@ import { OCPP16ChargePointStatus } from '../../../types/ocpp/1.6/ChargePointStat
 import { OCPP16DiagnosticsStatus } from '../../../types/ocpp/1.6/DiagnosticsStatus';
 import { OCPP16StandardParametersKey } from '../../../types/ocpp/1.6/Configuration';
 import { OCPPConfigurationKey } from '../../../types/ocpp/Configuration';
-import OCPPError from '../OCPPError';
+import OCPPError from '../../../exception/OCPPError';
 import OCPPIncomingRequestService from '../OCPPIncomingRequestService';
 import { URL } from 'url';
 import Utils from '../../../utils/Utils';
index 93bb2bcc4f401166a6b98a29ee17fac35c668d91..f4f1782ee97a6716e81206a1917c926221dd6e30 100644 (file)
@@ -16,7 +16,7 @@ import { OCPP16ChargePointErrorCode } from '../../../types/ocpp/1.6/ChargePointE
 import { OCPP16ChargePointStatus } from '../../../types/ocpp/1.6/ChargePointStatus';
 import { OCPP16DiagnosticsStatus } from '../../../types/ocpp/1.6/DiagnosticsStatus';
 import { OCPP16ServiceUtils } from './OCPP16ServiceUtils';
-import OCPPError from '../OCPPError';
+import OCPPError from '../../../exception/OCPPError';
 import OCPPRequestService from '../OCPPRequestService';
 import Utils from '../../../utils/Utils';
 import logger from '../../../utils/Logger';
index ca5c01570b96be7a0574a41dddc560d8e37ce10a..5b6a3feca3babbc40699c68b64e83a18d092c422 100644 (file)
@@ -10,7 +10,7 @@ import { ErrorType } from '../../../types/ocpp/ErrorType';
 import { OCPP16ChargePointStatus } from '../../../types/ocpp/1.6/ChargePointStatus';
 import { OCPP16ServiceUtils } from './OCPP16ServiceUtils';
 import { OCPP16StandardParametersKey } from '../../../types/ocpp/1.6/Configuration';
-import OCPPError from '../OCPPError';
+import OCPPError from '../../../exception/OCPPError';
 import OCPPResponseService from '../OCPPResponseService';
 import { ResponseHandler } from '../../../types/ocpp/Responses';
 import Utils from '../../../utils/Utils';
index f0fe3cc298a1977521b6d3d97d213746d453d8bf..289b00ea22c0b70e928c2f72c069f77196cbb107 100644 (file)
@@ -4,7 +4,7 @@ import { MeterValueContext, MeterValueLocation, MeterValueUnit, OCPP16MeterValue
 
 import ChargingStation from '../../ChargingStation';
 import { ErrorType } from '../../../types/ocpp/ErrorType';
-import OCPPError from '../OCPPError';
+import OCPPError from '../../../exception/OCPPError';
 import { RequestCommand } from '../../../types/ocpp/Requests';
 import { SampledValueTemplate } from '../../../types/Connectors';
 import Utils from '../../../utils/Utils';
index d36a5b22c5f9c37de19a4e87b6e606002ad1a832..b29c0451a968d916dae04f87abe2bf17427cbcff 100644 (file)
@@ -9,7 +9,7 @@ import Constants from '../../utils/Constants';
 import { ErrorType } from '../../types/ocpp/ErrorType';
 import { MessageType } from '../../types/ocpp/MessageType';
 import { MeterValue } from '../../types/ocpp/MeterValues';
-import OCPPError from './OCPPError';
+import OCPPError from '../../exception/OCPPError';
 import OCPPResponseService from './OCPPResponseService';
 import PerformanceStatistics from '../../performance/PerformanceStatistics';
 import Utils from '../../utils/Utils';
similarity index 74%
rename from src/charging-station/ocpp/OCPPError.ts
rename to src/exception/OCPPError.ts
index cdb75027986bf1413b0571bc5d908f4bed0217b5..cfcc4f40c8dacc0c6eefcd07e71706877cbb3c01 100644 (file)
@@ -1,9 +1,9 @@
 // Partial Copyright Jerome Benoit. 2021. All Rights Reserved.
 
-import { IncomingRequestCommand, RequestCommand } from '../../types/ocpp/Requests';
+import { IncomingRequestCommand, RequestCommand } from '../types/ocpp/Requests';
 
-import BaseError from '../../exception/BaseError';
-import { ErrorType } from '../../types/ocpp/ErrorType';
+import BaseError from './BaseError';
+import { ErrorType } from '../types/ocpp/ErrorType';
 
 export default class OCPPError extends BaseError {
   code: ErrorType | IncomingRequestCommand;
index bf3bd76dcaabf2d7b99b2c7cc556caa5825373e7..2808e2f56a31dc3cb0d7b60176a81d9fd6dc7a3b 100644 (file)
@@ -2,7 +2,7 @@ import { OCPP16AvailabilityType, OCPP16BootNotificationRequest, OCPP16IncomingRe
 
 import { MessageType } from './MessageType';
 import { OCPP16DiagnosticsStatus } from './1.6/DiagnosticsStatus';
-import OCPPError from '../../charging-station/ocpp/OCPPError';
+import OCPPError from '../../exception/OCPPError';
 
 export type IncomingRequestHandler = (commandPayload: Record<string, unknown>) => Record<string, unknown> | Promise<Record<string, unknown>>;
 
index b71191b043cb31e78f408496036675bccca15ce0..47d15bb36b3446afde85b6359216426c917219cd 100644 (file)
@@ -1,2 +1,5 @@
 GetDiagnostics:
   curl -d '[2,"123456789","GetDiagnostics",{"location":"ftp://localhost"}]' -H "Content-Type: application/json" -X POST http://localhost:3000/message
+TriggerMessage:
+  curl -d '[2,"123456789","TriggerMessage",{"requestedMessage":"BootNotification"}]' -H "Content-Type: application/json" -X POST http://localhost:3000/message
+  curl -d '[2,"123456789","TriggerMessage",{"requestedMessage":"HeartBeat"}]' -H "Content-Type: application/json" -X POST http://localhost:3000/message