+ 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) {
+ const evseId = Utils.convertToInt(evse);
+ this.evses.set(evseId, Utils.cloneObject<EvseStatus>(stationInfo?.Evses[evse]));
+ this.evses.get(evseId).availability = AvailabilityType.OPERATIVE;
+ }
+ }
+ } else {
+ if (this.connectors.size === 0) {
+ const logMsg = `No already defined connectors and charging station information from template ${this.templateFile} with no evses configuration defined`;
+ logger.error(`${this.logPrefix()} ${logMsg}`);
+ throw new BaseError(logMsg);
+ }
+ logger.info(
+ `${this.logPrefix()} Charging station information from template ${
+ this.templateFile
+ } with no evses configuration defined, mapping one connector to one evse`
+ );
+ for (const [connectorId, connectorStatus] of this.connectors) {
+ this.evses.set(connectorId, {
+ connectorIds: [connectorId],
+ availability: connectorStatus.availability,
+ });
+ }
+ }
+ }
+