-
Notifications
You must be signed in to change notification settings - Fork 112
/
Copy pathpresentation.ts
45 lines (35 loc) · 1.86 KB
/
presentation.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
import { Errors } from '@oclif/core'
import { APIOrganizationCommand, formatAndWriteItem } from '@smartthings/cli-lib'
import { buildTableOutput } from '../presentation'
import { chooseDeviceProfile } from '../../lib/commands/deviceprofiles-util'
export default class DeviceProfilePresentationCommand extends APIOrganizationCommand<typeof DeviceProfilePresentationCommand.flags> {
static description = 'get the presentation associated with a device profile' +
this.apiDocsURL('getDeviceProfile', 'getDevicePresentation')
static flags = {
...APIOrganizationCommand.flags,
...formatAndWriteItem.flags,
}
static args = [{
name: 'id',
description: 'device profile UUID or the number of the profile from list',
}]
static examples = [
'$ smartthings deviceprofiles:presentation fd4adb7f-4a23-4134-9b39-05ed889a03cf',
'$ smartthings deviceprofiles:presentation fd4adb7f-4a23-4134-9b39-05ed889a03cf --language=ko',
'$ smartthings deviceprofiles:presentation fd4adb7f-4a23-4134-9b39-05ed889a03cf --language=NONE',
'',
'Specifying only the presentationId defaults to the "SmartThingsCommunity" manufacturer',
'name and the language set for the computer\'s operating system. The language can be',
'overridden by specifying an ISO language code. If "NONE" is specified for the language',
'flag then no language header is specified in the API request',
]
async run(): Promise<void> {
const id = await chooseDeviceProfile(this, this.args.id, { allowIndex: true })
const profile = await this.client.deviceProfiles.get(id)
if (!profile.metadata) {
throw new Errors.CLIError('No presentation defined for device profile')
}
const presentation = await this.client.presentation.getPresentation(profile.metadata.vid, profile.metadata.mnmn)
await formatAndWriteItem(this, { buildTableOutput: data => buildTableOutput(this.tableGenerator, data) }, presentation)
}
}