- this.bootNotificationRequest = this.createBootNotificationRequest(this.stationInfo);
- this.ocppConfiguration = this.getOcppConfiguration();
- delete this.stationInfo.Configuration;
- // Build connectors if needed
- const maxConnectors = this.getMaxNumberOfConnectors();
- if (maxConnectors <= 0) {
- logger.warn(
- `${this.logPrefix()} Charging station template ${
- this.templateFile
- } with ${maxConnectors} connectors`
- );
- }
- const templateMaxConnectors = this.getTemplateMaxNumberOfConnectors();
- if (templateMaxConnectors <= 0) {
- logger.warn(
- `${this.logPrefix()} Charging station template ${
- this.templateFile
- } with no connector configuration`
- );
- }
- if (!this.stationInfo.Connectors[0]) {
- logger.warn(
- `${this.logPrefix()} Charging station template ${
- this.templateFile
- } with no connector Id 0 configuration`
- );
- }
- // Sanity check
- if (
- maxConnectors >
- (this.stationInfo.Connectors[0] ? templateMaxConnectors - 1 : templateMaxConnectors) &&
- !this.stationInfo.randomConnectors
- ) {
- logger.warn(
- `${this.logPrefix()} Number of connectors exceeds the number of connector configurations in template ${
- this.templateFile
- }, forcing random connector configurations affectation`
- );
- this.stationInfo.randomConnectors = true;
- }
- const connectorsConfigHash = crypto
- .createHash(Constants.DEFAULT_HASH_ALGORITHM)
- .update(JSON.stringify(this.stationInfo.Connectors) + maxConnectors.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 this.stationInfo.Connectors) {
- const lastConnectorId = Utils.convertToInt(lastConnector);
- if (
- lastConnectorId === 0 &&
- this.getUseConnectorId0() &&
- this.stationInfo.Connectors[lastConnector]
- ) {
- this.connectors.set(
- lastConnectorId,
- Utils.cloneObject<ConnectorStatus>(this.stationInfo.Connectors[lastConnector])
- );
- this.getConnectorStatus(lastConnectorId).availability = AvailabilityType.OPERATIVE;
- if (Utils.isUndefined(this.getConnectorStatus(lastConnectorId)?.chargingProfiles)) {
- this.getConnectorStatus(lastConnectorId).chargingProfiles = [];
- }
- }
- }
- // Generate all connectors
- if (
- (this.stationInfo.Connectors[0] ? templateMaxConnectors - 1 : templateMaxConnectors) > 0
- ) {
- for (let index = 1; index <= maxConnectors; index++) {
- const randConnectorId = this.stationInfo.randomConnectors
- ? Utils.getRandomInteger(Utils.convertToInt(lastConnector), 1)
- : index;
- this.connectors.set(
- index,
- Utils.cloneObject<ConnectorStatus>(this.stationInfo.Connectors[randConnectorId])
- );
- this.getConnectorStatus(index).availability = AvailabilityType.OPERATIVE;
- if (Utils.isUndefined(this.getConnectorStatus(index)?.chargingProfiles)) {
- this.getConnectorStatus(index).chargingProfiles = [];
- }
- }
- }
- }
- // The connectors attribute need to be initialized
- this.stationInfo.maximumAmperage = this.getMaximumAmperage();