@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
package/src/device/hub.ts CHANGED
@@ -174,19 +174,19 @@ export class Hub extends deviceBase {
174
174
  }
175
175
 
176
176
  async BLEparseStatus(): Promise<void> {
177
- await this.debugLog('BLEparseStatus')
178
- await this.debugLog(`(temperature, humidity, lightLevel) = BLE:(${this.serviceData.celsius}, ${this.serviceData.humidity}, ${this.serviceData.lightLevel}), current:(${this.TemperatureSensor?.CurrentTemperature}, ${this.HumiditySensor?.CurrentRelativeHumidity}, ${this.LightSensor?.CurrentAmbientLightLevel})`)
177
+ this.debugLog('BLEparseStatus')
178
+ this.debugLog(`(temperature, humidity, lightLevel) = BLE:(${this.serviceData.celsius}, ${this.serviceData.humidity}, ${this.serviceData.lightLevel}), current:(${this.TemperatureSensor?.CurrentTemperature}, ${this.HumiditySensor?.CurrentRelativeHumidity}, ${this.LightSensor?.CurrentAmbientLightLevel})`)
179
179
 
180
180
  // CurrentTemperature
181
181
  if (!(this.device as hubConfig).hide_temperature && this.TemperatureSensor?.Service) {
182
182
  this.TemperatureSensor.CurrentTemperature = this.serviceData.celsius
183
- await this.debugLog(`CurrentTemperature: ${this.TemperatureSensor.CurrentTemperature}°c`)
183
+ this.debugLog(`CurrentTemperature: ${this.TemperatureSensor.CurrentTemperature}°c`)
184
184
  }
185
185
 
186
186
  // CurrentRelativeHumidity
187
187
  if (!(this.device as hubConfig).hide_humidity && this.HumiditySensor?.Service) {
188
188
  this.HumiditySensor!.CurrentRelativeHumidity = validHumidity(this.serviceData.humidity, 0, 100)
189
- await this.debugLog(`CurrentRelativeHumidity: ${this.HumiditySensor.CurrentRelativeHumidity}%`)
189
+ this.debugLog(`CurrentRelativeHumidity: ${this.HumiditySensor.CurrentRelativeHumidity}%`)
190
190
  }
191
191
 
192
192
  // CurrentAmbientLightLevel
@@ -195,24 +195,24 @@ export class Hub extends deviceBase {
195
195
  const set_maxLux = (this.device as hubConfig).set_maxLux ?? 6001
196
196
  const lightLevel = this.serviceData.lightLevel
197
197
  this.LightSensor.CurrentAmbientLightLevel = await this.getLightLevel(lightLevel, set_minLux, set_maxLux, 19)
198
- await this.debugLog(`LightLevel: ${this.serviceData.lightLevel}, CurrentAmbientLightLevel: ${this.LightSensor.CurrentAmbientLightLevel}`)
198
+ this.debugLog(`LightLevel: ${this.serviceData.lightLevel}, CurrentAmbientLightLevel: ${this.LightSensor.CurrentAmbientLightLevel}`)
199
199
  }
200
200
  }
201
201
 
202
202
  async openAPIparseStatus(): Promise<void> {
203
- await this.debugLog('openAPIparseStatus')
204
- await this.debugLog(`(temperature, humidity, lightLevel) = OpenAPI:(${this.deviceStatus.temperature}, ${this.deviceStatus.humidity}, ${this.deviceStatus.lightLevel}), current:(${this.TemperatureSensor?.CurrentTemperature}, ${this.HumiditySensor?.CurrentRelativeHumidity}, ${this.LightSensor?.CurrentAmbientLightLevel})`)
203
+ this.debugLog('openAPIparseStatus')
204
+ this.debugLog(`(temperature, humidity, lightLevel) = OpenAPI:(${this.deviceStatus.temperature}, ${this.deviceStatus.humidity}, ${this.deviceStatus.lightLevel}), current:(${this.TemperatureSensor?.CurrentTemperature}, ${this.HumiditySensor?.CurrentRelativeHumidity}, ${this.LightSensor?.CurrentAmbientLightLevel})`)
205
205
 
206
206
  // CurrentRelativeHumidity
207
207
  if (!(this.device as hubConfig).hide_humidity && this.HumiditySensor?.Service) {
208
208
  this.HumiditySensor.CurrentRelativeHumidity = this.deviceStatus.humidity
209
- await this.debugLog(`CurrentRelativeHumidity: ${this.HumiditySensor.CurrentRelativeHumidity}%`)
209
+ this.debugLog(`CurrentRelativeHumidity: ${this.HumiditySensor.CurrentRelativeHumidity}%`)
210
210
  }
211
211
 
212
212
  // CurrentTemperature
213
213
  if (!(this.device as hubConfig).hide_temperature && this.TemperatureSensor?.Service) {
214
214
  this.TemperatureSensor.CurrentTemperature = this.deviceStatus.temperature
215
- await this.debugLog(`CurrentTemperature: ${this.TemperatureSensor.CurrentTemperature}°c`)
215
+ this.debugLog(`CurrentTemperature: ${this.TemperatureSensor.CurrentTemperature}°c`)
216
216
  }
217
217
 
218
218
  // LightSensor
@@ -221,13 +221,13 @@ export class Hub extends deviceBase {
221
221
  const set_maxLux = (this.device as hubConfig).set_maxLux ?? 6001
222
222
  const lightLevel = this.deviceStatus.lightLevel
223
223
  this.LightSensor.CurrentAmbientLightLevel = await this.getLightLevel(lightLevel, set_minLux, set_maxLux, 19)
224
- await this.debugLog(`LightLevel: ${this.deviceStatus.lightLevel}, CurrentAmbientLightLevel: ${this.LightSensor!.CurrentAmbientLightLevel}`)
224
+ this.debugLog(`LightLevel: ${this.deviceStatus.lightLevel}, CurrentAmbientLightLevel: ${this.LightSensor!.CurrentAmbientLightLevel}`)
225
225
  }
226
226
 
227
227
  // Firmware Version
228
228
  if (this.deviceStatus.version) {
229
229
  const version = this.deviceStatus.version.toString()
230
- await this.debugLog(`Firmware Version: ${version.replace(/^V|-.*$/g, '')}`)
230
+ this.debugLog(`Firmware Version: ${version.replace(/^V|-.*$/g, '')}`)
231
231
  const deviceVersion = version.replace(/^V|-.*$/g, '') ?? '0.0.0'
232
232
  this.accessory
233
233
  .getService(this.hap.Service.AccessoryInformation)!
@@ -236,28 +236,28 @@ export class Hub extends deviceBase {
236
236
  .getCharacteristic(this.hap.Characteristic.FirmwareRevision)
237
237
  .updateValue(deviceVersion)
238
238
  this.accessory.context.version = deviceVersion
239
- await this.debugSuccessLog(`version: ${this.accessory.context.version}`)
239
+ this.debugSuccessLog(`version: ${this.accessory.context.version}`)
240
240
  }
241
241
  }
242
242
 
243
243
  async parseStatusWebhook(): Promise<void> {
244
- await this.debugLog('parseStatusWebhook')
245
- await this.debugLog(`(scale, temperature, humidity, lightLevel) = Webhook:(${this.webhookContext.scale}, ${convertUnits(this.webhookContext.temperature, this.webhookContext.scale, (this.device as hubConfig).convertUnitTo)}, ${this.webhookContext.humidity}, ${this.webhookContext.lightLevel}), current:(${this.TemperatureSensor?.CurrentTemperature}, ${this.HumiditySensor?.CurrentRelativeHumidity}, ${this.LightSensor?.CurrentAmbientLightLevel})`)
244
+ this.debugLog('parseStatusWebhook')
245
+ this.debugLog(`(scale, temperature, humidity, lightLevel) = Webhook:(${this.webhookContext.scale}, ${convertUnits(this.webhookContext.temperature, this.webhookContext.scale, (this.device as hubConfig).convertUnitTo)}, ${this.webhookContext.humidity}, ${this.webhookContext.lightLevel}), current:(${this.TemperatureSensor?.CurrentTemperature}, ${this.HumiditySensor?.CurrentRelativeHumidity}, ${this.LightSensor?.CurrentAmbientLightLevel})`)
246
246
  // Check if the scale is not CELSIUS
247
247
  if (this.webhookContext.scale !== 'CELSIUS' && (this.device as hubConfig).convertUnitTo === undefined) {
248
- await this.warnLog(`received a non-CELSIUS Webhook scale: ${this.webhookContext.scale}, Use the *convertUnitsTo* config under Hub settings, if displaying incorrectly in HomeKit.`)
248
+ this.warnLog(`received a non-CELSIUS Webhook scale: ${this.webhookContext.scale}, Use the *convertUnitsTo* config under Hub settings, if displaying incorrectly in HomeKit.`)
249
249
  }
250
250
 
251
251
  // CurrentRelativeHumidity
252
252
  if (!(this.device as hubConfig).hide_humidity && this.HumiditySensor?.Service) {
253
253
  this.HumiditySensor.CurrentRelativeHumidity = this.webhookContext.humidity
254
- await this.debugLog(`CurrentRelativeHumidity: ${this.HumiditySensor.CurrentRelativeHumidity}`)
254
+ this.debugLog(`CurrentRelativeHumidity: ${this.HumiditySensor.CurrentRelativeHumidity}`)
255
255
  }
256
256
 
257
257
  // CurrentTemperature
258
258
  if (!(this.device as hubConfig).hide_temperature && this.TemperatureSensor?.Service) {
259
259
  this.TemperatureSensor.CurrentTemperature = convertUnits(this.webhookContext.temperature, this.webhookContext.scale, (this.device as hubConfig).convertUnitTo)
260
- await this.debugLog(`CurrentTemperature: ${this.TemperatureSensor.CurrentTemperature}`)
260
+ this.debugLog(`CurrentTemperature: ${this.TemperatureSensor.CurrentTemperature}`)
261
261
  }
262
262
 
263
263
  // CurrentAmbientLightLevel
@@ -265,7 +265,7 @@ export class Hub extends deviceBase {
265
265
  const set_minLux = (this.device as hubConfig).set_minLux ?? 1
266
266
  const set_maxLux = (this.device as hubConfig).set_maxLux ?? 6001
267
267
  this.LightSensor.CurrentAmbientLightLevel = await this.getLightLevel(this.webhookContext.lightLevel, set_minLux, set_maxLux, 19)
268
- await this.debugLog(`CurrentAmbientLightLevel: ${this.LightSensor.CurrentAmbientLightLevel}`)
268
+ this.debugLog(`CurrentAmbientLightLevel: ${this.LightSensor.CurrentAmbientLightLevel}`)
269
269
  }
270
270
  }
271
271
 
@@ -274,19 +274,19 @@ export class Hub extends deviceBase {
274
274
  */
275
275
  async refreshStatus(): Promise<void> {
276
276
  if (!this.device.enableCloudService && this.OpenAPI) {
277
- await this.errorLog(`refreshStatus enableCloudService: ${this.device.enableCloudService}`)
277
+ this.errorLog(`refreshStatus enableCloudService: ${this.device.enableCloudService}`)
278
278
  } else if (this.BLE) {
279
279
  await this.BLERefreshStatus()
280
280
  } else if (this.OpenAPI && this.platform.config.credentials?.token) {
281
281
  await this.openAPIRefreshStatus()
282
282
  } else {
283
283
  await this.offlineOff()
284
- await this.debugWarnLog(`Connection Type: ${this.device.connectionType}, refreshStatus will not happen.`)
284
+ this.debugWarnLog(`Connection Type: ${this.device.connectionType}, refreshStatus will not happen.`)
285
285
  }
286
286
  }
287
287
 
288
288
  async BLERefreshStatus(): Promise<void> {
289
- await this.debugLog('BLERefreshStatus')
289
+ this.debugLog('BLERefreshStatus')
290
290
  const switchBotBLE = await this.switchbotBLE()
291
291
  if (switchBotBLE === undefined) {
292
292
  await this.BLERefreshConnection(switchBotBLE)
@@ -301,7 +301,7 @@ export class Hub extends deviceBase {
301
301
  await this.BLEparseStatus()
302
302
  await this.updateHomeKitCharacteristics()
303
303
  } else {
304
- await this.errorLog(`failed to get serviceData, serviceData: ${JSON.stringify(serviceData)}`)
304
+ this.errorLog(`failed to get serviceData, serviceData: ${JSON.stringify(serviceData)}`)
305
305
  await this.BLERefreshConnection(switchBotBLE)
306
306
  }
307
307
  })()
@@ -309,67 +309,67 @@ export class Hub extends deviceBase {
309
309
  }
310
310
 
311
311
  async registerPlatformBLE(): Promise<void> {
312
- await this.debugLog('registerPlatformBLE')
312
+ this.debugLog('registerPlatformBLE')
313
313
  if (this.config.options?.BLE) {
314
- await this.debugLog('is listening to Platform BLE.')
314
+ this.debugLog('is listening to Platform BLE.')
315
315
  try {
316
316
  const formattedDeviceId = formatDeviceIdAsMac(this.device.deviceId)
317
317
  this.device.bleMac = formattedDeviceId
318
- await this.debugLog(`bleMac: ${this.device.bleMac}`)
318
+ this.debugLog(`bleMac: ${this.device.bleMac}`)
319
319
  this.platform.bleEventHandler[this.device.bleMac] = async (context: hub2ServiceData) => {
320
320
  try {
321
- await this.debugLog(`received BLE: ${JSON.stringify(context)}`)
321
+ this.debugLog(`received BLE: ${JSON.stringify(context)}`)
322
322
  this.serviceData = context
323
323
  await this.BLEparseStatus()
324
324
  await this.updateHomeKitCharacteristics()
325
325
  } catch (e: any) {
326
- await this.errorLog(`failed to handle BLE. Received: ${JSON.stringify(context)} Error: ${e.message ?? e}`)
326
+ this.errorLog(`failed to handle BLE. Received: ${JSON.stringify(context)} Error: ${e.message ?? e}`)
327
327
  }
328
328
  }
329
329
  } catch (error) {
330
- await this.errorLog(`failed to format device ID as MAC, Error: ${error}`)
330
+ this.errorLog(`failed to format device ID as MAC, Error: ${error}`)
331
331
  }
332
332
  } else {
333
- await this.debugLog('is not listening to Platform BLE')
333
+ this.debugLog('is not listening to Platform BLE')
334
334
  }
335
335
  }
336
336
 
337
337
  async openAPIRefreshStatus(): Promise<void> {
338
- await this.debugLog('openAPIRefreshStatus')
338
+ this.debugLog('openAPIRefreshStatus')
339
339
  try {
340
- const { body } = await this.deviceRefreshStatus()
341
- const deviceStatus: any = await body
342
- await this.debugLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
340
+ const response = await this.deviceRefreshStatus()
341
+ const deviceStatus: any = response.body
342
+ this.debugLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
343
343
  if (await this.successfulStatusCodes(deviceStatus)) {
344
- await this.debugSuccessLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
344
+ this.debugSuccessLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
345
345
  this.deviceStatus = deviceStatus.body
346
346
  await this.openAPIparseStatus()
347
347
  await this.updateHomeKitCharacteristics()
348
348
  } else {
349
- await this.debugWarnLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
350
- await this.debugWarnLog(deviceStatus)
349
+ this.debugWarnLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
350
+ this.debugWarnLog(deviceStatus)
351
351
  }
352
352
  } catch (e: any) {
353
353
  await this.apiError(e)
354
- await this.errorLog(`failed openAPIRefreshStatus with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`)
354
+ this.errorLog(`failed openAPIRefreshStatus with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`)
355
355
  }
356
356
  }
357
357
 
358
358
  async registerWebhook(): Promise<void> {
359
359
  if (this.device.webhook) {
360
- await this.debugLog('is listening webhook.')
360
+ this.debugLog('is listening webhook.')
361
361
  this.platform.webhookEventHandler[this.device.deviceId] = async (context: hub2WebhookContext) => {
362
362
  try {
363
- await this.debugLog(`received Webhook: ${JSON.stringify(context)}`)
363
+ this.debugLog(`received Webhook: ${JSON.stringify(context)}`)
364
364
  this.webhookContext = context
365
365
  await this.parseStatusWebhook()
366
366
  await this.updateHomeKitCharacteristics()
367
367
  } catch (e: any) {
368
- await this.errorLog(`failed to handle webhook. Received: ${JSON.stringify(context)} Error: ${e.message ?? e}`)
368
+ this.errorLog(`failed to handle webhook. Received: ${JSON.stringify(context)} Error: ${e.message ?? e}`)
369
369
  }
370
370
  }
371
371
  } else {
372
- await this.debugLog('is not listening webhook.')
372
+ this.debugLog('is not listening webhook.')
373
373
  }
374
374
  }
375
375
 
@@ -393,9 +393,9 @@ export class Hub extends deviceBase {
393
393
  }
394
394
 
395
395
  async BLERefreshConnection(switchbot: any): Promise<void> {
396
- await this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${switchbot}`)
396
+ this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${switchbot}`)
397
397
  if (this.platform.config.credentials?.token && this.device.connectionType === 'BLE/OpenAPI') {
398
- await this.warnLog('Using OpenAPI Connection to Refresh Status')
398
+ this.warnLog('Using OpenAPI Connection to Refresh Status')
399
399
  await this.openAPIRefreshStatus()
400
400
  }
401
401
  }