]> Piment Noir Git Repositories - e-mobility-charging-stations-simulator.git/commitdiff
refactor: factor out OCPP2 MeterValues types definition
authorJérôme Benoit <jerome.benoit@sap.com>
Sun, 2 Nov 2025 12:44:07 +0000 (13:44 +0100)
committerJérôme Benoit <jerome.benoit@sap.com>
Sun, 2 Nov 2025 12:44:07 +0000 (13:44 +0100)
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
src/types/index.ts
src/types/ocpp/2.0/Common.ts
src/types/ocpp/2.0/MeterValues.ts [new file with mode: 0644]
src/types/ocpp/MeterValues.ts

index 3e29b8d4b1b9e17da023595ebc7220fdf014e81f..5600888d7b5e54d1661864f68cf7fc77bdce22f5 100644 (file)
@@ -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,
index 0d88442fa1f3ee5a95d237c1d0b515bcdb6af4d1..c5f370a84b4df04e9dcebe9fde564abed69e8efb 100644 (file)
@@ -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 (file)
index 0000000..503ca44
--- /dev/null
@@ -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"
+}
index 82a1bce6b67169a83c4a286ace3a12a4036c2f43..ff377bf728754da0e71e959cd806d6cd8641cece 100644 (file)
@@ -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,