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

Function handler

src/commands/devices/history.ts:46–73  ·  view source on GitHub ↗
(argv: ArgumentsCamelCase<CommandArgs>)

Source from the content-addressed store, hash-verified

44 .epilog(buildEpilog({ command }))
45
46const handler = async (argv: ArgumentsCamelCase<CommandArgs>): Promise<void> => {
47 const command = await apiCommand(argv)
48
49 const limit = argv.limit
50 const perRequestLimit = calculateRequestLimit(limit)
51
52 const deviceId = await chooseDevice(command, argv.idOrIndex, { allowIndex: true })
53 const device = await command.client.devices.get(deviceId)
54 const params = {
55 deviceId,
56 locationId: device.locationId,
57 limit: perRequestLimit,
58 before: toEpochTime(argv.before),
59 after: toEpochTime(argv.after),
60 }
61
62 if (calculateOutputFormat(argv) === 'common') {
63 if (limit > perRequestLimit) {
64 console.log(`History is limited to ${maxItemsPerRequest} items per request.`)
65 }
66 const history = await command.client.history.devices(params)
67 await writeDeviceEventsTable(command, history, { utcTimeFormat: argv.utc })
68 } else {
69 const items = await getHistory(command.client, limit, perRequestLimit, params)
70 const outputFormatter = buildOutputFormatter<DeviceActivity[]>(argv, command.cliConfig)
71 await writeOutput(outputFormatter(items), argv.output)
72 }
73}
74
75const cmd: CommandModule<object, CommandArgs> = { command, describe, builder, handler }
76export default cmd

Callers

nothing calls this directly

Calls 8

apiCommandFunction · 0.85
calculateRequestLimitFunction · 0.85
toEpochTimeFunction · 0.85
calculateOutputFormatFunction · 0.85
writeDeviceEventsTableFunction · 0.85
getHistoryFunction · 0.85
buildOutputFormatterFunction · 0.85
writeOutputFunction · 0.85

Tested by

no test coverage detected