@switchbot/homebridge-switchbot 4.1.1-beta.2 → 4.1.1-beta.3

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 (96) hide show
  1. package/dist/device/blindtilt.js +102 -102
  2. package/dist/device/blindtilt.js.map +1 -1
  3. package/dist/device/bot.js +85 -85
  4. package/dist/device/bot.js.map +1 -1
  5. package/dist/device/ceilinglight.js +98 -98
  6. package/dist/device/ceilinglight.js.map +1 -1
  7. package/dist/device/colorbulb.js +140 -140
  8. package/dist/device/colorbulb.js.map +1 -1
  9. package/dist/device/contact.js +44 -44
  10. package/dist/device/contact.js.map +1 -1
  11. package/dist/device/curtain.js +82 -82
  12. package/dist/device/curtain.js.map +1 -1
  13. package/dist/device/device.d.ts +11 -11
  14. package/dist/device/device.d.ts.map +1 -1
  15. package/dist/device/device.js +41 -41
  16. package/dist/device/device.js.map +1 -1
  17. package/dist/device/fan.js +96 -96
  18. package/dist/device/fan.js.map +1 -1
  19. package/dist/device/hub.js +43 -43
  20. package/dist/device/hub.js.map +1 -1
  21. package/dist/device/humidifier.js +84 -84
  22. package/dist/device/humidifier.js.map +1 -1
  23. package/dist/device/iosensor.js +44 -44
  24. package/dist/device/iosensor.js.map +1 -1
  25. package/dist/device/lightstrip.js +119 -119
  26. package/dist/device/lightstrip.js.map +1 -1
  27. package/dist/device/lock.js +75 -75
  28. package/dist/device/lock.js.map +1 -1
  29. package/dist/device/meter.js +44 -44
  30. package/dist/device/meter.js.map +1 -1
  31. package/dist/device/meterplus.js +42 -42
  32. package/dist/device/meterplus.js.map +1 -1
  33. package/dist/device/meterpro.js +42 -42
  34. package/dist/device/meterpro.js.map +1 -1
  35. package/dist/device/motion.js +42 -42
  36. package/dist/device/motion.js.map +1 -1
  37. package/dist/device/plug.js +60 -60
  38. package/dist/device/plug.js.map +1 -1
  39. package/dist/device/robotvacuumcleaner.js +74 -74
  40. package/dist/device/robotvacuumcleaner.js.map +1 -1
  41. package/dist/device/waterdetector.js +44 -44
  42. package/dist/device/waterdetector.js.map +1 -1
  43. package/dist/irdevice/airconditioner.js +31 -31
  44. package/dist/irdevice/airconditioner.js.map +1 -1
  45. package/dist/irdevice/airpurifier.js +10 -10
  46. package/dist/irdevice/airpurifier.js.map +1 -1
  47. package/dist/irdevice/camera.js +9 -9
  48. package/dist/irdevice/camera.js.map +1 -1
  49. package/dist/irdevice/fan.js +11 -11
  50. package/dist/irdevice/fan.js.map +1 -1
  51. package/dist/irdevice/irdevice.js +11 -11
  52. package/dist/irdevice/irdevice.js.map +1 -1
  53. package/dist/irdevice/light.js +9 -9
  54. package/dist/irdevice/light.js.map +1 -1
  55. package/dist/irdevice/other.js +55 -55
  56. package/dist/irdevice/other.js.map +1 -1
  57. package/dist/irdevice/tv.js +33 -33
  58. package/dist/irdevice/tv.js.map +1 -1
  59. package/dist/irdevice/vacuumcleaner.js +9 -9
  60. package/dist/irdevice/vacuumcleaner.js.map +1 -1
  61. package/dist/irdevice/waterheater.js +9 -9
  62. package/dist/irdevice/waterheater.js.map +1 -1
  63. package/dist/platform.js +228 -228
  64. package/dist/platform.js.map +1 -1
  65. package/package.json +1 -1
  66. package/src/device/blindtilt.ts +102 -102
  67. package/src/device/bot.ts +85 -85
  68. package/src/device/ceilinglight.ts +98 -98
  69. package/src/device/colorbulb.ts +140 -140
  70. package/src/device/contact.ts +44 -44
  71. package/src/device/curtain.ts +82 -82
  72. package/src/device/device.ts +41 -41
  73. package/src/device/fan.ts +96 -96
  74. package/src/device/hub.ts +43 -43
  75. package/src/device/humidifier.ts +84 -84
  76. package/src/device/iosensor.ts +44 -44
  77. package/src/device/lightstrip.ts +119 -119
  78. package/src/device/lock.ts +75 -75
  79. package/src/device/meter.ts +44 -44
  80. package/src/device/meterplus.ts +42 -42
  81. package/src/device/meterpro.ts +42 -42
  82. package/src/device/motion.ts +42 -42
  83. package/src/device/plug.ts +60 -60
  84. package/src/device/robotvacuumcleaner.ts +74 -74
  85. package/src/device/waterdetector.ts +44 -44
  86. package/src/irdevice/airconditioner.ts +31 -31
  87. package/src/irdevice/airpurifier.ts +10 -10
  88. package/src/irdevice/camera.ts +9 -9
  89. package/src/irdevice/fan.ts +11 -11
  90. package/src/irdevice/irdevice.ts +11 -11
  91. package/src/irdevice/light.ts +9 -9
  92. package/src/irdevice/other.ts +55 -55
  93. package/src/irdevice/tv.ts +33 -33
  94. package/src/irdevice/vacuumcleaner.ts +9 -9
  95. package/src/irdevice/waterheater.ts +9 -9
  96. package/src/platform.ts +228 -228
@@ -90,7 +90,7 @@ export abstract class deviceBase {
90
90
  this.deviceLogging = this.platform.debugMode ? 'debugMode' : device.logging ?? this.config.logging ?? 'standard'
91
91
  const logging = this.platform.debugMode ? 'Debug Mode' : device.logging ? 'Device Config' : this.config.logging ? 'Platform Config' : 'Default'
92
92
  accessory.context.deviceLogging = this.deviceLogging
93
- await this.debugLog(`Using ${logging} Logging: ${this.deviceLogging}`)
93
+ this.debugLog(`Using ${logging} Logging: ${this.deviceLogging}`)
94
94
  }
95
95
 
96
96
  async getDeviceRateSettings(accessory: PlatformAccessory, device: device & devicesConfig): Promise<void> {
@@ -106,7 +106,7 @@ export abstract class deviceBase {
106
106
  this.devicePushRate = device.pushRate ?? this.config.options?.pushRate ?? 1
107
107
  accessory.context.devicePushRate = this.devicePushRate
108
108
  const pushRate = device.pushRate ? 'Device Config' : this.config.options?.pushRate ? 'Platform Config' : 'Default'
109
- await this.debugLog(`Using ${refreshRate} refreshRate: ${this.deviceRefreshRate}, ${updateRate} updateRate: ${this.deviceUpdateRate}, ${pushRate} pushRate: ${this.devicePushRate}`)
109
+ this.debugLog(`Using ${refreshRate} refreshRate: ${this.deviceRefreshRate}, ${updateRate} updateRate: ${this.deviceUpdateRate}, ${pushRate} pushRate: ${this.devicePushRate}`)
110
110
  }
111
111
 
112
112
  async getDeviceRetry(device: device & devicesConfig): Promise<void> {
@@ -114,7 +114,7 @@ export abstract class deviceBase {
114
114
  const maxRetries = device.maxRetries ? 'Device' : 'Default'
115
115
  this.deviceDelayBetweenRetries = device.delayBetweenRetries ? (device.delayBetweenRetries * 1000) : 3000
116
116
  const delayBetweenRetries = device.delayBetweenRetries ? 'Device' : 'Default'
117
- await this.debugLog(`Using ${maxRetries} Max Retries: ${this.deviceMaxRetries}, ${delayBetweenRetries} Delay Between Retries: ${this.deviceDelayBetweenRetries}`)
117
+ this.debugLog(`Using ${maxRetries} Max Retries: ${this.deviceMaxRetries}, ${delayBetweenRetries} Delay Between Retries: ${this.deviceDelayBetweenRetries}`)
118
118
  }
119
119
 
120
120
  async retryBLE({ max, fn }: { max: number, fn: { (): any, (): Promise<any> } }): Promise<null> {
@@ -122,14 +122,14 @@ export abstract class deviceBase {
122
122
  if (max === 0) {
123
123
  throw e
124
124
  }
125
- await this.warnLog(e)
126
- await this.infoLog('Retrying')
125
+ this.warnLog(e)
126
+ this.infoLog('Retrying')
127
127
  await sleep(1000)
128
128
  return this.retryBLE({ max: max - 1, fn })
129
129
  })
130
130
  }
131
131
 
132
- async maxRetryBLE(): Promise<number> {
132
+ maxRetryBLE(): number {
133
133
  return this.device.maxRetry ? this.device.maxRetry : 5
134
134
  }
135
135
 
@@ -261,7 +261,7 @@ export abstract class deviceBase {
261
261
  : lightLevel === numberOfLevels
262
262
  ? set_maxLux
263
263
  : ((set_maxLux - set_minLux) / spaceBetweenLevels) * (Number(lightLevel) - 1)
264
- await this.debugLog(`CurrentAmbientLightLevel: ${CurrentAmbientLightLevel}, LightLevel: ${lightLevel}, set_minLux: ${set_minLux}, set_maxLux: ${set_maxLux}`)
264
+ this.debugLog(`CurrentAmbientLightLevel: ${CurrentAmbientLightLevel}, LightLevel: ${lightLevel}, set_minLux: ${set_minLux}, set_maxLux: ${set_maxLux}`)
265
265
  return CurrentAmbientLightLevel
266
266
  }
267
267
 
@@ -291,7 +291,7 @@ export abstract class deviceBase {
291
291
  // mqttPubOptions
292
292
  this.deviceMqttPubOptions = device.mqttPubOptions ?? this.config.options?.mqttPubOptions ?? {}
293
293
  const mqttPubOptions = device.mqttPubOptions ? 'Device Config' : this.config.options?.mqttPubOptions ? 'Platform Config' : 'Default'
294
- await this.debugLog(`Using ${mqttURL} MQTT URL: ${this.deviceMqttURL}, ${mqttOptions} mqttOptions: ${JSON.stringify(this.deviceMqttOptions)}, ${mqttPubOptions} mqttPubOptions: ${JSON.stringify(this.deviceMqttPubOptions)}`)
294
+ this.debugLog(`Using ${mqttURL} MQTT URL: ${this.deviceMqttURL}, ${mqttOptions} mqttOptions: ${JSON.stringify(this.deviceMqttOptions)}, ${mqttPubOptions} mqttPubOptions: ${JSON.stringify(this.deviceMqttPubOptions)}`)
295
295
  }
296
296
 
297
297
  /*
@@ -301,7 +301,7 @@ export abstract class deviceBase {
301
301
  try {
302
302
  const formattedDeviceId = formatDeviceIdAsMac(this.device.deviceId)
303
303
  this.device.bleMac = formattedDeviceId
304
- await this.debugLog(`bleMac: ${this.device.bleMac}`)
304
+ this.debugLog(`bleMac: ${this.device.bleMac}`)
305
305
  this.historyService = device.history
306
306
  ? new this.platform.fakegatoAPI('room', accessory, {
307
307
  log: this.platform.log,
@@ -310,7 +310,7 @@ export abstract class deviceBase {
310
310
  })
311
311
  : null
312
312
  } catch (error) {
313
- await this.errorLog(`failed to format device ID as MAC, Error: ${error}`)
313
+ this.errorLog(`failed to format device ID as MAC, Error: ${error}`)
314
314
  }
315
315
  }
316
316
 
@@ -320,24 +320,24 @@ export abstract class deviceBase {
320
320
  try {
321
321
  const formattedDeviceId = formatDeviceIdAsMac(this.device.deviceId)
322
322
  this.device.bleMac = formattedDeviceId
323
- await this.debugLog(`bleMac: ${this.device.bleMac}`)
324
323
  await this.getCustomBLEAddress(switchBotBLE)
324
+ this.debugLog(`bleMac: ${this.device.bleMac}`)
325
325
  return switchBotBLE
326
326
  } catch (error) {
327
- await this.errorLog(`failed to format device ID as MAC, Error: ${error}`)
327
+ this.errorLog(`failed to format device ID as MAC, Error: ${error}`)
328
328
  }
329
329
  }
330
330
 
331
331
  async monitorAdvertisementPackets(switchbot: any) {
332
- await this.debugLog(`Scanning for ${this.device.bleModelName} devices...`)
332
+ this.debugLog(`Scanning for ${this.device.bleModelName} devices...`)
333
333
  try {
334
334
  await switchbot.startScan({ model: this.device.bleModel, id: this.device.bleMac })
335
335
  } catch (e: any) {
336
- await this.errorLog(`Failed to start BLE scanning. Error:${e.message ?? e}`)
336
+ this.errorLog(`Failed to start BLE scanning. Error:${e.message ?? e}`)
337
337
  }
338
338
  // Set an event handler
339
339
  let serviceData = { model: this.device.bleModel, modelName: this.device.bleModelName } as ad['serviceData']
340
- switchbot.onadvertisement = async (ad: ad) => {
340
+ switchbot.onadvertisement = (ad: ad) => {
341
341
  if (this.device.bleMac === ad.address && ad.serviceData.model === this.device.bleModel) {
342
342
  this.debugLog(`${JSON.stringify(ad, null, ' ')}`)
343
343
  this.debugLog(`address: ${ad.address}, model: ${ad.serviceData.model}`)
@@ -351,7 +351,7 @@ export abstract class deviceBase {
351
351
  try {
352
352
  await switchbot.stopScan()
353
353
  } catch (e: any) {
354
- await this.errorLog(`Failed to stop BLE scanning. Error:${e.message ?? e}`)
354
+ this.errorLog(`Failed to stop BLE scanning. Error:${e.message ?? e}`)
355
355
  }
356
356
  return serviceData
357
357
  }
@@ -364,10 +364,10 @@ export abstract class deviceBase {
364
364
  try {
365
365
  await switchbot.startScan({ model: this.device.bleModel })
366
366
  } catch (e: any) {
367
- await this.errorLog(`Failed to start BLE scanning. Error:${e.message ?? e}`)
367
+ this.errorLog(`Failed to start BLE scanning. Error:${e.message ?? e}`)
368
368
  }
369
369
  // Set an event handler
370
- switchbot.onadvertisement = async (ad: ad) => {
370
+ switchbot.onadvertisement = (ad: ad) => {
371
371
  this.warnLog(`ad: ${JSON.stringify(ad, null, ' ')}`)
372
372
  }
373
373
  await sleep(10000)
@@ -375,7 +375,7 @@ export abstract class deviceBase {
375
375
  try {
376
376
  switchbot.stopScan()
377
377
  } catch (e: any) {
378
- await this.errorLog(`Failed to stop BLE scanning. Error:${e.message ?? e}`)
378
+ this.errorLog(`Failed to stop BLE scanning. Error:${e.message ?? e}`)
379
379
  }
380
380
  })()
381
381
  }
@@ -676,7 +676,7 @@ export abstract class deviceBase {
676
676
  device.bleModel = deviceConfig.bleModel
677
677
  device.bleModelName = deviceConfig.bleModelName
678
678
  device.bleModelFriednlyName = deviceConfig.bleModelFriednlyName
679
- await this.debugLog(`Model: ${device.model}, BLE Model: ${device.bleModel}, BLE Model Name: ${device.bleModelName}, BLE Model Friendly Name: ${device.bleModelFriednlyName}`)
679
+ this.debugLog(`Model: ${device.model}, BLE Model: ${device.bleModel}, BLE Model Name: ${device.bleModelName}, BLE Model Friendly Name: ${device.bleModelFriednlyName}`)
680
680
 
681
681
  const deviceFirmwareVersion = device.firmware ?? device.version ?? accessory.context.version ?? this.platform.version ?? '0.0.0'
682
682
  const version = deviceFirmwareVersion.toString()
@@ -733,56 +733,56 @@ export abstract class deviceBase {
733
733
  /**
734
734
  * Logging for Device
735
735
  */
736
- async infoLog(...log: any[]): Promise<void> {
737
- if (await this.enablingDeviceLogging()) {
736
+ infoLog(...log: any[]): void {
737
+ if (this.enablingDeviceLogging()) {
738
738
  this.log.info(`${this.device.deviceType}: ${this.accessory.displayName}`, String(...log))
739
739
  }
740
740
  }
741
741
 
742
- async successLog(...log: any[]): Promise<void> {
743
- if (await this.enablingDeviceLogging()) {
742
+ successLog(...log: any[]): void {
743
+ if (this.enablingDeviceLogging()) {
744
744
  this.log.success(`${this.device.deviceType}: ${this.accessory.displayName}`, String(...log))
745
745
  }
746
746
  }
747
747
 
748
- async debugSuccessLog(...log: any[]): Promise<void> {
749
- if (await this.enablingDeviceLogging()) {
750
- if (await this.loggingIsDebug()) {
748
+ debugSuccessLog(...log: any[]): void {
749
+ if (this.enablingDeviceLogging()) {
750
+ if (this.loggingIsDebug()) {
751
751
  this.log.success(`[DEBUG] ${this.device.deviceType}: ${this.accessory.displayName}`, String(...log))
752
752
  }
753
753
  }
754
754
  }
755
755
 
756
- async warnLog(...log: any[]): Promise<void> {
757
- if (await this.enablingDeviceLogging()) {
756
+ warnLog(...log: any[]): void {
757
+ if (this.enablingDeviceLogging()) {
758
758
  this.log.warn(`${this.device.deviceType}: ${this.accessory.displayName}`, String(...log))
759
759
  }
760
760
  }
761
761
 
762
- async debugWarnLog(...log: any[]): Promise<void> {
763
- if (await this.enablingDeviceLogging()) {
764
- if (await this.loggingIsDebug()) {
762
+ debugWarnLog(...log: any[]): void {
763
+ if (this.enablingDeviceLogging()) {
764
+ if (this.loggingIsDebug()) {
765
765
  this.log.warn(`[DEBUG] ${this.device.deviceType}: ${this.accessory.displayName}`, String(...log))
766
766
  }
767
767
  }
768
768
  }
769
769
 
770
- async errorLog(...log: any[]): Promise<void> {
771
- if (await this.enablingDeviceLogging()) {
770
+ errorLog(...log: any[]): void {
771
+ if (this.enablingDeviceLogging()) {
772
772
  this.log.error(`${this.device.deviceType}: ${this.accessory.displayName}`, String(...log))
773
773
  }
774
774
  }
775
775
 
776
- async debugErrorLog(...log: any[]): Promise<void> {
777
- if (await this.enablingDeviceLogging()) {
778
- if (await this.loggingIsDebug()) {
776
+ debugErrorLog(...log: any[]): void {
777
+ if (this.enablingDeviceLogging()) {
778
+ if (this.loggingIsDebug()) {
779
779
  this.log.error(`[DEBUG] ${this.device.deviceType}: ${this.accessory.displayName}`, String(...log))
780
780
  }
781
781
  }
782
782
  }
783
783
 
784
- async debugLog(...log: any[]): Promise<void> {
785
- if (await this.enablingDeviceLogging()) {
784
+ debugLog(...log: any[]): void {
785
+ if (this.enablingDeviceLogging()) {
786
786
  if (this.deviceLogging === 'debug') {
787
787
  this.log.info(`[DEBUG] ${this.device.deviceType}: ${this.accessory.displayName}`, String(...log))
788
788
  } else if (this.deviceLogging === 'debugMode') {
@@ -791,11 +791,11 @@ export abstract class deviceBase {
791
791
  }
792
792
  }
793
793
 
794
- async loggingIsDebug(): Promise<boolean> {
794
+ loggingIsDebug(): boolean {
795
795
  return this.deviceLogging === 'debugMode' || this.deviceLogging === 'debug'
796
796
  }
797
797
 
798
- async enablingDeviceLogging(): Promise<boolean> {
798
+ enablingDeviceLogging(): boolean {
799
799
  return this.deviceLogging === 'debugMode' || this.deviceLogging === 'debug' || this.deviceLogging === 'standard'
800
800
  }
801
801
  }