import { PerformanceObserver, performance } from 'perf_hooks';
import AutomaticTransactionGenerator from './AutomaticTransactionGenerator';
+import { ChargePointStatus } from '../types/ChargePointStatus';
import Configuration from '../utils/Configuration';
import Constants from '../utils/Constants.js';
import ElectricUtils from '../utils/ElectricUtils';
-import { MeasurandValues } from '../types/MeasurandValues';
+import MeasurandValues from '../types/MeasurandValues';
import OCPPError from './OcppError.js';
import Statistics from '../utils/Statistics';
import Utils from '../utils/Utils';
// Initialize connectors status
for (const connector in this._connectors) {
if (!this.getConnector(Utils.convertToInt(connector)).transactionStarted) {
- if (this.getConnector(Utils.convertToInt(connector)).bootStatus) {
+ if (!this.getConnector(Utils.convertToInt(connector)).status && this.getConnector(Utils.convertToInt(connector)).bootStatus) {
this.sendStatusNotification(Utils.convertToInt(connector), this.getConnector(Utils.convertToInt(connector)).bootStatus);
+ } else if (this.getConnector(Utils.convertToInt(connector)).status) {
+ this.sendStatusNotification(Utils.convertToInt(connector), this.getConnector(Utils.convertToInt(connector)).status);
} else {
- this.sendStatusNotification(Utils.convertToInt(connector), 'Available');
+ this.sendStatusNotification(Utils.convertToInt(connector), ChargePointStatus.AVAILABLE);
}
} else {
- this.sendStatusNotification(Utils.convertToInt(connector), 'Charging');
+ this.sendStatusNotification(Utils.convertToInt(connector), ChargePointStatus.CHARGING);
}
}
// Start the ATG
await this._stopMessageSequence();
// eslint-disable-next-line guard-for-in
for (const connector in this._connectors) {
- await this.sendStatusNotification(Utils.convertToInt(connector), 'Unavailable');
+ await this.sendStatusNotification(Utils.convertToInt(connector), ChargePointStatus.UNAVAILABLE);
}
if (this._wsConnection && this._wsConnection.readyState === WebSocket.OPEN) {
this._wsConnection.close();
}
}
- onOpen() {
+ onOpen(): void {
logger.info(`${this._logPrefix()} Is connected to server through ${this._wsConnectionUrl}`);
if (!this._isSocketRestart) {
// Send BootNotification
this._isSocketRestart = false;
}
- onError(error) {
+ onError(error): void {
switch (error) {
case 'ECONNREFUSED':
this._isSocketRestart = true;
}
}
- onClose(error) {
+ onClose(error): void {
switch (error) {
case 1000: // Normal close
case 1005:
}
}
- onPing() {
+ onPing(): void {
logger.debug(this._logPrefix() + ' Has received a WS ping (rfc6455) from the server');
}
- async onMessage(message) {
+ async onMessage(message) : Promise<void> {
let [messageType, messageId, commandName, commandPayload, errorDetails] = [0, '', Constants.ENTITY_CHARGING_STATION, '', ''];
try {
// Parse the message
}
}
- async sendHeartbeat() {
+ async sendHeartbeat(): Promise<void> {
try {
const payload = {
currentTime: new Date().toISOString(),
}
}
- async sendBootNotification() {
+ async sendBootNotification(): Promise<void> {
try {
await this.sendMessage(Utils.generateUUID(), this._bootNotificationMessage, Constants.OCPP_JSON_CALL_MESSAGE, 'BootNotification');
} catch (error) {
}
}
- async sendStatusNotification(connectorId: number, status: string, errorCode = 'NoError') {
+ async sendStatusNotification(connectorId: number, status: ChargePointStatus, errorCode = 'NoError'): Promise<void> {
+ this.getConnector(connectorId).status = status;
try {
const payload = {
connectorId,
this.getConnector(requestPayload.connectorId).transactionId = payload.transactionId;
this.getConnector(requestPayload.connectorId).idTag = requestPayload.idTag;
this.getConnector(requestPayload.connectorId).lastEnergyActiveImportRegisterValue = 0;
- this.sendStatusNotification(requestPayload.connectorId, 'Charging');
+ this.sendStatusNotification(requestPayload.connectorId, ChargePointStatus.CHARGING);
logger.info(this._logPrefix() + ' Transaction ' + payload.transactionId + ' STARTED on ' + this._stationInfo.name + '#' + requestPayload.connectorId + ' for idTag ' + requestPayload.idTag);
if (this._stationInfo.powerSharedByConnectors) {
this._stationInfo.powerDivider++;
} else {
logger.error(this._logPrefix() + ' Starting transaction id ' + payload.transactionId + ' REJECTED with status ' + payload.idTagInfo.status + ', idTag ' + requestPayload.idTag);
this._resetTransactionOnConnector(requestPayload.connectorId);
- this.sendStatusNotification(requestPayload.connectorId, 'Available');
+ this.sendStatusNotification(requestPayload.connectorId, ChargePointStatus.AVAILABLE);
}
}
return;
}
if (payload.idTagInfo && payload.idTagInfo.status === 'Accepted') {
- this.sendStatusNotification(transactionConnectorId, 'Available');
+ this.sendStatusNotification(transactionConnectorId, ChargePointStatus.AVAILABLE);
if (this._stationInfo.powerSharedByConnectors) {
this._stationInfo.powerDivider--;
}