From ff9d1031c851d206c3edca93754b93a8b238aabe Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Thu, 11 May 2023 00:44:01 +0200 Subject: [PATCH] refactor: group conditions in connector status change check MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- src/charging-station/ocpp/OCPPServiceUtils.ts | 36 +++++++++---------- 1 file changed, 16 insertions(+), 20 deletions(-) diff --git a/src/charging-station/ocpp/OCPPServiceUtils.ts b/src/charging-station/ocpp/OCPPServiceUtils.ts index 1326cde4..ef678f31 100644 --- a/src/charging-station/ocpp/OCPPServiceUtils.ts +++ b/src/charging-station/ocpp/OCPPServiceUtils.ts @@ -205,16 +205,14 @@ export class OCPPServiceUtils { switch (chargingStation.stationInfo.ocppVersion) { case OCPPVersion.VERSION_16: if ( - connectorId === 0 && - OCPP16Constants.ChargePointStatusChargingStationTransitions.findIndex( - (transition) => transition.from === fromStatus && transition.to === status - ) !== -1 - ) { - transitionAllowed = true; - } else if ( - OCPP16Constants.ChargePointStatusConnectorTransitions.findIndex( - (transition) => transition.from === fromStatus && transition.to === status - ) !== -1 + (connectorId === 0 && + OCPP16Constants.ChargePointStatusChargingStationTransitions.findIndex( + (transition) => transition.from === fromStatus && transition.to === status + ) !== -1) || + (connectorId > 0 && + OCPP16Constants.ChargePointStatusConnectorTransitions.findIndex( + (transition) => transition.from === fromStatus && transition.to === status + ) !== -1) ) { transitionAllowed = true; } @@ -222,16 +220,14 @@ export class OCPPServiceUtils { case OCPPVersion.VERSION_20: case OCPPVersion.VERSION_201: if ( - connectorId === 0 && - OCPP20Constants.ChargingStationStatusTransitions.findIndex( - (transition) => transition.from === fromStatus && transition.to === status - ) !== -1 - ) { - transitionAllowed = true; - } else if ( - OCPP20Constants.ConnectorStatusTransitions.findIndex( - (transition) => transition.from === fromStatus && transition.to === status - ) !== -1 + (connectorId === 0 && + OCPP20Constants.ChargingStationStatusTransitions.findIndex( + (transition) => transition.from === fromStatus && transition.to === status + ) !== -1) || + (connectorId > 0 && + OCPP20Constants.ConnectorStatusTransitions.findIndex( + (transition) => transition.from === fromStatus && transition.to === status + ) !== -1) ) { transitionAllowed = true; } -- 2.34.1