diff --git a/src/lib/ChargeStation/configurations/default-ocpp-16.ts b/src/lib/ChargeStation/configurations/default-ocpp-16.ts index c944cf2..50d8d4e 100644 --- a/src/lib/ChargeStation/configurations/default-ocpp-16.ts +++ b/src/lib/ChargeStation/configurations/default-ocpp-16.ts @@ -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 @@ -74,5 +75,6 @@ export default { [e.ChargingLimitReached]: [sendChargingLimitReached], [e.ResetReceived]: [handleReset], [e.SetChargingProfileReceived]: [handleSetChargingProfile], - [e.DataTransferReceived]: [handleDataTransfer] + [e.DataTransferReceived]: [handleDataTransfer], + [e.UnlockConnectorReceived]: [handleUnlockConnector], }; diff --git a/src/lib/ChargeStation/eventHandlers/event-types.js b/src/lib/ChargeStation/eventHandlers/event-types.js index 74845a4..5663106 100644 --- a/src/lib/ChargeStation/eventHandlers/event-types.js +++ b/src/lib/ChargeStation/eventHandlers/event-types.js @@ -19,6 +19,7 @@ export const EventTypes = { SetChargingProfileReceived: 'setChargingProfileReceived', DataTransferReceived: 'dataTransferReceived', DataTransferCallResultReceived: 'dataTransferCallResultReceived', + UnlockConnectorReceived: 'unlockConnectorReceived', }; // OCPP 1.6 specific events diff --git a/src/lib/ChargeStation/eventHandlers/ocpp-16/handle-unlock-connector.ts b/src/lib/ChargeStation/eventHandlers/ocpp-16/handle-unlock-connector.ts new file mode 100644 index 0000000..76bff01 --- /dev/null +++ b/src/lib/ChargeStation/eventHandlers/ocpp-16/handle-unlock-connector.ts @@ -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;