Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add UnlockConnector handler #56

Merged
merged 1 commit into from
Apr 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;