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

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 (137) hide show
  1. package/.github/npm-version-script.cjs +81 -0
  2. package/config.schema.json +4 -4
  3. package/dist/device/blindtilt.d.ts.map +1 -1
  4. package/dist/device/blindtilt.js +64 -189
  5. package/dist/device/blindtilt.js.map +1 -1
  6. package/dist/device/bot.d.ts.map +1 -1
  7. package/dist/device/bot.js +34 -68
  8. package/dist/device/bot.js.map +1 -1
  9. package/dist/device/ceilinglight.d.ts +1 -1
  10. package/dist/device/ceilinglight.d.ts.map +1 -1
  11. package/dist/device/ceilinglight.js +65 -158
  12. package/dist/device/ceilinglight.js.map +1 -1
  13. package/dist/device/colorbulb.d.ts +1 -1
  14. package/dist/device/colorbulb.d.ts.map +1 -1
  15. package/dist/device/colorbulb.js +47 -159
  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 +42 -105
  19. package/dist/device/contact.js.map +1 -1
  20. package/dist/device/curtain.d.ts +1 -0
  21. package/dist/device/curtain.d.ts.map +1 -1
  22. package/dist/device/curtain.js +61 -182
  23. package/dist/device/curtain.js.map +1 -1
  24. package/dist/device/device.d.ts +41 -2
  25. package/dist/device/device.d.ts.map +1 -1
  26. package/dist/device/device.js +182 -5
  27. package/dist/device/device.js.map +1 -1
  28. package/dist/device/fan.d.ts.map +1 -1
  29. package/dist/device/fan.js +76 -145
  30. package/dist/device/fan.js.map +1 -1
  31. package/dist/device/hub.d.ts +7 -1
  32. package/dist/device/hub.d.ts.map +1 -1
  33. package/dist/device/hub.js +54 -17
  34. package/dist/device/hub.js.map +1 -1
  35. package/dist/device/humidifier.d.ts.map +1 -1
  36. package/dist/device/humidifier.js +55 -104
  37. package/dist/device/humidifier.js.map +1 -1
  38. package/dist/device/iosensor.d.ts.map +1 -1
  39. package/dist/device/iosensor.js +27 -46
  40. package/dist/device/iosensor.js.map +1 -1
  41. package/dist/device/lightstrip.d.ts +1 -1
  42. package/dist/device/lightstrip.d.ts.map +1 -1
  43. package/dist/device/lightstrip.js +56 -120
  44. package/dist/device/lightstrip.js.map +1 -1
  45. package/dist/device/lock.d.ts +1 -1
  46. package/dist/device/lock.d.ts.map +1 -1
  47. package/dist/device/lock.js +36 -66
  48. package/dist/device/lock.js.map +1 -1
  49. package/dist/device/meter.d.ts.map +1 -1
  50. package/dist/device/meter.js +27 -46
  51. package/dist/device/meter.js.map +1 -1
  52. package/dist/device/meterplus.d.ts.map +1 -1
  53. package/dist/device/meterplus.js +26 -45
  54. package/dist/device/meterplus.js.map +1 -1
  55. package/dist/device/motion.d.ts.map +1 -1
  56. package/dist/device/motion.js +24 -43
  57. package/dist/device/motion.js.map +1 -1
  58. package/dist/device/plug.d.ts.map +1 -1
  59. package/dist/device/plug.js +32 -66
  60. package/dist/device/plug.js.map +1 -1
  61. package/dist/device/robotvacuumcleaner.d.ts +1 -1
  62. package/dist/device/robotvacuumcleaner.d.ts.map +1 -1
  63. package/dist/device/robotvacuumcleaner.js +43 -88
  64. package/dist/device/robotvacuumcleaner.js.map +1 -1
  65. package/dist/device/waterdetector.d.ts.map +1 -1
  66. package/dist/device/waterdetector.js +23 -43
  67. package/dist/device/waterdetector.js.map +1 -1
  68. package/dist/irdevice/airconditioner.d.ts.map +1 -1
  69. package/dist/irdevice/airconditioner.js +10 -28
  70. package/dist/irdevice/airconditioner.js.map +1 -1
  71. package/dist/irdevice/airpurifier.d.ts.map +1 -1
  72. package/dist/irdevice/airpurifier.js +8 -20
  73. package/dist/irdevice/airpurifier.js.map +1 -1
  74. package/dist/irdevice/camera.d.ts.map +1 -1
  75. package/dist/irdevice/camera.js +8 -20
  76. package/dist/irdevice/camera.js.map +1 -1
  77. package/dist/irdevice/fan.d.ts.map +1 -1
  78. package/dist/irdevice/fan.js +8 -20
  79. package/dist/irdevice/fan.js.map +1 -1
  80. package/dist/irdevice/irdevice.d.ts +7 -0
  81. package/dist/irdevice/irdevice.d.ts.map +1 -1
  82. package/dist/irdevice/irdevice.js +28 -0
  83. package/dist/irdevice/irdevice.js.map +1 -1
  84. package/dist/irdevice/light.d.ts.map +1 -1
  85. package/dist/irdevice/light.js +8 -20
  86. package/dist/irdevice/light.js.map +1 -1
  87. package/dist/irdevice/other.d.ts.map +1 -1
  88. package/dist/irdevice/other.js +8 -20
  89. package/dist/irdevice/other.js.map +1 -1
  90. package/dist/irdevice/tv.d.ts.map +1 -1
  91. package/dist/irdevice/tv.js +8 -20
  92. package/dist/irdevice/tv.js.map +1 -1
  93. package/dist/irdevice/vacuumcleaner.d.ts.map +1 -1
  94. package/dist/irdevice/vacuumcleaner.js +8 -20
  95. package/dist/irdevice/vacuumcleaner.js.map +1 -1
  96. package/dist/irdevice/waterheater.d.ts.map +1 -1
  97. package/dist/irdevice/waterheater.js +8 -20
  98. package/dist/irdevice/waterheater.js.map +1 -1
  99. package/dist/settings.d.ts +4 -2
  100. package/dist/settings.d.ts.map +1 -1
  101. package/dist/settings.js.map +1 -1
  102. package/dist/utils.d.ts +19 -1
  103. package/dist/utils.d.ts.map +1 -1
  104. package/dist/utils.js +20 -1
  105. package/dist/utils.js.map +1 -1
  106. package/package.json +8 -8
  107. package/src/device/blindtilt.ts +71 -186
  108. package/src/device/bot.ts +32 -68
  109. package/src/device/ceilinglight.ts +67 -153
  110. package/src/device/colorbulb.ts +51 -155
  111. package/src/device/contact.ts +49 -104
  112. package/src/device/curtain.ts +70 -177
  113. package/src/device/device.ts +207 -8
  114. package/src/device/fan.ts +75 -147
  115. package/src/device/hub.ts +55 -19
  116. package/src/device/humidifier.ts +52 -104
  117. package/src/device/iosensor.ts +25 -46
  118. package/src/device/lightstrip.ts +54 -121
  119. package/src/device/lock.ts +35 -67
  120. package/src/device/meter.ts +25 -46
  121. package/src/device/meterplus.ts +24 -45
  122. package/src/device/motion.ts +22 -43
  123. package/src/device/plug.ts +30 -66
  124. package/src/device/robotvacuumcleaner.ts +40 -89
  125. package/src/device/waterdetector.ts +22 -43
  126. package/src/irdevice/airconditioner.ts +10 -26
  127. package/src/irdevice/airpurifier.ts +8 -20
  128. package/src/irdevice/camera.ts +8 -20
  129. package/src/irdevice/fan.ts +8 -20
  130. package/src/irdevice/irdevice.ts +29 -0
  131. package/src/irdevice/light.ts +8 -20
  132. package/src/irdevice/other.ts +8 -20
  133. package/src/irdevice/tv.ts +8 -20
  134. package/src/irdevice/vacuumcleaner.ts +8 -20
  135. package/src/irdevice/waterheater.ts +8 -20
  136. package/src/settings.ts +4 -2
  137. package/src/utils.ts +20 -1
@@ -2,10 +2,8 @@
2
2
  *
3
3
  * ceilinglight.ts: @switchbot/homebridge-switchbot.
4
4
  */
5
- import { request } from 'undici';
6
5
  import { deviceBase } from './device.js';
7
6
  import { interval, Subject } from 'rxjs';
8
- import { Devices } from '../settings.js';
9
7
  import { hs2rgb, rgb2hs, m2hs } from '../utils.js';
10
8
  import { debounceTime, skipWhile, take, tap } from 'rxjs/operators';
11
9
 
@@ -282,63 +280,42 @@ export class CeilingLight extends deviceBase {
282
280
 
283
281
  async BLERefreshStatus(): Promise<void> {
284
282
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLERefreshStatus`);
285
- const switchbot = await this.platform.connectBLE();
286
- // Convert to BLE Address
287
- this.device.bleMac = this.device
288
- .deviceId!.match(/.{1,2}/g)!
289
- .join(':')
290
- .toLowerCase();
291
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLE Address: ${this.device.bleMac}`);
292
- this.getCustomBLEAddress(switchbot);
293
- // Start to monitor advertisement packets
294
- (async () => {
283
+ const switchbot = await this.switchbotBLE();
284
+
285
+ if (switchbot === undefined) {
286
+ await this.BLERefreshConnection(switchbot);
287
+ } else {
288
+ (async () => {
295
289
  // Start to monitor advertisement packets
296
- await switchbot.startScan({ model: this.device.bleModel, id: this.device.bleMac });
297
- // Set an event handler
298
- switchbot.onadvertisement = (ad: any) => {
299
- if (this.device.bleMac === ad.address && ad.model === this.device.bleModel) {
300
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} ${JSON.stringify(ad, null, ' ')}`);
301
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} address: ${ad.address}, model: ${ad.model}`);
302
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} serviceData: ${JSON.stringify(ad.serviceData)}`);
290
+ const serviceData: serviceData = await this.monitorAdvertisementPackets(switchbot);
291
+ // Update HomeKit
292
+ if (serviceData.model !== '' && serviceData.modelName !== '') {
293
+ await this.BLEparseStatus(serviceData);
294
+ await this.updateHomeKitCharacteristics();
303
295
  } else {
304
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} serviceData: ${JSON.stringify(ad.serviceData)}`);
296
+ this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed to get serviceData, serviceData: ${serviceData}`);
297
+ await this.BLERefreshConnection(switchbot);
305
298
  }
306
- };
307
- // Wait 10 seconds
308
- await switchbot.wait(this.scanDuration * 1000);
309
- // Stop to monitor
310
- await switchbot.stopScan();
311
- // Update HomeKit
312
- await this.BLEparseStatus(switchbot.onadvertisement.serviceData);
313
- await this.updateHomeKitCharacteristics();
314
- })();
315
- if (switchbot === undefined) {
316
- await this.BLERefreshConnection(switchbot);
299
+ })();
317
300
  }
318
301
  }
319
302
 
320
303
  async openAPIRefreshStatus(): Promise<void> {
321
304
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIRefreshStatus`);
322
305
  try {
323
- const { body, statusCode } = await this.platform.retryRequest(this.deviceMaxRetries, this.deviceDelayBetweenRetries,
324
- `${Devices}/${this.device.deviceId}/status`, { headers: this.platform.generateHeaders() });
325
- this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} statusCode: ${statusCode}`);
306
+ const { body, statusCode } = await this.deviceRefreshStatus();
326
307
  const deviceStatus: any = await body.json();
327
- this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} deviceStatus: ${JSON.stringify(deviceStatus)}`);
328
- this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} deviceStatus statusCode: ${deviceStatus.statusCode}`);
308
+ await this.refreshStatusCodes(statusCode, deviceStatus);;
329
309
  if ((statusCode === 200 || statusCode === 100) && (deviceStatus.statusCode === 200 || deviceStatus.statusCode === 100)) {
330
- this.debugSuccessLog(`${this.device.deviceType}: ${this.accessory.displayName} `
331
- + `statusCode: ${statusCode} & deviceStatus StatusCode: ${deviceStatus.statusCode}`);
332
- this.openAPIparseStatus(deviceStatus);
333
- this.updateHomeKitCharacteristics();
310
+ await this.successfulRefreshStatus(statusCode, deviceStatus);
311
+ await this.openAPIparseStatus(deviceStatus);
312
+ await this.updateHomeKitCharacteristics();
334
313
  } else {
335
- this.statusCode(statusCode);
336
- this.statusCode(deviceStatus.statusCode);
314
+ await this.statusCodes(statusCode, deviceStatus);
337
315
  }
338
316
  } catch (e: any) {
339
- this.apiError(e);
340
- this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed openAPIRefreshStatus with ${this.device.connectionType}`
341
- + ` Connection, Error Message: ${JSON.stringify(e.message)}`);
317
+ await this.apiError(e);
318
+ await this.openAPIRefreshError(e);
342
319
  }
343
320
  }
344
321
 
@@ -403,14 +380,13 @@ export class CeilingLight extends deviceBase {
403
380
  async pushChanges(): Promise<void> {
404
381
  if (!this.device.enableCloudService && this.OpenAPI) {
405
382
  this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} pushChanges enableCloudService: ${this.device.enableCloudService}`);
406
- /*} else if (this.BLE) {
407
- await this.BLEpushChanges();*/
383
+ } else if (this.BLE) {
384
+ await this.BLEpushChanges();
408
385
  } else if (this.OpenAPI && this.platform.config.credentials?.token) {
409
386
  await this.openAPIpushChanges();
410
387
  } else {
411
388
  await this.offlineOff();
412
- this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} Connection Type:`
413
- + ` ${this.device.connectionType}, pushChanges will not happen.`);
389
+ await this.pushChangeDisabled();
414
390
  }
415
391
  // Refresh the status from the API
416
392
  interval(15000)
@@ -428,16 +404,9 @@ export class CeilingLight extends deviceBase {
428
404
  + ` BLEpushChanges On: ${this.LightBulb.On} OnCached: ${this.accessory.context.On}`);
429
405
  const switchbot = await this.platform.connectBLE();
430
406
  // Convert to BLE Address
431
- this.device.bleMac = this.device
432
- .deviceId!.match(/.{1,2}/g)!
433
- .join(':')
434
- .toLowerCase();
435
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLE Address: ${this.device.bleMac}`);
407
+ await this.convertBLEAddress();
436
408
  switchbot
437
- .discover({
438
- model: 'u',
439
- id: this.device.bleMac,
440
- })
409
+ .discover({ model: this.device.bleModel, id: this.device.bleMac })
441
410
  .then(async (device_list: any) => {
442
411
  this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} On: ${this.LightBulb.On}`);
443
412
  return await this.retryBLE({
@@ -486,24 +455,15 @@ export class CeilingLight extends deviceBase {
486
455
  });
487
456
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${bodyChange},`);
488
457
  try {
489
- const { body, statusCode } = await request(`${Devices}/${this.device.deviceId}/commands`, {
490
- body: bodyChange,
491
- method: 'POST',
492
- headers: this.platform.generateHeaders(),
493
- });
494
- this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} statusCode: ${statusCode}`);
458
+ const { body, statusCode } = await this.pushChangeRequest(bodyChange);
495
459
  const deviceStatus: any = await body.json();
496
- this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} deviceStatus: ${JSON.stringify(deviceStatus)}`);
497
- this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} deviceStatus body: ${JSON.stringify(deviceStatus.body)}`);
498
- this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} deviceStatus statusCode: ${deviceStatus.statusCode}`);
460
+ await this.pushStatusCodes(statusCode, deviceStatus);
499
461
  if ((statusCode === 200 || statusCode === 100) && (deviceStatus.statusCode === 200 || deviceStatus.statusCode === 100)) {
500
- this.debugSuccessLog(`${this.device.deviceType}: ${this.accessory.displayName} `
501
- + `statusCode: ${statusCode} & deviceStatus StatusCode: ${deviceStatus.statusCode}`);
502
- this.successLog(`${this.device.deviceType}: ${this.accessory.displayName} `
503
- + `request to SwitchBot API, body: ${JSON.stringify(JSON.parse(bodyChange))} sent successfully`);
462
+ await this.successfulPushChange(statusCode, deviceStatus, bodyChange);
463
+ await this.updateHomeKitCharacteristics();
504
464
  } else {
505
- this.statusCode(statusCode);
506
- this.statusCode(deviceStatus.statusCode);
465
+ await this.statusCode(statusCode);
466
+ await this.statusCode(deviceStatus.statusCode);
507
467
  }
508
468
  } catch (e: any) {
509
469
  this.apiError(e);
@@ -543,24 +503,15 @@ export class CeilingLight extends deviceBase {
543
503
  });
544
504
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${bodyChange},`);
545
505
  try {
546
- const { body, statusCode } = await request(`${Devices}/${this.device.deviceId}/commands`, {
547
- body: bodyChange,
548
- method: 'POST',
549
- headers: this.platform.generateHeaders(),
550
- });
551
- this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} statusCode: ${statusCode}`);
506
+ const { body, statusCode } = await this.pushChangeRequest(bodyChange);
552
507
  const deviceStatus: any = await body.json();
553
- this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} deviceStatus: ${JSON.stringify(deviceStatus)}`);
554
- this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} deviceStatus body: ${JSON.stringify(deviceStatus.body)}`);
555
- this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} deviceStatus statusCode: ${deviceStatus.statusCode}`);
508
+ await this.pushStatusCodes(statusCode, deviceStatus);
556
509
  if ((statusCode === 200 || statusCode === 100) && (deviceStatus.statusCode === 200 || deviceStatus.statusCode === 100)) {
557
- this.debugSuccessLog(`${this.device.deviceType}: ${this.accessory.displayName} `
558
- + `statusCode: ${statusCode} & deviceStatus StatusCode: ${deviceStatus.statusCode}`);
559
- this.successLog(`${this.device.deviceType}: ${this.accessory.displayName} `
560
- + `request to SwitchBot API, body: ${JSON.stringify(JSON.parse(bodyChange))} sent successfully`);
510
+ await this.successfulPushChange(statusCode, deviceStatus, bodyChange);
511
+ await this.updateHomeKitCharacteristics();
561
512
  } else {
562
- this.statusCode(statusCode);
563
- this.statusCode(deviceStatus.statusCode);
513
+ await this.statusCode(statusCode);
514
+ await this.statusCode(deviceStatus.statusCode);
564
515
  }
565
516
  } catch (e: any) {
566
517
  this.apiError(e);
@@ -585,22 +536,15 @@ export class CeilingLight extends deviceBase {
585
536
  });
586
537
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${bodyChange},`);
587
538
  try {
588
- const { body, statusCode } = await request(`${Devices}/${this.device.deviceId}/commands`, {
589
- body: bodyChange,
590
- method: 'POST',
591
- headers: this.platform.generateHeaders(),
592
- });
593
- this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} statusCode: ${statusCode}`);
539
+ const { body, statusCode } = await this.pushChangeRequest(bodyChange);
594
540
  const deviceStatus: any = await body.json();
595
- this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} deviceStatus: ${JSON.stringify(deviceStatus)}`);
596
- this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} deviceStatus body: ${JSON.stringify(deviceStatus.body)}`);
597
- this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} deviceStatus statusCode: ${deviceStatus.statusCode}`);
541
+ await this.pushStatusCodes(statusCode, deviceStatus);
598
542
  if ((statusCode === 200 || statusCode === 100) && (deviceStatus.statusCode === 200 || deviceStatus.statusCode === 100)) {
599
- this.debugSuccessLog(`${this.device.deviceType}: ${this.accessory.displayName} `
600
- + `statusCode: ${statusCode} & deviceStatus StatusCode: ${deviceStatus.statusCode}`);
543
+ await this.successfulPushChange(statusCode, deviceStatus, bodyChange);
544
+ await this.updateHomeKitCharacteristics();
601
545
  } else {
602
- this.statusCode(statusCode);
603
- this.statusCode(deviceStatus.statusCode);
546
+ await this.statusCode(statusCode);
547
+ await this.statusCode(deviceStatus.statusCode);
604
548
  }
605
549
  } catch (e: any) {
606
550
  this.apiError(e);
@@ -623,24 +567,15 @@ export class CeilingLight extends deviceBase {
623
567
  });
624
568
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${bodyChange},`);
625
569
  try {
626
- const { body, statusCode } = await request(`${Devices}/${this.device.deviceId}/commands`, {
627
- body: bodyChange,
628
- method: 'POST',
629
- headers: this.platform.generateHeaders(),
630
- });
631
- this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} statusCode: ${statusCode}`);
570
+ const { body, statusCode } = await this.pushChangeRequest(bodyChange);
632
571
  const deviceStatus: any = await body.json();
633
- this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} deviceStatus: ${JSON.stringify(deviceStatus)}`);
634
- this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} deviceStatus body: ${JSON.stringify(deviceStatus.body)}`);
635
- this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} deviceStatus statusCode: ${deviceStatus.statusCode}`);
572
+ await this.pushStatusCodes(statusCode, deviceStatus);
636
573
  if ((statusCode === 200 || statusCode === 100) && (deviceStatus.statusCode === 200 || deviceStatus.statusCode === 100)) {
637
- this.debugSuccessLog(`${this.device.deviceType}: ${this.accessory.displayName} `
638
- + `statusCode: ${statusCode} & deviceStatus StatusCode: ${deviceStatus.statusCode}`);
639
- this.successLog(`${this.device.deviceType}: ${this.accessory.displayName} `
640
- + `request to SwitchBot API, body: ${JSON.stringify(JSON.parse(bodyChange))} sent successfully`);
574
+ await this.successfulPushChange(statusCode, deviceStatus, bodyChange);
575
+ await this.updateHomeKitCharacteristics();
641
576
  } else {
642
- this.statusCode(statusCode);
643
- this.statusCode(deviceStatus.statusCode);
577
+ await this.statusCode(statusCode);
578
+ await this.statusCode(deviceStatus.statusCode);
644
579
  }
645
580
  } catch (e: any) {
646
581
  this.apiError(e);
@@ -754,42 +689,21 @@ export class CeilingLight extends deviceBase {
754
689
  }
755
690
 
756
691
  async updateHomeKitCharacteristics(): Promise<void> {
757
- if (this.LightBulb.On === undefined) {
758
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} On: ${this.LightBulb.On}`);
759
- } else {
760
- this.accessory.context.On = this.LightBulb.On;
761
- this.LightBulb!.Service.updateCharacteristic(this.hap.Characteristic.On, this.LightBulb.On);
762
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic On: ${this.LightBulb.On}`);
763
- }
764
- if (this.LightBulb.Brightness === undefined) {
765
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Brightness: ${this.LightBulb.Brightness}`);
766
- } else {
767
- this.accessory.context.Brightness = this.LightBulb.Brightness;
768
- this.LightBulb!.Service.updateCharacteristic(this.hap.Characteristic.Brightness, this.LightBulb.Brightness);
769
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic Brightness: ${this.LightBulb.Brightness}`);
770
- }
771
- if (this.LightBulb.ColorTemperature === undefined) {
772
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} ColorTemperature: ${this.LightBulb.ColorTemperature}`);
773
- } else {
774
- this.accessory.context.ColorTemperature = this.LightBulb.ColorTemperature;
775
- this.LightBulb!.Service.updateCharacteristic(this.hap.Characteristic.ColorTemperature, this.LightBulb.ColorTemperature);
776
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}`
777
- + ` updateCharacteristic ColorTemperature: ${this.LightBulb.ColorTemperature}`);
778
- }
779
- if (this.LightBulb.Hue === undefined) {
780
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Hue: ${this.LightBulb.Hue}`);
781
- } else {
782
- this.accessory.context.Hue = this.LightBulb.Hue;
783
- this.LightBulb!.Service.updateCharacteristic(this.hap.Characteristic.Hue, this.LightBulb.Hue);
784
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic Hue: ${this.LightBulb.Hue}`);
785
- }
786
- if (this.LightBulb.Saturation === undefined) {
787
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Saturation: ${this.LightBulb.Saturation}`);
788
- } else {
789
- this.accessory.context.Saturation = this.LightBulb.Saturation;
790
- this.LightBulb!.Service.updateCharacteristic(this.hap.Characteristic.Saturation, this.LightBulb.Saturation);
791
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic Saturation: ${this.LightBulb.Saturation}`);
792
- }
692
+ // On
693
+ await this.updateCharacteristic(this.LightBulb.Service, this.hap.Characteristic.On,
694
+ this.LightBulb.On, 'On');
695
+ // Brightness
696
+ await this.updateCharacteristic(this.LightBulb.Service, this.hap.Characteristic.Brightness,
697
+ this.LightBulb.Brightness, 'Brightness');
698
+ // ColorTemperature
699
+ await this.updateCharacteristic(this.LightBulb.Service, this.hap.Characteristic.ColorTemperature,
700
+ this.LightBulb.ColorTemperature, 'ColorTemperature');
701
+ // Hue
702
+ await this.updateCharacteristic(this.LightBulb.Service, this.hap.Characteristic.Hue,
703
+ this.LightBulb.Hue, 'Hue');
704
+ // Saturation
705
+ await this.updateCharacteristic(this.LightBulb.Service, this.hap.Characteristic.Saturation,
706
+ this.LightBulb.Saturation, 'Saturation');
793
707
  }
794
708
 
795
709
  async adaptiveLighting(device: device & devicesConfig): Promise<void> {
@@ -824,7 +738,7 @@ export class CeilingLight extends deviceBase {
824
738
  }
825
739
  }
826
740
 
827
- apiError(e: any): void {
741
+ async apiError(e: any): Promise<void> {
828
742
  this.LightBulb!.Service.updateCharacteristic(this.hap.Characteristic.On, e);
829
743
  this.LightBulb!.Service.updateCharacteristic(this.hap.Characteristic.Hue, e);
830
744
  this.LightBulb!.Service.updateCharacteristic(this.hap.Characteristic.Brightness, e);