@switchbot/homebridge-switchbot 3.5.0-beta.5 → 3.5.0-beta.51

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 (169) hide show
  1. package/CHANGELOG.md +2 -0
  2. package/config.schema.json +120 -17
  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 +352 -757
  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 +588 -761
  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 +214 -588
  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 +256 -634
  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 +209 -532
  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 +340 -787
  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 +682 -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 +505 -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 +247 -597
  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 +218 -579
  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 +179 -585
  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 +257 -569
  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 +215 -543
  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 +175 -578
  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 +164 -578
  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 +142 -520
  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 +87 -453
  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 +145 -452
  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 +126 -665
  78. package/dist/device/waterdetector.js.map +1 -1
  79. package/dist/homebridge-ui/public/index.html +2 -2
  80. package/dist/index.js +1 -1
  81. package/dist/irdevice/airconditioner.d.ts +8 -48
  82. package/dist/irdevice/airconditioner.d.ts.map +1 -1
  83. package/dist/irdevice/airconditioner.js +309 -419
  84. package/dist/irdevice/airconditioner.js.map +1 -1
  85. package/dist/irdevice/airpurifier.d.ts +7 -38
  86. package/dist/irdevice/airpurifier.d.ts.map +1 -1
  87. package/dist/irdevice/airpurifier.js +72 -304
  88. package/dist/irdevice/airpurifier.js.map +1 -1
  89. package/dist/irdevice/camera.d.ts +6 -35
  90. package/dist/irdevice/camera.d.ts.map +1 -1
  91. package/dist/irdevice/camera.js +34 -278
  92. package/dist/irdevice/camera.js.map +1 -1
  93. package/dist/irdevice/fan.d.ts +6 -39
  94. package/dist/irdevice/fan.d.ts.map +1 -1
  95. package/dist/irdevice/fan.js +67 -311
  96. package/dist/irdevice/fan.js.map +1 -1
  97. package/dist/irdevice/irdevice.d.ts +40 -0
  98. package/dist/irdevice/irdevice.d.ts.map +1 -0
  99. package/dist/irdevice/irdevice.js +512 -0
  100. package/dist/irdevice/irdevice.js.map +1 -0
  101. package/dist/irdevice/light.d.ts +6 -34
  102. package/dist/irdevice/light.d.ts.map +1 -1
  103. package/dist/irdevice/light.js +23 -272
  104. package/dist/irdevice/light.js.map +1 -1
  105. package/dist/irdevice/other.d.ts +18 -47
  106. package/dist/irdevice/other.d.ts.map +1 -1
  107. package/dist/irdevice/other.js +352 -546
  108. package/dist/irdevice/other.js.map +1 -1
  109. package/dist/irdevice/tv.d.ts +7 -39
  110. package/dist/irdevice/tv.d.ts.map +1 -1
  111. package/dist/irdevice/tv.js +82 -321
  112. package/dist/irdevice/tv.js.map +1 -1
  113. package/dist/irdevice/vacuumcleaner.d.ts +6 -35
  114. package/dist/irdevice/vacuumcleaner.d.ts.map +1 -1
  115. package/dist/irdevice/vacuumcleaner.js +41 -284
  116. package/dist/irdevice/vacuumcleaner.js.map +1 -1
  117. package/dist/irdevice/waterheater.d.ts +6 -35
  118. package/dist/irdevice/waterheater.d.ts.map +1 -1
  119. package/dist/irdevice/waterheater.js +42 -287
  120. package/dist/irdevice/waterheater.js.map +1 -1
  121. package/dist/platform.d.ts +14 -1
  122. package/dist/platform.d.ts.map +1 -1
  123. package/dist/platform.js +291 -147
  124. package/dist/platform.js.map +1 -1
  125. package/dist/settings.d.ts +41 -11
  126. package/dist/settings.d.ts.map +1 -1
  127. package/dist/settings.js +0 -552
  128. package/dist/settings.js.map +1 -1
  129. package/dist/utils.d.ts +77 -0
  130. package/dist/utils.d.ts.map +1 -1
  131. package/dist/utils.js +638 -1
  132. package/dist/utils.js.map +1 -1
  133. package/eslint.config.js +87 -0
  134. package/package.json +16 -15
  135. package/src/custom.d.ts +2 -1
  136. package/src/device/blindtilt.ts +378 -783
  137. package/src/device/bot.ts +621 -845
  138. package/src/device/ceilinglight.ts +227 -608
  139. package/src/device/colorbulb.ts +269 -657
  140. package/src/device/contact.ts +235 -555
  141. package/src/device/curtain.ts +360 -811
  142. package/src/device/device.ts +710 -0
  143. package/src/device/fan.ts +554 -0
  144. package/src/device/hub.ts +274 -625
  145. package/src/device/humidifier.ts +246 -624
  146. package/src/device/iosensor.ts +205 -611
  147. package/src/device/lightstrip.ts +278 -597
  148. package/src/device/lock.ts +252 -583
  149. package/src/device/meter.ts +200 -601
  150. package/src/device/meterplus.ts +189 -603
  151. package/src/device/motion.ts +161 -542
  152. package/src/device/plug.ts +97 -481
  153. package/src/device/robotvacuumcleaner.ts +166 -478
  154. package/src/device/waterdetector.ts +143 -689
  155. package/src/homebridge-ui/public/index.html +2 -2
  156. package/src/index.ts +1 -1
  157. package/src/irdevice/airconditioner.ts +330 -446
  158. package/src/irdevice/airpurifier.ts +89 -321
  159. package/src/irdevice/camera.ts +42 -293
  160. package/src/irdevice/fan.ts +78 -327
  161. package/src/irdevice/irdevice.ts +528 -0
  162. package/src/irdevice/light.ts +32 -287
  163. package/src/irdevice/other.ts +396 -615
  164. package/src/irdevice/tv.ts +100 -339
  165. package/src/irdevice/vacuumcleaner.ts +49 -305
  166. package/src/irdevice/waterheater.ts +50 -310
  167. package/src/platform.ts +301 -155
  168. package/src/settings.ts +57 -566
  169. package/src/utils.ts +642 -1
@@ -0,0 +1,528 @@
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.firmware)
47
+ .getCharacteristic(this.hap.Characteristic.FirmwareRevision)
48
+ .updateValue(accessory.context.firmware);
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) {
329
+ accessory.context.firmware = device.firmware;
330
+ } else if (device.firmware === undefined || accessory.context.firmware === undefined) {
331
+ device.firmware = this.platform.version;
332
+ accessory.context.firmware = device.firmware;
333
+ } else {
334
+ accessory.context.firmware = 'Unknown';
335
+ }
336
+ }
337
+
338
+ async disablePushOnChanges(device: irdevice & irDevicesConfig): Promise<void> {
339
+ if (device.disablePushOn === undefined) {
340
+ this.disablePushOn = false;
341
+ } else {
342
+ this.disablePushOn = device.disablePushOn;
343
+ }
344
+ }
345
+
346
+ async disablePushOffChanges(device: irdevice & irDevicesConfig): Promise<void> {
347
+ if (device.disablePushOff === undefined) {
348
+ this.disablePushOff = false;
349
+ } else {
350
+ this.disablePushOff = device.disablePushOff;
351
+ }
352
+ }
353
+
354
+ async disablePushDetailChanges(device: irdevice & irDevicesConfig): Promise<void> {
355
+ if (device.disablePushDetail === undefined) {
356
+ this.disablePushDetail = false;
357
+ } else {
358
+ this.disablePushDetail = device.disablePushDetail;
359
+ }
360
+ }
361
+
362
+ async commandType(): Promise<string> {
363
+ let commandType: string;
364
+ if (this.device.commandType && this.device.customize) {
365
+ commandType = this.device.commandType;
366
+ } else if (this.device.customize) {
367
+ commandType = 'customize';
368
+ } else {
369
+ commandType = 'command';
370
+ }
371
+ return commandType;
372
+ }
373
+
374
+ async commandOn(): Promise<string> {
375
+ let command: string;
376
+ if (this.device.customize && this.device.customOn) {
377
+ command = this.device.customOn;
378
+ } else {
379
+ command = 'turnOn';
380
+ }
381
+ return command;
382
+ }
383
+
384
+ async commandOff(): Promise<string> {
385
+ let command: string;
386
+ if (this.device.customize && this.device.customOff) {
387
+ command = this.device.customOff;
388
+ } else {
389
+ command = 'turnOff';
390
+ }
391
+ return command;
392
+ }
393
+
394
+ async statusCode(statusCode: number): Promise<void> {
395
+ switch (statusCode) {
396
+ case 151:
397
+ this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Command not supported by this deviceType, statusCode: ${statusCode}`);
398
+ break;
399
+ case 152:
400
+ this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Device not found, statusCode: ${statusCode}`);
401
+ break;
402
+ case 160:
403
+ this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Command is not supported, statusCode: ${statusCode}`);
404
+ break;
405
+ case 161:
406
+ this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Device is offline, statusCode: ${statusCode}`);
407
+ break;
408
+ case 171:
409
+ this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Hub Device is offline, statusCode: ${statusCode}. ` +
410
+ `Hub: ${this.device.hubDeviceId}`);
411
+ break;
412
+ case 190:
413
+ this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Device internal error due to device states not synchronized with` +
414
+ ` server, Or command format is invalid, statusCode: ${statusCode}`);
415
+ break;
416
+ case 100:
417
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Command successfully sent, statusCode: ${statusCode}`);
418
+ break;
419
+ case 200:
420
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Request successful, statusCode: ${statusCode}`);
421
+ break;
422
+ case 400:
423
+ this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Bad Request, The client has issued an invalid request. `
424
+ + `This is commonly used to specify validation errors in a request payload, statusCode: ${statusCode}`);
425
+ break;
426
+ case 401:
427
+ this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Unauthorized, Authorization for the API is required, `
428
+ + `but the request has not been authenticated, statusCode: ${statusCode}`);
429
+ break;
430
+ case 403:
431
+ this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Forbidden, The request has been authenticated but does not `
432
+ + `have appropriate permissions, or a requested resource is not found, statusCode: ${statusCode}`);
433
+ break;
434
+ case 404:
435
+ this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Not Found, Specifies the requested path does not exist, `
436
+ + `statusCode: ${statusCode}`);
437
+ break;
438
+ case 406:
439
+ this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Not Acceptable, The client has requested a MIME type via `
440
+ + `the Accept header for a value not supported by the server, statusCode: ${statusCode}`);
441
+ break;
442
+ case 415:
443
+ this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Unsupported Media Type, The client has defined a contentType `
444
+ + `header that is not supported by the server, statusCode: ${statusCode}`);
445
+ break;
446
+ case 422:
447
+ this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Unprocessable Entity, The client has made a valid request, `
448
+ + `but the server cannot process it. This is often used for APIs for which certain limits have been exceeded, statusCode: ${statusCode}`);
449
+ break;
450
+ case 429:
451
+ this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Too Many Requests, The client has exceeded the number of `
452
+ + `requests allowed for a given time window, statusCode: ${statusCode}`);
453
+ break;
454
+ case 500:
455
+ this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Internal Server Error, An unexpected error on the SmartThings `
456
+ + `servers has occurred. These errors should be rare, statusCode: ${statusCode}`);
457
+ break;
458
+ default:
459
+ this.infoLog(`${this.device.remoteType}: ${this.accessory.displayName} Unknown statusCode: `
460
+ + `${statusCode}, Submit Bugs Here: ' + 'https://tinyurl.com/SwitchBotBug`);
461
+ }
462
+ }
463
+
464
+ /**
465
+ * Logging for Device
466
+ */
467
+ infoLog(...log: any[]): void {
468
+ if (this.enablingDeviceLogging()) {
469
+ this.log.info(String(...log));
470
+ }
471
+ }
472
+
473
+ successLog(...log: any[]): void {
474
+ if (this.enablingDeviceLogging()) {
475
+ this.platform.log.success(String(...log));
476
+ }
477
+ }
478
+
479
+ debugSuccessLog(...log: any[]): void {
480
+ if (this.enablingDeviceLogging()) {
481
+ if (this.deviceLogging?.includes('debug')) {
482
+ this.log.success('[DEBUG]', String(...log));
483
+ }
484
+ }
485
+ }
486
+
487
+ warnLog(...log: any[]): void {
488
+ if (this.enablingDeviceLogging()) {
489
+ this.log.warn(String(...log));
490
+ }
491
+ }
492
+
493
+ debugWarnLog(...log: any[]): void {
494
+ if (this.enablingDeviceLogging()) {
495
+ if (this.deviceLogging?.includes('debug')) {
496
+ this.log.warn('[DEBUG]', String(...log));
497
+ }
498
+ }
499
+ }
500
+
501
+ errorLog(...log: any[]): void {
502
+ if (this.enablingDeviceLogging()) {
503
+ this.log.error(String(...log));
504
+ }
505
+ }
506
+
507
+ debugErrorLog(...log: any[]): void {
508
+ if (this.enablingDeviceLogging()) {
509
+ if (this.deviceLogging?.includes('debug')) {
510
+ this.log.error('[DEBUG]', String(...log));
511
+ }
512
+ }
513
+ }
514
+
515
+ debugLog(...log: any[]): void {
516
+ if (this.enablingDeviceLogging()) {
517
+ if (this.deviceLogging === 'debug') {
518
+ this.log.info('[DEBUG]', String(...log));
519
+ } else {
520
+ this.log.debug(String(...log));
521
+ }
522
+ }
523
+ }
524
+
525
+ enablingDeviceLogging(): boolean {
526
+ return this.deviceLogging.includes('debug') || this.deviceLogging === 'standard';
527
+ }
528
+ }