(command: APICommand)
| 17 | } |
| 18 | export const chooseHubFn = (options: ChooseHubFnOptions = {}): ChooseFunction<Device> => { |
| 19 | const listItems = async (command: APICommand): Promise<Device[]> => { |
| 20 | const unfiltered = ('includeOnlyOwnedHubs' in options) |
| 21 | ? await listOwnedHubs(command) |
| 22 | : await command.client.devices.list({ type: DeviceIntegrationType.HUB, locationId: options.locationId }) |
| 23 | if (!options.withInstalledDriverId) { |
| 24 | return unfiltered |
| 25 | } |
| 26 | |
| 27 | const filtered: Device[] = [] |
| 28 | for (const device of unfiltered) { |
| 29 | try { |
| 30 | // This command will throw an error if the driver is not installed on the hub. |
| 31 | await command.client.hubdevices.getInstalled(device.deviceId, options.withInstalledDriverId) |
| 32 | filtered.push(device) |
| 33 | } catch (error) { |
| 34 | if (!error.message?.includes('not currently installed')) { |
| 35 | throw error |
| 36 | } |
| 37 | } |
| 38 | } |
| 39 | return filtered |
| 40 | } |
| 41 | const customNotFoundMessage = options.withInstalledDriverId |
| 42 | ? `could not find hub with driver ${options.withInstalledDriverId} installed` |
| 43 | : undefined |
nothing calls this directly
no test coverage detected