From: Jérôme Benoit Date: Tue, 21 Oct 2025 17:05:08 +0000 (+0200) Subject: refactor: cleanups OCPP2 types X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=374ef8f2b6c4d1ffe4eb5a23e52c9c1c02619dff;p=e-mobility-charging-stations-simulator.git refactor: cleanups OCPP2 types Signed-off-by: Jérôme Benoit --- diff --git a/src/charging-station/ocpp/2.0/OCPP20IncomingRequestService.ts b/src/charging-station/ocpp/2.0/OCPP20IncomingRequestService.ts index 1fb65e8c..f2eb02ee 100644 --- a/src/charging-station/ocpp/2.0/OCPP20IncomingRequestService.ts +++ b/src/charging-station/ocpp/2.0/OCPP20IncomingRequestService.ts @@ -348,7 +348,7 @@ export class OCPP20IncomingRequestService extends OCPPIncomingRequestService { const stationInfo = chargingStation.stationInfo if (stationInfo.chargePointModel) { reportData.push({ - component: { name: 'ChargingStation' }, + component: { name: OCPP20ComponentName.DeviceDataCtrlr }, variable: { name: 'Model' }, variableAttribute: [{ type: 'Actual', value: stationInfo.chargePointModel }], variableCharacteristics: { dataType: 'string', supportsMonitoring: false }, @@ -356,7 +356,7 @@ export class OCPP20IncomingRequestService extends OCPPIncomingRequestService { } if (stationInfo.chargePointVendor) { reportData.push({ - component: { name: 'ChargingStation' }, + component: { name: OCPP20ComponentName.DeviceDataCtrlr }, variable: { name: 'VendorName' }, variableAttribute: [{ type: 'Actual', value: stationInfo.chargePointVendor }], variableCharacteristics: { dataType: 'string', supportsMonitoring: false }, @@ -364,7 +364,7 @@ export class OCPP20IncomingRequestService extends OCPPIncomingRequestService { } if (stationInfo.firmwareVersion) { reportData.push({ - component: { name: 'ChargingStation' }, + component: { name: OCPP20ComponentName.DeviceDataCtrlr }, variable: { name: 'FirmwareVersion' }, variableAttribute: [{ type: 'Actual', value: stationInfo.firmwareVersion }], variableCharacteristics: { dataType: 'string', supportsMonitoring: false }, diff --git a/src/types/index.ts b/src/types/index.ts index 1ab04353..bf4024f4 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -144,8 +144,10 @@ export { export { BootReasonEnumType, GenericDeviceModelStatusEnumType, + OCPP20ComponentName, OCPP20ConnectorStatusEnumType, ReportBaseEnumType, + type ReportDataType, } from './ocpp/2.0/Common.js' export { type OCPP20BootNotificationRequest, @@ -156,9 +158,6 @@ export { type OCPP20NotifyReportRequest, OCPP20RequestCommand, type OCPP20StatusNotificationRequest, - type ReportDataType, - type VariableAttributeType, - type VariableCharacteristicsType, } from './ocpp/2.0/Requests.js' export type { OCPP20BootNotificationResponse, @@ -168,7 +167,7 @@ export type { OCPP20NotifyReportResponse, OCPP20StatusNotificationResponse, } from './ocpp/2.0/Responses.js' -export { OCPP20ComponentName, OCPP20OptionalVariableName } from './ocpp/2.0/Variables.js' +export { OCPP20OptionalVariableName } from './ocpp/2.0/Variables.js' export { ChargePointErrorCode } from './ocpp/ChargePointErrorCode.js' export { type ChargingProfile, diff --git a/src/types/ocpp/2.0/Common.ts b/src/types/ocpp/2.0/Common.ts index a8a058a6..2a16d840 100644 --- a/src/types/ocpp/2.0/Common.ts +++ b/src/types/ocpp/2.0/Common.ts @@ -1,5 +1,6 @@ import type { JsonObject } from '../../JsonType.js' import type { GenericStatus } from '../Common.js' +import type { VariableType } from './Variables.js' export enum BootReasonEnumType { ApplicationReset = 'ApplicationReset', @@ -84,6 +85,27 @@ export enum InstallCertificateUseEnumType { V2GRootCertificate = 'V2GRootCertificate', } +export enum OCPP20ComponentName { + AlignedDataCtrlr = 'AlignedDataCtrlr', + AuthCacheCtrlr = 'AuthCacheCtrlr', + AuthCtrlr = 'AuthCtrlr', + CHAdeMOCtrlr = 'CHAdeMOCtrlr', + ClockCtrlr = 'ClockCtrlr', + CustomizationCtrlr = 'CustomizationCtrlr', + DeviceDataCtrlr = 'DeviceDataCtrlr', + DisplayMessageCtrlr = 'DisplayMessageCtrlr', + ISO15118Ctrlr = 'ISO15118Ctrlr', + LocalAuthListCtrlr = 'LocalAuthListCtrlr', + MonitoringCtrlr = 'MonitoringCtrlr', + OCPPCommCtrlr = 'OCPPCommCtrlr', + ReservationCtrlr = 'ReservationCtrlr', + SampledDataCtrlr = 'SampledDataCtrlr', + SecurityCtrlr = 'SecurityCtrlr', + SmartChargingCtrlr = 'SmartChargingCtrlr', + TariffCostCtrlr = 'TariffCostCtrlr', + TxCtrlr = 'TxCtrlr', +} + export enum OCPP20ConnectorEnumType { cCCS1 = 'cCCS1', cCCS2 = 'cCCS2', @@ -143,6 +165,19 @@ export interface CertificateHashDataType extends JsonObject { export type CertificateSignedStatusEnumType = GenericStatusEnumType +export interface ChargingStationType extends JsonObject { + firmwareVersion?: string + model: string + modem?: ModemType + serialNumber?: string + vendorName: string +} +export interface ComponentType extends JsonObject { + evse?: EVSEType + instance?: string + name: OCPP20ComponentName | string +} + export interface EVSEType extends JsonObject { connectorId?: string id: number @@ -158,7 +193,29 @@ export interface OCSPRequestDataType extends JsonObject { serialNumber: string } +export interface ReportDataType extends JsonObject { + component: ComponentType + variable: VariableType + variableAttribute?: VariableAttributeType[] + variableCharacteristics?: VariableCharacteristicsType +} + export interface StatusInfoType extends JsonObject { additionalInfo?: string reasonCode: string } + +interface ModemType extends JsonObject { + iccid?: string + imsi?: string +} + +interface VariableAttributeType extends JsonObject { + type?: string + value?: string +} + +interface VariableCharacteristicsType extends JsonObject { + dataType: string + supportsMonitoring: boolean +} diff --git a/src/types/ocpp/2.0/Requests.ts b/src/types/ocpp/2.0/Requests.ts index e4edd597..f3c42d4d 100644 --- a/src/types/ocpp/2.0/Requests.ts +++ b/src/types/ocpp/2.0/Requests.ts @@ -2,16 +2,13 @@ import type { EmptyObject } from '../../EmptyObject.js' import type { JsonObject } from '../../JsonType.js' import type { BootReasonEnumType, + ChargingStationType, InstallCertificateUseEnumType, OCPP20ConnectorStatusEnumType, ReportBaseEnumType, + ReportDataType, } from './Common.js' -import type { - ChargingStationType, - ComponentType, - OCPP20SetVariableDataType, - VariableType, -} from './Variables.js' +import type { OCPP20SetVariableDataType } from './Variables.js' export enum OCPP20IncomingRequestCommand { CLEAR_CACHE = 'ClearCache', @@ -64,20 +61,3 @@ export interface OCPP20StatusNotificationRequest extends JsonObject { evseId: number timestamp: Date } - -export interface ReportDataType extends JsonObject { - component: ComponentType - variable: VariableType - variableAttribute?: VariableAttributeType[] - variableCharacteristics?: VariableCharacteristicsType -} - -export interface VariableAttributeType extends JsonObject { - type?: string - value?: string -} - -export interface VariableCharacteristicsType extends JsonObject { - dataType: string - supportsMonitoring: boolean -} diff --git a/src/types/ocpp/2.0/Variables.ts b/src/types/ocpp/2.0/Variables.ts index 02a52eee..9168975c 100644 --- a/src/types/ocpp/2.0/Variables.ts +++ b/src/types/ocpp/2.0/Variables.ts @@ -1,26 +1,5 @@ import type { JsonObject } from '../../JsonType.js' -import type { EVSEType, StatusInfoType } from './Common.js' - -export enum OCPP20ComponentName { - AlignedDataCtrlr = 'AlignedDataCtrlr', - AuthCacheCtrlr = 'AuthCacheCtrlr', - AuthCtrlr = 'AuthCtrlr', - CHAdeMOCtrlr = 'CHAdeMOCtrlr', - ClockCtrlr = 'ClockCtrlr', - CustomizationCtrlr = 'CustomizationCtrlr', - DeviceDataCtrlr = 'DeviceDataCtrlr', - DisplayMessageCtrlr = 'DisplayMessageCtrlr', - ISO15118Ctrlr = 'ISO15118Ctrlr', - LocalAuthListCtrlr = 'LocalAuthListCtrlr', - MonitoringCtrlr = 'MonitoringCtrlr', - OCPPCommCtrlr = 'OCPPCommCtrlr', - ReservationCtrlr = 'ReservationCtrlr', - SampledDataCtrlr = 'SampledDataCtrlr', - SecurityCtrlr = 'SecurityCtrlr', - SmartChargingCtrlr = 'SmartChargingCtrlr', - TariffCostCtrlr = 'TariffCostCtrlr', - TxCtrlr = 'TxCtrlr', -} +import type { ComponentType, StatusInfoType } from './Common.js' export enum OCPP20OptionalVariableName { HeartbeatInterval = 'HeartbeatInterval', @@ -78,20 +57,6 @@ enum SetVariableStatusEnumType { UnknownVariable = 'UnknownVariable', } -export interface ChargingStationType extends JsonObject { - firmwareVersion?: string - model: string - modem?: ModemType - serialNumber?: string - vendorName: string -} - -export interface ComponentType extends JsonObject { - evse?: EVSEType - instance?: string - name: OCPP20ComponentName | string -} - export interface OCPP20ComponentVariableType extends JsonObject { component: ComponentType variable?: VariableType @@ -117,11 +82,6 @@ export interface VariableType extends JsonObject { name: VariableName } -interface ModemType extends JsonObject { - iccid?: string - imsi?: string -} - type VariableName = | OCPP20OptionalVariableName | OCPP20RequiredVariableName