Skip to content

Commit

Permalink
ocpp20: uses interface to map actions to result types for CheckedCall…
Browse files Browse the repository at this point in the history
…Result<C>
  • Loading branch information
jacoscaz committed Aug 27, 2024
1 parent b9bcbb8 commit 982fa61
Showing 1 changed file with 67 additions and 67 deletions.
134 changes: 67 additions & 67 deletions src/ocpp20/callresult.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,74 +216,74 @@ export const parseCallResult = (arr: [MessageType.CALLRESULT, string, ...any]):
return arr as UncheckedCallResult<any>;
};

export const CallResultTypesByAction = {
[Action.Authorize]: EMPTY as AuthorizeCallResult,
[Action.BootNotification]: EMPTY as BootNotificationCallResult,
[Action.CancelReservation]: EMPTY as CancelReservationCallResult,
[Action.CertificateSigned]: EMPTY as CertificateSignedCallResult,
[Action.ChangeAvailability]: EMPTY as ChangeAvailabilityCallResult,
[Action.ClearCache]: EMPTY as ClearCacheCallResult,
[Action.ClearChargingProfile]: EMPTY as ClearChargingProfileCallResult,
[Action.ClearDisplayMessage]: EMPTY as ClearDisplayMessageCallResult,
[Action.ClearedChargingLimit]: EMPTY as ClearedChargingLimitCallResult,
[Action.ClearVariableMonitoring]: EMPTY as ClearVariableMonitoringCallResult,
[Action.CostUpdated]: EMPTY as CostUpdatedCallResult,
[Action.CustomerInformation]: EMPTY as CustomerInformationCallResult,
[Action.DataTransfer]: EMPTY as DataTransferCallResult,
[Action.DeleteCertificate]: EMPTY as DeleteCertificateCallResult,
[Action.FirmwareStatusNotification]: EMPTY as FirmwareStatusNotificationCallResult,
[Action.Get15118EVCertificate]: EMPTY as Get15118EVCertificateCallResult,
[Action.GetBaseReport]: EMPTY as GetBaseReportCallResult,
[Action.GetCertificateStatus]: EMPTY as GetCertificateStatusCallResult,
[Action.GetChargingProfiles]: EMPTY as GetChargingProfilesCallResult,
[Action.GetCompositeSchedule]: EMPTY as GetCompositeScheduleCallResult,
[Action.GetDisplayMessages]: EMPTY as GetDisplayMessagesCallResult,
[Action.GetInstalledCertificateIds]: EMPTY as GetInstalledCertificateIdsCallResult,
[Action.GetLocalListVersion]: EMPTY as GetLocalListVersionCallResult,
[Action.GetLog]: EMPTY as GetLogCallResult,
[Action.GetMonitoringReport]: EMPTY as GetMonitoringReportCallResult,
[Action.GetReport]: EMPTY as GetReportCallResult,
[Action.GetTransactionStatus]: EMPTY as GetTransactionStatusCallResult,
[Action.GetVariables]: EMPTY as GetVariablesCallResult,
[Action.Heartbeat]: EMPTY as HeartbeatCallResult,
[Action.InstallCertificate]: EMPTY as InstallCertificateCallResult,
[Action.LogStatusNotification]: EMPTY as LogStatusNotificationCallResult,
[Action.MeterValues]: EMPTY as MeterValuesCallResult,
[Action.NotifyChargingLimit]: EMPTY as NotifyChargingLimitCallResult,
[Action.NotifyCustomerInformation]: EMPTY as NotifyCustomerInformationCallResult,
[Action.NotifyDisplayMessages]: EMPTY as NotifyDisplayMessagesCallResult,
[Action.NotifyEVChargingNeeds]: EMPTY as NotifyEVChargingNeedsCallResult,
[Action.NotifyEVChargingSchedule]: EMPTY as NotifyEVChargingScheduleCallResult,
[Action.NotifyEvent]: EMPTY as NotifyEventCallResult,
[Action.NotifyMonitoringReport]: EMPTY as NotifyMonitoringReportCallResult,
[Action.NotifyReport]: EMPTY as NotifyReportCallResult,
[Action.PublishFirmware]: EMPTY as PublishFirmwareCallResult,
[Action.PublishFirmwareStatusNotification]: EMPTY as PublishFirmwareStatusNotificationCallResult,
[Action.ReportChargingProfiles]: EMPTY as ReportChargingProfilesCallResult,
[Action.RequestStartTransaction]: EMPTY as RequestStartTransactionCallResult,
[Action.RequestStopTransaction]: EMPTY as RequestStopTransactionCallResult,
[Action.ReservationStatusUpdate]: EMPTY as ReservationStatusUpdateCallResult,
[Action.ReserveNow]: EMPTY as ReserveNowCallResult,
[Action.Reset]: EMPTY as ResetCallResult,
[Action.SecurityEventNotification]: EMPTY as SecurityEventNotificationCallResult,
[Action.SendLocalList]: EMPTY as SendLocalListCallResult,
[Action.SetChargingProfile]: EMPTY as SetChargingProfileCallResult,
[Action.SetDisplayMessage]: EMPTY as SetDisplayMessageCallResult,
[Action.SetMonitoringBase]: EMPTY as SetMonitoringBaseCallResult,
[Action.SetMonitoringLevel]: EMPTY as SetMonitoringLevelCallResult,
[Action.SetNetworkProfile]: EMPTY as SetNetworkProfileCallResult,
[Action.SetVariableMonitoring]: EMPTY as SetVariableMonitoringCallResult,
[Action.SetVariables]: EMPTY as SetVariablesCallResult,
[Action.SignCertificate]: EMPTY as SignCertificateCallResult,
[Action.StatusNotification]: EMPTY as StatusNotificationCallResult,
[Action.TransactionEvent]: EMPTY as TransactionEventCallResult,
[Action.TriggerMessage]: EMPTY as TriggerMessageCallResult,
[Action.UnlockConnector]: EMPTY as UnlockConnectorCallResult,
[Action.UnpublishFirmware]: EMPTY as UnpublishFirmwareCallResult,
[Action.UpdateFirmware]: EMPTY as UpdateFirmwareCallResult,
} satisfies Record<Action, CallResult>;
export interface CallResultTypesByAction extends Record<Action, CallResult> {
[Action.Authorize]: AuthorizeCallResult,
[Action.BootNotification]: BootNotificationCallResult,
[Action.CancelReservation]: CancelReservationCallResult,
[Action.CertificateSigned]: CertificateSignedCallResult,
[Action.ChangeAvailability]: ChangeAvailabilityCallResult,
[Action.ClearCache]: ClearCacheCallResult,
[Action.ClearChargingProfile]: ClearChargingProfileCallResult,
[Action.ClearDisplayMessage]: ClearDisplayMessageCallResult,
[Action.ClearedChargingLimit]: ClearedChargingLimitCallResult,
[Action.ClearVariableMonitoring]: ClearVariableMonitoringCallResult,
[Action.CostUpdated]: CostUpdatedCallResult,
[Action.CustomerInformation]: CustomerInformationCallResult,
[Action.DataTransfer]: DataTransferCallResult,
[Action.DeleteCertificate]: DeleteCertificateCallResult,
[Action.FirmwareStatusNotification]: FirmwareStatusNotificationCallResult,
[Action.Get15118EVCertificate]: Get15118EVCertificateCallResult,
[Action.GetBaseReport]: GetBaseReportCallResult,
[Action.GetCertificateStatus]: GetCertificateStatusCallResult,
[Action.GetChargingProfiles]: GetChargingProfilesCallResult,
[Action.GetCompositeSchedule]: GetCompositeScheduleCallResult,
[Action.GetDisplayMessages]: GetDisplayMessagesCallResult,
[Action.GetInstalledCertificateIds]: GetInstalledCertificateIdsCallResult,
[Action.GetLocalListVersion]: GetLocalListVersionCallResult,
[Action.GetLog]: GetLogCallResult,
[Action.GetMonitoringReport]: GetMonitoringReportCallResult,
[Action.GetReport]: GetReportCallResult,
[Action.GetTransactionStatus]: GetTransactionStatusCallResult,
[Action.GetVariables]: GetVariablesCallResult,
[Action.Heartbeat]: HeartbeatCallResult,
[Action.InstallCertificate]: InstallCertificateCallResult,
[Action.LogStatusNotification]: LogStatusNotificationCallResult,
[Action.MeterValues]: MeterValuesCallResult,
[Action.NotifyChargingLimit]: NotifyChargingLimitCallResult,
[Action.NotifyCustomerInformation]: NotifyCustomerInformationCallResult,
[Action.NotifyDisplayMessages]: NotifyDisplayMessagesCallResult,
[Action.NotifyEVChargingNeeds]: NotifyEVChargingNeedsCallResult,
[Action.NotifyEVChargingSchedule]: NotifyEVChargingScheduleCallResult,
[Action.NotifyEvent]: NotifyEventCallResult,
[Action.NotifyMonitoringReport]: NotifyMonitoringReportCallResult,
[Action.NotifyReport]: NotifyReportCallResult,
[Action.PublishFirmware]: PublishFirmwareCallResult,
[Action.PublishFirmwareStatusNotification]: PublishFirmwareStatusNotificationCallResult,
[Action.ReportChargingProfiles]: ReportChargingProfilesCallResult,
[Action.RequestStartTransaction]: RequestStartTransactionCallResult,
[Action.RequestStopTransaction]: RequestStopTransactionCallResult,
[Action.ReservationStatusUpdate]: ReservationStatusUpdateCallResult,
[Action.ReserveNow]: ReserveNowCallResult,
[Action.Reset]: ResetCallResult,
[Action.SecurityEventNotification]: SecurityEventNotificationCallResult,
[Action.SendLocalList]: SendLocalListCallResult,
[Action.SetChargingProfile]: SetChargingProfileCallResult,
[Action.SetDisplayMessage]: SetDisplayMessageCallResult,
[Action.SetMonitoringBase]: SetMonitoringBaseCallResult,
[Action.SetMonitoringLevel]: SetMonitoringLevelCallResult,
[Action.SetNetworkProfile]: SetNetworkProfileCallResult,
[Action.SetVariableMonitoring]: SetVariableMonitoringCallResult,
[Action.SetVariables]: SetVariablesCallResult,
[Action.SignCertificate]: SignCertificateCallResult,
[Action.StatusNotification]: StatusNotificationCallResult,
[Action.TransactionEvent]: TransactionEventCallResult,
[Action.TriggerMessage]: TriggerMessageCallResult,
[Action.UnlockConnector]: UnlockConnectorCallResult,
[Action.UnpublishFirmware]: UnpublishFirmwareCallResult,
[Action.UpdateFirmware]: UpdateFirmwareCallResult,
};

export type CheckedCallResult<C extends Call> = (typeof CallResultTypesByAction)[C[2]];
export type CheckedCallResult<C extends Call> = CallResultTypesByAction[C[2]];

export const checkCallResult = <T extends Call>(result: UncheckedCallResult<any>, call: T): CheckedCallResult<T> => {
ensure.equal(result[1], call[1], `Invalid OCPP call result: id ${result[1]} does not equal call id ${call[1]}`);
Expand Down

0 comments on commit 982fa61

Please sign in to comment.