@switchbot/homebridge-switchbot 1.12.7-beta.5 → 1.12.7
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 +12 -0
- package/config.schema.json +6 -6
- package/dist/device/bot.js +2 -2
- package/dist/device/bot.js.map +1 -1
- package/dist/device/colorbulb.d.ts +0 -6
- package/dist/device/colorbulb.d.ts.map +1 -1
- package/dist/device/colorbulb.js +74 -89
- package/dist/device/colorbulb.js.map +1 -1
- package/dist/device/curtain.js +1 -1
- package/dist/device/curtain.js.map +1 -1
- package/dist/device/humidifier.js +2 -2
- package/dist/device/humidifier.js.map +1 -1
- package/dist/device/lock.d.ts.map +1 -1
- package/dist/device/lock.js +1 -21
- package/dist/device/lock.js.map +1 -1
- package/dist/device/meter.d.ts +0 -1
- package/dist/device/meter.d.ts.map +1 -1
- package/dist/device/meter.js +1 -14
- package/dist/device/meter.js.map +1 -1
- package/dist/device/meterplus.d.ts +76 -0
- package/dist/device/meterplus.d.ts.map +1 -0
- package/dist/device/meterplus.js +464 -0
- package/dist/device/meterplus.js.map +1 -0
- package/dist/device/plug.js +1 -1
- package/dist/device/plug.js.map +1 -1
- package/dist/device/striplight.d.ts +90 -0
- package/dist/device/striplight.d.ts.map +1 -0
- package/dist/device/striplight.js +487 -0
- package/dist/device/striplight.js.map +1 -0
- package/dist/platform.d.ts +2 -0
- package/dist/platform.d.ts.map +1 -1
- package/dist/platform.js +119 -9
- package/dist/platform.js.map +1 -1
- package/package.json +76 -76
- package/src/device/bot.ts +2 -2
- package/src/device/colorbulb.ts +74 -89
- package/src/device/curtain.ts +1 -1
- package/src/device/humidifier.ts +2 -2
- package/src/device/lock.ts +1 -21
- package/src/device/meter.ts +1 -13
- package/src/device/meterplus.ts +518 -0
- package/src/device/plug.ts +1 -1
- package/src/device/striplight.ts +583 -0
- package/src/platform.ts +127 -9
package/src/platform.ts
CHANGED
|
@@ -5,7 +5,9 @@ import { Meter } from './device/meter';
|
|
|
5
5
|
import { Motion } from './device/motion';
|
|
6
6
|
import { Contact } from './device/contact';
|
|
7
7
|
import { Curtain } from './device/curtain';
|
|
8
|
+
import { MeterPlus } from './device/meterplus';
|
|
8
9
|
import { ColorBulb } from './device/colorbulb';
|
|
10
|
+
import { StripLight } from './device/striplight';
|
|
9
11
|
import { Humidifier } from './device/humidifier';
|
|
10
12
|
import { TV } from './irdevice/tv';
|
|
11
13
|
import { Fan } from './irdevice/fan';
|
|
@@ -374,10 +376,13 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
374
376
|
this.createBot(device);
|
|
375
377
|
break;
|
|
376
378
|
case 'Meter':
|
|
377
|
-
case 'MeterPlus':
|
|
378
379
|
this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId}`);
|
|
379
380
|
this.createMeter(device);
|
|
380
381
|
break;
|
|
382
|
+
case 'MeterPlus':
|
|
383
|
+
this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId}`);
|
|
384
|
+
this.createMeterPlus(device);
|
|
385
|
+
break;
|
|
381
386
|
case 'Motion Sensor':
|
|
382
387
|
this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId}`);
|
|
383
388
|
this.createMotion(device);
|
|
@@ -401,10 +406,13 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
401
406
|
this.createLock(device);
|
|
402
407
|
break;
|
|
403
408
|
case 'Color Bulb':
|
|
404
|
-
case 'Strip Light':
|
|
405
409
|
this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId}`);
|
|
406
410
|
this.createColorBulb(device);
|
|
407
411
|
break;
|
|
412
|
+
case 'Strip Light':
|
|
413
|
+
this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId}`);
|
|
414
|
+
this.createStripLight(device);
|
|
415
|
+
break;
|
|
408
416
|
case 'Indoor Cam':
|
|
409
417
|
this.deviceInfo(device);
|
|
410
418
|
this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId}`);
|
|
@@ -495,7 +503,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
495
503
|
this.debugLog(`Device: ${device.deviceName} OpenAPI Connection Enabled`);
|
|
496
504
|
} else {
|
|
497
505
|
this.registeringDevice = false;
|
|
498
|
-
this.debugLog(`Device: ${device.deviceName}
|
|
506
|
+
this.debugLog(`Device: ${device.deviceName} OpenAPI and BLE Are Not Enabled`);
|
|
499
507
|
}
|
|
500
508
|
return this.registeringDevice;
|
|
501
509
|
}
|
|
@@ -671,6 +679,61 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
671
679
|
}
|
|
672
680
|
}
|
|
673
681
|
|
|
682
|
+
private async createMeterPlus(device: device & devicesConfig) {
|
|
683
|
+
const uuid = this.api.hap.uuid.generate(`${device.deviceId}-${device.deviceType}`);
|
|
684
|
+
|
|
685
|
+
// see if an accessory with the same uuid has already been registered and restored from
|
|
686
|
+
// the cached devices we stored in the `configureAccessory` method above
|
|
687
|
+
const existingAccessory = this.accessories.find((accessory) => accessory.UUID === uuid);
|
|
688
|
+
|
|
689
|
+
if (existingAccessory) {
|
|
690
|
+
// the accessory already exists
|
|
691
|
+
if (this.registerDevice(device)) {
|
|
692
|
+
this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
|
|
693
|
+
|
|
694
|
+
// if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
|
|
695
|
+
existingAccessory.context.model = device.deviceType;
|
|
696
|
+
existingAccessory.context.deviceID = device.deviceId;
|
|
697
|
+
existingAccessory.displayName = device.deviceName;
|
|
698
|
+
existingAccessory.context.firmwareRevision = this.version;
|
|
699
|
+
existingAccessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
|
|
700
|
+
await this.connectionTypeExistingAccessory(device, existingAccessory);
|
|
701
|
+
this.api.updatePlatformAccessories([existingAccessory]);
|
|
702
|
+
// create the accessory handler for the restored accessory
|
|
703
|
+
// this is imported from `platformAccessory.ts`
|
|
704
|
+
new MeterPlus(this, existingAccessory, device);
|
|
705
|
+
this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${existingAccessory.UUID})`);
|
|
706
|
+
} else {
|
|
707
|
+
this.unregisterPlatformAccessories(existingAccessory);
|
|
708
|
+
}
|
|
709
|
+
} else if (this.registerDevice(device)) {
|
|
710
|
+
// the accessory does not yet exist, so we need to create it
|
|
711
|
+
this.infoLog(`Adding new accessory: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
|
|
712
|
+
|
|
713
|
+
// create a new accessory
|
|
714
|
+
const accessory = new this.api.platformAccessory(device.deviceName, uuid);
|
|
715
|
+
|
|
716
|
+
// store a copy of the device object in the `accessory.context`
|
|
717
|
+
// the `context` property can be used to store any data about the accessory you may need
|
|
718
|
+
accessory.context.device = device;
|
|
719
|
+
accessory.context.model = device.deviceType;
|
|
720
|
+
accessory.context.deviceID = device.deviceId;
|
|
721
|
+
accessory.context.firmwareRevision = this.version;
|
|
722
|
+
accessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
|
|
723
|
+
await this.connectionTypeNewAccessory(device, accessory);
|
|
724
|
+
// create the accessory handler for the newly create accessory
|
|
725
|
+
// this is imported from `platformAccessory.ts`
|
|
726
|
+
new MeterPlus(this, accessory, device);
|
|
727
|
+
this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`);
|
|
728
|
+
|
|
729
|
+
// link the accessory to your platform
|
|
730
|
+
this.api.registerPlatformAccessories(PLUGIN_NAME, PLATFORM_NAME, [accessory]);
|
|
731
|
+
this.accessories.push(accessory);
|
|
732
|
+
} else {
|
|
733
|
+
this.debugLog(`Unable to Register new device: ${device.deviceName} ${device.deviceType} - ${device.deviceId}`);
|
|
734
|
+
}
|
|
735
|
+
}
|
|
736
|
+
|
|
674
737
|
private async createMotion(device: device & devicesConfig) {
|
|
675
738
|
const uuid = this.api.hap.uuid.generate(`${device.deviceId}-${device.deviceType}`);
|
|
676
739
|
|
|
@@ -871,7 +934,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
871
934
|
|
|
872
935
|
if (existingAccessory) {
|
|
873
936
|
// the accessory already exists
|
|
874
|
-
if (
|
|
937
|
+
if (this.registerDevice(device)) {
|
|
875
938
|
this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
|
|
876
939
|
|
|
877
940
|
// if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
|
|
@@ -889,7 +952,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
889
952
|
} else {
|
|
890
953
|
this.unregisterPlatformAccessories(existingAccessory);
|
|
891
954
|
}
|
|
892
|
-
} else if (
|
|
955
|
+
} else if (this.registerDevice(device)) {
|
|
893
956
|
// the accessory does not yet exist, so we need to create it
|
|
894
957
|
this.infoLog(`Adding new accessory: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
|
|
895
958
|
|
|
@@ -926,7 +989,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
926
989
|
|
|
927
990
|
if (existingAccessory) {
|
|
928
991
|
// the accessory already exists
|
|
929
|
-
if (
|
|
992
|
+
if (this.registerDevice(device)) {
|
|
930
993
|
this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
|
|
931
994
|
|
|
932
995
|
// if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
|
|
@@ -944,7 +1007,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
944
1007
|
} else {
|
|
945
1008
|
this.unregisterPlatformAccessories(existingAccessory);
|
|
946
1009
|
}
|
|
947
|
-
} else if (
|
|
1010
|
+
} else if (this.registerDevice(device)) {
|
|
948
1011
|
// the accessory does not yet exist, so we need to create it
|
|
949
1012
|
this.infoLog(`Adding new accessory: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
|
|
950
1013
|
|
|
@@ -981,7 +1044,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
981
1044
|
|
|
982
1045
|
if (existingAccessory) {
|
|
983
1046
|
// the accessory already exists
|
|
984
|
-
if (
|
|
1047
|
+
if (this.registerDevice(device)) {
|
|
985
1048
|
this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
|
|
986
1049
|
|
|
987
1050
|
// if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
|
|
@@ -999,7 +1062,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
999
1062
|
} else {
|
|
1000
1063
|
this.unregisterPlatformAccessories(existingAccessory);
|
|
1001
1064
|
}
|
|
1002
|
-
} else if (
|
|
1065
|
+
} else if (this.registerDevice(device)) {
|
|
1003
1066
|
// the accessory does not yet exist, so we need to create it
|
|
1004
1067
|
this.infoLog(`Adding new accessory: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
|
|
1005
1068
|
|
|
@@ -1027,6 +1090,61 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
1027
1090
|
}
|
|
1028
1091
|
}
|
|
1029
1092
|
|
|
1093
|
+
private async createStripLight(device: device & devicesConfig) {
|
|
1094
|
+
const uuid = this.api.hap.uuid.generate(`${device.deviceId}-${device.deviceType}`);
|
|
1095
|
+
|
|
1096
|
+
// see if an accessory with the same uuid has already been registered and restored from
|
|
1097
|
+
// the cached devices we stored in the `configureAccessory` method above
|
|
1098
|
+
const existingAccessory = this.accessories.find((accessory) => accessory.UUID === uuid);
|
|
1099
|
+
|
|
1100
|
+
if (existingAccessory) {
|
|
1101
|
+
// the accessory already exists
|
|
1102
|
+
if (this.registerDevice(device)) {
|
|
1103
|
+
this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
|
|
1104
|
+
|
|
1105
|
+
// if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
|
|
1106
|
+
existingAccessory.context.model = device.deviceType;
|
|
1107
|
+
existingAccessory.context.deviceID = device.deviceId;
|
|
1108
|
+
existingAccessory.displayName = device.deviceName;
|
|
1109
|
+
existingAccessory.context.firmwareRevision = this.version;
|
|
1110
|
+
existingAccessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
|
|
1111
|
+
await this.connectionTypeExistingAccessory(device, existingAccessory);
|
|
1112
|
+
this.api.updatePlatformAccessories([existingAccessory]);
|
|
1113
|
+
// create the accessory handler for the restored accessory
|
|
1114
|
+
// this is imported from `platformAccessory.ts`
|
|
1115
|
+
new StripLight(this, existingAccessory, device);
|
|
1116
|
+
this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${existingAccessory.UUID})`);
|
|
1117
|
+
} else {
|
|
1118
|
+
this.unregisterPlatformAccessories(existingAccessory);
|
|
1119
|
+
}
|
|
1120
|
+
} else if (this.registerDevice(device)) {
|
|
1121
|
+
// the accessory does not yet exist, so we need to create it
|
|
1122
|
+
this.infoLog(`Adding new accessory: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
|
|
1123
|
+
|
|
1124
|
+
// create a new accessory
|
|
1125
|
+
const accessory = new this.api.platformAccessory(device.deviceName, uuid);
|
|
1126
|
+
|
|
1127
|
+
// store a copy of the device object in the `accessory.context`
|
|
1128
|
+
// the `context` property can be used to store any data about the accessory you may need
|
|
1129
|
+
accessory.context.device = device;
|
|
1130
|
+
accessory.context.model = device.deviceType;
|
|
1131
|
+
accessory.context.deviceID = device.deviceId;
|
|
1132
|
+
accessory.context.firmwareRevision = this.version;
|
|
1133
|
+
accessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
|
|
1134
|
+
await this.connectionTypeNewAccessory(device, accessory);
|
|
1135
|
+
// create the accessory handler for the newly create accessory
|
|
1136
|
+
// this is imported from `platformAccessory.ts`
|
|
1137
|
+
new StripLight(this, accessory, device);
|
|
1138
|
+
this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`);
|
|
1139
|
+
|
|
1140
|
+
// link the accessory to your platform
|
|
1141
|
+
this.api.registerPlatformAccessories(PLUGIN_NAME, PLATFORM_NAME, [accessory]);
|
|
1142
|
+
this.accessories.push(accessory);
|
|
1143
|
+
} else {
|
|
1144
|
+
this.debugLog(`Unable to Register new device: ${device.deviceName} ${device.deviceType} - ${device.deviceId}`);
|
|
1145
|
+
}
|
|
1146
|
+
}
|
|
1147
|
+
|
|
1030
1148
|
private async createTV(device: irdevice & devicesConfig) {
|
|
1031
1149
|
const uuid = this.api.hap.uuid.generate(`${device.deviceId}-${device.remoteType}`);
|
|
1032
1150
|
|