X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fcharging-station%2FChargingStation.ts;h=7b98ed35858bd4c524cccb1af9222c0100e3922b;hb=ed6cfcff3ef6596cdf76c68f600effcb25dece72;hp=05ef9252e93b096d074cec55e565737451459a66;hpb=56eb297e60819adea5d3a1f419a872cc8d3b5284;p=e-mobility-charging-stations-simulator.git diff --git a/src/charging-station/ChargingStation.ts b/src/charging-station/ChargingStation.ts index 05ef9252..7b98ed35 100644 --- a/src/charging-station/ChargingStation.ts +++ b/src/charging-station/ChargingStation.ts @@ -216,7 +216,10 @@ export default class ChargingStation { } public isRegistered(): boolean { - return !this.isInUnknownState() && (this.isInAcceptedState() || this.isInPendingState()); + return ( + this.isInUnknownState() === false && + (this.isInAcceptedState() === true || this.isInPendingState() === true) + ); } public isChargingStationAvailable(): boolean { @@ -535,21 +538,7 @@ export default class ChargingStation { if (this.stopping === false) { this.stopping = true; await this.stopMessageSequence(reason); - for (const connectorId of this.connectors.keys()) { - if (connectorId > 0) { - await this.ocppRequestService.requestHandler< - StatusNotificationRequest, - StatusNotificationResponse - >(this, RequestCommand.STATUS_NOTIFICATION, { - connectorId, - status: ChargePointStatus.UNAVAILABLE, - errorCode: ChargePointErrorCode.NO_ERROR, - }); - this.getConnectorStatus(connectorId).status = null; - } - } this.closeWSConnection(); - this.wsConnectionRestarted = false; if (this.getEnableStatistics()) { this.performanceStatistics.stop(); } @@ -966,7 +955,7 @@ export default class ChargingStation { this.handleUnsupportedVersion(this.getOcppVersion()); break; } - if (this.stationInfo?.autoRegister) { + if (this.stationInfo?.autoRegister === true) { this.bootNotificationResponse = { currentTime: new Date().toISOString(), interval: this.getHeartbeatInterval() / 1000, @@ -1340,7 +1329,7 @@ export default class ChargingStation { logger.info( `${this.logPrefix()} Connection to OCPP server through ${this.wsConnectionUrl.toString()} succeeded` ); - if (!this.isRegistered()) { + if (this.isRegistered() === false) { // Send BootNotification let registrationRetryCount = 0; do { @@ -1350,7 +1339,7 @@ export default class ChargingStation { >(this, RequestCommand.BOOT_NOTIFICATION, this.bootNotificationRequest, { skipBufferingOnError: true, }); - if (!this.isRegistered()) { + if (this.isRegistered() === false) { this.getRegistrationMaxRetries() !== -1 && registrationRetryCount++; await Utils.sleep( this.bootNotificationResponse?.interval @@ -1359,12 +1348,12 @@ export default class ChargingStation { ); } } while ( - !this.isRegistered() && + this.isRegistered() === false && (registrationRetryCount <= this.getRegistrationMaxRetries() || this.getRegistrationMaxRetries() === -1) ); } - if (this.isRegistered()) { + if (this.isRegistered() === true) { if (this.isInAcceptedState()) { await this.startMessageSequence(); } @@ -1758,7 +1747,7 @@ export default class ChargingStation { } private async startMessageSequence(): Promise { - if (this.stationInfo?.autoRegister) { + if (this.stationInfo?.autoRegister === true) { await this.ocppRequestService.requestHandler< BootNotificationRequest, BootNotificationResponse @@ -1777,17 +1766,16 @@ export default class ChargingStation { continue; } else if ( !this.getConnectorStatus(connectorId)?.status && - this.getConnectorStatus(connectorId)?.bootStatus + (this.isChargingStationAvailable() === false || + this.isConnectorAvailable(connectorId) === false) ) { - // Set boot status in template at startup - chargePointStatus = this.getConnectorStatus(connectorId).bootStatus; + chargePointStatus = ChargePointStatus.UNAVAILABLE; } else if ( !this.getConnectorStatus(connectorId)?.status && - (this.isChargingStationAvailable() === false || - (this.isChargingStationAvailable() === true && - this.isConnectorAvailable(connectorId) === false)) + this.getConnectorStatus(connectorId)?.bootStatus ) { - chargePointStatus = ChargePointStatus.UNAVAILABLE; + // Set boot status in template at startup + chargePointStatus = this.getConnectorStatus(connectorId).bootStatus; } else if (this.getConnectorStatus(connectorId)?.status) { // Set previous status at startup chargePointStatus = this.getConnectorStatus(connectorId).status; @@ -1825,6 +1813,19 @@ export default class ChargingStation { } else { await this.stopRunningTransactions(reason); } + for (const connectorId of this.connectors.keys()) { + if (connectorId > 0) { + await this.ocppRequestService.requestHandler< + StatusNotificationRequest, + StatusNotificationResponse + >(this, RequestCommand.STATUS_NOTIFICATION, { + connectorId, + status: ChargePointStatus.UNAVAILABLE, + errorCode: ChargePointErrorCode.NO_ERROR, + }); + this.getConnectorStatus(connectorId).status = null; + } + } } private startWebSocketPing(): void { @@ -1855,9 +1856,8 @@ export default class ChargingStation { } else if (this.webSocketPingSetInterval) { logger.info( this.logPrefix() + - ' WebSocket ping every ' + - Utils.formatDurationSeconds(webSocketPingInterval) + - ' already started' + ' WebSocket ping already started every ' + + Utils.formatDurationSeconds(webSocketPingInterval) ); } else { logger.error( @@ -1923,7 +1923,7 @@ export default class ChargingStation { if (HeartBeatInterval) { return Utils.convertToInt(HeartBeatInterval.value) * 1000; } - !this.stationInfo?.autoRegister && + this.stationInfo?.autoRegister === false && logger.warn( `${this.logPrefix()} Heartbeat interval configuration key not set, using default value: ${ Constants.DEFAULT_HEARTBEAT_INTERVAL @@ -1980,16 +1980,14 @@ export default class ChargingStation { ? reconnectDelay - reconnectDelayWithdraw : 0; logger.error( - `${this.logPrefix()} WebSocket: connection retry in ${Utils.roundTo( + `${this.logPrefix()} WebSocket connection retry in ${Utils.roundTo( reconnectDelay, 2 )}ms, timeout ${reconnectTimeout}ms` ); await Utils.sleep(reconnectDelay); logger.error( - this.logPrefix() + - ' WebSocket: reconnecting try #' + - this.autoReconnectRetryCount.toString() + this.logPrefix() + ' WebSocket connection retry #' + this.autoReconnectRetryCount.toString() ); this.openWSConnection( { ...(this.stationInfo?.wsOptions ?? {}), handshakeTimeout: reconnectTimeout }, @@ -1998,9 +1996,9 @@ export default class ChargingStation { this.wsConnectionRestarted = true; } else if (this.getAutoReconnectMaxRetries() !== -1) { logger.error( - `${this.logPrefix()} WebSocket reconnect failure: maximum retries reached (${ + `${this.logPrefix()} WebSocket connection retries failure: maximum retries reached (${ this.autoReconnectRetryCount - }) or retry disabled (${this.getAutoReconnectMaxRetries()})` + }) or retries disabled (${this.getAutoReconnectMaxRetries()})` ); } }