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 stubs to track reset and set charging profile commands. #28

Merged
merged 2 commits into from
Nov 14, 2023
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
2 changes: 1 addition & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module.exports = {
settings: {
jest: { version: 26 },
},
parser: '@typescript-eslint/eslint-parser',
parser: '@typescript-eslint/parser',
parserOptions: {
sourceType: 'module',
ecmaFeatures: {
Expand Down
4 changes: 4 additions & 0 deletions src/lib/ChargeStation/configurations/default-ocpp-16.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ import handleStartTransactionCallResultReceived from '../eventHandlers/ocpp-16/h
import handleStopTransactionCallResultReceived from '../eventHandlers/ocpp-16/handle-stop-transaction-call-result-received';
import sendChargingLimitReached from '../eventHandlers/ocpp-16/send-charging-limit-reached';
import sendMeterValues from '../eventHandlers/ocpp-16/send-meter-values';
import handleReset from '../eventHandlers/ocpp-16/handle-reset';
import handleSetChargingProfile from '../eventHandlers/ocpp-16/handle-set-charging-profile';

// 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 @@ -69,4 +71,6 @@ export default {
[e16.ChangeConfigurationReceived]: [handleChangeConfiguration],
[e.ChargingTick]: [sendMeterValues],
[e.ChargingLimitReached]: [sendChargingLimitReached],
[e.ResetReceived]: [handleReset],
[e.SetChargingProfileReceived]: [handleSetChargingProfile],
};
4 changes: 4 additions & 0 deletions src/lib/ChargeStation/configurations/default-ocpp-20.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import sendTransationEventUpdated from '../eventHandlers/ocpp-20/send-transactio
import sendChargingLimitReached from '../eventHandlers/ocpp-20/send-charging-limit-reached';
import handleTransactionStartedUI from "lib/ChargeStation/eventHandlers/ocpp-16/handle-transaction-started-ui";
import handleTransactionStoppedUI from "lib/ChargeStation/eventHandlers/ocpp-16/handle-transaction-stopped-ui";
import handleReset from "lib/ChargeStation/eventHandlers/ocpp-20/handle-reset";
import handleSetChargingProfile from "lib/ChargeStation/eventHandlers/ocpp-20/handle-set-charging-profile";

// 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 @@ -46,4 +48,6 @@ export default {
[e.Stopped]: [handleTransactionStoppedUI],
[e.ChargingTick]: [sendTransationEventUpdated],
[e.ChargingLimitReached]: [sendChargingLimitReached],
[e.ResetReceived]: [handleReset],
[e.SetChargingProfileReceived]: [handleSetChargingProfile],
};
2 changes: 2 additions & 0 deletions src/lib/ChargeStation/eventHandlers/event-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ export const EventTypes = {
AuthorizeCallResultReceived: 'authorizeCallResultReceived',
ChargingLimitReached: 'charingLimitReached',
ChargingTick: 'chargingTick',
ResetReceived: 'resetReceived',
SetChargingProfileReceived: 'setChargingProfileReceived',
};

// OCPP 1.6 specific events
Expand Down
13 changes: 13 additions & 0 deletions src/lib/ChargeStation/eventHandlers/ocpp-16/handle-reset.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { ChargeStationEventHandler } from 'lib/ChargeStation/eventHandlers';
import { ResetRequest } from 'schemas/ocpp/1.6/Reset';
import { ResetResponse } from 'schemas/ocpp/1.6/ResetResponse';

const handleReset: ChargeStationEventHandler<ResetRequest> =
({ chargepoint, callMessageId }) => {
const response: ResetResponse = {status: 'Accepted',};

chargepoint.writeCallResult(callMessageId, response);
chargepoint.reboot();
};

export default handleReset;
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { ChargeStationEventHandler } from 'lib/ChargeStation/eventHandlers';
import { SetChargingProfileRequest } from 'schemas/ocpp/1.6/SetChargingProfile';
import { SetChargingProfileResponse } from 'schemas/ocpp/1.6/SetChargingProfileResponse';

const handleSetChargingProfile: ChargeStationEventHandler<SetChargingProfileRequest> =
({ chargepoint, callMessageId }) => {
const response: SetChargingProfileResponse = {status: 'Accepted'};

chargepoint.writeCallResult(callMessageId, response);
};

export default handleSetChargingProfile;
13 changes: 13 additions & 0 deletions src/lib/ChargeStation/eventHandlers/ocpp-20/handle-reset.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { ChargeStationEventHandler } from 'lib/ChargeStation/eventHandlers';
import { ResetRequest } from 'schemas/ocpp/2.0/ResetRequest';
import { ResetResponse } from 'schemas/ocpp/2.0/ResetResponse';

const handleReset: ChargeStationEventHandler<ResetRequest> =
({ chargepoint, callMessageId }) => {
const response: ResetResponse = {status: 'Accepted',};

chargepoint.writeCallResult(callMessageId, response);
chargepoint.reboot();
};

export default handleReset;
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { ChargeStationEventHandler } from 'lib/ChargeStation/eventHandlers';
import { SetChargingProfileRequest } from 'schemas/ocpp/2.0/SetChargingProfileRequest';
import { SetChargingProfileResponse } from 'schemas/ocpp/2.0/SetChargingProfileResponse';

const handleSetChargingProfile: ChargeStationEventHandler<SetChargingProfileRequest> =
({ chargepoint, callMessageId }) => {
const response: SetChargingProfileResponse = {status: 'Accepted'};

chargepoint.writeCallResult(callMessageId, response);
};

export default handleSetChargingProfile;
11 changes: 9 additions & 2 deletions src/lib/ChargeStation/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ export default class ChargeStation {
this.emitter.emitEvent(EventTypes.StationConnected);
};
this.connection.onError = (error: Event) => {
if (!this.connected) return;
if (!this.connected) {return;}

this.connected = false;

Expand Down Expand Up @@ -188,6 +188,13 @@ export default class ChargeStation {
}
}

reboot() {
this.disconnect();
setTimeout(() => {
this.connect();
}, 1000);
}

reconnect() {
if (this.numConnectionAttempts > 100) {
this.log('error', 'Too many connection attempts, giving up');
Expand All @@ -196,7 +203,7 @@ export default class ChargeStation {
const numSeconds = this.numConnectionAttempts < 5 ? 5 : 30;
this.log('message', `> Reconnecting in ${numSeconds} seconds`);
setTimeout(() => {
if (!this.connection) throw new Error('Connection is undefined');
if (!this.connection) {throw new Error('Connection is undefined');}
this.connection.connect();
this.numConnectionAttempts++;
}, numSeconds * 1000);
Expand Down
2 changes: 1 addition & 1 deletion src/screens/Dashboard/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import {formatDateTimeRelative} from 'utils/date';
import StopSessionModal from './StopSessionModal';
import StatusNotificationModal from './StatusNotificationModal';

const SESSION_STORAGE_KEY = 'chargeStationSettingsCache'
const SESSION_STORAGE_KEY = 'chargeStationSettingsCache';

@screen
export default class Home extends React.Component {
Expand Down