)
}
- public static async requestStopTransaction(
+ public static async requestStopTransaction (
chargingStation: ChargingStation,
connectorId: number
): Promise<GenericResponse> {
return OCPP20Constants.OCPP_RESPONSE_REJECTED
}
+ const evseId = chargingStation.getEvseIdByConnectorId(connectorId)
+ if (evseId == null) {
+ logger.error(
+ `${chargingStation.logPrefix()} OCPP20ServiceUtils.requestStopTransaction: Cannot find EVSE ID for connector ${connectorId.toString()}`
+ )
+ return OCPP20Constants.OCPP_RESPONSE_REJECTED
+ }
+
const transactionEventRequest: OCPP20TransactionEventRequest = {
eventType: OCPP20TransactionEventEnumType.Ended,
evse: {
- id: connectorId,
+ id: evseId,
},
seqNo: 0, // This should be managed by the transaction sequence
timestamp: new Date(),
})
})
+ await describe('getEvseIdByConnectorId', async () => {
+ await it('Should return undefined for stations without EVSEs', () => {
+ const station = createChargingStation({
+ connectorsCount: 3,
+ stationInfo: { ocppVersion: OCPPVersion.VERSION_16 }, // OCPP 1.6 doesn't use EVSEs
+ })
+
+ expect(station.getEvseIdByConnectorId(1)).toBeUndefined()
+ expect(station.getEvseIdByConnectorId(2)).toBeUndefined()
+ })
+
+ await it('Should return correct EVSE ID for connectors in EVSE mode', () => {
+ const station = createChargingStation({
+ connectorsCount: 6,
+ evseConfiguration: { evsesCount: 2 }, // 2 EVSEs with 3 connectors each
+ stationInfo: { ocppVersion: OCPPVersion.VERSION_201 },
+ })
+
+ // EVSE 1 should have connectors 1, 2, 3
+ expect(station.getEvseIdByConnectorId(1)).toBe(1)
+ expect(station.getEvseIdByConnectorId(2)).toBe(1)
+ expect(station.getEvseIdByConnectorId(3)).toBe(1)
+
+ // EVSE 2 should have connectors 4, 5, 6
+ expect(station.getEvseIdByConnectorId(4)).toBe(2)
+ expect(station.getEvseIdByConnectorId(5)).toBe(2)
+ expect(station.getEvseIdByConnectorId(6)).toBe(2)
+ })
+
+ await it('Should return undefined for non-existent connector IDs', () => {
+ const station = createChargingStation({
+ connectorsCount: 4,
+ evseConfiguration: { evsesCount: 2 },
+ stationInfo: { ocppVersion: OCPPVersion.VERSION_201 },
+ })
+
+ expect(station.getEvseIdByConnectorId(0)).toBeUndefined() // Connector 0 not in EVSEs
+ expect(station.getEvseIdByConnectorId(99)).toBeUndefined() // Non-existent connector
+ expect(station.getEvseIdByConnectorId(-1)).toBeUndefined() // Invalid connector ID
+ })
+
+ await it('Should handle single EVSE with multiple connectors', () => {
+ const station = createChargingStation({
+ connectorsCount: 3,
+ evseConfiguration: { evsesCount: 1 }, // Single EVSE with all connectors
+ stationInfo: { ocppVersion: OCPPVersion.VERSION_201 },
+ })
+
+ // All connectors should belong to EVSE 1
+ expect(station.getEvseIdByConnectorId(1)).toBe(1)
+ expect(station.getEvseIdByConnectorId(2)).toBe(1)
+ expect(station.getEvseIdByConnectorId(3)).toBe(1)
+ })
+ })
+
await describe('isConnectorAvailable', async () => {
await it('Should return false for connector ID 0', () => {
const station = createChargingStation({ connectorsCount: 2 })
}
return chargingStation.connectors.get(connectorId)
},
+ getEvseIdByConnectorId: (connectorId: number) => {
+ if (!chargingStation.hasEvses) {
+ return undefined
+ }
+ for (const [evseId, evseStatus] of chargingStation.evses.entries()) {
+ if (evseStatus.connectors.has(connectorId)) {
+ return evseId
+ }
+ }
+ return undefined
+ },
getEvseIdByTransactionId: (transactionId: string) => {
// Search through EVSEs to find one with matching transaction ID
if (chargingStation.hasEvses) {