@switchbot/homebridge-switchbot 4.3.2-beta.3 → 4.3.2-beta.5

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 (97) hide show
  1. package/dist/device/airpurifier.d.ts +54 -0
  2. package/dist/device/airpurifier.d.ts.map +1 -0
  3. package/dist/device/airpurifier.js +527 -0
  4. package/dist/device/airpurifier.js.map +1 -0
  5. package/dist/device/blindtilt.d.ts.map +1 -1
  6. package/dist/device/blindtilt.js +2 -8
  7. package/dist/device/blindtilt.js.map +1 -1
  8. package/dist/device/bot.d.ts.map +1 -1
  9. package/dist/device/bot.js +2 -8
  10. package/dist/device/bot.js.map +1 -1
  11. package/dist/device/ceilinglight.d.ts.map +1 -1
  12. package/dist/device/ceilinglight.js +2 -8
  13. package/dist/device/ceilinglight.js.map +1 -1
  14. package/dist/device/colorbulb.d.ts.map +1 -1
  15. package/dist/device/colorbulb.js +2 -8
  16. package/dist/device/colorbulb.js.map +1 -1
  17. package/dist/device/contact.d.ts.map +1 -1
  18. package/dist/device/contact.js +1 -4
  19. package/dist/device/contact.js.map +1 -1
  20. package/dist/device/curtain.d.ts.map +1 -1
  21. package/dist/device/curtain.js +2 -8
  22. package/dist/device/curtain.js.map +1 -1
  23. package/dist/device/fan.d.ts.map +1 -1
  24. package/dist/device/fan.js +2 -8
  25. package/dist/device/fan.js.map +1 -1
  26. package/dist/device/hub.d.ts.map +1 -1
  27. package/dist/device/hub.js +1 -4
  28. package/dist/device/hub.js.map +1 -1
  29. package/dist/device/humidifier.d.ts.map +1 -1
  30. package/dist/device/humidifier.js +2 -8
  31. package/dist/device/humidifier.js.map +1 -1
  32. package/dist/device/iosensor.d.ts.map +1 -1
  33. package/dist/device/iosensor.js +1 -4
  34. package/dist/device/iosensor.js.map +1 -1
  35. package/dist/device/lightstrip.d.ts.map +1 -1
  36. package/dist/device/lightstrip.js +2 -8
  37. package/dist/device/lightstrip.js.map +1 -1
  38. package/dist/device/lock.d.ts.map +1 -1
  39. package/dist/device/lock.js +2 -8
  40. package/dist/device/lock.js.map +1 -1
  41. package/dist/device/meter.d.ts.map +1 -1
  42. package/dist/device/meter.js +1 -4
  43. package/dist/device/meter.js.map +1 -1
  44. package/dist/device/meterplus.d.ts.map +1 -1
  45. package/dist/device/meterplus.js +1 -4
  46. package/dist/device/meterplus.js.map +1 -1
  47. package/dist/device/meterpro.d.ts.map +1 -1
  48. package/dist/device/meterpro.js +1 -4
  49. package/dist/device/meterpro.js.map +1 -1
  50. package/dist/device/motion.d.ts.map +1 -1
  51. package/dist/device/motion.js +1 -4
  52. package/dist/device/motion.js.map +1 -1
  53. package/dist/device/plug.d.ts.map +1 -1
  54. package/dist/device/plug.js +2 -8
  55. package/dist/device/plug.js.map +1 -1
  56. package/dist/device/relayswitch.d.ts.map +1 -1
  57. package/dist/device/relayswitch.js +2 -8
  58. package/dist/device/relayswitch.js.map +1 -1
  59. package/dist/device/robotvacuumcleaner.d.ts.map +1 -1
  60. package/dist/device/robotvacuumcleaner.js +2 -8
  61. package/dist/device/robotvacuumcleaner.js.map +1 -1
  62. package/dist/device/waterdetector.d.ts.map +1 -1
  63. package/dist/device/waterdetector.js +1 -4
  64. package/dist/device/waterdetector.js.map +1 -1
  65. package/dist/irdevice/airpurifier.d.ts +1 -1
  66. package/dist/irdevice/airpurifier.d.ts.map +1 -1
  67. package/dist/irdevice/airpurifier.js +4 -4
  68. package/dist/irdevice/airpurifier.js.map +1 -1
  69. package/dist/platform.d.ts +2 -1
  70. package/dist/platform.d.ts.map +1 -1
  71. package/dist/platform.js +71 -7
  72. package/dist/platform.js.map +1 -1
  73. package/docs/variables/default.html +1 -1
  74. package/package.json +2 -2
  75. package/src/device/airpurifier.ts +563 -0
  76. package/src/device/blindtilt.ts +2 -6
  77. package/src/device/bot.ts +2 -6
  78. package/src/device/ceilinglight.ts +2 -6
  79. package/src/device/colorbulb.ts +2 -6
  80. package/src/device/contact.ts +1 -3
  81. package/src/device/curtain.ts +2 -6
  82. package/src/device/fan.ts +2 -6
  83. package/src/device/hub.ts +1 -3
  84. package/src/device/humidifier.ts +2 -6
  85. package/src/device/iosensor.ts +1 -3
  86. package/src/device/lightstrip.ts +2 -6
  87. package/src/device/lock.ts +2 -6
  88. package/src/device/meter.ts +1 -3
  89. package/src/device/meterplus.ts +1 -3
  90. package/src/device/meterpro.ts +1 -3
  91. package/src/device/motion.ts +1 -3
  92. package/src/device/plug.ts +2 -6
  93. package/src/device/relayswitch.ts +2 -6
  94. package/src/device/robotvacuumcleaner.ts +2 -6
  95. package/src/device/waterdetector.ts +1 -3
  96. package/src/irdevice/airpurifier.ts +4 -4
  97. package/src/platform.ts +73 -7
@@ -269,9 +269,7 @@ export class CeilingLight extends deviceBase {
269
269
  * Asks the SwitchBot API for the latest device information
270
270
  */
271
271
  async refreshStatus(): Promise<void> {
272
- if (!this.device.enableCloudService && this.OpenAPI) {
273
- this.errorLog(`refreshStatus enableCloudService: ${this.device.enableCloudService}`)
274
- } else if (this.BLE) {
272
+ if (this.BLE) {
275
273
  await this.BLERefreshStatus()
276
274
  } else if (this.OpenAPI && this.platform.config.credentials?.token) {
277
275
  await this.openAPIRefreshStatus()
@@ -392,9 +390,7 @@ export class CeilingLight extends deviceBase {
392
390
  *
393
391
  */
394
392
  async pushChanges(): Promise<void> {
395
- if (!this.device.enableCloudService && this.OpenAPI) {
396
- this.errorLog(`pushChanges enableCloudService: ${this.device.enableCloudService}`)
397
- } else if (this.BLE) {
393
+ if (this.BLE) {
398
394
  await this.BLEpushChanges()
399
395
  } else if (this.OpenAPI && this.platform.config.credentials?.token) {
400
396
  await this.openAPIpushChanges()
@@ -303,9 +303,7 @@ export class ColorBulb extends deviceBase {
303
303
  * Asks the SwitchBot API for the latest device information
304
304
  */
305
305
  async refreshStatus(): Promise<void> {
306
- if (!this.device.enableCloudService && this.OpenAPI) {
307
- this.errorLog(`refreshStatus enableCloudService: ${this.device.enableCloudService}`)
308
- } else if (this.BLE) {
306
+ if (this.BLE) {
309
307
  await this.BLERefreshStatus()
310
308
  } else if (this.OpenAPI && this.platform.config.credentials?.token) {
311
309
  await this.openAPIRefreshStatus()
@@ -427,9 +425,7 @@ export class ColorBulb extends deviceBase {
427
425
  *
428
426
  */
429
427
  async pushChanges(): Promise<void> {
430
- if (!this.device.enableCloudService && this.OpenAPI) {
431
- this.errorLog(`pushChanges enableCloudService: ${this.device.enableCloudService}`)
432
- } else if (this.BLE) {
428
+ if (this.BLE) {
433
429
  await this.BLEpushChanges()
434
430
  if (this.LightBulb.On) {
435
431
  // Push Brightness Update
@@ -284,9 +284,7 @@ export class Contact extends deviceBase {
284
284
  * Asks the SwitchBot API for the latest device information
285
285
  */
286
286
  async refreshStatus(): Promise<void> {
287
- if (!this.device.enableCloudService && this.OpenAPI) {
288
- this.errorLog(`refreshStatus enableCloudService: ${this.device.enableCloudService}`)
289
- } else if (this.BLE) {
287
+ if (this.BLE) {
290
288
  await this.BLERefreshStatus()
291
289
  } else if (this.OpenAPI && this.platform.config.credentials?.token) {
292
290
  await this.openAPIRefreshStatus()
@@ -468,9 +468,7 @@ export class Curtain extends deviceBase {
468
468
  * Asks the SwitchBot API for the latest device information
469
469
  */
470
470
  async refreshStatus(): Promise<void> {
471
- if (!this.device.enableCloudService && this.OpenAPI) {
472
- this.errorLog(`refreshStatus enableCloudService: ${this.device.enableCloudService}`)
473
- } else if (this.BLE) {
471
+ if (this.BLE) {
474
472
  await this.BLERefreshStatus()
475
473
  } else if (this.OpenAPI && this.platform.config.credentials?.token) {
476
474
  await this.openAPIRefreshStatus()
@@ -585,9 +583,7 @@ export class Curtain extends deviceBase {
585
583
  * Pushes the requested changes to the SwitchBot API
586
584
  */
587
585
  async pushChanges(): Promise<void> {
588
- if (!this.device.enableCloudService && this.OpenAPI) {
589
- this.errorLog(`pushChanges enableCloudService: ${this.device.enableCloudService}`)
590
- } else if (this.BLE) {
586
+ if (this.BLE) {
591
587
  await this.BLEpushChanges()
592
588
  } else if (this.OpenAPI && this.platform.config.credentials?.token) {
593
589
  await this.openAPIpushChanges()
package/src/device/fan.ts CHANGED
@@ -306,9 +306,7 @@ export class Fan extends deviceBase {
306
306
  * Asks the SwitchBot API for the latest device information
307
307
  */
308
308
  async refreshStatus(): Promise<void> {
309
- if (!this.device.enableCloudService && this.OpenAPI) {
310
- this.errorLog(`refreshStatus enableCloudService: ${this.device.enableCloudService}`)
311
- } else if (this.BLE) {
309
+ if (this.BLE) {
312
310
  await this.BLERefreshStatus()
313
311
  } else if (this.OpenAPI && this.platform.config.credentials?.token) {
314
312
  await this.openAPIRefreshStatus()
@@ -429,9 +427,7 @@ export class Fan extends deviceBase {
429
427
  */
430
428
 
431
429
  async pushChanges(): Promise<void> {
432
- if (!this.device.enableCloudService && this.OpenAPI) {
433
- this.errorLog(`pushChanges enableCloudService: ${this.device.enableCloudService}`)
434
- } else if (this.BLE) {
430
+ if (this.BLE) {
435
431
  await this.BLEpushChanges()
436
432
  } else if (this.OpenAPI && this.platform.config.credentials?.token) {
437
433
  await this.openAPIpushChanges()
package/src/device/hub.ts CHANGED
@@ -273,9 +273,7 @@ export class Hub extends deviceBase {
273
273
  * Asks the SwitchBot API for the latest device information
274
274
  */
275
275
  async refreshStatus(): Promise<void> {
276
- if (!this.device.enableCloudService && this.OpenAPI) {
277
- this.errorLog(`refreshStatus enableCloudService: ${this.device.enableCloudService}`)
278
- } else if (this.BLE) {
276
+ if (this.BLE) {
279
277
  await this.BLERefreshStatus()
280
278
  } else if (this.OpenAPI && this.platform.config.credentials?.token) {
281
279
  await this.openAPIRefreshStatus()
@@ -303,9 +303,7 @@ export class Humidifier extends deviceBase {
303
303
  * Asks the SwitchBot API for the latest device information
304
304
  */
305
305
  async refreshStatus(): Promise<void> {
306
- if (!this.device.enableCloudService && this.OpenAPI) {
307
- this.errorLog(`refreshStatus enableCloudService: ${this.device.enableCloudService}`)
308
- } else if (this.BLE) {
306
+ if (this.BLE) {
309
307
  await this.BLERefreshStatus()
310
308
  } else if (this.OpenAPI && this.platform.config.credentials?.token) {
311
309
  await this.openAPIRefreshStatus()
@@ -417,9 +415,7 @@ export class Humidifier extends deviceBase {
417
415
  * Pushes the requested changes to the SwitchBot API
418
416
  */
419
417
  async pushChanges(): Promise<void> {
420
- if (!this.device.enableCloudService && this.OpenAPI) {
421
- this.errorLog(`pushChanges enableCloudService: ${this.device.enableCloudService}`)
422
- } else if (this.BLE) {
418
+ if (this.BLE) {
423
419
  await this.BLEpushChanges()
424
420
  } else if (this.OpenAPI && this.platform.config.credentials?.token) {
425
421
  await this.openAPIpushChanges()
@@ -267,9 +267,7 @@ export class IOSensor extends deviceBase {
267
267
  * Asks the SwitchBot API for the latest device information
268
268
  */
269
269
  async refreshStatus(): Promise<void> {
270
- if (!this.device.enableCloudService && this.OpenAPI) {
271
- this.errorLog(`refreshStatus enableCloudService: ${this.device.enableCloudService}`)
272
- } else if (this.BLE) {
270
+ if (this.BLE) {
273
271
  await this.BLERefreshStatus()
274
272
  } else if (this.OpenAPI && this.platform.config.credentials?.token) {
275
273
  await this.openAPIRefreshStatus()
@@ -305,9 +305,7 @@ export class StripLight extends deviceBase {
305
305
  * Asks the SwitchBot API for the latest device information
306
306
  */
307
307
  async refreshStatus(): Promise<void> {
308
- if (!this.device.enableCloudService && this.OpenAPI) {
309
- this.errorLog(`refreshStatus enableCloudService: ${this.device.enableCloudService}`)
310
- } else if (this.BLE) {
308
+ if (this.BLE) {
311
309
  await this.BLERefreshStatus()
312
310
  } else if (this.OpenAPI && this.platform.config.credentials?.token) {
313
311
  await this.openAPIRefreshStatus()
@@ -428,9 +426,7 @@ export class StripLight extends deviceBase {
428
426
  *
429
427
  */
430
428
  async pushChanges(): Promise<void> {
431
- if (!this.device.enableCloudService && this.OpenAPI) {
432
- this.errorLog(`pushChanges enableCloudService: ${this.device.enableCloudService}`)
433
- } else if (this.BLE) {
429
+ if (this.BLE) {
434
430
  await this.BLEpushChanges()
435
431
  if (this.LightBulb.On) {
436
432
  // Push Brightness Update
@@ -308,9 +308,7 @@ export class Lock extends deviceBase {
308
308
  * Asks the SwitchBot API for the latest device information
309
309
  */
310
310
  async refreshStatus(): Promise<void> {
311
- if (!this.device.enableCloudService && this.OpenAPI) {
312
- this.errorLog(`refreshStatus enableCloudService: ${this.device.enableCloudService}`)
313
- } else if (this.BLE) {
311
+ if (this.BLE) {
314
312
  await this.BLERefreshStatus()
315
313
  } else if (this.OpenAPI && this.platform.config.credentials?.token) {
316
314
  await this.openAPIRefreshStatus()
@@ -428,9 +426,7 @@ export class Lock extends deviceBase {
428
426
  * Lock - "command" "unlock" "default" = set to ???? state - LockCurrentState
429
427
  */
430
428
  async pushChanges(): Promise<void> {
431
- if (!this.device.enableCloudService && this.OpenAPI) {
432
- this.errorLog(`pushChanges enableCloudService: ${this.device.enableCloudService}`)
433
- } else if (this.BLE) {
429
+ if (this.BLE) {
434
430
  await this.BLEpushChanges()
435
431
  } else if (this.OpenAPI && this.platform.config.credentials?.token) {
436
432
  await this.openAPIpushChanges()
@@ -264,9 +264,7 @@ export class Meter extends deviceBase {
264
264
  * Asks the SwitchBot API for the latest device information
265
265
  */
266
266
  async refreshStatus(): Promise<void> {
267
- if (!this.device.enableCloudService && this.OpenAPI) {
268
- this.errorLog(`refreshStatus enableCloudService: ${this.device.enableCloudService}`)
269
- } else if (this.BLE) {
267
+ if (this.BLE) {
270
268
  await this.BLERefreshStatus()
271
269
  } else if (this.OpenAPI && this.platform.config.credentials?.token) {
272
270
  await this.openAPIRefreshStatus()
@@ -268,9 +268,7 @@ export class MeterPlus extends deviceBase {
268
268
  * Asks the SwitchBot API for the latest device information
269
269
  */
270
270
  async refreshStatus(): Promise<void> {
271
- if (!this.device.enableCloudService && this.OpenAPI) {
272
- this.errorLog(`refreshStatus enableCloudService: ${this.device.enableCloudService}`)
273
- } else if (this.BLE) {
271
+ if (this.BLE) {
274
272
  await this.BLERefreshStatus()
275
273
  } else if (this.OpenAPI && this.platform.config.credentials?.token) {
276
274
  await this.openAPIRefreshStatus()
@@ -346,9 +346,7 @@ export class MeterPro extends deviceBase {
346
346
  * Asks the SwitchBot API for the latest device information
347
347
  */
348
348
  async refreshStatus(): Promise<void> {
349
- if (!this.device.enableCloudService && this.OpenAPI) {
350
- this.errorLog(`refreshStatus enableCloudService: ${this.device.enableCloudService}`)
351
- } else if (this.BLE) {
349
+ if (this.BLE) {
352
350
  await this.BLERefreshStatus()
353
351
  } else if (this.OpenAPI && this.platform.config.credentials?.token) {
354
352
  await this.openAPIRefreshStatus()
@@ -239,9 +239,7 @@ export class Motion extends deviceBase {
239
239
  * Asks the SwitchBot API for the latest device information
240
240
  */
241
241
  async refreshStatus(): Promise<void> {
242
- if (!this.device.enableCloudService && this.OpenAPI) {
243
- this.errorLog(`refreshStatus enableCloudService: ${this.device.enableCloudService}`)
244
- } else if (this.BLE) {
242
+ if (this.BLE) {
245
243
  await this.BLERefreshStatus()
246
244
  } else if (this.OpenAPI && this.platform.config.credentials?.token) {
247
245
  await this.openAPIRefreshStatus()
@@ -163,9 +163,7 @@ export class Plug extends deviceBase {
163
163
  * Asks the SwitchBot API for the latest device information
164
164
  */
165
165
  async refreshStatus(): Promise<void> {
166
- if (!this.device.enableCloudService && this.OpenAPI) {
167
- this.errorLog(`refreshStatus enableCloudService: ${this.device.enableCloudService}`)
168
- } else if (this.BLE) {
166
+ if (this.BLE) {
169
167
  await this.BLERefreshStatus()
170
168
  } else if (this.OpenAPI && this.platform.config.credentials?.token) {
171
169
  await this.openAPIRefreshStatus()
@@ -287,9 +285,7 @@ export class Plug extends deviceBase {
287
285
  */
288
286
 
289
287
  async pushChanges(): Promise<void> {
290
- if (!this.device.enableCloudService && this.OpenAPI) {
291
- this.errorLog(`pushChanges enableCloudService: ${this.device.enableCloudService}`)
292
- } else if (this.BLE) {
288
+ if (this.BLE) {
293
289
  await this.BLEpushChanges()
294
290
  } else if (this.OpenAPI && this.platform.config.credentials?.token) {
295
291
  await this.openAPIpushChanges()
@@ -292,9 +292,7 @@ export class RelaySwitch extends deviceBase {
292
292
  * Asks the SwitchBot API for the latest device information
293
293
  */
294
294
  async refreshStatus(): Promise<void> {
295
- if (!this.device.enableCloudService && this.OpenAPI) {
296
- this.errorLog(`refreshStatus enableCloudService: ${this.device.enableCloudService}`)
297
- } else if (this.BLE) {
295
+ if (this.BLE) {
298
296
  await this.BLERefreshStatus()
299
297
  } else if (this.OpenAPI && this.platform.config.credentials?.token) {
300
298
  await this.openAPIRefreshStatus()
@@ -411,9 +409,7 @@ export class RelaySwitch extends deviceBase {
411
409
  * RelaySwitch "command" "turnOn" "default" = set to ON state
412
410
  */
413
411
  async pushChanges(): Promise<void> {
414
- if (!this.device.enableCloudService && this.OpenAPI) {
415
- this.errorLog(`pushChanges enableCloudService: ${this.device.enableCloudService}`)
416
- } else if (this.BLE) {
412
+ if (this.BLE) {
417
413
  await this.BLEpushChanges()
418
414
  } else if (this.OpenAPI && this.platform.config.credentials?.token) {
419
415
  await this.openAPIpushChanges()
@@ -252,9 +252,7 @@ export class RobotVacuumCleaner extends deviceBase {
252
252
  * Asks the SwitchBot API for the latest device information
253
253
  */
254
254
  async refreshStatus(): Promise<void> {
255
- if (!this.device.enableCloudService && this.OpenAPI) {
256
- this.errorLog(`refreshStatus enableCloudService: ${this.device.enableCloudService}`)
257
- } else if (this.BLE) {
255
+ if (this.BLE) {
258
256
  await this.BLERefreshStatus()
259
257
  } else if (this.OpenAPI && this.platform.config.credentials?.token) {
260
258
  await this.openAPIRefreshStatus()
@@ -373,9 +371,7 @@ export class RobotVacuumCleaner extends deviceBase {
373
371
  * Robot Vacuum Cleaner S1 "command" "PowLevel" "{0-3}" = set suction power level: 0 (Quiet), 1 (Standard), 2 (Strong), 3 (MAX)
374
372
  */
375
373
  async pushChanges(): Promise<void> {
376
- if (!this.device.enableCloudService && this.OpenAPI) {
377
- this.errorLog(`pushChanges enableCloudService: ${this.device.enableCloudService}`)
378
- } else if (this.BLE) {
374
+ if (this.BLE) {
379
375
  await this.BLEpushChanges()
380
376
  } else if (this.OpenAPI && this.platform.config.credentials?.token) {
381
377
  await this.openAPIpushChanges()
@@ -246,9 +246,7 @@ export class WaterDetector extends deviceBase {
246
246
  * Asks the SwitchBot API for the latest device information
247
247
  */
248
248
  async refreshStatus(): Promise<void> {
249
- if (!this.device.enableCloudService && this.OpenAPI) {
250
- this.errorLog(`refreshStatus enableCloudService: ${this.device.enableCloudService}`)
251
- } else if (this.BLE) {
249
+ if (this.BLE) {
252
250
  await this.BLERefreshStatus()
253
251
  } else if (this.OpenAPI && this.platform.config.credentials?.token) {
254
252
  await this.openAPIRefreshStatus()
@@ -15,7 +15,7 @@ import { irdeviceBase } from './irdevice.js'
15
15
  * An instance of this class is created for each accessory your platform registers
16
16
  * Each accessory may expose multiple services of different service types.
17
17
  */
18
- export class AirPurifier extends irdeviceBase {
18
+ export class AirPurifierIR extends irdeviceBase {
19
19
  // Services
20
20
  private AirPurifier: {
21
21
  Name: CharacteristicValue
@@ -111,13 +111,13 @@ export class AirPurifier extends irdeviceBase {
111
111
  async TargetAirPurifierStateSet(value: CharacteristicValue): Promise<void> {
112
112
  switch (value) {
113
113
  case this.hap.Characteristic.CurrentAirPurifierState.PURIFYING_AIR:
114
- this.CurrentMode = AirPurifier.PURIFYING_AIR
114
+ this.CurrentMode = AirPurifierIR.PURIFYING_AIR
115
115
  break
116
116
  case this.hap.Characteristic.CurrentAirPurifierState.IDLE:
117
- this.CurrentMode = AirPurifier.IDLE
117
+ this.CurrentMode = AirPurifierIR.IDLE
118
118
  break
119
119
  case this.hap.Characteristic.CurrentAirPurifierState.INACTIVE:
120
- this.CurrentMode = AirPurifier.INACTIVE
120
+ this.CurrentMode = AirPurifierIR.INACTIVE
121
121
  break
122
122
  default:
123
123
  break
package/src/platform.ts CHANGED
@@ -24,6 +24,7 @@ import { EveHomeKitTypes } from 'homebridge-lib/EveHomeKitTypes'
24
24
  import { LogLevel, SwitchBotBLE, SwitchBotModel, SwitchBotOpenAPI } from 'node-switchbot'
25
25
  import { queueScheduler } from 'rxjs'
26
26
 
27
+ import { AirPurifier } from './device/airpurifier.js'
27
28
  import { BlindTilt } from './device/blindtilt.js'
28
29
  import { Bot } from './device/bot.js'
29
30
  import { CeilingLight } from './device/ceilinglight.js'
@@ -45,7 +46,7 @@ import { RelaySwitch } from './device/relayswitch.js'
45
46
  import { RobotVacuumCleaner } from './device/robotvacuumcleaner.js'
46
47
  import { WaterDetector } from './device/waterdetector.js'
47
48
  import { AirConditioner } from './irdevice/airconditioner.js'
48
- import { AirPurifier } from './irdevice/airpurifier.js'
49
+ import { AirPurifierIR } from './irdevice/airpurifier.js'
49
50
  import { Camera } from './irdevice/camera.js'
50
51
  import { IRFan } from './irdevice/fan.js'
51
52
  import { Light } from './irdevice/light.js'
@@ -616,6 +617,10 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
616
617
  'Ceiling Light Pro': this.createCeilingLight.bind(this),
617
618
  'Strip Light': this.createStripLight.bind(this),
618
619
  'Battery Circulator Fan': this.createFan.bind(this),
620
+ 'Air Purifier PM2.5': this.createAirPurifier.bind(this),
621
+ 'Air Purifier Table PM2.5': this.createAirPurifier.bind(this),
622
+ 'Air Purifier VOC': this.createAirPurifier.bind(this),
623
+ 'Air Purifier Table VOC': this.createAirPurifier.bind(this),
619
624
  }
620
625
 
621
626
  if (deviceTypeHandlers[device.deviceType!]) {
@@ -649,8 +654,8 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
649
654
  'DIY Air Conditioner': this.createAirConditioner.bind(this),
650
655
  'Light': this.createLight.bind(this),
651
656
  'DIY Light': this.createLight.bind(this),
652
- 'Air Purifier': this.createAirPurifier.bind(this),
653
- 'DIY Air Purifier': this.createAirPurifier.bind(this),
657
+ 'Air Purifier': this.createAirPurifierIR.bind(this),
658
+ 'DIY Air Purifier': this.createAirPurifierIR.bind(this),
654
659
  'Water Heater': this.createWaterHeater.bind(this),
655
660
  'DIY Water Heater': this.createWaterHeater.bind(this),
656
661
  'Vacuum Cleaner': this.createVacuumCleaner.bind(this),
@@ -1891,6 +1896,68 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
1891
1896
  }
1892
1897
  }
1893
1898
 
1899
+ private async createAirPurifier(device: device & devicesConfig) {
1900
+ const uuid = this.api.hap.uuid.generate(`${device.deviceId}-${device.deviceType}`)
1901
+
1902
+ // see if an accessory with the same uuid has already been registered and restored from
1903
+ // the cached devices we stored in the `configureAccessory` method above
1904
+ const existingAccessory = this.accessories.find(accessory => accessory.UUID === uuid)
1905
+
1906
+ if (existingAccessory) {
1907
+ // the accessory already exists
1908
+ if (await this.registerDevice(device)) {
1909
+ // if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
1910
+ existingAccessory.context.device = device
1911
+ existingAccessory.context.deviceId = device.deviceId
1912
+ existingAccessory.context.deviceType = device.deviceType
1913
+ existingAccessory.context.model = SwitchBotModel.BatteryCirculatorFan
1914
+ existingAccessory.displayName = device.configDeviceName
1915
+ ? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
1916
+ : await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName)
1917
+ existingAccessory.context.connectionType = await this.connectionType(device)
1918
+ existingAccessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0'
1919
+ this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`)
1920
+ this.api.updatePlatformAccessories([existingAccessory])
1921
+ // create the accessory handler for the restored accessory
1922
+ // this is imported from `platformAccessory.ts`
1923
+ new AirPurifier(this, existingAccessory, device)
1924
+ this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${existingAccessory.UUID})`)
1925
+ } else {
1926
+ this.unregisterPlatformAccessories(existingAccessory)
1927
+ }
1928
+ } else if (await this.registerDevice(device)) {
1929
+ // create a new accessory
1930
+ const accessory = new this.api.platformAccessory(device.configDeviceName
1931
+ ? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
1932
+ : await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName), uuid)
1933
+
1934
+ // store a copy of the device object in the `accessory.context`
1935
+ // the `context` property can be used to store any data about the accessory you may need
1936
+ accessory.context.device = device
1937
+ accessory.context.deviceId = device.deviceId
1938
+ accessory.context.deviceType = device.deviceType
1939
+ accessory.context.model = SwitchBotModel.BatteryCirculatorFan
1940
+ accessory.displayName = device.configDeviceName
1941
+ ? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
1942
+ : await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName)
1943
+ accessory.context.connectionType = await this.connectionType(device)
1944
+ accessory.context.connectionType = await this.connectionType(device)
1945
+ accessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0'
1946
+ const newOrExternal = !device.external ? 'Adding new' : 'Loading external'
1947
+ this.infoLog(`${newOrExternal} accessory: ${accessory.displayName} deviceId: ${device.deviceId}`)
1948
+ // create the accessory handler for the newly create accessory
1949
+ // this is imported from `platformAccessory.ts`
1950
+ new AirPurifier(this, accessory, device)
1951
+ this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`)
1952
+
1953
+ // publish device externally or link the accessory to your platform
1954
+ this.externalOrPlatform(device, accessory)
1955
+ this.accessories.push(accessory)
1956
+ } else {
1957
+ this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} deviceId: ${device.deviceId}`)
1958
+ }
1959
+ }
1960
+
1894
1961
  private async createRobotVacuumCleaner(device: device & devicesConfig) {
1895
1962
  const uuid = this.api.hap.uuid.generate(`${device.deviceId}-${device.deviceType}`)
1896
1963
 
@@ -2207,7 +2274,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
2207
2274
  }
2208
2275
  }
2209
2276
 
2210
- private async createAirPurifier(device: irdevice & irDevicesConfig) {
2277
+ private async createAirPurifierIR(device: irdevice & irDevicesConfig) {
2211
2278
  const uuid = this.api.hap.uuid.generate(`${device.deviceId}-${device.remoteType}`)
2212
2279
 
2213
2280
  // see if an accessory with the same uuid has already been registered and restored from
@@ -2230,7 +2297,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
2230
2297
  this.api.updatePlatformAccessories([existingAccessory])
2231
2298
  // create the accessory handler for the restored accessory
2232
2299
  // this is imported from `platformAccessory.ts`
2233
- new AirPurifier(this, existingAccessory, device)
2300
+ new AirPurifierIR(this, existingAccessory, device)
2234
2301
  this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${existingAccessory.UUID})`)
2235
2302
  } else {
2236
2303
  this.unregisterPlatformAccessories(existingAccessory)
@@ -2256,7 +2323,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
2256
2323
  this.infoLog(`${newOrExternal} accessory: ${accessory.displayName} deviceId: ${device.deviceId}`)
2257
2324
  // create the accessory handler for the newly create accessory
2258
2325
  // this is imported from `platformAccessory.ts`
2259
- new AirPurifier(this, accessory, device)
2326
+ new AirPurifierIR(this, accessory, device)
2260
2327
  this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${accessory.UUID})`)
2261
2328
 
2262
2329
  // publish device externally or link the accessory to your platform
@@ -2685,7 +2752,6 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
2685
2752
  hubDeviceId: '',
2686
2753
  version: 0,
2687
2754
  deviceName: '',
2688
- enableCloudService: false,
2689
2755
  }, statusCode: 500 }
2690
2756
  }
2691
2757