From 65099c1e7297b252523172096a8d6ded22daa702 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Sat, 8 Jun 2024 20:51:37 +0200 Subject: [PATCH] fix: allow to set charging profile with TxProfile purpose MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- src/charging-station/Helpers.ts | 5 +++-- .../ocpp/1.6/OCPP16IncomingRequestService.ts | 8 ++++++-- src/types/index.ts | 1 + src/types/ocpp/ChargingProfile.ts | 7 +++++++ 4 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/charging-station/Helpers.ts b/src/charging-station/Helpers.ts index 8f9d833a..2c264cd5 100644 --- a/src/charging-station/Helpers.ts +++ b/src/charging-station/Helpers.ts @@ -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) diff --git a/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts b/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts index 4ab585ff..e78ff997 100644 --- a/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts +++ b/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts @@ -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 } diff --git a/src/types/index.ts b/src/types/index.ts index 868dd73d..6fa70636 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -162,6 +162,7 @@ export { ChargePointErrorCode } from './ocpp/ChargePointErrorCode.js' export { type ChargingProfile, ChargingProfileKindType, + ChargingProfilePurposeType, ChargingRateUnitType, type ChargingSchedulePeriod, RecurrencyKindType diff --git a/src/types/ocpp/ChargingProfile.ts b/src/types/ocpp/ChargingProfile.ts index efc25b90..8fc773b7 100644 --- a/src/types/ocpp/ChargingProfile.ts +++ b/src/types/ocpp/ChargingProfile.ts @@ -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 -- 2.34.1