X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fcharging-station%2FChargingStation.ts;h=7b98ed35858bd4c524cccb1af9222c0100e3922b;hb=ed6cfcff3ef6596cdf76c68f600effcb25dece72;hp=7853d10ed8fc6b5d3bc58737bd3172c20fb581c9;hpb=45c0ae82dee8cf065f6303c4853c8adfe239dee1;p=e-mobility-charging-stations-simulator.git diff --git a/src/charging-station/ChargingStation.ts b/src/charging-station/ChargingStation.ts index 7853d10e..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 { @@ -536,7 +539,6 @@ export default class ChargingStation { this.stopping = true; await this.stopMessageSequence(reason); this.closeWSConnection(); - this.wsConnectionRestarted = false; if (this.getEnableStatistics()) { this.performanceStatistics.stop(); } @@ -953,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, @@ -1327,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 { @@ -1337,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 @@ -1346,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(); } @@ -1745,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 @@ -1765,8 +1767,7 @@ export default class ChargingStation { } else if ( !this.getConnectorStatus(connectorId)?.status && (this.isChargingStationAvailable() === false || - (this.isChargingStationAvailable() === true && - this.isConnectorAvailable(connectorId) === false)) + this.isConnectorAvailable(connectorId) === false) ) { chargePointStatus = ChargePointStatus.UNAVAILABLE; } else if ( @@ -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()})` ); } }