logger,
} from '../../utils/index.js'
import { getConfigurationKey } from '../ConfigurationKeyUtils.js'
-import { buildMeterValue } from '../ocpp/index.js'
+import { buildMeterValue, OCPP20ServiceUtils } from '../ocpp/index.js'
import { WorkerBroadcastChannel } from './WorkerBroadcastChannel.js'
const moduleName = 'ChargingStationWorkerBroadcastChannel'
private async handleMeterValues (
requestPayload?: BroadcastChannelRequestPayload
): Promise<MeterValuesResponse> {
+ const connectorId = requestPayload?.connectorId
if (
this.chargingStation.stationInfo?.ocppVersion === OCPPVersion.VERSION_20 ||
this.chargingStation.stationInfo?.ocppVersion === OCPPVersion.VERSION_201
) {
+ const txUpdatedInterval = OCPP20ServiceUtils.getTxUpdatedInterval(this.chargingStation)
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+ const evseId = this.chargingStation.getEvseIdByConnectorId(connectorId!)
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+ const transactionId = this.chargingStation.getConnectorStatus(connectorId!)?.transactionId
return await this.chargingStation.ocppRequestService.requestHandler<
MeterValuesRequest,
MeterValuesResponse
>(
this.chargingStation,
RequestCommand.METER_VALUES,
- requestPayload as MeterValuesRequest,
+ {
+ evseId,
+ meterValue: [
+ buildMeterValue(
+ this.chargingStation,
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+ connectorId!,
+ transactionId,
+ txUpdatedInterval
+ ),
+ ],
+ ...requestPayload,
+ } as MeterValuesRequest,
this.requestParams
)
}
this.chargingStation,
StandardParametersKey.MeterValueSampleInterval
)
- const connectorId = requestPayload?.connectorId
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const transactionId = this.chargingStation.getConnectorStatus(connectorId!)?.transactionId
return await this.chargingStation.ocppRequestService.requestHandler<
GenericStatus,
GetCertificateStatusEnumType,
Iso15118EVCertificateStatusEnumType,
+ MeterValueMeasurand,
OCPP20AuthorizationStatusEnumType,
OCPPVersion,
ProcedureName,
await it('should dispatch METER_VALUES for OCPP 2.0.1 via requestHandler', async () => {
const { sentRequests, station } = createMockStationWithRequestTracking()
+ // Add MeterValues template to connector 1 so buildMeterValue can construct a valid payload
+ const connectorStatus = station.getConnectorStatus(1)
+ if (connectorStatus != null) {
+ connectorStatus.MeterValues = [
+ {
+ measurand: MeterValueMeasurand.ENERGY_ACTIVE_IMPORT_REGISTER,
+ unit: 'Wh',
+ value: 0,
+ },
+ ]
+ }
+
instance = new ChargingStationWorkerBroadcastChannel(station)
const testable = createTestableWorkerBroadcastChannel(instance)
data: [
randomUUID(),
BroadcastChannelProcedureName.METER_VALUES,
- { hashIds: [station.stationInfo?.hashId] },
+ { connectorId: 1, hashIds: [station.stationInfo?.hashId] },
],
})
assert.strictEqual(sentRequests.length, 1)
assert.strictEqual(sentRequests[0].command, RequestCommand.METER_VALUES)
+ assert.ok(
+ sentRequests[0].payload.evseId != null,
+ 'OCPP 2.0.1 meter values payload should contain evseId'
+ )
+ assert.ok(
+ Array.isArray(sentRequests[0].payload.meterValue),
+ 'OCPP 2.0.1 meter values payload should contain meterValue array'
+ )
})
})