- try {
- switch (requestedMessage) {
- case OCPP16MessageTrigger.BootNotification:
- setTimeout(() => {
- chargingStation.ocppRequestService
- .requestHandler<OCPP16BootNotificationRequest, OCPP16BootNotificationResponse>(
- chargingStation,
- OCPP16RequestCommand.BOOT_NOTIFICATION,
- chargingStation.bootNotificationRequest,
- { skipBufferingOnError: true, triggerMessage: true }
- )
- .then(response => {
- chargingStation.bootNotificationResponse = response
- })
- .catch(Constants.EMPTY_FUNCTION)
- }, OCPP16Constants.OCPP_TRIGGER_MESSAGE_DELAY)
- return OCPP16Constants.OCPP_TRIGGER_MESSAGE_RESPONSE_ACCEPTED
- case OCPP16MessageTrigger.Heartbeat:
- setTimeout(() => {
- chargingStation.ocppRequestService
- .requestHandler<OCPP16HeartbeatRequest, OCPP16HeartbeatResponse>(
- chargingStation,
- OCPP16RequestCommand.HEARTBEAT,
- undefined,
- {
- triggerMessage: true
- }
- )
- .catch(Constants.EMPTY_FUNCTION)
- }, OCPP16Constants.OCPP_TRIGGER_MESSAGE_DELAY)
- return OCPP16Constants.OCPP_TRIGGER_MESSAGE_RESPONSE_ACCEPTED
- case OCPP16MessageTrigger.StatusNotification:
- setTimeout(() => {
- if (connectorId != null) {
- chargingStation.ocppRequestService
- .requestHandler<OCPP16StatusNotificationRequest, OCPP16StatusNotificationResponse>(
- chargingStation,
- OCPP16RequestCommand.STATUS_NOTIFICATION,
- {
- connectorId,
- errorCode: OCPP16ChargePointErrorCode.NO_ERROR,
- status: chargingStation.getConnectorStatus(connectorId)?.status
- },
- {
- triggerMessage: true
- }
- )
- .catch(Constants.EMPTY_FUNCTION)
- } else if (chargingStation.hasEvses) {
- for (const evseStatus of chargingStation.evses.values()) {
- for (const [id, connectorStatus] of evseStatus.connectors) {
- chargingStation.ocppRequestService
- .requestHandler<
- OCPP16StatusNotificationRequest,
- OCPP16StatusNotificationResponse
- >(
- chargingStation,
- OCPP16RequestCommand.STATUS_NOTIFICATION,
- {
- connectorId: id,
- errorCode: OCPP16ChargePointErrorCode.NO_ERROR,
- status: connectorStatus.status
- },
- {
- triggerMessage: true
- }
- )
- .catch(Constants.EMPTY_FUNCTION)
- }
- }
- } else {
- for (const [id, connectorStatus] of chargingStation.connectors) {
- chargingStation.ocppRequestService
- .requestHandler<
- OCPP16StatusNotificationRequest,
- OCPP16StatusNotificationResponse
- >(
- chargingStation,
- OCPP16RequestCommand.STATUS_NOTIFICATION,
- {
- connectorId: id,
- errorCode: OCPP16ChargePointErrorCode.NO_ERROR,
- status: connectorStatus.status
- },
- {
- triggerMessage: true
- }
- )
- .catch(Constants.EMPTY_FUNCTION)
- }
- }
- }, OCPP16Constants.OCPP_TRIGGER_MESSAGE_DELAY)
- return OCPP16Constants.OCPP_TRIGGER_MESSAGE_RESPONSE_ACCEPTED
- default:
- return OCPP16Constants.OCPP_TRIGGER_MESSAGE_RESPONSE_NOT_IMPLEMENTED
- }
- } catch (error) {
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
- return this.handleIncomingRequestError<OCPP16TriggerMessageResponse>(
- chargingStation,
- OCPP16IncomingRequestCommand.TRIGGER_MESSAGE,
- error as Error,
- { errorResponse: OCPP16Constants.OCPP_TRIGGER_MESSAGE_RESPONSE_REJECTED }
- )!