if (reservationFound != null) {
await this.removeReservation(reservationFound, ReservationTerminationReason.REPLACE_EXISTING)
}
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
- this.getConnectorStatus(reservation.connectorId)!.reservation = reservation
+ const connectorStatus = this.getConnectorStatus(reservation.connectorId)
+ if (connectorStatus == null) {
+ logger.error(
+ `${this.logPrefix()} No connector ${reservation.connectorId.toString()} found during reservation ${reservation.reservationId.toString()} addition`
+ )
+ return
+ }
+ connectorStatus.reservation = reservation
await sendAndSetConnectorStatus(
this,
reservation.connectorId,
}
public closeWSConnection (): void {
- if (this.isWebSocketConnectionOpened()) {
- this.wsConnection?.close()
+ if (this.wsConnection != null) {
+ if (this.isWebSocketConnectionOpened()) {
+ this.wsConnection.close()
+ }
this.wsConnection = null
}
}
}
AutomaticTransactionGenerator.deleteInstance(this)
PerformanceStatistics.deleteInstance(this.stationInfo?.hashId)
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
- this.idTagsCache.deleteIdTags(getIdTagsFile(this.stationInfo!)!)
+ if (this.stationInfo != null) {
+ const idTagsFile = getIdTagsFile(this.stationInfo)
+ if (idTagsFile != null) {
+ this.idTagsCache.deleteIdTags(idTagsFile)
+ } else {
+ logger.warn(`${this.logPrefix()} No ID tags file found during deletion`)
+ }
+ } else {
+ logger.warn(`${this.logPrefix()} No station info available during deletion`)
+ }
this.requests.clear()
this.connectors.clear()
this.evses.clear()
+ this.messageQueue.length = 0
this.templateFileWatcher?.unref()
- deleteConfiguration && rmSync(this.configurationFile, { force: true })
+ if (deleteConfiguration && existsSync(this.configurationFile)) {
+ try {
+ rmSync(this.configurationFile, { force: true })
+ } catch (error) {
+ logger.error(
+ `${this.logPrefix()} Failed to delete configuration file ${this.configurationFile}:`,
+ error
+ )
+ }
+ }
this.chargingStationWorkerBroadcastChannel.unref()
this.emitChargingStationEvent(ChargingStationEvents.deleted)
this.removeAllListeners()
if (templateMaxEvses > 0) {
for (const evseKey in stationTemplate.Evses) {
const evseId = convertToInt(evseKey)
- this.evses.set(evseId, {
+ const evseStatus: EvseStatus = {
availability: AvailabilityType.Operative,
connectors: buildConnectorsMap(
stationTemplate.Evses[evseKey].Connectors,
this.logPrefix(),
this.templateFile
),
- })
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
- initializeConnectorsMapStatus(this.evses.get(evseId)!.connectors, this.logPrefix())
+ }
+ this.evses.set(evseId, evseStatus)
+ initializeConnectorsMapStatus(evseStatus.connectors, this.logPrefix())
}
this.saveEvsesStatus()
} else {
beginId = PerformanceStatistics.beginMeasure(commandName)
}
this.wsConnection?.send(message, (error?: Error) => {
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
- isRequest && PerformanceStatistics.endMeasure(commandName!, beginId!)
+ if (isRequest && commandName != null && beginId != null) {
+ PerformanceStatistics.endMeasure(commandName, beginId)
+ }
if (error == null) {
logger.debug(
`${this.logPrefix()} >> Buffered ${getMessageTypeString(messageType)} OCPP message sent '${message}'`
this.messageQueue.shift()
} else {
logger.error(
- `${this.logPrefix()} >> Buffered ${getMessageTypeString(messageType)} OCPP message '${message}' send failed:`,
+ `${this.logPrefix()} Error while sending buffered ${getMessageTypeString(messageType)} OCPP message '${message}':`,
error
)
}
// eslint-disable-next-line promise/no-promise-in-callback
sleep(exponentialDelay(messageIdx))
.then(() => {
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
- ++messageIdx!
+ if (messageIdx != null) {
+ ++messageIdx
+ }
this.sendMessageBuffer(onCompleteCallback, messageIdx)
return undefined
})
} else {
for (const connectorId of this.connectors.keys()) {
if (connectorId > 0) {
+ const connectorStatus = this.getConnectorStatus(connectorId)
+ if (connectorStatus == null) {
+ logger.error(
+ `${this.logPrefix()} No connector ${connectorId.toString()} status found during message sequence start`
+ )
+ continue
+ }
await sendAndSetConnectorStatus(
this,
connectorId,
- getBootConnectorStatus(
- this,
- connectorId,
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
- this.getConnectorStatus(connectorId)!
- )
+ getBootConnectorStatus(this, connectorId, connectorStatus)
)
}
}