@@ -5,9 +5,12 @@ import { Links, Status, SuccessStatusValue } from '../types'
5
5
import { PresentationDevicePresentation } from './presentation'
6
6
7
7
8
+ const HEADER_OVERRIDES = { Accept : 'application/vnd.smartthings+json;v=20170916' }
9
+
8
10
export interface CapabilityReference {
9
11
id : string
10
12
version ?: number
13
+ status ?: CapabilityStatus
11
14
}
12
15
13
16
export interface Component {
@@ -84,6 +87,11 @@ export interface ProfileIdentifier {
84
87
id : string
85
88
}
86
89
90
+ export interface HealthState {
91
+ state : DeviceHealthState
92
+ lastUpdatedDate ?: string
93
+ }
94
+
87
95
export interface Device {
88
96
deviceId ?: string
89
97
name ?: string
@@ -104,6 +112,7 @@ export interface Device {
104
112
viper ?: ViperDeviceDetails
105
113
type ?: DeviceIntegrationType
106
114
restrictionTier ?: number
115
+ healthState ?: HealthState
107
116
}
108
117
109
118
export interface DeviceUpdate {
@@ -222,6 +231,16 @@ export interface DeviceListOptions {
222
231
*/
223
232
installedAppId ?: string
224
233
234
+ /**
235
+ * Include the device health, i.e. online/offline status in the response
236
+ */
237
+ includeHealth ?: boolean
238
+
239
+ /**
240
+ * Include the device status data, i.e. the values of all attributes, in the response
241
+ */
242
+ includeStatus ?: boolean
243
+
225
244
/**
226
245
* Limit the number of results to this value. By default all devices are returned
227
246
*/
@@ -238,6 +257,18 @@ export interface DeviceListOptions {
238
257
type ?: DeviceIntegrationType | DeviceIntegrationType [ ]
239
258
}
240
259
260
+ export interface DeviceGetOptions {
261
+ /**
262
+ * Include the device health, i.e. online/offline status in the response
263
+ */
264
+ includeHealth ?: boolean
265
+
266
+ /**
267
+ * Include the device status data, i.e. the values of all attributes, in the response
268
+ */
269
+ includeStatus ?: boolean
270
+ }
271
+
241
272
export interface HueSaturation {
242
273
hue : number
243
274
saturation : number
@@ -250,10 +281,12 @@ export class DevicesEndpoint extends Endpoint {
250
281
251
282
/**
252
283
* Returns a list of devices matching the query options or all devices accessible by the principal (i.e. user)
253
- * if no options are specified.
284
+ * if no options are specified. If the includeHealth option is set to true then the response will also contain
285
+ * the health status of each device (i.e. if it is online or offline). If the includeStatus option is set to true
286
+ * then the response will also include the status of all attributes (i.e. value and timestamp)
254
287
*
255
- * @param options query options, capability, capabilitiesMode ('and' or 'or'), locationId, deviceId. These can
256
- * be single values or arrays.
288
+ * @param options query options, capability, capabilitiesMode ('and' or 'or'), locationId, deviceId. which can
289
+ * be single values or arrays, and includeHealth & includeStatus booleans
257
290
*/
258
291
public async list ( options : DeviceListOptions = { } ) : Promise < Device [ ] > {
259
292
const params : HttpClientParams = { }
@@ -271,6 +304,12 @@ export class DevicesEndpoint extends Endpoint {
271
304
if ( 'deviceId' in options && options . deviceId ) {
272
305
params . deviceId = options . deviceId
273
306
}
307
+ if ( 'includeHealth' in options && options . includeHealth !== undefined ) {
308
+ params . includeHealth = options . includeHealth . toString ( )
309
+ }
310
+ if ( 'includeStatus' in options && options . includeStatus !== undefined ) {
311
+ params . includeStatus = options . includeStatus . toString ( )
312
+ }
274
313
if ( 'installedAppId' in options && options . installedAppId ) {
275
314
params . installedAppId = options . installedAppId
276
315
}
@@ -283,7 +322,8 @@ export class DevicesEndpoint extends Endpoint {
283
322
if ( 'type' in options && options . type ) {
284
323
params . type = options . type
285
324
}
286
- return this . client . getPagedItems < Device > ( undefined , params )
325
+ return this . client . getPagedItems < Device > ( undefined , params ,
326
+ { headerOverrides : HEADER_OVERRIDES } )
287
327
}
288
328
289
329
/**
@@ -320,9 +360,20 @@ export class DevicesEndpoint extends Endpoint {
320
360
/**
321
361
* Returns a description of the specified device
322
362
* @param id UUID of the device
363
+ * @param options optional includeHealth and includeStatus parameters.
364
+ * If the includeHealth option is set to true then the response will also contain
365
+ * the health status of each device (i.e. if it is online or offline). If the includeStatus option is set to true
366
+ * then the response will also include the status of all attributes (i.e. value and timestamp)
323
367
*/
324
- public get ( id : string ) : Promise < Device > {
325
- return this . client . get < Device > ( id )
368
+ public get ( id : string , options : DeviceGetOptions = { } ) : Promise < Device > {
369
+ const params : HttpClientParams = { }
370
+ if ( 'includeHealth' in options && options . includeHealth !== undefined ) {
371
+ params . includeHealth = options . includeHealth . toString ( )
372
+ }
373
+ if ( 'includeStatus' in options && options . includeStatus !== undefined ) {
374
+ params . includeStatus = options . includeStatus . toString ( )
375
+ }
376
+ return this . client . get < Device > ( id , params , { headerOverrides : HEADER_OVERRIDES } )
326
377
}
327
378
328
379
/**
@@ -382,8 +433,8 @@ export class DevicesEndpoint extends Endpoint {
382
433
* @param data the new device profile
383
434
*/
384
435
public updateProfile ( id : string , data : DeviceProfileUpdate ) : Promise < Device > {
385
- return this . client . request < Device > ( 'put' , `${ id } /profile` , data , undefined ,
386
- { headerOverrides : { Accept : 'application/vnd.smartthings+json;v=20170916' } } )
436
+ return this . client . put < Device > ( `${ id } /profile` , data , undefined ,
437
+ { headerOverrides : HEADER_OVERRIDES } )
387
438
}
388
439
389
440
/**
0 commit comments