import { URL } from 'node:url';
import { parentPort } from 'node:worker_threads';
+import { millisecondsToSeconds, secondsToMilliseconds } from 'date-fns';
import merge from 'just-merge';
import { type RawData, WebSocket } from 'ws';
public getHeartbeatInterval(): number {
const HeartbeatInterval = getConfigurationKey(this, StandardParametersKey.HeartbeatInterval);
if (HeartbeatInterval) {
- return convertToInt(HeartbeatInterval.value) * 1000;
+ return secondsToMilliseconds(convertToInt(HeartbeatInterval.value));
}
const HeartBeatInterval = getConfigurationKey(this, StandardParametersKey.HeartBeatInterval);
if (HeartBeatInterval) {
- return convertToInt(HeartBeatInterval.value) * 1000;
+ return secondsToMilliseconds(convertToInt(HeartBeatInterval.value));
}
this.stationInfo?.autoRegister === false &&
logger.warn(
public startMeterValues(connectorId: number, interval: number): void {
if (connectorId === 0) {
logger.error(
- `${this.logPrefix()} Trying to start MeterValues on connector id ${connectorId.toString()}`,
+ `${this.logPrefix()} Trying to start MeterValues on connector id ${connectorId}`,
);
return;
}
if (!this.getConnectorStatus(connectorId)) {
logger.error(
`${this.logPrefix()} Trying to start MeterValues on non existing connector id
- ${connectorId.toString()}`,
+ ${connectorId}`,
);
return;
}
terminateOpened: false,
},
): void {
- options = { handshakeTimeout: this.getConnectionTimeout() * 1000, ...options };
+ options = { handshakeTimeout: secondsToMilliseconds(this.getConnectionTimeout()), ...options };
params = { ...{ closeOpened: false, terminateOpened: false }, ...params };
if (this.started === false && this.starting === false) {
logger.warn(
public startReservationExpirationSetInterval(customInterval?: number): void {
const interval =
customInterval ?? Constants.DEFAULT_RESERVATION_EXPIRATION_OBSERVATION_INTERVAL;
- logger.info(
- `${this.logPrefix()} Reservation expiration date interval is set to ${interval}
- and starts on charging station now`,
- );
if (interval > 0) {
+ logger.info(
+ `${this.logPrefix()} Reservation expiration date checks started every ${formatDurationMilliSeconds(
+ interval,
+ )}`,
+ );
this.reservationExpirationSetInterval = setInterval((): void => {
const currentDate = new Date();
if (this.hasEvses) {
stationTemplate?.firmwareUpgrade ?? {},
);
stationInfo.resetTime = !isNullOrUndefined(stationTemplate?.resetTime)
- ? stationTemplate.resetTime! * 1000
+ ? secondsToMilliseconds(stationTemplate.resetTime!)
: Constants.CHARGING_STATION_DEFAULT_RESET_TIME;
stationInfo.maximumAmperage = this.getMaximumAmperage(stationInfo);
return stationInfo;
if (this.stationInfo?.autoRegister === true) {
this.bootNotificationResponse = {
currentTime: new Date(),
- interval: this.getHeartbeatInterval() / 1000,
+ interval: millisecondsToSeconds(this.getHeartbeatInterval()),
status: RegistrationStatusEnumType.ACCEPTED,
};
}
this.getRegistrationMaxRetries() !== -1 && ++registrationRetryCount;
await sleep(
this?.bootNotificationResponse?.interval
- ? this.bootNotificationResponse.interval * 1000
+ ? secondsToMilliseconds(this.bootNotificationResponse.interval)
: Constants.DEFAULT_BOOT_NOTIFICATION_INTERVAL,
);
}
if (this.isWebSocketConnectionOpened() === true) {
this.wsConnection?.ping();
}
- }, webSocketPingInterval * 1000);
+ }, secondsToMilliseconds(webSocketPingInterval));
logger.info(
`${this.logPrefix()} WebSocket ping started every ${formatDurationSeconds(
webSocketPingInterval,
++this.autoReconnectRetryCount;
const reconnectDelay = this.getReconnectExponentialDelay()
? exponentialDelay(this.autoReconnectRetryCount)
- : this.getConnectionTimeout() * 1000;
+ : secondsToMilliseconds(this.getConnectionTimeout());
const reconnectDelayWithdraw = 1000;
const reconnectTimeout =
reconnectDelay && reconnectDelay - reconnectDelayWithdraw > 0