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