import type { ChargingStation } from './ChargingStation';
import { checkChargingStation } from './Helpers';
import { IdTagsCache } from './IdTagsCache';
+import { OCPPServiceUtils } from './ocpp';
import { BaseError } from '../exception';
import { PerformanceStatistics } from '../performance';
import {
AuthorizationStatus,
- type AuthorizeRequest,
- type AuthorizeResponse,
ConnectorStatusEnum,
RequestCommand,
type StartTransactionRequest,
connectorId,
)} start transaction with an idTag '${idTag}'`;
if (this.getRequireAuthorize()) {
- // Authorize idTag
- const authorizeResponse: AuthorizeResponse =
- await this.chargingStation.ocppRequestService.requestHandler<
- AuthorizeRequest,
- AuthorizeResponse
- >(this.chargingStation, RequestCommand.AUTHORIZE, {
- idTag,
- });
++this.connectorsStatus.get(connectorId)!.authorizeRequests!;
- if (authorizeResponse?.idTagInfo?.status === AuthorizationStatus.ACCEPTED) {
- if (
- isNullOrUndefined(this.chargingStation.getConnectorStatus(connectorId)?.authorizeIdTag)
- ) {
- logger.warn(
- `${this.chargingStation.logPrefix()} IdTag ${idTag} is not set as authorized remotely, applying deferred initialization`,
- );
- this.chargingStation.getConnectorStatus(connectorId)!.authorizeIdTag = idTag;
- }
+ if (await OCPPServiceUtils.isIdTagAuthorized(this.chargingStation, connectorId, idTag)) {
++this.connectorsStatus.get(connectorId)!.acceptedAuthorizeRequests!;
logger.info(startTransactionLogMsg);
// Start transaction
const authorizeConnectorIdDefined = !isNullOrUndefined(authorizeConnectorId);
if (payload.idTagInfo.status === OCPP16AuthorizationStatus.ACCEPTED) {
if (authorizeConnectorIdDefined) {
- chargingStation.getConnectorStatus(authorizeConnectorId!)!.authorizeIdTag =
- requestPayload.idTag;
+ // chargingStation.getConnectorStatus(authorizeConnectorId!)!.authorizeIdTag =
+ // requestPayload.idTag;
chargingStation.getConnectorStatus(authorizeConnectorId!)!.idTagAuthorized = true;
}
logger.debug(
import type { JSONSchemaType } from 'ajv';
-import { type ChargingStation, getIdTagsFile, hasFeatureProfile } from '../../../charging-station';
+import { type ChargingStation, hasFeatureProfile } from '../../../charging-station';
import { OCPPError } from '../../../exception';
import {
type ClearChargingProfileRequest,
- type ConnectorStatus,
CurrentType,
ErrorType,
type JsonType,
MeterValueContext,
MeterValueLocation,
MeterValueUnit,
- OCPP16AuthorizationStatus,
- type OCPP16AuthorizeRequest,
- type OCPP16AuthorizeResponse,
type OCPP16ChargingProfile,
type OCPP16IncomingRequestCommand,
type OCPP16MeterValue,
getRandomFloatRounded,
getRandomInteger,
isNotEmptyArray,
- isNotEmptyString,
isNullOrUndefined,
isUndefined,
logger,
);
}
- public static async isIdTagAuthorized(
- chargingStation: ChargingStation,
- connectorId: number,
- idTag: string,
- ): Promise<boolean> {
- let authorized = false;
- const connectorStatus: ConnectorStatus = chargingStation.getConnectorStatus(connectorId)!;
- if (OCPP16ServiceUtils.isIdTagLocalAuthorized(chargingStation, idTag)) {
- connectorStatus.localAuthorizeIdTag = idTag;
- connectorStatus.idTagLocalAuthorized = true;
- authorized = true;
- } else {
- authorized = await OCPP16ServiceUtils.isIdTagRemoteAuthorized(chargingStation, idTag);
- if (authorized && isNullOrUndefined(connectorStatus.authorizeIdTag)) {
- logger.warn(
- `${chargingStation.logPrefix()} IdTag ${idTag} is not set as authorized remotely, applying deferred initialization`,
- );
- connectorStatus.authorizeIdTag = idTag;
- }
- }
- return authorized;
- }
-
private static buildSampledValue(
sampledValueTemplate: SampledValueTemplate,
value: number,
return MeterValueUnit.VOLT;
}
}
-
- private static isIdTagLocalAuthorized(chargingStation: ChargingStation, idTag: string): boolean {
- return (
- chargingStation.getLocalAuthListEnabled() === true &&
- chargingStation.hasIdTags() === true &&
- isNotEmptyString(
- chargingStation.idTagsCache
- .getIdTags(getIdTagsFile(chargingStation.stationInfo)!)
- ?.find((tag) => tag === idTag),
- )
- );
- }
-
- private static async isIdTagRemoteAuthorized(
- chargingStation: ChargingStation,
- idTag: string,
- ): Promise<boolean> {
- const authorizeResponse: OCPP16AuthorizeResponse =
- await chargingStation.ocppRequestService.requestHandler<
- OCPP16AuthorizeRequest,
- OCPP16AuthorizeResponse
- >(chargingStation, OCPP16RequestCommand.AUTHORIZE, {
- idTag,
- });
- return authorizeResponse?.idTagInfo?.status === OCPP16AuthorizationStatus.ACCEPTED;
- }
}
import { OCPP16Constants } from './1.6/OCPP16Constants';
import { OCPP20Constants } from './2.0/OCPP20Constants';
import { OCPPConstants } from './OCPPConstants';
-import { type ChargingStation, getConfigurationKey } from '../../charging-station';
+import { type ChargingStation, getConfigurationKey, getIdTagsFile } from '../../charging-station';
import { BaseError } from '../../exception';
import {
+ AuthorizationStatus,
+ type AuthorizeRequest,
+ type AuthorizeResponse,
ChargePointErrorCode,
+ type ConnectorStatus,
type ConnectorStatusEnum,
ErrorType,
FileType,
chargingStation.getConnectorStatus(connectorId)!.status = status;
}
+ public static async isIdTagAuthorized(
+ chargingStation: ChargingStation,
+ connectorId: number,
+ idTag: string,
+ ): Promise<boolean> {
+ let authorized = false;
+ if (OCPPServiceUtils.isIdTagLocalAuthorized(chargingStation, idTag)) {
+ const connectorStatus: ConnectorStatus = chargingStation.getConnectorStatus(connectorId)!;
+ connectorStatus.localAuthorizeIdTag = idTag;
+ connectorStatus.idTagLocalAuthorized = true;
+ authorized = true;
+ } else {
+ authorized = await OCPPServiceUtils.isIdTagRemoteAuthorized(
+ chargingStation,
+ connectorId,
+ idTag,
+ );
+ }
+ return authorized;
+ }
+
protected static checkConnectorStatusTransition(
chargingStation: ChargingStation,
connectorId: number,
: numberValue * options.unitMultiplier!;
}
+ private static isIdTagLocalAuthorized(chargingStation: ChargingStation, idTag: string): boolean {
+ return (
+ chargingStation.getLocalAuthListEnabled() === true &&
+ chargingStation.hasIdTags() === true &&
+ isNotEmptyString(
+ chargingStation.idTagsCache
+ .getIdTags(getIdTagsFile(chargingStation.stationInfo)!)
+ ?.find((tag) => tag === idTag),
+ )
+ );
+ }
+
+ private static async isIdTagRemoteAuthorized(
+ chargingStation: ChargingStation,
+ connectorId: number,
+ idTag: string,
+ ): Promise<boolean> {
+ chargingStation.getConnectorStatus(connectorId)!.authorizeIdTag = idTag;
+ return (
+ (
+ await chargingStation.ocppRequestService.requestHandler<
+ AuthorizeRequest,
+ AuthorizeResponse
+ >(chargingStation, RequestCommand.AUTHORIZE, {
+ idTag,
+ })
+ )?.idTagInfo?.status === AuthorizationStatus.ACCEPTED
+ );
+ }
+
private static logPrefix = (
ocppVersion: OCPPVersion,
moduleName?: string,