From: Jérôme Benoit Date: Sun, 2 Nov 2025 12:44:07 +0000 (+0100) Subject: refactor: factor out OCPP2 MeterValues types definition X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=a830001c57a5fc36ca076c85d582497cb0277f52;p=e-mobility-charging-stations-simulator.git refactor: factor out OCPP2 MeterValues types definition Signed-off-by: Jérôme Benoit --- diff --git a/src/types/index.ts b/src/types/index.ts index 3e29b8d4..5600888d 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -149,13 +149,24 @@ export { GenericDeviceModelStatusEnumType, OCPP20ComponentName, OCPP20ConnectorStatusEnumType, - OCPP20MeasurandEnumType, ReasonCodeEnumType, ReportBaseEnumType, type ReportDataType, ResetEnumType, ResetStatusEnumType, } from './ocpp/2.0/Common.js' +export { + OCPP20LocationEnumType, + OCPP20MeasurandEnumType, + type OCPP20MeterValue, + type OCPP20MeterValuesRequest, + type OCPP20MeterValuesResponse, + OCPP20PhaseEnumType, + OCPP20ReadingContextEnumType, + type OCPP20SampledValue, + type OCPP20SignedMeterValue, + type OCPP20UnitOfMeasure, +} from './ocpp/2.0/MeterValues.js' export { type OCPP20BootNotificationRequest, type OCPP20ClearCacheRequest, diff --git a/src/types/ocpp/2.0/Common.ts b/src/types/ocpp/2.0/Common.ts index 0d88442f..c5f370a8 100644 --- a/src/types/ocpp/2.0/Common.ts +++ b/src/types/ocpp/2.0/Common.ts @@ -196,47 +196,6 @@ export enum OCPP20ConnectorStatusEnumType { Unavailable = 'Unavailable', } -export enum OCPP20MeasurandEnumType { - CURRENT_EXPORT = 'Current.Export', - CURRENT_IMPORT = 'Current.Import', - CURRENT_OFFERED = 'Current.Offered', - ENERGY_ACTIVE_EXPORT_INTERVAL = 'Energy.Active.Export.Interval', - ENERGY_ACTIVE_EXPORT_REGISTER = 'Energy.Active.Export.Register', - ENERGY_ACTIVE_IMPORT_INTERVAL = 'Energy.Active.Import.Interval', - ENERGY_ACTIVE_IMPORT_REGISTER = 'Energy.Active.Import.Register', - ENERGY_ACTIVE_NET = 'Energy.Active.Net', - ENERGY_APPARENT_EXPORT = 'Energy.Apparent.Export', - ENERGY_APPARENT_IMPORT = 'Energy.Apparent.Import', - ENERGY_APPARENT_NET = 'Energy.Apparent.Net', - ENERGY_REACTIVE_EXPORT_INTERVAL = 'Energy.Reactive.Export.Interval', - ENERGY_REACTIVE_EXPORT_REGISTER = 'Energy.Reactive.Export.Register', - ENERGY_REACTIVE_IMPORT_INTERVAL = 'Energy.Reactive.Import.Interval', - ENERGY_REACTIVE_IMPORT_REGISTER = 'Energy.Reactive.Import.Register', - ENERGY_REACTIVE_NET = 'Energy.Reactive.Net', - FREQUENCY = 'Frequency', - POWER_ACTIVE_EXPORT = 'Power.Active.Export', - POWER_ACTIVE_IMPORT = 'Power.Active.Import', - POWER_FACTOR = 'Power.Factor', - POWER_OFFERED = 'Power.Offered', - POWER_REACTIVE_EXPORT = 'Power.Reactive.Export', - POWER_REACTIVE_IMPORT = 'Power.Reactive.Import', - STATE_OF_CHARGE = 'SoC', - VOLTAGE = 'Voltage', -} - -export enum OCPP20PhaseEnumType { - L1 = 'L1', - L1_L2 = 'L1-L2', - L1_N = 'L1-N', - L2 = 'L2', - L2_L3 = 'L2-L3', - L2_N = 'L2-N', - L3 = 'L3', - L3_L1 = 'L3-L1', - L3_N = 'L3-N', - N = 'N', -} - export enum OperationalStatusEnumType { Inoperative = 'Inoperative', Operative = 'Operative', diff --git a/src/types/ocpp/2.0/MeterValues.ts b/src/types/ocpp/2.0/MeterValues.ts new file mode 100644 index 00000000..503ca447 --- /dev/null +++ b/src/types/ocpp/2.0/MeterValues.ts @@ -0,0 +1,102 @@ +import type { EmptyObject } from '../../EmptyObject.js' +import type { JsonObject } from '../../JsonType.js' +import type { CustomDataType } from './Common.js' + +export enum OCPP20LocationEnumType { + Body = 'Body', + Cable = 'Cable', + EV = 'EV', + Inlet = 'Inlet', + Outlet = 'Outlet', +} + +export enum OCPP20MeasurandEnumType { + CURRENT_EXPORT = 'Current.Export', + CURRENT_IMPORT = 'Current.Import', + CURRENT_OFFERED = 'Current.Offered', + ENERGY_ACTIVE_EXPORT_INTERVAL = 'Energy.Active.Export.Interval', + ENERGY_ACTIVE_EXPORT_REGISTER = 'Energy.Active.Export.Register', + ENERGY_ACTIVE_IMPORT_INTERVAL = 'Energy.Active.Import.Interval', + ENERGY_ACTIVE_IMPORT_REGISTER = 'Energy.Active.Import.Register', + ENERGY_ACTIVE_NET = 'Energy.Active.Net', + ENERGY_APPARENT_EXPORT = 'Energy.Apparent.Export', + ENERGY_APPARENT_IMPORT = 'Energy.Apparent.Import', + ENERGY_APPARENT_NET = 'Energy.Apparent.Net', + ENERGY_REACTIVE_EXPORT_INTERVAL = 'Energy.Reactive.Export.Interval', + ENERGY_REACTIVE_EXPORT_REGISTER = 'Energy.Reactive.Export.Register', + ENERGY_REACTIVE_IMPORT_INTERVAL = 'Energy.Reactive.Import.Interval', + ENERGY_REACTIVE_IMPORT_REGISTER = 'Energy.Reactive.Import.Register', + ENERGY_REACTIVE_NET = 'Energy.Reactive.Net', + FREQUENCY = 'Frequency', + POWER_ACTIVE_EXPORT = 'Power.Active.Export', + POWER_ACTIVE_IMPORT = 'Power.Active.Import', + POWER_FACTOR = 'Power.Factor', + POWER_OFFERED = 'Power.Offered', + POWER_REACTIVE_EXPORT = 'Power.Reactive.Export', + POWER_REACTIVE_IMPORT = 'Power.Reactive.Import', + STATE_OF_CHARGE = 'SoC', + VOLTAGE = 'Voltage', +} + +export enum OCPP20PhaseEnumType { + L1 = 'L1', + L1_L2 = 'L1-L2', + L1_N = 'L1-N', + L2 = 'L2', + L2_L3 = 'L2-L3', + L2_N = 'L2-N', + L3 = 'L3', + L3_L1 = 'L3-L1', + L3_N = 'L3-N', + N = 'N', +} + +export enum OCPP20ReadingContextEnumType { + INTERRUPTION_BEGIN = 'Interruption.Begin', + INTERRUPTION_END = 'Interruption.End', + OTHER = 'Other', + SAMPLE_CLOCK = 'Sample.Clock', + SAMPLE_PERIODIC = 'Sample.Periodic', + TRANSACTION_BEGIN = 'Transaction.Begin', + TRANSACTION_END = 'Transaction.End', + TRIGGER = 'Trigger', +} + +export interface OCPP20MeterValue extends JsonObject { + customData?: CustomDataType + sampledValue: OCPP20SampledValue[] // minItems: 1 + timestamp: Date +} + +export interface OCPP20MeterValuesRequest extends JsonObject { + customData?: CustomDataType + evseId: number + meterValue: OCPP20MeterValue[] // minItems: 1 +} + +export type OCPP20MeterValuesResponse = EmptyObject + +export interface OCPP20SampledValue extends JsonObject { + context?: OCPP20ReadingContextEnumType + customData?: CustomDataType + location?: OCPP20LocationEnumType + measurand?: OCPP20MeasurandEnumType + phase?: OCPP20PhaseEnumType + signedMeterValue?: OCPP20SignedMeterValue + unitOfMeasure?: OCPP20UnitOfMeasure + value: number +} + +export interface OCPP20SignedMeterValue extends JsonObject { + customData?: CustomDataType + encodingMethod: string // maxLength: 50 + publicKey: string // Base64 encoded, maxLength: 2500 + signedMeterData: string // Base64 encoded, maxLength: 2500 + signingMethod: string // maxLength: 50 +} + +export interface OCPP20UnitOfMeasure extends JsonObject { + customData?: CustomDataType + multiplier?: number // Default: 0 + unit?: string // Default: "Wh" +} diff --git a/src/types/ocpp/MeterValues.ts b/src/types/ocpp/MeterValues.ts index 82a1bce6..ff377bf7 100644 --- a/src/types/ocpp/MeterValues.ts +++ b/src/types/ocpp/MeterValues.ts @@ -7,7 +7,12 @@ import { OCPP16MeterValueUnit, type OCPP16SampledValue, } from './1.6/MeterValues.js' -import { OCPP20MeasurandEnumType, OCPP20PhaseEnumType } from './2.0/Common.js' +import { + OCPP20LocationEnumType, + OCPP20MeasurandEnumType, + OCPP20PhaseEnumType, + OCPP20ReadingContextEnumType, +} from './2.0/MeterValues.js' export type MeterValue = OCPP16MeterValue @@ -19,15 +24,17 @@ export type MeterValueUnit = OCPP16MeterValueUnit export const MeterValueContext = { ...OCPP16MeterValueContext, + ...OCPP20ReadingContextEnumType, } as const // eslint-disable-next-line @typescript-eslint/no-redeclare -export type MeterValueContext = OCPP16MeterValueContext +export type MeterValueContext = OCPP16MeterValueContext | OCPP20ReadingContextEnumType export const MeterValueLocation = { ...OCPP16MeterValueLocation, + ...OCPP20LocationEnumType, } as const // eslint-disable-next-line @typescript-eslint/no-redeclare -export type MeterValueLocation = OCPP16MeterValueLocation +export type MeterValueLocation = OCPP16MeterValueLocation | OCPP20LocationEnumType export const MeterValueMeasurand = { ...OCPP16MeterValueMeasurand,