repositories
/
e-mobility-charging-stations-simulator.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
refactor: cleanup unneeded type casting
[e-mobility-charging-stations-simulator.git]
/
src
/
charging-station
/
ocpp
/
1.6
/
OCPP16IncomingRequestService.ts
diff --git
a/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts
b/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts
index 3e371e8251317646887eb92983fe7ef1b0d29a21..f934d418e6161600982b53d0ec7fb2a034682a6e 100644
(file)
--- a/
src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts
+++ b/
src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts
@@
-1,4
+1,4
@@
-// Partial Copyright Jerome Benoit. 2021-202
3
. All Rights Reserved.
+// Partial Copyright Jerome Benoit. 2021-202
4
. All Rights Reserved.
import { createWriteStream, readdirSync } from 'node:fs'
import { dirname, join, resolve } from 'node:path'
import { createWriteStream, readdirSync } from 'node:fs'
import { dirname, join, resolve } from 'node:path'
@@
-332,11
+332,7
@@
export class OCPP16IncomingRequestService extends OCPPIncomingRequestService {
)
]
])
)
]
])
- this.validatePayload = this.validatePayload.bind(this) as (
- chargingStation: ChargingStation,
- commandName: OCPP16IncomingRequestCommand,
- commandPayload: JsonType
- ) => boolean
+ this.validatePayload = this.validatePayload.bind(this)
}
public async incomingRequestHandler<ReqType extends JsonType, ResType extends JsonType>(
}
public async incomingRequestHandler<ReqType extends JsonType, ResType extends JsonType>(
@@
-726,10
+722,9
@@
export class OCPP16IncomingRequestService extends OCPPIncomingRequestService {
chargingProfile.chargingProfileId
} startSchedule property is not a Date instance. Trying to convert it to a Date instance`
)
chargingProfile.chargingProfileId
} startSchedule property is not a Date instance. Trying to convert it to a Date instance`
)
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
chargingProfile.chargingSchedule.startSchedule = convertToDate(
chargingProfile.chargingSchedule.startSchedule
chargingProfile.chargingSchedule.startSchedule = convertToDate(
chargingProfile.chargingSchedule.startSchedule
- )
!
+ )
}
if (chargingProfile.chargingSchedule.duration == null) {
logger.debug(
}
if (chargingProfile.chargingSchedule.duration == null) {
logger.debug(
@@
-740,7
+735,8
@@
export class OCPP16IncomingRequestService extends OCPPIncomingRequestService {
// OCPP specifies that if duration is not defined, it should be infinite
chargingProfile.chargingSchedule.duration = differenceInSeconds(
maxTime,
// OCPP specifies that if duration is not defined, it should be infinite
chargingProfile.chargingSchedule.duration = differenceInSeconds(
maxTime,
- chargingProfile.chargingSchedule.startSchedule
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+ chargingProfile.chargingSchedule.startSchedule!
)
}
if (
)
}
if (
@@
-772,8
+768,7
@@
export class OCPP16IncomingRequestService extends OCPPIncomingRequestService {
if (compositeSchedule != null) {
return {
status: GenericStatus.Accepted,
if (compositeSchedule != null) {
return {
status: GenericStatus.Accepted,
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
- scheduleStart: compositeSchedule.startSchedule!,
+ scheduleStart: compositeSchedule.startSchedule,
connectorId,
chargingSchedule: compositeSchedule
}
connectorId,
chargingSchedule: compositeSchedule
}
@@
-805,8
+800,7
@@
export class OCPP16IncomingRequestService extends OCPPIncomingRequestService {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const connectorStatus = chargingStation.getConnectorStatus(connectorId!)
if (connectorId != null && isNotEmptyArray(connectorStatus?.chargingProfiles)) {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const connectorStatus = chargingStation.getConnectorStatus(connectorId!)
if (connectorId != null && isNotEmptyArray(connectorStatus?.chargingProfiles)) {
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
- connectorStatus!.chargingProfiles = []
+ connectorStatus.chargingProfiles = []
logger.debug(
`${chargingStation.logPrefix()} Charging profile(s) cleared on connector id ${connectorId}`
)
logger.debug(
`${chargingStation.logPrefix()} Charging profile(s) cleared on connector id ${connectorId}`
)
@@
-922,8
+916,9
@@
export class OCPP16IncomingRequestService extends OCPPIncomingRequestService {
)
}
const remoteStartTransactionLogMsg = `
)
}
const remoteStartTransactionLogMsg = `
- ${chargingStation.logPrefix()} Transaction remotely STARTED on ${chargingStation.stationInfo
- ?.chargingStationId}#${transactionConnectorId} for idTag '${idTag}'`
+ ${chargingStation.logPrefix()} Transaction remotely STARTED on ${
+ chargingStation.stationInfo?.chargingStationId
+ }#${transactionConnectorId} for idTag '${idTag}'`
await OCPP16ServiceUtils.sendAndSetConnectorStatus(
chargingStation,
transactionConnectorId,
await OCPP16ServiceUtils.sendAndSetConnectorStatus(
chargingStation,
transactionConnectorId,
@@
-1098,15
+1093,15
@@
export class OCPP16IncomingRequestService extends OCPPIncomingRequestService {
)
return OCPP16Constants.OCPP_RESPONSE_EMPTY
}
)
return OCPP16Constants.OCPP_RESPONSE_EMPTY
}
- let { retrieveDate } = commandPayload
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+ commandPayload.retrieveDate = convertToDate(commandPayload.retrieveDate)!
+ const { retrieveDate } = commandPayload
if (chargingStation.stationInfo?.firmwareStatus !== OCPP16FirmwareStatus.Installed) {
logger.warn(
`${chargingStation.logPrefix()} ${moduleName}.handleRequestUpdateFirmware: Cannot simulate firmware update: firmware update is already in progress`
)
return OCPP16Constants.OCPP_RESPONSE_EMPTY
}
if (chargingStation.stationInfo?.firmwareStatus !== OCPP16FirmwareStatus.Installed) {
logger.warn(
`${chargingStation.logPrefix()} ${moduleName}.handleRequestUpdateFirmware: Cannot simulate firmware update: firmware update is already in progress`
)
return OCPP16Constants.OCPP_RESPONSE_EMPTY
}
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
- retrieveDate = convertToDate(retrieveDate)!
const now = Date.now()
if (retrieveDate.getTime() <= now) {
this.updateFirmwareSimulation(chargingStation).catch(Constants.EMPTY_FUNCTION)
const now = Date.now()
if (retrieveDate.getTime() <= now) {
this.updateFirmwareSimulation(chargingStation).catch(Constants.EMPTY_FUNCTION)
@@
-1289,8
+1284,8
@@
export class OCPP16IncomingRequestService extends OCPPIncomingRequestService {
let ftpClient: Client | undefined
try {
const logFiles = readdirSync(resolve(dirname(fileURLToPath(import.meta.url)), '../'))
let ftpClient: Client | undefined
try {
const logFiles = readdirSync(resolve(dirname(fileURLToPath(import.meta.url)), '../'))
- .filter(
(file)
=> file.endsWith('.log'))
- .map(
(file)
=> join('./', file))
+ .filter(
file
=> file.endsWith('.log'))
+ .map(
file
=> join('./', file))
const diagnosticsArchive = `${chargingStation.stationInfo?.chargingStationId}_logs.tar.gz`
create({ gzip: true }, logFiles).pipe(createWriteStream(diagnosticsArchive))
ftpClient = new Client()
const diagnosticsArchive = `${chargingStation.stationInfo?.chargingStationId}_logs.tar.gz`
create({ gzip: true }, logFiles).pipe(createWriteStream(diagnosticsArchive))
ftpClient = new Client()
@@
-1302,7
+1297,7
@@
export class OCPP16IncomingRequestService extends OCPPIncomingRequestService {
})
let uploadResponse: FTPResponse | undefined
if (accessResponse.code === 220) {
})
let uploadResponse: FTPResponse | undefined
if (accessResponse.code === 220) {
- ftpClient.trackProgress(
(info)
=> {
+ ftpClient.trackProgress(
info
=> {
logger.info(
`${chargingStation.logPrefix()} ${moduleName}.handleRequestGetDiagnostics: ${
info.bytes / 1024
logger.info(
`${chargingStation.logPrefix()} ${moduleName}.handleRequestGetDiagnostics: ${
info.bytes / 1024
@@
-1315,7
+1310,7
@@
export class OCPP16IncomingRequestService extends OCPPIncomingRequestService {
>(chargingStation, OCPP16RequestCommand.DIAGNOSTICS_STATUS_NOTIFICATION, {
status: OCPP16DiagnosticsStatus.Uploading
})
>(chargingStation, OCPP16RequestCommand.DIAGNOSTICS_STATUS_NOTIFICATION, {
status: OCPP16DiagnosticsStatus.Uploading
})
- .catch(
(error)
=> {
+ .catch(
error
=> {
logger.error(
`${chargingStation.logPrefix()} ${moduleName}.handleRequestGetDiagnostics: Error while sending '${
OCPP16RequestCommand.DIAGNOSTICS_STATUS_NOTIFICATION
logger.error(
`${chargingStation.logPrefix()} ${moduleName}.handleRequestGetDiagnostics: Error while sending '${
OCPP16RequestCommand.DIAGNOSTICS_STATUS_NOTIFICATION
@@
-1417,7
+1412,7
@@
export class OCPP16IncomingRequestService extends OCPPIncomingRequestService {
chargingStation.bootNotificationRequest,
{ skipBufferingOnError: true, triggerMessage: true }
)
chargingStation.bootNotificationRequest,
{ skipBufferingOnError: true, triggerMessage: true }
)
- .then(
(response)
=> {
+ .then(
response
=> {
chargingStation.bootNotificationResponse = response
})
.catch(Constants.EMPTY_FUNCTION)
chargingStation.bootNotificationResponse = response
})
.catch(Constants.EMPTY_FUNCTION)
@@
-1547,6
+1542,8
@@
export class OCPP16IncomingRequestService extends OCPPIncomingRequestService {
) {
return OCPP16Constants.OCPP_RESERVATION_RESPONSE_REJECTED
}
) {
return OCPP16Constants.OCPP_RESERVATION_RESPONSE_REJECTED
}
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+ commandPayload.expiryDate = convertToDate(commandPayload.expiryDate)!
const { reservationId, idTag, connectorId } = commandPayload
let response: OCPP16ReserveNowResponse
try {
const { reservationId, idTag, connectorId } = commandPayload
let response: OCPP16ReserveNowResponse
try {