@@ -5,9 +5,12 @@ import { Links, Status, SuccessStatusValue } from '../types'
55import { PresentationDevicePresentation } from './presentation'
66
77
8+ const HEADER_OVERRIDES = { Accept : 'application/vnd.smartthings+json;v=20170916' }
9+
810export interface CapabilityReference {
911 id : string
1012 version ?: number
13+ status ?: CapabilityStatus
1114}
1215
1316export interface Component {
@@ -84,6 +87,11 @@ export interface ProfileIdentifier {
8487 id : string
8588}
8689
90+ export interface HealthState {
91+ state : DeviceHealthState
92+ lastUpdatedDate ?: string
93+ }
94+
8795export interface Device {
8896 deviceId ?: string
8997 name ?: string
@@ -104,6 +112,7 @@ export interface Device {
104112 viper ?: ViperDeviceDetails
105113 type ?: DeviceIntegrationType
106114 restrictionTier ?: number
115+ healthState ?: HealthState
107116}
108117
109118export interface DeviceUpdate {
@@ -222,6 +231,16 @@ export interface DeviceListOptions {
222231 */
223232 installedAppId ?: string
224233
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+
225244 /**
226245 * Limit the number of results to this value. By default all devices are returned
227246 */
@@ -238,6 +257,18 @@ export interface DeviceListOptions {
238257 type ?: DeviceIntegrationType | DeviceIntegrationType [ ]
239258}
240259
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+
241272export interface HueSaturation {
242273 hue : number
243274 saturation : number
@@ -250,10 +281,12 @@ export class DevicesEndpoint extends Endpoint {
250281
251282 /**
252283 * 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)
254287 *
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
257290 */
258291 public async list ( options : DeviceListOptions = { } ) : Promise < Device [ ] > {
259292 const params : HttpClientParams = { }
@@ -271,6 +304,12 @@ export class DevicesEndpoint extends Endpoint {
271304 if ( 'deviceId' in options && options . deviceId ) {
272305 params . deviceId = options . deviceId
273306 }
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+ }
274313 if ( 'installedAppId' in options && options . installedAppId ) {
275314 params . installedAppId = options . installedAppId
276315 }
@@ -283,7 +322,8 @@ export class DevicesEndpoint extends Endpoint {
283322 if ( 'type' in options && options . type ) {
284323 params . type = options . type
285324 }
286- return this . client . getPagedItems < Device > ( undefined , params )
325+ return this . client . getPagedItems < Device > ( undefined , params ,
326+ { headerOverrides : HEADER_OVERRIDES } )
287327 }
288328
289329 /**
@@ -320,9 +360,20 @@ export class DevicesEndpoint extends Endpoint {
320360 /**
321361 * Returns a description of the specified device
322362 * @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)
323367 */
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 } )
326377 }
327378
328379 /**
@@ -382,8 +433,8 @@ export class DevicesEndpoint extends Endpoint {
382433 * @param data the new device profile
383434 */
384435 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 } )
387438 }
388439
389440 /**
0 commit comments