MCPcopy Create free account
hub / github.com/SmartThingsCommunity/smartthings-cli / listItems

Function listItems

src/lib/command/util/hubs-choose.ts:19–40  ·  view source on GitHub ↗
(command: APICommand)

Source from the content-addressed store, hash-verified

17}
18export 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

Callers

nothing calls this directly

Calls 1

listOwnedHubsFunction · 0.85

Tested by

no test coverage detected