fix: allow to set charging profile with TxProfile purpose
authorJérôme Benoit <jerome.benoit@piment-noir.org>
Sat, 8 Jun 2024 18:51:37 +0000 (20:51 +0200)
committerJérôme Benoit <jerome.benoit@piment-noir.org>
Sat, 8 Jun 2024 18:51:37 +0000 (20:51 +0200)
Signed-off-by: Jérôme Benoit <jerome.benoit@piment-noir.org>
src/charging-station/Helpers.ts
src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts
src/types/index.ts
src/types/ocpp/ChargingProfile.ts

index 8f9d833ae08b660528e541b9a78bb0ae745b0cd8..2c264cd5612cfbeb8d1ccf01347e06810fcabf0d 100644 (file)
@@ -31,6 +31,7 @@ import {
   BootReasonEnumType,
   type ChargingProfile,
   ChargingProfileKindType,
+  ChargingProfilePurposeType,
   ChargingRateUnitType,
   type ChargingSchedulePeriod,
   type ChargingStationConfiguration,
@@ -419,10 +420,10 @@ export const resetConnectorStatus = (connectorStatus: ConnectorStatus | undefine
   if (isNotEmptyArray(connectorStatus.chargingProfiles)) {
     connectorStatus.chargingProfiles = connectorStatus.chargingProfiles.filter(
       chargingProfile =>
+        chargingProfile.chargingProfilePurpose !== ChargingProfilePurposeType.TX_PROFILE ||
         (chargingProfile.transactionId != null &&
           connectorStatus.transactionId != null &&
-          chargingProfile.transactionId !== connectorStatus.transactionId) ||
-        chargingProfile.transactionId == null
+          chargingProfile.transactionId !== connectorStatus.transactionId)
     )
   }
   resetAuthorizeConnectorStatus(connectorStatus)
index 4ab585ff247372cef68074da3b888f1523ea038f..e78ff997c443907fb0d7b00ad0be854e98990ca7 100644 (file)
@@ -918,6 +918,7 @@ export class OCPP16IncomingRequestService extends OCPPIncomingRequestService {
       csChargingProfiles.chargingProfilePurpose === OCPP16ChargingProfilePurposeType.TX_PROFILE &&
       connectorId > 0 &&
       connectorStatus?.transactionStarted === true &&
+      csChargingProfiles.transactionId != null &&
       csChargingProfiles.transactionId !== connectorStatus.transactionId
     ) {
       logger.error(
@@ -1276,7 +1277,10 @@ export class OCPP16IncomingRequestService extends OCPPIncomingRequestService {
     connectorId: number,
     chargingProfile: OCPP16ChargingProfile
   ): boolean {
-    if (chargingProfile.chargingProfilePurpose === OCPP16ChargingProfilePurposeType.TX_PROFILE) {
+    if (
+      chargingProfile.chargingProfilePurpose === OCPP16ChargingProfilePurposeType.TX_PROFILE &&
+      chargingProfile.transactionId == null
+    ) {
       OCPP16ServiceUtils.setChargingProfile(chargingStation, connectorId, chargingProfile)
       logger.debug(
         `${chargingStation.logPrefix()} Charging profile(s) set at remote start transaction on ${
@@ -1289,7 +1293,7 @@ export class OCPP16IncomingRequestService extends OCPPIncomingRequestService {
     logger.debug(
       `${chargingStation.logPrefix()} Not allowed to set ${
         chargingProfile.chargingProfilePurpose
-      } charging profile(s) at remote start transaction`
+      } charging profile(s)${chargingProfile.transactionId != null ? ' with transactionId set' : ''} at remote start transaction`
     )
     return false
   }
index 868dd73df07ea4fa37b95a333357c8bf4436a381..6fa70636b9d3e9b153d90c8f5dd20a4b36d75018 100644 (file)
@@ -162,6 +162,7 @@ export { ChargePointErrorCode } from './ocpp/ChargePointErrorCode.js'
 export {
   type ChargingProfile,
   ChargingProfileKindType,
+  ChargingProfilePurposeType,
   ChargingRateUnitType,
   type ChargingSchedulePeriod,
   RecurrencyKindType
index efc25b90083ad54a28aa977ee587e63851d643f0..8fc773b73a5352642006bd249a4f6fc42e44e09e 100644 (file)
@@ -1,6 +1,7 @@
 import {
   type OCPP16ChargingProfile,
   OCPP16ChargingProfileKindType,
+  OCPP16ChargingProfilePurposeType,
   OCPP16ChargingRateUnitType,
   type OCPP16ChargingSchedulePeriod,
   OCPP16RecurrencyKindType
@@ -10,6 +11,12 @@ export type ChargingProfile = OCPP16ChargingProfile
 
 export type ChargingSchedulePeriod = OCPP16ChargingSchedulePeriod
 
+export const ChargingProfilePurposeType = {
+  ...OCPP16ChargingProfilePurposeType
+} as const
+// eslint-disable-next-line @typescript-eslint/no-redeclare
+export type ChargingProfilePurposeType = OCPP16ChargingProfilePurposeType
+
 export const ChargingProfileKindType = {
   ...OCPP16ChargingProfileKindType
 } as const