) {
if (
this.incomingRequestHandlers.has(commandName) &&
- ChargingStationUtils.isIncomingRequestCommandSupported(commandName, chargingStation)
+ OCPP16ServiceUtils.isIncomingRequestCommandSupported(chargingStation, commandName)
) {
try {
this.validatePayload(chargingStation, commandName, commandPayload);
chargingStation: ChargingStation,
commandPayload: ResetRequest
): DefaultResponse {
- // eslint-disable-next-line @typescript-eslint/no-misused-promises
- setImmediate(async (): Promise<void> => {
- await chargingStation.reset((commandPayload.type + 'Reset') as OCPP16StopTransactionReason);
- });
+ this.asyncResource.runInAsyncScope(
+ chargingStation.reset.bind(chargingStation) as (
+ this: ChargingStation,
+ ...args: any[]
+ ) => void,
+ chargingStation,
+ (commandPayload.type + 'Reset') as OCPP16StopTransactionReason
+ );
logger.info(
`${chargingStation.logPrefix()} ${
commandPayload.type
return Constants.OCPP_RESPONSE_ACCEPTED;
}
- private handleRequestClearCache(): DefaultResponse {
+ private handleRequestClearCache(chargingStation: ChargingStation): DefaultResponse {
+ chargingStation.authorizedTagsCache.deleteAuthorizedTags(
+ ChargingStationUtils.getAuthorizationFile(chargingStation.stationInfo)
+ );
return Constants.OCPP_RESPONSE_ACCEPTED;
}
): GetConfigurationResponse {
const configurationKey: OCPPConfigurationKey[] = [];
const unknownKey: string[] = [];
- if (Utils.isEmptyArray(commandPayload.key)) {
+ if (Utils.isEmptyArray(commandPayload.key) === true) {
for (const configuration of chargingStation.ocppConfiguration.configurationKey) {
- if (Utils.isUndefined(configuration.visible)) {
+ if (Utils.isUndefined(configuration.visible) === true) {
configuration.visible = true;
}
- if (!configuration.visible) {
+ if (configuration.visible === false) {
continue;
}
configurationKey.push({
key
);
if (keyFound) {
- if (Utils.isUndefined(keyFound.visible)) {
+ if (Utils.isUndefined(keyFound.visible) === true) {
keyFound.visible = true;
}
- if (!keyFound.visible) {
+ if (keyFound.visible === false) {
continue;
}
configurationKey.push({
commandPayload: SetChargingProfileRequest
): SetChargingProfileResponse {
if (
- !OCPP16ServiceUtils.checkFeatureProfile(
+ OCPP16ServiceUtils.checkFeatureProfile(
chargingStation,
OCPP16SupportedFeatureProfiles.SmartCharging,
OCPP16IncomingRequestCommand.SET_CHARGING_PROFILE
- )
+ ) === false
) {
return Constants.OCPP_SET_CHARGING_PROFILE_RESPONSE_NOT_SUPPORTED;
}
- if (!chargingStation.getConnectorStatus(commandPayload.connectorId)) {
+ if (chargingStation.connectors.has(commandPayload.connectorId) === false) {
logger.error(
`${chargingStation.logPrefix()} Trying to set charging profile(s) to a non existing connector Id ${
commandPayload.connectorId
) {
return Constants.OCPP_SET_CHARGING_PROFILE_RESPONSE_REJECTED;
}
- chargingStation.setChargingProfile(
+ OCPP16ServiceUtils.setChargingProfile(
+ chargingStation,
commandPayload.connectorId,
commandPayload.csChargingProfiles
);
commandPayload: ClearChargingProfileRequest
): ClearChargingProfileResponse {
if (
- !OCPP16ServiceUtils.checkFeatureProfile(
+ OCPP16ServiceUtils.checkFeatureProfile(
chargingStation,
OCPP16SupportedFeatureProfiles.SmartCharging,
OCPP16IncomingRequestCommand.CLEAR_CHARGING_PROFILE
- )
+ ) === false
) {
return Constants.OCPP_CLEAR_CHARGING_PROFILE_RESPONSE_UNKNOWN;
}
- const connectorStatus = chargingStation.getConnectorStatus(commandPayload.connectorId);
- if (!connectorStatus) {
+ if (chargingStation.connectors.has(commandPayload.connectorId) === false) {
logger.error(
`${chargingStation.logPrefix()} Trying to clear a charging profile(s) to a non existing connector Id ${
commandPayload.connectorId
);
return Constants.OCPP_CLEAR_CHARGING_PROFILE_RESPONSE_UNKNOWN;
}
+ const connectorStatus = chargingStation.getConnectorStatus(commandPayload.connectorId);
if (commandPayload.connectorId && !Utils.isEmptyArray(connectorStatus.chargingProfiles)) {
connectorStatus.chargingProfiles = [];
logger.debug(
return response;
} else if (
connectorId > 0 &&
- (chargingStation.getConnectorStatus(0).availability === OCPP16AvailabilityType.OPERATIVE ||
- (chargingStation.getConnectorStatus(0).availability ===
- OCPP16AvailabilityType.INOPERATIVE &&
+ (chargingStation.isChargingStationAvailable() === true ||
+ (chargingStation.isChargingStationAvailable() === false &&
commandPayload.type === OCPP16AvailabilityType.INOPERATIVE))
) {
if (chargingStation.getConnectorStatus(connectorId)?.transactionStarted === true) {
commandPayload: RemoteStartTransactionRequest
): Promise<DefaultResponse> {
const transactionConnectorId = commandPayload.connectorId;
- const connectorStatus = chargingStation.getConnectorStatus(transactionConnectorId);
- if (transactionConnectorId) {
+ if (chargingStation.connectors.has(transactionConnectorId) === true) {
const remoteStartTransactionLogMsg =
chargingStation.logPrefix() +
' Transaction remotely STARTED on ' +
status: OCPP16ChargePointStatus.PREPARING,
errorCode: OCPP16ChargePointErrorCode.NO_ERROR,
});
+ const connectorStatus = chargingStation.getConnectorStatus(transactionConnectorId);
connectorStatus.status = OCPP16ChargePointStatus.PREPARING;
- if (chargingStation.isChargingStationAvailable() && connectorStatus) {
+ if (chargingStation.isChargingStationAvailable() === true) {
// Check if authorized
- if (chargingStation.getAuthorizeRemoteTxRequests()) {
+ if (chargingStation.getAuthorizeRemoteTxRequests() === true) {
let authorized = false;
if (
- chargingStation.getLocalAuthListEnabled() &&
- chargingStation.hasAuthorizedTags() &&
+ chargingStation.getLocalAuthListEnabled() === true &&
+ chargingStation.hasAuthorizedTags() === true &&
chargingStation.authorizedTagsCache
.getAuthorizedTags(
ChargingStationUtils.getAuthorizationFile(chargingStation.stationInfo)
)
- .find((value) => value === commandPayload.idTag)
+ .find((idTag) => idTag === commandPayload.idTag)
) {
connectorStatus.localAuthorizeIdTag = commandPayload.idTag;
connectorStatus.idTagLocalAuthorized = true;
authorized = true;
- } else if (chargingStation.getMustAuthorizeAtRemoteStart()) {
+ } else if (chargingStation.getMustAuthorizeAtRemoteStart() === true) {
connectorStatus.authorizeIdTag = commandPayload.idTag;
const authorizeResponse: OCPP16AuthorizeResponse =
await chargingStation.ocppRequestService.requestHandler<
`${chargingStation.logPrefix()} The charging station configuration expects authorize at remote start transaction but local authorization or authorize isn't enabled`
);
}
- if (authorized) {
+ if (authorized === true) {
// Authorization successful, start transaction
if (
this.setRemoteStartTransactionChargingProfile(
chargingStation,
transactionConnectorId,
commandPayload.chargingProfile
- )
+ ) === true
) {
connectorStatus.transactionRemoteStarted = true;
if (
chargingStation,
transactionConnectorId,
commandPayload.chargingProfile
- )
+ ) === true
) {
connectorStatus.transactionRemoteStarted = true;
if (
cp: OCPP16ChargingProfile
): boolean {
if (cp && cp.chargingProfilePurpose === ChargingProfilePurposeType.TX_PROFILE) {
- chargingStation.setChargingProfile(connectorId, cp);
+ OCPP16ServiceUtils.setChargingProfile(chargingStation, connectorId, cp);
logger.debug(
`${chargingStation.logPrefix()} Charging profile(s) set at remote start transaction on connector id ${connectorId}, dump their stack: %j`,
chargingStation.getConnectorStatus(connectorId).chargingProfiles
commandPayload: GetDiagnosticsRequest
): Promise<GetDiagnosticsResponse> {
if (
- !OCPP16ServiceUtils.checkFeatureProfile(
+ OCPP16ServiceUtils.checkFeatureProfile(
chargingStation,
OCPP16SupportedFeatureProfiles.FirmwareManagement,
OCPP16IncomingRequestCommand.GET_DIAGNOSTICS
- )
+ ) === false
) {
return Constants.OCPP_RESPONSE_EMPTY;
}
.requestHandler<OCPP16BootNotificationRequest, OCPP16BootNotificationResponse>(
chargingStation,
OCPP16RequestCommand.BOOT_NOTIFICATION,
- {
- chargePointModel: chargingStation.bootNotificationRequest.chargePointModel,
- chargePointVendor: chargingStation.bootNotificationRequest.chargePointVendor,
- chargeBoxSerialNumber:
- chargingStation.bootNotificationRequest.chargeBoxSerialNumber,
- firmwareVersion: chargingStation.bootNotificationRequest.firmwareVersion,
- chargePointSerialNumber:
- chargingStation.bootNotificationRequest.chargePointSerialNumber,
- iccid: chargingStation.bootNotificationRequest.iccid,
- imsi: chargingStation.bootNotificationRequest.imsi,
- meterSerialNumber: chargingStation.bootNotificationRequest.meterSerialNumber,
- meterType: chargingStation.bootNotificationRequest.meterType,
- },
+ chargingStation.bootNotificationRequest,
{ skipBufferingOnError: true, triggerMessage: true }
)
- .then((value) => {
- chargingStation.bootNotificationResponse = value;
+ .then((response) => {
+ chargingStation.bootNotificationResponse = response;
})
.catch(() => {
/* This is intentional */