X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fcharging-station%2Focpp%2FOCPPServiceUtils.ts;h=7da384d3a22e802928e10aeebd8208ff12e4792d;hb=1a6188b2fcd2bf644e6fea0c697a095228c1aed0;hp=ef16bfb8703302c74488af11ff635b8c6da4dd2d;hpb=9ff486f4329a4902e8bcd280c0649a74cb31e4df;p=e-mobility-charging-stations-simulator.git diff --git a/src/charging-station/ocpp/OCPPServiceUtils.ts b/src/charging-station/ocpp/OCPPServiceUtils.ts index ef16bfb8..7da384d3 100644 --- a/src/charging-station/ocpp/OCPPServiceUtils.ts +++ b/src/charging-station/ocpp/OCPPServiceUtils.ts @@ -15,6 +15,7 @@ import { type AuthorizeRequest, type AuthorizeResponse, ChargePointErrorCode, + ChargingStationEvents, type ConnectorStatus, type ConnectorStatusEnum, ErrorType, @@ -173,7 +174,7 @@ export class OCPPServiceUtils { status: ConnectorStatusEnum, evseId?: number, ): StatusNotificationRequest { - switch (chargingStation.stationInfo.ocppVersion ?? OCPPVersion.VERSION_16) { + switch (chargingStation.stationInfo?.ocppVersion) { case OCPPVersion.VERSION_16: return { connectorId, @@ -226,6 +227,10 @@ export class OCPPServiceUtils { ); } chargingStation.getConnectorStatus(connectorId)!.status = status; + chargingStation.emit(ChargingStationEvents.connectorStatusChanged, { + connectorId, + ...chargingStation.getConnectorStatus(connectorId), + }); } public static async isIdTagAuthorized( @@ -233,7 +238,10 @@ export class OCPPServiceUtils { connectorId: number, idTag: string, ): Promise { - if (!chargingStation.getLocalAuthListEnabled() && !chargingStation.getRemoteAuthorization()) { + if ( + !chargingStation.getLocalAuthListEnabled() && + !chargingStation.stationInfo?.remoteAuthorization + ) { logger.warn( `${chargingStation.logPrefix()} The charging station expects to authorize RFID tags but nor local authorization nor remote authorization are enabled. Misbehavior may occur`, ); @@ -246,7 +254,7 @@ export class OCPPServiceUtils { connectorStatus.localAuthorizeIdTag = idTag; connectorStatus.idTagLocalAuthorized = true; return true; - } else if (chargingStation.getRemoteAuthorization()) { + } else if (chargingStation.stationInfo?.remoteAuthorization) { return await OCPPServiceUtils.isIdTagRemoteAuthorized(chargingStation, connectorId, idTag); } return false; @@ -259,7 +267,7 @@ export class OCPPServiceUtils { ): boolean { const fromStatus = chargingStation.getConnectorStatus(connectorId)!.status; let transitionAllowed = false; - switch (chargingStation.stationInfo.ocppVersion) { + switch (chargingStation.stationInfo?.ocppVersion) { case OCPPVersion.VERSION_16: if ( (connectorId === 0 && @@ -292,14 +300,13 @@ export class OCPPServiceUtils { default: throw new BaseError( // eslint-disable-next-line @typescript-eslint/restrict-template-expressions - `Cannot check connector status transition: OCPP version ${chargingStation.stationInfo.ocppVersion} not supported`, + `Cannot check connector status transition: OCPP version ${chargingStation.stationInfo?.ocppVersion} not supported`, ); } if (transitionAllowed === false) { logger.warn( - `${chargingStation.logPrefix()} OCPP ${ - chargingStation.stationInfo.ocppVersion - } connector id ${connectorId} status transition from '${ + `${chargingStation.logPrefix()} OCPP ${chargingStation.stationInfo + ?.ocppVersion} connector id ${connectorId} status transition from '${ chargingStation.getConnectorStatus(connectorId)!.status }' to '${status}' is not allowed`, );