-
Notifications
You must be signed in to change notification settings - Fork 103
/
presentation.ts
125 lines (108 loc) · 4.47 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
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
import { PresentationDevicePresentation } from '@smartthings/core-sdk'
import { APICommand, outputItem, TableGenerator } from '@smartthings/cli-lib'
export function buildTableOutput(tableGenerator: TableGenerator, presentation: PresentationDevicePresentation): string {
const basicInfo = tableGenerator.buildTableFromItem(presentation, [
{ prop: 'presentationId', label: 'Presentation ID' }, { prop: 'manufacturerName', label: 'Manufacturer Name' }, 'iconUrl',
])
let dashboardStates = 'No dashboard states'
if (presentation.dashboard?.states && presentation.dashboard.states.length > 0) {
const subTable = tableGenerator.newOutputTable({ head: ['Label', 'Alternatives', 'Group'] })
for (const state of presentation.dashboard.states) {
const alternatives = state.alternatives?.length
? state.alternatives.length
: 'none'
subTable.push([
state.label,
alternatives,
state.group ? state.group : '',
])
}
dashboardStates = `Dashboard States\n${subTable.toString()}`
}
function buildDisplayTypeTable(items: { displayType: string }[]): string {
const subTable = tableGenerator.newOutputTable({ head: ['Display Type'] })
for (const item of items) {
subTable.push([item.displayType])
}
return subTable.toString()
}
function buildLabelDisplayTypeTable(items: { label: string; displayType: string }[]): string {
const subTable = tableGenerator.newOutputTable({ head: ['Label', 'Display Type'] })
for (const item of items) {
subTable.push([item.label, item.displayType])
}
return subTable.toString()
}
let dashboardActions = 'No dashboard actions'
if (presentation.dashboard?.actions?.length) {
dashboardActions = `Dashboard Actions\n${buildDisplayTypeTable(presentation.dashboard.actions)}`
}
let dashboardBasicPlus = 'No dashboard basic plus items'
if (presentation.dashboard?.basicPlus?.length) {
dashboardBasicPlus = `Dashboard Basic Plus\n${buildDisplayTypeTable(presentation.dashboard.basicPlus)}`
}
let detailViews = 'No detail views'
if (presentation.detailView?.length) {
const subTable = tableGenerator.newOutputTable({ head: ['Capability', 'Version', 'Component'] })
for (const detailView of presentation.detailView) {
subTable.push([
detailView.capability,
detailView.version ? detailView.version : 'none',
detailView.component,
])
}
detailViews = `Detail Views\n${subTable.toString()}`
}
let automationConditions = 'No automation conditions'
if (presentation.automation?.conditions?.length) {
automationConditions = `Automation Conditions\n${buildLabelDisplayTypeTable(presentation.automation.conditions)}`
}
let automationActions = 'No automation actions'
if (presentation.automation?.actions?.length) {
automationActions = `Automation Actions\n${buildLabelDisplayTypeTable(presentation.automation.actions)}`
}
return `Basic Information\n${basicInfo}\n\n` +
`${dashboardStates}\n\n` +
`${dashboardActions}\n\n` +
`${dashboardBasicPlus}\n\n` +
`${detailViews}\n\n` +
`${automationConditions}\n\n` +
automationActions
}
export default class PresentationCommand extends APICommand<typeof PresentationCommand.flags> {
static description = 'query device presentation by vid'
static flags = {
...APICommand.flags,
...outputItem.flags,
}
static args = [
{
name: 'presentationId',
description: 'system generated identifier that corresponds to a device presentation',
required: true,
},
{
name: 'manufacturerName',
description: 'manufacturer name. Defaults to SmartThingsCommunity',
required: false,
},
]
static examples = [
'$ smartthings presentation fd4adb7f-4a23-4134-9b39-05ed889a03cf',
'$ smartthings presentation 4ea31e30-2aba-41c7-a3ec-8f97423d565a SmartThings',
'$ smartthings presentation fd4adb7f-4a23-4134-9b39-05ed889a03cf --language=ko',
'$ smartthings 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 config = {
buildTableOutput: (data: PresentationDevicePresentation) => buildTableOutput(this.tableGenerator, data),
}
await outputItem(this, config,
() => this.client.presentation.getPresentation(this.args.presentationId, this.args.manufacturerName))
}
}