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

Function handler

src/commands/edge/drivers/switch.ts:54–90  ·  view source on GitHub ↗
(argv: ArgumentsCamelCase<CommandArgs>)

Source from the content-addressed store, hash-verified

52 .epilog(buildEpilog({ command, apiDocs: 'updateHubDevice' }))
53
54const handler = async (argv: ArgumentsCamelCase<CommandArgs>): Promise<void> => {
55 const command = await apiCommand(argv)
56
57 const hubId = await chooseHub(
58 command,
59 argv.hub,
60 { promptMessage: 'Which hub is the device connected to?', useConfigDefault: true },
61 )
62 const deviceListFilter = (device: Device): boolean =>
63 device.type === DeviceIntegrationType.LAN && device.lan?.hubId === hubId ||
64 device.type === DeviceIntegrationType.MATTER && device.matter?.hubId === hubId ||
65 device.type === DeviceIntegrationType.ZIGBEE && device.zigbee?.hubId === hubId ||
66 device.type === DeviceIntegrationType.ZWAVE && device.zwave?.hubId === hubId
67
68 const deviceListOptions = {
69 type: edgeDeviceTypes,
70 }
71 const deviceId = await chooseDeviceFn(deviceListOptions)(
72 command,
73 argv.deviceId,
74 { listFilter: deviceListFilter },
75 )
76
77 const matchingDrivers = await listMatchingDrivers(command.client, deviceId, hubId)
78 const listItems = argv.includeNonMatching
79 ? () => listAllAvailableDrivers(command.client, deviceId, hubId)
80 : async () => matchingDrivers
81 const driverId = await chooseDriver(
82 command,
83 argv.driver,
84 { promptMessage: 'Choose a driver to use.', listItems },
85 )
86 const forceUpdate = argv.includeNonMatching && !matchingDrivers.find(driver => driver.driverId === driverId)
87
88 await command.client.hubdevices.switchDriver(driverId, hubId, deviceId, forceUpdate)
89 console.log(`Updated driver for device ${deviceId} to ${driverId}.`)
90}
91
92const cmd: CommandModule<object, CommandArgs> = { command, describe, builder, handler }
93export default cmd

Callers

nothing calls this directly

Calls 4

apiCommandFunction · 0.85
chooseDeviceFnFunction · 0.85
listMatchingDriversFunction · 0.85
listAllAvailableDriversFunction · 0.85

Tested by

no test coverage detected