Skip to content

Commit

Permalink
Respect AuthorizeRemoteStart config option when starting a session
Browse files Browse the repository at this point in the history
  • Loading branch information
nick-jones committed Oct 1, 2024
1 parent 3e057cd commit ce565ca
Show file tree
Hide file tree
Showing 12 changed files with 76 additions and 14 deletions.
8 changes: 3 additions & 5 deletions src/lib/ChargeStation/configurations/ads-tec-ocpp-16.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
import { EventTypes as e } from '../eventHandlers/event-types';
import DefaultOCPP16 from 'lib/ChargeStation/configurations/default-ocpp-16';
import sendStartTransaction from 'lib/ChargeStation/eventHandlers/ocpp-16/send-start-transaction';
import { ChargeStationEventHandler } from 'lib/ChargeStation/eventHandlers';
import sendAuthorize from 'lib/ChargeStation/eventHandlers/ocpp-16/send-authorize';
import { AuthorizationType } from 'lib/settings';
import sendAuthorizeOrStartTransaction from 'lib/ChargeStation/eventHandlers/ocpp-16/send-authorize-or-start-transaction';

const initiateSession: ChargeStationEventHandler = async (params) => {
const { session, chargepoint } = params;
if (session.options.authorizationType === AuthorizationType.CreditCard) {
session.options.uid = chargepoint.configuration.getVariableValue(
'CreditIdToken'
) as string;
await sendStartTransaction(params);
} else {
await sendAuthorize(params);
session.options.skipAuthorize = true;
}
return sendAuthorizeOrStartTransaction(params);
};

export default {
Expand Down
4 changes: 2 additions & 2 deletions src/lib/ChargeStation/configurations/default-ocpp-16.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import {
import sendBootNotification from '../eventHandlers/ocpp-16/send-boot-notification';
import sendHeartbeat from '../eventHandlers/ocpp-16/send-heartbeat';
import sendHeartbeatDelayed from '../eventHandlers/ocpp-16/send-heartbeat-delayed';
import sendAuthorize from '../eventHandlers/ocpp-16/send-authorize';
import sendStopTransaction from '../eventHandlers/ocpp-16/send-stop-transaction';
import handleTokenRejection from '../eventHandlers/ocpp-16/handle-token-rejection';
import sendStartTransaction from '../eventHandlers/ocpp-16/send-start-transaction';
Expand Down Expand Up @@ -33,6 +32,7 @@ import handleDataTransfer from 'lib/ChargeStation/eventHandlers/ocpp-16/handle-d
import handleGetInstalledCertificateIds from 'lib/ChargeStation/eventHandlers/ocpp-16/handle-get-installed-certificate-ids';
import handleUpdateFirmwareReceived from '../eventHandlers/ocpp-16/handle-update-firmware-received';
import handleTriggerMessageReceived from '../eventHandlers/ocpp-16/handle-trigger-message-received';
import sendAuthorizeOrStartTransaction from 'lib/ChargeStation/eventHandlers/ocpp-16/send-authorize-or-start-transaction';

// This is the default configuration for OCPP 1.6
// Each key represents an event, and the value represents an array of handlers that will be called when the event is emitted
Expand All @@ -47,7 +47,7 @@ export default {
],
[e.HeartbeatCallResultReceived]: [handleHeartbeatCallResultReceived],
[e.HeartbeatAccepted]: [sendHeartbeatDelayed],
[e.SessionStartInitiated]: [sendAuthorize],
[e.SessionStartInitiated]: [sendAuthorizeOrStartTransaction],
[e.SessionStopInitiated]: [sendStopTransaction],
[e.AuthorizeCallResultReceived]: [handleAuthorizeCallResultReceived],
[e.AuthorizationFailed]: [handleTokenRejection],
Expand Down
3 changes: 2 additions & 1 deletion src/lib/ChargeStation/configurations/default-ocpp-20.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import handleRequestStopTransaction from 'lib/ChargeStation/eventHandlers/ocpp-2
import handleGetInstalledCertificateIds from 'lib/ChargeStation/eventHandlers/ocpp-20/handle-get-installed-certificate-ids';
import handleUpdateFirmwareReceived from '../eventHandlers/ocpp-20/handle-update-firmware-received';
import handleTriggerMessageReceived from '../eventHandlers/ocpp-20/handle-trigger-message-received';
import sendAuthorizeOrStartTransaction from 'lib/ChargeStation/eventHandlers/ocpp-20/send-authorize-or-start-transaction';

// This is the default configuration for OCPP 2.0.*
// Each key represents an event, and the value represents an array of handlers that will be called when the event is emitted
Expand All @@ -43,7 +44,7 @@ export default {
[e201.GetBaseReportReceived]: [handleGetBaseReportReceived],
[e201.SetVariablesReceived]: [handleSetVariables],
[e201.GetVariablesReceived]: [handleGetVariables],
[e.SessionStartInitiated]: [sendAuthorize],
[e.SessionStartInitiated]: [sendAuthorizeOrStartTransaction],
[e.SessionStopInitiated]: [sendStopTransaction],
[e.AuthorizeCallResultReceived]: [handleAuthorizeCallResultReceived],
[e.AuthorizationFailed]: [handleTokenRejection],
Expand Down
7 changes: 5 additions & 2 deletions src/lib/ChargeStation/configurations/e-totem-ocpp-16.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import DefaultOCPP16 from 'lib/ChargeStation/configurations/default-ocpp-16';
import sendAuthorize from 'lib/ChargeStation/eventHandlers/ocpp-16/send-authorize';
import {
EventTypes as e,
EventTypes16 as e16,
Expand All @@ -12,10 +11,14 @@ import {
import sendStatusNotificationFinishing from 'lib/ChargeStation/eventHandlers/ocpp-16/send-status-notification-finishing';
import sendStatusNotificationAvailable from 'lib/ChargeStation/eventHandlers/ocpp-16/send-status-notification-available';
import handleTransactionStoppedUI from 'lib/ChargeStation/eventHandlers/ocpp-16/handle-transaction-stopped-ui';
import sendAuthorizeOrStartTransaction from 'lib/ChargeStation/eventHandlers/ocpp-16/send-authorize-or-start-transaction';

export default {
...DefaultOCPP16,
[e.SessionStartInitiated]: [overrideSessionUid, sendAuthorize],
[e.SessionStartInitiated]: [
overrideSessionUid,
sendAuthorizeOrStartTransaction,
],
[e.DataTransferCallResultReceived]: [processDataTransferResult],
[e16.StopTransactionAccepted]: [
sendStatusNotificationFinishing,
Expand Down
7 changes: 5 additions & 2 deletions src/lib/ChargeStation/configurations/sicharge-ocpp-16.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@ import { EventTypes as e } from '../eventHandlers/event-types';
import DefaultOCPP16 from 'lib/ChargeStation/configurations/default-ocpp-16';
import handleDataTransfer from 'lib/ChargeStation/eventHandlers/ocpp-16/sicharge/handle-data-transfer';
import generateSessionUid from 'lib/ChargeStation/eventHandlers/ocpp-16/sicharge/generate-session-uid';
import sendAuthorize from 'lib/ChargeStation/eventHandlers/ocpp-16/send-authorize';
import sendAuthorizeOrStartTransaction from 'lib/ChargeStation/eventHandlers/ocpp-16/send-authorize-or-start-transaction';

export default {
...DefaultOCPP16,
[e.SessionStartInitiated]: [generateSessionUid, sendAuthorize],
[e.SessionStartInitiated]: [
generateSessionUid,
sendAuthorizeOrStartTransaction,
],
[e.DataTransferReceived]: [handleDataTransfer],
};
5 changes: 4 additions & 1 deletion src/lib/ChargeStation/eventHandlers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ import ChargeStation, { Session } from 'lib/ChargeStation';
import { OCPPVersion } from 'lib/settings';
import { Map } from '../../../types/generic';

interface ChargeStationEventHandlerParams<CallBodyType, CallResultBodyType> {
export interface ChargeStationEventHandlerParams<
CallBodyType,
CallResultBodyType,
> {
chargepoint: ChargeStation;
emitter: ChargeStationEventEmitter;
session: Session;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ export default async function handleRemoteStartTransaction({
setTimeout(() => {
chargepoint.startSession(Number(connectorId), {
uid: idTag,
skipAuthorize:
chargepoint.configuration
.getVariableValue('AuthorizeRemoteTxRequests')
?.toString() === 'false',
});
}, 100);
response = {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { ChargeStationEventHandler } from 'lib/ChargeStation/eventHandlers';
import sendAuthorize from 'lib/ChargeStation/eventHandlers/ocpp-16/send-authorize';
import sendStartTransaction from 'lib/ChargeStation/eventHandlers/ocpp-16/send-start-transaction';

const sendAuthorizeOrStartTransaction: ChargeStationEventHandler = async (
params
) => {
if (params.session.options?.skipAuthorize !== true) {
return sendAuthorize(params);
}
return sendStartTransaction(params);
};

export default sendAuthorizeOrStartTransaction;
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ const handleRequestStartTransaction: ChargeStationEventHandler<
maxPowerKw: 0,
uid: idToken.idToken,
remoteStartId,
skipAuthorize:
chargepoint.configuration
.getVariableValue('AuthCtrlr.AuthorizeRemoteStart')
?.toString() === 'false',
},
'rfid'
);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import {
ChargeStationEventHandler,
ChargeStationEventHandlerParams,
} from 'lib/ChargeStation/eventHandlers';
import sendStartTransaction from 'lib/ChargeStation/eventHandlers/ocpp-20/send-start-transaction';
import sendAuthorize from 'lib/ChargeStation/eventHandlers/ocpp-20/send-authorize';
import { AuthorizeRequest } from 'schemas/ocpp/2.0/AuthorizeRequest';
import { AuthorizeResponse } from 'schemas/ocpp/2.0/AuthorizeResponse';

const sendAuthorizeOrStartTransaction: ChargeStationEventHandler = async (
params
) => {
if (params.session.options?.skipAuthorize !== true) {
return sendAuthorize(
params as ChargeStationEventHandlerParams<
AuthorizeRequest,
AuthorizeResponse
>
);
}

return sendStartTransaction(params);
};

export default sendAuthorizeOrStartTransaction;
1 change: 1 addition & 0 deletions src/lib/ChargeStation/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,7 @@ interface SessionOptions {
uid: string;
authorizationType: AuthorizationType;
remoteStartId?: number;
skipAuthorize?: boolean;
}

export class Session {
Expand Down
8 changes: 7 additions & 1 deletion src/lib/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ export const sessionSettingsList: SettingsListSetting<SessionSetting>[] = [
export interface Variable16 {
key: string;
description?: string;
value: string | number;
value: string | number | boolean;
predicate?: (settings: Settings) => boolean;
}

Expand Down Expand Up @@ -241,6 +241,12 @@ export const defaultVariableConfig16: Variable16[] = [
description: 'Meta data about max current on connector 2',
value: 32,
},
{
key: 'AuthorizeRemoteTxRequests',
description:
'Whether a remote request to start a transaction should be authorized before start',
value: true,
},
{
key: 'PaymentCurrency',
description: 'Currency that payments should be made in',
Expand Down

0 comments on commit ce565ca

Please sign in to comment.