@switchbot/homebridge-switchbot 3.5.0-beta.9 → 3.5.1-beta.0

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 (177) hide show
  1. package/.vscode/settings.json +4 -1
  2. package/CHANGELOG.md +4 -1
  3. package/config.schema.json +164 -22
  4. package/dist/device/blindtilt.d.ts +21 -96
  5. package/dist/device/blindtilt.d.ts.map +1 -1
  6. package/dist/device/blindtilt.js +457 -866
  7. package/dist/device/blindtilt.js.map +1 -1
  8. package/dist/device/bot.d.ts +27 -72
  9. package/dist/device/bot.d.ts.map +1 -1
  10. package/dist/device/bot.js +851 -913
  11. package/dist/device/bot.js.map +1 -1
  12. package/dist/device/ceilinglight.d.ts +15 -69
  13. package/dist/device/ceilinglight.d.ts.map +1 -1
  14. package/dist/device/ceilinglight.js +316 -742
  15. package/dist/device/ceilinglight.js.map +1 -1
  16. package/dist/device/colorbulb.d.ts +15 -76
  17. package/dist/device/colorbulb.d.ts.map +1 -1
  18. package/dist/device/colorbulb.js +380 -833
  19. package/dist/device/colorbulb.js.map +1 -1
  20. package/dist/device/contact.d.ts +14 -66
  21. package/dist/device/contact.d.ts.map +1 -1
  22. package/dist/device/contact.js +267 -602
  23. package/dist/device/contact.js.map +1 -1
  24. package/dist/device/curtain.d.ts +18 -89
  25. package/dist/device/curtain.d.ts.map +1 -1
  26. package/dist/device/curtain.js +469 -897
  27. package/dist/device/curtain.js.map +1 -1
  28. package/dist/device/device.d.ts +76 -0
  29. package/dist/device/device.d.ts.map +1 -0
  30. package/dist/device/device.js +846 -0
  31. package/dist/device/device.js.map +1 -0
  32. package/dist/device/fan.d.ts +63 -0
  33. package/dist/device/fan.d.ts.map +1 -0
  34. package/dist/device/fan.js +645 -0
  35. package/dist/device/fan.js.map +1 -0
  36. package/dist/device/hub.d.ts +19 -58
  37. package/dist/device/hub.d.ts.map +1 -1
  38. package/dist/device/hub.js +304 -640
  39. package/dist/device/hub.js.map +1 -1
  40. package/dist/device/humidifier.d.ts +11 -66
  41. package/dist/device/humidifier.d.ts.map +1 -1
  42. package/dist/device/humidifier.js +300 -710
  43. package/dist/device/humidifier.js.map +1 -1
  44. package/dist/device/iosensor.d.ts +12 -64
  45. package/dist/device/iosensor.d.ts.map +1 -1
  46. package/dist/device/iosensor.js +225 -643
  47. package/dist/device/iosensor.js.map +1 -1
  48. package/dist/device/lightstrip.d.ts +12 -70
  49. package/dist/device/lightstrip.d.ts.map +1 -1
  50. package/dist/device/lightstrip.js +371 -742
  51. package/dist/device/lightstrip.js.map +1 -1
  52. package/dist/device/lock.d.ts +17 -63
  53. package/dist/device/lock.d.ts.map +1 -1
  54. package/dist/device/lock.js +309 -642
  55. package/dist/device/lock.js.map +1 -1
  56. package/dist/device/meter.d.ts +15 -64
  57. package/dist/device/meter.d.ts.map +1 -1
  58. package/dist/device/meter.js +223 -638
  59. package/dist/device/meter.js.map +1 -1
  60. package/dist/device/meterplus.d.ts +15 -65
  61. package/dist/device/meterplus.d.ts.map +1 -1
  62. package/dist/device/meterplus.js +216 -644
  63. package/dist/device/meterplus.js.map +1 -1
  64. package/dist/device/motion.d.ts +12 -69
  65. package/dist/device/motion.d.ts.map +1 -1
  66. package/dist/device/motion.js +209 -588
  67. package/dist/device/motion.js.map +1 -1
  68. package/dist/device/plug.d.ts +10 -57
  69. package/dist/device/plug.d.ts.map +1 -1
  70. package/dist/device/plug.js +141 -532
  71. package/dist/device/plug.js.map +1 -1
  72. package/dist/device/robotvacuumcleaner.d.ts +13 -63
  73. package/dist/device/robotvacuumcleaner.d.ts.map +1 -1
  74. package/dist/device/robotvacuumcleaner.js +252 -609
  75. package/dist/device/robotvacuumcleaner.js.map +1 -1
  76. package/dist/device/waterdetector.d.ts +11 -63
  77. package/dist/device/waterdetector.d.ts.map +1 -1
  78. package/dist/device/waterdetector.js +179 -521
  79. package/dist/device/waterdetector.js.map +1 -1
  80. package/dist/homebridge-ui/public/index.html +22 -16
  81. package/dist/homebridge-ui/server.js +1 -1
  82. package/dist/homebridge-ui/server.js.map +1 -1
  83. package/dist/index.d.ts +1 -1
  84. package/dist/index.d.ts.map +1 -1
  85. package/dist/index.js +2 -2
  86. package/dist/index.js.map +1 -1
  87. package/dist/irdevice/airconditioner.d.ts +10 -50
  88. package/dist/irdevice/airconditioner.d.ts.map +1 -1
  89. package/dist/irdevice/airconditioner.js +337 -482
  90. package/dist/irdevice/airconditioner.js.map +1 -1
  91. package/dist/irdevice/airpurifier.d.ts +8 -39
  92. package/dist/irdevice/airpurifier.d.ts.map +1 -1
  93. package/dist/irdevice/airpurifier.js +108 -333
  94. package/dist/irdevice/airpurifier.js.map +1 -1
  95. package/dist/irdevice/camera.d.ts +7 -36
  96. package/dist/irdevice/camera.d.ts.map +1 -1
  97. package/dist/irdevice/camera.js +47 -299
  98. package/dist/irdevice/camera.js.map +1 -1
  99. package/dist/irdevice/fan.d.ts +7 -43
  100. package/dist/irdevice/fan.d.ts.map +1 -1
  101. package/dist/irdevice/fan.js +95 -364
  102. package/dist/irdevice/fan.js.map +1 -1
  103. package/dist/irdevice/irdevice.d.ts +46 -0
  104. package/dist/irdevice/irdevice.d.ts.map +1 -0
  105. package/dist/irdevice/irdevice.js +393 -0
  106. package/dist/irdevice/irdevice.js.map +1 -0
  107. package/dist/irdevice/light.d.ts +12 -45
  108. package/dist/irdevice/light.d.ts.map +1 -1
  109. package/dist/irdevice/light.js +121 -376
  110. package/dist/irdevice/light.js.map +1 -1
  111. package/dist/irdevice/other.d.ts +19 -48
  112. package/dist/irdevice/other.d.ts.map +1 -1
  113. package/dist/irdevice/other.js +441 -584
  114. package/dist/irdevice/other.js.map +1 -1
  115. package/dist/irdevice/tv.d.ts +8 -40
  116. package/dist/irdevice/tv.d.ts.map +1 -1
  117. package/dist/irdevice/tv.js +94 -353
  118. package/dist/irdevice/tv.js.map +1 -1
  119. package/dist/irdevice/vacuumcleaner.d.ts +7 -36
  120. package/dist/irdevice/vacuumcleaner.d.ts.map +1 -1
  121. package/dist/irdevice/vacuumcleaner.js +48 -299
  122. package/dist/irdevice/vacuumcleaner.js.map +1 -1
  123. package/dist/irdevice/waterheater.d.ts +7 -36
  124. package/dist/irdevice/waterheater.d.ts.map +1 -1
  125. package/dist/irdevice/waterheater.js +50 -305
  126. package/dist/irdevice/waterheater.js.map +1 -1
  127. package/dist/platform.d.ts +22 -8
  128. package/dist/platform.d.ts.map +1 -1
  129. package/dist/platform.js +342 -191
  130. package/dist/platform.js.map +1 -1
  131. package/dist/settings.d.ts +66 -18
  132. package/dist/settings.d.ts.map +1 -1
  133. package/dist/settings.js +16 -552
  134. package/dist/settings.js.map +1 -1
  135. package/dist/utils.d.ts +95 -0
  136. package/dist/utils.d.ts.map +1 -1
  137. package/dist/utils.js +657 -1
  138. package/dist/utils.js.map +1 -1
  139. package/eslint.config.js +96 -0
  140. package/package.json +20 -16
  141. package/src/custom.d.ts +2 -1
  142. package/src/device/blindtilt.ts +488 -937
  143. package/src/device/bot.ts +907 -1016
  144. package/src/device/ceilinglight.ts +330 -798
  145. package/src/device/colorbulb.ts +394 -904
  146. package/src/device/contact.ts +298 -637
  147. package/src/device/curtain.ts +496 -954
  148. package/src/device/device.ts +872 -0
  149. package/src/device/fan.ts +692 -0
  150. package/src/device/hub.ts +338 -671
  151. package/src/device/humidifier.ts +330 -777
  152. package/src/device/iosensor.ts +258 -671
  153. package/src/device/lightstrip.ts +394 -809
  154. package/src/device/lock.ts +345 -700
  155. package/src/device/meter.ts +256 -666
  156. package/src/device/meterplus.ts +248 -672
  157. package/src/device/motion.ts +234 -622
  158. package/src/device/plug.ts +152 -572
  159. package/src/device/robotvacuumcleaner.ts +273 -653
  160. package/src/device/waterdetector.ts +198 -549
  161. package/src/homebridge-ui/public/index.html +22 -16
  162. package/src/homebridge-ui/server.ts +1 -1
  163. package/src/index.ts +4 -3
  164. package/src/irdevice/airconditioner.ts +368 -540
  165. package/src/irdevice/airpurifier.ts +134 -369
  166. package/src/irdevice/camera.ts +60 -324
  167. package/src/irdevice/fan.ts +111 -392
  168. package/src/irdevice/irdevice.ts +406 -0
  169. package/src/irdevice/light.ts +159 -425
  170. package/src/irdevice/other.ts +509 -661
  171. package/src/irdevice/tv.ts +123 -388
  172. package/src/irdevice/vacuumcleaner.ts +61 -324
  173. package/src/irdevice/waterheater.ts +63 -333
  174. package/src/platform.ts +395 -259
  175. package/src/settings.ts +120 -610
  176. package/src/utils.ts +661 -1
  177. package/src/device/waterdetector.json +0 -11
@@ -0,0 +1,406 @@
1
+ /* Copyright(C) 2021-2024, donavanbecker (https://github.com/donavanbecker). All rights reserved.
2
+ *
3
+ * device.ts: @switchbot/homebridge-switchbot.
4
+ */
5
+ import { request } from 'undici';
6
+ import { Devices } from '../settings.js';
7
+
8
+ import type { SwitchBotPlatform } from '../platform.js';
9
+ import type { API, HAP, Logging, PlatformAccessory } from 'homebridge';
10
+ import type { SwitchBotPlatformConfig, irDevicesConfig, irdevice } from '../settings.js';
11
+
12
+ export abstract class irdeviceBase {
13
+ public readonly api: API;
14
+ public readonly log: Logging;
15
+ public readonly config!: SwitchBotPlatformConfig;
16
+ protected readonly hap: HAP;
17
+
18
+ // Config
19
+ protected deviceLogging!: string;
20
+ protected disablePushOn!: boolean;
21
+ protected disablePushOff!: boolean;
22
+ protected disablePushDetail?: boolean;
23
+
24
+ constructor(
25
+ protected readonly platform: SwitchBotPlatform,
26
+ protected accessory: PlatformAccessory,
27
+ protected device: irdevice & irDevicesConfig,
28
+ ) {
29
+ this.api = this.platform.api;
30
+ this.log = this.platform.log;
31
+ this.config = this.platform.config;
32
+ this.hap = this.api.hap;
33
+
34
+ this.getDeviceLogSettings(device);
35
+ this.getDeviceConfigSettings(device);
36
+ this.getDeviceContext(accessory, device);
37
+ this.disablePushOnChanges(device);
38
+ this.disablePushOffChanges(device);
39
+
40
+ // Set accessory information
41
+ accessory
42
+ .getService(this.hap.Service.AccessoryInformation)!
43
+ .setCharacteristic(this.hap.Characteristic.Manufacturer, 'SwitchBot')
44
+ .setCharacteristic(this.hap.Characteristic.AppMatchingIdentifier, 'id1087374760')
45
+ .setCharacteristic(this.hap.Characteristic.Name, accessory.context.name ?? accessory.displayName)
46
+ .setCharacteristic(this.hap.Characteristic.ConfiguredName, accessory.context.name ?? accessory.displayName)
47
+ .setCharacteristic(this.hap.Characteristic.Model, accessory.context.model ?? 'Unknown')
48
+ .setCharacteristic(this.hap.Characteristic.ProductData, accessory.context.deviceId)
49
+ .setCharacteristic(this.hap.Characteristic.SerialNumber, accessory.context.deviceId);
50
+ }
51
+
52
+ async getDeviceLogSettings(device: irdevice & irDevicesConfig): Promise<void> {
53
+ if (this.platform.debugMode) {
54
+ this.deviceLogging = this.accessory.context.logging = 'debugMode';
55
+ this.debugWarnLog(`${this.device.remoteType}: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`);
56
+ } else if (device.logging) {
57
+ this.deviceLogging = this.accessory.context.logging = device.logging;
58
+ this.debugWarnLog(`${this.device.remoteType}: ${this.accessory.displayName} Using Device Config Logging: ${this.deviceLogging}`);
59
+ } else if (this.config.logging) {
60
+ this.deviceLogging = this.accessory.context.logging = this.config.logging;
61
+ this.debugWarnLog(`${this.device.remoteType}: ${this.accessory.displayName} Using Platform Config Logging: ${this.deviceLogging}`);
62
+ } else {
63
+ this.deviceLogging = this.accessory.context.logging = 'standard';
64
+ this.debugWarnLog(`${this.device.remoteType}: ${this.accessory.displayName} Logging Not Set, Using: ${this.deviceLogging}`);
65
+ }
66
+ }
67
+
68
+ async getDeviceConfigSettings(device: irdevice & irDevicesConfig): Promise<void> {
69
+ const deviceConfig = {};
70
+ if (device.logging !== 'standard') {
71
+ deviceConfig['logging'] = device.logging;
72
+ }
73
+ if (device.connectionType !== '') {
74
+ deviceConfig['connectionType'] = device.connectionType;
75
+ }
76
+ if (device.external === true) {
77
+ deviceConfig['external'] = device.external;
78
+ }
79
+ if (device.customize === true) {
80
+ deviceConfig['customize'] = device.customize;
81
+ }
82
+ if (device.commandType !== '') {
83
+ deviceConfig['commandType'] = device.commandType;
84
+ }
85
+ if (device.customOn !== '') {
86
+ deviceConfig['customOn'] = device.customOn;
87
+ }
88
+ if (device.customOff !== '') {
89
+ deviceConfig['customOff'] = device.customOff;
90
+ }
91
+ if (device.disablePushOn === true) {
92
+ deviceConfig['disablePushOn'] = device.disablePushOn;
93
+ }
94
+ if (device.disablePushOff === true) {
95
+ deviceConfig['disablePushOff'] = device.disablePushOff;
96
+ }
97
+ if (device.disablePushDetail === true) {
98
+ deviceConfig['disablePushDetail'] = device.disablePushDetail;
99
+ }
100
+ let irairConfig = {};
101
+ if (device.irair) {
102
+ irairConfig = device.irair;
103
+ }
104
+ let irpurConfig = {};
105
+ if (device.irpur) {
106
+ irpurConfig = device.irpur;
107
+ }
108
+ let ircamConfig = {};
109
+ if (device.ircam) {
110
+ ircamConfig = device.ircam;
111
+ }
112
+ let irfanConfig = {};
113
+ if (device.irfan) {
114
+ irfanConfig = device.irfan;
115
+ }
116
+ let irlightConfig = {};
117
+ if (device.irlight) {
118
+ irlightConfig = device.irlight;
119
+ }
120
+ let otherConfig = {};
121
+ if (device.other) {
122
+ otherConfig = device.other;
123
+ }
124
+ let irtvConfig = {};
125
+ if (device.irtv) {
126
+ irtvConfig = device.irtv;
127
+ }
128
+ let irvcConfig = {};
129
+ if (device.irvc) {
130
+ irvcConfig = device.irvc;
131
+ }
132
+ let irwhConfig = {};
133
+ if (device.irwh) {
134
+ irwhConfig = device.irwh;
135
+ }
136
+ const config = Object.assign({}, deviceConfig, irairConfig, irpurConfig, ircamConfig, irfanConfig, irlightConfig, otherConfig,
137
+ irtvConfig, irvcConfig, irwhConfig);
138
+ if (Object.entries(config).length !== 0) {
139
+ this.debugSuccessLog(`${this.device.remoteType}: ${this.accessory.displayName} Config: ${JSON.stringify(config)}`);
140
+ }
141
+ }
142
+
143
+ async getDeviceContext(accessory: PlatformAccessory, device: irdevice & irDevicesConfig): Promise<void> {
144
+ accessory.context.name = device.deviceName;
145
+ accessory.context.model = device.remoteType;
146
+ accessory.context.deviceId = device.deviceId;
147
+ accessory.context.remoteType = device.remoteType;
148
+ if (device.firmware) {
149
+ accessory.context.firmware = device.firmware;
150
+ } else if (device.firmware === undefined || accessory.context.firmware === undefined) {
151
+ device.firmware = this.platform.version;
152
+ accessory.context.firmware = device.firmware;
153
+ } else {
154
+ accessory.context.firmware = 'Unknown';
155
+ }
156
+
157
+ // Firmware Version
158
+ let deviceFirmwareVersion: string;
159
+ if (device.firmware) {
160
+ deviceFirmwareVersion = device.firmware;
161
+ this.debugSuccessLog(`${device.remoteType}: ${accessory.displayName} 1 FirmwareRevision: ${device.firmware}`);
162
+ } else if (accessory.context.deviceVersion) {
163
+ deviceFirmwareVersion = accessory.context.deviceVersion;
164
+ this.debugSuccessLog(`${device.remoteType}: ${accessory.displayName} 2 FirmwareRevision: ${accessory.context.deviceVersion}`);
165
+ } else {
166
+ deviceFirmwareVersion = this.platform.version ?? '0.0.0';
167
+ if (this.platform.version) {
168
+ this.debugSuccessLog(`${device.remoteType}: ${accessory.displayName} 3 FirmwareRevision: ${this.platform.version}`);
169
+ } else {
170
+ this.debugSuccessLog(`${device.remoteType}: ${accessory.displayName} 4 FirmwareRevision: ${deviceFirmwareVersion}`);
171
+ }
172
+ }
173
+ const version = deviceFirmwareVersion.toString();
174
+ this.debugLog(`${this.device.remoteType}: ${accessory.displayName} Firmware Version: ${version?.replace(/^V|-.*$/g, '')}`);
175
+ let deviceVersion: string;
176
+ if (version?.includes('.') === false) {
177
+ const replace = version?.replace(/^V|-.*$/g, '');
178
+ const match = replace?.match(/.{1,1}/g);
179
+ const validVersion = match?.join('.');
180
+ deviceVersion = validVersion ?? '0.0.0';
181
+ } else {
182
+ deviceVersion = version?.replace(/^V|-.*$/g, '') ?? '0.0.0';
183
+ }
184
+ accessory
185
+ .getService(this.hap.Service.AccessoryInformation)!
186
+ .setCharacteristic(this.hap.Characteristic.HardwareRevision, deviceVersion)
187
+ .setCharacteristic(this.hap.Characteristic.SoftwareRevision, deviceVersion)
188
+ .setCharacteristic(this.hap.Characteristic.FirmwareRevision, deviceVersion)
189
+ .getCharacteristic(this.hap.Characteristic.FirmwareRevision)
190
+ .updateValue(deviceVersion);
191
+ accessory.context.deviceVersion = deviceVersion;
192
+ this.debugSuccessLog(`${device.remoteType}: ${accessory.displayName} deviceVersion: ${accessory.context.deviceVersion}`);
193
+ }
194
+
195
+ async pushChangeRequest(bodyChange: string): Promise<{ body: any; statusCode: any; }> {
196
+ return await request(`${Devices}/${this.device.deviceId}/commands`, {
197
+ body: bodyChange,
198
+ method: 'POST',
199
+ headers: this.platform.generateHeaders(),
200
+ });
201
+ }
202
+
203
+ async pushStatusCodes(statusCode: any, deviceStatus: any) {
204
+ this.debugWarnLog(`${this.device.remoteType}: ${this.accessory.displayName} statusCode: ${statusCode}`);
205
+ this.debugWarnLog(`${this.device.remoteType}: ${this.accessory.displayName} deviceStatus: ${JSON.stringify(deviceStatus)}`);
206
+ this.debugWarnLog(`${this.device.remoteType}: ${this.accessory.displayName} deviceStatus statusCode: ${deviceStatus.statusCode}`);
207
+ }
208
+
209
+ async successfulPushChange(statusCode: any, deviceStatus: any, bodyChange: any) {
210
+ this.debugSuccessLog(`${this.device.remoteType}: ${this.accessory.displayName} statusCode: ${statusCode} & deviceStatus `
211
+ + `StatusCode: ${deviceStatus.statusCode}`);
212
+ this.successLog(`${this.device.remoteType}: ${this.accessory.displayName} request to SwitchBot API,`
213
+ + ` body: ${JSON.stringify(JSON.parse(bodyChange))} sent successfully`);
214
+ }
215
+
216
+ async disablePushOnChanges(device: irdevice & irDevicesConfig): Promise<void> {
217
+ if (device.disablePushOn === undefined) {
218
+ this.disablePushOn = false;
219
+ } else {
220
+ this.disablePushOn = device.disablePushOn;
221
+ }
222
+ }
223
+
224
+ async disablePushOffChanges(device: irdevice & irDevicesConfig): Promise<void> {
225
+ if (device.disablePushOff === undefined) {
226
+ this.disablePushOff = false;
227
+ } else {
228
+ this.disablePushOff = device.disablePushOff;
229
+ }
230
+ }
231
+
232
+ async disablePushDetailChanges(device: irdevice & irDevicesConfig): Promise<void> {
233
+ if (device.disablePushDetail === undefined) {
234
+ this.disablePushDetail = false;
235
+ } else {
236
+ this.disablePushDetail = device.disablePushDetail;
237
+ }
238
+ }
239
+
240
+ async commandType(): Promise<string> {
241
+ let commandType: string;
242
+ if (this.device.commandType && this.device.customize) {
243
+ commandType = this.device.commandType;
244
+ } else if (this.device.customize) {
245
+ commandType = 'customize';
246
+ } else {
247
+ commandType = 'command';
248
+ }
249
+ return commandType;
250
+ }
251
+
252
+ async commandOn(): Promise<string> {
253
+ let command: string;
254
+ if (this.device.customize && this.device.customOn) {
255
+ command = this.device.customOn;
256
+ } else {
257
+ command = 'turnOn';
258
+ }
259
+ return command;
260
+ }
261
+
262
+ async commandOff(): Promise<string> {
263
+ let command: string;
264
+ if (this.device.customize && this.device.customOff) {
265
+ command = this.device.customOff;
266
+ } else {
267
+ command = 'turnOff';
268
+ }
269
+ return command;
270
+ }
271
+
272
+ async statusCode(statusCode: number): Promise<void> {
273
+ switch (statusCode) {
274
+ case 151:
275
+ this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Command not supported by this deviceType, statusCode: ${statusCode}`);
276
+ break;
277
+ case 152:
278
+ this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Device not found, statusCode: ${statusCode}`);
279
+ break;
280
+ case 160:
281
+ this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Command is not supported, statusCode: ${statusCode}`);
282
+ break;
283
+ case 161:
284
+ this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Device is offline, statusCode: ${statusCode}`);
285
+ break;
286
+ case 171:
287
+ this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Hub Device is offline, statusCode: ${statusCode}. `
288
+ + `Hub: ${this.device.hubDeviceId}`);
289
+ break;
290
+ case 190:
291
+ this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Device internal error due to device states not synchronized with`
292
+ + ` server, Or command format is invalid, statusCode: ${statusCode}`);
293
+ break;
294
+ case 100:
295
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Command successfully sent, statusCode: ${statusCode}`);
296
+ break;
297
+ case 200:
298
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Request successful, statusCode: ${statusCode}`);
299
+ break;
300
+ case 400:
301
+ this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Bad Request, The client has issued an invalid request. `
302
+ + `This is commonly used to specify validation errors in a request payload, statusCode: ${statusCode}`);
303
+ break;
304
+ case 401:
305
+ this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Unauthorized, Authorization for the API is required, `
306
+ + `but the request has not been authenticated, statusCode: ${statusCode}`);
307
+ break;
308
+ case 403:
309
+ this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Forbidden, The request has been authenticated but does not `
310
+ + `have appropriate permissions, or a requested resource is not found, statusCode: ${statusCode}`);
311
+ break;
312
+ case 404:
313
+ this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Not Found, Specifies the requested path does not exist, `
314
+ + `statusCode: ${statusCode}`);
315
+ break;
316
+ case 406:
317
+ this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Not Acceptable, The client has requested a MIME type via `
318
+ + `the Accept header for a value not supported by the server, statusCode: ${statusCode}`);
319
+ break;
320
+ case 415:
321
+ this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Unsupported Media Type, The client has defined a contentType `
322
+ + `header that is not supported by the server, statusCode: ${statusCode}`);
323
+ break;
324
+ case 422:
325
+ this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Unprocessable Entity, The client has made a valid request, `
326
+ + `but the server cannot process it. This is often used for APIs for which certain limits have been exceeded, statusCode: ${statusCode}`);
327
+ break;
328
+ case 429:
329
+ this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Too Many Requests, The client has exceeded the number of `
330
+ + `requests allowed for a given time window, statusCode: ${statusCode}`);
331
+ break;
332
+ case 500:
333
+ this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Internal Server Error, An unexpected error on the SmartThings `
334
+ + `servers has occurred. These errors should be rare, statusCode: ${statusCode}`);
335
+ break;
336
+ default:
337
+ this.infoLog(`${this.device.remoteType}: ${this.accessory.displayName} Unknown statusCode: `
338
+ + `${statusCode}, Submit Bugs Here: ' + 'https://tinyurl.com/SwitchBotBug`);
339
+ }
340
+ }
341
+
342
+ /**
343
+ * Logging for Device
344
+ */
345
+ infoLog(...log: any[]): void {
346
+ if (this.enablingDeviceLogging()) {
347
+ this.log.info(String(...log));
348
+ }
349
+ }
350
+
351
+ successLog(...log: any[]): void {
352
+ if (this.enablingDeviceLogging()) {
353
+ this.platform.log.success(String(...log));
354
+ }
355
+ }
356
+
357
+ debugSuccessLog(...log: any[]): void {
358
+ if (this.enablingDeviceLogging()) {
359
+ if (this.deviceLogging?.includes('debug')) {
360
+ this.log.success('[DEBUG]', String(...log));
361
+ }
362
+ }
363
+ }
364
+
365
+ warnLog(...log: any[]): void {
366
+ if (this.enablingDeviceLogging()) {
367
+ this.log.warn(String(...log));
368
+ }
369
+ }
370
+
371
+ debugWarnLog(...log: any[]): void {
372
+ if (this.enablingDeviceLogging()) {
373
+ if (this.deviceLogging?.includes('debug')) {
374
+ this.log.warn('[DEBUG]', String(...log));
375
+ }
376
+ }
377
+ }
378
+
379
+ errorLog(...log: any[]): void {
380
+ if (this.enablingDeviceLogging()) {
381
+ this.log.error(String(...log));
382
+ }
383
+ }
384
+
385
+ debugErrorLog(...log: any[]): void {
386
+ if (this.enablingDeviceLogging()) {
387
+ if (this.deviceLogging?.includes('debug')) {
388
+ this.log.error('[DEBUG]', String(...log));
389
+ }
390
+ }
391
+ }
392
+
393
+ debugLog(...log: any[]): void {
394
+ if (this.enablingDeviceLogging()) {
395
+ if (this.deviceLogging === 'debug') {
396
+ this.log.info('[DEBUG]', String(...log));
397
+ } else {
398
+ this.log.debug(String(...log));
399
+ }
400
+ }
401
+ }
402
+
403
+ enablingDeviceLogging(): boolean {
404
+ return this.deviceLogging.includes('debug') || this.deviceLogging === 'standard';
405
+ }
406
+ }