]> Piment Noir Git Repositories - e-mobility-charging-stations-simulator.git/commitdiff
refactor: constify some emums
authorJérôme Benoit <jerome.benoit@sap.com>
Tue, 11 Nov 2025 13:15:26 +0000 (14:15 +0100)
committerJérôme Benoit <jerome.benoit@sap.com>
Tue, 11 Nov 2025 13:15:26 +0000 (14:15 +0100)
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
12 files changed:
src/charging-station/ocpp/1.6/OCPP16ServiceUtils.ts
src/charging-station/ocpp/2.0/OCPP20IncomingRequestService.ts
src/charging-station/ocpp/2.0/OCPP20RequestService.ts
src/charging-station/ocpp/2.0/OCPP20ServiceUtils.ts
src/types/ConnectorStatus.ts
src/types/ocpp/1.6/Requests.ts
src/types/ocpp/1.6/Responses.ts
src/types/ocpp/2.0/Requests.ts
src/types/ocpp/Common.ts
src/types/ocpp/ErrorType.ts
src/types/ocpp/MessageType.ts
src/types/ocpp/OCPPVersion.ts

index 1f9f1a220fc2d9adba35d338197f2d325e6dde95..c56f0870444c0b038e0460e27d0483d9005f9c74 100644 (file)
@@ -723,7 +723,7 @@ export class OCPP16ServiceUtils extends OCPPServiceUtils {
     moduleName?: string,
     methodName?: string
   ): JSONSchemaType<T> {
-    return OCPP16ServiceUtils.parseJsonSchemaFile<T>(
+    return super.parseJsonSchemaFile<T>(
       relativePath,
       OCPPVersion.VERSION_16,
       moduleName,
index 4f7412b5e9d1d1b1723319a90b24b816269b12ce..316a47bdc8b9ef7d425a891883b8c2871a359e2e 100644 (file)
@@ -1376,7 +1376,6 @@ export class OCPP20IncomingRequestService extends OCPPIncomingRequestService {
     }
   }
 
-  // Helper methods for RequestStartTransaction
   private isIdTokenAuthorized (
     chargingStation: ChargingStation,
     idToken: OCPP20IdTokenType
index 6201fdf1024ac392d73aedde30efea02d64d1083..3ccddc56cb7828d2eda74a2df5471a8e555e3388 100644 (file)
@@ -161,9 +161,14 @@ export class OCPP20RequestService extends OCPPRequestService {
           timestamp: new Date(),
           ...commandParams,
         } as unknown as Request
+      case OCPP20RequestCommand.TRANSACTION_EVENT:
+        return {
+          timestamp: new Date(),
+          ...commandParams,
+        } as unknown as Request
       default: {
         // OCPPError usage here is debatable: it's an error in the OCPP stack but not targeted to sendError().
-        const errorMsg = `Unsupported OCPP command ${commandName} for payload building`
+        const errorMsg = `Unsupported OCPP command ${commandName as string} for payload building`
         logger.error(
           `${chargingStation.logPrefix()} ${moduleName}.buildRequestPayload: ${errorMsg}`
         )
index d2b8eb7becfd2788717ba11723c01eaae2db5d38..36cd9b2417aa13d9aafff77d7023db5096ef76da 100644 (file)
@@ -2,8 +2,7 @@
 
 import type { JSONSchemaType } from 'ajv'
 
-import type { ChargingStation } from '../../../charging-station/index.js'
-
+import { type ChargingStation, resetConnectorStatus } from '../../../charging-station/index.js'
 import {
   ConnectorStatusEnum,
   type GenericResponse,
@@ -277,7 +276,7 @@ export class OCPP20ServiceUtils extends OCPPServiceUtils {
     moduleName?: string,
     methodName?: string
   ): JSONSchemaType<T> {
-    return OCPP20ServiceUtils.parseJsonSchemaFile<T>(
+    return super.parseJsonSchemaFile<T>(
       relativePath,
       OCPPVersion.VERSION_201,
       moduleName,
@@ -318,12 +317,14 @@ export class OCPP20ServiceUtils extends OCPPServiceUtils {
         return OCPP20Constants.OCPP_RESPONSE_REJECTED
       }
 
+      connectorStatus.transactionSeqNo = (connectorStatus.transactionSeqNo ?? 0) + 1
+
       const transactionEventRequest: OCPP20TransactionEventRequest = {
         eventType: OCPP20TransactionEventEnumType.Ended,
         evse: {
           id: evseId,
         },
-        seqNo: 0, // This should be managed by the transaction sequence
+        seqNo: connectorStatus.transactionSeqNo,
         timestamp: new Date(),
         transactionInfo: {
           stoppedReason: OCPP20ReasonEnumType.Remote,
@@ -337,6 +338,7 @@ export class OCPP20ServiceUtils extends OCPPServiceUtils {
         OCPP20TransactionEventRequest
       >(chargingStation, OCPP20RequestCommand.TRANSACTION_EVENT, transactionEventRequest)
 
+      resetConnectorStatus(connectorStatus)
       await sendAndSetConnectorStatus(chargingStation, connectorId, ConnectorStatusEnum.Available)
 
       return OCPP20Constants.OCPP_RESPONSE_ACCEPTED
index b3ebfe150dfbdbf0a86c7259ca0863c66a09a939..aa637eff33c24270b8b0b4f034d6373f882c8ba0 100644 (file)
@@ -24,6 +24,7 @@ export interface ConnectorStatus {
   transactionId?: number | string
   transactionIdTag?: string
   transactionRemoteStarted?: boolean
+  transactionSeqNo?: number
   transactionSetInterval?: NodeJS.Timeout
   transactionStart?: Date
   transactionStarted?: boolean
index e4283183b7455e9b27cedbefd4cd494022fbe96d..b7a68402e01fdd32b95cad7653f6d484893b1a27 100644 (file)
@@ -10,12 +10,12 @@ import type {
 import type { OCPP16StandardParametersKey, OCPP16VendorParametersKey } from './Configuration.js'
 import type { OCPP16DiagnosticsStatus } from './DiagnosticsStatus.js'
 
-export enum OCPP16AvailabilityType {
+export const enum OCPP16AvailabilityType {
   Inoperative = 'Inoperative',
   Operative = 'Operative',
 }
 
-export enum OCPP16FirmwareStatus {
+export const enum OCPP16FirmwareStatus {
   Downloaded = 'Downloaded',
   DownloadFailed = 'DownloadFailed',
   Downloading = 'Downloading',
@@ -25,7 +25,7 @@ export enum OCPP16FirmwareStatus {
   Installing = 'Installing',
 }
 
-export enum OCPP16IncomingRequestCommand {
+export const enum OCPP16IncomingRequestCommand {
   CANCEL_RESERVATION = 'CancelReservation',
   CHANGE_AVAILABILITY = 'ChangeAvailability',
   CHANGE_CONFIGURATION = 'ChangeConfiguration',
@@ -54,7 +54,7 @@ export enum OCPP16MessageTrigger {
   StatusNotification = 'StatusNotification',
 }
 
-export enum OCPP16RequestCommand {
+export const enum OCPP16RequestCommand {
   AUTHORIZE = 'Authorize',
   BOOT_NOTIFICATION = 'BootNotification',
   DATA_TRANSFER = 'DataTransfer',
@@ -67,7 +67,7 @@ export enum OCPP16RequestCommand {
   STOP_TRANSACTION = 'StopTransaction',
 }
 
-enum ResetType {
+export const enum ResetType {
   HARD = 'Hard',
   SOFT = 'Soft',
 }
index 6dc0358065370752ea7f59edcb021ac15043336a..d0fddacebb31c16c006c2d9233b0b4517a04398a 100644 (file)
@@ -4,13 +4,13 @@ import type { GenericStatus, RegistrationStatusEnumType } from '../Common.js'
 import type { OCPPConfigurationKey } from '../Configuration.js'
 import type { OCPP16ChargingSchedule } from './ChargingProfile.js'
 
-export enum OCPP16AvailabilityStatus {
+export const enum OCPP16AvailabilityStatus {
   ACCEPTED = 'Accepted',
   REJECTED = 'Rejected',
   SCHEDULED = 'Scheduled',
 }
 
-export enum OCPP16ChargingProfileStatus {
+export const enum OCPP16ChargingProfileStatus {
   ACCEPTED = 'Accepted',
   NOT_SUPPORTED = 'NotSupported',
   REJECTED = 'Rejected',
@@ -21,14 +21,14 @@ export enum OCPP16ClearChargingProfileStatus {
   UNKNOWN = 'Unknown',
 }
 
-export enum OCPP16ConfigurationStatus {
+export const enum OCPP16ConfigurationStatus {
   ACCEPTED = 'Accepted',
   NOT_SUPPORTED = 'NotSupported',
   REBOOT_REQUIRED = 'RebootRequired',
   REJECTED = 'Rejected',
 }
 
-export enum OCPP16DataTransferStatus {
+export const enum OCPP16DataTransferStatus {
   ACCEPTED = 'Accepted',
   REJECTED = 'Rejected',
   UNKNOWN_MESSAGE_ID = 'UnknownMessageId',
@@ -50,7 +50,7 @@ export enum OCPP16TriggerMessageStatus {
   REJECTED = 'Rejected',
 }
 
-export enum OCPP16UnlockStatus {
+export const enum OCPP16UnlockStatus {
   NOT_SUPPORTED = 'NotSupported',
   UNLOCK_FAILED = 'UnlockFailed',
   UNLOCKED = 'Unlocked',
index 1b7d3521de104d0f092d104fc7daece88df56a1d..cf7be3179d553b7c8a0350bb2a4ec1b6c61f4274 100644 (file)
@@ -19,7 +19,7 @@ import type {
   ReportDataType,
 } from './Variables.js'
 
-export enum OCPP20IncomingRequestCommand {
+export const enum OCPP20IncomingRequestCommand {
   CLEAR_CACHE = 'ClearCache',
   GET_BASE_REPORT = 'GetBaseReport',
   GET_VARIABLES = 'GetVariables',
@@ -29,7 +29,7 @@ export enum OCPP20IncomingRequestCommand {
   SET_VARIABLES = 'SetVariables',
 }
 
-export enum OCPP20RequestCommand {
+export const enum OCPP20RequestCommand {
   BOOT_NOTIFICATION = 'BootNotification',
   HEARTBEAT = 'Heartbeat',
   NOTIFY_REPORT = 'NotifyReport',
index 7190d9a4483f3ccb53095b5c76eb2d645651d68e..4800dcd41df79c7cc3cd90516787589d101a05dd 100644 (file)
@@ -1,6 +1,6 @@
 import type { JsonObject } from '../JsonType.js'
 
-export enum GenericStatus {
+export const enum GenericStatus {
   Accepted = 'Accepted',
   Rejected = 'Rejected',
 }
index 40a6e7353ac25979ca10bff45a06d1d8cb2b2440..d6367e1617174792f1bf7ff1e408297e21a1e7e0 100644 (file)
@@ -1,4 +1,4 @@
-export enum ErrorType {
+export const enum ErrorType {
   // Payload for Action is syntactically incorrect or not conform the PDU structure for Action
   FORMAT_VIOLATION = 'FormatViolation',
   /** @deprecated use FORMAT_VIOLATION instead */
index d8573eee5fe3ce5146c5c127d7f5d599eeb082b2..2601ffb6ee52dfe68ec23d5fec4458411a8cab59 100644 (file)
@@ -1,5 +1,5 @@
 /* eslint-disable perfectionist/sort-enums */
-export enum MessageType {
+export const enum MessageType {
   CALL_MESSAGE = 2, // Caller to Callee
   CALL_RESULT_MESSAGE = 3, // Callee to Caller
   CALL_ERROR_MESSAGE = 4, // Callee to Caller
index a19fc28033e6afe9f9475cbd8d12334185ad3b04..2bc8210c580687a4410a8eba1e42a8d7853fba71 100644 (file)
@@ -1,4 +1,4 @@
-export enum OCPPVersion {
+export const enum OCPPVersion {
   VERSION_16 = '1.6',
   VERSION_20 = '2.0',
   VERSION_201 = '2.0.1',