@switchbot/homebridge-switchbot 2.0.0-beta.12 → 2.0.0-beta.14
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/bot.d.ts.map +1 -1
- package/dist/device/bot.js +19 -18
- package/dist/device/bot.js.map +1 -1
- package/dist/device/colorbulb.d.ts.map +1 -1
- package/dist/device/colorbulb.js +32 -25
- package/dist/device/colorbulb.js.map +1 -1
- package/dist/device/contact.d.ts.map +1 -1
- package/dist/device/contact.js +7 -6
- package/dist/device/contact.js.map +1 -1
- package/dist/device/curtain.d.ts.map +1 -1
- package/dist/device/curtain.js +14 -13
- package/dist/device/curtain.js.map +1 -1
- package/dist/device/humidifier.d.ts.map +1 -1
- package/dist/device/humidifier.js +18 -17
- package/dist/device/humidifier.js.map +1 -1
- package/dist/device/lock.d.ts.map +1 -1
- package/dist/device/lock.js +8 -7
- package/dist/device/lock.js.map +1 -1
- package/dist/device/meter.d.ts.map +1 -1
- package/dist/device/meter.js +9 -8
- package/dist/device/meter.js.map +1 -1
- package/dist/device/meterplus.d.ts.map +1 -1
- package/dist/device/meterplus.js +8 -7
- package/dist/device/meterplus.js.map +1 -1
- package/dist/device/motion.d.ts.map +1 -1
- package/dist/device/motion.js +7 -6
- package/dist/device/motion.js.map +1 -1
- package/dist/device/plug.d.ts.map +1 -1
- package/dist/device/plug.js +13 -12
- package/dist/device/plug.js.map +1 -1
- package/dist/device/striplight.d.ts +2 -2
- package/dist/device/striplight.d.ts.map +1 -1
- package/dist/device/striplight.js +44 -36
- package/dist/device/striplight.js.map +1 -1
- package/dist/irdevice/airconditioner.d.ts.map +1 -1
- package/dist/irdevice/airconditioner.js +10 -9
- package/dist/irdevice/airconditioner.js.map +1 -1
- package/dist/irdevice/airpurifier.d.ts.map +1 -1
- package/dist/irdevice/airpurifier.js +8 -7
- package/dist/irdevice/airpurifier.js.map +1 -1
- package/dist/irdevice/camera.d.ts.map +1 -1
- package/dist/irdevice/camera.js +7 -6
- package/dist/irdevice/camera.js.map +1 -1
- package/dist/irdevice/fan.d.ts.map +1 -1
- package/dist/irdevice/fan.js +10 -9
- package/dist/irdevice/fan.js.map +1 -1
- package/dist/irdevice/light.d.ts.map +1 -1
- package/dist/irdevice/light.js +9 -8
- package/dist/irdevice/light.js.map +1 -1
- package/dist/irdevice/other.d.ts.map +1 -1
- package/dist/irdevice/other.js +7 -6
- package/dist/irdevice/other.js.map +1 -1
- package/dist/irdevice/tv.d.ts.map +1 -1
- package/dist/irdevice/tv.js +16 -15
- package/dist/irdevice/tv.js.map +1 -1
- package/dist/irdevice/vacuumcleaner.d.ts.map +1 -1
- package/dist/irdevice/vacuumcleaner.js +7 -6
- package/dist/irdevice/vacuumcleaner.js.map +1 -1
- package/dist/irdevice/waterheater.d.ts.map +1 -1
- package/dist/irdevice/waterheater.js +7 -6
- package/dist/irdevice/waterheater.js.map +1 -1
- package/dist/platform.d.ts.map +1 -1
- package/dist/platform.js +24 -23
- package/dist/platform.js.map +1 -1
- package/package.json +1 -1
- package/src/device/bot.ts +19 -18
- package/src/device/colorbulb.ts +33 -26
- package/src/device/contact.ts +7 -6
- package/src/device/curtain.ts +14 -13
- package/src/device/humidifier.ts +18 -17
- package/src/device/lock.ts +8 -7
- package/src/device/meter.ts +9 -8
- package/src/device/meterplus.ts +8 -7
- package/src/device/motion.ts +7 -6
- package/src/device/plug.ts +13 -12
- package/src/device/striplight.ts +47 -39
- package/src/irdevice/airconditioner.ts +10 -9
- package/src/irdevice/airpurifier.ts +8 -7
- package/src/irdevice/camera.ts +7 -6
- package/src/irdevice/fan.ts +10 -9
- package/src/irdevice/light.ts +9 -8
- package/src/irdevice/other.ts +7 -6
- package/src/irdevice/tv.ts +16 -15
- package/src/irdevice/vacuumcleaner.ts +7 -6
- package/src/irdevice/waterheater.ts +7 -6
- package/src/platform.ts +24 -23
package/src/device/humidifier.ts
CHANGED
|
@@ -3,6 +3,7 @@ import crypto from 'crypto';
|
|
|
3
3
|
import { Context } from 'vm';
|
|
4
4
|
import { IncomingMessage } from 'http';
|
|
5
5
|
import { interval, Subject } from 'rxjs';
|
|
6
|
+
import superStringify from 'super-stringify';
|
|
6
7
|
import { SwitchBotPlatform } from '../platform';
|
|
7
8
|
import { debounceTime, skipWhile, take, tap } from 'rxjs/operators';
|
|
8
9
|
import { Service, PlatformAccessory, CharacteristicValue } from 'homebridge';
|
|
@@ -183,7 +184,7 @@ export class Humidifier {
|
|
|
183
184
|
} catch (e: any) {
|
|
184
185
|
this.errorLog(`Humidifier: ${this.accessory.displayName} failed pushChanges`);
|
|
185
186
|
if (this.deviceLogging.includes('debug')) {
|
|
186
|
-
this.errorLog(`Humidifier: ${this.accessory.displayName} failed pushChanges,` + ` Error Message: ${
|
|
187
|
+
this.errorLog(`Humidifier: ${this.accessory.displayName} failed pushChanges,` + ` Error Message: ${superStringify(e.message)}`);
|
|
187
188
|
}
|
|
188
189
|
this.apiError(e);
|
|
189
190
|
}
|
|
@@ -315,7 +316,7 @@ export class Humidifier {
|
|
|
315
316
|
this.autoMode = ad.serviceData.autoMode;
|
|
316
317
|
this.onState = ad.serviceData.onState;
|
|
317
318
|
this.percentage = ad.serviceData.percentage;
|
|
318
|
-
this.debugLog(`Humidifier: ${this.accessory.displayName} serviceData: ${
|
|
319
|
+
this.debugLog(`Humidifier: ${this.accessory.displayName} serviceData: ${superStringify(ad.serviceData)}`);
|
|
319
320
|
this.debugLog(
|
|
320
321
|
`Humidifier: ${this.accessory.displayName} model: ${ad.serviceData.model}, modelName: ${ad.serviceData.modelName},` +
|
|
321
322
|
`autoMode: ${ad.serviceData.autoMode}, onState: ${ad.serviceData.onState}, percentage: ${ad.serviceData.percentage}`,
|
|
@@ -346,7 +347,7 @@ export class Humidifier {
|
|
|
346
347
|
this.errorLog(`Humidifier: ${this.accessory.displayName} failed refreshStatus with BLE Connection`);
|
|
347
348
|
if (this.deviceLogging.includes('debug')) {
|
|
348
349
|
this.errorLog(
|
|
349
|
-
`Humidifier: ${this.accessory.displayName} failed refreshStatus with BLE Connection,` + ` Error Message: ${
|
|
350
|
+
`Humidifier: ${this.accessory.displayName} failed refreshStatus with BLE Connection,` + ` Error Message: ${superStringify(e.message)}`,
|
|
350
351
|
);
|
|
351
352
|
}
|
|
352
353
|
if (this.platform.config.credentials?.token) {
|
|
@@ -369,7 +370,7 @@ export class Humidifier {
|
|
|
369
370
|
});
|
|
370
371
|
// Set an event handler
|
|
371
372
|
switchbot.onadvertisement = (ad: any) => {
|
|
372
|
-
this.warnLog(`Humidifier: ${this.accessory.displayName} ad: ${
|
|
373
|
+
this.warnLog(`Humidifier: ${this.accessory.displayName} ad: ${superStringify(ad, null, ' ')}`);
|
|
373
374
|
};
|
|
374
375
|
await switchbot.wait(10000);
|
|
375
376
|
// Stop to monitor
|
|
@@ -419,7 +420,7 @@ export class Humidifier {
|
|
|
419
420
|
res.on('end', () => {
|
|
420
421
|
try {
|
|
421
422
|
this.deviceStatus = JSON.parse(rawData);
|
|
422
|
-
this.debugLog(`Humidifier: ${this.accessory.displayName} refreshStatus: ${
|
|
423
|
+
this.debugLog(`Humidifier: ${this.accessory.displayName} refreshStatus: ${superStringify(this.deviceStatus)}`);
|
|
423
424
|
this.auto = this.deviceStatus.body.auto;
|
|
424
425
|
this.power = this.deviceStatus.body.power;
|
|
425
426
|
this.lackWater = this.deviceStatus.body.lackWater;
|
|
@@ -442,7 +443,7 @@ export class Humidifier {
|
|
|
442
443
|
if (this.deviceLogging.includes('debug')) {
|
|
443
444
|
this.errorLog(
|
|
444
445
|
`Humidifier: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection,` +
|
|
445
|
-
` Error Message: ${
|
|
446
|
+
` Error Message: ${superStringify(e.message)}`,
|
|
446
447
|
);
|
|
447
448
|
}
|
|
448
449
|
this.apiError(e);
|
|
@@ -489,7 +490,7 @@ export class Humidifier {
|
|
|
489
490
|
this.errorLog(`Humidifier: ${this.accessory.displayName} failed pushChanges with BLE Connection`);
|
|
490
491
|
if (this.deviceLogging.includes('debug')) {
|
|
491
492
|
this.errorLog(
|
|
492
|
-
`Humidifier: ${this.accessory.displayName} failed pushChanges with BLE Connection,` + ` Error Message: ${
|
|
493
|
+
`Humidifier: ${this.accessory.displayName} failed pushChanges with BLE Connection,` + ` Error Message: ${superStringify(e.message)}`,
|
|
493
494
|
);
|
|
494
495
|
}
|
|
495
496
|
if (this.platform.config.credentials?.token) {
|
|
@@ -524,7 +525,7 @@ export class Humidifier {
|
|
|
524
525
|
const sign = signTerm.toString('base64');
|
|
525
526
|
this.debugLog(`Humidifier: ${this.accessory.displayName} sign: ${sign}`);
|
|
526
527
|
this.debugLog(`Pushing Manual: ${this.RelativeHumidityHumidifierThreshold}!`);
|
|
527
|
-
const body =
|
|
528
|
+
const body = superStringify({
|
|
528
529
|
'command': 'setMode',
|
|
529
530
|
'parameter': `${this.RelativeHumidityHumidifierThreshold}`,
|
|
530
531
|
'commandType': 'command',
|
|
@@ -556,7 +557,7 @@ export class Humidifier {
|
|
|
556
557
|
});
|
|
557
558
|
req.write(body);
|
|
558
559
|
req.end();
|
|
559
|
-
this.debugLog(`Humidifier: ${this.accessory.displayName} openAPIpushChanges: ${
|
|
560
|
+
this.debugLog(`Humidifier: ${this.accessory.displayName} openAPIpushChanges: ${superStringify(req)}`);
|
|
560
561
|
} else if (
|
|
561
562
|
this.TargetHumidifierDehumidifierState === this.platform.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER_OR_DEHUMIDIFIER &&
|
|
562
563
|
this.Active === this.platform.Characteristic.Active.ACTIVE
|
|
@@ -587,7 +588,7 @@ export class Humidifier {
|
|
|
587
588
|
const sign = signTerm.toString('base64');
|
|
588
589
|
this.debugLog(`Humidifier: ${this.accessory.displayName} sign: ${sign}`);
|
|
589
590
|
this.debugLog('Pushing Auto!');
|
|
590
|
-
const body =
|
|
591
|
+
const body = superStringify({
|
|
591
592
|
'command': 'setMode',
|
|
592
593
|
'parameter': 'auto',
|
|
593
594
|
'commandType': 'command',
|
|
@@ -619,14 +620,14 @@ export class Humidifier {
|
|
|
619
620
|
});
|
|
620
621
|
req.write(body);
|
|
621
622
|
req.end();
|
|
622
|
-
this.debugLog(`Humidifier: ${this.accessory.displayName} pushAutoChanges: ${
|
|
623
|
+
this.debugLog(`Humidifier: ${this.accessory.displayName} pushAutoChanges: ${superStringify(req)}`);
|
|
623
624
|
}
|
|
624
625
|
} catch (e: any) {
|
|
625
626
|
this.errorLog(`Humidifier: ${this.accessory.displayName} failed pushAutoChanges with OpenAPI Connection`);
|
|
626
627
|
if (this.deviceLogging.includes('debug')) {
|
|
627
628
|
this.errorLog(
|
|
628
629
|
`Humidifier: ${this.accessory.displayName} failed pushAutoChanges with OpenAPI Connection,` +
|
|
629
|
-
` Error Message: ${
|
|
630
|
+
` Error Message: ${superStringify(e.message)}`,
|
|
630
631
|
);
|
|
631
632
|
}
|
|
632
633
|
this.apiError(e);
|
|
@@ -649,7 +650,7 @@ export class Humidifier {
|
|
|
649
650
|
const sign = signTerm.toString('base64');
|
|
650
651
|
this.debugLog(`Humidifier: ${this.accessory.displayName} sign: ${sign}`);
|
|
651
652
|
this.debugLog('Pushing Off!');
|
|
652
|
-
const body =
|
|
653
|
+
const body = superStringify({
|
|
653
654
|
'command': 'turnOff',
|
|
654
655
|
'parameter': 'default',
|
|
655
656
|
'commandType': 'command',
|
|
@@ -681,14 +682,14 @@ export class Humidifier {
|
|
|
681
682
|
});
|
|
682
683
|
req.write(body);
|
|
683
684
|
req.end();
|
|
684
|
-
this.debugLog(`Humidifier: ${this.accessory.displayName} pushActiveChanges: ${
|
|
685
|
+
this.debugLog(`Humidifier: ${this.accessory.displayName} pushActiveChanges: ${superStringify(req)}`);
|
|
685
686
|
}
|
|
686
687
|
} catch (e: any) {
|
|
687
688
|
this.errorLog(`Humidifier: ${this.accessory.displayName} failed pushActiveChanges with OpenAPI Connection`);
|
|
688
689
|
if (this.deviceLogging.includes('debug')) {
|
|
689
690
|
this.errorLog(
|
|
690
691
|
`Humidifier: ${this.accessory.displayName} failed pushActiveChanges with OpenAPI Connection,` +
|
|
691
|
-
` Error Message: ${
|
|
692
|
+
` Error Message: ${superStringify(e.message)}`,
|
|
692
693
|
);
|
|
693
694
|
}
|
|
694
695
|
this.apiError(e);
|
|
@@ -804,7 +805,7 @@ export class Humidifier {
|
|
|
804
805
|
case 190:
|
|
805
806
|
this.errorLog(
|
|
806
807
|
`Humidifier: ${this.accessory.displayName} Device internal error due to device states not synchronized with server,` +
|
|
807
|
-
` Or command: ${
|
|
808
|
+
` Or command: ${superStringify(res)} format is invalid`,
|
|
808
809
|
);
|
|
809
810
|
break;
|
|
810
811
|
case 100:
|
|
@@ -876,7 +877,7 @@ export class Humidifier {
|
|
|
876
877
|
config['offline'] = device.offline;
|
|
877
878
|
}
|
|
878
879
|
if (Object.entries(config).length !== 0) {
|
|
879
|
-
this.infoLog(`Humidifier: ${this.accessory.displayName} Config: ${
|
|
880
|
+
this.infoLog(`Humidifier: ${this.accessory.displayName} Config: ${superStringify(config)}`);
|
|
880
881
|
}
|
|
881
882
|
}
|
|
882
883
|
|
package/src/device/lock.ts
CHANGED
|
@@ -3,6 +3,7 @@ import crypto from 'crypto';
|
|
|
3
3
|
import { Context } from 'vm';
|
|
4
4
|
import { IncomingMessage } from 'http';
|
|
5
5
|
import { interval, Subject } from 'rxjs';
|
|
6
|
+
import superStringify from 'super-stringify';
|
|
6
7
|
import { SwitchBotPlatform } from '../platform';
|
|
7
8
|
import { debounceTime, skipWhile, take, tap } from 'rxjs/operators';
|
|
8
9
|
import { Service, PlatformAccessory, CharacteristicValue } from 'homebridge';
|
|
@@ -121,7 +122,7 @@ export class Lock {
|
|
|
121
122
|
} catch (e: any) {
|
|
122
123
|
this.errorLog(`Lock: ${this.accessory.displayName} failed pushChanges`);
|
|
123
124
|
if (this.deviceLogging.includes('debug')) {
|
|
124
|
-
this.errorLog(`Lock: ${this.accessory.displayName} failed pushChanges,` + ` Error Message: ${
|
|
125
|
+
this.errorLog(`Lock: ${this.accessory.displayName} failed pushChanges,` + ` Error Message: ${superStringify(e.message)}`);
|
|
125
126
|
}
|
|
126
127
|
this.apiError(e);
|
|
127
128
|
}
|
|
@@ -182,7 +183,7 @@ export class Lock {
|
|
|
182
183
|
res.on('end', () => {
|
|
183
184
|
try {
|
|
184
185
|
this.deviceStatus = JSON.parse(rawData);
|
|
185
|
-
this.debugLog(`Lock: ${this.accessory.displayName} refreshStatus: ${
|
|
186
|
+
this.debugLog(`Lock: ${this.accessory.displayName} refreshStatus: ${superStringify(this.deviceStatus)}`);
|
|
186
187
|
this.lockState = this.deviceStatus.body.lockState;
|
|
187
188
|
this.doorState = this.deviceStatus.body.doorState;
|
|
188
189
|
this.parseStatus();
|
|
@@ -200,7 +201,7 @@ export class Lock {
|
|
|
200
201
|
this.errorLog(`Lock: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection`);
|
|
201
202
|
if (this.deviceLogging.includes('debug')) {
|
|
202
203
|
this.errorLog(
|
|
203
|
-
`Lock: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection,` + ` Error Message: ${
|
|
204
|
+
`Lock: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection,` + ` Error Message: ${superStringify(e.message)}`,
|
|
204
205
|
);
|
|
205
206
|
}
|
|
206
207
|
this.apiError(e);
|
|
@@ -229,7 +230,7 @@ export class Lock {
|
|
|
229
230
|
} else {
|
|
230
231
|
command = 'unlock';
|
|
231
232
|
}
|
|
232
|
-
const body =
|
|
233
|
+
const body = superStringify({
|
|
233
234
|
'command': `${command}`,
|
|
234
235
|
'parameter': 'default',
|
|
235
236
|
'commandType': 'command',
|
|
@@ -261,7 +262,7 @@ export class Lock {
|
|
|
261
262
|
});
|
|
262
263
|
req.write(body);
|
|
263
264
|
req.end();
|
|
264
|
-
this.debugLog(`Lock: ${this.accessory.displayName} pushchanges: ${
|
|
265
|
+
this.debugLog(`Lock: ${this.accessory.displayName} pushchanges: ${superStringify(req)}`);
|
|
265
266
|
this.accessory.context.On = this.LockTargetState;
|
|
266
267
|
interval(5000)
|
|
267
268
|
.pipe(take(1))
|
|
@@ -322,7 +323,7 @@ export class Lock {
|
|
|
322
323
|
case 190:
|
|
323
324
|
this.errorLog(
|
|
324
325
|
`Lock: ${this.accessory.displayName} Device internal error due to device states not synchronized with server,` +
|
|
325
|
-
` Or command: ${
|
|
326
|
+
` Or command: ${superStringify(res)} format is invalid`,
|
|
326
327
|
);
|
|
327
328
|
break;
|
|
328
329
|
case 100:
|
|
@@ -361,7 +362,7 @@ export class Lock {
|
|
|
361
362
|
config['scanDuration'] = device.scanDuration;
|
|
362
363
|
}
|
|
363
364
|
if (Object.entries(config).length !== 0) {
|
|
364
|
-
this.infoLog(`Lock: ${this.accessory.displayName} Config: ${
|
|
365
|
+
this.infoLog(`Lock: ${this.accessory.displayName} Config: ${superStringify(config)}`);
|
|
365
366
|
}
|
|
366
367
|
}
|
|
367
368
|
|
package/src/device/meter.ts
CHANGED
|
@@ -6,6 +6,7 @@ import { MqttClient } from 'mqtt';
|
|
|
6
6
|
import { connectAsync } from 'async-mqtt';
|
|
7
7
|
import { interval, Subject } from 'rxjs';
|
|
8
8
|
import { skipWhile } from 'rxjs/operators';
|
|
9
|
+
import superStringify from 'super-stringify';
|
|
9
10
|
import { SwitchBotPlatform } from '../platform';
|
|
10
11
|
import { Service, PlatformAccessory, Units, CharacteristicValue } from 'homebridge';
|
|
11
12
|
import { device, devicesConfig, serviceData, ad, switchbot, temperature, deviceStatus, HostDomain, DevicePath } from '../settings';
|
|
@@ -187,7 +188,7 @@ export class Meter {
|
|
|
187
188
|
?.join(':');
|
|
188
189
|
const options = this.device.mqttPubOptions || {};
|
|
189
190
|
this.mqttClient?.publish(`homebridge-switchbot/meter/${mac}`, `${message}`, options);
|
|
190
|
-
this.debugLog(`Meter: ${this.accessory.displayName} MQTT message: ${message} options:${
|
|
191
|
+
this.debugLog(`Meter: ${this.accessory.displayName} MQTT message: ${message} options:${superStringify(options)}`);
|
|
191
192
|
}
|
|
192
193
|
|
|
193
194
|
/*
|
|
@@ -327,10 +328,10 @@ export class Meter {
|
|
|
327
328
|
this.humidity = ad.serviceData.humidity;
|
|
328
329
|
this.battery = ad.serviceData.battery;
|
|
329
330
|
}
|
|
330
|
-
this.debugLog(`Meter: ${this.accessory.displayName} serviceData: ${
|
|
331
|
+
this.debugLog(`Meter: ${this.accessory.displayName} serviceData: ${superStringify(ad.serviceData)}`);
|
|
331
332
|
this.debugLog(
|
|
332
333
|
`Meter: ${this.accessory.displayName} model: ${ad.serviceData.model}, modelName: ${ad.serviceData.modelName}, ` +
|
|
333
|
-
`temperature: ${
|
|
334
|
+
`temperature: ${superStringify(ad.serviceData.temperature?.c)}, humidity: ${ad.serviceData.humidity}, ` +
|
|
334
335
|
`battery: ${ad.serviceData.battery}`,
|
|
335
336
|
);
|
|
336
337
|
|
|
@@ -359,7 +360,7 @@ export class Meter {
|
|
|
359
360
|
this.errorLog(`Meter: ${this.accessory.displayName} failed refreshStatus with BLE Connection`);
|
|
360
361
|
if (this.deviceLogging.includes('debug')) {
|
|
361
362
|
this.errorLog(
|
|
362
|
-
`Meter: ${this.accessory.displayName} failed refreshStatus with BLE Connection,` + ` Error Message: ${
|
|
363
|
+
`Meter: ${this.accessory.displayName} failed refreshStatus with BLE Connection,` + ` Error Message: ${superStringify(e.message)}`,
|
|
363
364
|
);
|
|
364
365
|
}
|
|
365
366
|
if (this.platform.config.credentials?.token) {
|
|
@@ -383,7 +384,7 @@ export class Meter {
|
|
|
383
384
|
});
|
|
384
385
|
// Set an event handler
|
|
385
386
|
switchbot.onadvertisement = (ad: any) => {
|
|
386
|
-
this.warnLog(`Meter: ${this.accessory.displayName} ad: ${
|
|
387
|
+
this.warnLog(`Meter: ${this.accessory.displayName} ad: ${superStringify(ad, null, ' ')}`);
|
|
387
388
|
};
|
|
388
389
|
await switchbot.wait(10000);
|
|
389
390
|
// Stop to monitor
|
|
@@ -434,7 +435,7 @@ export class Meter {
|
|
|
434
435
|
res.on('end', () => {
|
|
435
436
|
try {
|
|
436
437
|
this.deviceStatus = JSON.parse(rawData);
|
|
437
|
-
this.debugLog(`Meter: ${this.accessory.displayName} openAPIRefreshStatus: ${
|
|
438
|
+
this.debugLog(`Meter: ${this.accessory.displayName} openAPIRefreshStatus: ${superStringify(this.deviceStatus)}`);
|
|
438
439
|
this.Humidity = this.deviceStatus.body.humidity!;
|
|
439
440
|
this.Temperature = this.deviceStatus.body.temperature!;
|
|
440
441
|
this.parseStatus();
|
|
@@ -452,7 +453,7 @@ export class Meter {
|
|
|
452
453
|
this.errorLog(`Meter: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection`);
|
|
453
454
|
if (this.deviceLogging.includes('debug')) {
|
|
454
455
|
this.errorLog(
|
|
455
|
-
`Meter: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection,` + ` Error Message: ${
|
|
456
|
+
`Meter: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection,` + ` Error Message: ${superStringify(e.message)}`,
|
|
456
457
|
);
|
|
457
458
|
}
|
|
458
459
|
this.apiError(e);
|
|
@@ -541,7 +542,7 @@ export class Meter {
|
|
|
541
542
|
config['scanDuration'] = device.scanDuration;
|
|
542
543
|
}
|
|
543
544
|
if (Object.entries(config).length !== 0) {
|
|
544
|
-
this.infoLog(`Meter: ${this.accessory.displayName} Config: ${
|
|
545
|
+
this.infoLog(`Meter: ${this.accessory.displayName} Config: ${superStringify(config)}`);
|
|
545
546
|
}
|
|
546
547
|
}
|
|
547
548
|
|
package/src/device/meterplus.ts
CHANGED
|
@@ -3,6 +3,7 @@ import crypto from 'crypto';
|
|
|
3
3
|
import { Context } from 'vm';
|
|
4
4
|
import { interval, Subject } from 'rxjs';
|
|
5
5
|
import { skipWhile } from 'rxjs/operators';
|
|
6
|
+
import superStringify from 'super-stringify';
|
|
6
7
|
import { SwitchBotPlatform } from '../platform';
|
|
7
8
|
import { Service, PlatformAccessory, Units, CharacteristicValue } from 'homebridge';
|
|
8
9
|
import { device, devicesConfig, serviceData, ad, switchbot, temperature, deviceStatus, HostDomain, DevicePath } from '../settings';
|
|
@@ -264,10 +265,10 @@ export class MeterPlus {
|
|
|
264
265
|
this.temperature = ad.serviceData.temperature!.c;
|
|
265
266
|
this.humidity = ad.serviceData.humidity;
|
|
266
267
|
this.battery = ad.serviceData.battery;
|
|
267
|
-
this.debugLog(`Meter Plus: ${this.accessory.displayName} serviceData: ${
|
|
268
|
+
this.debugLog(`Meter Plus: ${this.accessory.displayName} serviceData: ${superStringify(ad.serviceData)}`);
|
|
268
269
|
this.debugLog(
|
|
269
270
|
`Meter Plus: ${this.accessory.displayName} model: ${ad.serviceData.model}, modelName: ${ad.serviceData.modelName}, ` +
|
|
270
|
-
`temperature: ${
|
|
271
|
+
`temperature: ${superStringify(ad.serviceData.temperature?.c)}, humidity: ${ad.serviceData.humidity}, ` +
|
|
271
272
|
`battery: ${ad.serviceData.battery}`,
|
|
272
273
|
);
|
|
273
274
|
|
|
@@ -296,7 +297,7 @@ export class MeterPlus {
|
|
|
296
297
|
this.errorLog(`Meter Plus: ${this.accessory.displayName} failed refreshStatus with BLE Connection`);
|
|
297
298
|
if (this.deviceLogging.includes('debug')) {
|
|
298
299
|
this.errorLog(
|
|
299
|
-
`Meter Plus: ${this.accessory.displayName} failed refreshStatus with BLE Connection,` + ` Error Message: ${
|
|
300
|
+
`Meter Plus: ${this.accessory.displayName} failed refreshStatus with BLE Connection,` + ` Error Message: ${superStringify(e.message)}`,
|
|
300
301
|
);
|
|
301
302
|
}
|
|
302
303
|
if (this.platform.config.credentials?.token) {
|
|
@@ -320,7 +321,7 @@ export class MeterPlus {
|
|
|
320
321
|
});
|
|
321
322
|
// Set an event handler
|
|
322
323
|
switchbot.onadvertisement = (ad: any) => {
|
|
323
|
-
this.warnLog(`Meter Plus: ${this.accessory.displayName} ad: ${
|
|
324
|
+
this.warnLog(`Meter Plus: ${this.accessory.displayName} ad: ${superStringify(ad, null, ' ')}`);
|
|
324
325
|
};
|
|
325
326
|
await switchbot.wait(10000);
|
|
326
327
|
// Stop to monitor
|
|
@@ -371,7 +372,7 @@ export class MeterPlus {
|
|
|
371
372
|
res.on('end', () => {
|
|
372
373
|
try {
|
|
373
374
|
this.deviceStatus = JSON.parse(rawData);
|
|
374
|
-
this.debugLog(`Meter Plus: ${this.accessory.displayName} openAPIRefreshStatus: ${
|
|
375
|
+
this.debugLog(`Meter Plus: ${this.accessory.displayName} openAPIRefreshStatus: ${superStringify(this.deviceStatus)}`);
|
|
375
376
|
this.Humidity = this.deviceStatus.body.humidity!;
|
|
376
377
|
this.Temperature = this.deviceStatus.body.temperature!;
|
|
377
378
|
this.parseStatus();
|
|
@@ -390,7 +391,7 @@ export class MeterPlus {
|
|
|
390
391
|
if (this.deviceLogging.includes('debug')) {
|
|
391
392
|
this.errorLog(
|
|
392
393
|
`Meter Plus: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection,` +
|
|
393
|
-
` Error Message: ${
|
|
394
|
+
` Error Message: ${superStringify(e.message)}`,
|
|
394
395
|
);
|
|
395
396
|
}
|
|
396
397
|
this.apiError(e);
|
|
@@ -476,7 +477,7 @@ export class MeterPlus {
|
|
|
476
477
|
config['scanDuration'] = device.scanDuration;
|
|
477
478
|
}
|
|
478
479
|
if (Object.entries(config).length !== 0) {
|
|
479
|
-
this.infoLog(`Meter Plus: ${this.accessory.displayName} Config: ${
|
|
480
|
+
this.infoLog(`Meter Plus: ${this.accessory.displayName} Config: ${superStringify(config)}`);
|
|
480
481
|
}
|
|
481
482
|
}
|
|
482
483
|
|
package/src/device/motion.ts
CHANGED
|
@@ -3,6 +3,7 @@ import crypto from 'crypto';
|
|
|
3
3
|
import { Context } from 'vm';
|
|
4
4
|
import { interval, Subject } from 'rxjs';
|
|
5
5
|
import { skipWhile } from 'rxjs/operators';
|
|
6
|
+
import superStringify from 'super-stringify';
|
|
6
7
|
import { SwitchBotPlatform } from '../platform';
|
|
7
8
|
import { Service, PlatformAccessory, CharacteristicValue } from 'homebridge';
|
|
8
9
|
import { device, devicesConfig, serviceData, switchbot, deviceStatus, ad, HostDomain, DevicePath } from '../settings';
|
|
@@ -250,7 +251,7 @@ export class Motion {
|
|
|
250
251
|
this.movement = ad.serviceData.movement;
|
|
251
252
|
this.battery = ad.serviceData.battery;
|
|
252
253
|
this.lightLevel = ad.serviceData.lightLevel;
|
|
253
|
-
this.debugLog(`Motion Sensor: ${this.accessory.displayName} serviceData: ${
|
|
254
|
+
this.debugLog(`Motion Sensor: ${this.accessory.displayName} serviceData: ${superStringify(ad.serviceData)}`);
|
|
254
255
|
this.debugLog(
|
|
255
256
|
`Motion Sensor: ${this.accessory.displayName} movement: ${ad.serviceData.movement}, lightLevel: ` +
|
|
256
257
|
`${ad.serviceData.lightLevel}, battery: ${ad.serviceData.battery}`,
|
|
@@ -282,7 +283,7 @@ export class Motion {
|
|
|
282
283
|
if (this.deviceLogging.includes('debug')) {
|
|
283
284
|
this.errorLog(
|
|
284
285
|
`Motion Sensor: ${this.accessory.displayName} failed refreshStatus with BLE Connection,` +
|
|
285
|
-
` Error Message: ${
|
|
286
|
+
` Error Message: ${superStringify(e.message)}`,
|
|
286
287
|
);
|
|
287
288
|
}
|
|
288
289
|
if (this.platform.config.credentials?.token) {
|
|
@@ -306,7 +307,7 @@ export class Motion {
|
|
|
306
307
|
});
|
|
307
308
|
// Set an event handler
|
|
308
309
|
switchbot.onadvertisement = (ad: any) => {
|
|
309
|
-
this.warnLog(`Motion Sensor: ${this.accessory.displayName} ad: ${
|
|
310
|
+
this.warnLog(`Motion Sensor: ${this.accessory.displayName} ad: ${superStringify(ad, null, ' ')}`);
|
|
310
311
|
};
|
|
311
312
|
await switchbot.wait(10000);
|
|
312
313
|
// Stop to monitor
|
|
@@ -357,7 +358,7 @@ export class Motion {
|
|
|
357
358
|
res.on('end', () => {
|
|
358
359
|
try {
|
|
359
360
|
this.deviceStatus = JSON.parse(rawData);
|
|
360
|
-
this.debugLog(`Motion Sensor: ${this.accessory.displayName} refreshStatus: ${
|
|
361
|
+
this.debugLog(`Motion Sensor: ${this.accessory.displayName} refreshStatus: ${superStringify(this.deviceStatus)}`);
|
|
361
362
|
this.moveDetected = this.deviceStatus.body.moveDetected;
|
|
362
363
|
this.brightness = this.deviceStatus.body.brightness;
|
|
363
364
|
this.parseStatus();
|
|
@@ -376,7 +377,7 @@ export class Motion {
|
|
|
376
377
|
if (this.deviceLogging.includes('debug')) {
|
|
377
378
|
this.errorLog(
|
|
378
379
|
`Motion Sensor: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection,` +
|
|
379
|
-
` Error Message: ${
|
|
380
|
+
` Error Message: ${superStringify(e.message)}`,
|
|
380
381
|
);
|
|
381
382
|
}
|
|
382
383
|
this.apiError(e);
|
|
@@ -449,7 +450,7 @@ export class Motion {
|
|
|
449
450
|
config['offline'] = device.offline;
|
|
450
451
|
}
|
|
451
452
|
if (Object.entries(config).length !== 0) {
|
|
452
|
-
this.infoLog(`Motion Sensor: ${this.accessory.displayName} Config: ${
|
|
453
|
+
this.infoLog(`Motion Sensor: ${this.accessory.displayName} Config: ${superStringify(config)}`);
|
|
453
454
|
}
|
|
454
455
|
}
|
|
455
456
|
|
package/src/device/plug.ts
CHANGED
|
@@ -3,6 +3,7 @@ import crypto from 'crypto';
|
|
|
3
3
|
import { Context } from 'vm';
|
|
4
4
|
import { IncomingMessage } from 'http';
|
|
5
5
|
import { interval, Subject } from 'rxjs';
|
|
6
|
+
import superStringify from 'super-stringify';
|
|
6
7
|
import { SwitchBotPlatform } from '../platform';
|
|
7
8
|
import { debounceTime, skipWhile, take, tap } from 'rxjs/operators';
|
|
8
9
|
import { Service, PlatformAccessory, CharacteristicValue } from 'homebridge';
|
|
@@ -115,7 +116,7 @@ export class Plug {
|
|
|
115
116
|
} catch (e: any) {
|
|
116
117
|
this.errorLog(`Plug: ${this.accessory.displayName} failed pushChanges`);
|
|
117
118
|
if (this.deviceLogging.includes('debug')) {
|
|
118
|
-
this.errorLog(`Plug: ${this.accessory.displayName} failed pushChanges,` + ` Error Message: ${
|
|
119
|
+
this.errorLog(`Plug: ${this.accessory.displayName} failed pushChanges,` + ` Error Message: ${superStringify(e.message)}`);
|
|
119
120
|
}
|
|
120
121
|
this.apiError(e);
|
|
121
122
|
}
|
|
@@ -198,7 +199,7 @@ export class Plug {
|
|
|
198
199
|
this.wifiRssi = ad.serviceData.wifiRssi;
|
|
199
200
|
this.overload = ad.serviceData.overload;
|
|
200
201
|
this.currentPower = ad.serviceData.currentPower;
|
|
201
|
-
this.debugLog(`Plug: ${this.accessory.displayName} serviceData: ${
|
|
202
|
+
this.debugLog(`Plug: ${this.accessory.displayName} serviceData: ${superStringify(ad.serviceData)}`);
|
|
202
203
|
this.debugLog(
|
|
203
204
|
`Plug: ${this.accessory.displayName} state: ${ad.serviceData.state}, ` +
|
|
204
205
|
`delay: ${ad.serviceData.delay}, timer: ${ad.serviceData.timer}, syncUtcTime: ${ad.serviceData.syncUtcTime} ` +
|
|
@@ -230,7 +231,7 @@ export class Plug {
|
|
|
230
231
|
this.errorLog(`Plug: ${this.accessory.displayName} failed refreshStatus with BLE Connection`);
|
|
231
232
|
if (this.deviceLogging.includes('debug')) {
|
|
232
233
|
this.errorLog(
|
|
233
|
-
`Plug: ${this.accessory.displayName} failed refreshStatus with BLE Connection,` + ` Error Message: ${
|
|
234
|
+
`Plug: ${this.accessory.displayName} failed refreshStatus with BLE Connection,` + ` Error Message: ${superStringify(e.message)}`,
|
|
234
235
|
);
|
|
235
236
|
}
|
|
236
237
|
if (this.platform.config.credentials?.token) {
|
|
@@ -262,7 +263,7 @@ export class Plug {
|
|
|
262
263
|
});
|
|
263
264
|
// Set an event handler
|
|
264
265
|
switchbot.onadvertisement = (ad: any) => {
|
|
265
|
-
this.warnLog(`Plug: ${this.accessory.displayName} ad: ${
|
|
266
|
+
this.warnLog(`Plug: ${this.accessory.displayName} ad: ${superStringify(ad, null, ' ')}`);
|
|
266
267
|
};
|
|
267
268
|
await switchbot.wait(10000);
|
|
268
269
|
// Stop to monitor
|
|
@@ -311,7 +312,7 @@ export class Plug {
|
|
|
311
312
|
res.on('end', () => {
|
|
312
313
|
try {
|
|
313
314
|
this.deviceStatus = JSON.parse(rawData);
|
|
314
|
-
this.debugLog(`Plug: ${this.accessory.displayName} refreshStatus: ${
|
|
315
|
+
this.debugLog(`Plug: ${this.accessory.displayName} refreshStatus: ${superStringify(this.deviceStatus)}`);
|
|
315
316
|
this.power = this.deviceStatus.body.power;
|
|
316
317
|
this.parseStatus();
|
|
317
318
|
this.updateHomeKitCharacteristics();
|
|
@@ -328,7 +329,7 @@ export class Plug {
|
|
|
328
329
|
this.errorLog(`Plug: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection`);
|
|
329
330
|
if (this.deviceLogging.includes('debug')) {
|
|
330
331
|
this.errorLog(
|
|
331
|
-
`Plug: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection,` + ` Error Message: ${
|
|
332
|
+
`Plug: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection,` + ` Error Message: ${superStringify(e.message)}`,
|
|
332
333
|
);
|
|
333
334
|
}
|
|
334
335
|
this.apiError(e);
|
|
@@ -380,11 +381,11 @@ export class Plug {
|
|
|
380
381
|
this.errorLog(`Plug: ${this.accessory.displayName} failed pushChanges with BLE Connection`);
|
|
381
382
|
if (this.deviceLogging.includes('debug')) {
|
|
382
383
|
this.errorLog(
|
|
383
|
-
`Plug: ${this.accessory.displayName} failed pushChanges with BLE Connection,` + ` Error Message: ${
|
|
384
|
+
`Plug: ${this.accessory.displayName} failed pushChanges with BLE Connection,` + ` Error Message: ${superStringify(e.message)}`,
|
|
384
385
|
);
|
|
385
386
|
}
|
|
386
387
|
if (this.platform.debugMode) {
|
|
387
|
-
this.errorLog(`Plug: ${this.accessory.displayName} failed pushChanges with BLE Connection,` + ` Error: ${
|
|
388
|
+
this.errorLog(`Plug: ${this.accessory.displayName} failed pushChanges with BLE Connection,` + ` Error: ${superStringify(e)}`);
|
|
388
389
|
}
|
|
389
390
|
if (this.platform.config.credentials?.token) {
|
|
390
391
|
this.warnLog(`Plug: ${this.accessory.displayName} Using OpenAPI Connection`);
|
|
@@ -427,7 +428,7 @@ export class Plug {
|
|
|
427
428
|
} else {
|
|
428
429
|
command = 'turnOff';
|
|
429
430
|
}
|
|
430
|
-
const body =
|
|
431
|
+
const body = superStringify({
|
|
431
432
|
'command': `${command}`,
|
|
432
433
|
'parameter': 'default',
|
|
433
434
|
'commandType': 'command',
|
|
@@ -459,7 +460,7 @@ export class Plug {
|
|
|
459
460
|
});
|
|
460
461
|
req.write(body);
|
|
461
462
|
req.end();
|
|
462
|
-
this.debugLog(`Plug: ${this.accessory.displayName} openAPIpushChanges: ${
|
|
463
|
+
this.debugLog(`Plug: ${this.accessory.displayName} openAPIpushChanges: ${superStringify(req)}`);
|
|
463
464
|
}
|
|
464
465
|
interval(5000)
|
|
465
466
|
.pipe(take(1))
|
|
@@ -506,7 +507,7 @@ export class Plug {
|
|
|
506
507
|
case 190:
|
|
507
508
|
this.errorLog(
|
|
508
509
|
`Plug: ${this.accessory.displayName} Device internal error due to device states not synchronized with server,` +
|
|
509
|
-
` Or command: ${
|
|
510
|
+
` Or command: ${superStringify(res)} format is invalid`,
|
|
510
511
|
);
|
|
511
512
|
break;
|
|
512
513
|
case 100:
|
|
@@ -589,7 +590,7 @@ export class Plug {
|
|
|
589
590
|
config['offline'] = device.offline;
|
|
590
591
|
}
|
|
591
592
|
if (Object.entries(config).length !== 0) {
|
|
592
|
-
this.infoLog(`Plug: ${this.accessory.displayName} Config: ${
|
|
593
|
+
this.infoLog(`Plug: ${this.accessory.displayName} Config: ${superStringify(config)}`);
|
|
593
594
|
}
|
|
594
595
|
}
|
|
595
596
|
|