Skip to content

Commit

Permalink
Merge pull request #56 from e-flux-platform/add-unlock-connector-16
Browse files Browse the repository at this point in the history
  • Loading branch information
Bholtland authored Apr 2, 2024
2 parents ebe0be8 + 2e652bb commit b394d0b
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/lib/ChargeStation/configurations/default-ocpp-16.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import handleReset from '../eventHandlers/ocpp-16/handle-reset';
import handleSetChargingProfile from '../eventHandlers/ocpp-16/handle-set-charging-profile';
import handleAuthorizeCallResultReceived from 'lib/ChargeStation/eventHandlers/ocpp-16/handle-authorize-call-result-received';
import handleDataTransfer from 'lib/ChargeStation/eventHandlers/ocpp-16/handle-data-transfer';
import handleUnlockConnector from 'lib/ChargeStation/eventHandlers/ocpp-16/handle-unlock-connector';

// 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 Down Expand Up @@ -74,5 +75,6 @@ export default {
[e.ChargingLimitReached]: [sendChargingLimitReached],
[e.ResetReceived]: [handleReset],
[e.SetChargingProfileReceived]: [handleSetChargingProfile],
[e.DataTransferReceived]: [handleDataTransfer]
[e.DataTransferReceived]: [handleDataTransfer],
[e.UnlockConnectorReceived]: [handleUnlockConnector],
};
1 change: 1 addition & 0 deletions src/lib/ChargeStation/eventHandlers/event-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export const EventTypes = {
SetChargingProfileReceived: 'setChargingProfileReceived',
DataTransferReceived: 'dataTransferReceived',
DataTransferCallResultReceived: 'dataTransferCallResultReceived',
UnlockConnectorReceived: 'unlockConnectorReceived',
};

// OCPP 1.6 specific events
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { ChargeStationEventHandler } from 'lib/ChargeStation/eventHandlers';
import { UnlockConnectorResponse } from 'schemas/ocpp/1.6/UnlockConnectorResponse';
import { UnlockConnectorRequest } from 'schemas/ocpp/1.6/UnlockConnector';

const handleUnlockConnector: ChargeStationEventHandler<
UnlockConnectorRequest
> = async ({ chargepoint, callMessageBody, callMessageId }) => {
// connectorId 0 is not a valid connectorId
if (!callMessageBody.connectorId) {
const result: UnlockConnectorResponse = {
status: 'UnlockFailed',
};
chargepoint.writeCallResult(callMessageId, result);
}

if (chargepoint.hasRunningSession(callMessageBody.connectorId)) {
await chargepoint.stopSession(callMessageBody.connectorId);
}

const response: UnlockConnectorResponse = {
status: 'Unlocked',
};

chargepoint.writeCallResult(callMessageId, response);
};

export default handleUnlockConnector;

0 comments on commit b394d0b

Please sign in to comment.