From e58068fde9b27e3de6733be24fc7b3dfac37331b Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Mon, 20 Dec 2021 17:05:18 +0100 Subject: [PATCH] Refine autoRegister CS template tunable handling MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- package-lock.json | 14 +++++++------- package.json | 2 +- src/charging-station/ChargingStation.ts | 12 ++++++++---- .../ocpp/1.6/OCPP16IncomingRequestService.ts | 2 +- .../ocpp/1.6/OCPP16RequestService.ts | 2 +- .../ocpp/1.6/OCPP16ResponseService.ts | 2 +- .../ocpp/1.6/OCPP16ServiceUtils.ts | 2 +- src/charging-station/ocpp/OCPPRequestService.ts | 2 +- .../ocpp => exception}/OCPPError.ts | 6 +++--- src/types/ocpp/Requests.ts | 2 +- test/robohydra/messages.txt | 3 +++ 11 files changed, 28 insertions(+), 21 deletions(-) rename src/{charging-station/ocpp => exception}/OCPPError.ts (74%) diff --git a/package-lock.json b/package-lock.json index 1ae72307..3e93f33d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -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", @@ -6010,9 +6010,9 @@ } }, "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", @@ -24095,9 +24095,9 @@ } }, "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", diff --git a/package.json b/package.json index 60f994f7..c2369786 100644 --- a/package.json +++ b/package.json @@ -106,7 +106,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", diff --git a/src/charging-station/ChargingStation.ts b/src/charging-station/ChargingStation.ts index 8b5b1ac2..00cfce9f 100644 --- a/src/charging-station/ChargingStation.ts +++ b/src/charging-station/ChargingStation.ts @@ -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 diff --git a/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts b/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts index c4a0989e..fa03c535 100644 --- a/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts +++ b/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts @@ -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'; diff --git a/src/charging-station/ocpp/1.6/OCPP16RequestService.ts b/src/charging-station/ocpp/1.6/OCPP16RequestService.ts index 93bb2bcc..f4f1782e 100644 --- a/src/charging-station/ocpp/1.6/OCPP16RequestService.ts +++ b/src/charging-station/ocpp/1.6/OCPP16RequestService.ts @@ -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'; diff --git a/src/charging-station/ocpp/1.6/OCPP16ResponseService.ts b/src/charging-station/ocpp/1.6/OCPP16ResponseService.ts index ca5c0157..5b6a3fec 100644 --- a/src/charging-station/ocpp/1.6/OCPP16ResponseService.ts +++ b/src/charging-station/ocpp/1.6/OCPP16ResponseService.ts @@ -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'; diff --git a/src/charging-station/ocpp/1.6/OCPP16ServiceUtils.ts b/src/charging-station/ocpp/1.6/OCPP16ServiceUtils.ts index f0fe3cc2..289b00ea 100644 --- a/src/charging-station/ocpp/1.6/OCPP16ServiceUtils.ts +++ b/src/charging-station/ocpp/1.6/OCPP16ServiceUtils.ts @@ -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'; diff --git a/src/charging-station/ocpp/OCPPRequestService.ts b/src/charging-station/ocpp/OCPPRequestService.ts index d36a5b22..b29c0451 100644 --- a/src/charging-station/ocpp/OCPPRequestService.ts +++ b/src/charging-station/ocpp/OCPPRequestService.ts @@ -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'; diff --git a/src/charging-station/ocpp/OCPPError.ts b/src/exception/OCPPError.ts similarity index 74% rename from src/charging-station/ocpp/OCPPError.ts rename to src/exception/OCPPError.ts index cdb75027..cfcc4f40 100644 --- a/src/charging-station/ocpp/OCPPError.ts +++ b/src/exception/OCPPError.ts @@ -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; diff --git a/src/types/ocpp/Requests.ts b/src/types/ocpp/Requests.ts index bf3bd76d..2808e2f5 100644 --- a/src/types/ocpp/Requests.ts +++ b/src/types/ocpp/Requests.ts @@ -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) => Record | Promise>; diff --git a/test/robohydra/messages.txt b/test/robohydra/messages.txt index b71191b0..47d15bb3 100644 --- a/test/robohydra/messages.txt +++ b/test/robohydra/messages.txt @@ -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 -- 2.34.1