@switchbot/homebridge-switchbot 3.5.1-beta.1 → 3.5.1-beta.11

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 (197) hide show
  1. package/README.md +16 -0
  2. package/dist/device/blindtilt.d.ts +15 -6
  3. package/dist/device/blindtilt.d.ts.map +1 -1
  4. package/dist/device/blindtilt.js +203 -255
  5. package/dist/device/blindtilt.js.map +1 -1
  6. package/dist/device/bot.d.ts +9 -4
  7. package/dist/device/bot.d.ts.map +1 -1
  8. package/dist/device/bot.js +196 -218
  9. package/dist/device/bot.js.map +1 -1
  10. package/dist/device/ceilinglight.d.ts +9 -4
  11. package/dist/device/ceilinglight.d.ts.map +1 -1
  12. package/dist/device/ceilinglight.js +203 -249
  13. package/dist/device/ceilinglight.js.map +1 -1
  14. package/dist/device/colorbulb.d.ts +10 -5
  15. package/dist/device/colorbulb.d.ts.map +1 -1
  16. package/dist/device/colorbulb.js +329 -378
  17. package/dist/device/colorbulb.js.map +1 -1
  18. package/dist/device/contact.d.ts +9 -4
  19. package/dist/device/contact.d.ts.map +1 -1
  20. package/dist/device/contact.js +99 -142
  21. package/dist/device/contact.js.map +1 -1
  22. package/dist/device/curtain.d.ts +19 -7
  23. package/dist/device/curtain.d.ts.map +1 -1
  24. package/dist/device/curtain.js +203 -264
  25. package/dist/device/curtain.js.map +1 -1
  26. package/dist/device/device.d.ts +28 -32
  27. package/dist/device/device.d.ts.map +1 -1
  28. package/dist/device/device.js +186 -225
  29. package/dist/device/device.js.map +1 -1
  30. package/dist/device/fan.d.ts +9 -4
  31. package/dist/device/fan.d.ts.map +1 -1
  32. package/dist/device/fan.js +198 -227
  33. package/dist/device/fan.js.map +1 -1
  34. package/dist/device/hub.d.ts +9 -5
  35. package/dist/device/hub.d.ts.map +1 -1
  36. package/dist/device/hub.js +106 -231
  37. package/dist/device/hub.js.map +1 -1
  38. package/dist/device/humidifier.d.ts +12 -4
  39. package/dist/device/humidifier.d.ts.map +1 -1
  40. package/dist/device/humidifier.js +192 -232
  41. package/dist/device/humidifier.js.map +1 -1
  42. package/dist/device/iosensor.d.ts +9 -4
  43. package/dist/device/iosensor.d.ts.map +1 -1
  44. package/dist/device/iosensor.js +91 -157
  45. package/dist/device/iosensor.js.map +1 -1
  46. package/dist/device/lightstrip.d.ts +10 -5
  47. package/dist/device/lightstrip.d.ts.map +1 -1
  48. package/dist/device/lightstrip.js +287 -367
  49. package/dist/device/lightstrip.js.map +1 -1
  50. package/dist/device/lock.d.ts +10 -5
  51. package/dist/device/lock.d.ts.map +1 -1
  52. package/dist/device/lock.js +171 -216
  53. package/dist/device/lock.js.map +1 -1
  54. package/dist/device/meter.d.ts +9 -4
  55. package/dist/device/meter.d.ts.map +1 -1
  56. package/dist/device/meter.js +93 -158
  57. package/dist/device/meter.js.map +1 -1
  58. package/dist/device/meterplus.d.ts +9 -4
  59. package/dist/device/meterplus.d.ts.map +1 -1
  60. package/dist/device/meterplus.js +94 -155
  61. package/dist/device/meterplus.js.map +1 -1
  62. package/dist/device/motion.d.ts +9 -4
  63. package/dist/device/motion.d.ts.map +1 -1
  64. package/dist/device/motion.js +84 -142
  65. package/dist/device/motion.js.map +1 -1
  66. package/dist/device/plug.d.ts +9 -4
  67. package/dist/device/plug.d.ts.map +1 -1
  68. package/dist/device/plug.js +99 -124
  69. package/dist/device/plug.js.map +1 -1
  70. package/dist/device/robotvacuumcleaner.d.ts +9 -6
  71. package/dist/device/robotvacuumcleaner.d.ts.map +1 -1
  72. package/dist/device/robotvacuumcleaner.js +170 -253
  73. package/dist/device/robotvacuumcleaner.js.map +1 -1
  74. package/dist/device/waterdetector.d.ts +12 -4
  75. package/dist/device/waterdetector.d.ts.map +1 -1
  76. package/dist/device/waterdetector.js +105 -129
  77. package/dist/device/waterdetector.js.map +1 -1
  78. package/dist/irdevice/airconditioner.d.ts +2 -1
  79. package/dist/irdevice/airconditioner.d.ts.map +1 -1
  80. package/dist/irdevice/airconditioner.js +45 -51
  81. package/dist/irdevice/airconditioner.js.map +1 -1
  82. package/dist/irdevice/airpurifier.d.ts +2 -1
  83. package/dist/irdevice/airpurifier.d.ts.map +1 -1
  84. package/dist/irdevice/airpurifier.js +17 -17
  85. package/dist/irdevice/airpurifier.js.map +1 -1
  86. package/dist/irdevice/camera.d.ts +2 -1
  87. package/dist/irdevice/camera.d.ts.map +1 -1
  88. package/dist/irdevice/camera.js +9 -9
  89. package/dist/irdevice/camera.js.map +1 -1
  90. package/dist/irdevice/fan.d.ts +2 -1
  91. package/dist/irdevice/fan.d.ts.map +1 -1
  92. package/dist/irdevice/fan.js +19 -19
  93. package/dist/irdevice/fan.js.map +1 -1
  94. package/dist/irdevice/irdevice.d.ts +24 -11
  95. package/dist/irdevice/irdevice.d.ts.map +1 -1
  96. package/dist/irdevice/irdevice.js +90 -68
  97. package/dist/irdevice/irdevice.js.map +1 -1
  98. package/dist/irdevice/light.d.ts +2 -1
  99. package/dist/irdevice/light.d.ts.map +1 -1
  100. package/dist/irdevice/light.js +15 -17
  101. package/dist/irdevice/light.js.map +1 -1
  102. package/dist/irdevice/other.d.ts +2 -1
  103. package/dist/irdevice/other.d.ts.map +1 -1
  104. package/dist/irdevice/other.js +76 -76
  105. package/dist/irdevice/other.js.map +1 -1
  106. package/dist/irdevice/tv.d.ts +2 -1
  107. package/dist/irdevice/tv.d.ts.map +1 -1
  108. package/dist/irdevice/tv.js +35 -35
  109. package/dist/irdevice/tv.js.map +1 -1
  110. package/dist/irdevice/vacuumcleaner.d.ts +2 -1
  111. package/dist/irdevice/vacuumcleaner.d.ts.map +1 -1
  112. package/dist/irdevice/vacuumcleaner.js +9 -9
  113. package/dist/irdevice/vacuumcleaner.js.map +1 -1
  114. package/dist/irdevice/waterheater.d.ts +2 -1
  115. package/dist/irdevice/waterheater.d.ts.map +1 -1
  116. package/dist/irdevice/waterheater.js +9 -9
  117. package/dist/irdevice/waterheater.js.map +1 -1
  118. package/dist/platform.d.ts +15 -15
  119. package/dist/platform.d.ts.map +1 -1
  120. package/dist/platform.js +288 -271
  121. package/dist/platform.js.map +1 -1
  122. package/dist/settings.d.ts +49 -191
  123. package/dist/settings.d.ts.map +1 -1
  124. package/dist/settings.js +19 -0
  125. package/dist/settings.js.map +1 -1
  126. package/dist/types/bledevicestatus.d.ts +279 -0
  127. package/dist/types/bledevicestatus.d.ts.map +1 -0
  128. package/dist/types/bledevicestatus.js +2 -0
  129. package/dist/types/bledevicestatus.js.map +1 -0
  130. package/dist/types/devicelist.d.ts +89 -0
  131. package/dist/types/devicelist.d.ts.map +1 -0
  132. package/dist/types/devicelist.js +6 -0
  133. package/dist/types/devicelist.js.map +1 -0
  134. package/dist/types/deviceresponse.d.ts +13 -0
  135. package/dist/types/deviceresponse.d.ts.map +1 -0
  136. package/dist/types/deviceresponse.js +2 -0
  137. package/dist/types/deviceresponse.js.map +1 -0
  138. package/dist/types/devicestatus.d.ts +149 -0
  139. package/dist/types/devicestatus.d.ts.map +1 -0
  140. package/dist/types/devicestatus.js +3 -0
  141. package/dist/types/devicestatus.js.map +1 -0
  142. package/dist/types/devicewebhookstatus.d.ts +156 -0
  143. package/dist/types/devicewebhookstatus.d.ts.map +1 -0
  144. package/dist/types/devicewebhookstatus.js +2 -0
  145. package/dist/types/devicewebhookstatus.js.map +1 -0
  146. package/dist/types/irdevicelist.d.ts +10 -0
  147. package/dist/types/irdevicelist.d.ts.map +1 -0
  148. package/dist/types/irdevicelist.js +2 -0
  149. package/dist/types/irdevicelist.js.map +1 -0
  150. package/dist/types/pushbody.d.ts +6 -0
  151. package/dist/types/pushbody.d.ts.map +1 -0
  152. package/dist/types/pushbody.js +2 -0
  153. package/dist/types/pushbody.js.map +1 -0
  154. package/dist/utils.d.ts +25 -0
  155. package/dist/utils.d.ts.map +1 -1
  156. package/dist/utils.js +28 -0
  157. package/dist/utils.js.map +1 -1
  158. package/package.json +10 -10
  159. package/src/device/blindtilt.ts +224 -264
  160. package/src/device/bot.ts +208 -221
  161. package/src/device/ceilinglight.ts +211 -261
  162. package/src/device/colorbulb.ts +334 -397
  163. package/src/device/contact.ts +111 -146
  164. package/src/device/curtain.ts +220 -283
  165. package/src/device/device.ts +194 -245
  166. package/src/device/fan.ts +214 -230
  167. package/src/device/hub.ts +126 -246
  168. package/src/device/humidifier.ts +216 -243
  169. package/src/device/iosensor.ts +114 -166
  170. package/src/device/lightstrip.ts +302 -377
  171. package/src/device/lock.ts +187 -221
  172. package/src/device/meter.ts +116 -177
  173. package/src/device/meterplus.ts +117 -174
  174. package/src/device/motion.ts +99 -144
  175. package/src/device/plug.ts +110 -128
  176. package/src/device/robotvacuumcleaner.ts +189 -252
  177. package/src/device/waterdetector.ts +123 -139
  178. package/src/irdevice/airconditioner.ts +47 -52
  179. package/src/irdevice/airpurifier.ts +19 -18
  180. package/src/irdevice/camera.ts +11 -10
  181. package/src/irdevice/fan.ts +21 -20
  182. package/src/irdevice/irdevice.ts +95 -70
  183. package/src/irdevice/light.ts +17 -18
  184. package/src/irdevice/other.ts +78 -77
  185. package/src/irdevice/tv.ts +37 -36
  186. package/src/irdevice/vacuumcleaner.ts +11 -10
  187. package/src/irdevice/waterheater.ts +11 -10
  188. package/src/platform.ts +290 -272
  189. package/src/settings.ts +30 -239
  190. package/src/types/bledevicestatus.ts +305 -0
  191. package/src/types/devicelist.ts +124 -0
  192. package/src/types/deviceresponse.ts +15 -0
  193. package/src/types/devicestatus.ts +178 -0
  194. package/src/types/devicewebhookstatus.ts +196 -0
  195. package/src/types/irdevicelist.ts +15 -0
  196. package/src/types/pushbody.ts +9 -0
  197. package/src/utils.ts +33 -0
@@ -6,8 +6,9 @@ import { request } from 'undici';
6
6
  import { Devices } from '../settings.js';
7
7
 
8
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';
9
+ import type { API, HAP, Logging, PlatformAccessory, Service, CharacteristicValue } from 'homebridge';
10
+ import type { SwitchBotPlatformConfig, irDevicesConfig } from '../settings.js';
11
+ import type { irdevice } from '../types/irdevicelist.js';
11
12
 
12
13
  export abstract class irdeviceBase {
13
14
  public readonly api: API;
@@ -52,16 +53,16 @@ export abstract class irdeviceBase {
52
53
  async getDeviceLogSettings(device: irdevice & irDevicesConfig): Promise<void> {
53
54
  if (this.platform.debugMode) {
54
55
  this.deviceLogging = this.accessory.context.logging = 'debugMode';
55
- this.debugWarnLog(`${this.device.remoteType}: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`);
56
+ await this.debugWarnLog(`Using Debug Mode Logging: ${this.deviceLogging}`);
56
57
  } else if (device.logging) {
57
58
  this.deviceLogging = this.accessory.context.logging = device.logging;
58
- this.debugWarnLog(`${this.device.remoteType}: ${this.accessory.displayName} Using Device Config Logging: ${this.deviceLogging}`);
59
+ await this.debugWarnLog(`Using Device Config Logging: ${this.deviceLogging}`);
59
60
  } else if (this.config.logging) {
60
61
  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
+ await this.debugWarnLog(`Using Platform Config Logging: ${this.deviceLogging}`);
62
63
  } else {
63
64
  this.deviceLogging = this.accessory.context.logging = 'standard';
64
- this.debugWarnLog(`${this.device.remoteType}: ${this.accessory.displayName} Logging Not Set, Using: ${this.deviceLogging}`);
65
+ await this.debugWarnLog(`Logging Not Set, Using: ${this.deviceLogging}`);
65
66
  }
66
67
  }
67
68
 
@@ -136,7 +137,7 @@ export abstract class irdeviceBase {
136
137
  const config = Object.assign({}, deviceConfig, irairConfig, irpurConfig, ircamConfig, irfanConfig, irlightConfig, otherConfig,
137
138
  irtvConfig, irvcConfig, irwhConfig);
138
139
  if (Object.entries(config).length !== 0) {
139
- this.debugSuccessLog(`${this.device.remoteType}: ${this.accessory.displayName} Config: ${JSON.stringify(config)}`);
140
+ this.debugSuccessLog(`Config: ${JSON.stringify(config)}`);
140
141
  }
141
142
  }
142
143
 
@@ -171,7 +172,7 @@ export abstract class irdeviceBase {
171
172
  }
172
173
  }
173
174
  const version = deviceFirmwareVersion.toString();
174
- this.debugLog(`${this.device.remoteType}: ${accessory.displayName} Firmware Version: ${version?.replace(/^V|-.*$/g, '')}`);
175
+ await this.debugLog(`${this.device.remoteType}: ${accessory.displayName} Firmware Version: ${version?.replace(/^V|-.*$/g, '')}`);
175
176
  let deviceVersion: string;
176
177
  if (version?.includes('.') === false) {
177
178
  const replace = version?.replace(/^V|-.*$/g, '');
@@ -179,7 +180,7 @@ export abstract class irdeviceBase {
179
180
  const validVersion = match?.join('.');
180
181
  deviceVersion = validVersion ?? '0.0.0';
181
182
  } else {
182
- deviceVersion = version?.replace(/^V|-.*$/g, '') ?? '0.0.0';
183
+ deviceVersion = version.replace(/^V|-.*$/g, '') ?? '0.0.0';
183
184
  }
184
185
  accessory
185
186
  .getService(this.hap.Service.AccessoryInformation)!
@@ -200,21 +201,48 @@ export abstract class irdeviceBase {
200
201
  });
201
202
  }
202
203
 
204
+ async successfulStatusCodes(statusCode: any, deviceStatus: any) {
205
+ return (statusCode === 200 || statusCode === 100) && (deviceStatus.statusCode === 200 || deviceStatus.statusCode === 100);
206
+ }
207
+
208
+ /**
209
+ * Update the characteristic value and log the change.
210
+ *
211
+ * @param Service: Service
212
+ * @param Characteristic: Characteristic
213
+ * @param CharacteristicValue: CharacteristicValue | undefined
214
+ * @param CharacteristicName: string
215
+ * @return: void
216
+ *
217
+ */
218
+ async updateCharacteristic(Service: Service, Characteristic: any,
219
+ CharacteristicValue: CharacteristicValue | undefined, CharacteristicName: string): Promise<void> {
220
+ if (CharacteristicValue === undefined) {
221
+ await await this.debugLog(`${CharacteristicName}: ${CharacteristicValue}`);
222
+ } else {
223
+ Service.updateCharacteristic(Characteristic, CharacteristicValue);
224
+ await await this.debugLog(`updateCharacteristic ${CharacteristicName}: ${CharacteristicValue}`);
225
+ await await this.debugWarnLog(`context before: ${this.accessory.context[CharacteristicName]}`);
226
+ this.accessory.context[CharacteristicName] = CharacteristicValue;
227
+ await await this.debugWarnLog(`context after: ${this.accessory.context[CharacteristicName]}`);
228
+ }
229
+ }
230
+
203
231
  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}`);
232
+ await this.debugWarnLog(`statusCode: ${statusCode}`);
233
+ await this.debugWarnLog(`deviceStatus: ${JSON.stringify(deviceStatus)}`);
234
+ await this.debugWarnLog(`deviceStatus statusCode: ${deviceStatus.statusCode}`);
207
235
  }
208
236
 
209
237
  async successfulPushChange(statusCode: any, deviceStatus: any, bodyChange: any) {
210
- this.debugSuccessLog(`${this.device.remoteType}: ${this.accessory.displayName} statusCode: ${statusCode} & deviceStatus `
238
+ this.debugSuccessLog(`statusCode: ${statusCode} & deviceStatus `
211
239
  + `StatusCode: ${deviceStatus.statusCode}`);
212
- this.successLog(`${this.device.remoteType}: ${this.accessory.displayName} request to SwitchBot API,`
240
+ this.successLog('request to SwitchBot API,'
213
241
  + ` body: ${JSON.stringify(JSON.parse(bodyChange))} sent successfully`);
214
242
  }
215
243
 
216
244
  async pushChangeError(e: Error) {
217
- this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} failed pushChanges with ${this.device.connectionType}`
245
+ this.errorLog(`failed pushChanges with ${this.device.connectionType}`
218
246
  + ` Connection, Error Message: ${JSON.stringify(e.message)}`);
219
247
  }
220
248
 
@@ -277,69 +305,66 @@ export abstract class irdeviceBase {
277
305
  async statusCode(statusCode: number): Promise<void> {
278
306
  switch (statusCode) {
279
307
  case 151:
280
- this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Command not supported by this deviceType, statusCode: ${statusCode}`);
308
+ this.errorLog(`Command not supported by this deviceType, statusCode: ${statusCode}`);
281
309
  break;
282
310
  case 152:
283
- this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Device not found, statusCode: ${statusCode}`);
311
+ this.errorLog(`Device not found, statusCode: ${statusCode}`);
284
312
  break;
285
313
  case 160:
286
- this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Command is not supported, statusCode: ${statusCode}`);
314
+ this.errorLog(`Command is not supported, statusCode: ${statusCode}`);
287
315
  break;
288
316
  case 161:
289
- this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Device is offline, statusCode: ${statusCode}`);
317
+ this.errorLog(`Device is offline, statusCode: ${statusCode}`);
290
318
  break;
291
319
  case 171:
292
- this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Hub Device is offline, statusCode: ${statusCode}. `
293
- + `Hub: ${this.device.hubDeviceId}`);
320
+ this.errorLog(`Hub Device is offline, statusCode: ${statusCode}. Hub: ${this.device.hubDeviceId}`);
294
321
  break;
295
322
  case 190:
296
- this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Device internal error due to device states not synchronized with`
297
- + ` server, Or command format is invalid, statusCode: ${statusCode}`);
323
+ this.errorLog('Device internal error due to device states not synchronized with server, Or command format is invalid,'
324
+ + ` statusCode: ${statusCode}`);
298
325
  break;
299
326
  case 100:
300
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Command successfully sent, statusCode: ${statusCode}`);
327
+ await this.debugLog(`Command successfully sent, statusCode: ${statusCode}`);
301
328
  break;
302
329
  case 200:
303
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Request successful, statusCode: ${statusCode}`);
330
+ await this.debugLog(`Request successful, statusCode: ${statusCode}`);
304
331
  break;
305
332
  case 400:
306
- this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Bad Request, The client has issued an invalid request. `
307
- + `This is commonly used to specify validation errors in a request payload, statusCode: ${statusCode}`);
333
+ this.errorLog('Bad Request, The client has issued an invalid request. This is commonly used to specify validation errors in a request'
334
+ + ` payload, statusCode: ${statusCode}`);
308
335
  break;
309
336
  case 401:
310
- this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Unauthorized, Authorization for the API is required, `
311
- + `but the request has not been authenticated, statusCode: ${statusCode}`);
337
+ this.errorLog(`Unauthorized, Authorization for the API is required, but the request has not been authenticated, statusCode: ${statusCode}`);
312
338
  break;
313
339
  case 403:
314
- this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Forbidden, The request has been authenticated but does not `
315
- + `have appropriate permissions, or a requested resource is not found, statusCode: ${statusCode}`);
340
+ this.errorLog('Forbidden, The request has been authenticated but does not have appropriate permissions, or a requested resource is not'
341
+ + ` found, statusCode: ${statusCode}`);
316
342
  break;
317
343
  case 404:
318
- this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Not Found, Specifies the requested path does not exist, `
319
- + `statusCode: ${statusCode}`);
344
+ this.errorLog(`Not Found, Specifies the requested path does not exist, statusCode: ${statusCode}`);
320
345
  break;
321
346
  case 406:
322
- this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Not Acceptable, The client has requested a MIME type via `
323
- + `the Accept header for a value not supported by the server, statusCode: ${statusCode}`);
347
+ this.errorLog('Not Acceptable, The client has requested a MIME type via the Accept header for a value not supported by the server,'
348
+ + ` statusCode: ${statusCode}`);
324
349
  break;
325
350
  case 415:
326
- this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Unsupported Media Type, The client has defined a contentType `
327
- + `header that is not supported by the server, statusCode: ${statusCode}`);
351
+ this.errorLog('Unsupported Media Type, The client has defined a contentType header that is not supported by the server,'
352
+ + ` statusCode: ${statusCode}`);
328
353
  break;
329
354
  case 422:
330
- this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Unprocessable Entity, The client has made a valid request, `
331
- + `but the server cannot process it. This is often used for APIs for which certain limits have been exceeded, statusCode: ${statusCode}`);
355
+ this.errorLog('Unprocessable Entity, The client has made a valid request, but the server cannot process it. This is often used for APIs'
356
+ + ` for which certain limits have been exceeded, statusCode: ${statusCode}`);
332
357
  break;
333
358
  case 429:
334
- this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Too Many Requests, The client has exceeded the number of `
335
- + `requests allowed for a given time window, statusCode: ${statusCode}`);
359
+ this.errorLog('Too Many Requests, The client has exceeded the number of requests allowed for a given time window,'
360
+ + ` statusCode: ${statusCode}`);
336
361
  break;
337
362
  case 500:
338
- this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Internal Server Error, An unexpected error on the SmartThings `
339
- + `servers has occurred. These errors should be rare, statusCode: ${statusCode}`);
363
+ this.errorLog('Internal Server Error, An unexpected error on the SmartThings servers has occurred. These errors should be rare,'
364
+ + ` statusCode: ${statusCode}`);
340
365
  break;
341
366
  default:
342
- this.infoLog(`${this.device.remoteType}: ${this.accessory.displayName} Unknown statusCode: `
367
+ this.infoLog('Unknown statusCode: '
343
368
  + `${statusCode}, Submit Bugs Here: ' + 'https://tinyurl.com/SwitchBotBug`);
344
369
  }
345
370
  }
@@ -347,65 +372,65 @@ export abstract class irdeviceBase {
347
372
  /**
348
373
  * Logging for Device
349
374
  */
350
- infoLog(...log: any[]): void {
351
- if (this.enablingDeviceLogging()) {
352
- this.log.info(String(...log));
375
+ async infoLog(...log: any[]): Promise<void> {
376
+ if (await this.enablingDeviceLogging()) {
377
+ this.log.info(`${this.device.remoteType}: ${this.accessory.displayName}`, String(...log));
353
378
  }
354
379
  }
355
380
 
356
- successLog(...log: any[]): void {
357
- if (this.enablingDeviceLogging()) {
358
- this.platform.log.success(String(...log));
381
+ async successLog(...log: any[]): Promise<void> {
382
+ if (await this.enablingDeviceLogging()) {
383
+ this.log.success(`${this.device.remoteType}: ${this.accessory.displayName}`, String(...log));
359
384
  }
360
385
  }
361
386
 
362
- debugSuccessLog(...log: any[]): void {
363
- if (this.enablingDeviceLogging()) {
387
+ async debugSuccessLog(...log: any[]): Promise<void> {
388
+ if (await this.enablingDeviceLogging()) {
364
389
  if (this.deviceLogging?.includes('debug')) {
365
- this.log.success('[DEBUG]', String(...log));
390
+ this.log.success(`[DEBUG] ${this.device.remoteType}: ${this.accessory.displayName}`, String(...log));
366
391
  }
367
392
  }
368
393
  }
369
394
 
370
- warnLog(...log: any[]): void {
371
- if (this.enablingDeviceLogging()) {
372
- this.log.warn(String(...log));
395
+ async warnLog(...log: any[]): Promise<void> {
396
+ if (await this.enablingDeviceLogging()) {
397
+ this.log.warn(`${this.device.remoteType}: ${this.accessory.displayName}`, String(...log));
373
398
  }
374
399
  }
375
400
 
376
- debugWarnLog(...log: any[]): void {
377
- if (this.enablingDeviceLogging()) {
401
+ async debugWarnLog(...log: any[]): Promise<void> {
402
+ if (await this.enablingDeviceLogging()) {
378
403
  if (this.deviceLogging?.includes('debug')) {
379
- this.log.warn('[DEBUG]', String(...log));
404
+ this.log.warn(`[DEBUG] ${this.device.remoteType}: ${this.accessory.displayName}`, String(...log));
380
405
  }
381
406
  }
382
407
  }
383
408
 
384
- errorLog(...log: any[]): void {
385
- if (this.enablingDeviceLogging()) {
386
- this.log.error(String(...log));
409
+ async errorLog(...log: any[]): Promise<void> {
410
+ if (await this.enablingDeviceLogging()) {
411
+ this.log.error(`${this.device.remoteType}: ${this.accessory.displayName}`, String(...log));
387
412
  }
388
413
  }
389
414
 
390
- debugErrorLog(...log: any[]): void {
391
- if (this.enablingDeviceLogging()) {
415
+ async debugErrorLog(...log: any[]): Promise<void> {
416
+ if (await this.enablingDeviceLogging()) {
392
417
  if (this.deviceLogging?.includes('debug')) {
393
- this.log.error('[DEBUG]', String(...log));
418
+ this.log.error(`[DEBUG] ${this.device.remoteType}: ${this.accessory.displayName}`, String(...log));
394
419
  }
395
420
  }
396
421
  }
397
422
 
398
- debugLog(...log: any[]): void {
399
- if (this.enablingDeviceLogging()) {
423
+ async debugLog(...log: any[]): Promise<void> {
424
+ if (await this.enablingDeviceLogging()) {
400
425
  if (this.deviceLogging === 'debug') {
401
- this.log.info('[DEBUG]', String(...log));
426
+ this.log.info(`[DEBUG] ${this.device.remoteType}: ${this.accessory.displayName}`, String(...log));
402
427
  } else {
403
- this.log.debug(String(...log));
428
+ this.log.debug(`${this.device.remoteType}: ${this.accessory.displayName}`, String(...log));
404
429
  }
405
430
  }
406
431
  }
407
432
 
408
- enablingDeviceLogging(): boolean {
433
+ async enablingDeviceLogging(): Promise<boolean> {
409
434
  return this.deviceLogging.includes('debug') || this.deviceLogging === 'standard';
410
435
  }
411
436
  }
@@ -5,7 +5,8 @@
5
5
  import { irdeviceBase } from './irdevice.js';
6
6
 
7
7
  import type { SwitchBotPlatform } from '../platform.js';
8
- import type { irDevicesConfig, irdevice } from '../settings.js';
8
+ import type { irDevicesConfig } from '../settings.js';
9
+ import type { irdevice } from '../types/irdevicelist.js';
9
10
  import type { CharacteristicValue, PlatformAccessory, Service } from 'homebridge';
10
11
 
11
12
  /**
@@ -126,7 +127,7 @@ export class Light extends irdeviceBase {
126
127
  }
127
128
 
128
129
  async OnSet(value: CharacteristicValue): Promise<void> {
129
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} On: ${value}`);
130
+ await this.debugLog(`On: ${value}`);
130
131
 
131
132
  this.LightBulb!.On = value;
132
133
  if (this.LightBulb?.On) {
@@ -143,7 +144,7 @@ export class Light extends irdeviceBase {
143
144
  }
144
145
 
145
146
  async ProgrammableSwitchOutputStateSetOn(value: CharacteristicValue): Promise<void> {
146
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} On: ${value}`);
147
+ await this.debugLog(`On: ${value}`);
147
148
 
148
149
  this.ProgrammableSwitchOn!.ProgrammableSwitchOutputState = value;
149
150
  if (this.ProgrammableSwitchOn?.ProgrammableSwitchOutputState === 1) {
@@ -157,7 +158,7 @@ export class Light extends irdeviceBase {
157
158
  }
158
159
 
159
160
  async ProgrammableSwitchOutputStateSetOff(value: CharacteristicValue): Promise<void> {
160
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} On: ${value}`);
161
+ await this.debugLog(`On: ${value}`);
161
162
 
162
163
  this.ProgrammableSwitchOff!.ProgrammableSwitchOutputState = value;
163
164
  if (this.ProgrammableSwitchOff?.ProgrammableSwitchOutputState === 1) {
@@ -183,7 +184,7 @@ export class Light extends irdeviceBase {
183
184
  * Light - "command" "channelSub" "default" = previous channel
184
185
  */
185
186
  async pushLightOnChanges(On: boolean): Promise<void> {
186
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushLightOnChanges On: ${On}, disablePushOn: ${this.disablePushOn}`);
187
+ await this.debugLog(`pushLightOnChanges On: ${On}, disablePushOn: ${this.disablePushOn}`);
187
188
  if (On === true && this.disablePushOn === false) {
188
189
  const commandType: string = await this.commandType();
189
190
  const command: string = await this.commandOn();
@@ -197,7 +198,7 @@ export class Light extends irdeviceBase {
197
198
  }
198
199
 
199
200
  async pushLightOffChanges(On: boolean): Promise<void> {
200
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushLightOffChanges On: ${On}, disablePushOff: ${this.disablePushOff}`);
201
+ await this.debugLog(`pushLightOffChanges On: ${On}, disablePushOff: ${this.disablePushOff}`);
201
202
  if (On === false && this.disablePushOff === false) {
202
203
  const commandType: string = await this.commandType();
203
204
  const command: string = await this.commandOff();
@@ -211,9 +212,9 @@ export class Light extends irdeviceBase {
211
212
  }
212
213
 
213
214
  async pushChanges(bodyChange: any, On: boolean): Promise<void> {
214
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushChanges`);
215
+ this.debugLog('pushChanges');
215
216
  if (this.device.connectionType === 'OpenAPI') {
216
- this.infoLog(`${this.device.remoteType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${bodyChange},`);
217
+ this.infoLog(`Sending request to SwitchBot API, body: ${bodyChange},`);
217
218
  try {
218
219
  const { body, statusCode } = await this.pushChangeRequest(bodyChange);
219
220
  const deviceStatus: any = await body.json();
@@ -231,43 +232,41 @@ export class Light extends irdeviceBase {
231
232
  await this.pushChangeError(e);
232
233
  }
233
234
  } else {
234
- this.warnLog(`${this.device.remoteType}: ${this.accessory.displayName} Connection Type: `
235
+ this.warnLog('Connection Type: '
235
236
  + `${this.device.connectionType}, commands will not be sent to OpenAPI`);
236
237
  }
237
238
  }
238
239
 
239
240
  async updateHomeKitCharacteristics(): Promise<void> {
241
+ await this.debugLog('updateHomeKitCharacteristics');
240
242
  if (!this.device.irlight?.stateless) {
241
243
  // On
242
244
  if (this.LightBulb?.On === undefined) {
243
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} On: ${this.LightBulb?.On}`);
245
+ await this.debugLog(`On: ${this.LightBulb?.On}`);
244
246
  } else {
245
247
  this.accessory.context.On = this.LightBulb.On;
246
248
  this.LightBulb?.Service.updateCharacteristic(this.hap.Characteristic.On, this.LightBulb.On);
247
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic On: ${this.LightBulb.On}`);
249
+ await this.debugLog(`updateCharacteristic On: ${this.LightBulb.On}`);
248
250
  }
249
251
  } else {
250
252
  // On Stateful Programmable Switch
251
253
  if (this.ProgrammableSwitchOn?.ProgrammableSwitchOutputState === undefined) {
252
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName}`
253
- + ` ProgrammableSwitchOutputStateOn: ${this.ProgrammableSwitchOn?.ProgrammableSwitchOutputState}`);
254
+ await this.debugLog(`ProgrammableSwitchOutputStateOn: ${this.ProgrammableSwitchOn?.ProgrammableSwitchOutputState}`);
254
255
  } else {
255
256
  this.accessory.context.ProgrammableSwitchOutputStateOn = this.ProgrammableSwitchOn.ProgrammableSwitchOutputState;
256
257
  this.ProgrammableSwitchOn?.Service.updateCharacteristic(this.hap.Characteristic.ProgrammableSwitchOutputState,
257
258
  this.ProgrammableSwitchOn.ProgrammableSwitchOutputState);
258
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic`
259
+ this.debugLog('updateCharacteristic'
259
260
  + ` ProgrammableSwitchOutputStateOn: ${this.ProgrammableSwitchOn.ProgrammableSwitchOutputState}`);
260
261
  }
261
262
  // Off Stateful Programmable Switch
262
263
  if (this.ProgrammableSwitchOff?.ProgrammableSwitchOutputState === undefined) {
263
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName}`
264
- + ` ProgrammableSwitchOutputStateOff: ${this.ProgrammableSwitchOff?.ProgrammableSwitchOutputState}`);
264
+ await this.debugLog(`ProgrammableSwitchOutputStateOff: ${this.ProgrammableSwitchOff?.ProgrammableSwitchOutputState}`);
265
265
  } else {
266
266
  this.accessory.context.ProgrammableSwitchOutputStateOff = this.ProgrammableSwitchOff.ProgrammableSwitchOutputState;
267
267
  this.ProgrammableSwitchOff.Service.updateCharacteristic(this.hap.Characteristic.ProgrammableSwitchOutputState,
268
268
  this.ProgrammableSwitchOff.ProgrammableSwitchOutputState);
269
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic`
270
- + ` ProgrammableSwitchOutputStateOff: ${this.ProgrammableSwitchOff?.ProgrammableSwitchOutputState}`);
269
+ await this.debugLog(`updateCharacteristic ProgrammableSwitchOutputStateOff: ${this.ProgrammableSwitchOff?.ProgrammableSwitchOutputState}`);
271
270
  }
272
271
  }
273
272
  }