]> Piment Noir Git Repositories - e-mobility-charging-stations-simulator.git/commit
feat(ocpp): add signed meter values support for OCPP 1.6 and 2.0.x (#1775)
authorJérôme Benoit <jerome.benoit@piment-noir.org>
Tue, 7 Apr 2026 17:05:43 +0000 (19:05 +0200)
committerGitHub <noreply@github.com>
Tue, 7 Apr 2026 17:05:43 +0000 (19:05 +0200)
commit7d69543150e590831d93769443cd82d457c825bc
tree93938e118e3ca134212e386f55b7d95a28ad17ed
parentdd828de59d6e65fc7ec0203ab79b6bb9a0a3e644
feat(ocpp): add signed meter values support for OCPP 1.6 and 2.0.x (#1775)

* feat(types): export OCPP16MeterValueFormat and add OCPP16SignedMeterValue

* feat(ocpp1.6): add vendor configuration keys for signed meter values

* feat(ocpp2.0): add variable registry entries for signed meter readings

* feat(mock-server): handle signed meter value payloads

* feat(ocpp): add simulated signed meter data generator

* feat(ocpp): add PublicKeyWithSignedMeterValue enum and state tracking

* feat(ocpp2.0): populate signedMeterValue in sampled value building

* feat(ocpp1.6): add signed meter value support to sampled value building

* feat(templates): add station templates with signed meter value config

* docs: document signed meter values configuration

* fix(lint): apply formatter fixes to signed meter value files

* fix(ocpp): fix publicKey state tracking and reset in signed meter values

* fix(ocpp): fix OCMF payload, hash, and public key encoding

* fix(ocpp): add defensive guards and improve signing code quality

* fix(ocpp2.0): respect SignStartedReadings and SignUpdatedReadings sub-switches

* [autofix.ci] apply automated fixes

* fix(ocpp): consistent publicKey state update, version-gated vendor keys, use enum constants

* [autofix.ci] apply automated fixes

* refactor(ocpp): use union types in common code and correct enum classification per OCPP specs

- Use VendorParametersKey (union) in ChargingStation.ts, not OCPP16VendorParametersKey
- Remove VERSION_16 guard: OCPP2_PARAMETER_KEY_MAP resolves keys per version
- Add 6 mapping entries to OCPP2_PARAMETER_KEY_MAP for signed MV config keys
- Classify enums per OCPP 2.0.1 base spec: SignReadings and
  PublicKeyWithSignedMeterValue in OCPP20OptionalVariableName (Required: no)
- Classify Application Note-only variables (SignStartedReadings,
  SignUpdatedReadings, PublicKey, SigningMethod) in OCPP20VendorVariableName
- Replace all string literals with enum references in variable registry

* [autofix.ci] apply automated fixes

* fix(ocpp): fix corrupted Measurands entry, Wh/kWh unit handling, context mapping, and enum validation

- Fix AlignedDataCtrlr.Measurands variable corrupted by lint auto-sort (was SignUpdatedReadings)
- Add meterValueUnit to SignedMeterDataParams to handle kWh input without double-division
- Replace unsafe context cast with explicit OCPP20-to-generator context mapping
- Extract parsePublicKeyWithSignedMeterValue helper (hoisted Set, shared across OCPP versions)
- Use MeterValueUnit enum constant instead of string literal for kWh comparison

* [autofix.ci] apply automated fixes

* refactor(ocpp): use MeterValueContext/MeterValueUnit enums and barrel imports instead of string literals

* style: apply prettier formatting to SignedMeterDataGenerator test

* fix(ocpp): add vendorSpecific flag, guard publicKey inclusion on key availability, add kWh test

* refactor(ocpp): use PublicKeyWithSignedMeterValueEnumType.Never instead of string literal

* test(ocpp): add JSDoc header, TX=P/Clock tests, non-energy measurand and transactionData force tests

* test(ocpp1.6): add periodic signing tests with mock timers for startUpdatedMeterValues

* refactor(test): use beforeEach for station creation in OCPP16SignedMeterValues per style guide

* fix(ocpp): treat undefined context as periodic for SignUpdatedReadings, conditional try/catch for signing-forced transactionData, use node:assert/strict import

* refactor(ocpp2.0): add defaultValue and enumeration to PublicKeyWithSignedMeterValue registry entry

* refactor(ocpp1.6): remove redundant nullish coalescing on publicKeyHex

* refactor(ocpp): use BaseError, return tuple in OCPP 2.0 builder, extract config reading in OCPP 1.6

* refactor(ocpp): harmonize naming, signatures, and data structures across signing paths

- SignedMeterData extends JsonObject: eliminates as-cast to OCPP16SignedMeterValue
- Rename publicKeyConfig to publicKeyWithSignedMeterValue: consistent with OCPP 2.0 interface
- Rename meterValueWh to meterValue: unit-agnostic (generator handles via meterValueUnit)
- Remove unused OCPP16SignedMeterValue import

* fix(mock-server): log signed meter values in TransactionEvent.Ended and add test

* fix(ocpp): include Transaction.Begin MV in TransactionEvent(Ended) per spec §4.1.2, set signingMethod to empty string per spec §3.2.1

* refactor(ocpp): rename SignedMeter* files to follow OCPP* naming convention

* refactor(ocpp): extract generic SignedSampledValueResult<T> to shared utils

* refactor(ocpp): extract shared SigningConfig interface, OCPP20SampledValueSigningConfig extends it

* refactor(ocpp): use roundTo helper instead of Number/toFixed for kWh conversion

* style(mock-server): reorder signed MV tests to follow Started/Updated/Ended lifecycle

* refactor(ocpp): move SampledValueSigningConfig to shared utils, remove version-specific type import from common code

* fix(ocpp): map StartTxnSampledData to SampledDataCtrlr.TxStartedMeasurands, remove VERSION_16 guard

* [autofix.ci] apply automated fixes

* style: remove unnecessary parenthetical from eslint cspell comment

* style: rename Configuration.test.ts to OCPP16VendorParametersKey.test.ts to reflect content

* refactor(ocpp): rename ocpp20SigningConfig/State to signingConfig/State (version-agnostic)

* style: harmonize blank lines in OCPP20VariableRegistry between component sections

* [autofix.ci] apply automated fixes

* style: remove unjustified blank lines before inline comments within same component section

* fix(ocpp2.0): add missing DeviceDataCtrlr section comment in variable registry

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
31 files changed:
README.md
eslint.config.js
src/assets/station-templates/keba-ocpp2-signed.station-template.json [new file with mode: 0644]
src/assets/station-templates/virtual-simple-signed.station-template.json [new file with mode: 0644]
src/charging-station/ChargingStation.ts
src/charging-station/ConfigurationKeyUtils.ts
src/charging-station/Helpers.ts
src/charging-station/ocpp/1.6/OCPP16RequestBuilders.ts
src/charging-station/ocpp/1.6/OCPP16RequestService.ts
src/charging-station/ocpp/1.6/OCPP16ServiceUtils.ts
src/charging-station/ocpp/2.0/OCPP20RequestBuilders.ts
src/charging-station/ocpp/2.0/OCPP20ServiceUtils.ts
src/charging-station/ocpp/2.0/OCPP20VariableRegistry.ts
src/charging-station/ocpp/OCPPServiceUtils.ts
src/charging-station/ocpp/OCPPSignedMeterDataGenerator.ts [new file with mode: 0644]
src/charging-station/ocpp/OCPPSignedMeterValueUtils.ts [new file with mode: 0644]
src/charging-station/ocpp/index.ts
src/types/ConnectorStatus.ts
src/types/index.ts
src/types/ocpp/1.6/Configuration.ts
src/types/ocpp/1.6/MeterValues.ts
src/types/ocpp/2.0/Variables.ts
src/types/ocpp/Configuration.ts
tests/charging-station/ocpp/1.6/OCPP16SignedMeterValues.test.ts [new file with mode: 0644]
tests/charging-station/ocpp/2.0/OCPP20SignedMeterValues.test.ts [new file with mode: 0644]
tests/charging-station/ocpp/OCPPSignedMeterDataGenerator.test.ts [new file with mode: 0644]
tests/charging-station/ocpp/OCPPSignedMeterValueUtils.test.ts [new file with mode: 0644]
tests/ocpp-server/server.py
tests/ocpp-server/test_server.py
tests/types/ocpp/1.6/MeterValues.test.ts [new file with mode: 0644]
tests/types/ocpp/1.6/OCPP16VendorParametersKey.test.ts [new file with mode: 0644]