@switchbot/homebridge-switchbot 3.6.1-beta.0 → 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 (106) hide show
  1. package/CHANGELOG.md +11 -0
  2. package/config.schema.json +11 -0
  3. package/dist/device/blindtilt.d.ts.map +1 -1
  4. package/dist/device/blindtilt.js +36 -18
  5. package/dist/device/blindtilt.js.map +1 -1
  6. package/dist/device/bot.d.ts +1 -2
  7. package/dist/device/bot.d.ts.map +1 -1
  8. package/dist/device/bot.js +186 -396
  9. package/dist/device/bot.js.map +1 -1
  10. package/dist/device/ceilinglight.d.ts +3 -2
  11. package/dist/device/ceilinglight.d.ts.map +1 -1
  12. package/dist/device/ceilinglight.js +57 -32
  13. package/dist/device/ceilinglight.js.map +1 -1
  14. package/dist/device/colorbulb.d.ts +3 -2
  15. package/dist/device/colorbulb.d.ts.map +1 -1
  16. package/dist/device/colorbulb.js +58 -30
  17. package/dist/device/colorbulb.js.map +1 -1
  18. package/dist/device/contact.d.ts.map +1 -1
  19. package/dist/device/contact.js +36 -19
  20. package/dist/device/contact.js.map +1 -1
  21. package/dist/device/curtain.d.ts.map +1 -1
  22. package/dist/device/curtain.js +37 -18
  23. package/dist/device/curtain.js.map +1 -1
  24. package/dist/device/device.d.ts +9 -0
  25. package/dist/device/device.d.ts.map +1 -1
  26. package/dist/device/device.js +32 -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 +36 -19
  30. package/dist/device/fan.js.map +1 -1
  31. package/dist/device/hub.d.ts.map +1 -1
  32. package/dist/device/hub.js +38 -19
  33. package/dist/device/hub.js.map +1 -1
  34. package/dist/device/humidifier.d.ts.map +1 -1
  35. package/dist/device/humidifier.js +40 -21
  36. package/dist/device/humidifier.js.map +1 -1
  37. package/dist/device/iosensor.d.ts.map +1 -1
  38. package/dist/device/iosensor.js +38 -19
  39. package/dist/device/iosensor.js.map +1 -1
  40. package/dist/device/lightstrip.d.ts +4 -3
  41. package/dist/device/lightstrip.d.ts.map +1 -1
  42. package/dist/device/lightstrip.js +58 -32
  43. package/dist/device/lightstrip.js.map +1 -1
  44. package/dist/device/lock.d.ts.map +1 -1
  45. package/dist/device/lock.js +37 -18
  46. package/dist/device/lock.js.map +1 -1
  47. package/dist/device/meter.d.ts.map +1 -1
  48. package/dist/device/meter.js +38 -19
  49. package/dist/device/meter.js.map +1 -1
  50. package/dist/device/meterplus.d.ts.map +1 -1
  51. package/dist/device/meterplus.js +38 -19
  52. package/dist/device/meterplus.js.map +1 -1
  53. package/dist/device/motion.d.ts.map +1 -1
  54. package/dist/device/motion.js +36 -17
  55. package/dist/device/motion.js.map +1 -1
  56. package/dist/device/plug.d.ts.map +1 -1
  57. package/dist/device/plug.js +37 -18
  58. package/dist/device/plug.js.map +1 -1
  59. package/dist/device/robotvacuumcleaner.d.ts.map +1 -1
  60. package/dist/device/robotvacuumcleaner.js +36 -17
  61. package/dist/device/robotvacuumcleaner.js.map +1 -1
  62. package/dist/device/waterdetector.d.ts.map +1 -1
  63. package/dist/device/waterdetector.js +36 -17
  64. package/dist/device/waterdetector.js.map +1 -1
  65. package/dist/irdevice/other.d.ts +1 -0
  66. package/dist/irdevice/other.d.ts.map +1 -1
  67. package/dist/irdevice/other.js +186 -228
  68. package/dist/irdevice/other.js.map +1 -1
  69. package/dist/platform.d.ts +4 -0
  70. package/dist/platform.d.ts.map +1 -1
  71. package/dist/platform.js +41 -0
  72. package/dist/platform.js.map +1 -1
  73. package/dist/settings.d.ts +1 -0
  74. package/dist/settings.d.ts.map +1 -1
  75. package/dist/settings.js.map +1 -1
  76. package/dist/types/bledevicestatus.d.ts +1 -0
  77. package/dist/types/bledevicestatus.d.ts.map +1 -1
  78. package/dist/utils.d.ts +8 -0
  79. package/dist/utils.d.ts.map +1 -1
  80. package/dist/utils.js +16 -0
  81. package/dist/utils.js.map +1 -1
  82. package/package.json +8 -8
  83. package/src/device/blindtilt.ts +33 -18
  84. package/src/device/bot.ts +179 -406
  85. package/src/device/ceilinglight.ts +54 -34
  86. package/src/device/colorbulb.ts +56 -32
  87. package/src/device/contact.ts +33 -20
  88. package/src/device/curtain.ts +34 -18
  89. package/src/device/device.ts +38 -5
  90. package/src/device/fan.ts +33 -20
  91. package/src/device/hub.ts +35 -19
  92. package/src/device/humidifier.ts +37 -21
  93. package/src/device/iosensor.ts +35 -19
  94. package/src/device/lightstrip.ts +57 -34
  95. package/src/device/lock.ts +34 -18
  96. package/src/device/meter.ts +35 -19
  97. package/src/device/meterplus.ts +35 -19
  98. package/src/device/motion.ts +33 -17
  99. package/src/device/plug.ts +34 -18
  100. package/src/device/robotvacuumcleaner.ts +33 -17
  101. package/src/device/waterdetector.ts +33 -17
  102. package/src/irdevice/other.ts +214 -283
  103. package/src/platform.ts +39 -0
  104. package/src/settings.ts +1 -0
  105. package/src/types/bledevicestatus.ts +1 -0
  106. package/src/utils.ts +15 -0
package/src/platform.ts CHANGED
@@ -78,6 +78,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
78
78
  public readonly eve: any;
79
79
  public readonly fakegatoAPI: any;
80
80
  public readonly webhookEventHandler: { [x: string]: (context: any) => void } = {};
81
+ public readonly bleEventHandler: { [x: string]: (context: any) => void } = {};
81
82
 
82
83
  constructor(
83
84
  log: Logging,
@@ -148,6 +149,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
148
149
 
149
150
  this.setupMqtt();
150
151
  this.setupwebhook();
152
+ this.setupBlE();
151
153
  }
152
154
 
153
155
  async setupMqtt(): Promise<void> {
@@ -312,6 +314,43 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
312
314
  }
313
315
  }
314
316
 
317
+ async setupBlE() {
318
+ if (this.config.options?.BLE) {
319
+ await this.debugLog('setupBLE');
320
+ const SwitchBot = (await import('node-switchbot')).SwitchBot;
321
+ const switchbot = new SwitchBot();
322
+ if (switchbot === undefined) {
323
+ await this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${switchbot}`);
324
+ } else {
325
+ // Start to monitor advertisement packets
326
+ (async () => {
327
+ // Start to monitor advertisement packets
328
+ await this.debugLog('Scanning for BLE SwitchBot devices...');
329
+ await switchbot.startScan();
330
+ // Set an event handler to monitor advertisement packets
331
+ switchbot.onadvertisement = async (ad: any) => {
332
+ try {
333
+ this.bleEventHandler[ad.address]?.(ad.serviceData);
334
+ } catch (e: any) {
335
+ await this.errorLog(`Failed to handle BLE event. Error:${e}`);
336
+ }
337
+ };
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
+ });
348
+ }
349
+ } else {
350
+ await this.debugLog('Platform BLE is not enabled');
351
+ }
352
+ }
353
+
315
354
  /**
316
355
  * This function is invoked when homebridge restores cached accessories from disk at startup.
317
356
  * It should be used to setup event handlers for characteristics and update respective values.
package/src/settings.ts CHANGED
@@ -61,6 +61,7 @@ interface options {
61
61
  mqttURL?: string;
62
62
  mqttOptions?: IClientOptions;
63
63
  mqttPubOptions?: IClientOptions;
64
+ BLE?: boolean;
64
65
  webhookURL?: string;
65
66
  maxRetries?: number;
66
67
  delayBetweenRetries?: number;
@@ -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