Configuration,
Constants,
DCElectricUtils,
- Utils,
buildChargingStationAutomaticTransactionGeneratorConfiguration,
buildConnectorsStatus,
buildEvsesStatus,
buildStartedMessage,
buildStoppedMessage,
buildUpdatedMessage,
+ cloneObject,
+ convertToBoolean,
+ convertToInt,
+ exponentialDelay,
+ formatDurationMilliSeconds,
+ formatDurationSeconds,
+ getRandomInteger,
+ getWebSocketCloseEventStatusString,
handleFileException,
+ isNotEmptyArray,
+ isNotEmptyString,
+ isNullOrUndefined,
+ isUndefined,
+ logPrefix,
logger,
+ roundTo,
+ secureRandom,
+ sleep,
watchJsonFile,
} from '../utils';
return new URL(
`${
this.getSupervisionUrlOcppConfiguration() &&
- Utils.isNotEmptyString(this.getSupervisionUrlOcppKey()) &&
- Utils.isNotEmptyString(
+ isNotEmptyString(this.getSupervisionUrlOcppKey()) &&
+ isNotEmptyString(
ChargingStationConfigurationUtils.getConfigurationKey(
this,
this.getSupervisionUrlOcppKey()
}
public logPrefix = (): string => {
- return Utils.logPrefix(
+ return logPrefix(
` ${
- (Utils.isNotEmptyString(this?.stationInfo?.chargingStationId)
+ (isNotEmptyString(this?.stationInfo?.chargingStationId)
? this?.stationInfo?.chargingStationId
: ChargingStationUtils.getChargingStationId(this.index, this.getTemplateFromFile())) ??
'Error at building log prefix'
};
public hasIdTags(): boolean {
- return Utils.isNotEmptyArray(
+ return isNotEmptyArray(
this.idTagsCache.getIdTags(ChargingStationUtils.getIdTagsFile(this.stationInfo))
);
}
const localStationInfo: ChargingStationInfo = stationInfo ?? this.stationInfo;
switch (this.getCurrentOutType(stationInfo)) {
case CurrentType.AC:
- return !Utils.isUndefined(localStationInfo.numberOfPhases)
- ? localStationInfo.numberOfPhases
- : 3;
+ return !isUndefined(localStationInfo.numberOfPhases) ? localStationInfo.numberOfPhases : 3;
case CurrentType.DC:
return 0;
}
}
public inUnknownState(): boolean {
- return Utils.isNullOrUndefined(this?.bootNotificationResponse?.status);
+ return isNullOrUndefined(this?.bootNotificationResponse?.status);
}
public inPendingState(): boolean {
public getConnectorMaximumAvailablePower(connectorId: number): number {
let connectorAmperageLimitationPowerLimit: number;
if (
- !Utils.isNullOrUndefined(this.getAmperageLimitation()) &&
+ !isNullOrUndefined(this.getAmperageLimitation()) &&
this.getAmperageLimitation() < this.stationInfo?.maximumAmperage
) {
connectorAmperageLimitationPowerLimit =
this,
StandardParametersKey.AuthorizeRemoteTxRequests
);
- return authorizeRemoteTxRequests
- ? Utils.convertToBoolean(authorizeRemoteTxRequests.value)
- : false;
+ return authorizeRemoteTxRequests ? convertToBoolean(authorizeRemoteTxRequests.value) : false;
}
public getLocalAuthListEnabled(): boolean {
this,
StandardParametersKey.LocalAuthListEnabled
);
- return localAuthListEnabled ? Utils.convertToBoolean(localAuthListEnabled.value) : false;
+ return localAuthListEnabled ? convertToBoolean(localAuthListEnabled.value) : false;
}
public getHeartbeatInterval(): number {
StandardParametersKey.HeartbeatInterval
);
if (HeartbeatInterval) {
- return Utils.convertToInt(HeartbeatInterval.value) * 1000;
+ return convertToInt(HeartbeatInterval.value) * 1000;
}
const HeartBeatInterval = ChargingStationConfigurationUtils.getConfigurationKey(
this,
StandardParametersKey.HeartBeatInterval
);
if (HeartBeatInterval) {
- return Utils.convertToInt(HeartBeatInterval.value) * 1000;
+ return convertToInt(HeartBeatInterval.value) * 1000;
}
this.stationInfo?.autoRegister === false &&
logger.warn(
public setSupervisionUrl(url: string): void {
if (
this.getSupervisionUrlOcppConfiguration() &&
- Utils.isNotEmptyString(this.getSupervisionUrlOcppKey())
+ isNotEmptyString(this.getSupervisionUrlOcppKey())
) {
ChargingStationConfigurationUtils.setConfigurationKeyValue(
this,
});
}, this.getHeartbeatInterval());
logger.info(
- `${this.logPrefix()} Heartbeat started every ${Utils.formatDurationMilliSeconds(
+ `${this.logPrefix()} Heartbeat started every ${formatDurationMilliSeconds(
this.getHeartbeatInterval()
)}`
);
} else if (this.heartbeatSetInterval) {
logger.info(
- `${this.logPrefix()} Heartbeat already started every ${Utils.formatDurationMilliSeconds(
+ `${this.logPrefix()} Heartbeat already started every ${formatDurationMilliSeconds(
this.getHeartbeatInterval()
)}`
);
return;
} else if (
this.getConnectorStatus(connectorId)?.transactionStarted === true &&
- Utils.isNullOrUndefined(this.getConnectorStatus(connectorId)?.transactionId)
+ isNullOrUndefined(this.getConnectorStatus(connectorId)?.transactionId)
) {
logger.error(
`${this.logPrefix()} Trying to start MeterValues on connector id ${connectorId}
this.logPrefix(),
undefined,
(event, filename): void => {
- if (Utils.isNotEmptyString(filename) && event === 'change') {
+ if (isNotEmptyString(filename) && event === 'change') {
try {
logger.debug(
`${this.logPrefix()} ${FileType.ChargingStationTemplate} ${
public async reset(reason?: StopTransactionReason): Promise<void> {
await this.stop(reason);
- await Utils.sleep(this.stationInfo.resetTime);
+ await sleep(this.stationInfo.resetTime);
this.initialize();
this.start();
}
return;
}
if (
- !Utils.isNullOrUndefined(this.stationInfo.supervisionUser) &&
- !Utils.isNullOrUndefined(this.stationInfo.supervisionPassword)
+ !isNullOrUndefined(this.stationInfo.supervisionUser) &&
+ !isNullOrUndefined(this.stationInfo.supervisionPassword)
) {
options.auth = `${this.stationInfo.supervisionUser}:${this.stationInfo.supervisionPassword}`;
}
public startAutomaticTransactionGenerator(connectorIds?: number[]): void {
this.automaticTransactionGenerator = AutomaticTransactionGenerator.getInstance(this);
- if (Utils.isNotEmptyArray(connectorIds)) {
+ if (isNotEmptyArray(connectorIds)) {
for (const connectorId of connectorIds) {
this.automaticTransactionGenerator?.startConnector(connectorId);
}
}
public stopAutomaticTransactionGenerator(connectorIds?: number[]): void {
- if (Utils.isNotEmptyArray(connectorIds)) {
+ if (isNotEmptyArray(connectorIds)) {
for (const connectorId of connectorIds) {
this.automaticTransactionGenerator?.stopConnector(connectorId);
}
}
public getReservationOnConnectorId0Enabled(): boolean {
- return Utils.convertToBoolean(
+ return convertToBoolean(
ChargingStationConfigurationUtils.getConfigurationKey(
this,
StandardParametersKey.ReserveConnectorZeroSupported
ReservationFilterKey.RESERVATION_ID,
reservation?.id
);
- return Utils.isUndefined(foundReservation) ? [false, null] : [true, foundReservation];
+ return isUndefined(foundReservation) ? [false, null] : [true, foundReservation];
}
public startReservationExpirationSetInterval(customInterval?: number): void {
if (alreadyExists) {
return alreadyExists;
}
- const userReservedAlready = Utils.isUndefined(
+ const userReservedAlready = isUndefined(
this.getReservationBy(ReservationFilterKey.ID_TAG, idTag)
)
? false
: true;
- const notConnectorZero = Utils.isUndefined(connectorId) ? true : connectorId > 0;
+ const notConnectorZero = isUndefined(connectorId) ? true : connectorId > 0;
const freeConnectorsAvailable = this.getNumberOfReservableConnectors() > 0;
return !alreadyExists && !userReservedAlready && notConnectorZero && freeConnectorsAvailable;
}
);
stationInfo.ocppVersion = stationTemplate?.ocppVersion ?? OCPPVersion.VERSION_16;
ChargingStationUtils.createSerialNumber(stationTemplate, stationInfo);
- if (Utils.isNotEmptyArray(stationTemplate?.power)) {
+ if (isNotEmptyArray(stationTemplate?.power)) {
stationTemplate.power = stationTemplate.power as number[];
- const powerArrayRandomIndex = Math.floor(Utils.secureRandom() * stationTemplate.power.length);
+ const powerArrayRandomIndex = Math.floor(secureRandom() * stationTemplate.power.length);
stationInfo.maximumPower =
stationTemplate?.powerUnit === PowerUnits.KILO_WATT
? stationTemplate.power[powerArrayRandomIndex] * 1000
stationInfo.firmwareVersionPattern =
stationTemplate?.firmwareVersionPattern ?? Constants.SEMVER_PATTERN;
if (
- Utils.isNotEmptyString(stationInfo.firmwareVersion) &&
+ isNotEmptyString(stationInfo.firmwareVersion) &&
new RegExp(stationInfo.firmwareVersionPattern).test(stationInfo.firmwareVersion) === false
) {
logger.warn(
},
stationTemplate?.firmwareUpgrade ?? {}
);
- stationInfo.resetTime = !Utils.isNullOrUndefined(stationTemplate?.resetTime)
+ stationInfo.resetTime = !isNullOrUndefined(stationTemplate?.resetTime)
? stationTemplate.resetTime * 1000
: Constants.CHARGING_STATION_DEFAULT_RESET_TIME;
stationInfo.maximumAmperage = this.getMaximumAmperage(stationInfo);
this.stationInfo = this.getStationInfo();
if (
this.stationInfo.firmwareStatus === FirmwareStatus.Installing &&
- Utils.isNotEmptyString(this.stationInfo.firmwareVersion) &&
- Utils.isNotEmptyString(this.stationInfo.firmwareVersionPattern)
+ isNotEmptyString(this.stationInfo.firmwareVersion) &&
+ isNotEmptyString(this.stationInfo.firmwareVersionPattern)
) {
const patternGroup: number | undefined =
this.stationInfo.firmwareUpgrade?.versionUpgrade?.patternGroup ??
?.slice(1, patternGroup + 1);
const patchLevelIndex = match.length - 1;
match[patchLevelIndex] = (
- Utils.convertToInt(match[patchLevelIndex]) +
+ convertToInt(match[patchLevelIndex]) +
this.stationInfo.firmwareUpgrade?.versionUpgrade?.step
).toString();
this.stationInfo.firmwareVersion = match?.join('.');
}
if (
this.getSupervisionUrlOcppConfiguration() &&
- Utils.isNotEmptyString(this.getSupervisionUrlOcppKey()) &&
+ isNotEmptyString(this.getSupervisionUrlOcppKey()) &&
!ChargingStationConfigurationUtils.getConfigurationKey(this, this.getSupervisionUrlOcppKey())
) {
ChargingStationConfigurationUtils.addConfigurationKey(
);
} else if (
!this.getSupervisionUrlOcppConfiguration() &&
- Utils.isNotEmptyString(this.getSupervisionUrlOcppKey()) &&
+ isNotEmptyString(this.getSupervisionUrlOcppKey()) &&
ChargingStationConfigurationUtils.getConfigurationKey(this, this.getSupervisionUrlOcppKey())
) {
ChargingStationConfigurationUtils.deleteConfigurationKey(
);
}
if (
- Utils.isNotEmptyString(this.stationInfo?.amperageLimitationOcppKey) &&
+ isNotEmptyString(this.stationInfo?.amperageLimitationOcppKey) &&
!ChargingStationConfigurationUtils.getConfigurationKey(
this,
this.stationInfo.amperageLimitationOcppKey
private initializeConnectorsOrEvsesFromFile(configuration: ChargingStationConfiguration): void {
if (configuration?.connectorsStatus && !configuration?.evsesStatus) {
for (const [connectorId, connectorStatus] of configuration.connectorsStatus.entries()) {
- this.connectors.set(connectorId, Utils.cloneObject<ConnectorStatus>(connectorStatus));
+ this.connectors.set(connectorId, cloneObject<ConnectorStatus>(connectorStatus));
}
} else if (configuration?.evsesStatus && !configuration?.connectorsStatus) {
for (const [evseId, evseStatusConfiguration] of configuration.evsesStatus.entries()) {
- const evseStatus = Utils.cloneObject<EvseStatusConfiguration>(evseStatusConfiguration);
+ const evseStatus = cloneObject<EvseStatusConfiguration>(evseStatusConfiguration);
delete evseStatus.connectorsStatus;
this.evses.set(evseId, {
...(evseStatus as EvseStatus),
}
const templateConnectorId =
connectorId > 0 && stationTemplate?.randomConnectors
- ? Utils.getRandomInteger(templateMaxAvailableConnectors, 1)
+ ? getRandomInteger(templateMaxAvailableConnectors, 1)
: connectorId;
const connectorStatus = stationTemplate?.Connectors[templateConnectorId];
ChargingStationUtils.checkStationInfoConnectorStatus(
this.logPrefix(),
this.templateFile
);
- this.connectors.set(connectorId, Utils.cloneObject<ConnectorStatus>(connectorStatus));
+ this.connectors.set(connectorId, cloneObject<ConnectorStatus>(connectorStatus));
}
ChargingStationUtils.initializeConnectorsMapStatus(this.connectors, this.logPrefix());
this.saveConnectorsStatus();
const templateMaxEvses = ChargingStationUtils.getMaxNumberOfEvses(stationTemplate?.Evses);
if (templateMaxEvses > 0) {
for (const evse in stationTemplate.Evses) {
- const evseId = Utils.convertToInt(evse);
+ const evseId = convertToInt(evse);
this.evses.set(evseId, {
connectors: ChargingStationUtils.buildConnectorsMap(
stationTemplate?.Evses[evse]?.Connectors,
private getConfigurationFromFile(): ChargingStationConfiguration | undefined {
let configuration: ChargingStationConfiguration | undefined;
- if (Utils.isNotEmptyString(this.configurationFile) && existsSync(this.configurationFile)) {
+ if (isNotEmptyString(this.configurationFile) && existsSync(this.configurationFile)) {
try {
if (this.sharedLRUCache.hasChargingStationConfiguration(this.configurationFileHash)) {
configuration = this.sharedLRUCache.getChargingStationConfiguration(
}
private saveConfiguration(): void {
- if (Utils.isNotEmptyString(this.configurationFile)) {
+ if (isNotEmptyString(this.configurationFile)) {
try {
if (!existsSync(dirname(this.configurationFile))) {
mkdirSync(dirname(this.configurationFile), { recursive: true });
}
let configurationData: ChargingStationConfiguration =
- Utils.cloneObject<ChargingStationConfiguration>(this.getConfigurationFromFile()) ?? {};
+ cloneObject<ChargingStationConfiguration>(this.getConfigurationFromFile()) ?? {};
if (this.getStationInfoPersistentConfiguration() && this.stationInfo) {
configurationData.stationInfo = this.stationInfo;
} else {
});
if (this.isRegistered() === false) {
this.getRegistrationMaxRetries() !== -1 && ++registrationRetryCount;
- await Utils.sleep(
+ await sleep(
this?.bootNotificationResponse?.interval
? this.bootNotificationResponse.interval * 1000
: Constants.DEFAULT_BOOT_NOTIFICATION_INTERVAL
case WebSocketCloseEventStatusCode.CLOSE_NORMAL:
case WebSocketCloseEventStatusCode.CLOSE_NO_STATUS:
logger.info(
- `${this.logPrefix()} WebSocket normally closed with status '${Utils.getWebSocketCloseEventStatusString(
+ `${this.logPrefix()} WebSocket normally closed with status '${getWebSocketCloseEventStatusString(
code
)}' and reason '${reason.toString()}'`
);
// Abnormal close
default:
logger.error(
- `${this.logPrefix()} WebSocket abnormally closed with status '${Utils.getWebSocketCloseEventStatusString(
+ `${this.logPrefix()} WebSocket abnormally closed with status '${getWebSocketCloseEventStatusString(
code
)}' and reason '${reason.toString()}'`
);
private getAmperageLimitation(): number | undefined {
if (
- Utils.isNotEmptyString(this.stationInfo?.amperageLimitationOcppKey) &&
+ isNotEmptyString(this.stationInfo?.amperageLimitationOcppKey) &&
ChargingStationConfigurationUtils.getConfigurationKey(
this,
this.stationInfo.amperageLimitationOcppKey
)
) {
return (
- Utils.convertToInt(
+ convertToInt(
ChargingStationConfigurationUtils.getConfigurationKey(
this,
this.stationInfo.amperageLimitationOcppKey
this,
StandardParametersKey.WebSocketPingInterval
)
- ? Utils.convertToInt(
+ ? convertToInt(
ChargingStationConfigurationUtils.getConfigurationKey(
this,
StandardParametersKey.WebSocketPingInterval
}
}, webSocketPingInterval * 1000);
logger.info(
- `${this.logPrefix()} WebSocket ping started every ${Utils.formatDurationSeconds(
+ `${this.logPrefix()} WebSocket ping started every ${formatDurationSeconds(
webSocketPingInterval
)}`
);
} else if (this.webSocketPingSetInterval) {
logger.info(
- `${this.logPrefix()} WebSocket ping already started every ${Utils.formatDurationSeconds(
+ `${this.logPrefix()} WebSocket ping already started every ${formatDurationSeconds(
webSocketPingInterval
)}`
);
private getConfiguredSupervisionUrl(): URL {
let configuredSupervisionUrl: string;
const supervisionUrls = this.stationInfo?.supervisionUrls ?? Configuration.getSupervisionUrls();
- if (Utils.isNotEmptyArray(supervisionUrls)) {
+ if (isNotEmptyArray(supervisionUrls)) {
let configuredSupervisionUrlIndex: number;
switch (Configuration.getSupervisionUrlDistribution()) {
case SupervisionUrlDistribution.RANDOM:
- configuredSupervisionUrlIndex = Math.floor(Utils.secureRandom() * supervisionUrls.length);
+ configuredSupervisionUrlIndex = Math.floor(secureRandom() * supervisionUrls.length);
break;
case SupervisionUrlDistribution.ROUND_ROBIN:
case SupervisionUrlDistribution.CHARGING_STATION_AFFINITY:
} else {
configuredSupervisionUrl = supervisionUrls as string;
}
- if (Utils.isNotEmptyString(configuredSupervisionUrl)) {
+ if (isNotEmptyString(configuredSupervisionUrl)) {
return new URL(configuredSupervisionUrl);
}
const errorMsg = 'No supervision url(s) configured';
) {
++this.autoReconnectRetryCount;
const reconnectDelay = this.getReconnectExponentialDelay()
- ? Utils.exponentialDelay(this.autoReconnectRetryCount)
+ ? exponentialDelay(this.autoReconnectRetryCount)
: this.getConnectionTimeout() * 1000;
const reconnectDelayWithdraw = 1000;
const reconnectTimeout =
? reconnectDelay - reconnectDelayWithdraw
: 0;
logger.error(
- `${this.logPrefix()} WebSocket connection retry in ${Utils.roundTo(
+ `${this.logPrefix()} WebSocket connection retry in ${roundTo(
reconnectDelay,
2
)}ms, timeout ${reconnectTimeout}ms`
);
- await Utils.sleep(reconnectDelay);
+ await sleep(reconnectDelay);
logger.error(
`${this.logPrefix()} WebSocket connection retry #${this.autoReconnectRetryCount.toString()}`
);