Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 0 additions & 22 deletions packages/cli/src/commands/devices/health.ts

This file was deleted.

52 changes: 52 additions & 0 deletions src/commands/devices/health.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import { type ArgumentsCamelCase, type Argv, type CommandModule } from 'yargs'

import {
apiCommand,
apiCommandBuilder,
type APICommandFlags,
} from '../../lib/command/api-command.js'
import {
formatAndWriteItem,
formatAndWriteItemBuilder,
type FormatAndWriteItemFlags,
} from '../../lib/command/format.js'
import { chooseDevice } from '../../lib/command/util/devices-choose.js'


export type CommandArgs =
& APICommandFlags
& FormatAndWriteItemFlags
& {
idOrIndex?: string
}

const command = 'devices:health [id-or-index]'

const describe = 'get the current health status of a device'

const builder = (yargs: Argv): Argv<CommandArgs> =>
formatAndWriteItemBuilder(apiCommandBuilder(yargs))
.positional('id-or-index', { describe: 'device id or number from list', type: 'string' })
.example([
['$0 devices:health', 'choose a device from a list and display its health status'],
[
'$0 devices:health 3',
'display the health status for the third device listed when running "smartthings devices"',
],
[
'$0 devices:health a13a3fbb-2b97-4c73-978d-ae7c2fca3ea8',
'display the health status for the specified device',
],
])


const handler = async (argv: ArgumentsCamelCase<CommandArgs>): Promise<void> => {
const command = await apiCommand(argv)

const deviceId = await chooseDevice(command, argv.idOrIndex, { allowIndex: true })
const health = await command.client.devices.getHealth(deviceId)
await formatAndWriteItem(command, { tableFieldDefinitions: ['deviceId', 'state', 'lastUpdatedDate'] }, health)
}

const cmd: CommandModule<object, CommandArgs> = { command, describe, builder, handler }
export default cmd
2 changes: 2 additions & 0 deletions src/commands/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ import devicesComponentStatusCommand from './devices/component-status.js'
import devicesCommandsCommand from './devices/commands.js'
import devicesStatusCommand from './devices/status.js'
import devicesDeleteCommand from './devices/delete.js'
import devicesHealthCommand from './devices/health.js'
import devicesHistoryCommand from './devices/history.js'
import devicesPreferencesCommand from './devices/preferences.js'
import devicesUpdateCommand from './devices/update.js'
Expand Down Expand Up @@ -165,6 +166,7 @@ export const commands: CommandModule<object, any>[] = [
devicesCommandsCommand,
devicesStatusCommand,
devicesDeleteCommand,
devicesHealthCommand,
devicesHistoryCommand,
devicesPreferencesCommand,
devicesUpdateCommand,
Expand Down