+import { secondsToMilliseconds } from 'date-fns';
+
import { WorkerBroadcastChannel } from './WorkerBroadcastChannel';
import { BaseError, type OCPPError } from '../../exception';
import {
DataTransferStatus,
type DiagnosticsStatusNotificationRequest,
type DiagnosticsStatusNotificationResponse,
+ type EmptyObject,
type FirmwareStatusNotificationRequest,
type FirmwareStatusNotificationResponse,
type HeartbeatRequest,
} from '../../types';
import { Constants, convertToInt, isEmptyObject, isNullOrUndefined, logger } from '../../utils';
import type { ChargingStation } from '../ChargingStation';
-import { ChargingStationConfigurationUtils } from '../ChargingStationConfigurationUtils';
+import { getConfigurationKey } from '../ConfigurationKeyUtils';
import { OCPP16ServiceUtils } from '../ocpp';
const moduleName = 'ChargingStationWorkerBroadcastChannel';
type CommandResponse =
+ | EmptyObject
| StartTransactionResponse
| StopTransactionResponse
| AuthorizeResponse
| BootNotificationResponse
- | StatusNotificationResponse
| HeartbeatResponse
| DataTransferResponse;
[
BroadcastChannelProcedureName.METER_VALUES,
async (requestPayload?: BroadcastChannelRequestPayload) => {
- const configuredMeterValueSampleInterval =
- ChargingStationConfigurationUtils.getConfigurationKey(
- chargingStation,
- StandardParametersKey.MeterValueSampleInterval,
- );
+ const configuredMeterValueSampleInterval = getConfigurationKey(
+ chargingStation,
+ StandardParametersKey.MeterValueSampleInterval,
+ );
return this.chargingStation.ocppRequestService.requestHandler<
MeterValuesRequest,
MeterValuesResponse
this.chargingStation.getConnectorStatus(requestPayload!.connectorId!)!
.transactionId!,
configuredMeterValueSampleInterval
- ? convertToInt(configuredMeterValueSampleInterval.value) * 1000
+ ? secondsToMilliseconds(convertToInt(configuredMeterValueSampleInterval.value))
: Constants.DEFAULT_METER_VALUES_INTERVAL,
),
],
}
const [uuid, command, requestPayload] = validatedMessageEvent.data as BroadcastChannelRequest;
if (
- !isNullOrUndefined(requestPayload?.hashIds) &&
- requestPayload?.hashIds?.includes(this.chargingStation.stationInfo.hashId) === false
+ !isNullOrUndefined(requestPayload.hashIds) &&
+ requestPayload.hashIds?.includes(this.chargingStation.stationInfo.hashId) === false
) {
return;
}
- if (!isNullOrUndefined(requestPayload?.hashId)) {
+ if (!isNullOrUndefined(requestPayload.hashId)) {
logger.error(
`${this.chargingStation.logPrefix()} ${moduleName}.requestHandler: 'hashId' field usage in PDU is deprecated, use 'hashIds' array instead`,
);
this.cleanRequestPayload(command, requestPayload);
return this.commandHandlers.get(command)!(requestPayload);
}
- throw new BaseError(`Unknown worker broadcast channel command: ${command}`);
+ throw new BaseError(`Unknown worker broadcast channel command: '${command}'`);
}
private cleanRequestPayload(