@switchbot/homebridge-switchbot 3.3.0-beta.1 → 3.3.0-beta.3
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/dist/device/blindtilt.d.ts.map +1 -1
- package/dist/device/blindtilt.js +72 -37
- package/dist/device/blindtilt.js.map +1 -1
- package/dist/device/bot.d.ts.map +1 -1
- package/dist/device/bot.js +68 -35
- package/dist/device/bot.js.map +1 -1
- package/dist/device/ceilinglight.d.ts.map +1 -1
- package/dist/device/ceilinglight.js +73 -39
- package/dist/device/ceilinglight.js.map +1 -1
- package/dist/device/colorbulb.d.ts +5 -3
- package/dist/device/colorbulb.d.ts.map +1 -1
- package/dist/device/colorbulb.js +84 -44
- package/dist/device/colorbulb.js.map +1 -1
- package/dist/device/contact.d.ts.map +1 -1
- package/dist/device/contact.js +71 -39
- package/dist/device/contact.js.map +1 -1
- package/dist/device/curtain.d.ts.map +1 -1
- package/dist/device/curtain.js +71 -36
- package/dist/device/curtain.js.map +1 -1
- package/dist/device/hub.d.ts.map +1 -1
- package/dist/device/hub.js +8 -2
- package/dist/device/hub.js.map +1 -1
- package/dist/device/humidifier.d.ts.map +1 -1
- package/dist/device/humidifier.js +69 -36
- package/dist/device/humidifier.js.map +1 -1
- package/dist/device/iosensor.d.ts.map +1 -1
- package/dist/device/iosensor.js +74 -40
- package/dist/device/iosensor.js.map +1 -1
- package/dist/device/lightstrip.d.ts.map +1 -1
- package/dist/device/lightstrip.js +67 -39
- package/dist/device/lightstrip.js.map +1 -1
- package/dist/device/lock.d.ts.map +1 -1
- package/dist/device/lock.js +70 -36
- package/dist/device/lock.js.map +1 -1
- package/dist/device/meter.d.ts.map +1 -1
- package/dist/device/meter.js +74 -40
- package/dist/device/meter.js.map +1 -1
- package/dist/device/meterplus.d.ts.map +1 -1
- package/dist/device/meterplus.js +74 -40
- package/dist/device/meterplus.js.map +1 -1
- package/dist/device/motion.d.ts.map +1 -1
- package/dist/device/motion.js +86 -53
- package/dist/device/motion.js.map +1 -1
- package/dist/device/plug.d.ts.map +1 -1
- package/dist/device/plug.js +67 -37
- package/dist/device/plug.js.map +1 -1
- package/dist/device/robotvacuumcleaner.d.ts +0 -1
- package/dist/device/robotvacuumcleaner.d.ts.map +1 -1
- package/dist/device/robotvacuumcleaner.js +69 -47
- package/dist/device/robotvacuumcleaner.js.map +1 -1
- package/dist/platform.d.ts.map +1 -1
- package/dist/platform.js +2 -6
- package/dist/platform.js.map +1 -1
- package/package.json +2 -2
- package/src/device/blindtilt.ts +32 -3
- package/src/device/bot.ts +30 -3
- package/src/device/ceilinglight.ts +35 -5
- package/src/device/colorbulb.ts +46 -10
- package/src/device/contact.ts +29 -3
- package/src/device/curtain.ts +34 -3
- package/src/device/hub.ts +6 -2
- package/src/device/humidifier.ts +30 -3
- package/src/device/iosensor.ts +31 -3
- package/src/device/lightstrip.ts +29 -5
- package/src/device/lock.ts +31 -3
- package/src/device/meter.ts +31 -3
- package/src/device/meterplus.ts +31 -3
- package/src/device/motion.ts +30 -3
- package/src/device/plug.ts +28 -4
- package/src/device/robotvacuumcleaner.ts +29 -13
- package/src/platform.ts +2 -6
package/src/device/motion.ts
CHANGED
|
@@ -4,7 +4,7 @@ import { interval, Subject } from 'rxjs';
|
|
|
4
4
|
import { skipWhile } from 'rxjs/operators';
|
|
5
5
|
import { SwitchBotPlatform } from '../platform.js';
|
|
6
6
|
import { Service, PlatformAccessory, CharacteristicValue, API, Logging, HAP } from 'homebridge';
|
|
7
|
-
import { device, devicesConfig, serviceData, deviceStatus,
|
|
7
|
+
import { device, devicesConfig, serviceData, deviceStatus, Devices, SwitchBotPlatformConfig } from '../settings.js';
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
10
|
* Platform Accessory
|
|
@@ -296,7 +296,34 @@ export class Motion {
|
|
|
296
296
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLE Address: ${this.device.bleMac}`);
|
|
297
297
|
this.getCustomBLEAddress(switchbot);
|
|
298
298
|
// Start to monitor advertisement packets
|
|
299
|
-
|
|
299
|
+
(async () => {
|
|
300
|
+
// Start to monitor advertisement packets
|
|
301
|
+
await switchbot.startScan({
|
|
302
|
+
model: 's',
|
|
303
|
+
id: this.device.bleMac,
|
|
304
|
+
});
|
|
305
|
+
// Set an event handler
|
|
306
|
+
switchbot.onadvertisement = (ad: any) => {
|
|
307
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} ${JSON.stringify(ad, null, ' ')}`);
|
|
308
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} address: ${ad.address}, model: ${ad.model}`);
|
|
309
|
+
if (this.device.bleMac === ad.address && ad.model === 's') {
|
|
310
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} serviceData: ${JSON.stringify(ad.serviceData)}`);
|
|
311
|
+
this.BLE_MotionDetected = ad.serviceData.movement;
|
|
312
|
+
this.BLE_BatteryLevel = ad.serviceData.battery;
|
|
313
|
+
this.BLE_CurrentAmbientLightLevel = ad.serviceData.lightLevel;
|
|
314
|
+
} else {
|
|
315
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} serviceData: ${JSON.stringify(ad.serviceData)}`);
|
|
316
|
+
}
|
|
317
|
+
};
|
|
318
|
+
// Wait 1 seconds
|
|
319
|
+
await switchbot.wait(this.scanDuration * 1000);
|
|
320
|
+
// Stop to monitor
|
|
321
|
+
await switchbot.stopScan();
|
|
322
|
+
// Update HomeKit
|
|
323
|
+
await this.BLEparseStatus();
|
|
324
|
+
await this.updateHomeKitCharacteristics();
|
|
325
|
+
})();
|
|
326
|
+
/*if (switchbot !== false) {
|
|
300
327
|
await switchbot
|
|
301
328
|
.startScan({
|
|
302
329
|
model: 's',
|
|
@@ -359,7 +386,7 @@ export class Motion {
|
|
|
359
386
|
} else {
|
|
360
387
|
this.debugErrorLog('4');
|
|
361
388
|
await this.BLERefreshConnection(switchbot);
|
|
362
|
-
}
|
|
389
|
+
}*/
|
|
363
390
|
}
|
|
364
391
|
|
|
365
392
|
async openAPIRefreshStatus(): Promise<void> {
|
package/src/device/plug.ts
CHANGED
|
@@ -4,7 +4,7 @@ import { interval, Subject } from 'rxjs';
|
|
|
4
4
|
import { SwitchBotPlatform } from '../platform.js';
|
|
5
5
|
import { debounceTime, skipWhile, take, tap } from 'rxjs/operators';
|
|
6
6
|
import { Service, PlatformAccessory, CharacteristicValue, API, Logging, HAP } from 'homebridge';
|
|
7
|
-
import { device, devicesConfig, deviceStatus,
|
|
7
|
+
import { device, devicesConfig, deviceStatus, serviceData, Devices, SwitchBotPlatformConfig } from '../settings.js';
|
|
8
8
|
|
|
9
9
|
export class Plug {
|
|
10
10
|
public readonly api: API;
|
|
@@ -220,7 +220,31 @@ export class Plug {
|
|
|
220
220
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLE Address: ${this.device.bleMac}`);
|
|
221
221
|
this.getCustomBLEAddress(switchbot);
|
|
222
222
|
// Start to monitor advertisement packets
|
|
223
|
-
|
|
223
|
+
(async () => {
|
|
224
|
+
await switchbot.startScan({
|
|
225
|
+
model: this.BLEmodel(),
|
|
226
|
+
id: this.device.bleMac,
|
|
227
|
+
});
|
|
228
|
+
// Set an event handler
|
|
229
|
+
switchbot.onadvertisement = (ad: any) => {
|
|
230
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} ${JSON.stringify(ad, null, ' ')}`);
|
|
231
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} address: ${ad.address}, model: ${ad.serviceData.model}`);
|
|
232
|
+
if (this.device.bleMac === ad.address && ad.serviceData.model === this.BLEmodel()) {
|
|
233
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} serviceData: ${JSON.stringify(ad.serviceData)}`);
|
|
234
|
+
this.BLE_On = ad.serviceData.state;
|
|
235
|
+
} else {
|
|
236
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} serviceData: ${JSON.stringify(ad.serviceData)}`);
|
|
237
|
+
}
|
|
238
|
+
};
|
|
239
|
+
// Wait 1 seconds
|
|
240
|
+
await switchbot.wait(this.scanDuration * 1000);
|
|
241
|
+
// Stop to monitor
|
|
242
|
+
await switchbot.stopScan();
|
|
243
|
+
// Update HomeKit
|
|
244
|
+
await this.BLEparseStatus();
|
|
245
|
+
await this.updateHomeKitCharacteristics();
|
|
246
|
+
})();
|
|
247
|
+
/*if (switchbot !== false) {
|
|
224
248
|
switchbot
|
|
225
249
|
.startScan({
|
|
226
250
|
model: this.BLEmodel(),
|
|
@@ -267,7 +291,7 @@ export class Plug {
|
|
|
267
291
|
});
|
|
268
292
|
} else {
|
|
269
293
|
await this.BLERefreshConnection(switchbot);
|
|
270
|
-
}
|
|
294
|
+
}*/
|
|
271
295
|
}
|
|
272
296
|
|
|
273
297
|
async openAPIRefreshStatus() {
|
|
@@ -464,7 +488,7 @@ export class Plug {
|
|
|
464
488
|
}
|
|
465
489
|
|
|
466
490
|
BLEmodel(): 'g' | 'j' {
|
|
467
|
-
if (this.device.deviceType === 'Plug Mini (US)') {
|
|
491
|
+
if (this.device.deviceType === 'Plug Mini (US)' || this.device.configDeviceType === 'Plug Mini (US)') {
|
|
468
492
|
return 'g';
|
|
469
493
|
} else {
|
|
470
494
|
return 'j';
|
|
@@ -4,7 +4,7 @@ import { interval, Subject } from 'rxjs';
|
|
|
4
4
|
import { SwitchBotPlatform } from '../platform.js';
|
|
5
5
|
import { debounceTime, skipWhile, take, tap } from 'rxjs/operators';
|
|
6
6
|
import { Service, PlatformAccessory, CharacteristicValue, API, Logging, HAP } from 'homebridge';
|
|
7
|
-
import { device, devicesConfig, deviceStatus,
|
|
7
|
+
import { device, devicesConfig, deviceStatus, serviceData, Devices, SwitchBotPlatformConfig } from '../settings.js';
|
|
8
8
|
|
|
9
9
|
export class RobotVacuumCleaner {
|
|
10
10
|
public readonly api: API;
|
|
@@ -267,7 +267,31 @@ export class RobotVacuumCleaner {
|
|
|
267
267
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLE Address: ${this.device.bleMac}`);
|
|
268
268
|
this.getCustomBLEAddress(switchbot);
|
|
269
269
|
// Start to monitor advertisement packets
|
|
270
|
-
|
|
270
|
+
(async () => {
|
|
271
|
+
await switchbot.startScan({
|
|
272
|
+
model: '?',
|
|
273
|
+
id: this.device.bleMac,
|
|
274
|
+
});
|
|
275
|
+
// Set an event handler
|
|
276
|
+
switchbot.onadvertisement = (ad: any) => {
|
|
277
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} ${JSON.stringify(ad, null, ' ')}`);
|
|
278
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} address: ${ad.address}, model: ${ad.serviceData.model}`);
|
|
279
|
+
if (this.device.bleMac === ad.address && ad.serviceData.model === '?') {
|
|
280
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} serviceData: ${JSON.stringify(ad.serviceData)}`);
|
|
281
|
+
this.BLE_On = ad.serviceData.state;
|
|
282
|
+
} else {
|
|
283
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} serviceData: ${JSON.stringify(ad.serviceData)}`);
|
|
284
|
+
}
|
|
285
|
+
};
|
|
286
|
+
// Wait 1 seconds
|
|
287
|
+
await switchbot.wait(this.scanDuration * 1000);
|
|
288
|
+
// Stop to monitor
|
|
289
|
+
await switchbot.stopScan();
|
|
290
|
+
// Update HomeKit
|
|
291
|
+
await this.BLEparseStatus();
|
|
292
|
+
await this.updateHomeKitCharacteristics();
|
|
293
|
+
})();
|
|
294
|
+
/*if (switchbot !== false) {
|
|
271
295
|
switchbot
|
|
272
296
|
.startScan({
|
|
273
297
|
model: this.BLEmodel(),
|
|
@@ -314,7 +338,7 @@ export class RobotVacuumCleaner {
|
|
|
314
338
|
});
|
|
315
339
|
} else {
|
|
316
340
|
await this.BLERefreshConnection(switchbot);
|
|
317
|
-
}
|
|
341
|
+
}*/
|
|
318
342
|
}
|
|
319
343
|
|
|
320
344
|
async openAPIRefreshStatus() {
|
|
@@ -392,7 +416,7 @@ export class RobotVacuumCleaner {
|
|
|
392
416
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLE Address: ${this.device.bleMac}`);
|
|
393
417
|
switchbot
|
|
394
418
|
.discover({
|
|
395
|
-
model:
|
|
419
|
+
model: '?',
|
|
396
420
|
id: this.device.bleMac,
|
|
397
421
|
})
|
|
398
422
|
.then(async (device_list: any) => {
|
|
@@ -625,20 +649,12 @@ export class RobotVacuumCleaner {
|
|
|
625
649
|
}
|
|
626
650
|
}
|
|
627
651
|
|
|
628
|
-
BLEmodel(): 'g' | 'j' {
|
|
629
|
-
if (this.device.deviceType === 'Plug Mini (US)') {
|
|
630
|
-
return 'g';
|
|
631
|
-
} else {
|
|
632
|
-
return 'j';
|
|
633
|
-
}
|
|
634
|
-
}
|
|
635
|
-
|
|
636
652
|
async getCustomBLEAddress(switchbot: any) {
|
|
637
653
|
if (this.device.customBLEaddress && this.deviceLogging.includes('debug')) {
|
|
638
654
|
(async () => {
|
|
639
655
|
// Start to monitor advertisement packets
|
|
640
656
|
await switchbot.startScan({
|
|
641
|
-
model:
|
|
657
|
+
model: '?',
|
|
642
658
|
});
|
|
643
659
|
// Set an event handler
|
|
644
660
|
switchbot.onadvertisement = (ad: any) => {
|
package/src/platform.ts
CHANGED
|
@@ -2556,14 +2556,10 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
2556
2556
|
|
|
2557
2557
|
// BLE Connection
|
|
2558
2558
|
async connectBLE() {
|
|
2559
|
-
let noble: any;
|
|
2560
|
-
let SwitchBot: any;
|
|
2561
2559
|
let switchbot: any;
|
|
2562
2560
|
try {
|
|
2563
|
-
|
|
2564
|
-
|
|
2565
|
-
//SwitchBot = (await import('/Users/Shared/GitHub/OpenWonderLabs/node-switchbot/dist/switchbot.js')).default;
|
|
2566
|
-
queueScheduler.schedule(() => (switchbot = new SwitchBot({ 'noble': noble })));
|
|
2561
|
+
const SwitchBot = (await import('node-switchbot')).SwitchBot;
|
|
2562
|
+
queueScheduler.schedule(() => (switchbot = new SwitchBot()));
|
|
2567
2563
|
} catch (e: any) {
|
|
2568
2564
|
switchbot = false;
|
|
2569
2565
|
this.errorLog(`Was 'node-switchbot' found: ${switchbot}, Error: ${e}`);
|