Fixed potential NPE on getting connector
MODIFY
src/integration/charging-station-vendor/ChargingStationVendorIntegration.ts
src/integration/charging-station-vendor/ChargingStationVendorIntegration.ts
@@ -136,6 +136,7 @@ export default abstract class ChargingStationVendorIntegration {
// Update the connector limit amps
for (const connectorID of chargePoint.connectorIDs) {
const connector = Utils.getConnectorFromID(chargingStation, connectorID);
+ if (connector) {
connector.amperageLimit = this.convertLimitAmpToAllPhases(
chargingStation, chargePoint, connectorID, Utils.convertToInt(ocppParamValue));
Logging.logInfo({
@@ -150,6 +151,7 @@ export default abstract class ChargingStationVendorIntegration {
}
});
}
+ }
// Save it
await ChargingStationStorage.saveChargingStation(tenantID, chargingStation);
}

MODIFY
src/server/ocpp/utils/OCPPUtils.ts
src/server/ocpp/utils/OCPPUtils.ts
@@ -888,7 +888,7 @@ export default class OCPPUtils {
if (chargingStationVendor) {
// Get current limitation
const connector = Utils.getConnectorFromID(chargingStation, connectorID);
- const chargePoint = Utils.getChargePointFromID(chargingStation, connector.chargePointID);
+ const chargePoint = Utils.getChargePointFromID(chargingStation, connector?.chargePointID);
const connectorLimit = await chargingStationVendor.getCurrentConnectorLimit(
tenantID, chargingStation, chargePoint, connectorID);
consumption.limitAmps = connectorLimit.limitAmps;
@@ -897,8 +897,8 @@ export default class OCPPUtils {
} else {
// Default
const connector = Utils.getConnectorFromID(chargingStation, connectorID);
- consumption.limitAmps = connector.amperageLimit;
- consumption.limitWatts = connector.power;
+ consumption.limitAmps = connector?.amperageLimit;
+ consumption.limitWatts = connector?.power;
consumption.limitSource = ConnectorCurrentLimitSource.CONNECTOR;
}
}

MODIFY
src/server/rest/service/ChargingStationService.ts
src/server/rest/service/ChargingStationService.ts
@@ -1087,7 +1087,7 @@ export default class ChargingStationService {
} else {
// Connector ID > 0
const connector = Utils.getConnectorFromID(chargingStation, filteredRequest.args.connectorId);
- const chargePoint = Utils.getChargePointFromID(chargingStation, connector.chargePointID);
+ const chargePoint = Utils.getChargePointFromID(chargingStation, connector?.chargePointID);
result = await chargingStationVendor.getCompositeSchedule(
req.user.tenantID, chargingStation, chargePoint, filteredRequest.args.connectorId, filteredRequest.args.duration);
}

MODIFY
src/utils/Utils.ts
src/utils/Utils.ts
@@ -112,6 +112,7 @@ export default class Utils {
return 0;
}
const connector = Utils.getConnectorFromID(chargingStation, connectorId);
+ if (connector) {
if (connector.power <= 3680) {
// Notify every 120 mins
intervalMins = 120;
@@ -125,6 +126,7 @@ export default class Utils {
// Notify every 15 mins
intervalMins = 15;
}
+ }
return intervalMins;
}
@@ -670,7 +672,7 @@ export default class Utils {
if (chargePointOfCS.cannotChargeInParallel || chargePointOfCS.sharePowerToAllConnectors) {
// Check Connector ID
const connector = Utils.getConnectorFromID(chargingStation, connectorId);
- if (connector.power) {
+ if (connector?.power) {
return connector.power;
}
return chargePointOfCS.power;
@@ -759,7 +761,7 @@ export default class Utils {
if (chargePointOfCS.connectorIDs.includes(connectorId) && chargePointOfCS.voltage) {
// Check Connector ID
const connector = Utils.getConnectorFromID(chargingStation, connectorId);
- if (connector.voltage) {
+ if (connector?.voltage) {
return connector.voltage;
}
return chargePointOfCS.voltage;
@@ -796,7 +798,7 @@ export default class Utils {
} else if (chargePointOfCS.connectorIDs.includes(connectorId) && chargePointOfCS.currentType) {
// Check Connector ID
const connector = Utils.getConnectorFromID(chargingStation, connectorId);
- if (connector.currentType) {
+ if (connector?.currentType) {
return connector.currentType;
}
return chargePointOfCS.currentType;
@@ -835,7 +837,7 @@ export default class Utils {
// Same power for all connectors
// Check Connector ID first
const connector = Utils.getConnectorFromID(chargingStation, connectorId);
- if (connector.amperage) {
+ if (connector?.amperage) {
return connector.amperage;
}
return chargePointOfCS.amperage;
@@ -865,7 +867,7 @@ export default class Utils {
let amperageLimit = 0;
if (chargingStation) {
if (connectorId > 0) {
- return Utils.getConnectorFromID(chargingStation, connectorId).amperageLimit;
+ return Utils.getConnectorFromID(chargingStation, connectorId)?.amperageLimit;
}
// Check at charge point level
if (chargingStation.chargePoints) {
@@ -877,11 +879,11 @@ export default class Utils {
if (chargePointOfCS.cannotChargeInParallel ||
chargePointOfCS.sharePowerToAllConnectors) {
// Add limit amp of one connector
- amperageLimit += Utils.getConnectorFromID(chargingStation, chargePointOfCS.connectorIDs[0]).amperageLimit;
+ amperageLimit += Utils.getConnectorFromID(chargingStation, chargePointOfCS.connectorIDs[0])?.amperageLimit;
} else {
// Add limit amp of all connectors
for (const connectorID of chargePointOfCS.connectorIDs) {
- amperageLimit += Utils.getConnectorFromID(chargingStation, connectorID).amperageLimit;
+ amperageLimit += Utils.getConnectorFromID(chargingStation, connectorID)?.amperageLimit;
}
}
}

Fixed potential NPE on getting connector