@switchbot/homebridge-switchbot 3.5.0-beta.26 → 3.5.0-beta.28

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 (108) hide show
  1. package/dist/device/blindtilt.d.ts.map +1 -1
  2. package/dist/device/blindtilt.js +19 -16
  3. package/dist/device/blindtilt.js.map +1 -1
  4. package/dist/device/bot.js +15 -15
  5. package/dist/device/bot.js.map +1 -1
  6. package/dist/device/ceilinglight.js +8 -8
  7. package/dist/device/ceilinglight.js.map +1 -1
  8. package/dist/device/colorbulb.js +4 -4
  9. package/dist/device/colorbulb.js.map +1 -1
  10. package/dist/device/contact.js +6 -6
  11. package/dist/device/contact.js.map +1 -1
  12. package/dist/device/curtain.d.ts.map +1 -1
  13. package/dist/device/curtain.js +13 -13
  14. package/dist/device/curtain.js.map +1 -1
  15. package/dist/device/device.d.ts +2 -1
  16. package/dist/device/device.d.ts.map +1 -1
  17. package/dist/device/device.js +10 -3
  18. package/dist/device/device.js.map +1 -1
  19. package/dist/device/hub.d.ts.map +1 -1
  20. package/dist/device/hub.js +7 -7
  21. package/dist/device/hub.js.map +1 -1
  22. package/dist/device/humidifier.js +5 -5
  23. package/dist/device/humidifier.js.map +1 -1
  24. package/dist/device/iosensor.js +6 -6
  25. package/dist/device/iosensor.js.map +1 -1
  26. package/dist/device/lightstrip.js +4 -4
  27. package/dist/device/lightstrip.js.map +1 -1
  28. package/dist/device/lock.js +7 -7
  29. package/dist/device/lock.js.map +1 -1
  30. package/dist/device/meter.js +6 -6
  31. package/dist/device/meter.js.map +1 -1
  32. package/dist/device/meterplus.js +6 -6
  33. package/dist/device/meterplus.js.map +1 -1
  34. package/dist/device/motion.js +6 -7
  35. package/dist/device/motion.js.map +1 -1
  36. package/dist/device/plug.js +4 -4
  37. package/dist/device/plug.js.map +1 -1
  38. package/dist/device/robotvacuumcleaner.js +6 -6
  39. package/dist/device/robotvacuumcleaner.js.map +1 -1
  40. package/dist/device/waterdetector.d.ts.map +1 -1
  41. package/dist/device/waterdetector.js +10 -17
  42. package/dist/device/waterdetector.js.map +1 -1
  43. package/dist/irdevice/airconditioner.d.ts +4 -14
  44. package/dist/irdevice/airconditioner.d.ts.map +1 -1
  45. package/dist/irdevice/airconditioner.js +227 -235
  46. package/dist/irdevice/airconditioner.js.map +1 -1
  47. package/dist/irdevice/airpurifier.d.ts +3 -6
  48. package/dist/irdevice/airpurifier.d.ts.map +1 -1
  49. package/dist/irdevice/airpurifier.js +66 -57
  50. package/dist/irdevice/airpurifier.js.map +1 -1
  51. package/dist/irdevice/camera.d.ts +2 -3
  52. package/dist/irdevice/camera.d.ts.map +1 -1
  53. package/dist/irdevice/camera.js +25 -28
  54. package/dist/irdevice/camera.js.map +1 -1
  55. package/dist/irdevice/fan.d.ts +2 -7
  56. package/dist/irdevice/fan.d.ts.map +1 -1
  57. package/dist/irdevice/fan.js +58 -62
  58. package/dist/irdevice/fan.js.map +1 -1
  59. package/dist/irdevice/irdevice.d.ts +2 -1
  60. package/dist/irdevice/irdevice.d.ts.map +1 -1
  61. package/dist/irdevice/irdevice.js +10 -3
  62. package/dist/irdevice/irdevice.js.map +1 -1
  63. package/dist/irdevice/light.d.ts +1 -1
  64. package/dist/irdevice/light.d.ts.map +1 -1
  65. package/dist/irdevice/light.js +14 -16
  66. package/dist/irdevice/light.js.map +1 -1
  67. package/dist/irdevice/other.js +52 -51
  68. package/dist/irdevice/other.js.map +1 -1
  69. package/dist/irdevice/tv.js +3 -3
  70. package/dist/irdevice/tv.js.map +1 -1
  71. package/dist/irdevice/vacuumcleaner.js +2 -2
  72. package/dist/irdevice/vacuumcleaner.js.map +1 -1
  73. package/dist/irdevice/waterheater.js +2 -2
  74. package/dist/irdevice/waterheater.js.map +1 -1
  75. package/dist/platform.d.ts.map +1 -1
  76. package/dist/platform.js +22 -1
  77. package/dist/platform.js.map +1 -1
  78. package/package.json +2 -2
  79. package/src/custom.d.ts +1 -0
  80. package/src/device/blindtilt.ts +22 -20
  81. package/src/device/bot.ts +16 -16
  82. package/src/device/ceilinglight.ts +9 -9
  83. package/src/device/colorbulb.ts +5 -5
  84. package/src/device/contact.ts +7 -7
  85. package/src/device/curtain.ts +15 -14
  86. package/src/device/device.ts +11 -3
  87. package/src/device/hub.ts +8 -7
  88. package/src/device/humidifier.ts +6 -6
  89. package/src/device/iosensor.ts +7 -7
  90. package/src/device/lightstrip.ts +5 -5
  91. package/src/device/lock.ts +8 -8
  92. package/src/device/meter.ts +7 -7
  93. package/src/device/meterplus.ts +7 -7
  94. package/src/device/motion.ts +7 -7
  95. package/src/device/plug.ts +5 -5
  96. package/src/device/robotvacuumcleaner.ts +7 -7
  97. package/src/device/waterdetector.ts +10 -18
  98. package/src/irdevice/airconditioner.ts +240 -239
  99. package/src/irdevice/airpurifier.ts +76 -57
  100. package/src/irdevice/camera.ts +28 -28
  101. package/src/irdevice/fan.ts +64 -64
  102. package/src/irdevice/irdevice.ts +11 -3
  103. package/src/irdevice/light.ts +18 -16
  104. package/src/irdevice/other.ts +52 -52
  105. package/src/irdevice/tv.ts +3 -3
  106. package/src/irdevice/vacuumcleaner.ts +2 -2
  107. package/src/irdevice/waterheater.ts +2 -2
  108. package/src/platform.ts +21 -4
@@ -60,34 +60,34 @@ export class BlindTilt extends deviceBase {
60
60
  this.blindTiltUpdateInProgress = false;
61
61
  this.setNewTarget = false;
62
62
 
63
- // Retrieve initial values and updateHomekit
64
- this.refreshStatus();
65
-
66
63
  // Initialize LightBulb property
67
64
  this.WindowCovering = {
68
- Service: this.accessory.addService(this.hap.Service.WindowCovering),
69
- PositionState: this.accessory.context.PositionState || this.hap.Characteristic.PositionState.STOPPED,
70
- TargetPosition: this.accessory.context.TargetPosition || 100,
71
- CurrentPosition: this.accessory.context.CurrentPosition || 100,
72
- TargetHorizontalTiltAngle: this.accessory.context.TargetHorizontalTiltAngle || 0,
73
- CurrentHorizontalTiltAngle: this.accessory.context.CurrentHorizontalTiltAngle || 0,
65
+ Service: accessory.getService(this.hap.Service.WindowCovering)!,
66
+ PositionState: accessory.context.PositionState || this.hap.Characteristic.PositionState.STOPPED,
67
+ TargetPosition: accessory.context.TargetPosition || 100,
68
+ CurrentPosition: accessory.context.CurrentPosition || 100,
69
+ TargetHorizontalTiltAngle: accessory.context.TargetHorizontalTiltAngle || 0,
70
+ CurrentHorizontalTiltAngle: accessory.context.CurrentHorizontalTiltAngle || 0,
74
71
  };
75
72
 
76
73
  // Initialize Battery property
77
74
  this.Battery = {
78
- Service: this.accessory.addService(this.hap.Service.Battery),
79
- BatteryLevel: this.accessory.context.BatteryLevel || 100,
75
+ Service: accessory.getService(this.hap.Service.Battery)!,
76
+ BatteryLevel: accessory.context.BatteryLevel || 100,
80
77
  StatusLowBattery: this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL,
81
78
  };
82
79
 
83
80
  // Initialize LightSensor property
84
81
  if (!this.device.blindTilt?.hide_lightsensor) {
85
82
  this.LightSensor = {
86
- Service: this.accessory.addService(this.hap.Service.LightSensor),
87
- CurrentAmbientLightLevel: this.accessory.context.CurrentAmbientLightLevel || 0,
83
+ Service: accessory.getService(this.hap.Service.LightSensor)!,
84
+ CurrentAmbientLightLevel: accessory.context.CurrentAmbientLightLevel || 0.0001,
88
85
  };
89
86
  }
90
87
 
88
+ // Retrieve initial values and updateHomekit
89
+ this.refreshStatus();
90
+
91
91
  // get the WindowCovering service if it exists, otherwise create a new WindowCovering service
92
92
  // you can create multiple services for each accessory
93
93
  (this.WindowCovering!.Service =
@@ -262,16 +262,18 @@ export class BlindTilt extends deviceBase {
262
262
  this.WindowCovering.PositionState = this.hap.Characteristic.PositionState.STOPPED;
263
263
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Stopped`);
264
264
  }
265
- this.debugLog(
266
- `${this.device.deviceType}: ${this.accessory.displayName} CurrentPosition: ${this.WindowCovering.CurrentPosition},` +
267
- ` TargetPosition: ${this.WindowCovering.TargetPosition}, PositionState: ${this.WindowCovering.PositionState},`,
268
- );
265
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} CurrentPosition: ${this.WindowCovering.CurrentPosition},`
266
+ + ` TargetPosition: ${this.WindowCovering.TargetPosition}, PositionState: ${this.WindowCovering.PositionState},`);
269
267
 
270
268
  if (!this.device.blindTilt?.hide_lightsensor) {
271
269
  const set_minLux = await this.minLux();
272
270
  const set_maxLux = await this.maxLux();
273
271
  const spaceBetweenLevels = 9;
274
272
 
273
+ if (this.LightSensor?.CurrentAmbientLightLevel === 0) {
274
+ this.LightSensor!.CurrentAmbientLightLevel = 0.0001;
275
+ }
276
+
275
277
  // Brightness
276
278
  switch (serviceData.lightLevel) {
277
279
  case 1:
@@ -347,7 +349,7 @@ export class BlindTilt extends deviceBase {
347
349
  String(deviceStatus.body.direction));
348
350
  this.debugLog(` device: ${deviceStatus.body.slidePosition} => HK: ${homekitPosition}`);
349
351
 
350
- this.WindowCovering.CurrentPosition = homekitPosition;
352
+ this.WindowCovering!.CurrentPosition = homekitPosition;
351
353
  // CurrentPosition
352
354
  await this.setMinMax();
353
355
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} CurrentPosition: ${this.WindowCovering.CurrentPosition}`);
@@ -500,7 +502,7 @@ export class BlindTilt extends deviceBase {
500
502
  this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} deviceStatus: ${JSON.stringify(deviceStatus)}`);
501
503
  this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} deviceStatus statusCode: ${deviceStatus.statusCode}`);
502
504
  if ((statusCode === 200 || statusCode === 100) && (deviceStatus.statusCode === 200 || deviceStatus.statusCode === 100)) {
503
- this.debugErrorLog(`${this.device.deviceType}: ${this.accessory.displayName} `
505
+ this.debugSuccessLog(`${this.device.deviceType}: ${this.accessory.displayName} `
504
506
  + `statusCode: ${statusCode} & deviceStatus StatusCode: ${deviceStatus.statusCode}`);
505
507
  this.openAPIparseStatus(deviceStatus);
506
508
  this.updateHomeKitCharacteristics();
@@ -632,7 +634,7 @@ export class BlindTilt extends deviceBase {
632
634
  this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} deviceStatus body: ${JSON.stringify(deviceStatus.body)}`);
633
635
  this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} deviceStatus statusCode: ${deviceStatus.statusCode}`);
634
636
  if ((statusCode === 200 || statusCode === 100) && (deviceStatus.statusCode === 200 || deviceStatus.statusCode === 100)) {
635
- this.debugErrorLog(`${this.device.deviceType}: ${this.accessory.displayName} `
637
+ this.debugSuccessLog(`${this.device.deviceType}: ${this.accessory.displayName} `
636
638
  + `statusCode: ${statusCode} & deviceStatus StatusCode: ${deviceStatus.statusCode}`);
637
639
  this.successLog(`${this.device.deviceType}: ${this.accessory.displayName} `
638
640
  + `request to SwitchBot API, body: ${bodyChange} sent successfully`);
package/src/device/bot.ts CHANGED
@@ -98,12 +98,9 @@ export class Bot extends deviceBase {
98
98
  this.doBotUpdate = new Subject();
99
99
  this.botUpdateInProgress = false;
100
100
 
101
- // Retrieve initial values and updateHomekit
102
- this.refreshStatus();
103
-
104
101
  // Initialize Battery property
105
102
  this.Battery = {
106
- Service: accessory.addService(this.hap.Service.Battery),
103
+ Service: accessory.getService(this.hap.Service.Battery)!,
107
104
  BatteryLevel: accessory.context.BatteryLevel || 100,
108
105
  StatusLowBattery: accessory.context.StatusLowBattery || this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL,
109
106
  };
@@ -112,7 +109,7 @@ export class Bot extends deviceBase {
112
109
  if (this.botDeviceType === 'switch') {
113
110
  // Initialize Switch property
114
111
  this.Switch = {
115
- Service: this.accessory.addService(this.hap.Service.Switch),
112
+ Service: accessory.getService(this.hap.Service.Switch)!,
116
113
  On: accessory.context.On || false,
117
114
  };
118
115
  this.removeFanService(accessory);
@@ -136,7 +133,7 @@ export class Bot extends deviceBase {
136
133
  } else if (this.botDeviceType === 'garagedoor') {
137
134
  // Initialize Switch property
138
135
  this.GarageDoor = {
139
- Service: this.accessory.addService(this.hap.Service.GarageDoorOpener),
136
+ Service: accessory.getService(this.hap.Service.GarageDoorOpener)!,
140
137
  On: accessory.context.On || false,
141
138
  };
142
139
  this.removeFanService(accessory);
@@ -161,7 +158,7 @@ export class Bot extends deviceBase {
161
158
  } else if (this.botDeviceType === 'door') {
162
159
  // Initialize Switch property
163
160
  this.Door = {
164
- Service: this.accessory.addService(this.hap.Service.Door),
161
+ Service: accessory.getService(this.hap.Service.Door)!,
165
162
  On: accessory.context.On || false,
166
163
  };
167
164
  this.removeFanService(accessory);
@@ -194,7 +191,7 @@ export class Bot extends deviceBase {
194
191
  } else if (this.botDeviceType === 'window') {
195
192
  // Initialize Switch property
196
193
  this.Window = {
197
- Service: this.accessory.addService(this.hap.Service.Window),
194
+ Service: accessory.getService(this.hap.Service.Window)!,
198
195
  On: accessory.context.On || false,
199
196
  };
200
197
  this.removeFanService(accessory);
@@ -227,7 +224,7 @@ export class Bot extends deviceBase {
227
224
  } else if (this.botDeviceType === 'windowcovering') {
228
225
  // Initialize Switch property
229
226
  this.WindowCovering = {
230
- Service: this.accessory.addService(this.hap.Service.WindowCovering),
227
+ Service: accessory.getService(this.hap.Service.WindowCovering)!,
231
228
  On: accessory.context.On || false,
232
229
  };
233
230
  this.removeFanService(accessory);
@@ -260,7 +257,7 @@ export class Bot extends deviceBase {
260
257
  } else if (this.botDeviceType === 'lock') {
261
258
  // Initialize Switch property
262
259
  this.Lock = {
263
- Service: this.accessory.addService(this.hap.Service.LockMechanism),
260
+ Service: accessory.getService(this.hap.Service.LockMechanism)!,
264
261
  On: accessory.context.On || false,
265
262
  };
266
263
  this.removeFanService(accessory);
@@ -284,7 +281,7 @@ export class Bot extends deviceBase {
284
281
  } else if (this.botDeviceType === 'faucet') {
285
282
  // Initialize Switch property
286
283
  this.Faucet = {
287
- Service: this.accessory.addService(this.hap.Service.Faucet),
284
+ Service: accessory.getService(this.hap.Service.Faucet)!,
288
285
  On: accessory.context.On || false,
289
286
  };
290
287
  this.removeFanService(accessory);
@@ -308,7 +305,7 @@ export class Bot extends deviceBase {
308
305
  } else if (this.botDeviceType === 'fan') {
309
306
  // Initialize Switch property
310
307
  this.Fan = {
311
- Service: this.accessory.addService(this.hap.Service.Fanv2),
308
+ Service: accessory.getService(this.hap.Service.Fanv2)!,
312
309
  On: accessory.context.On || false,
313
310
  };
314
311
  this.removeLockService(accessory);
@@ -332,7 +329,7 @@ export class Bot extends deviceBase {
332
329
  } else if (this.botDeviceType === 'stateful') {
333
330
  // Initialize Switch property
334
331
  this.StatefulProgrammableSwitch = {
335
- Service: this.accessory.addService(this.hap.Service.StatefulProgrammableSwitch),
332
+ Service: accessory.getService(this.hap.Service.StatefulProgrammableSwitch)!,
336
333
  On: accessory.context.On || false,
337
334
  };
338
335
  this.removeFanService(accessory);
@@ -358,7 +355,7 @@ export class Bot extends deviceBase {
358
355
  } else {
359
356
  // Initialize Switch property
360
357
  this.Outlet = {
361
- Service: this.accessory.addService(this.hap.Service.Outlet),
358
+ Service: accessory.getService(this.hap.Service.Outlet)!,
362
359
  On: accessory.context.On || false,
363
360
  };
364
361
  this.removeFanService(accessory);
@@ -381,6 +378,9 @@ export class Bot extends deviceBase {
381
378
  this.Outlet!.Service.getCharacteristic(this.hap.Characteristic.On).onSet(this.OnSet.bind(this));
382
379
  }
383
380
 
381
+ // Retrieve initial values and updateHomekit
382
+ this.refreshStatus();
383
+
384
384
  // batteryService
385
385
  const batteryService = `${accessory.displayName} Battery`;
386
386
  (this.Battery.Service = this.accessory.getService(this.hap.Service.Battery)
@@ -588,7 +588,7 @@ export class Bot extends deviceBase {
588
588
  this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} deviceStatus: ${JSON.stringify(deviceStatus)}`);
589
589
  this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} deviceStatus statusCode: ${deviceStatus.statusCode}`);
590
590
  if ((statusCode === 200 || statusCode === 100) && (deviceStatus.statusCode === 200 || deviceStatus.statusCode === 100)) {
591
- this.debugErrorLog(`${this.device.deviceType}: ${this.accessory.displayName} `
591
+ this.debugSuccessLog(`${this.device.deviceType}: ${this.accessory.displayName} `
592
592
  + `statusCode: ${statusCode} & deviceStatus StatusCode: ${deviceStatus.statusCode}`);
593
593
  this.openAPIparseStatus(deviceStatus);
594
594
  this.updateHomeKitCharacteristics();
@@ -754,7 +754,7 @@ export class Bot extends deviceBase {
754
754
  this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} deviceStatus body: ${JSON.stringify(deviceStatus.body)}`);
755
755
  this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} deviceStatus statusCode: ${deviceStatus.statusCode}`);
756
756
  if ((statusCode === 200 || statusCode === 100) && (deviceStatus.statusCode === 200 || deviceStatus.statusCode === 100)) {
757
- this.debugErrorLog(`${this.device.deviceType}: ${this.accessory.displayName} `
757
+ this.debugSuccessLog(`${this.device.deviceType}: ${this.accessory.displayName} `
758
758
  + `statusCode: ${statusCode} & deviceStatus StatusCode: ${deviceStatus.statusCode}`);
759
759
  this.successLog(`${this.device.deviceType}: ${this.accessory.displayName} `
760
760
  + `request to SwitchBot API, body: ${bodyChange} sent successfully`);
@@ -48,12 +48,9 @@ export class CeilingLight extends deviceBase {
48
48
  this.doCeilingLightUpdate = new Subject();
49
49
  this.ceilingLightUpdateInProgress = false;
50
50
 
51
- // Retrieve initial values and updateHomekit
52
- this.refreshStatus();
53
-
54
51
  // Initialize LightBulb property
55
52
  this.LightBulb = {
56
- Service: this.accessory.addService(this.hap.Service.Lightbulb),
53
+ Service: accessory.getService(this.hap.Service.Lightbulb)!,
57
54
  On: accessory.context.On || false,
58
55
  Hue: accessory.context.Hue || 0,
59
56
  Saturation: accessory.context.Saturation || 0,
@@ -61,6 +58,9 @@ export class CeilingLight extends deviceBase {
61
58
  ColorTemperature: accessory.context.ColorTemperature || 140,
62
59
  };
63
60
 
61
+ // Retrieve initial values and updateHomekit
62
+ this.refreshStatus();
63
+
64
64
  const LightBulbService = `${accessory.displayName} ${device.deviceType}`;
65
65
  (this.LightBulb!.Service = accessory.getService(this.hap.Service.Lightbulb)
66
66
  || accessory.addService(this.hap.Service.Lightbulb)), LightBulbService;
@@ -336,7 +336,7 @@ export class CeilingLight extends deviceBase {
336
336
  this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} deviceStatus: ${JSON.stringify(deviceStatus)}`);
337
337
  this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} deviceStatus statusCode: ${deviceStatus.statusCode}`);
338
338
  if ((statusCode === 200 || statusCode === 100) && (deviceStatus.statusCode === 200 || deviceStatus.statusCode === 100)) {
339
- this.debugErrorLog(`${this.device.deviceType}: ${this.accessory.displayName} `
339
+ this.debugSuccessLog(`${this.device.deviceType}: ${this.accessory.displayName} `
340
340
  + `statusCode: ${statusCode} & deviceStatus StatusCode: ${deviceStatus.statusCode}`);
341
341
  this.openAPIparseStatus(deviceStatus);
342
342
  this.updateHomeKitCharacteristics();
@@ -465,7 +465,7 @@ export class CeilingLight extends deviceBase {
465
465
  this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} deviceStatus body: ${JSON.stringify(deviceStatus.body)}`);
466
466
  this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} deviceStatus statusCode: ${deviceStatus.statusCode}`);
467
467
  if ((statusCode === 200 || statusCode === 100) && (deviceStatus.statusCode === 200 || deviceStatus.statusCode === 100)) {
468
- this.debugErrorLog(`${this.device.deviceType}: ${this.accessory.displayName} `
468
+ this.debugSuccessLog(`${this.device.deviceType}: ${this.accessory.displayName} `
469
469
  + `statusCode: ${statusCode} & deviceStatus StatusCode: ${deviceStatus.statusCode}`);
470
470
  this.successLog(`${this.device.deviceType}: ${this.accessory.displayName} `
471
471
  + `request to SwitchBot API, body: ${bodyChange} sent successfully`);
@@ -526,7 +526,7 @@ export class CeilingLight extends deviceBase {
526
526
  this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} deviceStatus body: ${JSON.stringify(deviceStatus.body)}`);
527
527
  this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} deviceStatus statusCode: ${deviceStatus.statusCode}`);
528
528
  if ((statusCode === 200 || statusCode === 100) && (deviceStatus.statusCode === 200 || deviceStatus.statusCode === 100)) {
529
- this.debugErrorLog(`${this.device.deviceType}: ${this.accessory.displayName} `
529
+ this.debugSuccessLog(`${this.device.deviceType}: ${this.accessory.displayName} `
530
530
  + `statusCode: ${statusCode} & deviceStatus StatusCode: ${deviceStatus.statusCode}`);
531
531
  this.successLog(`${this.device.deviceType}: ${this.accessory.displayName} `
532
532
  + `request to SwitchBot API, body: ${bodyChange} sent successfully`);
@@ -572,7 +572,7 @@ export class CeilingLight extends deviceBase {
572
572
  this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} deviceStatus body: ${JSON.stringify(deviceStatus.body)}`);
573
573
  this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} deviceStatus statusCode: ${deviceStatus.statusCode}`);
574
574
  if ((statusCode === 200 || statusCode === 100) && (deviceStatus.statusCode === 200 || deviceStatus.statusCode === 100)) {
575
- this.debugErrorLog(`${this.device.deviceType}: ${this.accessory.displayName} `
575
+ this.debugSuccessLog(`${this.device.deviceType}: ${this.accessory.displayName} `
576
576
  + `statusCode: ${statusCode} & deviceStatus StatusCode: ${deviceStatus.statusCode}`);
577
577
  } else {
578
578
  this.statusCode(statusCode);
@@ -614,7 +614,7 @@ export class CeilingLight extends deviceBase {
614
614
  this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} deviceStatus body: ${JSON.stringify(deviceStatus.body)}`);
615
615
  this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} deviceStatus statusCode: ${deviceStatus.statusCode}`);
616
616
  if ((statusCode === 200 || statusCode === 100) && (deviceStatus.statusCode === 200 || deviceStatus.statusCode === 100)) {
617
- this.debugErrorLog(`${this.device.deviceType}: ${this.accessory.displayName} `
617
+ this.debugSuccessLog(`${this.device.deviceType}: ${this.accessory.displayName} `
618
618
  + `statusCode: ${statusCode} & deviceStatus StatusCode: ${deviceStatus.statusCode}`);
619
619
  this.successLog(`${this.device.deviceType}: ${this.accessory.displayName} `
620
620
  + `request to SwitchBot API, body: ${bodyChange} sent successfully`);
@@ -49,12 +49,9 @@ export class ColorBulb extends deviceBase {
49
49
  this.doColorBulbUpdate = new Subject();
50
50
  this.colorBulbUpdateInProgress = false;
51
51
 
52
- // Retrieve initial values and updateHomekit
53
- this.refreshStatus();
54
-
55
52
  // Initialize LightBulb property
56
53
  this.LightBulb = {
57
- Service: this.accessory.addService(this.hap.Service.Lightbulb),
54
+ Service: accessory.getService(this.hap.Service.Lightbulb)!,
58
55
  On: accessory.context.On || false,
59
56
  Hue: accessory.context.Hue || 0,
60
57
  Saturation: accessory.context.Saturation || 0,
@@ -62,6 +59,9 @@ export class ColorBulb extends deviceBase {
62
59
  ColorTemperature: accessory.context.ColorTemperature || 140,
63
60
  };
64
61
 
62
+ // Retrieve initial values and updateHomekit
63
+ this.refreshStatus();
64
+
65
65
  // get the Lightbulb service if it exists, otherwise create a new Lightbulb service
66
66
  // you can create multiple services for each accessory
67
67
  const lightBulbService = `${accessory.displayName} ${device.deviceType}`;
@@ -404,7 +404,7 @@ export class ColorBulb extends deviceBase {
404
404
  this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} deviceStatus: ${JSON.stringify(deviceStatus)}`);
405
405
  this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} deviceStatus statusCode: ${deviceStatus.statusCode}`);
406
406
  if ((statusCode === 200 || statusCode === 100) && (deviceStatus.statusCode === 200 || deviceStatus.statusCode === 100)) {
407
- this.debugErrorLog(`${this.device.deviceType}: ${this.accessory.displayName} `
407
+ this.debugSuccessLog(`${this.device.deviceType}: ${this.accessory.displayName} `
408
408
  + `statusCode: ${statusCode} & deviceStatus StatusCode: ${deviceStatus.statusCode}`);
409
409
  this.openAPIparseStatus(deviceStatus);
410
410
  this.updateHomeKitCharacteristics();
@@ -51,19 +51,16 @@ export class Contact extends deviceBase {
51
51
  this.doContactUpdate = new Subject();
52
52
  this.contactUpdateInProgress = false;
53
53
 
54
- // Retrieve initial values and updateHomekit
55
- this.refreshStatus();
56
-
57
54
  // Initialize Contact Sensor property
58
55
  this.ContactSensor = {
59
- Service: this.accessory.addService(this.hap.Service.ContactSensor),
56
+ Service: accessory.getService(this.hap.Service.ContactSensor)!,
60
57
  ContactSensorState: this.hap.Characteristic.ContactSensorState.CONTACT_DETECTED,
61
58
  };
62
59
 
63
60
  // Initialize Motion Sensor property
64
61
  if (!this.device.contact?.hide_motionsensor) {
65
62
  this.MotionSensor = {
66
- Service: this.accessory.addService(this.hap.Service.MotionSensor),
63
+ Service: accessory.getService(this.hap.Service.MotionSensor)!,
67
64
  MotionDetected: false,
68
65
  };
69
66
  }
@@ -71,11 +68,14 @@ export class Contact extends deviceBase {
71
68
  // Initialize Light Sensor property
72
69
  if (!this.device.contact?.hide_lightsensor) {
73
70
  this.LightSensor = {
74
- Service: this.accessory.addService(this.hap.Service.LightSensor),
71
+ Service: accessory.getService(this.hap.Service.LightSensor)!,
75
72
  CurrentAmbientLightLevel: 0,
76
73
  };
77
74
  }
78
75
 
76
+ // Retrieve initial values and updateHomekit
77
+ this.refreshStatus();
78
+
79
79
  // get the Contact service if it exists, otherwise create a new Contact service
80
80
  // you can create multiple services for each accessory
81
81
  const ContactSensorService = `${accessory.displayName} Contact Sensor`;
@@ -348,7 +348,7 @@ export class Contact extends deviceBase {
348
348
  this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} deviceStatus: ${JSON.stringify(deviceStatus)}`);
349
349
  this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} deviceStatus statusCode: ${deviceStatus.statusCode}`);
350
350
  if ((statusCode === 200 || statusCode === 100) && (deviceStatus.statusCode === 200 || deviceStatus.statusCode === 100)) {
351
- this.debugErrorLog(`${this.device.deviceType}: ${this.accessory.displayName} `
351
+ this.debugSuccessLog(`${this.device.deviceType}: ${this.accessory.displayName} `
352
352
  + `statusCode: ${statusCode} & deviceStatus StatusCode: ${deviceStatus.statusCode}`);
353
353
  this.openAPIparseStatus(deviceStatus);
354
354
  this.updateHomeKitCharacteristics();
@@ -53,32 +53,33 @@ export class Curtain extends deviceBase {
53
53
  this.curtainUpdateInProgress = false;
54
54
  this.setNewTarget = false;
55
55
 
56
- // Retrieve initial values and updateHomekit
57
- this.refreshStatus();
58
56
  // Initialize LightBulb property
59
57
  this.WindowCovering = {
60
- Service: this.accessory.addService(this.hap.Service.WindowCovering),
61
- PositionState: this.accessory.context.PositionState || this.hap.Characteristic.PositionState.STOPPED,
62
- TargetPosition: this.accessory.context.TargetPosition || 100,
63
- CurrentPosition: this.accessory.context.CurrentPosition || 100,
64
- HoldPosition: this.accessory.context.HoldPosition || false,
58
+ Service: accessory.getService(this.hap.Service.WindowCovering)!,
59
+ PositionState: accessory.context.PositionState || this.hap.Characteristic.PositionState.STOPPED,
60
+ TargetPosition: accessory.context.TargetPosition || 100,
61
+ CurrentPosition: accessory.context.CurrentPosition || 100,
62
+ HoldPosition: accessory.context.HoldPosition || false,
65
63
  };
66
64
 
67
65
  // Initialize Battery property
68
66
  this.Battery = {
69
- Service: this.accessory.addService(this.hap.Service.Battery),
70
- BatteryLevel: this.accessory.context.BatteryLevel || 100,
71
- StatusLowBattery: this.accessory.context.StatusLowBattery || this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL,
67
+ Service: accessory.getService(this.hap.Service.Battery)!,
68
+ BatteryLevel: accessory.context.BatteryLevel || 100,
69
+ StatusLowBattery: accessory.context.StatusLowBattery || this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL,
72
70
  };
73
71
 
74
72
  // Initialize LightSensor property
75
73
  if (!this.device.curtain?.hide_lightsensor) {
76
74
  this.LightSensor = {
77
- Service: this.accessory.addService(this.hap.Service.LightSensor),
78
- CurrentAmbientLightLevel: this.accessory.context.CurrentAmbientLightLevel || 0,
75
+ Service: accessory.getService(this.hap.Service.LightSensor)!,
76
+ CurrentAmbientLightLevel: accessory.context.CurrentAmbientLightLevel || 0.0001,
79
77
  };
80
78
  }
81
79
 
80
+ // Retrieve initial values and updateHomekit
81
+ this.refreshStatus();
82
+
82
83
  // get the WindowCovering service if it exists, otherwise create a new WindowCovering service
83
84
  // you can create multiple services for each accessory
84
85
  const WindowCoveringService = `${accessory.displayName} ${device.deviceType}`;
@@ -393,7 +394,7 @@ export class Curtain extends deviceBase {
393
394
  async openAPIparseStatus(deviceStatus: deviceStatus): Promise<void> {
394
395
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIparseStatus`);
395
396
  // CurrentPosition
396
- this.WindowCovering.CurrentPosition = 100 - Number(deviceStatus.body.slidePosition);
397
+ this.WindowCovering!.CurrentPosition = 100 - Number(deviceStatus.body.slidePosition);
397
398
  await this.setMinMax();
398
399
  this.debugLog(`Curtain ${this.accessory.displayName} CurrentPosition: ${this.WindowCovering.CurrentPosition}`);
399
400
  if (this.setNewTarget) {
@@ -529,7 +530,7 @@ export class Curtain extends deviceBase {
529
530
  this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} deviceStatus: ${JSON.stringify(deviceStatus)}`);
530
531
  this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} deviceStatus statusCode: ${deviceStatus.statusCode}`);
531
532
  if ((statusCode === 200 || statusCode === 100) && (deviceStatus.statusCode === 200 || deviceStatus.statusCode === 100)) {
532
- this.debugErrorLog(`${this.device.deviceType}: ${this.accessory.displayName} `
533
+ this.debugSuccessLog(`${this.device.deviceType}: ${this.accessory.displayName} `
533
534
  + `statusCode: ${statusCode} & deviceStatus StatusCode: ${deviceStatus.statusCode}`);
534
535
  this.openAPIparseStatus(deviceStatus);
535
536
  this.updateHomeKitCharacteristics();
@@ -599,15 +599,23 @@ export abstract class deviceBase {
599
599
  /**
600
600
  * Logging for Device
601
601
  */
602
+ infoLog(...log: any[]): void {
603
+ if (this.enablingDeviceLogging()) {
604
+ this.log.info(String(...log));
605
+ }
606
+ }
607
+
602
608
  successLog(...log: any[]): void {
603
609
  if (this.enablingDeviceLogging()) {
604
- this.platform.log.success(String(...log));
610
+ this.log.success(String(...log));
605
611
  }
606
612
  }
607
613
 
608
- infoLog(...log: any[]): void {
614
+ debugSuccessLog(...log: any[]): void {
609
615
  if (this.enablingDeviceLogging()) {
610
- this.log.info(String(...log));
616
+ if (this.deviceLogging?.includes('debug')) {
617
+ this.log.success('[DEBUG]', String(...log));
618
+ }
611
619
  }
612
620
  }
613
621
 
package/src/device/hub.ts CHANGED
@@ -38,13 +38,11 @@ export class Hub extends deviceBase {
38
38
  // this is subject we use to track when we need to POST changes to the SwitchBot API
39
39
  this.doHubUpdate = new Subject();
40
40
  this.hubUpdateInProgress = false;
41
- // Retrieve initial values and updateHomekit
42
- this.refreshStatus();
43
41
 
44
42
  // Initialize Temperature Sensor property
45
43
  if (!device.hub?.hide_temperature) {
46
44
  this.TemperatureSensor = {
47
- Service: this.accessory.addService(this.hap.Service.TemperatureSensor),
45
+ Service: accessory.getService(this.hap.Service.TemperatureSensor)!,
48
46
  CurrentTemperature: accessory.context.CurrentTemperature || 0,
49
47
  };
50
48
  }
@@ -52,7 +50,7 @@ export class Hub extends deviceBase {
52
50
  // Initialize Humidity Sensor property
53
51
  if (!device.hub?.hide_humidity) {
54
52
  this.HumiditySensor = {
55
- Service: this.accessory.addService(this.hap.Service.HumiditySensor),
53
+ Service: accessory.getService(this.hap.Service.HumiditySensor)!,
56
54
  CurrentRelativeHumidity: accessory.context.CurrentRelativeHumidity || 0,
57
55
  };
58
56
  }
@@ -60,11 +58,14 @@ export class Hub extends deviceBase {
60
58
  // Initialize Light Sensor property
61
59
  if (!device.hub?.hide_lightsensor) {
62
60
  this.LightSensor = {
63
- Service: this.accessory.addService(this.hap.Service.LightSensor),
64
- CurrentAmbientLightLevel: accessory.context.CurrentAmbientLightLevel || 0,
61
+ Service: accessory.getService(this.hap.Service.LightSensor)!,
62
+ CurrentAmbientLightLevel: accessory.context.CurrentAmbientLightLevel || 0.0001,
65
63
  };
66
64
  }
67
65
 
66
+ // Retrieve initial values and updateHomekit
67
+ this.refreshStatus();
68
+
68
69
  // Temperature Sensor Service
69
70
  if (device.hub?.hide_temperature) {
70
71
  this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Removing Temperature Sensor Service`);
@@ -239,7 +240,7 @@ export class Hub extends deviceBase {
239
240
  this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} deviceStatus: ${JSON.stringify(deviceStatus)}`);
240
241
  this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} deviceStatus statusCode: ${deviceStatus.statusCode}`);
241
242
  if ((statusCode === 200 || statusCode === 100) && (deviceStatus.statusCode === 200 || deviceStatus.statusCode === 100)) {
242
- this.debugErrorLog(`${this.device.deviceType}: ${this.accessory.displayName} `
243
+ this.debugSuccessLog(`${this.device.deviceType}: ${this.accessory.displayName} `
243
244
  + `statusCode: ${statusCode} & deviceStatus StatusCode: ${deviceStatus.statusCode}`);
244
245
 
245
246
  this.openAPIparseStatus(deviceStatus);
@@ -42,12 +42,9 @@ export class Humidifier extends deviceBase {
42
42
  this.doHumidifierUpdate = new Subject();
43
43
  this.humidifierUpdateInProgress = false;
44
44
 
45
- // Retrieve initial values and updateHomekit
46
- this.refreshStatus();
47
-
48
45
  // Initialize the HumidifierDehumidifier Service
49
46
  this.HumidifierDehumidifier = {
50
- Service: accessory.addService(this.hap.Service.HumidifierDehumidifier),
47
+ Service: accessory.getService(this.hap.Service.HumidifierDehumidifier)!,
51
48
  Active: accessory.context.Active || this.hap.Characteristic.Active.ACTIVE,
52
49
  WaterLevel: accessory.context.WaterLevel || 100,
53
50
  CurrentRelativeHumidity: accessory.context.CurrentRelativeHumidity || 50,
@@ -61,11 +58,14 @@ export class Humidifier extends deviceBase {
61
58
  // Initialize the Temperature Sensor Service
62
59
  if (!device.humidifier?.hide_temperature) {
63
60
  this.TemperatureSensor = {
64
- Service: accessory.addService(this.hap.Service.TemperatureSensor),
61
+ Service: accessory.getService(this.hap.Service.TemperatureSensor)!,
65
62
  CurrentTemperature: accessory.context.CurrentTemperature || 30,
66
63
  };
67
64
  }
68
65
 
66
+ // Retrieve initial values and updateHomekit
67
+ this.refreshStatus();
68
+
69
69
  // get the service if it exists, otherwise create a new service
70
70
  // you can create multiple services for each accessory
71
71
  const HumidifierDehumidifierService = `${accessory.displayName} Humidifier`;
@@ -335,7 +335,7 @@ export class Humidifier extends deviceBase {
335
335
  this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} deviceStatus: ${JSON.stringify(deviceStatus)}`);
336
336
  this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} deviceStatus statusCode: ${deviceStatus.statusCode}`);
337
337
  if ((statusCode === 200 || statusCode === 100) && (deviceStatus.statusCode === 200 || deviceStatus.statusCode === 100)) {
338
- this.debugErrorLog(`${this.device.deviceType}: ${this.accessory.displayName} `
338
+ this.debugSuccessLog(`${this.device.deviceType}: ${this.accessory.displayName} `
339
339
  + `statusCode: ${statusCode} & deviceStatus StatusCode: ${deviceStatus.statusCode}`);
340
340
  this.openAPIparseStatus(deviceStatus);
341
341
  this.updateHomeKitCharacteristics();
@@ -45,13 +45,10 @@ export class IOSensor extends deviceBase {
45
45
  this.doIOSensorUpdate = new Subject();
46
46
  this.ioSensorUpdateInProgress = false;
47
47
 
48
- // Retrieve initial values and updateHomekit
49
- this.refreshStatus();
50
-
51
48
  // Initialize Temperature Sensor property
52
49
  if (!device.iosensor?.hide_temperature) {
53
50
  this.TemperatureSensor = {
54
- Service: this.accessory.addService(this.hap.Service.TemperatureSensor),
51
+ Service: accessory.getService(this.hap.Service.TemperatureSensor)!,
55
52
  CurrentTemperature: accessory.context.CurrentTemperature || 30,
56
53
  };
57
54
  }
@@ -59,18 +56,21 @@ export class IOSensor extends deviceBase {
59
56
  // Initialize Humidity Sensor property
60
57
  if (!device.iosensor?.hide_humidity) {
61
58
  this.HumiditySensor = {
62
- Service: this.accessory.addService(this.hap.Service.HumiditySensor),
59
+ Service: accessory.getService(this.hap.Service.HumiditySensor)!,
63
60
  CurrentRelativeHumidity: accessory.context.CurrentRelativeHumidity || 50,
64
61
  };
65
62
  }
66
63
 
67
64
  // Initialize Battery property
68
65
  this.Battery = {
69
- Service: this.accessory.addService(this.hap.Service.Battery),
66
+ Service: accessory.getService(this.hap.Service.Battery)!,
70
67
  BatteryLevel: accessory.context.BatteryLevel || 100,
71
68
  StatusLowBattery: accessory.context.StatusLowBattery || this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL,
72
69
  };
73
70
 
71
+ // Retrieve initial values and updateHomekit
72
+ this.refreshStatus();
73
+
74
74
  // Temperature Sensor Service
75
75
  if (device.iosensor?.hide_temperature) {
76
76
  this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Removing Temperature Sensor Service`);
@@ -294,7 +294,7 @@ export class IOSensor extends deviceBase {
294
294
  this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} deviceStatus: ${JSON.stringify(deviceStatus)}`);
295
295
  this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} deviceStatus statusCode: ${deviceStatus.statusCode}`);
296
296
  if ((statusCode === 200 || statusCode === 100) && (deviceStatus.statusCode === 200 || deviceStatus.statusCode === 100)) {
297
- this.debugErrorLog(`${this.device.deviceType}: ${this.accessory.displayName} `
297
+ this.debugSuccessLog(`${this.device.deviceType}: ${this.accessory.displayName} `
298
298
  + `statusCode: ${statusCode} & deviceStatus StatusCode: ${deviceStatus.statusCode}`);
299
299
  this.openAPIparseStatus(deviceStatus);
300
300
  this.updateHomeKitCharacteristics();
@@ -42,12 +42,9 @@ export class StripLight extends deviceBase {
42
42
  this.doStripLightUpdate = new Subject();
43
43
  this.stripLightUpdateInProgress = false;
44
44
 
45
- // Retrieve initial values and updateHomekit
46
- this.refreshStatus();
47
-
48
45
  // Initialize the LightBulb property
49
46
  this.LightBulb = {
50
- Service: this.accessory.addService(this.hap.Service.Lightbulb),
47
+ Service: accessory.getService(this.hap.Service.Lightbulb)!,
51
48
  On: accessory.context.On || false,
52
49
  Hue: accessory.context.Hue || 0,
53
50
  Saturation: accessory.context.Saturation || 0,
@@ -55,6 +52,9 @@ export class StripLight extends deviceBase {
55
52
  ColorTemperature: accessory.context.ColorTemperature || 140,
56
53
  };
57
54
 
55
+ // Retrieve initial values and updateHomekit
56
+ this.refreshStatus();
57
+
58
58
  // get the Lightbulb service if it exists, otherwise create a new Lightbulb service
59
59
  // you can create multiple services for each accessory
60
60
  const LightBulbService = `${accessory.displayName} ${device.deviceType}`;
@@ -366,7 +366,7 @@ export class StripLight extends deviceBase {
366
366
  this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} deviceStatus: ${JSON.stringify(deviceStatus)}`);
367
367
  this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} deviceStatus statusCode: ${deviceStatus.statusCode}`);
368
368
  if ((statusCode === 200 || statusCode === 100) && (deviceStatus.statusCode === 200 || deviceStatus.statusCode === 100)) {
369
- this.debugErrorLog(`${this.device.deviceType}: ${this.accessory.displayName} `
369
+ this.debugSuccessLog(`${this.device.deviceType}: ${this.accessory.displayName} `
370
370
  + `statusCode: ${statusCode} & deviceStatus StatusCode: ${deviceStatus.statusCode}`);
371
371
  this.openAPIparseStatus(deviceStatus);
372
372
  this.updateHomeKitCharacteristics();