- this.configuration = this.getConfiguration();
- delete this.stationInfo.Configuration;
- this.bootNotificationRequest = {
- chargePointModel: this.stationInfo.chargePointModel,
- chargePointVendor: this.stationInfo.chargePointVendor,
- ...(!Utils.isUndefined(this.stationInfo.chargeBoxSerialNumberPrefix) && {
- chargeBoxSerialNumber: this.stationInfo.chargeBoxSerialNumberPrefix,
- }),
- ...(!Utils.isUndefined(this.stationInfo.firmwareVersion) && {
- firmwareVersion: this.stationInfo.firmwareVersion,
- }),
- };
- // Build connectors if needed
- const maxConnectors = this.getMaxNumberOfConnectors();
- if (maxConnectors <= 0) {
- logger.warn(
- `${this.logPrefix()} Charging station template ${
- this.stationTemplateFile
- } with ${maxConnectors} connectors`
- );
- }
- const templateMaxConnectors = this.getTemplateMaxNumberOfConnectors();
- if (templateMaxConnectors <= 0) {
- logger.warn(
- `${this.logPrefix()} Charging station template ${
- this.stationTemplateFile
- } with no connector configuration`
- );
- }
- if (!this.stationInfo.Connectors[0]) {
- logger.warn(
- `${this.logPrefix()} Charging station template ${
- this.stationTemplateFile
- } 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.stationTemplateFile
- }, forcing random connector configurations affectation`
- );
- this.stationInfo.randomConnectors = true;
- }
- const connectorsConfigHash = crypto
- .createHash('sha256')
- .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 = [];
- }
- }
- }
- }
- // Avoid duplication of connectors related information
- delete this.stationInfo.Connectors;
- // Initialize transaction attributes on connectors
- for (const connectorId of this.connectors.keys()) {
- if (connectorId > 0 && !this.getConnectorStatus(connectorId)?.transactionStarted) {
- this.initializeConnectorStatus(connectorId);
- }