@switchbot/homebridge-switchbot 3.6.1-beta.1 → 3.6.1-beta.10

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 (100) hide show
  1. package/CHANGELOG.md +11 -0
  2. package/dist/device/blindtilt.d.ts.map +1 -1
  3. package/dist/device/blindtilt.js +35 -17
  4. package/dist/device/blindtilt.js.map +1 -1
  5. package/dist/device/bot.d.ts +1 -2
  6. package/dist/device/bot.d.ts.map +1 -1
  7. package/dist/device/bot.js +186 -396
  8. package/dist/device/bot.js.map +1 -1
  9. package/dist/device/ceilinglight.d.ts +3 -2
  10. package/dist/device/ceilinglight.d.ts.map +1 -1
  11. package/dist/device/ceilinglight.js +56 -31
  12. package/dist/device/ceilinglight.js.map +1 -1
  13. package/dist/device/colorbulb.d.ts +3 -2
  14. package/dist/device/colorbulb.d.ts.map +1 -1
  15. package/dist/device/colorbulb.js +57 -29
  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 +35 -18
  19. package/dist/device/contact.js.map +1 -1
  20. package/dist/device/curtain.d.ts.map +1 -1
  21. package/dist/device/curtain.js +7 -5
  22. package/dist/device/curtain.js.map +1 -1
  23. package/dist/device/device.d.ts +9 -0
  24. package/dist/device/device.d.ts.map +1 -1
  25. package/dist/device/device.js +30 -3
  26. package/dist/device/device.js.map +1 -1
  27. package/dist/device/fan.d.ts.map +1 -1
  28. package/dist/device/fan.js +35 -18
  29. package/dist/device/fan.js.map +1 -1
  30. package/dist/device/hub.d.ts.map +1 -1
  31. package/dist/device/hub.js +37 -18
  32. package/dist/device/hub.js.map +1 -1
  33. package/dist/device/humidifier.d.ts.map +1 -1
  34. package/dist/device/humidifier.js +39 -20
  35. package/dist/device/humidifier.js.map +1 -1
  36. package/dist/device/iosensor.d.ts.map +1 -1
  37. package/dist/device/iosensor.js +37 -18
  38. package/dist/device/iosensor.js.map +1 -1
  39. package/dist/device/lightstrip.d.ts +4 -3
  40. package/dist/device/lightstrip.d.ts.map +1 -1
  41. package/dist/device/lightstrip.js +57 -31
  42. package/dist/device/lightstrip.js.map +1 -1
  43. package/dist/device/lock.d.ts.map +1 -1
  44. package/dist/device/lock.js +36 -17
  45. package/dist/device/lock.js.map +1 -1
  46. package/dist/device/meter.d.ts.map +1 -1
  47. package/dist/device/meter.js +37 -18
  48. package/dist/device/meter.js.map +1 -1
  49. package/dist/device/meterplus.d.ts.map +1 -1
  50. package/dist/device/meterplus.js +37 -18
  51. package/dist/device/meterplus.js.map +1 -1
  52. package/dist/device/motion.d.ts.map +1 -1
  53. package/dist/device/motion.js +35 -16
  54. package/dist/device/motion.js.map +1 -1
  55. package/dist/device/plug.d.ts.map +1 -1
  56. package/dist/device/plug.js +36 -17
  57. package/dist/device/plug.js.map +1 -1
  58. package/dist/device/robotvacuumcleaner.d.ts.map +1 -1
  59. package/dist/device/robotvacuumcleaner.js +35 -16
  60. package/dist/device/robotvacuumcleaner.js.map +1 -1
  61. package/dist/device/waterdetector.d.ts.map +1 -1
  62. package/dist/device/waterdetector.js +35 -16
  63. package/dist/device/waterdetector.js.map +1 -1
  64. package/dist/irdevice/other.d.ts +1 -0
  65. package/dist/irdevice/other.d.ts.map +1 -1
  66. package/dist/irdevice/other.js +186 -228
  67. package/dist/irdevice/other.js.map +1 -1
  68. package/dist/platform.d.ts.map +1 -1
  69. package/dist/platform.js +11 -2
  70. package/dist/platform.js.map +1 -1
  71. package/dist/types/bledevicestatus.d.ts +1 -0
  72. package/dist/types/bledevicestatus.d.ts.map +1 -1
  73. package/dist/utils.d.ts +8 -0
  74. package/dist/utils.d.ts.map +1 -1
  75. package/dist/utils.js +16 -0
  76. package/dist/utils.js.map +1 -1
  77. package/package.json +6 -6
  78. package/src/device/blindtilt.ts +32 -17
  79. package/src/device/bot.ts +179 -406
  80. package/src/device/ceilinglight.ts +53 -33
  81. package/src/device/colorbulb.ts +55 -31
  82. package/src/device/contact.ts +32 -19
  83. package/src/device/curtain.ts +7 -6
  84. package/src/device/device.ts +36 -3
  85. package/src/device/fan.ts +32 -19
  86. package/src/device/hub.ts +34 -18
  87. package/src/device/humidifier.ts +36 -20
  88. package/src/device/iosensor.ts +34 -18
  89. package/src/device/lightstrip.ts +56 -33
  90. package/src/device/lock.ts +33 -17
  91. package/src/device/meter.ts +34 -18
  92. package/src/device/meterplus.ts +34 -18
  93. package/src/device/motion.ts +32 -16
  94. package/src/device/plug.ts +33 -17
  95. package/src/device/robotvacuumcleaner.ts +32 -16
  96. package/src/device/waterdetector.ts +32 -16
  97. package/src/irdevice/other.ts +214 -283
  98. package/src/platform.ts +11 -2
  99. package/src/types/bledevicestatus.ts +1 -0
  100. package/src/utils.ts +15 -0
package/src/platform.ts CHANGED
@@ -330,12 +330,21 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
330
330
  // Set an event handler to monitor advertisement packets
331
331
  switchbot.onadvertisement = async (ad: any) => {
332
332
  try {
333
- this.bleEventHandler[ad.id]?.(ad);
333
+ this.bleEventHandler[ad.address]?.(ad.serviceData);
334
334
  } catch (e: any) {
335
- this.errorLog(`Failed to handle BLE event. Error:${e}`);
335
+ await this.errorLog(`Failed to handle BLE event. Error:${e}`);
336
336
  }
337
337
  };
338
338
  })();
339
+
340
+ this.api.on('shutdown', async () => {
341
+ try {
342
+ switchbot.stopScan();
343
+ this.infoLog('Stopped BLE scanning to close listening.');
344
+ } catch (e: any) {
345
+ this.errorLog(`Failed to stop Platform BLE scanning. Error:${e.message}`);
346
+ }
347
+ });
339
348
  }
340
349
  } else {
341
350
  await this.debugLog('Platform BLE is not enabled');
@@ -291,6 +291,7 @@ export type humidifierServiceData = serviceData & {
291
291
  onState: boolean;
292
292
  autoMode: boolean;
293
293
  percentage: number;
294
+ humidity: number;
294
295
  };
295
296
 
296
297
  export type robotVacuumCleanerServiceData = serviceData & {
package/src/utils.ts CHANGED
@@ -129,6 +129,21 @@ export function isBlindTiltDevice(device: device & devicesConfig): device is bli
129
129
  export function sleep(ms: number): Promise<void> {
130
130
  return new Promise((resolve) => setTimeout(resolve, ms));
131
131
  }
132
+ /**
133
+ * Check if the humidity is within the min and max range
134
+ * @param humidity - The humidity value
135
+ * @param min - The minimum humidity value
136
+ * @param max - The maximum humidity value
137
+ * @returns The humidity value
138
+ **/
139
+ export function validHumidity(humidity: number, min?: number, max?: number): number {
140
+ if (humidity < (min || 0)) {
141
+ return min ?? 0;
142
+ } else if (humidity > (max || 100)) {
143
+ return max ?? 100;
144
+ }
145
+ return humidity;
146
+ }
132
147
 
133
148
  /**
134
149
  * Converts the value to celsius if the temperature units are in Fahrenheit