@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.
- package/CHANGELOG.md +11 -0
- package/config.schema.json +11 -0
- package/dist/device/blindtilt.d.ts.map +1 -1
- package/dist/device/blindtilt.js +36 -18
- package/dist/device/blindtilt.js.map +1 -1
- package/dist/device/bot.d.ts +1 -2
- package/dist/device/bot.d.ts.map +1 -1
- package/dist/device/bot.js +186 -396
- package/dist/device/bot.js.map +1 -1
- package/dist/device/ceilinglight.d.ts +3 -2
- package/dist/device/ceilinglight.d.ts.map +1 -1
- package/dist/device/ceilinglight.js +57 -32
- package/dist/device/ceilinglight.js.map +1 -1
- package/dist/device/colorbulb.d.ts +3 -2
- package/dist/device/colorbulb.d.ts.map +1 -1
- package/dist/device/colorbulb.js +58 -30
- package/dist/device/colorbulb.js.map +1 -1
- package/dist/device/contact.d.ts.map +1 -1
- package/dist/device/contact.js +36 -19
- package/dist/device/contact.js.map +1 -1
- package/dist/device/curtain.d.ts.map +1 -1
- package/dist/device/curtain.js +37 -18
- package/dist/device/curtain.js.map +1 -1
- package/dist/device/device.d.ts +9 -0
- package/dist/device/device.d.ts.map +1 -1
- package/dist/device/device.js +32 -5
- package/dist/device/device.js.map +1 -1
- package/dist/device/fan.d.ts.map +1 -1
- package/dist/device/fan.js +36 -19
- package/dist/device/fan.js.map +1 -1
- package/dist/device/hub.d.ts.map +1 -1
- package/dist/device/hub.js +38 -19
- package/dist/device/hub.js.map +1 -1
- package/dist/device/humidifier.d.ts.map +1 -1
- package/dist/device/humidifier.js +40 -21
- package/dist/device/humidifier.js.map +1 -1
- package/dist/device/iosensor.d.ts.map +1 -1
- package/dist/device/iosensor.js +38 -19
- package/dist/device/iosensor.js.map +1 -1
- package/dist/device/lightstrip.d.ts +4 -3
- package/dist/device/lightstrip.d.ts.map +1 -1
- package/dist/device/lightstrip.js +58 -32
- package/dist/device/lightstrip.js.map +1 -1
- package/dist/device/lock.d.ts.map +1 -1
- package/dist/device/lock.js +37 -18
- package/dist/device/lock.js.map +1 -1
- package/dist/device/meter.d.ts.map +1 -1
- package/dist/device/meter.js +38 -19
- package/dist/device/meter.js.map +1 -1
- package/dist/device/meterplus.d.ts.map +1 -1
- package/dist/device/meterplus.js +38 -19
- package/dist/device/meterplus.js.map +1 -1
- package/dist/device/motion.d.ts.map +1 -1
- package/dist/device/motion.js +36 -17
- package/dist/device/motion.js.map +1 -1
- package/dist/device/plug.d.ts.map +1 -1
- package/dist/device/plug.js +37 -18
- package/dist/device/plug.js.map +1 -1
- package/dist/device/robotvacuumcleaner.d.ts.map +1 -1
- package/dist/device/robotvacuumcleaner.js +36 -17
- package/dist/device/robotvacuumcleaner.js.map +1 -1
- package/dist/device/waterdetector.d.ts.map +1 -1
- package/dist/device/waterdetector.js +36 -17
- package/dist/device/waterdetector.js.map +1 -1
- package/dist/irdevice/other.d.ts +1 -0
- package/dist/irdevice/other.d.ts.map +1 -1
- package/dist/irdevice/other.js +186 -228
- package/dist/irdevice/other.js.map +1 -1
- package/dist/platform.d.ts +4 -0
- package/dist/platform.d.ts.map +1 -1
- package/dist/platform.js +41 -0
- package/dist/platform.js.map +1 -1
- package/dist/settings.d.ts +1 -0
- package/dist/settings.d.ts.map +1 -1
- package/dist/settings.js.map +1 -1
- package/dist/types/bledevicestatus.d.ts +1 -0
- package/dist/types/bledevicestatus.d.ts.map +1 -1
- package/dist/utils.d.ts +8 -0
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +16 -0
- package/dist/utils.js.map +1 -1
- package/package.json +8 -8
- package/src/device/blindtilt.ts +33 -18
- package/src/device/bot.ts +179 -406
- package/src/device/ceilinglight.ts +54 -34
- package/src/device/colorbulb.ts +56 -32
- package/src/device/contact.ts +33 -20
- package/src/device/curtain.ts +34 -18
- package/src/device/device.ts +38 -5
- package/src/device/fan.ts +33 -20
- package/src/device/hub.ts +35 -19
- package/src/device/humidifier.ts +37 -21
- package/src/device/iosensor.ts +35 -19
- package/src/device/lightstrip.ts +57 -34
- package/src/device/lock.ts +34 -18
- package/src/device/meter.ts +35 -19
- package/src/device/meterplus.ts +35 -19
- package/src/device/motion.ts +33 -17
- package/src/device/plug.ts +34 -18
- package/src/device/robotvacuumcleaner.ts +33 -17
- package/src/device/waterdetector.ts +33 -17
- package/src/irdevice/other.ts +214 -283
- package/src/platform.ts +39 -0
- package/src/settings.ts +1 -0
- package/src/types/bledevicestatus.ts +1 -0
- 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
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
|