MCPcopy Index your code
hub / github.com/SmartThingsCommunity/smartthings-cli / handler

Function handler

src/commands/devices/capability-status.ts:63–98  ·  view source on GitHub ↗
(argv: ArgumentsCamelCase<CommandArgs>)

Source from the content-addressed store, hash-verified

61}
62
63const handler = async (argv: ArgumentsCamelCase<CommandArgs>): Promise<void> => {
64 const command = await apiCommand(argv)
65
66 const deviceId = await chooseDevice(command, argv.deviceIdOrIndex, { allowIndex: true })
67
68 const device = await command.client.devices.get(deviceId)
69 const chooseComponent = chooseComponentFn(device)
70 const componentId = await chooseComponent(command, argv.componentId, { autoChoose: true })
71
72 const component = device.components?.find(component => component.id === componentId)
73 const capabilities = component?.capabilities
74 if (!capabilities) {
75 return fatalError(`no capabilities found for component ${componentId} of device ${deviceId}`)
76 }
77
78 const config: SelectFromListConfig<CapabilityReference> = {
79 itemName: 'capability',
80 pluralItemName: 'capabilities',
81 primaryKeyName: 'id',
82 sortKeyName: 'id',
83 listTableFieldDefinitions: ['id'],
84 }
85 const listItems = async (): Promise<CapabilityReference[]> => capabilities
86 const preselectedId = await stringTranslateToId(config, argv.capabilityId, listItems)
87 const capabilityId = await selectFromList(command, config, { preselectedId, listItems })
88 const capabilityStatus = await command.client.devices.getCapabilityStatus(
89 deviceId,
90 componentId,
91 capabilityId,
92 )
93 await formatAndWriteItem(
94 command,
95 { buildTableOutput: data => buildTableOutput(command.tableGenerator, data) },
96 capabilityStatus,
97 )
98}
99
100const cmd: CommandModule<object, CommandArgs> = { command, describe, builder, handler }
101export default cmd

Callers

nothing calls this directly

Calls 7

apiCommandFunction · 0.85
chooseComponentFnFunction · 0.85
fatalErrorFunction · 0.85
stringTranslateToIdFunction · 0.85
selectFromListFunction · 0.85
formatAndWriteItemFunction · 0.85
buildTableOutputFunction · 0.70

Tested by

no test coverage detected