@switchbot/homebridge-switchbot 1.6.4-beta.2 → 1.7.0
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 +8 -2
- package/config.schema.json +30 -0
- package/dist/devices/bots.d.ts +17 -8
- package/dist/devices/bots.d.ts.map +1 -1
- package/dist/devices/bots.js +446 -145
- package/dist/devices/bots.js.map +1 -1
- package/dist/devices/contact.d.ts +2 -2
- package/dist/devices/contact.d.ts.map +1 -1
- package/dist/devices/contact.js +26 -9
- package/dist/devices/contact.js.map +1 -1
- package/dist/devices/curtains.d.ts +2 -2
- package/dist/devices/curtains.d.ts.map +1 -1
- package/dist/devices/curtains.js +27 -10
- package/dist/devices/curtains.js.map +1 -1
- package/dist/devices/humidifiers.d.ts +2 -2
- package/dist/devices/humidifiers.d.ts.map +1 -1
- package/dist/devices/humidifiers.js +28 -11
- package/dist/devices/humidifiers.js.map +1 -1
- package/dist/devices/meters.d.ts.map +1 -1
- package/dist/devices/meters.js +27 -10
- package/dist/devices/meters.js.map +1 -1
- package/dist/devices/motion.d.ts +2 -2
- package/dist/devices/motion.d.ts.map +1 -1
- package/dist/devices/motion.js +27 -10
- package/dist/devices/motion.js.map +1 -1
- package/dist/platform.d.ts +0 -2
- package/dist/platform.d.ts.map +1 -1
- package/dist/platform.js +0 -12
- package/dist/platform.js.map +1 -1
- package/package.json +71 -71
- package/src/devices/bots.ts +431 -131
- package/src/devices/contact.ts +25 -9
- package/src/devices/curtains.ts +26 -10
- package/src/devices/humidifiers.ts +27 -11
- package/src/devices/meters.ts +26 -11
- package/src/devices/motion.ts +26 -10
- package/src/platform.ts +0 -13
package/src/devices/contact.ts
CHANGED
|
@@ -273,18 +273,34 @@ export class Contact {
|
|
|
273
273
|
}
|
|
274
274
|
}
|
|
275
275
|
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
276
|
+
public async connectBLE() {
|
|
277
|
+
let switchbot: any;
|
|
278
|
+
try {
|
|
279
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
280
|
+
const Switchbot = require('node-switchbot');
|
|
281
|
+
switchbot = new Switchbot();
|
|
282
|
+
// Convert to BLE Address
|
|
283
|
+
this.device.bleMac = ((this.device.deviceId!.match(/.{1,2}/g))!.join(':')).toLowerCase();
|
|
284
|
+
this.debugLog(`Contact Sensor: ${this.accessory.displayName} BLE Address: ${this.device.bleMac}`);
|
|
285
|
+
} catch (e: any) {
|
|
286
|
+
switchbot = false;
|
|
287
|
+
this.errorLog(`Contact Sensor: ${this.accessory.displayName} 'node-switchbot' found: ${switchbot}`);
|
|
288
|
+
if (this.deviceLogging === 'debug') {
|
|
289
|
+
this.errorLog(`Contact Sensor: ${this.accessory.displayName} 'node-switchbot' found: ${switchbot},`
|
|
290
|
+
+ ` Error Message: ${JSON.stringify(e.message)}`);
|
|
291
|
+
}
|
|
292
|
+
if (this.platform.debugMode) {
|
|
293
|
+
this.errorLog(`Contact Sensor: ${this.accessory.displayName} 'node-switchbot' found: ${switchbot},`
|
|
294
|
+
+ ` Error: ${JSON.stringify(e)}`);
|
|
295
|
+
}
|
|
296
|
+
}
|
|
281
297
|
return switchbot;
|
|
282
298
|
}
|
|
283
299
|
|
|
284
300
|
private async BLERefreshStatus() {
|
|
285
301
|
this.debugLog(`Contact Sensor: ${this.accessory.displayName} BLE refreshStatus`);
|
|
286
302
|
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
287
|
-
const switchbot = this.connectBLE();
|
|
303
|
+
const switchbot = await this.connectBLE();
|
|
288
304
|
// Start to monitor advertisement packets
|
|
289
305
|
if (switchbot !== false) {
|
|
290
306
|
switchbot.startScan({
|
|
@@ -342,12 +358,12 @@ export class Contact {
|
|
|
342
358
|
this.apiError(e);
|
|
343
359
|
});
|
|
344
360
|
} else {
|
|
345
|
-
await this.BLEconnection();
|
|
361
|
+
await this.BLEconnection(switchbot);
|
|
346
362
|
}
|
|
347
363
|
}
|
|
348
364
|
|
|
349
|
-
|
|
350
|
-
this.errorLog(`Contact Sensor: ${this.accessory.displayName} wasn't able to establish BLE Connection`);
|
|
365
|
+
public async BLEconnection(switchbot: any) {
|
|
366
|
+
this.errorLog(`Contact Sensor: ${this.accessory.displayName} wasn't able to establish BLE Connection, node-switchbot: ${switchbot}`);
|
|
351
367
|
if (this.platform.config.credentials?.openToken) {
|
|
352
368
|
this.warnLog(`Contact Sensor: ${this.accessory.displayName} Using OpenAPI Connection`);
|
|
353
369
|
await this.openAPIRefreshStatus();
|
package/src/devices/curtains.ts
CHANGED
|
@@ -253,11 +253,27 @@ export class Curtain {
|
|
|
253
253
|
}
|
|
254
254
|
}
|
|
255
255
|
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
256
|
+
public async connectBLE() {
|
|
257
|
+
let switchbot: any;
|
|
258
|
+
try {
|
|
259
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
260
|
+
const Switchbot = require('node-switchbot');
|
|
261
|
+
switchbot = new Switchbot();
|
|
262
|
+
// Convert to BLE Address
|
|
263
|
+
this.device.bleMac = ((this.device.deviceId!.match(/.{1,2}/g))!.join(':')).toLowerCase();
|
|
264
|
+
this.debugLog(`Curtain: ${this.accessory.displayName} BLE Address: ${this.device.bleMac}`);
|
|
265
|
+
} catch (e: any) {
|
|
266
|
+
switchbot = false;
|
|
267
|
+
this.errorLog(`Curtain: ${this.accessory.displayName} 'node-switchbot' found: ${switchbot}`);
|
|
268
|
+
if (this.deviceLogging === 'debug') {
|
|
269
|
+
this.errorLog(`Curtain: ${this.accessory.displayName} 'node-switchbot' found: ${switchbot},`
|
|
270
|
+
+ ` Error Message: ${JSON.stringify(e.message)}`);
|
|
271
|
+
}
|
|
272
|
+
if (this.platform.debugMode) {
|
|
273
|
+
this.errorLog(`Curtain: ${this.accessory.displayName} 'node-switchbot' found: ${switchbot},`
|
|
274
|
+
+ ` Error: ${JSON.stringify(e)}`);
|
|
275
|
+
}
|
|
276
|
+
}
|
|
261
277
|
return switchbot;
|
|
262
278
|
}
|
|
263
279
|
|
|
@@ -452,7 +468,7 @@ export class Curtain {
|
|
|
452
468
|
private async BLERefreshStatus() {
|
|
453
469
|
this.debugLog(`Curtain: ${this.accessory.displayName} BLE refreshStatus`);
|
|
454
470
|
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
455
|
-
const switchbot = this.connectBLE();
|
|
471
|
+
const switchbot = await this.connectBLE();
|
|
456
472
|
// Start to monitor advertisement packets
|
|
457
473
|
if (switchbot !== false) {
|
|
458
474
|
switchbot.startScan({
|
|
@@ -510,12 +526,12 @@ export class Curtain {
|
|
|
510
526
|
this.apiError(e);
|
|
511
527
|
});
|
|
512
528
|
} else {
|
|
513
|
-
await this.BLEconnection();
|
|
529
|
+
await this.BLEconnection(switchbot);
|
|
514
530
|
}
|
|
515
531
|
}
|
|
516
532
|
|
|
517
|
-
|
|
518
|
-
this.errorLog(`Curtain: ${this.accessory.displayName} wasn't able to establish BLE Connection`);
|
|
533
|
+
public async BLEconnection(switchbot: any) {
|
|
534
|
+
this.errorLog(`Curtain: ${this.accessory.displayName} wasn't able to establish BLE Connection, node-switchbot: ${switchbot}`);
|
|
519
535
|
if (this.platform.config.credentials?.openToken) {
|
|
520
536
|
this.warnLog(`Curtain: ${this.accessory.displayName} Using OpenAPI Connection`);
|
|
521
537
|
await this.openAPIRefreshStatus();
|
|
@@ -562,7 +578,7 @@ export class Curtain {
|
|
|
562
578
|
private async BLEpushChanges() {
|
|
563
579
|
if (this.TargetPosition !== this.CurrentPosition) {
|
|
564
580
|
this.debugLog(`Curtain: ${this.accessory.displayName} BLE pushChanges`);
|
|
565
|
-
const switchbot = this.connectBLE();
|
|
581
|
+
const switchbot = await this.connectBLE();
|
|
566
582
|
if (switchbot !== false) {
|
|
567
583
|
switchbot.discover({ model: 'c', quick: true, id: this.device.bleMac }).then((device_list) => {
|
|
568
584
|
this.infoLog(`${this.accessory.displayName} Target Position: ${this.TargetPosition}`);
|
|
@@ -339,18 +339,34 @@ export class Humidifier {
|
|
|
339
339
|
}
|
|
340
340
|
}
|
|
341
341
|
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
342
|
+
public async connectBLE() {
|
|
343
|
+
let switchbot: any;
|
|
344
|
+
try {
|
|
345
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
346
|
+
const Switchbot = require('node-switchbot');
|
|
347
|
+
switchbot = new Switchbot();
|
|
348
|
+
// Convert to BLE Address
|
|
349
|
+
this.device.bleMac = ((this.device.deviceId!.match(/.{1,2}/g))!.join(':')).toLowerCase();
|
|
350
|
+
this.debugLog(`Humidifier: ${this.accessory.displayName} BLE Address: ${this.device.bleMac}`);
|
|
351
|
+
} catch (e: any) {
|
|
352
|
+
switchbot = false;
|
|
353
|
+
this.errorLog(`Humidifier: ${this.accessory.displayName} 'node-switchbot' found: ${switchbot}`);
|
|
354
|
+
if (this.deviceLogging === 'debug') {
|
|
355
|
+
this.errorLog(`Humidifier: ${this.accessory.displayName} 'node-switchbot' found: ${switchbot},`
|
|
356
|
+
+ ` Error Message: ${JSON.stringify(e.message)}`);
|
|
357
|
+
}
|
|
358
|
+
if (this.platform.debugMode) {
|
|
359
|
+
this.errorLog(`Humidifier: ${this.accessory.displayName} 'node-switchbot' found: ${switchbot},`
|
|
360
|
+
+ ` Error: ${JSON.stringify(e)}`);
|
|
361
|
+
}
|
|
362
|
+
}
|
|
347
363
|
return switchbot;
|
|
348
364
|
}
|
|
349
365
|
|
|
350
366
|
private async BLERefreshStatus() {
|
|
351
367
|
this.debugLog(`Humidifier: ${this.accessory.displayName} BLE refreshStatus`);
|
|
352
368
|
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
353
|
-
const switchbot = this.connectBLE();
|
|
369
|
+
const switchbot = await this.connectBLE();
|
|
354
370
|
// Start to monitor advertisement packets
|
|
355
371
|
if (switchbot !== false) {
|
|
356
372
|
switchbot.startScan({
|
|
@@ -384,7 +400,7 @@ export class Humidifier {
|
|
|
384
400
|
this.parseStatus();
|
|
385
401
|
this.updateHomeKitCharacteristics();
|
|
386
402
|
} else {
|
|
387
|
-
await this.BLEconnection();
|
|
403
|
+
await this.BLEconnection(switchbot);
|
|
388
404
|
}
|
|
389
405
|
}).catch(async (e: any) => {
|
|
390
406
|
this.errorLog(`Humidifier: ${this.accessory.displayName} failed refreshStatus with BLE Connection`);
|
|
@@ -403,12 +419,12 @@ export class Humidifier {
|
|
|
403
419
|
this.apiError(e);
|
|
404
420
|
});
|
|
405
421
|
} else {
|
|
406
|
-
await this.BLEconnection();
|
|
422
|
+
await this.BLEconnection(switchbot);
|
|
407
423
|
}
|
|
408
424
|
}
|
|
409
425
|
|
|
410
|
-
|
|
411
|
-
this.errorLog(`Humidifier: ${this.accessory.displayName} wasn't able to establish BLE Connection`);
|
|
426
|
+
public async BLEconnection(switchbot: any) {
|
|
427
|
+
this.errorLog(`Humidifier: ${this.accessory.displayName} wasn't able to establish BLE Connection, node-switchbot: ${switchbot}`);
|
|
412
428
|
if (this.platform.config.credentials?.openToken) {
|
|
413
429
|
this.warnLog(`Humidifier: ${this.accessory.displayName} Using OpenAPI Connection`);
|
|
414
430
|
await this.openAPIRefreshStatus();
|
|
@@ -461,7 +477,7 @@ export class Humidifier {
|
|
|
461
477
|
|
|
462
478
|
private async BLEpushChanges() {
|
|
463
479
|
this.debugLog(`Humidifier: ${this.accessory.displayName} BLE pushChanges`);
|
|
464
|
-
const switchbot = this.connectBLE();
|
|
480
|
+
const switchbot = await this.connectBLE();
|
|
465
481
|
if (switchbot !== false) {
|
|
466
482
|
switchbot.discover({ model: 'e', quick: true, id: this.device.bleMac }).then((device_list) => {
|
|
467
483
|
this.infoLog(`${this.accessory.displayName} Target Position: ${this.Active}`);
|
package/src/devices/meters.ts
CHANGED
|
@@ -303,19 +303,34 @@ export class Meter {
|
|
|
303
303
|
}
|
|
304
304
|
}
|
|
305
305
|
|
|
306
|
-
private connectBLE() {
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
306
|
+
private async connectBLE() {
|
|
307
|
+
let switchbot: any;
|
|
308
|
+
try {
|
|
309
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
310
|
+
const Switchbot = require('node-switchbot');
|
|
311
|
+
switchbot = new Switchbot();
|
|
312
|
+
// Convert to BLE Address
|
|
313
|
+
this.device.bleMac = ((this.device.deviceId!.match(/.{1,2}/g))!.join(':')).toLowerCase();
|
|
314
|
+
this.debugLog(`Meter: ${this.accessory.displayName} BLE Address: ${this.device.bleMac}`);
|
|
315
|
+
} catch (e: any) {
|
|
316
|
+
switchbot = false;
|
|
317
|
+
this.errorLog(`Meter: ${this.accessory.displayName} 'node-switchbot' found: ${switchbot}`);
|
|
318
|
+
if (this.deviceLogging === 'debug') {
|
|
319
|
+
this.errorLog(`Meter: ${this.accessory.displayName} 'node-switchbot' found: ${switchbot},`
|
|
320
|
+
+ ` Error Message: ${JSON.stringify(e.message)}`);
|
|
321
|
+
}
|
|
322
|
+
if (this.platform.debugMode) {
|
|
323
|
+
this.errorLog(`Meter: ${this.accessory.displayName} 'node-switchbot' found: ${switchbot},`
|
|
324
|
+
+ ` Error: ${JSON.stringify(e)}`);
|
|
325
|
+
}
|
|
326
|
+
}
|
|
311
327
|
return switchbot;
|
|
312
328
|
}
|
|
313
329
|
|
|
314
|
-
|
|
315
330
|
private async BLErefreshStatus() {
|
|
316
331
|
this.debugLog(`Meter: ${this.accessory.displayName} BLE RefreshStatus`);
|
|
317
332
|
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
318
|
-
const switchbot = this.connectBLE();
|
|
333
|
+
const switchbot = await this.connectBLE();
|
|
319
334
|
// Start to monitor advertisement packets
|
|
320
335
|
if (switchbot !== false) {
|
|
321
336
|
switchbot.startScan({
|
|
@@ -356,7 +371,7 @@ export class Meter {
|
|
|
356
371
|
this.parseStatus();
|
|
357
372
|
this.updateHomeKitCharacteristics();
|
|
358
373
|
} else {
|
|
359
|
-
await this.BLEconnection();
|
|
374
|
+
await this.BLEconnection(switchbot);
|
|
360
375
|
}
|
|
361
376
|
}).catch(async (e: any) => {
|
|
362
377
|
this.errorLog(`Meter: ${this.accessory.displayName} failed refreshStatus with BLE Connection`);
|
|
@@ -375,12 +390,12 @@ export class Meter {
|
|
|
375
390
|
this.apiError(e);
|
|
376
391
|
});
|
|
377
392
|
} else {
|
|
378
|
-
await this.BLEconnection();
|
|
393
|
+
await this.BLEconnection(switchbot);
|
|
379
394
|
}
|
|
380
395
|
}
|
|
381
396
|
|
|
382
|
-
private async BLEconnection() {
|
|
383
|
-
this.errorLog(`Meter: ${this.accessory.displayName} wasn't able to establish BLE Connection`);
|
|
397
|
+
private async BLEconnection(switchbot: any) {
|
|
398
|
+
this.errorLog(`Meter: ${this.accessory.displayName} wasn't able to establish BLE Connection, node-switchbot: ${switchbot}`);
|
|
384
399
|
if (this.platform.config.credentials?.openToken) {
|
|
385
400
|
this.warnLog(`Meter: ${this.accessory.displayName} Using OpenAPI Connection`);
|
|
386
401
|
await this.openAPIRefreshStatus();
|
package/src/devices/motion.ts
CHANGED
|
@@ -226,18 +226,34 @@ export class Motion {
|
|
|
226
226
|
}
|
|
227
227
|
}
|
|
228
228
|
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
229
|
+
public async connectBLE() {
|
|
230
|
+
let switchbot: any;
|
|
231
|
+
try {
|
|
232
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
233
|
+
const Switchbot = require('node-switchbot');
|
|
234
|
+
switchbot = new Switchbot();
|
|
235
|
+
// Convert to BLE Address
|
|
236
|
+
this.device.bleMac = ((this.device.deviceId!.match(/.{1,2}/g))!.join(':')).toLowerCase();
|
|
237
|
+
this.debugLog(`Motion Sensor: ${this.accessory.displayName} BLE Address: ${this.device.bleMac}`);
|
|
238
|
+
} catch (e: any) {
|
|
239
|
+
switchbot = false;
|
|
240
|
+
this.errorLog(`Motion Sensor: ${this.accessory.displayName} 'node-switchbot' found: ${switchbot}`);
|
|
241
|
+
if (this.deviceLogging === 'debug') {
|
|
242
|
+
this.errorLog(`Motion Sensor: ${this.accessory.displayName} 'node-switchbot' found: ${switchbot},`
|
|
243
|
+
+ ` Error Message: ${JSON.stringify(e.message)}`);
|
|
244
|
+
}
|
|
245
|
+
if (this.platform.debugMode) {
|
|
246
|
+
this.errorLog(`Motion Sensor: ${this.accessory.displayName} 'node-switchbot' found: ${switchbot},`
|
|
247
|
+
+ ` Error: ${JSON.stringify(e)}`);
|
|
248
|
+
}
|
|
249
|
+
}
|
|
234
250
|
return switchbot;
|
|
235
251
|
}
|
|
236
252
|
|
|
237
253
|
private async BLERefreshStatus() {
|
|
238
254
|
this.debugLog(`Motion Sensor: ${this.accessory.displayName} BLE RefreshStatus`);
|
|
239
255
|
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
240
|
-
const switchbot = this.connectBLE();
|
|
256
|
+
const switchbot = await this.connectBLE();
|
|
241
257
|
// Start to monitor advertisement packets
|
|
242
258
|
if (switchbot !== false) {
|
|
243
259
|
switchbot.startScan({
|
|
@@ -271,7 +287,7 @@ export class Motion {
|
|
|
271
287
|
this.parseStatus();
|
|
272
288
|
this.updateHomeKitCharacteristics();
|
|
273
289
|
} else {
|
|
274
|
-
await this.BLEconnection();
|
|
290
|
+
await this.BLEconnection(switchbot);
|
|
275
291
|
}
|
|
276
292
|
}).catch(async (e: any) => {
|
|
277
293
|
this.errorLog(`Motion Sensor: ${this.accessory.displayName} failed refreshStatus with BLE Connection`);
|
|
@@ -290,12 +306,12 @@ export class Motion {
|
|
|
290
306
|
this.apiError(e);
|
|
291
307
|
});
|
|
292
308
|
} else {
|
|
293
|
-
await this.BLEconnection();
|
|
309
|
+
await this.BLEconnection(switchbot);
|
|
294
310
|
}
|
|
295
311
|
}
|
|
296
312
|
|
|
297
|
-
|
|
298
|
-
this.errorLog(`Motion Sensor: ${this.accessory.displayName} wasn't able to establish BLE Connection`);
|
|
313
|
+
public async BLEconnection(switchbot: any) {
|
|
314
|
+
this.errorLog(`Motion Sensor: ${this.accessory.displayName} wasn't able to establish BLE Connection, node-switchbot: ${switchbot}`);
|
|
299
315
|
if (this.platform.config.credentials?.openToken) {
|
|
300
316
|
this.warnLog(`Motion Sensor: ${this.accessory.displayName} Using OpenAPI Connection`);
|
|
301
317
|
await this.openAPIRefreshStatus();
|
package/src/platform.ts
CHANGED
|
@@ -41,7 +41,6 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
41
41
|
registeringDevice!: boolean;
|
|
42
42
|
debugMode!: boolean;
|
|
43
43
|
platformLogging?: string;
|
|
44
|
-
switchbot: any;
|
|
45
44
|
|
|
46
45
|
constructor(public readonly log: Logger, public readonly config: SwitchBotPlatformConfig, public readonly api: API) {
|
|
47
46
|
this.logs();
|
|
@@ -193,18 +192,6 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
193
192
|
}
|
|
194
193
|
}
|
|
195
194
|
|
|
196
|
-
connectBLE() {
|
|
197
|
-
try {
|
|
198
|
-
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
199
|
-
const Switchbot = require('node-switchbot');
|
|
200
|
-
this.switchbot = new Switchbot();
|
|
201
|
-
} catch (e) {
|
|
202
|
-
this.switchbot = false;
|
|
203
|
-
this.errorLog(`Was 'node-switchbot' found: ${this.switchbot}`);
|
|
204
|
-
}
|
|
205
|
-
return this.switchbot;
|
|
206
|
-
}
|
|
207
|
-
|
|
208
195
|
/**
|
|
209
196
|
* this method discovers the Locations
|
|
210
197
|
*/
|