@switchbot/homebridge-switchbot 3.5.0-beta.22 → 3.5.0-beta.24

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 (150) hide show
  1. package/config.schema.json +23 -2
  2. package/dist/device/blindtilt.d.ts +21 -98
  3. package/dist/device/blindtilt.d.ts.map +1 -1
  4. package/dist/device/blindtilt.js +332 -785
  5. package/dist/device/blindtilt.js.map +1 -1
  6. package/dist/device/bot.d.ts +25 -75
  7. package/dist/device/bot.d.ts.map +1 -1
  8. package/dist/device/bot.js +566 -778
  9. package/dist/device/bot.js.map +1 -1
  10. package/dist/device/ceilinglight.d.ts +13 -71
  11. package/dist/device/ceilinglight.d.ts.map +1 -1
  12. package/dist/device/ceilinglight.js +168 -606
  13. package/dist/device/ceilinglight.js.map +1 -1
  14. package/dist/device/colorbulb.d.ts +13 -78
  15. package/dist/device/colorbulb.d.ts.map +1 -1
  16. package/dist/device/colorbulb.js +218 -655
  17. package/dist/device/colorbulb.js.map +1 -1
  18. package/dist/device/contact.d.ts +14 -69
  19. package/dist/device/contact.d.ts.map +1 -1
  20. package/dist/device/contact.js +196 -553
  21. package/dist/device/contact.js.map +1 -1
  22. package/dist/device/curtain.d.ts +17 -90
  23. package/dist/device/curtain.d.ts.map +1 -1
  24. package/dist/device/curtain.js +324 -810
  25. package/dist/device/curtain.js.map +1 -1
  26. package/dist/device/device.d.ts +58 -0
  27. package/dist/device/device.d.ts.map +1 -0
  28. package/dist/device/device.js +629 -0
  29. package/dist/device/device.js.map +1 -0
  30. package/dist/device/hub.d.ts +15 -63
  31. package/dist/device/hub.d.ts.map +1 -1
  32. package/dist/device/hub.js +223 -610
  33. package/dist/device/hub.js.map +1 -1
  34. package/dist/device/humidifier.d.ts +10 -69
  35. package/dist/device/humidifier.d.ts.map +1 -1
  36. package/dist/device/humidifier.js +192 -595
  37. package/dist/device/humidifier.js.map +1 -1
  38. package/dist/device/iosensor.d.ts +11 -68
  39. package/dist/device/iosensor.d.ts.map +1 -1
  40. package/dist/device/iosensor.js +156 -599
  41. package/dist/device/iosensor.js.map +1 -1
  42. package/dist/device/lightstrip.d.ts +10 -72
  43. package/dist/device/lightstrip.d.ts.map +1 -1
  44. package/dist/device/lightstrip.js +204 -591
  45. package/dist/device/lightstrip.js.map +1 -1
  46. package/dist/device/lock.d.ts +15 -66
  47. package/dist/device/lock.d.ts.map +1 -1
  48. package/dist/device/lock.js +199 -566
  49. package/dist/device/lock.js.map +1 -1
  50. package/dist/device/meter.d.ts +13 -67
  51. package/dist/device/meter.d.ts.map +1 -1
  52. package/dist/device/meter.js +152 -592
  53. package/dist/device/meter.js.map +1 -1
  54. package/dist/device/meterplus.d.ts +13 -68
  55. package/dist/device/meterplus.d.ts.map +1 -1
  56. package/dist/device/meterplus.js +151 -599
  57. package/dist/device/meterplus.js.map +1 -1
  58. package/dist/device/motion.d.ts +13 -73
  59. package/dist/device/motion.d.ts.map +1 -1
  60. package/dist/device/motion.js +129 -540
  61. package/dist/device/motion.js.map +1 -1
  62. package/dist/device/plug.d.ts +9 -61
  63. package/dist/device/plug.d.ts.map +1 -1
  64. package/dist/device/plug.js +71 -476
  65. package/dist/device/plug.js.map +1 -1
  66. package/dist/device/robotvacuumcleaner.d.ts +11 -66
  67. package/dist/device/robotvacuumcleaner.d.ts.map +1 -1
  68. package/dist/device/robotvacuumcleaner.js +122 -471
  69. package/dist/device/robotvacuumcleaner.js.map +1 -1
  70. package/dist/device/waterdetector.d.ts +9 -66
  71. package/dist/device/waterdetector.d.ts.map +1 -1
  72. package/dist/device/waterdetector.js +105 -478
  73. package/dist/device/waterdetector.js.map +1 -1
  74. package/dist/irdevice/airconditioner.d.ts +5 -36
  75. package/dist/irdevice/airconditioner.d.ts.map +1 -1
  76. package/dist/irdevice/airconditioner.js +228 -337
  77. package/dist/irdevice/airconditioner.js.map +1 -1
  78. package/dist/irdevice/airpurifier.d.ts +5 -34
  79. package/dist/irdevice/airpurifier.d.ts.map +1 -1
  80. package/dist/irdevice/airpurifier.js +19 -267
  81. package/dist/irdevice/airpurifier.js.map +1 -1
  82. package/dist/irdevice/camera.d.ts +5 -34
  83. package/dist/irdevice/camera.d.ts.map +1 -1
  84. package/dist/irdevice/camera.js +13 -261
  85. package/dist/irdevice/camera.js.map +1 -1
  86. package/dist/irdevice/fan.d.ts +5 -34
  87. package/dist/irdevice/fan.d.ts.map +1 -1
  88. package/dist/irdevice/fan.js +13 -260
  89. package/dist/irdevice/fan.js.map +1 -1
  90. package/dist/irdevice/irdevice.d.ts +39 -0
  91. package/dist/irdevice/irdevice.d.ts.map +1 -0
  92. package/dist/irdevice/irdevice.js +502 -0
  93. package/dist/irdevice/irdevice.js.map +1 -0
  94. package/dist/irdevice/light.d.ts +5 -34
  95. package/dist/irdevice/light.d.ts.map +1 -1
  96. package/dist/irdevice/light.js +13 -267
  97. package/dist/irdevice/light.js.map +1 -1
  98. package/dist/irdevice/other.d.ts +18 -48
  99. package/dist/irdevice/other.d.ts.map +1 -1
  100. package/dist/irdevice/other.js +349 -551
  101. package/dist/irdevice/other.js.map +1 -1
  102. package/dist/irdevice/tv.d.ts +7 -40
  103. package/dist/irdevice/tv.d.ts.map +1 -1
  104. package/dist/irdevice/tv.js +79 -325
  105. package/dist/irdevice/tv.js.map +1 -1
  106. package/dist/irdevice/vacuumcleaner.d.ts +6 -36
  107. package/dist/irdevice/vacuumcleaner.d.ts.map +1 -1
  108. package/dist/irdevice/vacuumcleaner.js +38 -288
  109. package/dist/irdevice/vacuumcleaner.js.map +1 -1
  110. package/dist/irdevice/waterheater.d.ts +6 -36
  111. package/dist/irdevice/waterheater.d.ts.map +1 -1
  112. package/dist/irdevice/waterheater.js +39 -291
  113. package/dist/irdevice/waterheater.js.map +1 -1
  114. package/dist/settings.d.ts +15 -2
  115. package/dist/settings.d.ts.map +1 -1
  116. package/dist/utils.d.ts +68 -0
  117. package/dist/utils.d.ts.map +1 -1
  118. package/dist/utils.js +71 -0
  119. package/dist/utils.js.map +1 -1
  120. package/package.json +8 -8
  121. package/src/device/blindtilt.ts +356 -809
  122. package/src/device/bot.ts +601 -865
  123. package/src/device/ceilinglight.ts +182 -628
  124. package/src/device/colorbulb.ts +235 -683
  125. package/src/device/contact.ts +220 -575
  126. package/src/device/curtain.ts +344 -836
  127. package/src/device/device.ts +655 -0
  128. package/src/device/hub.ts +246 -636
  129. package/src/device/humidifier.ts +224 -645
  130. package/src/device/iosensor.ts +181 -625
  131. package/src/device/lightstrip.ts +230 -622
  132. package/src/device/lock.ts +236 -607
  133. package/src/device/meter.ts +177 -616
  134. package/src/device/meterplus.ts +175 -624
  135. package/src/device/motion.ts +147 -563
  136. package/src/device/plug.ts +81 -505
  137. package/src/device/robotvacuumcleaner.ts +139 -494
  138. package/src/device/waterdetector.ts +126 -506
  139. package/src/irdevice/airconditioner.ts +228 -353
  140. package/src/irdevice/airpurifier.ts +23 -282
  141. package/src/irdevice/camera.ts +18 -277
  142. package/src/irdevice/fan.ts +18 -275
  143. package/src/irdevice/irdevice.ts +518 -0
  144. package/src/irdevice/light.ts +18 -283
  145. package/src/irdevice/other.ts +394 -621
  146. package/src/irdevice/tv.ts +97 -344
  147. package/src/irdevice/vacuumcleaner.ts +46 -310
  148. package/src/irdevice/waterheater.ts +47 -315
  149. package/src/settings.ts +20 -3
  150. package/src/utils.ts +71 -0
@@ -0,0 +1,518 @@
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.model;
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
+ successLog(...log: any[]): void {
466
+ if (this.enablingDeviceLogging()) {
467
+ this.platform.log.success(String(...log));
468
+ }
469
+ }
470
+
471
+ infoLog(...log: any[]): void {
472
+ if (this.enablingDeviceLogging()) {
473
+ this.log.info(String(...log));
474
+ }
475
+ }
476
+
477
+ warnLog(...log: any[]): void {
478
+ if (this.enablingDeviceLogging()) {
479
+ this.log.warn(String(...log));
480
+ }
481
+ }
482
+
483
+ debugWarnLog(...log: any[]): void {
484
+ if (this.enablingDeviceLogging()) {
485
+ if (this.deviceLogging?.includes('debug')) {
486
+ this.log.warn('[DEBUG]', String(...log));
487
+ }
488
+ }
489
+ }
490
+
491
+ errorLog(...log: any[]): void {
492
+ if (this.enablingDeviceLogging()) {
493
+ this.log.error(String(...log));
494
+ }
495
+ }
496
+
497
+ debugErrorLog(...log: any[]): void {
498
+ if (this.enablingDeviceLogging()) {
499
+ if (this.deviceLogging?.includes('debug')) {
500
+ this.log.error('[DEBUG]', String(...log));
501
+ }
502
+ }
503
+ }
504
+
505
+ debugLog(...log: any[]): void {
506
+ if (this.enablingDeviceLogging()) {
507
+ if (this.deviceLogging === 'debug') {
508
+ this.log.info('[DEBUG]', String(...log));
509
+ } else {
510
+ this.log.debug(String(...log));
511
+ }
512
+ }
513
+ }
514
+
515
+ enablingDeviceLogging(): boolean {
516
+ return this.deviceLogging.includes('debug') || this.deviceLogging === 'standard';
517
+ }
518
+ }