// Partial Copyright Jerome Benoit. 2021-2023. All Rights Reserved.
-import { AsyncResource } from 'node:async_hooks';
-
import { hoursToMilliseconds, secondsToMilliseconds } from 'date-fns';
import type { ChargingStation } from './ChargingStation';
sleep,
} from '../utils';
-const moduleName = 'AutomaticTransactionGenerator';
-
-export class AutomaticTransactionGenerator extends AsyncResource {
+export class AutomaticTransactionGenerator {
private static readonly instances: Map<string, AutomaticTransactionGenerator> = new Map<
string,
AutomaticTransactionGenerator
private readonly chargingStation: ChargingStation;
private constructor(chargingStation: ChargingStation) {
- super(moduleName);
this.started = false;
this.starting = false;
this.stopping = false;
throw new BaseError(`Connector ${connectorId} does not exist`);
}
if (this.connectorsStatus.get(connectorId)?.start === false) {
- this.runInAsyncScope(
- this.internalStartConnector.bind(this) as (
- this: AutomaticTransactionGenerator,
- ...args: unknown[]
- ) => Promise<void>,
- this,
- connectorId,
- ).catch(Constants.EMPTY_FUNCTION);
+ this.internalStartConnector(connectorId).catch(Constants.EMPTY_FUNCTION);
} else if (this.connectorsStatus.get(connectorId)?.start === true) {
logger.warn(`${this.logPrefix(connectorId)} is already started on connector`);
}
commandPayload: ResetRequest,
): GenericResponse {
const { type } = commandPayload;
- this.runInAsyncScope(
- chargingStation.reset.bind(chargingStation) as (
- this: ChargingStation,
- ...args: unknown[]
- ) => Promise<void>,
- chargingStation,
- `${type}Reset` as OCPP16StopTransactionReason,
- ).catch(Constants.EMPTY_FUNCTION);
+ chargingStation
+ .reset(`${type}Reset` as OCPP16StopTransactionReason)
+ .catch(Constants.EMPTY_FUNCTION);
logger.info(
`${chargingStation.logPrefix()} ${type} reset command received, simulating it. The station will be back online in ${formatDurationMilliSeconds(
chargingStation.stationInfo.resetTime!,
retrieveDate = convertToDate(retrieveDate)!;
const now = Date.now();
if (retrieveDate?.getTime() <= now) {
- this.runInAsyncScope(
- this.updateFirmwareSimulation.bind(this) as (
- this: OCPP16IncomingRequestService,
- ...args: unknown[]
- ) => Promise<void>,
- this,
- chargingStation,
- ).catch(Constants.EMPTY_FUNCTION);
+ this.updateFirmwareSimulation(chargingStation).catch(Constants.EMPTY_FUNCTION);
} else {
setTimeout(
() => {
- this.runInAsyncScope(
- this.updateFirmwareSimulation.bind(this) as (
- this: OCPP16IncomingRequestService,
- ...args: unknown[]
- ) => Promise<void>,
- this,
- chargingStation,
- ).catch(Constants.EMPTY_FUNCTION);
+ this.updateFirmwareSimulation(chargingStation).catch(Constants.EMPTY_FUNCTION);
},
retrieveDate?.getTime() - now,
);
-import { AsyncResource } from 'node:async_hooks';
-
import Ajv, { type JSONSchemaType, type ValidateFunction } from 'ajv';
import ajvFormats from 'ajv-formats';
const moduleName = 'OCPPIncomingRequestService';
-export abstract class OCPPIncomingRequestService extends AsyncResource {
+export abstract class OCPPIncomingRequestService {
private static instance: OCPPIncomingRequestService | null = null;
private readonly version: OCPPVersion;
private readonly ajv: Ajv;
protected abstract jsonSchemas: Map<IncomingRequestCommand, JSONSchemaType<JsonType>>;
protected constructor(version: OCPPVersion) {
- super(moduleName);
this.version = version;
this.ajv = new Ajv({
keywords: ['javaType'],