-
Notifications
You must be signed in to change notification settings - Fork 54
/
presentation.ts
236 lines (221 loc) · 6.6 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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
import { Endpoint } from '../endpoint'
import { EndpointClient, EndpointClientConfig, HttpClientParams } from '../endpoint-client'
import {
CapabilityVisibleCondition,
CapabilityLabeledState,
CapabilityGrouped,
CapabilityDashboardAction,
CapabilityDashboardBasicPlusItem,
CapabilityDetailView,
CapabilityMultiArgCommand,
CapabilityAutomationCondition,
CapabilityAutomationAction} from './capabilities'
export enum PatchItemOpEnum {
ADD = 'add',
REPLACE = 'replace',
REMOVE = 'remove'
}
export interface PatchItem {
/**
* Operation objects MUST have exactly one \"op\" member, whose value indicates the operation to perform
*/
op: PatchItemOpEnum
/**
* path specifies a string format for identifying a specific value within a JSON document. It is used by all operations in patch to specify the part of the document to operate on.
*/
path: string
// eslint-disable-next-line @typescript-eslint/no-explicit-any
value?: any
}
export interface PresentationDeviceConfigEntry {
component: string
capability: string
version?: number
values?: {
/**
* This can be either command name or attribute name.
*/
key: string
/**
* A list of values supported among those defined in the
* capability alternatives. For instance, a device may not support
* auto for supported thermostat fan modes, so this field might be
* an array containing on and off.
*/
enabledValues?: string[]
range?: [number, number]
/**
* default: 1
*/
step?: number
}[]
patch?: PatchItem[]
visibleCondition?: CapabilityVisibleCondition
}
export interface PresentationDeviceConfigCreate {
/**
* Type should be set to 'profile' for anything new.
*
* 'dth' is for backwards compatibility only
*/
type?: 'profile' | 'dth'
/**
* Preloaded iconId or URL used to retrieve icons to be drawn on the UI
* client.
*/
iconUrl?: string
dashboard?: {
states: PresentationDeviceConfigEntry[]
actions: PresentationDeviceConfigEntry[]
}
detailView?: PresentationDeviceConfigEntry[]
automation?: {
conditions: PresentationDeviceConfigEntry[]
actions: PresentationDeviceConfigEntry[]
}
}
export interface PresentationDPInfo {
/**
* The OS of the UI Client used to show the details page. 'iOS': iOS
* Samsung Connect 'android': Android Samsung Connect.
*/
os: string
/**
* This is linked to obtain the vendor-specific device details page.
* The device's dashboard card opens the detail view using this link
* when the user clicks the device card.
*/
dpUri: string
/**
* This describes operating mode after onboarding.
*/
operatingMode?: 'easySetup' | 'deviceControl'
}
export interface PresentationDeviceConfig extends PresentationDeviceConfigCreate {
/**
* The name of the manufacturer.
*/
manufacturerName: string
/**
* A unique identifier for the presentation of a device. This can be a
* model number on some device integrations, but moving forward will
* usually be a system generated value based on a device's structure as
* well as its display configuration.
*
* You can ignore this field unless you are specifically designing a
* plugin with an external detail view.
*/
presentationId: string
/**
* Information used for obtaining details page plugins on different
* platforms.
*/
dpInfo?: PresentationDPInfo[]
}
export interface PresentationDevicePresentation {
manufacturerName: string
presentationId: string
/**
* Preloaded iconId or URL used to retrieve icons to be drawn on the UI
* Client.
*/
iconUrl?: string
dashboard?: {
states?: (CapabilityLabeledState & CapabilityGrouped & {
label: string
capability: string
version?: number
component: string
visibleCondition: CapabilityVisibleCondition
})[]
actions?: (CapabilityDashboardAction & {
capability: string
version?: number
component: string
visibleCondition: CapabilityVisibleCondition
})[]
basicPlus: (CapabilityDashboardBasicPlusItem & {
capability: string
version?: number
component: string
})[]
}
detailView?: (CapabilityDetailView & {
capability: string
version?: number
component: string
multiArgCommand: CapabilityMultiArgCommand
visibleCondition: CapabilityVisibleCondition
})[]
automation?: {
conditions: (CapabilityAutomationCondition & {
capability: string
version?: number
component: string
visibleCondition: CapabilityVisibleCondition
})[]
actions: (CapabilityAutomationAction & {
component: string
visibleCondition: CapabilityVisibleCondition
})[]
}
dpInfo?: PresentationDPInfo[]
language?: {
/**
* ICU locale
*/
locale: string
poCodes: {
label: string
/**
* Po code. Should begin with "__PO_CODE" and match
* `/^___PO_CODE_[a-zA-Z0-9_]+$/`
*/
po: string
}[]
}[]
}
export class PresentationEndpoint extends Endpoint {
constructor(config: EndpointClientConfig) {
super(new EndpointClient('presentation', config))
}
/**
* Get or generate a device configuration based on profile.
*
* @param extraParams deprecated.
*/
public generate(profileId: string, extraParams?: HttpClientParams): Promise<PresentationDeviceConfig> {
return this.client.get<PresentationDeviceConfig>(`types/${profileId}/deviceconfig`, extraParams)
}
/**
* Get a device configuration
* @param presentationId The id returned from the device config create operation
* @param manufacturerName The manufacturer name, e.g. SmartThingsCommunity
*/
public get(presentationId: string, manufacturerName?: string): Promise<PresentationDeviceConfig> {
if (manufacturerName) {
return this.client.get<PresentationDeviceConfig>('deviceconfig', { presentationId, manufacturerName })
} else {
return this.client.get<PresentationDeviceConfig>('deviceconfig', { presentationId })
}
}
/**
* Make an idempotent call to either create or update a device configuration
* based on the structure of the provided payload.
*/
public create(deviceConfig: PresentationDeviceConfigCreate): Promise<PresentationDeviceConfig> {
return this.client.post<PresentationDeviceConfig>('deviceconfig', deviceConfig)
}
/**
* Get a device presentation. If manufacturerName is omitted the default SmartThingsCommunity manufacturerName is used.
* @param presentationId The id returned from the device config create operation
* @param manufacturerName The manufacturer name, e.g. SmartThingsCommunity
*/
public getPresentation(presentationId: string, manufacturerName?: string): Promise<PresentationDevicePresentation> {
if (manufacturerName) {
return this.client.get<PresentationDevicePresentation>('', { presentationId, manufacturerName })
} else {
return this.client.get<PresentationDevicePresentation>('', { presentationId })
}
}
}