From: Jérôme Benoit Date: Tue, 18 Apr 2023 17:18:40 +0000 (+0200) Subject: fix: ensure constants are readonly data structures X-Git-Tag: v1.2.10~4 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=4cf856f0ff988b709da7b9185913266146e82add;p=e-mobility-charging-stations-simulator.git fix: ensure constants are readonly data structures Signed-off-by: Jérôme Benoit --- diff --git a/src/charging-station/ocpp/1.6/OCPP16Constants.ts b/src/charging-station/ocpp/1.6/OCPP16Constants.ts index 2697171c..5f695881 100644 --- a/src/charging-station/ocpp/1.6/OCPP16Constants.ts +++ b/src/charging-station/ocpp/1.6/OCPP16Constants.ts @@ -1,25 +1,29 @@ import { OCPP16ChargePointStatus } from '../../../types'; import { OCPPConstants } from '../internal'; -type Transition = { from?: OCPP16ChargePointStatus; to: OCPP16ChargePointStatus }; +type Transition = Readonly<{ + from?: OCPP16ChargePointStatus; + to: OCPP16ChargePointStatus; +}>; export class OCPP16Constants extends OCPPConstants { - static readonly ChargePointStatusChargingStationTransitions: Transition[] = [ - { to: OCPP16ChargePointStatus.Available }, - // { from: OCPP16ChargePointStatus.Available, to: OCPP16ChargePointStatus.Available }, - { from: OCPP16ChargePointStatus.Available, to: OCPP16ChargePointStatus.Unavailable }, - { from: OCPP16ChargePointStatus.Available, to: OCPP16ChargePointStatus.Faulted }, - { to: OCPP16ChargePointStatus.Unavailable }, - { from: OCPP16ChargePointStatus.Unavailable, to: OCPP16ChargePointStatus.Available }, - // { from: OCPP16ChargePointStatus.Unavailable, to: OCPP16ChargePointStatus.Unavailable }, - { from: OCPP16ChargePointStatus.Unavailable, to: OCPP16ChargePointStatus.Faulted }, - { to: OCPP16ChargePointStatus.Faulted }, - { from: OCPP16ChargePointStatus.Faulted, to: OCPP16ChargePointStatus.Available }, - { from: OCPP16ChargePointStatus.Faulted, to: OCPP16ChargePointStatus.Unavailable }, - // { from: OCPP16ChargePointStatus.Faulted, to: OCPP16ChargePointStatus.Faulted }, - ]; + static readonly ChargePointStatusChargingStationTransitions: Readonly = + Object.freeze([ + { to: OCPP16ChargePointStatus.Available }, + // { from: OCPP16ChargePointStatus.Available, to: OCPP16ChargePointStatus.Available }, + { from: OCPP16ChargePointStatus.Available, to: OCPP16ChargePointStatus.Unavailable }, + { from: OCPP16ChargePointStatus.Available, to: OCPP16ChargePointStatus.Faulted }, + { to: OCPP16ChargePointStatus.Unavailable }, + { from: OCPP16ChargePointStatus.Unavailable, to: OCPP16ChargePointStatus.Available }, + // { from: OCPP16ChargePointStatus.Unavailable, to: OCPP16ChargePointStatus.Unavailable }, + { from: OCPP16ChargePointStatus.Unavailable, to: OCPP16ChargePointStatus.Faulted }, + { to: OCPP16ChargePointStatus.Faulted }, + { from: OCPP16ChargePointStatus.Faulted, to: OCPP16ChargePointStatus.Available }, + { from: OCPP16ChargePointStatus.Faulted, to: OCPP16ChargePointStatus.Unavailable }, + // { from: OCPP16ChargePointStatus.Faulted, to: OCPP16ChargePointStatus.Faulted }, + ]); - static readonly ChargePointStatusConnectorTransitions: Transition[] = [ + static readonly ChargePointStatusConnectorTransitions: Readonly = Object.freeze([ { to: OCPP16ChargePointStatus.Available }, // { from: OCPP16ChargePointStatus.Available, to: OCPP16ChargePointStatus.Available }, { from: OCPP16ChargePointStatus.Available, to: OCPP16ChargePointStatus.Preparing }, @@ -110,5 +114,5 @@ export class OCPP16Constants extends OCPPConstants { { from: OCPP16ChargePointStatus.Faulted, to: OCPP16ChargePointStatus.Reserved }, { from: OCPP16ChargePointStatus.Faulted, to: OCPP16ChargePointStatus.Unavailable }, // { from: OCPP16ChargePointStatus.Faulted, to: OCPP16ChargePointStatus.Faulted }, - ]; + ]); } diff --git a/src/charging-station/ocpp/2.0/OCPP20Constants.ts b/src/charging-station/ocpp/2.0/OCPP20Constants.ts index 58a1004c..f24cc565 100644 --- a/src/charging-station/ocpp/2.0/OCPP20Constants.ts +++ b/src/charging-station/ocpp/2.0/OCPP20Constants.ts @@ -1,10 +1,13 @@ import { OCPP20ConnectorStatusEnumType } from '../../../types'; import { OCPPConstants } from '../internal'; -type Transition = { from?: OCPP20ConnectorStatusEnumType; to: OCPP20ConnectorStatusEnumType }; +type Transition = Readonly<{ + from?: OCPP20ConnectorStatusEnumType; + to: OCPP20ConnectorStatusEnumType; +}>; export class OCPP20Constants extends OCPPConstants { - static readonly ChargingStationStatusTransitions: Transition[] = [ + static readonly ChargingStationStatusTransitions: Readonly = Object.freeze([ { to: OCPP20ConnectorStatusEnumType.Available }, // { from: OCPP20ConnectorStatusEnumType.Available, to: OCPP20ConnectorStatusEnumType.Available }, { @@ -26,9 +29,9 @@ export class OCPP20Constants extends OCPPConstants { { from: OCPP20ConnectorStatusEnumType.Faulted, to: OCPP20ConnectorStatusEnumType.Available }, { from: OCPP20ConnectorStatusEnumType.Faulted, to: OCPP20ConnectorStatusEnumType.Unavailable }, // { from: OCPP20ConnectorStatusEnumType.Faulted, to: OCPP20ConnectorStatusEnumType.Faulted }, - ]; + ]); - static readonly ConnectorStatusTransitions: Transition[] = [ + static readonly ConnectorStatusTransitions: Readonly = Object.freeze([ { to: OCPP20ConnectorStatusEnumType.Available }, // { from: OCPP20ConnectorStatusEnumType.Available, to: OCPP20ConnectorStatusEnumType.Available }, { from: OCPP20ConnectorStatusEnumType.Available, to: OCPP20ConnectorStatusEnumType.Occupied }, @@ -65,5 +68,5 @@ export class OCPP20Constants extends OCPPConstants { { from: OCPP20ConnectorStatusEnumType.Faulted, to: OCPP20ConnectorStatusEnumType.Reserved }, { from: OCPP20ConnectorStatusEnumType.Faulted, to: OCPP20ConnectorStatusEnumType.Unavailable }, // { from: OCPP20ConnectorStatusEnumType.Faulted, to: OCPP20ConnectorStatusEnumType.Faulted }, - ]; + ]); }