@switchbot/homebridge-switchbot 0.1.2-beta.11 → 0.1.2-beta.15
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 +5 -1
- package/dist/devices/bots.d.ts.map +1 -1
- package/dist/devices/bots.js +10 -13
- package/dist/devices/bots.js.map +1 -1
- package/dist/devices/bulb.d.ts.map +1 -1
- package/dist/devices/bulb.js +4 -5
- package/dist/devices/bulb.js.map +1 -1
- package/dist/devices/contact.d.ts.map +1 -1
- package/dist/devices/contact.js +22 -14
- package/dist/devices/contact.js.map +1 -1
- package/dist/devices/curtains.d.ts.map +1 -1
- package/dist/devices/curtains.js +9 -12
- package/dist/devices/curtains.js.map +1 -1
- package/dist/devices/humidifiers.d.ts.map +1 -1
- package/dist/devices/humidifiers.js +4 -10
- package/dist/devices/humidifiers.js.map +1 -1
- package/dist/devices/indoorcam.d.ts.map +1 -1
- package/dist/devices/indoorcam.js +8 -11
- package/dist/devices/indoorcam.js.map +1 -1
- package/dist/devices/meters.d.ts.map +1 -1
- package/dist/devices/meters.js +14 -28
- package/dist/devices/meters.js.map +1 -1
- package/dist/devices/motion.d.ts.map +1 -1
- package/dist/devices/motion.js +6 -9
- package/dist/devices/motion.js.map +1 -1
- package/dist/devices/plugs.d.ts.map +1 -1
- package/dist/devices/plugs.js +8 -11
- package/dist/devices/plugs.js.map +1 -1
- package/dist/platform.d.ts +5 -0
- package/dist/platform.d.ts.map +1 -1
- package/dist/platform.js +44 -70
- package/dist/platform.js.map +1 -1
- package/package.json +3 -3
- package/src/devices/bots.ts +10 -16
- package/src/devices/bulb.ts +4 -9
- package/src/devices/contact.ts +19 -18
- package/src/devices/curtains.ts +9 -16
- package/src/devices/humidifiers.ts +4 -10
- package/src/devices/indoorcam.ts +8 -14
- package/src/devices/meters.ts +14 -33
- package/src/devices/motion.ts +6 -13
- package/src/devices/plugs.ts +8 -14
- package/src/platform.ts +47 -161
package/src/platform.ts
CHANGED
|
@@ -74,8 +74,8 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
74
74
|
|
|
75
75
|
// setup axios interceptor to add headers / api key to each request
|
|
76
76
|
this.axios.interceptors.request.use((request: AxiosRequestConfig) => {
|
|
77
|
-
request.headers
|
|
78
|
-
request.headers['Content-Type'] = 'application/json; charset=utf8';
|
|
77
|
+
request.headers!.Authorization = this.config.credentials?.openToken;
|
|
78
|
+
request.headers!['Content-Type'] = 'application/json; charset=utf8';
|
|
79
79
|
return request;
|
|
80
80
|
});
|
|
81
81
|
|
|
@@ -208,16 +208,14 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
208
208
|
*/
|
|
209
209
|
async discoverDevices() {
|
|
210
210
|
try {
|
|
211
|
-
const devices = (await this.axios.get(DeviceURL)).data;
|
|
211
|
+
const devices: any = (await this.axios.get(DeviceURL)).data;
|
|
212
212
|
|
|
213
213
|
this.deviceListInfo(devices);
|
|
214
214
|
this.debug(JSON.stringify(devices));
|
|
215
215
|
this.log.info('Total SwitchBot Devices Found:', devices.body.deviceList.length);
|
|
216
216
|
this.log.info('Total IR Devices Found:', devices.body.infraredRemoteList.length);
|
|
217
217
|
for (const device of devices.body.deviceList) {
|
|
218
|
-
|
|
219
|
-
this.deviceInfo(device);
|
|
220
|
-
}
|
|
218
|
+
this.deviceInfo(device);
|
|
221
219
|
this.debug(JSON.stringify(device));
|
|
222
220
|
// For Future Devices
|
|
223
221
|
switch (device.deviceType) {
|
|
@@ -272,9 +270,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
272
270
|
}
|
|
273
271
|
}
|
|
274
272
|
for (const device of devices.body.infraredRemoteList) {
|
|
275
|
-
|
|
276
|
-
this.deviceInfo(device);
|
|
277
|
-
}
|
|
273
|
+
this.deviceInfo(device);
|
|
278
274
|
this.debug(JSON.stringify(device));
|
|
279
275
|
// For Future Devices
|
|
280
276
|
switch (device.remoteType) {
|
|
@@ -400,14 +396,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
400
396
|
this.api.registerPlatformAccessories(PLUGIN_NAME, PLATFORM_NAME, [accessory]);
|
|
401
397
|
this.accessories.push(accessory);
|
|
402
398
|
} else {
|
|
403
|
-
|
|
404
|
-
this.log.error(
|
|
405
|
-
'Unable to Register new device: %s %s - %s',
|
|
406
|
-
device.deviceName,
|
|
407
|
-
device.deviceType,
|
|
408
|
-
device.deviceId,
|
|
409
|
-
);
|
|
410
|
-
}
|
|
399
|
+
this.device(`Unable to Register new device: ${device.deviceName} ${device.deviceType} - ${device.deviceId}`);
|
|
411
400
|
}
|
|
412
401
|
}
|
|
413
402
|
|
|
@@ -467,14 +456,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
467
456
|
this.api.registerPlatformAccessories(PLUGIN_NAME, PLATFORM_NAME, [accessory]);
|
|
468
457
|
this.accessories.push(accessory);
|
|
469
458
|
} else {
|
|
470
|
-
|
|
471
|
-
this.log.error(
|
|
472
|
-
'Unable to Register new device: %s %s - %s',
|
|
473
|
-
device.deviceName,
|
|
474
|
-
device.deviceType,
|
|
475
|
-
device.deviceId,
|
|
476
|
-
);
|
|
477
|
-
}
|
|
459
|
+
this.device(`Unable to Register new device: ${device.deviceName} ${device.deviceType} - ${device.deviceId}`);
|
|
478
460
|
}
|
|
479
461
|
}
|
|
480
462
|
|
|
@@ -530,14 +512,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
530
512
|
this.api.registerPlatformAccessories(PLUGIN_NAME, PLATFORM_NAME, [accessory]);
|
|
531
513
|
this.accessories.push(accessory);
|
|
532
514
|
} else {
|
|
533
|
-
|
|
534
|
-
this.log.error(
|
|
535
|
-
'Unable to Register new device: %s %s - %s',
|
|
536
|
-
device.deviceName,
|
|
537
|
-
device.deviceType,
|
|
538
|
-
device.deviceId,
|
|
539
|
-
);
|
|
540
|
-
}
|
|
515
|
+
this.device(`Unable to Register new device: ${device.deviceName} ${device.deviceType} - ${device.deviceId}`);
|
|
541
516
|
}
|
|
542
517
|
}
|
|
543
518
|
|
|
@@ -591,14 +566,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
591
566
|
this.api.registerPlatformAccessories(PLUGIN_NAME, PLATFORM_NAME, [accessory]);
|
|
592
567
|
this.accessories.push(accessory);
|
|
593
568
|
} else {
|
|
594
|
-
|
|
595
|
-
this.log.error(
|
|
596
|
-
'Unable to Register new device: %s %s - %s',
|
|
597
|
-
device.deviceName,
|
|
598
|
-
device.deviceType,
|
|
599
|
-
device.deviceId,
|
|
600
|
-
);
|
|
601
|
-
}
|
|
569
|
+
this.device(`Unable to Register new device: ${device.deviceName} ${device.deviceType} - ${device.deviceId}`);
|
|
602
570
|
}
|
|
603
571
|
}
|
|
604
572
|
|
|
@@ -652,14 +620,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
652
620
|
this.api.registerPlatformAccessories(PLUGIN_NAME, PLATFORM_NAME, [accessory]);
|
|
653
621
|
this.accessories.push(accessory);
|
|
654
622
|
} else {
|
|
655
|
-
|
|
656
|
-
this.log.error(
|
|
657
|
-
'Unable to Register new device: %s %s - %s',
|
|
658
|
-
device.deviceName,
|
|
659
|
-
device.deviceType,
|
|
660
|
-
device.deviceId,
|
|
661
|
-
);
|
|
662
|
-
}
|
|
623
|
+
this.device(`Unable to Register new device: ${device.deviceName} ${device.deviceType} - ${device.deviceId}`);
|
|
663
624
|
}
|
|
664
625
|
}
|
|
665
626
|
|
|
@@ -696,16 +657,13 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
696
657
|
// the accessory does not yet exist, so we need to create it
|
|
697
658
|
this.log.info('Adding new accessory: %s %s DeviceID: %s', device.deviceName, device.deviceType, device.deviceId);
|
|
698
659
|
if (device.group && !this.config.options?.curtain?.disable_group) {
|
|
699
|
-
this.
|
|
700
|
-
|
|
701
|
-
device.deviceName,
|
|
702
|
-
device.deviceId,
|
|
703
|
-
);
|
|
660
|
+
this.device(`Your Curtains are grouped
|
|
661
|
+
, Secondary curtain automatically hidden. Main Curtain: ${device.deviceName}, DeviceID: ${device.deviceId}`);
|
|
704
662
|
} else {
|
|
705
663
|
if (device.master) {
|
|
706
|
-
this.
|
|
664
|
+
this.device(`Main Curtain: ${device.deviceName}, DeviceID: ${device.deviceId}`);
|
|
707
665
|
} else {
|
|
708
|
-
this.
|
|
666
|
+
this.device(`Secondary Curtain: ${device.deviceName}, DeviceID: ${device.deviceId}`);
|
|
709
667
|
}
|
|
710
668
|
}
|
|
711
669
|
|
|
@@ -728,14 +686,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
728
686
|
this.api.registerPlatformAccessories(PLUGIN_NAME, PLATFORM_NAME, [accessory]);
|
|
729
687
|
this.accessories.push(accessory);
|
|
730
688
|
} else {
|
|
731
|
-
|
|
732
|
-
this.log.error(
|
|
733
|
-
'Unable to Register new device: %s %s - %s',
|
|
734
|
-
device.deviceName,
|
|
735
|
-
device.deviceType,
|
|
736
|
-
device.deviceId,
|
|
737
|
-
);
|
|
738
|
-
}
|
|
689
|
+
this.device(`Unable to Register new device: ${device.deviceName} ${device.deviceType} - ${device.deviceId}`);
|
|
739
690
|
}
|
|
740
691
|
}
|
|
741
692
|
|
|
@@ -799,14 +750,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
799
750
|
this.api.registerPlatformAccessories(PLUGIN_NAME, PLATFORM_NAME, [accessory]);
|
|
800
751
|
this.accessories.push(accessory);
|
|
801
752
|
} else {
|
|
802
|
-
|
|
803
|
-
this.log.error(
|
|
804
|
-
'Unable to Register new device: %s %s - %s',
|
|
805
|
-
device.deviceName,
|
|
806
|
-
device.deviceType,
|
|
807
|
-
device.deviceId,
|
|
808
|
-
);
|
|
809
|
-
}
|
|
753
|
+
this.device(`Unable to Register new device: ${device.deviceName} ${device.deviceType} - ${device.deviceId}`);
|
|
810
754
|
}
|
|
811
755
|
}
|
|
812
756
|
|
|
@@ -862,14 +806,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
862
806
|
this.api.registerPlatformAccessories(PLUGIN_NAME, PLATFORM_NAME, [accessory]);
|
|
863
807
|
this.accessories.push(accessory);
|
|
864
808
|
} else {
|
|
865
|
-
|
|
866
|
-
this.log.error(
|
|
867
|
-
'Unable to Register new device: %s %s - %s',
|
|
868
|
-
device.deviceName,
|
|
869
|
-
device.deviceType,
|
|
870
|
-
device.deviceId,
|
|
871
|
-
);
|
|
872
|
-
}
|
|
809
|
+
this.device(`Unable to Register new device: ${device.deviceName} ${device.deviceType} - ${device.deviceId}`);
|
|
873
810
|
}
|
|
874
811
|
}
|
|
875
812
|
|
|
@@ -930,14 +867,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
930
867
|
this.api.publishExternalAccessories(PLUGIN_NAME, [accessory]);
|
|
931
868
|
this.accessories.push(accessory);
|
|
932
869
|
} else {
|
|
933
|
-
|
|
934
|
-
this.log.error(
|
|
935
|
-
'Unable to Register new device: %s %s - %s',
|
|
936
|
-
device.deviceName,
|
|
937
|
-
device.remoteType,
|
|
938
|
-
device.deviceId,
|
|
939
|
-
);
|
|
940
|
-
}
|
|
870
|
+
this.device(`Unable to Register new device: ${device.deviceName} ${device.remoteType} - ${device.deviceId}`);
|
|
941
871
|
}
|
|
942
872
|
}
|
|
943
873
|
|
|
@@ -994,14 +924,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
994
924
|
this.api.registerPlatformAccessories(PLUGIN_NAME, PLATFORM_NAME, [accessory]);
|
|
995
925
|
this.accessories.push(accessory);
|
|
996
926
|
} else {
|
|
997
|
-
|
|
998
|
-
this.log.error(
|
|
999
|
-
'Unable to Register new device: %s %s - %s',
|
|
1000
|
-
device.deviceName,
|
|
1001
|
-
device.remoteType,
|
|
1002
|
-
device.deviceId,
|
|
1003
|
-
);
|
|
1004
|
-
}
|
|
927
|
+
this.device(`Unable to Register new device: ${device.deviceName} ${device.remoteType} - ${device.deviceId}`);
|
|
1005
928
|
}
|
|
1006
929
|
}
|
|
1007
930
|
|
|
@@ -1057,14 +980,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
1057
980
|
this.api.registerPlatformAccessories(PLUGIN_NAME, PLATFORM_NAME, [accessory]);
|
|
1058
981
|
this.accessories.push(accessory);
|
|
1059
982
|
} else {
|
|
1060
|
-
|
|
1061
|
-
this.log.error(
|
|
1062
|
-
'Unable to Register new device: %s %s - %s',
|
|
1063
|
-
device.deviceName,
|
|
1064
|
-
device.remoteType,
|
|
1065
|
-
device.deviceId,
|
|
1066
|
-
);
|
|
1067
|
-
}
|
|
983
|
+
this.device(`Unable to Register new device: ${device.deviceName} ${device.remoteType} - ${device.deviceId}`);
|
|
1068
984
|
}
|
|
1069
985
|
}
|
|
1070
986
|
|
|
@@ -1120,14 +1036,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
1120
1036
|
this.api.registerPlatformAccessories(PLUGIN_NAME, PLATFORM_NAME, [accessory]);
|
|
1121
1037
|
this.accessories.push(accessory);
|
|
1122
1038
|
} else {
|
|
1123
|
-
|
|
1124
|
-
this.log.error(
|
|
1125
|
-
'Unable to Register new device: %s %s - %s',
|
|
1126
|
-
device.deviceName,
|
|
1127
|
-
device.remoteType,
|
|
1128
|
-
device.deviceId,
|
|
1129
|
-
);
|
|
1130
|
-
}
|
|
1039
|
+
this.device(`Unable to Register new device: ${device.deviceName} ${device.remoteType} - ${device.deviceId}`);
|
|
1131
1040
|
}
|
|
1132
1041
|
}
|
|
1133
1042
|
|
|
@@ -1183,14 +1092,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
1183
1092
|
this.api.registerPlatformAccessories(PLUGIN_NAME, PLATFORM_NAME, [accessory]);
|
|
1184
1093
|
this.accessories.push(accessory);
|
|
1185
1094
|
} else {
|
|
1186
|
-
|
|
1187
|
-
this.log.error(
|
|
1188
|
-
'Unable to Register new device: %s %s - %s',
|
|
1189
|
-
device.deviceName,
|
|
1190
|
-
device.remoteType,
|
|
1191
|
-
device.deviceId,
|
|
1192
|
-
);
|
|
1193
|
-
}
|
|
1095
|
+
this.device(`Unable to Register new device: ${device.deviceName} ${device.remoteType} - ${device.deviceId}`);
|
|
1194
1096
|
}
|
|
1195
1097
|
}
|
|
1196
1098
|
|
|
@@ -1246,14 +1148,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
1246
1148
|
this.api.registerPlatformAccessories(PLUGIN_NAME, PLATFORM_NAME, [accessory]);
|
|
1247
1149
|
this.accessories.push(accessory);
|
|
1248
1150
|
} else {
|
|
1249
|
-
|
|
1250
|
-
this.log.error(
|
|
1251
|
-
'Unable to Register new device: %s %s - %s',
|
|
1252
|
-
device.deviceName,
|
|
1253
|
-
device.remoteType,
|
|
1254
|
-
device.deviceId,
|
|
1255
|
-
);
|
|
1256
|
-
}
|
|
1151
|
+
this.device(`Unable to Register new device: ${device.deviceName} ${device.remoteType} - ${device.deviceId}`);
|
|
1257
1152
|
}
|
|
1258
1153
|
}
|
|
1259
1154
|
|
|
@@ -1309,14 +1204,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
1309
1204
|
this.api.registerPlatformAccessories(PLUGIN_NAME, PLATFORM_NAME, [accessory]);
|
|
1310
1205
|
this.accessories.push(accessory);
|
|
1311
1206
|
} else {
|
|
1312
|
-
|
|
1313
|
-
this.log.error(
|
|
1314
|
-
'Unable to Register new device: %s %s - %s',
|
|
1315
|
-
device.deviceName,
|
|
1316
|
-
device.remoteType,
|
|
1317
|
-
device.deviceId,
|
|
1318
|
-
);
|
|
1319
|
-
}
|
|
1207
|
+
this.device(`Unable to Register new device: ${device.deviceName} ${device.remoteType} - ${device.deviceId}`);
|
|
1320
1208
|
}
|
|
1321
1209
|
}
|
|
1322
1210
|
|
|
@@ -1372,14 +1260,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
1372
1260
|
this.api.registerPlatformAccessories(PLUGIN_NAME, PLATFORM_NAME, [accessory]);
|
|
1373
1261
|
this.accessories.push(accessory);
|
|
1374
1262
|
} else {
|
|
1375
|
-
|
|
1376
|
-
this.log.error(
|
|
1377
|
-
'Unable to Register new device: %s %s - %s',
|
|
1378
|
-
device.deviceName,
|
|
1379
|
-
device.remoteType,
|
|
1380
|
-
device.deviceId,
|
|
1381
|
-
);
|
|
1382
|
-
}
|
|
1263
|
+
this.device(`Unable to Register new device: ${device.deviceName} ${device.remoteType} - ${device.deviceId}`);
|
|
1383
1264
|
}
|
|
1384
1265
|
}
|
|
1385
1266
|
|
|
@@ -1435,14 +1316,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
1435
1316
|
this.api.registerPlatformAccessories(PLUGIN_NAME, PLATFORM_NAME, [accessory]);
|
|
1436
1317
|
this.accessories.push(accessory);
|
|
1437
1318
|
} else {
|
|
1438
|
-
|
|
1439
|
-
this.log.error(
|
|
1440
|
-
'Unable to Register new device: %s %s - %s',
|
|
1441
|
-
device.deviceName,
|
|
1442
|
-
device.remoteType,
|
|
1443
|
-
device.deviceId,
|
|
1444
|
-
);
|
|
1445
|
-
}
|
|
1319
|
+
this.device(`Unable to Register new device: ${device.deviceName} ${device.remoteType} - ${device.deviceId}`);
|
|
1446
1320
|
}
|
|
1447
1321
|
}
|
|
1448
1322
|
|
|
@@ -1474,17 +1348,19 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
1474
1348
|
}
|
|
1475
1349
|
|
|
1476
1350
|
public deviceListInfo(devices: deviceResponses) {
|
|
1477
|
-
this.
|
|
1351
|
+
this.device(JSON.stringify(devices));
|
|
1478
1352
|
}
|
|
1479
1353
|
|
|
1480
1354
|
public async deviceInfo(device: irdevice | device) {
|
|
1481
|
-
this.
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1355
|
+
if (this.config.options?.debug === 'device') {
|
|
1356
|
+
this.device(JSON.stringify(device));
|
|
1357
|
+
const deviceStatus: deviceStatusResponse = (await this.axios.get(`${DeviceURL}/${device.deviceId}/status`)).data;
|
|
1358
|
+
if (deviceStatus.message === 'success') {
|
|
1359
|
+
this.device(`${device.deviceName} deviceStatus - ${JSON.stringify(deviceStatus)}`);
|
|
1360
|
+
} else {
|
|
1361
|
+
this.device(`${device.deviceName} deviceStatus - ${JSON.stringify(deviceStatus.message)}`);
|
|
1362
|
+
this.device('Unable to retreive device status.');
|
|
1363
|
+
}
|
|
1488
1364
|
}
|
|
1489
1365
|
}
|
|
1490
1366
|
|
|
@@ -1495,7 +1371,17 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
1495
1371
|
debug(...log: any[]) {
|
|
1496
1372
|
if (this.config.options!.debug === 'debug') {
|
|
1497
1373
|
this.log.info('[DEBUG]', String(...log));
|
|
1498
|
-
} else
|
|
1374
|
+
} else {
|
|
1375
|
+
this.log.debug(String(...log));
|
|
1376
|
+
}
|
|
1377
|
+
}
|
|
1378
|
+
|
|
1379
|
+
/**
|
|
1380
|
+
* If debug level logging is turned on, log to log.info
|
|
1381
|
+
* Otherwise send debug logs to log.debug
|
|
1382
|
+
*/
|
|
1383
|
+
device(...log: any[]) {
|
|
1384
|
+
if (this.config.options!.debug === 'device') {
|
|
1499
1385
|
this.log.warn('[DEVICE]', String(...log));
|
|
1500
1386
|
} else {
|
|
1501
1387
|
this.log.debug(String(...log));
|