@switchbot/homebridge-switchbot 3.5.0-beta.3 → 3.5.0-beta.30

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (166) hide show
  1. package/CHANGELOG.md +4 -1
  2. package/config.schema.json +147 -9
  3. package/dist/device/blindtilt.d.ts +21 -94
  4. package/dist/device/blindtilt.d.ts.map +1 -1
  5. package/dist/device/blindtilt.js +347 -756
  6. package/dist/device/blindtilt.js.map +1 -1
  7. package/dist/device/bot.d.ts +25 -71
  8. package/dist/device/bot.d.ts.map +1 -1
  9. package/dist/device/bot.js +582 -759
  10. package/dist/device/bot.js.map +1 -1
  11. package/dist/device/ceilinglight.d.ts +13 -67
  12. package/dist/device/ceilinglight.d.ts.map +1 -1
  13. package/dist/device/ceilinglight.js +209 -587
  14. package/dist/device/ceilinglight.js.map +1 -1
  15. package/dist/device/colorbulb.d.ts +13 -74
  16. package/dist/device/colorbulb.d.ts.map +1 -1
  17. package/dist/device/colorbulb.js +250 -632
  18. package/dist/device/colorbulb.js.map +1 -1
  19. package/dist/device/contact.d.ts +14 -65
  20. package/dist/device/contact.d.ts.map +1 -1
  21. package/dist/device/contact.js +204 -531
  22. package/dist/device/contact.js.map +1 -1
  23. package/dist/device/curtain.d.ts +17 -86
  24. package/dist/device/curtain.d.ts.map +1 -1
  25. package/dist/device/curtain.js +335 -786
  26. package/dist/device/curtain.js.map +1 -1
  27. package/dist/device/device.d.ts +59 -0
  28. package/dist/device/device.d.ts.map +1 -0
  29. package/dist/device/device.js +646 -0
  30. package/dist/device/device.js.map +1 -0
  31. package/dist/device/fan.d.ts +51 -0
  32. package/dist/device/fan.d.ts.map +1 -0
  33. package/dist/device/fan.js +499 -0
  34. package/dist/device/fan.js.map +1 -0
  35. package/dist/device/hub.d.ts +15 -59
  36. package/dist/device/hub.d.ts.map +1 -1
  37. package/dist/device/hub.js +242 -596
  38. package/dist/device/hub.js.map +1 -1
  39. package/dist/device/humidifier.d.ts +10 -65
  40. package/dist/device/humidifier.d.ts.map +1 -1
  41. package/dist/device/humidifier.js +207 -571
  42. package/dist/device/humidifier.js.map +1 -1
  43. package/dist/device/iosensor.d.ts +11 -64
  44. package/dist/device/iosensor.d.ts.map +1 -1
  45. package/dist/device/iosensor.js +174 -584
  46. package/dist/device/iosensor.js.map +1 -1
  47. package/dist/device/lightstrip.d.ts +10 -68
  48. package/dist/device/lightstrip.d.ts.map +1 -1
  49. package/dist/device/lightstrip.js +252 -568
  50. package/dist/device/lightstrip.js.map +1 -1
  51. package/dist/device/lock.d.ts +15 -62
  52. package/dist/device/lock.d.ts.map +1 -1
  53. package/dist/device/lock.js +210 -542
  54. package/dist/device/lock.js.map +1 -1
  55. package/dist/device/meter.d.ts +13 -63
  56. package/dist/device/meter.d.ts.map +1 -1
  57. package/dist/device/meter.js +170 -577
  58. package/dist/device/meter.js.map +1 -1
  59. package/dist/device/meterplus.d.ts +13 -64
  60. package/dist/device/meterplus.d.ts.map +1 -1
  61. package/dist/device/meterplus.js +159 -577
  62. package/dist/device/meterplus.js.map +1 -1
  63. package/dist/device/motion.d.ts +13 -69
  64. package/dist/device/motion.d.ts.map +1 -1
  65. package/dist/device/motion.js +136 -518
  66. package/dist/device/motion.js.map +1 -1
  67. package/dist/device/plug.d.ts +9 -57
  68. package/dist/device/plug.d.ts.map +1 -1
  69. package/dist/device/plug.js +82 -452
  70. package/dist/device/plug.js.map +1 -1
  71. package/dist/device/robotvacuumcleaner.d.ts +11 -62
  72. package/dist/device/robotvacuumcleaner.d.ts.map +1 -1
  73. package/dist/device/robotvacuumcleaner.js +140 -451
  74. package/dist/device/robotvacuumcleaner.js.map +1 -1
  75. package/dist/device/waterdetector.d.ts +9 -70
  76. package/dist/device/waterdetector.d.ts.map +1 -1
  77. package/dist/device/waterdetector.js +121 -664
  78. package/dist/device/waterdetector.js.map +1 -1
  79. package/dist/index.js +1 -1
  80. package/dist/irdevice/airconditioner.d.ts +8 -48
  81. package/dist/irdevice/airconditioner.d.ts.map +1 -1
  82. package/dist/irdevice/airconditioner.js +309 -419
  83. package/dist/irdevice/airconditioner.js.map +1 -1
  84. package/dist/irdevice/airpurifier.d.ts +7 -38
  85. package/dist/irdevice/airpurifier.d.ts.map +1 -1
  86. package/dist/irdevice/airpurifier.js +72 -304
  87. package/dist/irdevice/airpurifier.js.map +1 -1
  88. package/dist/irdevice/camera.d.ts +6 -35
  89. package/dist/irdevice/camera.d.ts.map +1 -1
  90. package/dist/irdevice/camera.js +34 -278
  91. package/dist/irdevice/camera.js.map +1 -1
  92. package/dist/irdevice/fan.d.ts +6 -39
  93. package/dist/irdevice/fan.d.ts.map +1 -1
  94. package/dist/irdevice/fan.js +67 -311
  95. package/dist/irdevice/fan.js.map +1 -1
  96. package/dist/irdevice/irdevice.d.ts +40 -0
  97. package/dist/irdevice/irdevice.d.ts.map +1 -0
  98. package/dist/irdevice/irdevice.js +509 -0
  99. package/dist/irdevice/irdevice.js.map +1 -0
  100. package/dist/irdevice/light.d.ts +6 -34
  101. package/dist/irdevice/light.d.ts.map +1 -1
  102. package/dist/irdevice/light.js +23 -272
  103. package/dist/irdevice/light.js.map +1 -1
  104. package/dist/irdevice/other.d.ts +18 -47
  105. package/dist/irdevice/other.d.ts.map +1 -1
  106. package/dist/irdevice/other.js +352 -546
  107. package/dist/irdevice/other.js.map +1 -1
  108. package/dist/irdevice/tv.d.ts +7 -39
  109. package/dist/irdevice/tv.d.ts.map +1 -1
  110. package/dist/irdevice/tv.js +82 -321
  111. package/dist/irdevice/tv.js.map +1 -1
  112. package/dist/irdevice/vacuumcleaner.d.ts +6 -35
  113. package/dist/irdevice/vacuumcleaner.d.ts.map +1 -1
  114. package/dist/irdevice/vacuumcleaner.js +41 -284
  115. package/dist/irdevice/vacuumcleaner.js.map +1 -1
  116. package/dist/irdevice/waterheater.d.ts +6 -35
  117. package/dist/irdevice/waterheater.d.ts.map +1 -1
  118. package/dist/irdevice/waterheater.js +42 -287
  119. package/dist/irdevice/waterheater.js.map +1 -1
  120. package/dist/platform.d.ts +14 -1
  121. package/dist/platform.d.ts.map +1 -1
  122. package/dist/platform.js +237 -94
  123. package/dist/platform.js.map +1 -1
  124. package/dist/settings.d.ts +40 -10
  125. package/dist/settings.d.ts.map +1 -1
  126. package/dist/settings.js +0 -552
  127. package/dist/settings.js.map +1 -1
  128. package/dist/utils.d.ts +77 -0
  129. package/dist/utils.d.ts.map +1 -1
  130. package/dist/utils.js +638 -1
  131. package/dist/utils.js.map +1 -1
  132. package/package.json +16 -15
  133. package/src/custom.d.ts +2 -1
  134. package/src/device/blindtilt.ts +373 -782
  135. package/src/device/bot.ts +616 -844
  136. package/src/device/ceilinglight.ts +222 -607
  137. package/src/device/colorbulb.ts +264 -656
  138. package/src/device/contact.ts +229 -553
  139. package/src/device/curtain.ts +355 -810
  140. package/src/device/device.ts +673 -0
  141. package/src/device/fan.ts +548 -0
  142. package/src/device/hub.ts +268 -623
  143. package/src/device/humidifier.ts +237 -618
  144. package/src/device/iosensor.ts +200 -610
  145. package/src/device/lightstrip.ts +273 -596
  146. package/src/device/lock.ts +247 -582
  147. package/src/device/meter.ts +196 -601
  148. package/src/device/meterplus.ts +184 -602
  149. package/src/device/motion.ts +156 -541
  150. package/src/device/plug.ts +92 -480
  151. package/src/device/robotvacuumcleaner.ts +161 -477
  152. package/src/device/waterdetector.ts +139 -689
  153. package/src/index.ts +1 -1
  154. package/src/irdevice/airconditioner.ts +330 -446
  155. package/src/irdevice/airpurifier.ts +89 -321
  156. package/src/irdevice/camera.ts +42 -293
  157. package/src/irdevice/fan.ts +78 -327
  158. package/src/irdevice/irdevice.ts +526 -0
  159. package/src/irdevice/light.ts +32 -287
  160. package/src/irdevice/other.ts +396 -615
  161. package/src/irdevice/tv.ts +100 -339
  162. package/src/irdevice/vacuumcleaner.ts +49 -305
  163. package/src/irdevice/waterheater.ts +50 -310
  164. package/src/platform.ts +247 -102
  165. package/src/settings.ts +56 -565
  166. package/src/utils.ts +642 -1
@@ -0,0 +1,526 @@
1
+ /* Copyright(C) 2021-2024, donavanbecker (https://github.com/donavanbecker). All rights reserved.
2
+ *
3
+ * device.ts: homebridge-august.
4
+ */
5
+ import { API, HAP, Logging, PlatformAccessory } from 'homebridge';
6
+
7
+ import { SwitchBotPlatform } from '../platform.js';
8
+ import { SwitchBotPlatformConfig, irDevicesConfig, irdevice } from '../settings.js';
9
+
10
+ export abstract class irdeviceBase {
11
+ public readonly api: API;
12
+ public readonly log: Logging;
13
+ public readonly config!: SwitchBotPlatformConfig;
14
+ protected readonly hap: HAP;
15
+
16
+ // Config
17
+ protected deviceLogging!: string;
18
+ protected disablePushOn!: boolean;
19
+ protected disablePushOff!: boolean;
20
+ protected disablePushDetail?: boolean;
21
+
22
+ constructor(
23
+ protected readonly platform: SwitchBotPlatform,
24
+ protected accessory: PlatformAccessory,
25
+ protected device: irdevice & irDevicesConfig,
26
+ ) {
27
+ this.api = this.platform.api;
28
+ this.log = this.platform.log;
29
+ this.config = this.platform.config;
30
+ this.hap = this.api.hap;
31
+
32
+ this.getDeviceLogSettings(device);
33
+ this.getDeviceConfigSettings(device);
34
+ this.getDeviceContext(accessory, device);
35
+ this.disablePushOnChanges(device);
36
+ this.disablePushOffChanges(device);
37
+
38
+ // Set accessory information
39
+ accessory
40
+ .getService(this.hap.Service.AccessoryInformation)!
41
+ .setCharacteristic(this.hap.Characteristic.Manufacturer, 'SwitchBot')
42
+ .setCharacteristic(this.hap.Characteristic.Name, accessory.displayName)
43
+ .setCharacteristic(this.hap.Characteristic.ConfiguredName, accessory.context.name)
44
+ .setCharacteristic(this.hap.Characteristic.Model, accessory.context.model)
45
+ .setCharacteristic(this.hap.Characteristic.SerialNumber, accessory.context.deviceId)
46
+ .setCharacteristic(this.hap.Characteristic.FirmwareRevision, accessory.context.FirmwareRevision)
47
+ .getCharacteristic(this.hap.Characteristic.FirmwareRevision)
48
+ .updateValue(accessory.context.FirmwareRevision);
49
+ }
50
+
51
+ async getDeviceLogSettings(device: irdevice & irDevicesConfig): Promise<void> {
52
+ if (this.platform.debugMode) {
53
+ this.deviceLogging = this.accessory.context.logging = 'debugMode';
54
+ this.debugWarnLog(`${this.device.remoteType}: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`);
55
+ } else if (device.logging) {
56
+ this.deviceLogging = this.accessory.context.logging = device.logging;
57
+ this.debugWarnLog(`${this.device.remoteType}: ${this.accessory.displayName} Using Device Config Logging: ${this.deviceLogging}`);
58
+ } else if (this.config.logging) {
59
+ this.deviceLogging = this.accessory.context.logging = this.config.logging;
60
+ this.debugWarnLog(`${this.device.remoteType}: ${this.accessory.displayName} Using Platform Config Logging: ${this.deviceLogging}`);
61
+ } else {
62
+ this.deviceLogging = this.accessory.context.logging = 'standard';
63
+ this.debugWarnLog(`${this.device.remoteType}: ${this.accessory.displayName} Logging Not Set, Using: ${this.deviceLogging}`);
64
+ }
65
+ }
66
+
67
+ async getDeviceConfigSettings(device: irdevice & irDevicesConfig): Promise<void> {
68
+ let config = {};
69
+ if (device.logging !== undefined) {
70
+ config['logging'] = device.logging;
71
+ }
72
+ if (device.irair) {
73
+ config = device.irair;
74
+ }
75
+ if (device.connectionType !== undefined) {
76
+ config['connectionType'] = device.connectionType;
77
+ }
78
+ if (device.external !== undefined) {
79
+ config['external'] = device.external;
80
+ }
81
+ if (device.customOn !== undefined) {
82
+ config['customOn'] = device.customOn;
83
+ }
84
+ if (device.customOff !== undefined) {
85
+ config['customOff'] = device.customOff;
86
+ }
87
+ if (device.customize !== undefined) {
88
+ config['customize'] = device.customize;
89
+ }
90
+ if (device.disablePushOn !== undefined) {
91
+ config['disablePushOn'] = device.disablePushOn;
92
+ }
93
+ if (device.disablePushOff !== undefined) {
94
+ config['disablePushOff'] = device.disablePushOff;
95
+ }
96
+ if (device.disablePushDetail !== undefined) {
97
+ config['disablePushDetail'] = device.disablePushDetail;
98
+ }
99
+ if (device.irpur) {
100
+ config = device.irpur;
101
+ }
102
+ if (device.logging !== undefined) {
103
+ config['logging'] = device.logging;
104
+ }
105
+ if (device.connectionType !== undefined) {
106
+ config['connectionType'] = device.connectionType;
107
+ }
108
+ if (device.external !== undefined) {
109
+ config['external'] = device.external;
110
+ }
111
+ if (device.customOn !== undefined) {
112
+ config['customOn'] = device.customOn;
113
+ }
114
+ if (device.customOff !== undefined) {
115
+ config['customOff'] = device.customOff;
116
+ }
117
+ if (device.customize !== undefined) {
118
+ config['customize'] = device.customize;
119
+ }
120
+ if (device.disablePushOn !== undefined) {
121
+ config['disablePushOn'] = device.disablePushOn;
122
+ }
123
+ if (device.disablePushOff !== undefined) {
124
+ config['disablePushOff'] = device.disablePushOff;
125
+ }
126
+ if (device.ircam) {
127
+ config = device.ircam;
128
+ }
129
+ if (device.logging !== undefined) {
130
+ config['logging'] = device.logging;
131
+ }
132
+ if (device.connectionType !== undefined) {
133
+ config['connectionType'] = device.connectionType;
134
+ }
135
+ if (device.external !== undefined) {
136
+ config['external'] = device.external;
137
+ }
138
+ if (device.customOn !== undefined) {
139
+ config['customOn'] = device.customOn;
140
+ }
141
+ if (device.customOff !== undefined) {
142
+ config['customOff'] = device.customOff;
143
+ }
144
+ if (device.customize !== undefined) {
145
+ config['customize'] = device.customize;
146
+ }
147
+ if (device.disablePushOn !== undefined) {
148
+ config['disablePushOn'] = device.disablePushOn;
149
+ }
150
+ if (device.disablePushOff !== undefined) {
151
+ config['disablePushOff'] = device.disablePushOff;
152
+ }
153
+ if (device.irfan) {
154
+ config = device.irfan;
155
+ }
156
+ if (device.logging !== undefined) {
157
+ config['logging'] = device.logging;
158
+ }
159
+ if (device.connectionType !== undefined) {
160
+ config['connectionType'] = device.connectionType;
161
+ }
162
+ if (device.external !== undefined) {
163
+ config['external'] = device.external;
164
+ }
165
+ if (device.customOn !== undefined) {
166
+ config['customOn'] = device.customOn;
167
+ }
168
+ if (device.customOff !== undefined) {
169
+ config['customOff'] = device.customOff;
170
+ }
171
+ if (device.customize !== undefined) {
172
+ config['customize'] = device.customize;
173
+ }
174
+ if (device.disablePushOn !== undefined) {
175
+ config['disablePushOn'] = device.disablePushOn;
176
+ }
177
+ if (device.disablePushOff !== undefined) {
178
+ config['disablePushOff'] = device.disablePushOff;
179
+ }
180
+ if (device.irlight) {
181
+ config = device.irlight;
182
+ }
183
+ if (device.logging !== undefined) {
184
+ config['logging'] = device.logging;
185
+ }
186
+ if (device.connectionType !== undefined) {
187
+ config['connectionType'] = device.connectionType;
188
+ }
189
+ if (device.external !== undefined) {
190
+ config['external'] = device.external;
191
+ }
192
+ if (device.customOn !== undefined) {
193
+ config['customOn'] = device.customOn;
194
+ }
195
+ if (device.customOff !== undefined) {
196
+ config['customOff'] = device.customOff;
197
+ }
198
+ if (device.customize !== undefined) {
199
+ config['customize'] = device.customize;
200
+ }
201
+ if (device.disablePushOn !== undefined) {
202
+ config['disablePushOn'] = device.disablePushOn;
203
+ }
204
+ if (device.disablePushOff !== undefined) {
205
+ config['disablePushOff'] = device.disablePushOff;
206
+ }
207
+ if (device.other) {
208
+ config = device.other;
209
+ }
210
+ if (device.logging !== undefined) {
211
+ config['logging'] = device.logging;
212
+ }
213
+ if (device.connectionType !== undefined) {
214
+ config['connectionType'] = device.connectionType;
215
+ }
216
+ if (device.external !== undefined) {
217
+ config['external'] = device.external;
218
+ }
219
+ if (device.customOn !== undefined) {
220
+ config['customOn'] = device.customOn;
221
+ }
222
+ if (device.customOff !== undefined) {
223
+ config['customOff'] = device.customOff;
224
+ }
225
+ if (device.customize !== undefined) {
226
+ config['customize'] = device.customize;
227
+ }
228
+ if (device.disablePushOn !== undefined) {
229
+ config['disablePushOn'] = device.disablePushOn;
230
+ }
231
+ if (device.disablePushOff !== undefined) {
232
+ config['disablePushOff'] = device.disablePushOff;
233
+ }
234
+ if (device.irtv) {
235
+ config = device.irtv;
236
+ }
237
+ if (device.logging !== undefined) {
238
+ config['logging'] = device.logging;
239
+ }
240
+ if (device.connectionType !== undefined) {
241
+ config['connectionType'] = device.connectionType;
242
+ }
243
+ if (device.external !== undefined) {
244
+ config['external'] = device.external;
245
+ }
246
+ if (device.customOn !== undefined) {
247
+ config['customOn'] = device.customOn;
248
+ }
249
+ if (device.customOff !== undefined) {
250
+ config['customOff'] = device.customOff;
251
+ }
252
+ if (device.customize !== undefined) {
253
+ config['customize'] = device.customize;
254
+ }
255
+ if (device.disablePushOn !== undefined) {
256
+ config['disablePushOn'] = device.disablePushOn;
257
+ }
258
+ if (device.disablePushOff !== undefined) {
259
+ config['disablePushOff'] = device.disablePushOff;
260
+ }
261
+ if (device.disablePushDetail !== undefined) {
262
+ config['disablePushDetail'] = device.disablePushDetail;
263
+ }
264
+ if (device.irvc) {
265
+ config = device.irvc;
266
+ }
267
+ if (device.logging !== undefined) {
268
+ config['logging'] = device.logging;
269
+ }
270
+ if (device.connectionType !== undefined) {
271
+ config['connectionType'] = device.connectionType;
272
+ }
273
+ if (device.external !== undefined) {
274
+ config['external'] = device.external;
275
+ }
276
+ if (device.customOn !== undefined) {
277
+ config['customOn'] = device.customOn;
278
+ }
279
+ if (device.customOff !== undefined) {
280
+ config['customOff'] = device.customOff;
281
+ }
282
+ if (device.customize !== undefined) {
283
+ config['customize'] = device.customize;
284
+ }
285
+ if (device.disablePushOn !== undefined) {
286
+ config['disablePushOn'] = device.disablePushOn;
287
+ }
288
+ if (device.disablePushOff !== undefined) {
289
+ config['disablePushOff'] = device.disablePushOff;
290
+ }
291
+ if (device.irwh) {
292
+ config = device.irwh;
293
+ }
294
+ if (device.logging !== undefined) {
295
+ config['logging'] = device.logging;
296
+ }
297
+ if (device.connectionType !== undefined) {
298
+ config['connectionType'] = device.connectionType;
299
+ }
300
+ if (device.external !== undefined) {
301
+ config['external'] = device.external;
302
+ }
303
+ if (device.customOn !== undefined) {
304
+ config['customOn'] = device.customOn;
305
+ }
306
+ if (device.customOff !== undefined) {
307
+ config['customOff'] = device.customOff;
308
+ }
309
+ if (device.customize !== undefined) {
310
+ config['customize'] = device.customize;
311
+ }
312
+ if (device.disablePushOn !== undefined) {
313
+ config['disablePushOn'] = device.disablePushOn;
314
+ }
315
+ if (device.disablePushOff !== undefined) {
316
+ config['disablePushOff'] = device.disablePushOff;
317
+ }
318
+ if (Object.entries(config).length !== 0) {
319
+ this.infoLog(`Lock: ${this.accessory.displayName} Config: ${JSON.stringify(config)}`);
320
+ }
321
+ }
322
+
323
+ async getDeviceContext(accessory: PlatformAccessory, device: irdevice & irDevicesConfig): Promise<void> {
324
+ accessory.context.name = device.deviceName;
325
+ accessory.context.model = device.remoteType;
326
+ accessory.context.deviceId = device.deviceId;
327
+ accessory.context.remoteType = device.remoteType;
328
+ if (device.firmware === undefined) {
329
+ device.firmware = this.platform.version;
330
+ accessory.context.FirmwareRevision = device.firmware;
331
+ } else {
332
+ accessory.context.FirmwareRevision = device.firmware;
333
+ }
334
+ }
335
+
336
+ async disablePushOnChanges(device: irdevice & irDevicesConfig): Promise<void> {
337
+ if (device.disablePushOn === undefined) {
338
+ this.disablePushOn = false;
339
+ } else {
340
+ this.disablePushOn = device.disablePushOn;
341
+ }
342
+ }
343
+
344
+ async disablePushOffChanges(device: irdevice & irDevicesConfig): Promise<void> {
345
+ if (device.disablePushOff === undefined) {
346
+ this.disablePushOff = false;
347
+ } else {
348
+ this.disablePushOff = device.disablePushOff;
349
+ }
350
+ }
351
+
352
+ async disablePushDetailChanges(device: irdevice & irDevicesConfig): Promise<void> {
353
+ if (device.disablePushDetail === undefined) {
354
+ this.disablePushDetail = false;
355
+ } else {
356
+ this.disablePushDetail = device.disablePushDetail;
357
+ }
358
+ }
359
+
360
+ async commandType(): Promise<string> {
361
+ let commandType: string;
362
+ if (this.device.commandType && this.device.customize) {
363
+ commandType = this.device.commandType;
364
+ } else if (this.device.customize) {
365
+ commandType = 'customize';
366
+ } else {
367
+ commandType = 'command';
368
+ }
369
+ return commandType;
370
+ }
371
+
372
+ async commandOn(): Promise<string> {
373
+ let command: string;
374
+ if (this.device.customize && this.device.customOn) {
375
+ command = this.device.customOn;
376
+ } else {
377
+ command = 'turnOn';
378
+ }
379
+ return command;
380
+ }
381
+
382
+ async commandOff(): Promise<string> {
383
+ let command: string;
384
+ if (this.device.customize && this.device.customOff) {
385
+ command = this.device.customOff;
386
+ } else {
387
+ command = 'turnOff';
388
+ }
389
+ return command;
390
+ }
391
+
392
+ async statusCode(statusCode: number): Promise<void> {
393
+ switch (statusCode) {
394
+ case 151:
395
+ this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Command not supported by this deviceType, statusCode: ${statusCode}`);
396
+ break;
397
+ case 152:
398
+ this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Device not found, statusCode: ${statusCode}`);
399
+ break;
400
+ case 160:
401
+ this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Command is not supported, statusCode: ${statusCode}`);
402
+ break;
403
+ case 161:
404
+ this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Device is offline, statusCode: ${statusCode}`);
405
+ break;
406
+ case 171:
407
+ this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Hub Device is offline, statusCode: ${statusCode}. ` +
408
+ `Hub: ${this.device.hubDeviceId}`);
409
+ break;
410
+ case 190:
411
+ this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Device internal error due to device states not synchronized with` +
412
+ ` server, Or command format is invalid, statusCode: ${statusCode}`);
413
+ break;
414
+ case 100:
415
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Command successfully sent, statusCode: ${statusCode}`);
416
+ break;
417
+ case 200:
418
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Request successful, statusCode: ${statusCode}`);
419
+ break;
420
+ case 400:
421
+ this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Bad Request, The client has issued an invalid request. `
422
+ + `This is commonly used to specify validation errors in a request payload, statusCode: ${statusCode}`);
423
+ break;
424
+ case 401:
425
+ this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Unauthorized, Authorization for the API is required, `
426
+ + `but the request has not been authenticated, statusCode: ${statusCode}`);
427
+ break;
428
+ case 403:
429
+ this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Forbidden, The request has been authenticated but does not `
430
+ + `have appropriate permissions, or a requested resource is not found, statusCode: ${statusCode}`);
431
+ break;
432
+ case 404:
433
+ this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Not Found, Specifies the requested path does not exist, `
434
+ + `statusCode: ${statusCode}`);
435
+ break;
436
+ case 406:
437
+ this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Not Acceptable, The client has requested a MIME type via `
438
+ + `the Accept header for a value not supported by the server, statusCode: ${statusCode}`);
439
+ break;
440
+ case 415:
441
+ this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Unsupported Media Type, The client has defined a contentType `
442
+ + `header that is not supported by the server, statusCode: ${statusCode}`);
443
+ break;
444
+ case 422:
445
+ this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Unprocessable Entity, The client has made a valid request, `
446
+ + `but the server cannot process it. This is often used for APIs for which certain limits have been exceeded, statusCode: ${statusCode}`);
447
+ break;
448
+ case 429:
449
+ this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Too Many Requests, The client has exceeded the number of `
450
+ + `requests allowed for a given time window, statusCode: ${statusCode}`);
451
+ break;
452
+ case 500:
453
+ this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Internal Server Error, An unexpected error on the SmartThings `
454
+ + `servers has occurred. These errors should be rare, statusCode: ${statusCode}`);
455
+ break;
456
+ default:
457
+ this.infoLog(`${this.device.remoteType}: ${this.accessory.displayName} Unknown statusCode: `
458
+ + `${statusCode}, Submit Bugs Here: ' + 'https://tinyurl.com/SwitchBotBug`);
459
+ }
460
+ }
461
+
462
+ /**
463
+ * Logging for Device
464
+ */
465
+ infoLog(...log: any[]): void {
466
+ if (this.enablingDeviceLogging()) {
467
+ this.log.info(String(...log));
468
+ }
469
+ }
470
+
471
+ successLog(...log: any[]): void {
472
+ if (this.enablingDeviceLogging()) {
473
+ this.platform.log.success(String(...log));
474
+ }
475
+ }
476
+
477
+ debugSuccessLog(...log: any[]): void {
478
+ if (this.enablingDeviceLogging()) {
479
+ if (this.deviceLogging?.includes('debug')) {
480
+ this.log.success('[DEBUG]', String(...log));
481
+ }
482
+ }
483
+ }
484
+
485
+ warnLog(...log: any[]): void {
486
+ if (this.enablingDeviceLogging()) {
487
+ this.log.warn(String(...log));
488
+ }
489
+ }
490
+
491
+ debugWarnLog(...log: any[]): void {
492
+ if (this.enablingDeviceLogging()) {
493
+ if (this.deviceLogging?.includes('debug')) {
494
+ this.log.warn('[DEBUG]', String(...log));
495
+ }
496
+ }
497
+ }
498
+
499
+ errorLog(...log: any[]): void {
500
+ if (this.enablingDeviceLogging()) {
501
+ this.log.error(String(...log));
502
+ }
503
+ }
504
+
505
+ debugErrorLog(...log: any[]): void {
506
+ if (this.enablingDeviceLogging()) {
507
+ if (this.deviceLogging?.includes('debug')) {
508
+ this.log.error('[DEBUG]', String(...log));
509
+ }
510
+ }
511
+ }
512
+
513
+ debugLog(...log: any[]): void {
514
+ if (this.enablingDeviceLogging()) {
515
+ if (this.deviceLogging === 'debug') {
516
+ this.log.info('[DEBUG]', String(...log));
517
+ } else {
518
+ this.log.debug(String(...log));
519
+ }
520
+ }
521
+ }
522
+
523
+ enablingDeviceLogging(): boolean {
524
+ return this.deviceLogging.includes('debug') || this.deviceLogging === 'standard';
525
+ }
526
+ }