fix: ensure message sequence is fired at boot notification response
authorJérôme Benoit <jerome.benoit@piment-noir.org>
Wed, 29 May 2024 18:02:34 +0000 (20:02 +0200)
committerJérôme Benoit <jerome.benoit@piment-noir.org>
Wed, 29 May 2024 18:02:34 +0000 (20:02 +0200)
processing

closes #1039

Signed-off-by: Jérôme Benoit <jerome.benoit@piment-noir.org>
src/charging-station/ChargingStation.ts
src/charging-station/ocpp/1.6/OCPP16ResponseService.ts
src/charging-station/ocpp/2.0/OCPP20ResponseService.ts

index 7df0a35ff7486bb7282455b4c3d63f629bbf7d99..ba1979542cf0767ae030cd5030ed779478cf9b3c 100644 (file)
@@ -1861,15 +1861,7 @@ export class ChargingStation extends EventEmitter {
             this.stationInfo?.registrationMaxRetries === -1)
         )
       }
-      if (this.isRegistered()) {
-        this.emit(ChargingStationEvents.registered)
-        if (this.inAcceptedState()) {
-          this.emit(ChargingStationEvents.accepted)
-        }
-      } else {
-        if (this.inRejectedState()) {
-          this.emit(ChargingStationEvents.rejected)
-        }
+      if (!this.isRegistered()) {
         logger.error(
           `${this.logPrefix()} Registration failure: maximum retries reached (${registrationRetryCount}) or retry disabled (${
             this.stationInfo?.registrationMaxRetries
index 64e33061d60c222c407003404708e9273baca9ea..ff04f4dc7ef7516675c00cb168a45fb1e44d1b74 100644 (file)
@@ -13,6 +13,7 @@ import {
 import { OCPPError } from '../../../exception/index.js'
 import {
   type ChangeConfigurationResponse,
+  ChargingStationEvents,
   ErrorType,
   type GenericResponse,
   type GetConfigurationResponse,
@@ -527,6 +528,14 @@ export class OCPP16ResponseService extends OCPPResponseService {
       OCPP16ServiceUtils.startHeartbeatInterval(chargingStation, payload.interval)
     }
     if (Object.values(RegistrationStatusEnumType).includes(payload.status)) {
+      if (chargingStation.isRegistered()) {
+        chargingStation.emit(ChargingStationEvents.registered)
+        if (chargingStation.inAcceptedState()) {
+          chargingStation.emit(ChargingStationEvents.accepted)
+        }
+      } else if (chargingStation.inRejectedState()) {
+        chargingStation.emit(ChargingStationEvents.rejected)
+      }
       const logMsg = `${chargingStation.logPrefix()} Charging station in '${
         payload.status
       }' state on the central server`
index 6ab91c074d01ec4f24b01a4c5fbdffb374ad1fa9..54ccdeec15921d0c511f04cb561ea00042f2f606 100644 (file)
@@ -5,6 +5,7 @@ import type { ValidateFunction } from 'ajv'
 import { addConfigurationKey, type ChargingStation } from '../../../charging-station/index.js'
 import { OCPPError } from '../../../exception/index.js'
 import {
+  ChargingStationEvents,
   ErrorType,
   type JsonType,
   type OCPP20BootNotificationResponse,
@@ -193,6 +194,14 @@ export class OCPP20ResponseService extends OCPPResponseService {
       OCPP20ServiceUtils.startHeartbeatInterval(chargingStation, payload.interval)
     }
     if (Object.values(RegistrationStatusEnumType).includes(payload.status)) {
+      if (chargingStation.isRegistered()) {
+        chargingStation.emit(ChargingStationEvents.registered)
+        if (chargingStation.inAcceptedState()) {
+          chargingStation.emit(ChargingStationEvents.accepted)
+        }
+      } else if (chargingStation.inRejectedState()) {
+        chargingStation.emit(ChargingStationEvents.rejected)
+      }
       const logMsg = `${chargingStation.logPrefix()} Charging station in '${
         payload.status
       }' state on the central server`