return numberOfRunningTransactions
}
- public getConnectorIdByTransactionId (transactionId: number): number | undefined {
- if (this.hasEvses) {
+ public getConnectorIdByTransactionId (transactionId: number | undefined): number | undefined {
+ if (transactionId == null) {
+ return undefined
+ } else if (this.hasEvses) {
for (const evseStatus of this.evses.values()) {
for (const [connectorId, connectorStatus] of evseStatus.connectors) {
if (connectorStatus.transactionId === transactionId) {
}
public getEnergyActiveImportRegisterByTransactionId (
- transactionId: number,
+ transactionId: number | undefined,
rounded = false
): number {
return this.getEnergyActiveImportRegister(
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
- this.getConnectorStatus(this.getConnectorIdByTransactionId(transactionId)!)!,
+ this.getConnectorStatus(this.getConnectorIdByTransactionId(transactionId)!),
rounded
)
}
public getEnergyActiveImportRegisterByConnectorId (connectorId: number, rounded = false): number {
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
- return this.getEnergyActiveImportRegister(this.getConnectorStatus(connectorId)!, rounded)
+ return this.getEnergyActiveImportRegister(this.getConnectorStatus(connectorId), rounded)
}
public getAuthorizeRemoteTxRequests (): boolean {
logger.error(`${this.logPrefix()} Trying to start MeterValues on connector id ${connectorId}`)
return
}
- if (this.getConnectorStatus(connectorId) == null) {
+ const connectorStatus = this.getConnectorStatus(connectorId)
+ if (connectorStatus == null) {
logger.error(
`${this.logPrefix()} Trying to start MeterValues on non existing connector id
${connectorId}`
)
return
}
- if (this.getConnectorStatus(connectorId)?.transactionStarted === false) {
+ if (connectorStatus.transactionStarted === false) {
logger.error(
`${this.logPrefix()} Trying to start MeterValues on connector id ${connectorId} with no transaction started`
)
return
} else if (
- this.getConnectorStatus(connectorId)?.transactionStarted === true &&
- this.getConnectorStatus(connectorId)?.transactionId == null
+ connectorStatus.transactionStarted === true &&
+ connectorStatus.transactionId == null
) {
logger.error(
`${this.logPrefix()} Trying to start MeterValues on connector id ${connectorId} with no transaction id`
return
}
if (interval > 0) {
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
- this.getConnectorStatus(connectorId)!.transactionSetInterval = setInterval(() => {
+ connectorStatus.transactionSetInterval = setInterval(() => {
const meterValue = buildMeterValue(
this,
connectorId,
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
- this.getConnectorStatus(connectorId)!.transactionId!,
+ connectorStatus.transactionId!,
interval
)
this.ocppRequestService
RequestCommand.METER_VALUES,
{
connectorId,
- transactionId: this.getConnectorStatus(connectorId)?.transactionId,
+ transactionId: connectorStatus.transactionId,
meterValue: [meterValue]
}
)
}
public stopMeterValues (connectorId: number): void {
- if (this.getConnectorStatus(connectorId)?.transactionSetInterval != null) {
- clearInterval(this.getConnectorStatus(connectorId)?.transactionSetInterval)
+ const connectorStatus = this.getConnectorStatus(connectorId)
+ if (connectorStatus?.transactionSetInterval != null) {
+ clearInterval(connectorStatus.transactionSetInterval)
}
}
connectorId: number,
reason?: StopTransactionReason
): Promise<StopTransactionResponse> {
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
- const transactionId = this.getConnectorStatus(connectorId)!.transactionId!
+ const transactionId = this.getConnectorStatus(connectorId)?.transactionId
if (
this.stationInfo?.beginEndMeterValues === true &&
this.stationInfo.ocppStrictCompliance === true &&
logger.error(`${this.logPrefix()} WebSocket error:`, error)
}
- private getEnergyActiveImportRegister (connectorStatus: ConnectorStatus, rounded = false): number {
+ private getEnergyActiveImportRegister (
+ connectorStatus: ConnectorStatus | undefined,
+ rounded = false
+ ): number {
if (this.stationInfo?.meteringPerTransaction === true) {
return (
(rounded
- ? // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
- Math.round(connectorStatus.transactionEnergyActiveImportRegisterValue!)
- : connectorStatus.transactionEnergyActiveImportRegisterValue) ?? 0
+ ? connectorStatus?.transactionEnergyActiveImportRegisterValue != null
+ ? Math.round(connectorStatus.transactionEnergyActiveImportRegisterValue)
+ : undefined
+ : connectorStatus?.transactionEnergyActiveImportRegisterValue) ?? 0
)
}
return (
(rounded
- ? // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
- Math.round(connectorStatus.energyActiveImportRegisterValue!)
- : connectorStatus.energyActiveImportRegisterValue) ?? 0
+ ? connectorStatus?.energyActiveImportRegisterValue != null
+ ? Math.round(connectorStatus.energyActiveImportRegisterValue)
+ : undefined
+ : connectorStatus?.energyActiveImportRegisterValue) ?? 0
)
}
}
}
-export const resetConnectorStatus = (connectorStatus: ConnectorStatus): void => {
+export const resetConnectorStatus = (connectorStatus: ConnectorStatus | undefined): void => {
+ if (connectorStatus == null) {
+ return
+ }
connectorStatus.chargingProfiles =
connectorStatus.transactionId != null && isNotEmptyArray(connectorStatus.chargingProfiles)
? connectorStatus.chargingProfiles?.filter(
): ChargingProfilesLimit | undefined => {
const debugLogMsg = `${logPrefix} ${moduleName}.getLimitFromChargingProfiles: Matching charging profile found for power limitation: %j`
const currentDate = new Date()
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
- const connectorStatus = chargingStation.getConnectorStatus(connectorId)!
+ const connectorStatus = chargingStation.getConnectorStatus(connectorId)
for (const chargingProfile of chargingProfiles) {
const chargingSchedule = chargingProfile.chargingSchedule
if (chargingSchedule.startSchedule == null) {
`${logPrefix} ${moduleName}.getLimitFromChargingProfiles: Charging profile id ${chargingProfile.chargingProfileId} has no startSchedule defined. Trying to set it to the connector current transaction start date`
)
// OCPP specifies that if startSchedule is not defined, it should be relative to start of the connector transaction
- chargingSchedule.startSchedule = connectorStatus.transactionStart
+ chargingSchedule.startSchedule = connectorStatus?.transactionStart
}
if (!isDate(chargingSchedule.startSchedule)) {
logger.warn(
}
export const prepareChargingProfileKind = (
- connectorStatus: ConnectorStatus,
+ connectorStatus: ConnectorStatus | undefined,
chargingProfile: ChargingProfile,
currentDate: string | number | Date,
logPrefix: string
)
delete chargingProfile.chargingSchedule.startSchedule
}
- if (connectorStatus.transactionStarted === true) {
+ if (connectorStatus?.transactionStarted === true) {
chargingProfile.chargingSchedule.startSchedule = connectorStatus.transactionStart
}
// FIXME: Handle relative charging profile duration
RequestCommand.STOP_TRANSACTION,
{
meterStop: this.chargingStation.getEnergyActiveImportRegisterByTransactionId(
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
- requestPayload!.transactionId!,
+ requestPayload?.transactionId,
true
),
...requestPayload
`${chargingStation.logPrefix()} Get composite schedule with a specified rate unit is not yet supported, no conversion will be done`
)
}
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
- const connectorStatus = chargingStation.getConnectorStatus(connectorId)!
+ const connectorStatus = chargingStation.getConnectorStatus(connectorId)
if (
- isEmptyArray(connectorStatus.chargingProfiles) &&
+ isEmptyArray(connectorStatus?.chargingProfiles) &&
isEmptyArray(chargingStation.getConnectorStatus(0)?.chargingProfiles)
) {
return OCPP16Constants.OCPP_RESPONSE_REJECTED
} has no startSchedule defined. Trying to set it to the connector current transaction start date`
)
// OCPP specifies that if startSchedule is not defined, it should be relative to start of the connector transaction
- chargingProfile.chargingSchedule.startSchedule = connectorStatus.transactionStart
+ chargingProfile.chargingSchedule.startSchedule = connectorStatus?.transactionStart
}
if (!isDate(chargingProfile.chargingSchedule.startSchedule)) {
logger.warn(
? OCPP16ChargePointStatus.Available
: OCPP16ChargePointStatus.Unavailable
if (connectorId === 0) {
- let response: OCPP16ChangeAvailabilityResponse
+ let response: OCPP16ChangeAvailabilityResponse | undefined
if (chargingStation.hasEvses) {
for (const evseStatus of chargingStation.evses.values()) {
response = await OCPP16ServiceUtils.changeAvailability(
}
)
.catch(Constants.EMPTY_FUNCTION)
- } else {
- if (chargingStation.hasEvses) {
- for (const evseStatus of chargingStation.evses.values()) {
- for (const [id, connectorStatus] of evseStatus.connectors) {
- chargingStation.ocppRequestService
- .requestHandler<
- OCPP16StatusNotificationRequest,
- OCPP16StatusNotificationResponse
- >(
- chargingStation,
- OCPP16RequestCommand.STATUS_NOTIFICATION,
- {
- connectorId: id,
- errorCode: OCPP16ChargePointErrorCode.NO_ERROR,
- status: connectorStatus.status
- },
- {
- triggerMessage: true
- }
- )
- .catch(Constants.EMPTY_FUNCTION)
- }
- }
- } else {
- for (const id of chargingStation.connectors.keys()) {
+ } else if (chargingStation.hasEvses) {
+ for (const evseStatus of chargingStation.evses.values()) {
+ for (const [id, connectorStatus] of evseStatus.connectors) {
chargingStation.ocppRequestService
.requestHandler<
OCPP16StatusNotificationRequest,
{
connectorId: id,
errorCode: OCPP16ChargePointErrorCode.NO_ERROR,
- status: chargingStation.getConnectorStatus(id)?.status
+ status: connectorStatus.status
},
{
triggerMessage: true
.catch(Constants.EMPTY_FUNCTION)
}
}
+ } else {
+ for (const [id, connectorStatus] of chargingStation.connectors) {
+ chargingStation.ocppRequestService
+ .requestHandler<
+ OCPP16StatusNotificationRequest,
+ OCPP16StatusNotificationResponse
+ >(
+ chargingStation,
+ OCPP16RequestCommand.STATUS_NOTIFICATION,
+ {
+ connectorId: id,
+ errorCode: OCPP16ChargePointErrorCode.NO_ERROR,
+ status: connectorStatus.status
+ },
+ {
+ triggerMessage: true
+ }
+ )
+ .catch(Constants.EMPTY_FUNCTION)
+ }
}
}, OCPP16Constants.OCPP_TRIGGER_MESSAGE_DELAY)
return OCPP16Constants.OCPP_TRIGGER_MESSAGE_RESPONSE_ACCEPTED
return OCPP16Constants.OCPP_RESERVATION_RESPONSE_REJECTED
}
await removeExpiredReservations(chargingStation)
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
- switch (chargingStation.getConnectorStatus(connectorId)!.status) {
+ switch (chargingStation.getConnectorStatus(connectorId)?.status) {
case OCPP16ChargePointStatus.Faulted:
response = OCPP16Constants.OCPP_RESERVATION_RESPONSE_FAULTED
break
} as unknown as Request
case OCPP16RequestCommand.STOP_TRANSACTION:
chargingStation.stationInfo?.transactionDataMeterValues === true &&
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
(connectorId = chargingStation.getConnectorIdByTransactionId(
commandParams.transactionId as number
- )!)
+ ))
energyActiveImportRegister = chargingStation.getEnergyActiveImportRegisterByTransactionId(
commandParams.transactionId as number,
true
}
}
}
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
- const authorizeConnectorStatus = chargingStation.getConnectorStatus(authorizeConnectorId!)
- const authorizeConnectorIdDefined = authorizeConnectorId != null
- if (payload.idTagInfo.status === OCPP16AuthorizationStatus.ACCEPTED) {
- if (authorizeConnectorIdDefined) {
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
- authorizeConnectorStatus!.idTagAuthorized = true
+ if (authorizeConnectorId != null) {
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+ const authorizeConnectorStatus = chargingStation.getConnectorStatus(authorizeConnectorId)!
+ if (payload.idTagInfo.status === OCPP16AuthorizationStatus.ACCEPTED) {
+ authorizeConnectorStatus.idTagAuthorized = true
+ logger.debug(
+ `${chargingStation.logPrefix()} idTag '${
+ requestPayload.idTag
+ }' accepted on connector id ${authorizeConnectorId}`
+ )
+ } else {
+ authorizeConnectorStatus.idTagAuthorized = false
+ delete authorizeConnectorStatus.authorizeIdTag
+ logger.debug(
+ `${chargingStation.logPrefix()} idTag '${requestPayload.idTag}' rejected with status '${
+ payload.idTagInfo.status
+ }`
+ )
}
- logger.debug(
- `${chargingStation.logPrefix()} idTag '${requestPayload.idTag}' accepted${
- authorizeConnectorIdDefined ? ` on connector id ${authorizeConnectorId}` : ''
- }`
- )
} else {
- if (authorizeConnectorIdDefined) {
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
- authorizeConnectorStatus!.idTagAuthorized = false
- delete authorizeConnectorStatus?.authorizeIdTag
- }
- logger.debug(
- `${chargingStation.logPrefix()} idTag '${requestPayload.idTag}' rejected with status '${
- payload.idTagInfo.status
- }'${authorizeConnectorIdDefined ? ` on connector id ${authorizeConnectorId}` : ''}`
+ logger.error(
+ `${chargingStation.logPrefix()} idTag '${
+ requestPayload.idTag
+ }' has no authorize request pending`
)
}
}
connectorId: number
): Promise<void> {
const connectorStatus = chargingStation.getConnectorStatus(connectorId)
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
- resetConnectorStatus(connectorStatus!)
+ resetConnectorStatus(connectorStatus)
chargingStation.stopMeterValues(connectorId)
if (connectorStatus?.status !== OCPP16ChargePointStatus.Available) {
await OCPP16ServiceUtils.sendAndSetConnectorStatus(
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
chargingStation.powerDivider!--
}
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
- resetConnectorStatus(chargingStation.getConnectorStatus(transactionConnectorId)!)
+ resetConnectorStatus(chargingStation.getConnectorStatus(transactionConnectorId))
chargingStation.stopMeterValues(transactionConnectorId)
const logMsg = `${chargingStation.logPrefix()} Transaction with id ${
requestPayload.transactionId
`${chargingStation.logPrefix()} The charging station expects to authorize RFID tags but nor local authorization nor remote authorization are enabled. Misbehavior may occur`
)
}
- if (chargingStation.getLocalAuthListEnabled() && isIdTagLocalAuthorized(chargingStation, idTag)) {
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
- const connectorStatus = chargingStation.getConnectorStatus(connectorId)!
+ const connectorStatus = chargingStation.getConnectorStatus(connectorId)
+ if (
+ connectorStatus != null &&
+ chargingStation.getLocalAuthListEnabled() &&
+ isIdTagLocalAuthorized(chargingStation, idTag)
+ ) {
connectorStatus.localAuthorizeIdTag = idTag
connectorStatus.idTagLocalAuthorized = true
return true
connectorId: number,
status: ConnectorStatusEnum
): boolean => {
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
- const fromStatus = chargingStation.getConnectorStatus(connectorId)!.status
+ const fromStatus = chargingStation.getConnectorStatus(connectorId)?.status
let transitionAllowed = false
switch (chargingStation.stationInfo?.ocppVersion) {
case OCPPVersion.VERSION_16:
logger.warn(
`${chargingStation.logPrefix()} OCPP ${
chargingStation.stationInfo.ocppVersion
- } connector id ${connectorId} status transition from '${
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
- chargingStation.getConnectorStatus(connectorId)!.status
- }' to '${status}' is not allowed`
+ } connector id ${connectorId} status transition from '${chargingStation.getConnectorStatus(
+ connectorId
+ )?.status}' to '${status}' is not allowed`
)
}
return transitionAllowed