-import crypto from 'node:crypto';
-import type EventEmitter from 'node:events';
-import path from 'node:path';
+import { createHash, randomBytes } from 'node:crypto';
+import type { EventEmitter } from 'node:events';
+import { basename, dirname, join } from 'node:path';
import { fileURLToPath } from 'node:url';
import chalk from 'chalk';
)}${idSuffix}`;
}
+ public static countReservableConnectors(connectors: Map<number, ConnectorStatus>) {
+ let reservableConnectors = 0;
+ for (const [connectorId, connectorStatus] of connectors) {
+ if (connectorId === 0) {
+ continue;
+ }
+ if (connectorStatus.status === ConnectorStatusEnum.Available) {
+ ++reservableConnectors;
+ }
+ }
+ return reservableConnectors;
+ }
+
public static getHashId(index: number, stationTemplate: ChargingStationTemplate): string {
const chargingStationInfo = {
chargePointModel: stationTemplate.chargePointModel,
meterType: stationTemplate.meterType,
}),
};
- return crypto
- .createHash(Constants.DEFAULT_HASH_ALGORITHM)
+ return createHash(Constants.DEFAULT_HASH_ALGORITHM)
.update(
`${JSON.stringify(chargingStationInfo)}${ChargingStationUtils.getChargingStationId(
index,
public static getIdTagsFile(stationInfo: ChargingStationInfo): string | undefined {
return (
stationInfo.idTagsFile &&
- path.join(
- path.dirname(fileURLToPath(import.meta.url)),
- 'assets',
- path.basename(stationInfo.idTagsFile)
- )
+ join(dirname(fileURLToPath(import.meta.url)), 'assets', basename(stationInfo.idTagsFile))
);
}
randomBytesLength?: number;
upperCase?: boolean;
}): string {
- const randomSerialNumberSuffix = crypto
- .randomBytes(params?.randomBytesLength ?? 16)
- .toString('hex');
+ const randomSerialNumberSuffix = randomBytes(params?.randomBytesLength ?? 16).toString('hex');
if (params?.upperCase) {
return randomSerialNumberSuffix.toUpperCase();
}