-
Notifications
You must be signed in to change notification settings - Fork 111
/
Copy pathvirtualdevices.ts
77 lines (67 loc) · 2.02 KB
/
virtualdevices.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import { Flags } from '@oclif/core'
import {
Device,
DeviceIntegrationType,
DeviceListOptions,
} from '@smartthings/core-sdk'
import {
APICommand,
outputItemOrList,
OutputItemOrListConfig,
withLocationsAndRooms,
WithNamedRoom,
} from '@smartthings/cli-lib'
import { buildTableOutput } from '../lib/commands/devices-util'
export default class VirtualDevicesCommand extends APICommand<typeof VirtualDevicesCommand.flags> {
static description = 'list all virtual devices available in a user account or retrieve a single device'
static flags = {
...APICommand.flags,
...outputItemOrList.flags,
location: Flags.string({
char: 'l',
description: 'filter results by location',
multiple: true,
helpValue: '<UUID>',
}),
// eslint-disable-next-line @typescript-eslint/naming-convention
'installed-app': Flags.string({
char: 'a',
description: 'filter results by installed app that created the device',
helpValue: '<UUID>',
}),
verbose: Flags.boolean({
description: 'include location name in output',
char: 'v',
}),
}
static args = [{
name: 'id',
description: 'device to retrieve; UUID or the number of the device from list',
}]
async run(): Promise<void> {
const config: OutputItemOrListConfig<Device & WithNamedRoom> = {
primaryKeyName: 'deviceId',
sortKeyName: 'label',
listTableFieldDefinitions: ['label', 'deviceId'],
buildTableOutput: (data: Device) => buildTableOutput(this.tableGenerator, data),
}
if (this.flags.verbose) {
config.listTableFieldDefinitions.splice(3, 0, 'location', 'room')
}
const deviceListOptions: DeviceListOptions = {
locationId: this.flags.location,
installedAppId: this.flags['installed-app'],
type: DeviceIntegrationType.VIRTUAL,
}
await outputItemOrList(this, config, this.args.id,
async () => {
const devices = await this.client.devices.list(deviceListOptions)
if (this.flags.verbose) {
return await withLocationsAndRooms(this.client, devices)
}
return devices
},
id => this.client.devices.get(id),
)
}
}