From 17e9e8cef1f7d1cbc4ec6aa4c95d8f3d93c593a6 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Sat, 24 Sep 2022 23:57:03 +0200 Subject: [PATCH] Convert interface to type MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- .../ui-services/AbstractUIService.ts | 4 +++- src/types/ChargingStationInfo.ts | 23 +++++++++---------- src/types/ChargingStationOcppConfiguration.ts | 4 ++-- src/types/ChargingStationWorker.ts | 13 +++++++---- .../MeasurandPerPhaseSampledValueTemplates.ts | 4 ++-- src/utils/ElectricUtils.ts | 4 ++++ src/utils/Logger.ts | 2 +- 7 files changed, 32 insertions(+), 22 deletions(-) diff --git a/src/charging-station/ui-server/ui-services/AbstractUIService.ts b/src/charging-station/ui-server/ui-services/AbstractUIService.ts index 64053c42..729b816d 100644 --- a/src/charging-station/ui-server/ui-services/AbstractUIService.ts +++ b/src/charging-station/ui-server/ui-services/AbstractUIService.ts @@ -24,7 +24,9 @@ const moduleName = 'AbstractUIService'; export default abstract class AbstractUIService { private static readonly ProcedureNameToBroadCastChannelProcedureNameMap: Omit< Record, - 'startSimulator' | 'stopSimulator' | 'listChargingStations' + | ProcedureName.START_SIMULATOR + | ProcedureName.STOP_SIMULATOR + | ProcedureName.LIST_CHARGING_STATIONS > = { [ProcedureName.START_CHARGING_STATION]: BroadcastChannelProcedureName.START_CHARGING_STATION, [ProcedureName.STOP_CHARGING_STATION]: BroadcastChannelProcedureName.STOP_CHARGING_STATION, diff --git a/src/types/ChargingStationInfo.ts b/src/types/ChargingStationInfo.ts index f83ba030..65098870 100644 --- a/src/types/ChargingStationInfo.ts +++ b/src/types/ChargingStationInfo.ts @@ -1,16 +1,15 @@ import type { ChargingStationTemplate } from './ChargingStationTemplate'; -export interface ChargingStationInfo - extends Omit< - ChargingStationTemplate, - | 'AutomaticTransactionGenerator' - | 'Configuration' - | 'power' - | 'powerUnit' - | 'chargeBoxSerialNumberPrefix' - | 'chargePointSerialNumberPrefix' - | 'meterSerialNumberPrefix' - > { +export type ChargingStationInfo = Omit< + ChargingStationTemplate, + | 'AutomaticTransactionGenerator' + | 'Configuration' + | 'power' + | 'powerUnit' + | 'chargeBoxSerialNumberPrefix' + | 'chargePointSerialNumberPrefix' + | 'meterSerialNumberPrefix' +> & { hashId: string; infoHash?: string; chargingStationId?: string; @@ -19,7 +18,7 @@ export interface ChargingStationInfo meterSerialNumber?: string; maximumPower?: number; // Always in Watt maximumAmperage?: number; // Always in Ampere -} +}; export type ChargingStationInfoConfiguration = { stationInfo?: ChargingStationInfo; diff --git a/src/types/ChargingStationOcppConfiguration.ts b/src/types/ChargingStationOcppConfiguration.ts index 77c38f04..834b1d1d 100644 --- a/src/types/ChargingStationOcppConfiguration.ts +++ b/src/types/ChargingStationOcppConfiguration.ts @@ -1,9 +1,9 @@ import type { OCPPConfigurationKey } from './ocpp/Configuration'; -export interface ConfigurationKey extends OCPPConfigurationKey { +export type ConfigurationKey = OCPPConfigurationKey & { visible?: boolean; reboot?: boolean; -} +}; export type ChargingStationOcppConfiguration = { configurationKey?: ConfigurationKey[]; diff --git a/src/types/ChargingStationWorker.ts b/src/types/ChargingStationWorker.ts index 3604a85d..ec6e92b5 100644 --- a/src/types/ChargingStationWorker.ts +++ b/src/types/ChargingStationWorker.ts @@ -1,3 +1,5 @@ +import type { WebSocket } from 'ws'; + import type { Status } from './AutomaticTransactionGenerator'; import type { ChargingStationInfo } from './ChargingStationInfo'; import type { ConnectorStatus } from './ConnectorStatus'; @@ -19,7 +21,11 @@ export interface ChargingStationWorkerData extends WorkerData { export interface ChargingStationData extends WorkerData { stationInfo: ChargingStationInfo; started: boolean; - wsState?: number; + wsState?: + | typeof WebSocket.CONNECTING + | typeof WebSocket.OPEN + | typeof WebSocket.CLOSING + | typeof WebSocket.CLOSED; bootNotificationResponse: BootNotificationResponse; connectors: ConnectorStatus[]; automaticTransactionGeneratorStatuses?: Status[]; @@ -41,7 +47,6 @@ export const ChargingStationWorkerMessageEvents = { export type ChargingStationWorkerMessageData = ChargingStationData | Statistics; -export interface ChargingStationWorkerMessage - extends Omit, 'id'> { +export type ChargingStationWorkerMessage = Omit, 'id'> & { id: ChargingStationWorkerMessageEvents; -} +}; diff --git a/src/types/MeasurandPerPhaseSampledValueTemplates.ts b/src/types/MeasurandPerPhaseSampledValueTemplates.ts index 34ead1a5..2a534b4a 100644 --- a/src/types/MeasurandPerPhaseSampledValueTemplates.ts +++ b/src/types/MeasurandPerPhaseSampledValueTemplates.ts @@ -1,8 +1,8 @@ import type { SampledValue } from './ocpp/MeterValues'; -export interface SampledValueTemplate extends SampledValue { +export type SampledValueTemplate = SampledValue & { fluctuationPercent?: number; -} +}; export type MeasurandPerPhaseSampledValueTemplates = { L1?: SampledValueTemplate; diff --git a/src/utils/ElectricUtils.ts b/src/utils/ElectricUtils.ts index 9f0c680a..b779bf1d 100644 --- a/src/utils/ElectricUtils.ts +++ b/src/utils/ElectricUtils.ts @@ -50,6 +50,10 @@ export class ACElectricUtils { * Targeted to DC related values calculation. */ export class DCElectricUtils { + private constructor() { + // This is intentional + } + static power(V: number, I: number): number { return V * I; } diff --git a/src/utils/Logger.ts b/src/utils/Logger.ts index 1baea780..95d5347d 100644 --- a/src/utils/Logger.ts +++ b/src/utils/Logger.ts @@ -38,7 +38,7 @@ if (Configuration.getLogRotate()) { const logger: Logger = createLogger({ level: Configuration.getLogLevel(), format: format.combine(format.splat(), (format[Configuration.getLogFormat()] as () => Format)()), - transports: transports, + transports, }); // -- 2.34.1