+ if (
+ !ChargingStationConfigurationUtils.getConfigurationKey(
+ this,
+ StandardParametersKey.AuthorizeRemoteTxRequests
+ )
+ ) {
+ ChargingStationConfigurationUtils.addConfigurationKey(
+ this,
+ StandardParametersKey.AuthorizeRemoteTxRequests,
+ 'true'
+ );
+ }
+ if (
+ !ChargingStationConfigurationUtils.getConfigurationKey(
+ this,
+ StandardParametersKey.LocalAuthListEnabled
+ ) &&
+ ChargingStationConfigurationUtils.getConfigurationKey(
+ this,
+ StandardParametersKey.SupportedFeatureProfiles
+ )?.value?.includes(SupportedFeatureProfiles.LocalAuthListManagement)
+ ) {
+ ChargingStationConfigurationUtils.addConfigurationKey(
+ this,
+ StandardParametersKey.LocalAuthListEnabled,
+ 'false'
+ );
+ }
+ if (
+ !ChargingStationConfigurationUtils.getConfigurationKey(
+ this,
+ StandardParametersKey.ConnectionTimeOut
+ )
+ ) {
+ ChargingStationConfigurationUtils.addConfigurationKey(
+ this,
+ StandardParametersKey.ConnectionTimeOut,
+ Constants.DEFAULT_CONNECTION_TIMEOUT.toString()
+ );
+ }
+ this.saveOcppConfiguration();
+ }
+
+ private initializeConnectors(
+ stationInfo: ChargingStationInfo,
+ configuredMaxConnectors: number
+ ): void {
+ if (!stationInfo?.Connectors && this.connectors.size === 0) {
+ const logMsg = `No already defined connectors and charging station information from template ${this.templateFile} with no connectors configuration defined`;
+ logger.error(`${this.logPrefix()} ${logMsg}`);
+ throw new BaseError(logMsg);
+ }
+ if (!stationInfo?.Connectors[0]) {
+ logger.warn(
+ `${this.logPrefix()} Charging station information from template ${
+ this.templateFile
+ } with no connector id 0 configuration`
+ );
+ }
+ if (stationInfo?.Connectors) {
+ const connectorsConfigHash = crypto
+ .createHash(Constants.DEFAULT_HASH_ALGORITHM)
+ .update(`${JSON.stringify(stationInfo?.Connectors)}${configuredMaxConnectors.toString()}`)
+ .digest('hex');
+ const connectorsConfigChanged =
+ this.connectors?.size !== 0 && this.connectorsConfigurationHash !== connectorsConfigHash;
+ if (this.connectors?.size === 0 || connectorsConfigChanged) {
+ connectorsConfigChanged && this.connectors.clear();
+ this.connectorsConfigurationHash = connectorsConfigHash;
+ // Add connector id 0
+ let lastConnector = '0';
+ for (lastConnector in stationInfo?.Connectors) {
+ const connectorStatus = stationInfo?.Connectors[lastConnector];
+ const lastConnectorId = Utils.convertToInt(lastConnector);
+ if (
+ lastConnectorId === 0 &&
+ this.getUseConnectorId0(stationInfo) === true &&
+ connectorStatus
+ ) {
+ this.checkStationInfoConnectorStatus(lastConnectorId, connectorStatus);
+ this.connectors.set(
+ lastConnectorId,
+ Utils.cloneObject<ConnectorStatus>(connectorStatus)
+ );
+ this.getConnectorStatus(lastConnectorId).availability = AvailabilityType.Operative;
+ if (Utils.isUndefined(this.getConnectorStatus(lastConnectorId)?.chargingProfiles)) {
+ this.getConnectorStatus(lastConnectorId).chargingProfiles = [];
+ }
+ }
+ }
+ // Generate all connectors
+ const templateMaxConnectors = ChargingStationUtils.getMaxNumberOfConnectors(
+ stationInfo?.Connectors
+ );
+ if ((stationInfo?.Connectors[0] ? templateMaxConnectors - 1 : templateMaxConnectors) > 0) {
+ for (let index = 1; index <= configuredMaxConnectors; index++) {
+ const randConnectorId = stationInfo?.randomConnectors
+ ? Utils.getRandomInteger(Utils.convertToInt(lastConnector), 1)
+ : index;
+ const connectorStatus = stationInfo?.Connectors[randConnectorId.toString()];
+ this.checkStationInfoConnectorStatus(randConnectorId, connectorStatus);
+ this.connectors.set(index, Utils.cloneObject<ConnectorStatus>(connectorStatus));
+ this.getConnectorStatus(index).availability = AvailabilityType.Operative;
+ if (Utils.isUndefined(this.getConnectorStatus(index)?.chargingProfiles)) {
+ this.getConnectorStatus(index).chargingProfiles = [];
+ }
+ }
+ }
+ }
+ } else {
+ logger.warn(
+ `${this.logPrefix()} Charging station information from template ${
+ this.templateFile
+ } with no connectors configuration defined, using already defined connectors`
+ );
+ }
+ // Initialize connectors status
+ for (const connectorId of this.connectors.keys()) {
+ if (connectorId > 0 && this.getConnectorStatus(connectorId)?.transactionStarted === true) {
+ logger.warn(
+ `${this.logPrefix()} Connector ${connectorId} at initialization has a transaction started: ${
+ this.getConnectorStatus(connectorId)?.transactionId
+ }`
+ );
+ }
+ if (
+ connectorId > 0 &&
+ Utils.isNullOrUndefined(this.getConnectorStatus(connectorId)?.transactionStarted)
+ ) {
+ this.initializeConnectorStatus(this.getConnectorStatus(connectorId));
+ }
+ }
+ }
+
+ private buildConnectorsMap(
+ connectors: Record<string, ConnectorStatus>
+ ): Map<number, ConnectorStatus> {
+ const connectorsMap = new Map<number, ConnectorStatus>();
+ for (const connector in connectors) {
+ const connectorStatus = connectors[connector];
+ const connectorId = Utils.convertToInt(connector);
+ this.checkStationInfoConnectorStatus(connectorId, connectorStatus);
+ connectorsMap.set(connectorId, Utils.cloneObject<ConnectorStatus>(connectorStatus));
+ connectorsMap.get(connectorId).availability = AvailabilityType.Operative;
+ if (Utils.isUndefined(connectorsMap.get(connectorId)?.chargingProfiles)) {
+ connectorsMap.get(connectorId).chargingProfiles = [];
+ }
+ }
+ return connectorsMap;
+ }
+
+ private initializeConnectorsMapStatus(connectors: Map<number, ConnectorStatus>): void {
+ for (const connectorId of connectors.keys()) {
+ if (connectorId > 0 && connectors.get(connectorId)?.transactionStarted === true) {
+ logger.warn(
+ `${this.logPrefix()} Connector ${connectorId} at initialization has a transaction started: ${
+ connectors.get(connectorId)?.transactionId
+ }`
+ );
+ }
+ if (
+ connectorId > 0 &&
+ Utils.isNullOrUndefined(connectors.get(connectorId)?.transactionStarted)
+ ) {
+ this.initializeConnectorStatus(connectors.get(connectorId));
+ }
+ }
+ }
+
+ private initializeEvses(stationInfo: ChargingStationInfo): void {
+ if (!stationInfo?.Evses && this.evses.size === 0) {
+ const logMsg = `No already defined evses and charging station information from template ${this.templateFile} with no evses configuration defined`;
+ logger.warn(`${this.logPrefix()} ${logMsg}`);
+ return;
+ }
+ if (!stationInfo?.Evses[0]) {
+ logger.warn(
+ `${this.logPrefix()} Charging station information from template ${
+ this.templateFile
+ } with no evse id 0 configuration`
+ );
+ }
+ if (stationInfo?.Evses) {
+ const evsesConfigHash = crypto
+ .createHash(Constants.DEFAULT_HASH_ALGORITHM)
+ .update(`${JSON.stringify(stationInfo?.Evses)}`)
+ .digest('hex');
+ const evsesConfigChanged =
+ this.evses?.size !== 0 && this.evsesConfigurationHash !== evsesConfigHash;
+ if (this.evses?.size === 0 || evsesConfigChanged) {
+ evsesConfigChanged && this.evses.clear();
+ this.evsesConfigurationHash = evsesConfigHash;
+ for (const evse in stationInfo?.Evses) {
+ this.evses.set(Utils.convertToInt(evse), {
+ connectors: this.buildConnectorsMap(stationInfo?.Evses[evse]?.Connectors),
+ availability: AvailabilityType.Operative,
+ });
+ this.initializeConnectorsMapStatus(this.evses.get(Utils.convertToInt(evse))?.connectors);
+ }
+ }
+ } else {
+ logger.warn(
+ `${this.logPrefix()} Charging station information from template ${
+ this.templateFile
+ } with no evses configuration defined, using already defined evses`
+ );
+ }
+ }
+
+ private checkStationInfoConnectorStatus(
+ connectorId: number,
+ connectorStatus: ConnectorStatus
+ ): void {
+ if (!Utils.isNullOrUndefined(connectorStatus?.status)) {
+ logger.warn(
+ `${this.logPrefix()} Charging station information from template ${
+ this.templateFile
+ } with connector ${connectorId} status configuration defined, undefine it`