@switchbot/homebridge-switchbot 1.4.0 → 1.4.1-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (91) hide show
  1. package/dist/devices/bots.d.ts +1 -1
  2. package/dist/devices/bots.d.ts.map +1 -1
  3. package/dist/devices/bots.js +7 -16
  4. package/dist/devices/bots.js.map +1 -1
  5. package/dist/devices/colorbulb.d.ts +1 -1
  6. package/dist/devices/colorbulb.d.ts.map +1 -1
  7. package/dist/devices/colorbulb.js +8 -12
  8. package/dist/devices/colorbulb.js.map +1 -1
  9. package/dist/devices/contact.d.ts +1 -1
  10. package/dist/devices/contact.d.ts.map +1 -1
  11. package/dist/devices/contact.js +4 -14
  12. package/dist/devices/contact.js.map +1 -1
  13. package/dist/devices/curtains.d.ts +1 -1
  14. package/dist/devices/curtains.d.ts.map +1 -1
  15. package/dist/devices/curtains.js +7 -16
  16. package/dist/devices/curtains.js.map +1 -1
  17. package/dist/devices/humidifiers.d.ts +1 -1
  18. package/dist/devices/humidifiers.d.ts.map +1 -1
  19. package/dist/devices/humidifiers.js +9 -19
  20. package/dist/devices/humidifiers.js.map +1 -1
  21. package/dist/devices/indoorcam.d.ts +1 -1
  22. package/dist/devices/indoorcam.d.ts.map +1 -1
  23. package/dist/devices/indoorcam.js +5 -5
  24. package/dist/devices/indoorcam.js.map +1 -1
  25. package/dist/devices/meters.d.ts +1 -1
  26. package/dist/devices/meters.d.ts.map +1 -1
  27. package/dist/devices/meters.js +10 -16
  28. package/dist/devices/meters.js.map +1 -1
  29. package/dist/devices/motion.d.ts +1 -1
  30. package/dist/devices/motion.d.ts.map +1 -1
  31. package/dist/devices/motion.js +4 -9
  32. package/dist/devices/motion.js.map +1 -1
  33. package/dist/devices/plugs.d.ts +1 -1
  34. package/dist/devices/plugs.d.ts.map +1 -1
  35. package/dist/devices/plugs.js +4 -4
  36. package/dist/devices/plugs.js.map +1 -1
  37. package/dist/irdevices/airconditioners.d.ts +1 -1
  38. package/dist/irdevices/airconditioners.d.ts.map +1 -1
  39. package/dist/irdevices/airconditioners.js +3 -8
  40. package/dist/irdevices/airconditioners.js.map +1 -1
  41. package/dist/irdevices/airpurifiers.d.ts +1 -1
  42. package/dist/irdevices/airpurifiers.d.ts.map +1 -1
  43. package/dist/irdevices/airpurifiers.js +3 -6
  44. package/dist/irdevices/airpurifiers.js.map +1 -1
  45. package/dist/irdevices/cameras.d.ts +1 -1
  46. package/dist/irdevices/cameras.d.ts.map +1 -1
  47. package/dist/irdevices/cameras.js +3 -3
  48. package/dist/irdevices/cameras.js.map +1 -1
  49. package/dist/irdevices/fans.d.ts +1 -1
  50. package/dist/irdevices/fans.d.ts.map +1 -1
  51. package/dist/irdevices/fans.js +3 -5
  52. package/dist/irdevices/fans.js.map +1 -1
  53. package/dist/irdevices/lights.d.ts +1 -1
  54. package/dist/irdevices/lights.d.ts.map +1 -1
  55. package/dist/irdevices/lights.js +3 -3
  56. package/dist/irdevices/lights.js.map +1 -1
  57. package/dist/irdevices/others.d.ts +1 -1
  58. package/dist/irdevices/others.d.ts.map +1 -1
  59. package/dist/irdevices/others.js +3 -3
  60. package/dist/irdevices/others.js.map +1 -1
  61. package/dist/irdevices/tvs.d.ts +1 -1
  62. package/dist/irdevices/tvs.d.ts.map +1 -1
  63. package/dist/irdevices/tvs.js +3 -4
  64. package/dist/irdevices/tvs.js.map +1 -1
  65. package/dist/irdevices/vacuumcleaners.d.ts +1 -1
  66. package/dist/irdevices/vacuumcleaners.d.ts.map +1 -1
  67. package/dist/irdevices/vacuumcleaners.js +3 -3
  68. package/dist/irdevices/vacuumcleaners.js.map +1 -1
  69. package/dist/irdevices/waterheaters.d.ts +1 -1
  70. package/dist/irdevices/waterheaters.d.ts.map +1 -1
  71. package/dist/irdevices/waterheaters.js +3 -3
  72. package/dist/irdevices/waterheaters.js.map +1 -1
  73. package/package.json +66 -66
  74. package/src/devices/bots.ts +8 -16
  75. package/src/devices/colorbulb.ts +9 -13
  76. package/src/devices/contact.ts +5 -15
  77. package/src/devices/curtains.ts +8 -17
  78. package/src/devices/humidifiers.ts +10 -20
  79. package/src/devices/indoorcam.ts +6 -6
  80. package/src/devices/meters.ts +11 -17
  81. package/src/devices/motion.ts +5 -10
  82. package/src/devices/plugs.ts +5 -5
  83. package/src/irdevices/airconditioners.ts +4 -9
  84. package/src/irdevices/airpurifiers.ts +4 -7
  85. package/src/irdevices/cameras.ts +4 -4
  86. package/src/irdevices/fans.ts +4 -6
  87. package/src/irdevices/lights.ts +4 -4
  88. package/src/irdevices/others.ts +4 -4
  89. package/src/irdevices/tvs.ts +4 -5
  90. package/src/irdevices/vacuumcleaners.ts +4 -4
  91. package/src/irdevices/waterheaters.ts +4 -4
@@ -4,7 +4,7 @@ import Switchbot from 'node-switchbot';
4
4
  import { interval, Subject } from 'rxjs';
5
5
  import { SwitchBotPlatform } from '../platform';
6
6
  import { debounceTime, skipWhile, take, tap } from 'rxjs/operators';
7
- import { Service, PlatformAccessory, CharacteristicValue } from 'homebridge';
7
+ import { Service, PlatformAccessory, CharacteristicValue, HAPStatus } from 'homebridge';
8
8
  import { DeviceURL, device, devicesConfig, serviceData, ad, switchbot, deviceStatusResponse, payload } from '../settings';
9
9
 
10
10
  /**
@@ -286,7 +286,7 @@ export class Bot {
286
286
  this.platform.log.warn(`Bot: ${this.accessory.displayName} Using OpenAPI Connection`);
287
287
  await this.openAPIRefreshStatus();
288
288
  }
289
- this.apiError(e);
289
+ this.apiError();
290
290
  });
291
291
  }
292
292
 
@@ -318,7 +318,7 @@ export class Bot {
318
318
  this.platform.log.error(`Bot: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection,`
319
319
  + ` Error: ${JSON.stringify(e)}`);
320
320
  }
321
- this.apiError(e);
321
+ this.apiError();
322
322
  }
323
323
  }
324
324
  }
@@ -370,7 +370,7 @@ export class Bot {
370
370
  this.platform.log.warn(`Bot: ${this.accessory.displayName} Using OpenAPI Connection`);
371
371
  await this.openAPIpushChanges();
372
372
  }
373
- this.apiError(e);
373
+ this.apiError();
374
374
  });
375
375
  } else if (this.device.bot?.mode === 'switch') {
376
376
  this.platform.device(`Bot: ${this.accessory.displayName} Press Mode: ${this.device.bot?.mode}`);
@@ -393,7 +393,7 @@ export class Bot {
393
393
  this.platform.log.warn(`Bot: ${this.accessory.displayName} Using OpenAPI Connection`);
394
394
  await this.openAPIpushChanges();
395
395
  }
396
- this.apiError(e);
396
+ this.apiError();
397
397
  });
398
398
  } else {
399
399
  this.platform.log.error(`Bot: ${this.accessory.displayName} Mode Not Set, mode: ${this.device.bot?.mode}`);
@@ -457,7 +457,7 @@ export class Bot {
457
457
  this.platform.log.error(`Bot: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,`
458
458
  + ` Error: ${JSON.stringify(e)}`);
459
459
  }
460
- this.apiError(e);
460
+ this.apiError();
461
461
  }
462
462
  }
463
463
  }
@@ -492,16 +492,8 @@ export class Bot {
492
492
  }
493
493
  }
494
494
 
495
- public apiError(e: any) {
496
- if (this.device.bot?.deviceType === 'switch') {
497
- this.switchService?.updateCharacteristic(this.platform.Characteristic.On, e);
498
- } else {
499
- this.outletService?.updateCharacteristic(this.platform.Characteristic.On, e);
500
- }
501
- if (this.device.ble) {
502
- this.batteryService?.updateCharacteristic(this.platform.Characteristic.BatteryLevel, e);
503
- this.batteryService?.updateCharacteristic(this.platform.Characteristic.StatusLowBattery, e);
504
- }
495
+ public apiError() {
496
+ throw new this.platform.api.hap.HapStatusError(HAPStatus.SERVICE_COMMUNICATION_FAILURE);
505
497
  }
506
498
 
507
499
  private statusCode(push: AxiosResponse<{ statusCode: number; }>) {
@@ -2,7 +2,7 @@ import { AxiosResponse } from 'axios';
2
2
  import { interval, Subject } from 'rxjs';
3
3
  import { SwitchBotPlatform } from '../platform';
4
4
  import { debounceTime, skipWhile, tap } from 'rxjs/operators';
5
- import { Service, PlatformAccessory, CharacteristicValue, ControllerConstructor, Controller, ControllerServiceMap } from 'homebridge';
5
+ import { Service, PlatformAccessory, CharacteristicValue, ControllerConstructor, Controller, ControllerServiceMap, HAPStatus } from 'homebridge';
6
6
  import { DeviceURL, device, devicesConfig, switchbot, deviceStatusResponse, payload, hs2rgb, rgb2hs, m2hs } from '../settings';
7
7
 
8
8
  /**
@@ -189,7 +189,7 @@ export class ColorBulb {
189
189
  this.platform.log.error(`Color Bulb: ${this.accessory.displayName} failed pushChanges,`
190
190
  + ` Error: ${JSON.stringify(e)}`);
191
191
  }
192
- this.apiError(e);
192
+ this.apiError();
193
193
  }
194
194
  this.colorBulbUpdateInProgress = false;
195
195
  });
@@ -266,7 +266,7 @@ export class ColorBulb {
266
266
  this.platform.log.error(`Color Bulb: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection,`
267
267
  + ` Error: ${JSON.stringify(e)}`);
268
268
  }
269
- this.apiError(e);
269
+ this.apiError();
270
270
  }
271
271
  }
272
272
 
@@ -330,7 +330,7 @@ export class ColorBulb {
330
330
  this.platform.log.error(`Color Bulb: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,`
331
331
  + ` Error: ${JSON.stringify(e)}`);
332
332
  }
333
- this.apiError(e);
333
+ this.apiError();
334
334
  }
335
335
  }
336
336
 
@@ -372,7 +372,7 @@ export class ColorBulb {
372
372
  this.platform.log.error(`Color Bulb: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,`
373
373
  + ` Error: ${JSON.stringify(e)}`);
374
374
  }
375
- this.apiError(e);
375
+ this.apiError();
376
376
  }
377
377
  }
378
378
 
@@ -410,7 +410,7 @@ export class ColorBulb {
410
410
  this.platform.log.error(`Color Bulb: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,`
411
411
  + ` Error: ${JSON.stringify(e)}`);
412
412
  }
413
- this.apiError(e);
413
+ this.apiError();
414
414
  }
415
415
  }
416
416
 
@@ -445,7 +445,7 @@ export class ColorBulb {
445
445
  this.platform.log.error(`Color Bulb: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,`
446
446
  + ` Error: ${JSON.stringify(e)}`);
447
447
  }
448
- this.apiError(e);
448
+ this.apiError();
449
449
  }
450
450
  }
451
451
 
@@ -482,12 +482,8 @@ export class ColorBulb {
482
482
  }
483
483
  }
484
484
 
485
- public apiError(e: any) {
486
- this.service.updateCharacteristic(this.platform.Characteristic.On, e);
487
- this.service.updateCharacteristic(this.platform.Characteristic.Hue, e);
488
- this.service.updateCharacteristic(this.platform.Characteristic.Brightness, e);
489
- this.service.updateCharacteristic(this.platform.Characteristic.Saturation, e);
490
- this.service.updateCharacteristic(this.platform.Characteristic.ColorTemperature, e);
485
+ public apiError() {
486
+ throw new this.platform.api.hap.HapStatusError(HAPStatus.SERVICE_COMMUNICATION_FAILURE);
491
487
  }
492
488
 
493
489
  private statusCode(push: AxiosResponse<{ statusCode: number; }>) {
@@ -2,7 +2,7 @@ import Switchbot from 'node-switchbot';
2
2
  import { interval, Subject } from 'rxjs';
3
3
  import { skipWhile } from 'rxjs/operators';
4
4
  import { SwitchBotPlatform } from '../platform';
5
- import { Service, PlatformAccessory, CharacteristicValue } from 'homebridge';
5
+ import { Service, PlatformAccessory, CharacteristicValue, HAPStatus } from 'homebridge';
6
6
  import { DeviceURL, device, devicesConfig, serviceData, switchbot, deviceStatusResponse } from '../settings';
7
7
 
8
8
  /**
@@ -287,7 +287,7 @@ export class Contact {
287
287
  this.platform.log.warn(`Contact Sensor: ${this.accessory.displayName} Using OpenAPI Connection`);
288
288
  await this.openAPIRefreshStatus();
289
289
  }
290
- this.apiError(e);
290
+ this.apiError();
291
291
  });
292
292
  }
293
293
 
@@ -309,7 +309,7 @@ export class Contact {
309
309
  this.platform.log.error(`Contact Sensor: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection,`
310
310
  + ` Error: ${JSON.stringify(e)}`);
311
311
  }
312
- this.apiError(e);
312
+ this.apiError();
313
313
  }
314
314
  }
315
315
  }
@@ -357,17 +357,7 @@ export class Contact {
357
357
  }
358
358
  }
359
359
 
360
- public apiError(e: any) {
361
- this.service.updateCharacteristic(this.platform.Characteristic.ContactSensorState, e);
362
- if (!this.device.contact?.hide_motionsensor) {
363
- this.motionService?.updateCharacteristic(this.platform.Characteristic.MotionDetected, e);
364
- }
365
- if (!this.device.contact?.hide_lightsensor) {
366
- this.lightSensorService?.updateCharacteristic(this.platform.Characteristic.CurrentAmbientLightLevel, e);
367
- }
368
- if (this.device.ble) {
369
- this.batteryService?.updateCharacteristic(this.platform.Characteristic.BatteryLevel, e);
370
- this.batteryService?.updateCharacteristic(this.platform.Characteristic.StatusLowBattery, e);
371
- }
360
+ public apiError() {
361
+ throw new this.platform.api.hap.HapStatusError(HAPStatus.SERVICE_COMMUNICATION_FAILURE);
372
362
  }
373
363
  }
@@ -4,7 +4,7 @@ import Switchbot from 'node-switchbot';
4
4
  import { interval, Subject } from 'rxjs';
5
5
  import { SwitchBotPlatform } from '../platform';
6
6
  import { debounceTime, skipWhile, take, tap } from 'rxjs/operators';
7
- import { Service, PlatformAccessory, CharacteristicValue } from 'homebridge';
7
+ import { Service, PlatformAccessory, CharacteristicValue, HAPStatus } from 'homebridge';
8
8
  import { DeviceURL, device, devicesConfig, serviceData, switchbot, deviceStatusResponse, payload } from '../settings';
9
9
 
10
10
  export class Curtain {
@@ -184,7 +184,7 @@ export class Curtain {
184
184
  this.platform.log.error(`Curtain: ${this.accessory.displayName} failed pushChanges,`
185
185
  + ` Error: ${JSON.stringify(e)}`);
186
186
  }
187
- this.apiError(e);
187
+ this.apiError();
188
188
  }
189
189
  this.curtainUpdateInProgress = false;
190
190
  });
@@ -454,7 +454,7 @@ export class Curtain {
454
454
  this.platform.log.warn(`Curtain: ${this.accessory.displayName} Using OpenAPI Connection`);
455
455
  await this.openAPIRefreshStatus();
456
456
  }
457
- this.apiError(e);
457
+ this.apiError();
458
458
  });
459
459
  }
460
460
 
@@ -476,7 +476,7 @@ export class Curtain {
476
476
  this.platform.log.error(`Curtain: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection,`
477
477
  + ` Error: ${JSON.stringify(e)}`);
478
478
  }
479
- this.apiError(e);
479
+ this.apiError();
480
480
  }
481
481
  }
482
482
  }
@@ -518,7 +518,7 @@ export class Curtain {
518
518
  this.platform.log.warn(`Curtain: ${this.accessory.displayName} Using OpenAPI Connection`);
519
519
  await this.OpenAPIpushChanges();
520
520
  }
521
- this.apiError(e);
521
+ this.apiError();
522
522
  });
523
523
  } else {
524
524
  this.platform.debug(`Curtain: ${this.accessory.displayName} No BLE Changes, CurrentPosition & TargetPosition Are the Same.`
@@ -560,7 +560,7 @@ export class Curtain {
560
560
  this.platform.log.error(`Curtain: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,`
561
561
  + ` Error: ${JSON.stringify(e)}`);
562
562
  }
563
- this.apiError(e);
563
+ this.apiError();
564
564
  }
565
565
  }
566
566
  }
@@ -609,17 +609,8 @@ export class Curtain {
609
609
  }
610
610
  }
611
611
 
612
- public apiError(e: any) {
613
- this.service.updateCharacteristic(this.platform.Characteristic.CurrentPosition, e);
614
- this.service.updateCharacteristic(this.platform.Characteristic.PositionState, e);
615
- this.service.updateCharacteristic(this.platform.Characteristic.TargetPosition, e);
616
- if (!this.device.curtain?.hide_lightsensor) {
617
- this.lightSensorService?.updateCharacteristic(this.platform.Characteristic.CurrentAmbientLightLevel, e);
618
- }
619
- if (this.device.ble) {
620
- this.batteryService?.updateCharacteristic(this.platform.Characteristic.BatteryLevel, e);
621
- this.batteryService?.updateCharacteristic(this.platform.Characteristic.StatusLowBattery, e);
622
- }
612
+ public apiError() {
613
+ throw new this.platform.api.hap.HapStatusError(HAPStatus.SERVICE_COMMUNICATION_FAILURE);
623
614
  }
624
615
 
625
616
  private statusCode(push: AxiosResponse<{ statusCode: number; }>) {
@@ -3,7 +3,7 @@ import Switchbot from 'node-switchbot';
3
3
  import { interval, Subject } from 'rxjs';
4
4
  import { SwitchBotPlatform } from '../platform';
5
5
  import { debounceTime, skipWhile, take, tap } from 'rxjs/operators';
6
- import { Service, PlatformAccessory, CharacteristicValue } from 'homebridge';
6
+ import { Service, PlatformAccessory, CharacteristicValue, HAPStatus } from 'homebridge';
7
7
  import { DeviceURL, device, devicesConfig, serviceData, ad, deviceStatusResponse, payload } from '../settings';
8
8
 
9
9
  /**
@@ -184,7 +184,7 @@ export class Humidifier {
184
184
  this.platform.log.error(`Humidifier: ${this.accessory.displayName} failed pushChanges,`
185
185
  + ` Error: ${JSON.stringify(e)}`);
186
186
  }
187
- this.apiError(e);
187
+ this.apiError();
188
188
  }
189
189
  this.humidifierUpdateInProgress = false;
190
190
  });
@@ -354,7 +354,7 @@ export class Humidifier {
354
354
  this.platform.log.warn(`Humidifier: ${this.accessory.displayName} Using OpenAPI Connection`);
355
355
  await this.openAPIRefreshStatus();
356
356
  }
357
- this.apiError(e);
357
+ this.apiError();
358
358
  });
359
359
  }
360
360
 
@@ -380,7 +380,7 @@ export class Humidifier {
380
380
  this.platform.log.error(`Humidifier: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection,`
381
381
  + ` Error: ${JSON.stringify(e)}`);
382
382
  }
383
- this.apiError(e);
383
+ this.apiError();
384
384
  }
385
385
  }
386
386
  }
@@ -424,7 +424,7 @@ export class Humidifier {
424
424
  this.platform.log.warn(`Humidifier: ${this.accessory.displayName} Using OpenAPI Connection`);
425
425
  await this.OpenAPIpushChanges();
426
426
  }
427
- this.apiError(e);
427
+ this.apiError();
428
428
  });
429
429
  }
430
430
 
@@ -461,7 +461,7 @@ export class Humidifier {
461
461
  this.platform.log.error(`Humidifier: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,`
462
462
  + ` Error: ${JSON.stringify(e)}`);
463
463
  }
464
- this.apiError(e);
464
+ this.apiError();
465
465
  }
466
466
  } else if (
467
467
  this.TargetHumidifierDehumidifierState ===
@@ -510,7 +510,7 @@ export class Humidifier {
510
510
  this.platform.log.error(`Humidifier: ${this.accessory.displayName} failed pushAutoChanges with OpenAPI Connection,`
511
511
  + ` Error: ${JSON.stringify(e)}`);
512
512
  }
513
- this.apiError(e);
513
+ this.apiError();
514
514
  }
515
515
  }
516
516
 
@@ -545,7 +545,7 @@ export class Humidifier {
545
545
  this.platform.log.error(`Humidifier: ${this.accessory.displayName} failed pushActiveChanges with OpenAPI Connection,`
546
546
  + ` Error: ${JSON.stringify(e)}`);
547
547
  }
548
- this.apiError(e);
548
+ this.apiError();
549
549
  }
550
550
  }
551
551
 
@@ -606,18 +606,8 @@ export class Humidifier {
606
606
  }
607
607
  }
608
608
 
609
- public apiError(e: any) {
610
- this.service.updateCharacteristic(this.platform.Characteristic.CurrentRelativeHumidity, e);
611
- if (!this.device.ble) {
612
- this.service.updateCharacteristic(this.platform.Characteristic.WaterLevel, e);
613
- }
614
- this.service.updateCharacteristic(this.platform.Characteristic.CurrentHumidifierDehumidifierState, e);
615
- this.service.updateCharacteristic(this.platform.Characteristic.TargetHumidifierDehumidifierState, e);
616
- this.service.updateCharacteristic(this.platform.Characteristic.Active, e);
617
- this.service.updateCharacteristic(this.platform.Characteristic.RelativeHumidityHumidifierThreshold, e);
618
- if (!this.device.humidifier?.hide_temperature && !this.device.ble) {
619
- this.temperatureservice?.updateCharacteristic(this.platform.Characteristic.CurrentTemperature, e);
620
- }
609
+ public apiError() {
610
+ throw new this.platform.api.hap.HapStatusError(HAPStatus.SERVICE_COMMUNICATION_FAILURE);
621
611
  }
622
612
 
623
613
  private statusCode(push: AxiosResponse<{ statusCode: number; }>) {
@@ -2,7 +2,7 @@ import { AxiosResponse } from 'axios';
2
2
  import { interval, Subject } from 'rxjs';
3
3
  import { SwitchBotPlatform } from '../platform';
4
4
  import { debounceTime, skipWhile, take, tap } from 'rxjs/operators';
5
- import { Service, PlatformAccessory, CharacteristicValue } from 'homebridge';
5
+ import { Service, PlatformAccessory, CharacteristicValue, HAPStatus } from 'homebridge';
6
6
  import { DeviceURL, device, devicesConfig, deviceStatusResponse, payload } from '../settings';
7
7
 
8
8
  export class IndoorCam {
@@ -126,7 +126,7 @@ export class IndoorCam {
126
126
  this.platform.log.error(`Indoor Cam: ${this.accessory.displayName} failed pushChanges,`
127
127
  + ` Error: ${JSON.stringify(e)}`);
128
128
  }
129
- this.apiError(e);
129
+ this.apiError();
130
130
  }
131
131
  this.cameraUpdateInProgress = false;
132
132
  });
@@ -139,7 +139,7 @@ export class IndoorCam {
139
139
 
140
140
  private async refreshStatus() {
141
141
  try {
142
- this.deviceStatus = (await this.platform.axios.get(`${DeviceURL}/${this.device.deviceId}/status`)).data;
142
+ //this.deviceStatus = (await this.platform.axios.get(`${DeviceURL}/${this.device.deviceId}/status`)).data;
143
143
  this.platform.device(`Indoor Cam: ${this.accessory.displayName} refreshStatus: ${JSON.stringify(this.deviceStatus)}`);
144
144
  this.parseStatus();
145
145
  this.updateHomeKitCharacteristics();
@@ -153,7 +153,7 @@ export class IndoorCam {
153
153
  this.platform.log.error(`Indoor Cam: ${this.accessory.displayName} failed refreshStatus with BLE Connection,`
154
154
  + ` Error: ${JSON.stringify(e)}`);
155
155
  }
156
- this.apiError(e);
156
+ this.apiError();
157
157
  }
158
158
  }
159
159
 
@@ -198,8 +198,8 @@ export class IndoorCam {
198
198
  }
199
199
  }
200
200
 
201
- public apiError(e: any) {
202
- this.service.updateCharacteristic(this.platform.Characteristic.SelectedRTPStreamConfiguration, e);
201
+ public apiError() {
202
+ throw new this.platform.api.hap.HapStatusError(HAPStatus.SERVICE_COMMUNICATION_FAILURE);
203
203
  }
204
204
 
205
205
  private statusCode(push: AxiosResponse<{ statusCode: number; }>) {
@@ -2,7 +2,7 @@ import Switchbot from 'node-switchbot';
2
2
  import { interval, Subject } from 'rxjs';
3
3
  import { skipWhile } from 'rxjs/operators';
4
4
  import { SwitchBotPlatform } from '../platform';
5
- import { Service, PlatformAccessory, Units, CharacteristicValue } from 'homebridge';
5
+ import { Service, PlatformAccessory, Units, CharacteristicValue, HAPStatus } from 'homebridge';
6
6
  import { DeviceURL, device, devicesConfig, serviceData, ad, switchbot, deviceStatusResponse, temperature } from '../settings';
7
7
 
8
8
  /**
@@ -247,9 +247,9 @@ export class Meter {
247
247
  */
248
248
  async refreshStatus() {
249
249
  if (this.device.ble) {
250
- await this.BLErefreshStatus();
250
+ this.BLErefreshStatus();
251
251
  } else {
252
- await this.openAPIRefreshStatus();
252
+ this.openAPIRefreshStatus();
253
253
  }
254
254
  }
255
255
 
@@ -260,12 +260,13 @@ export class Meter {
260
260
  return switchbot;
261
261
  }
262
262
 
263
- private async BLErefreshStatus() {
263
+ private BLErefreshStatus() {
264
264
  this.platform.debug(`Meter: ${this.accessory.displayName} BLE RefreshStatus`);
265
265
  // eslint-disable-next-line @typescript-eslint/no-var-requires
266
266
  const switchbot = this.connectBLE();
267
267
  // Start to monitor advertisement packets
268
268
  switchbot.startScan({
269
+ model: 'T',
269
270
  id: this.device.bleMac,
270
271
  }).then(() => {
271
272
  // Set an event hander
@@ -305,7 +306,7 @@ export class Meter {
305
306
  this.platform.log.error(`Meter: ${this.accessory.displayName} wasn't able to establish BLE Connection`);
306
307
  if (this.platform.config.credentials?.openToken) {
307
308
  this.platform.log.warn(`Meter: ${this.accessory.displayName} Using OpenAPI Connection`);
308
- await this.openAPIRefreshStatus();
309
+ this.openAPIRefreshStatus();
309
310
  }
310
311
  }
311
312
  }).catch(async (e: any) => {
@@ -320,9 +321,9 @@ export class Meter {
320
321
  }
321
322
  if (this.platform.config.credentials?.openToken) {
322
323
  this.platform.log.warn(`Meter: ${this.accessory.displayName} Using OpenAPI Connection`);
323
- await this.openAPIRefreshStatus();
324
+ this.openAPIRefreshStatus();
324
325
  }
325
- this.apiError(e);
326
+ this.apiError();
326
327
  });
327
328
  }
328
329
 
@@ -350,7 +351,7 @@ export class Meter {
350
351
  this.platform.log.error(`Meter: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection,`
351
352
  + ` Error: ${JSON.stringify(e)}`);
352
353
  }
353
- this.apiError(e);
354
+ this.apiError();
354
355
  }
355
356
  }
356
357
  }
@@ -389,14 +390,7 @@ export class Meter {
389
390
  }
390
391
  }
391
392
 
392
- public apiError(e: any) {
393
- this.service.updateCharacteristic(this.platform.Characteristic.StatusLowBattery, e);
394
- this.service.updateCharacteristic(this.platform.Characteristic.BatteryLevel, e);
395
- if (!this.device.meter?.hide_humidity) {
396
- this.humidityservice?.updateCharacteristic(this.platform.Characteristic.CurrentRelativeHumidity, e);
397
- }
398
- if (!this.device.meter?.hide_temperature) {
399
- this.temperatureservice?.updateCharacteristic(this.platform.Characteristic.CurrentTemperature, e);
400
- }
393
+ public apiError() {
394
+ throw new this.platform.api.hap.HapStatusError(HAPStatus.SERVICE_COMMUNICATION_FAILURE);
401
395
  }
402
396
  }
@@ -2,7 +2,7 @@ import Switchbot from 'node-switchbot';
2
2
  import { interval, Subject } from 'rxjs';
3
3
  import { skipWhile } from 'rxjs/operators';
4
4
  import { SwitchBotPlatform } from '../platform';
5
- import { Service, PlatformAccessory, CharacteristicValue } from 'homebridge';
5
+ import { Service, PlatformAccessory, CharacteristicValue, HAPStatus } from 'homebridge';
6
6
  import { DeviceURL, device, devicesConfig, serviceData, switchbot, deviceStatusResponse } from '../settings';
7
7
 
8
8
  /**
@@ -224,7 +224,7 @@ export class Motion {
224
224
  this.platform.log.warn(`Motion Sensor: ${this.accessory.displayName} Using OpenAPI Connection`);
225
225
  await this.openAPIRefreshStatus();
226
226
  }
227
- this.apiError(e);
227
+ this.apiError();
228
228
  });
229
229
  }
230
230
 
@@ -246,7 +246,7 @@ export class Motion {
246
246
  this.platform.log.error(`Motion Sensor: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection,`
247
247
  + ` Error: ${JSON.stringify(e)}`);
248
248
  }
249
- this.apiError(e);
249
+ this.apiError();
250
250
  }
251
251
  }
252
252
  }
@@ -284,12 +284,7 @@ export class Motion {
284
284
  }
285
285
  }
286
286
 
287
- public apiError(e: any) {
288
- this.service.updateCharacteristic(this.platform.Characteristic.MotionDetected, e);
289
- if (this.device.ble) {
290
- this.batteryService?.updateCharacteristic(this.platform.Characteristic.BatteryLevel, e);
291
- this.batteryService?.updateCharacteristic(this.platform.Characteristic.StatusLowBattery, e);
292
- this.lightSensorService?.updateCharacteristic(this.platform.Characteristic.CurrentAmbientLightLevel, e);
293
- }
287
+ public apiError() {
288
+ throw new this.platform.api.hap.HapStatusError(HAPStatus.SERVICE_COMMUNICATION_FAILURE);
294
289
  }
295
290
  }
@@ -3,7 +3,7 @@ import { AxiosResponse } from 'axios';
3
3
  import { interval, Subject } from 'rxjs';
4
4
  import { SwitchBotPlatform } from '../platform';
5
5
  import { debounceTime, skipWhile, take, tap } from 'rxjs/operators';
6
- import { Service, PlatformAccessory, CharacteristicValue } from 'homebridge';
6
+ import { Service, PlatformAccessory, CharacteristicValue, HAPStatus } from 'homebridge';
7
7
  import { DeviceURL, device, devicesConfig, deviceStatusResponse, payload } from '../settings';
8
8
 
9
9
  export class Plug {
@@ -106,7 +106,7 @@ export class Plug {
106
106
  this.platform.log.error(`Plug: ${this.accessory.displayName} failed pushChanges,`
107
107
  + ` Error: ${JSON.stringify(e)}`);
108
108
  }
109
- this.apiError(e);
109
+ this.apiError();
110
110
  }
111
111
  this.plugUpdateInProgress = false;
112
112
  });
@@ -139,7 +139,7 @@ export class Plug {
139
139
  this.platform.log.error(`Plug: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection,`
140
140
  + ` Error: ${JSON.stringify(e)}`);
141
141
  }
142
- this.apiError(e);
142
+ this.apiError();
143
143
  }
144
144
  }
145
145
 
@@ -189,8 +189,8 @@ export class Plug {
189
189
  }
190
190
  }
191
191
 
192
- public apiError(e: any) {
193
- this.service.updateCharacteristic(this.platform.Characteristic.On, e);
192
+ public apiError() {
193
+ throw new this.platform.api.hap.HapStatusError(HAPStatus.SERVICE_COMMUNICATION_FAILURE);
194
194
  }
195
195
 
196
196
  private statusCode(push: AxiosResponse<{ statusCode: number; }>) {
@@ -1,7 +1,7 @@
1
1
  import { AxiosResponse } from 'axios';
2
2
  import { SwitchBotPlatform } from '../platform';
3
3
  import { irDevicesConfig, DeviceURL, irdevice, payload } from '../settings';
4
- import { CharacteristicValue, PlatformAccessory, Service } from 'homebridge';
4
+ import { CharacteristicValue, HAPStatus, PlatformAccessory, Service } from 'homebridge';
5
5
 
6
6
  /**
7
7
  * Platform Accessory
@@ -376,7 +376,7 @@ export class AirConditioner {
376
376
  this.platform.log.error(`Air Conditioner: ${this.accessory.displayName} failed pushChanges,`
377
377
  + ` Error: ${JSON.stringify(e)}`);
378
378
  }
379
- this.apiError(e);
379
+ this.apiError();
380
380
  }
381
381
  }
382
382
 
@@ -409,12 +409,7 @@ export class AirConditioner {
409
409
  }
410
410
  }
411
411
 
412
- public apiError(e: any) {
413
- this.service.updateCharacteristic(this.platform.Characteristic.Active, e);
414
- this.service.updateCharacteristic(this.platform.Characteristic.RotationSpeed, e);
415
- this.service.updateCharacteristic(this.platform.Characteristic.CurrentTemperature, e);
416
- this.service.updateCharacteristic(this.platform.Characteristic.TargetHeaterCoolerState, e);
417
- this.service.updateCharacteristic(this.platform.Characteristic.CurrentHeaterCoolerState, e);
418
- this.service.updateCharacteristic(this.platform.Characteristic.HeatingThresholdTemperature, e);
412
+ public apiError() {
413
+ throw new this.platform.api.hap.HapStatusError(HAPStatus.SERVICE_COMMUNICATION_FAILURE);
419
414
  }
420
415
  }
@@ -1,7 +1,7 @@
1
1
  import { AxiosResponse } from 'axios';
2
2
  import { SwitchBotPlatform } from '../platform';
3
3
  import { irDevicesConfig, DeviceURL, irdevice, payload } from '../settings';
4
- import { CharacteristicValue, PlatformAccessory, Service } from 'homebridge';
4
+ import { CharacteristicValue, HAPStatus, PlatformAccessory, Service } from 'homebridge';
5
5
 
6
6
  /**
7
7
  * Platform Accessory
@@ -238,7 +238,7 @@ export class AirPurifier {
238
238
  this.platform.log.error(`Air Purifier: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,`
239
239
  + ` Error: ${JSON.stringify(e)}`);
240
240
  }
241
- this.apiError(e);
241
+ this.apiError();
242
242
  }
243
243
  }
244
244
 
@@ -271,10 +271,7 @@ export class AirPurifier {
271
271
  }
272
272
  }
273
273
 
274
- public apiError(e: any) {
275
- this.service.updateCharacteristic(this.platform.Characteristic.CurrentHeaterCoolerState, e);
276
- this.service.updateCharacteristic(this.platform.Characteristic.CurrentAirPurifierState, e);
277
- this.service.updateCharacteristic(this.platform.Characteristic.TargetAirPurifierState, e);
278
- this.service.updateCharacteristic(this.platform.Characteristic.Active, e);
274
+ public apiError() {
275
+ throw new this.platform.api.hap.HapStatusError(HAPStatus.SERVICE_COMMUNICATION_FAILURE);
279
276
  }
280
277
  }
@@ -1,7 +1,7 @@
1
1
  import { AxiosResponse } from 'axios';
2
2
  import { SwitchBotPlatform } from '../platform';
3
3
  import { irDevicesConfig, DeviceURL, irdevice, payload } from '../settings';
4
- import { CharacteristicValue, PlatformAccessory, Service } from 'homebridge';
4
+ import { CharacteristicValue, HAPStatus, PlatformAccessory, Service } from 'homebridge';
5
5
 
6
6
  /**
7
7
  * Platform Accessory
@@ -130,7 +130,7 @@ export class Camera {
130
130
  this.platform.log.error(`Camera: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,`
131
131
  + ` Error: ${JSON.stringify(e)}`);
132
132
  }
133
- this.apiError(e);
133
+ this.apiError();
134
134
  }
135
135
  }
136
136
 
@@ -163,7 +163,7 @@ export class Camera {
163
163
  }
164
164
  }
165
165
 
166
- public apiError(e: any) {
167
- this.service.updateCharacteristic(this.platform.Characteristic.On, e);
166
+ public apiError() {
167
+ throw new this.platform.api.hap.HapStatusError(HAPStatus.SERVICE_COMMUNICATION_FAILURE);
168
168
  }
169
169
  }