-
Notifications
You must be signed in to change notification settings - Fork 54
/
devices.ts
1341 lines (1146 loc) · 33.4 KB
/
devices.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
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import { Endpoint } from '../endpoint'
import { EndpointClient, EndpointClientConfig, HttpClientParams } from '../endpoint-client'
import { ConfigEntry} from './installedapps'
import { Links, Status, SuccessStatusValue } from '../types'
import { PresentationDevicePresentation } from './presentation'
const HEADER_OVERRIDES = { Accept: 'application/vnd.smartthings+json;v=20170916' }
export interface CapabilityReference {
id: string
version?: number
status?: CapabilityStatus
}
export interface DeviceProfileReference {
id?: string
}
/**
* Included for backwards compatibility (renamed to match API docs).
* For new code, use DeviceProfileReference.
*
* @deprecated
*/
export type ProfileIdentifier = DeviceProfileReference
export type CategoryType = 'manufacturer' | 'user'
export interface DeviceCategory {
name: string
categoryType: CategoryType
}
export interface Restrictions {
/**
* integer
*/
tier: number
/**
* integer
*/
historyRetentionTTLDays?: number
/**
* default: false
*/
visibleWhenRestricted?: boolean
}
export interface Component {
id: string // <^[-_!.~'()*0-9a-zA-Z]{1,36}$>
capabilities: CapabilityReference[]
categories: DeviceCategory[]
label?: string
restrictions?: Restrictions
icon?: string
}
export interface AppDeviceDetails {
/**
* The ID of the installed app that integrates this device.
*
* <^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$>
*/
installedAppId?: string
/**
* A field to store an ID from a system external to SmartThings.
*
* <= 64 characters
*/
externalId?: string
profile?: DeviceProfileReference
}
// eslint-disable-next-line @typescript-eslint/no-empty-interface
export interface BleDeviceDetails {
// The API defines this object without properties.
}
export interface BleD2DDeviceDetails {
encryptionKey?: string
cipher?: string
advertisingId?: string
identifier?: string
configurationVersion?: string
configurationUrl?: string
metadata?: object
}
export enum DeviceNetworkSecurityLevel {
UNKNOWN = 'UNKNOWN',
ZWAVE_LEGACY_NON_SECURE = 'ZWAVE_LEGACY_NON_SECURE',
ZWAVE_S0_LEGACY = 'ZWAVE_S0_LEGACY',
ZWAVE_S0_FALLBACK = 'ZWAVE_S0_FALLBACK',
ZWAVE_S2_UNAUTHENTICATED = 'ZWAVE_S2_UNAUTHENTICATED',
ZWAVE_S2_AUTHENTICATED = 'ZWAVE_S2_AUTHENTICATED',
ZWAVE_S2_ACCESS_CONTROL = 'ZWAVE_S2_ACCESS_CONTROL',
ZWAVE_S2_FAILED = 'ZWAVE_S2_FAILED',
ZWAVE_S0_FAILED = 'ZWAVE_S0_FAILED',
ZWAVE_S2_DOWNGRADE = 'ZWAVE_S2_DOWNGRADE',
ZWAVE_S0_DOWNGRADE = 'ZWAVE_S0_DOWNGRADE'
}
export interface DthDeviceDetails {
deviceTypeId: string // <^(?:([0-9a-fA-F]{32})|([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}))$>
deviceTypeName: string
completedSetup: boolean
deviceNetworkType?: string
executingLocally?: boolean
hubId?: string
installedGroovyAppId?: string // <^(?:([0-9a-fA-F]{32})|([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}))$>
networkSecurityLevel?: DeviceNetworkSecurityLevel
}
export type ProvisioningState = 'PROVISIONED' | 'TYPED' | 'DRIVER_SWITCH' | 'NONFUNCTIONAL'
export interface LanDeviceDetails {
networkId?: string
driverId?: string
executingLocally?: boolean
hubId?: string
provisioningState?: ProvisioningState
}
export interface ZigbeeDeviceDetails {
eui?: string
networkId?: string
driverId?: string
executingLocally?: boolean
hubId?: string
provisioningState?: ProvisioningState
}
export interface ZwaveDeviceDetails {
networkId?: string
driverId?: string
executingLocally?: boolean
hubId?: string
networkSecurityLevel?: DeviceNetworkSecurityLevel
provisioningState?: ProvisioningState
}
export type MatterListeningType = 'ALWAYS' | 'SLEEPY'
export type MatterNetworkInterfaces = 'THREAD' | 'WIFI' | 'ETHERNET'
export type MatterVersion = {
/**
* 16-bit hardware version
*/
hardware?: number
hardwareLabel?: string
/**
* 32-bit software version
*/
software?: number
softwareLabel?: string
}
export type MatterEndpointDeviceType = {
/**
* 32-bit identifier for the device type
*
* [ 0 .. 4294967295 ]
*/
deviceTypeId?: number
}
export type MatterEndpoint = {
/**
* 16-bit identifier for the endpoint
*/
endpointId?: number
deviceTypes?: MatterEndpointDeviceType[]
}
export interface MatterDeviceDetails {
/**
* matches: string <^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$> (DriverId)
*/
driverId?: string
/**
* The hub that the device is connected to
*/
hubId?: string
/**
* Provisioning type for a device
*/
provisioningState?: ProvisioningState
/**
* The network-specific identifier of the device on the network
*/
networkId?: string
/**
* True if the device is executing locally on the hub
*/
executingLocally?: boolean
/**
* Optional Vendor-supplied unique identifier.
*/
uniqueId?: string
/**
* integer
*/
vendorId?: number
/**
* integer
*/
productId?: number
listeningType?: MatterListeningType
supportedNetworkInterfaces?: MatterNetworkInterfaces[]
version?: MatterVersion
endpoints?: MatterEndpoint[]
}
/**
* Possible Values for Hub Characteristic "Availability" flags.
*/
export type AvailabilityCharacteristic = 'Available' | 'Unavailable' | 'Unsupported'
export type HubData = {
/**
* Whether zwaveS2 is enabled for this hub.
*/
zwaveS2: boolean
/**
* Whether the hub supports zigbee3.
*/
zigbee3: boolean
hardwareType: string
/**
* Whether the hub allows zigbee unsecure rejoin.
*/
zigbeeUnsecureRejoin: boolean
zwaveStaticDsk?: string
hardwareId?: string
/**
* The Zigbee firmware version for this hub.
*/
zigbeeFirmware: string
/**
* Describes state of Zigbee OTA.
*/
zigbeeOta?: string
/**
* Indicates if Zigbee OTA is enabled.
*/
otaEnable?: string
primarySupportAvailability?: AvailabilityCharacteristic
secondarySupportAvailability?: AvailabilityCharacteristic
zigbeeAvailability?: AvailabilityCharacteristic
zwaveAvailability?: AvailabilityCharacteristic
threadAvailability?: AvailabilityCharacteristic
lanAvailability?: AvailabilityCharacteristic
matterAvailability?: AvailabilityCharacteristic
localVirtualDeviceAvailability?: AvailabilityCharacteristic
/**
* The primary hub device id for this hub. Null/Empty if hub is not a repeater.
*/
primaryHubDeviceId?: string
zigbeeChannel?: string
/**
* The Personal Area Network (PAN) id of the zigbee network the hub is on.
*/
zigbeePanId?: string
/**
* The unique identifier for this manufactured hub.
*/
zigbeeEui?: string
/**
* The short address of a node in Zigbee network.
*/
zigbeeNodeID?: string
/**
* The address of a single node in the network.
*/
zwaveNodeID?: string
/**
* The common identification of all nodes belonging to one logical Z-Wave network.
*/
zwaveHomeID?: string
zwaveSucID?: string
zwaveVersion?: string
/**
* The global region this zwave radio is operating in.
*/
zwaveRegion?: string
/**
* MAC address of the hubs network interface.
*/
macAddress?: string
/**
* IP address of the hub.
*/
localIP?: string
/**
* Whether the hub is zigbee radio functional.
*/
zigbeeRadioFunctional?: boolean
/**
* Whether the hub is zwave radio functional.
*/
zwaveRadioFunctional?: boolean
}
export type HubDriver = {
/**
* The id of the edge driver.
*/
driverId: string
/**
* The version of the edge driver.
*/
driverVersion?: string
/**
* The id of the edge channel.
*/
channelId?: string
}
export type HubDeviceDetails = {
/**
* The unique identifier for this manufactured hub.
*
* <^[0-9A-F]{16}$>
*/
hubEui: string
/**
* The hub's firmware version.
*
* <^[0-9]\.[0-9]\.[0-9]{3}$>
*/
firmwareVersion?: string
hubData: HubData
/**
* A list of drivers installed on the hub.
*/
hubDrivers: HubDriver[]
}
export type EdgeChildDeviceDetails = {
driverId?: string
/**
* The hub that the device is connected to.
*/
hubId?: string
/**
* Provisioning type for a device.
*/
provisioningState?: ProvisioningState
/**
* The network-specific identifier of the device on the network.
*/
networkId?: string
/**
* True if the device is executing locally on the hub.
*/
executingLocally?: boolean
/**
* The identifier assigned to this edge child device by its parent.
*/
parentAssignedChildKey?: string
}
export interface IrDeviceDetails {
parentDeviceId?: string // <^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$>
profileId?: string // <^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$>
ocfDeviceType?: string
irCode?: string
// eslint-disable-next-line @typescript-eslint/no-explicit-any
functionCodes?: { default?: string; [name: string]: any }
childDevices?: IrDeviceDetails[]
metadata?: object
}
export interface OcfDeviceDetails {
deviceId?: string
ocfDeviceType?: string
name?: string
specVersion?: string
verticalDomainSpecVersion?: string
manufacturerName?: string
modelNumber?: string
platformVersion?: string
platformOS?: string
hwVersion?: string
firmwareVersion?: string
vendorId?: string
vendorResourceClientServerVersion?: string
locale?: string
lastSignupTime?: string
}
export type DeviceGroupType = 'UNDETERMINED' | 'GENERIC' | 'VIDEO_CAMERA' | 'LIGHTING'
export type GroupDeviceDetails = {
groupName?: string
/**
* The type of the group in question
*
* "UNDETERMINED" is a default value and is not used during normal operation. Passing
* "UNDETERMINED" into the API is the same as not passing a group type.
*/
groupType?: DeviceGroupType
devices?: {
deviceId: string
/**
* Components to add to the group.
*/
components?: {
id?: string
[name: string]: unknown
}
}[]
}
export interface ViperDeviceDetails {
uniqueIdentifier?: string
manufacturerName?: string
modelName?: string
swVersion?: string
hwVersion?: string
}
export interface AttributeValue {
/**
* The attribute that this command will correspond to
*/
attribute?: string
/**
* How will the attribute be provided? Choose 'ARGUMENT' to provide it with a command at
* runtime or 'STATIC' to provide a set value here.
*/
inputType: 'ARGUMENT' | 'STATIC'
/**
* The argument to be used automatically for this command mapping. Any simple type is accepted.
*/
staticValue: string | number | boolean
}
export interface CommandMapping {
capabilityId: string
/**
* The capability version number.
*/
version: string
/**
* The command name to apply the mapping to on the device
*/
command: string
/**
* A collection of attribute values, replicator will use these to create device events in
* serial for the specified command.
*/
eventValues: AttributeValue[]
}
export interface CommandMappings {
commands: CommandMapping[]
}
export interface VirtualDeviceDetails {
name?: string
hubId?: string
driverId?: string
commandMappings?: CommandMappings
}
export enum DeviceIntegrationType {
BLE = 'BLE',
BLE_D2D = 'BLE_D2D',
DTH = 'DTH',
ENDPOINT_APP = 'ENDPOINT_APP',
GROUP = 'GROUP',
HUB = 'HUB',
IR = 'IR',
IR_OCF = 'IR_OCF',
LAN = 'LAN',
MATTER = 'MATTER',
MOBILE = 'MOBILE',
MQTT = 'MQTT',
OCF = 'OCF',
PENGYOU = 'PENGYOU',
SHP = 'SHP',
VIDEO = 'VIDEO',
VIPER = 'VIPER',
VIRTUAL = 'VIRTUAL',
WATCH = 'WATCH',
ZIGBEE = 'ZIGBEE',
ZWAVE = 'ZWAVE',
EDGE_CHILD = 'EDGE_CHILD',
}
export interface HealthState {
state: DeviceHealthState
lastUpdatedDate?: string
}
interface ChildDeviceRef {
id: string
}
export type DeviceClientAction = 'w:devices' | 'w:devices:locationId' | 'w:devices:roomId' | 'x:devices' | 'd:devices'
export type IndoorMap = {
/**
* The coordinates to be used to map the device.
*/
coordinates?: [number, number, number]
/**
* The rotational data for the device.
*/
rotation?: [number, number, number]
/**
* Whether or not the device is visible on the map.
*/
visible?: boolean
/**
* Key value pairs to place additional information.
*/
data: {
[name: string]: unknown
}
}
export interface Device {
deviceId: string
/**
* A non-unique id that is used to help drive UI information.
*/
presentationId: string
/**
* The device manufacturer name.
*/
manufacturerName: string
/**
* The type of device integration (may be null). If the type is LAN, the device implementation
* is a groovy Device Handler and the details are in the "lan" field. If the type is
* ENDPOINT_APP, the device implementation is a SmartApp and the details are in the "app"
* field, etc.
*/
type: DeviceIntegrationType
/**
* Restriction tier of the device, if any.
*
* integer value
*/
restrictionTier: number
/**
* The name that the Device integration (Device Handler or SmartApp) defines for the Device.
*/
name?: string
/**
* The name that a user chooses for the Device. This defaults to the same value as name.
*/
label?: string
/**
* The device manufacturer code.
*/
deviceManufacturerCode?: string
/**
* The ID of the Location with which the Device is associated.
*
* matches; <^(?:([0-9a-fA-F]{32})|([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}))$>
*/
locationId?: string
/**
* The identifier for the owner of the Device instance.
*/
ownerId?: string
/**
* The ID of the Room with which the Device is associated. If the Device is not associated with
* any room, this field will be null.
*
* matches: <^(?:([0-9a-fA-F]{32})|([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}))$>
*/
roomId?: string
/**
* @deprecated please use dth.deviceTypeId instead
*
* matches: <^(?:([0-9a-fA-F]{32})|([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}))$>
*/
deviceTypeId?: string
/**
* The IDs of all components on the device.
*/
components?: Component[]
/**
* The time when the device was created.
*/
createTime?: string
/**
* The id of the parent device.
*/
parentDeviceId?: string
/**
* References containing device ids of all child devices of the device.
*/
childDevices?: ChildDeviceRef[]
profile?: DeviceProfileReference
app?: AppDeviceDetails
ble?: BleDeviceDetails
bleD2D?: BleD2DDeviceDetails
dth?: DthDeviceDetails
lan?: LanDeviceDetails
zigbee?: ZigbeeDeviceDetails
zwave?: ZwaveDeviceDetails
matter?: MatterDeviceDetails
hub?: HubDeviceDetails
edgeChild?: EdgeChildDeviceDetails
ir?: IrDeviceDetails
irOcf?: IrDeviceDetails
ocf?: OcfDeviceDetails
group?: GroupDeviceDetails
viper?: ViperDeviceDetails
virtual?: VirtualDeviceDetails
/**
* List of client-facing action identifiers that are currently permitted for the user.
* If the value of this property is not null, then any action not included in the list value of
* the property is currently prohibited for the user.
*
* * w:devices - the user can change device details
* * w:devices:locationId - the user can move the device from a location
* * w:devices:roomId - the user can move or remove the device from a room
* * x:devices - the user can execute commands on the device
* * d:devices - the user can uninstall the device
*/
allowed?: DeviceClientAction[]
indoorMap?: IndoorMap
}
export interface UpdateDeviceComponent {
id: string
categories: string[]
icon?: string
}
export interface DeviceUpdate {
label?: string
locationId?: string
roomId?: string
components?: UpdateDeviceComponent[]
}
export interface DeviceProfileUpdate {
profileId: string
}
export interface CreateAppDeviceDetails {
profileId: string
/**
* installedAppId is required but the user can set a default when instantiating
* SmartThingsClient so we don't required it here.
*
* <^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$>
*/
installedAppId?: string
/**
* A field to store an ID from a system external to SmartThings.
*
* <= 64 characters
*/
externalId?: string
}
export interface DeviceCreateBase {
app?: CreateAppDeviceDetails
/**
* locationId is required but the user can set a default when instantiating
* SmartThingsClient so we don't required it here.
*/
locationId?: string // <^(?:([0-9a-fA-F]{32})|([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}))$>
label?: string
roomId?: string
}
export interface DeviceCreate extends DeviceCreateBase {
app: CreateAppDeviceDetails
}
export interface AlternateDeviceCreate extends DeviceCreateBase {
installedAppId?: string // <^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$>
/**
* A field to store an ID from a system external to SmartThings.
*
* <= 64 characters
*/
externalId?: string
profileId: string
app?: undefined
}
export interface DeviceList {
items: Device[]
_links: Links
}
export interface AttributeState {
value?: unknown
unit?: string
data?: { [name: string]: object }
timestamp?: string
}
export interface CapabilityStatus {
[attributeName: string]: AttributeState
}
export interface ComponentStatus {
[attributeName: string]: CapabilityStatus
}
export interface DeviceStatus {
components?: { [componentId: string]: ComponentStatus }
healthState?: HealthState
}
export interface DeviceEvent {
value: unknown
component: string
capability: string
attribute: string
unit?: string
data?: { [name: string]: object }
}
export interface DeviceEventList {
deviceEvents: DeviceEvent[]
}
export enum DeviceHealthState {
ONLINE = 'ONLINE',
OFFLINE = 'OFFLINE',
UNKNOWN = 'UNKNOWN',
}
export interface DeviceHealth {
deviceId: string
state: DeviceHealthState
lastUpdatedDate?: string
}
export interface Command {
capability: string
command: string
component?: string
arguments?: (object | string | number)[]
}
export interface CommandRequest {
capability: string
command: string
arguments?: (object | string | number)[]
}
export interface CommandList {
commands: Command[]
}
export type CommandStatus = 'ACCEPTED' | 'COMPLETED' | 'FAILED'
export interface CommandResult {
id: string
status: CommandStatus
}
export interface CommandResponse {
results: CommandResult[]
}
export type PreferenceType = 'integer' | 'number' | 'boolean' | 'string' | 'enumeration'
export interface DevicePreferenceEntry {
preferenceType: PreferenceType
value: string | number | boolean
}
export interface DevicePreferenceResponse {
/**
* Map of preference name to its stored value
*/
values: Partial<Record<string, DevicePreferenceEntry>>
}
export interface DeviceListOptions {
/**
* Capability ID (for example, 'switchLevel') or array of capability IDs
*/
capability?: string | string[]
/**
* Location UUID or array of location UUIDs
*/
locationId?: string | string[]
/**
* Device UUID or array of device UUIDs
*/
deviceId?: string | string[]
/**
* Whether to AND or OR the capability IDs when more than one is specified
*/
capabilitiesMode?: 'and' | 'or'
/**
* Restricted Devices are hidden by default. This option will reveal them. Device status will
* not be provided if the token does not have sufficient access level to view the device status
* even if includeStatus parameter is set to true.
*/
includeRestricted?: boolean
/**
* Only list Devices accessible by the given integer accessLevel.
*/
accessLevel?: number
/**
* UUID of an installed app instance
*/
installedAppId?: string
/**
* Include the device health, i.e. online/offline status in the response
*/
includeHealth?: boolean
/**
* Include the device status data, i.e. the values of all attributes, in the response
*/
includeStatus?: boolean
/**
* Limit the number of results to this value. By default all devices are returned
*/
max?: number
/**
* Page number for when a max number of results has been specified, starting with 1
*/
page?: number
/**
* Device Type
*/
type?: DeviceIntegrationType | DeviceIntegrationType[]
}
export interface DeviceGetOptions {
/**
* Include the device health, i.e. online/offline status in the response
*/
includeHealth?: boolean
/**
* Include the device status data, i.e. the values of all attributes, in the response
*/
includeStatus?: boolean
}
export interface HueSaturation {
hue: number
saturation: number
}
export class DevicesEndpoint extends Endpoint {
constructor(config: EndpointClientConfig) {
super(new EndpointClient('devices', config))
}
/**
* Returns a list of devices matching the query options or all devices accessible by the principal (i.e. user)
* if no options are specified. If the includeHealth option is set to true then the response will also contain
* the health status of each device (i.e. if it is online or offline). If the includeStatus option is set to true
* then the response will also include the status of all attributes (i.e. value and timestamp)
*
* @param options query options, capability, capabilitiesMode ('and' or 'or'), locationId, deviceId. which can
* be single values or arrays, and includeHealth & includeStatus booleans
*/
public async list(options: DeviceListOptions = {}): Promise<Device[]> {
const params: HttpClientParams = {}
if ('capability' in options && options.capability) {
params.capability = options.capability
}
if ('locationId' in options && options.locationId) {
params.locationId = options.locationId
} else if (this.client.config.locationId) {
params.locationId = this.client.config.locationId
}
if ('deviceId' in options && options.deviceId) {
params.deviceId = options.deviceId
}
if ('capabilitiesMode' in options && options.capabilitiesMode) {
params.capabilitiesMode = options.capabilitiesMode
}
if ('includeRestricted' in options && options.includeRestricted !== undefined) {
params.includeRestricted = options.includeRestricted.toString()
}
if ('accessLevel' in options && options.accessLevel) {
params.accessLevel = options.accessLevel
}
if ('includeHealth' in options && options.includeHealth !== undefined) {
params.includeHealth = options.includeHealth.toString()
}
if ('includeStatus' in options && options.includeStatus !== undefined) {
params.includeStatus = options.includeStatus.toString()
}
if ('installedAppId' in options && options.installedAppId) {
params.installedAppId = options.installedAppId
}
if ('max' in options && options.max) {
params.max = options.max
}
if ('page' in options && options.page) {
params.page = options.page
}
if ('type' in options && options.type) {
params.type = options.type
}
return this.client.getPagedItems<Device>(undefined, params,
{ headerOverrides: HEADER_OVERRIDES })
}