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

Function handler

src/commands/edge/drivers/devices.ts:53–86  ·  view source on GitHub ↗
(argv: ArgumentsCamelCase<CommandArgs>)

Source from the content-addressed store, hash-verified

51 .epilog(buildEpilog({ command, apiDocs: ['getDevices', 'listDrivers', 'getDriver', 'getDriverRevision'] }))
52
53const handler = async (argv: ArgumentsCamelCase<CommandArgs>): Promise<void> => {
54 const command = await apiCommand(argv)
55
56 const config: OutputItemOrListConfig<DeviceDriverInfo> = {
57 primaryKeyName: 'deviceId',
58 sortKeyName: 'label',
59 tableFieldDefinitions: ['label', 'type', 'deviceId', 'driverId', 'hubId', 'hubLabel'],
60 listTableFieldDefinitions: ['label', 'type', 'deviceId', 'driverId'],
61 }
62
63 const matchesUserFilters = (device: DeviceDriverInfo): boolean => {
64 if (argv.hub && device.hubId !== argv.hub) {
65 return false
66 }
67 if (argv.driver && device.driverId !== argv.driver) {
68 return false
69 }
70 return true
71 }
72
73 const matchingDevices = (await getDriverDevices(command.client)).filter(matchesUserFilters)
74
75 const list = async (): Promise<DeviceDriverInfo[]> => matchingDevices
76
77 const get = async (id: string): Promise<DeviceDriverInfo> => {
78 const match = matchingDevices.find(device => device.deviceId === id)
79 if (match) {
80 return match
81 }
82 throw Error(`Could not find device with id ${id}`)
83 }
84
85 await outputItemOrList(command, config, argv.idOrIndex, list, get)
86}
87
88const cmd: CommandModule<object, CommandArgs> = { command, describe, builder, handler }
89export default cmd

Callers

nothing calls this directly

Calls 3

apiCommandFunction · 0.85
getDriverDevicesFunction · 0.85
outputItemOrListFunction · 0.85

Tested by

no test coverage detected