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

Function handler

src/commands/edge/channels/unenroll.ts:43–71  ·  view source on GitHub ↗
(argv: ArgumentsCamelCase<CommandArgs>)

Source from the content-addressed store, hash-verified

41 .epilog(buildEpilog({ command }))
42
43const handler = async (argv: ArgumentsCamelCase<CommandArgs>): Promise<void> => {
44 const command = await apiCommand(argv)
45
46 // A special listItems for `chooseHub` that will only include hubs which are enrolled in channels.
47 const listItems = async (): Promise<Device[]> => {
48 const hubs = await listOwnedHubs(command)
49 const hubsWithChannels = await Promise.all(hubs.map(async hub =>
50 ({ hub, channels: await command.client.hubdevices.enrolledChannels(hub.deviceId) })))
51 return hubsWithChannels
52 .flat()
53 .filter(({ channels }) => channels.length > 0)
54 .map(({ hub }) => hub)
55 }
56 const hubId = await chooseHub(
57 command,
58 argv.hubId,
59 { useConfigDefault: true, listItems },
60 )
61
62 const channelId = await chooseChannelFn({ includeReadOnly: true })(
63 command,
64 argv.channel,
65 { listItems: () => command.client.hubdevices.enrolledChannels(hubId) },
66 )
67
68 await command.client.channels.unenrollHub(channelId, hubId)
69
70 console.log(`Hub ${hubId} unenrolled from channel ${channelId}.`)
71}
72
73const cmd: CommandModule<object, CommandArgs> = { command, describe, builder, handler }
74export default cmd

Callers

nothing calls this directly

Calls 2

apiCommandFunction · 0.85
chooseChannelFnFunction · 0.85

Tested by

no test coverage detected