From 73c4266dacc6883a6089ed86725e4c19842cdad8 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Mon, 7 Feb 2022 11:16:59 +0100 Subject: [PATCH] Fix charging station initial registration at boot notification MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- src/charging-station/ChargingStation.ts | 6 +++++- src/charging-station/ocpp/OCPPRequestService.ts | 3 ++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/charging-station/ChargingStation.ts b/src/charging-station/ChargingStation.ts index 99e8f5ee..48833337 100644 --- a/src/charging-station/ChargingStation.ts +++ b/src/charging-station/ChargingStation.ts @@ -123,6 +123,10 @@ export default class ChargingStation { return this?.wsConnection?.readyState === OPEN; } + public isInUnknownState(): boolean { + return Utils.isNullOrUndefined(this?.bootNotificationResponse?.status); + } + public isInPendingState(): boolean { return this?.bootNotificationResponse?.status === RegistrationStatus.PENDING; } @@ -136,7 +140,7 @@ export default class ChargingStation { } public isRegistered(): boolean { - return this.isInAcceptedState() || this.isInPendingState(); + return !this.isInUnknownState() && (this.isInAcceptedState() || this.isInPendingState()); } public isChargingStationAvailable(): boolean { diff --git a/src/charging-station/ocpp/OCPPRequestService.ts b/src/charging-station/ocpp/OCPPRequestService.ts index 14cab283..af116c4e 100644 --- a/src/charging-station/ocpp/OCPPRequestService.ts +++ b/src/charging-station/ocpp/OCPPRequestService.ts @@ -32,7 +32,8 @@ export default abstract class OCPPRequestService { }): Promise { if (this.chargingStation.isInRejectedState() || (this.chargingStation.isInPendingState() && !params.triggerMessage)) { throw new OCPPError(ErrorType.SECURITY_ERROR, 'Cannot send command payload if the charging station is not in accepted state', commandName); - } else if (this.chargingStation.isInAcceptedState() || (this.chargingStation.isInPendingState() && params.triggerMessage)) { + } else if ((this.chargingStation.isInUnknownState() && commandName === RequestCommand.BOOT_NOTIFICATION) + || this.chargingStation.isInAcceptedState() || (this.chargingStation.isInPendingState() && params.triggerMessage)) { // eslint-disable-next-line @typescript-eslint/no-this-alias const self = this; // Send a message through wsConnection -- 2.34.1