@switchbot/homebridge-switchbot 3.6.1-beta.8 → 3.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 +2 -1
- package/dist/device/blindtilt.js +3 -3
- package/dist/device/blindtilt.js.map +1 -1
- package/dist/device/bot.js +12 -12
- package/dist/device/bot.js.map +1 -1
- package/dist/device/ceilinglight.js +1 -1
- package/dist/device/ceilinglight.js.map +1 -1
- package/dist/device/colorbulb.js +1 -1
- package/dist/device/colorbulb.js.map +1 -1
- package/dist/device/contact.js +4 -4
- package/dist/device/contact.js.map +1 -1
- package/dist/device/curtain.js +3 -3
- package/dist/device/curtain.js.map +1 -1
- package/dist/device/device.d.ts +1 -9
- package/dist/device/device.d.ts.map +1 -1
- package/dist/device/device.js +14 -38
- package/dist/device/device.js.map +1 -1
- package/dist/device/fan.js +3 -3
- package/dist/device/fan.js.map +1 -1
- package/dist/device/hub.js +3 -3
- package/dist/device/hub.js.map +1 -1
- package/dist/device/humidifier.js +2 -2
- package/dist/device/humidifier.js.map +1 -1
- package/dist/device/iosensor.js +3 -3
- package/dist/device/iosensor.js.map +1 -1
- package/dist/device/lightstrip.js +1 -1
- package/dist/device/lightstrip.js.map +1 -1
- package/dist/device/lock.js +4 -4
- package/dist/device/lock.js.map +1 -1
- package/dist/device/meter.js +3 -3
- package/dist/device/meter.js.map +1 -1
- package/dist/device/meterplus.js +3 -3
- package/dist/device/meterplus.js.map +1 -1
- package/dist/device/motion.d.ts.map +1 -1
- package/dist/device/motion.js +4 -5
- package/dist/device/motion.js.map +1 -1
- package/dist/device/plug.js +2 -2
- package/dist/device/plug.js.map +1 -1
- package/dist/device/robotvacuumcleaner.js +3 -3
- package/dist/device/robotvacuumcleaner.js.map +1 -1
- package/dist/device/waterdetector.js +2 -2
- package/dist/device/waterdetector.js.map +1 -1
- package/dist/irdevice/airconditioner.d.ts.map +1 -1
- package/dist/irdevice/airconditioner.js +4 -3
- package/dist/irdevice/airconditioner.js.map +1 -1
- package/dist/irdevice/airpurifier.js +2 -2
- package/dist/irdevice/airpurifier.js.map +1 -1
- package/dist/irdevice/camera.js +1 -1
- package/dist/irdevice/camera.js.map +1 -1
- package/dist/irdevice/fan.js +1 -1
- package/dist/irdevice/fan.js.map +1 -1
- package/dist/irdevice/irdevice.d.ts +1 -0
- package/dist/irdevice/irdevice.d.ts.map +1 -1
- package/dist/irdevice/irdevice.js +14 -11
- package/dist/irdevice/irdevice.js.map +1 -1
- package/dist/irdevice/light.js +3 -3
- package/dist/irdevice/light.js.map +1 -1
- package/dist/irdevice/other.d.ts +1 -1
- package/dist/irdevice/other.d.ts.map +1 -1
- package/dist/irdevice/other.js +26 -36
- package/dist/irdevice/other.js.map +1 -1
- package/dist/irdevice/tv.js +3 -3
- package/dist/irdevice/tv.js.map +1 -1
- package/dist/irdevice/vacuumcleaner.js +1 -1
- package/dist/irdevice/vacuumcleaner.js.map +1 -1
- package/dist/irdevice/waterheater.js +2 -2
- package/dist/irdevice/waterheater.js.map +1 -1
- package/dist/platform.d.ts +9 -0
- package/dist/platform.d.ts.map +1 -1
- package/dist/platform.js +319 -91
- package/dist/platform.js.map +1 -1
- package/dist/settings.d.ts +1 -1
- package/dist/settings.d.ts.map +1 -1
- package/docs/.nojekyll +1 -0
- package/docs/assets/highlight.css +22 -0
- package/docs/assets/icons.js +18 -0
- package/docs/assets/icons.svg +1 -0
- package/docs/assets/main.js +60 -0
- package/docs/assets/navigation.js +1 -0
- package/docs/assets/search.js +1 -0
- package/docs/assets/style.css +1448 -0
- package/docs/functions/default.html +1 -0
- package/docs/index.html +368 -0
- package/docs/modules.html +2 -0
- package/package.json +10 -7
- package/src/device/blindtilt.ts +3 -3
- package/src/device/bot.ts +12 -12
- package/src/device/ceilinglight.ts +1 -1
- package/src/device/colorbulb.ts +1 -1
- package/src/device/contact.ts +4 -4
- package/src/device/curtain.ts +3 -3
- package/src/device/device.ts +15 -44
- package/src/device/fan.ts +3 -3
- package/src/device/hub.ts +3 -3
- package/src/device/humidifier.ts +2 -2
- package/src/device/iosensor.ts +3 -3
- package/src/device/lightstrip.ts +1 -1
- package/src/device/lock.ts +4 -4
- package/src/device/meter.ts +4 -4
- package/src/device/meterplus.ts +4 -4
- package/src/device/motion.ts +6 -7
- package/src/device/plug.ts +2 -2
- package/src/device/robotvacuumcleaner.ts +3 -3
- package/src/device/waterdetector.ts +2 -2
- package/src/irdevice/airconditioner.ts +5 -4
- package/src/irdevice/airpurifier.ts +2 -2
- package/src/irdevice/camera.ts +1 -1
- package/src/irdevice/fan.ts +1 -1
- package/src/irdevice/irdevice.ts +15 -11
- package/src/irdevice/light.ts +3 -3
- package/src/irdevice/other.ts +26 -34
- package/src/irdevice/tv.ts +3 -3
- package/src/irdevice/vacuumcleaner.ts +1 -1
- package/src/irdevice/waterheater.ts +2 -2
- package/src/platform.ts +324 -90
- package/src/settings.ts +1 -1
- package/typedoc.json +17 -0
- package/.github/npm-version-script.cjs +0 -81
package/dist/platform.js
CHANGED
|
@@ -81,8 +81,8 @@ export class SwitchBotPlatform {
|
|
|
81
81
|
options: config.options,
|
|
82
82
|
};
|
|
83
83
|
// Plugin Configuration
|
|
84
|
-
this.getPlatformConfigSettings();
|
|
85
84
|
this.getPlatformLogSettings();
|
|
85
|
+
this.getPlatformConfigSettings();
|
|
86
86
|
this.getVersion();
|
|
87
87
|
// Finish initializing the platform
|
|
88
88
|
this.debugLog(`Finished initializing platform: ${config.name}`);
|
|
@@ -316,6 +316,15 @@ export class SwitchBotPlatform {
|
|
|
316
316
|
}
|
|
317
317
|
};
|
|
318
318
|
})();
|
|
319
|
+
this.api.on('shutdown', async () => {
|
|
320
|
+
try {
|
|
321
|
+
switchbot.stopScan();
|
|
322
|
+
this.infoLog('Stopped BLE scanning to close listening.');
|
|
323
|
+
}
|
|
324
|
+
catch (e) {
|
|
325
|
+
this.errorLog(`Failed to stop Platform BLE scanning. Error:${e.message}`);
|
|
326
|
+
}
|
|
327
|
+
});
|
|
319
328
|
}
|
|
320
329
|
}
|
|
321
330
|
else {
|
|
@@ -825,7 +834,9 @@ export class SwitchBotPlatform {
|
|
|
825
834
|
existingAccessory.context.deviceId = device.deviceId;
|
|
826
835
|
existingAccessory.context.deviceType = device.deviceType;
|
|
827
836
|
existingAccessory.context.model = SwitchBotModel.Humidifier;
|
|
828
|
-
existingAccessory.displayName = device.configDeviceName
|
|
837
|
+
existingAccessory.displayName = device.configDeviceName
|
|
838
|
+
? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
|
|
839
|
+
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName);
|
|
829
840
|
existingAccessory.context.connectionType = await this.connectionType(device);
|
|
830
841
|
existingAccessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
|
|
831
842
|
await this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`);
|
|
@@ -841,14 +852,18 @@ export class SwitchBotPlatform {
|
|
|
841
852
|
}
|
|
842
853
|
else if (await this.registerDevice(device)) {
|
|
843
854
|
// create a new accessory
|
|
844
|
-
const accessory = new this.api.platformAccessory(device.
|
|
855
|
+
const accessory = new this.api.platformAccessory(device.configDeviceName
|
|
856
|
+
? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
|
|
857
|
+
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName), uuid);
|
|
845
858
|
// store a copy of the device object in the `accessory.context`
|
|
846
859
|
// the `context` property can be used to store any data about the accessory you may need
|
|
847
860
|
accessory.context.device = device;
|
|
848
861
|
accessory.context.deviceId = device.deviceId;
|
|
849
862
|
accessory.context.deviceType = device.deviceType;
|
|
850
863
|
accessory.context.model = SwitchBotModel.Humidifier;
|
|
851
|
-
accessory.displayName = device.configDeviceName
|
|
864
|
+
accessory.displayName = device.configDeviceName
|
|
865
|
+
? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
|
|
866
|
+
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName);
|
|
852
867
|
accessory.context.connectionType = await this.connectionType(device);
|
|
853
868
|
accessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
|
|
854
869
|
const newOrExternal = !device.external ? 'Adding new' : 'Loading external';
|
|
@@ -878,7 +893,9 @@ export class SwitchBotPlatform {
|
|
|
878
893
|
existingAccessory.context.deviceId = device.deviceId;
|
|
879
894
|
existingAccessory.context.deviceType = device.deviceType;
|
|
880
895
|
existingAccessory.context.model = SwitchBotModel.Bot;
|
|
881
|
-
existingAccessory.displayName = device.configDeviceName
|
|
896
|
+
existingAccessory.displayName = device.configDeviceName
|
|
897
|
+
? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
|
|
898
|
+
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName);
|
|
882
899
|
existingAccessory.context.connectionType = await this.connectionType(device);
|
|
883
900
|
existingAccessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
|
|
884
901
|
this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`);
|
|
@@ -894,14 +911,19 @@ export class SwitchBotPlatform {
|
|
|
894
911
|
}
|
|
895
912
|
else if (await this.registerDevice(device)) {
|
|
896
913
|
// create a new accessory
|
|
897
|
-
const accessory = new this.api.platformAccessory(device.
|
|
914
|
+
const accessory = new this.api.platformAccessory(device.configDeviceName
|
|
915
|
+
? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
|
|
916
|
+
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName), uuid);
|
|
898
917
|
// store a copy of the device object in the `accessory.context`
|
|
899
918
|
// the `context` property can be used to store any data about the accessory you may need
|
|
900
919
|
accessory.context.device = device;
|
|
901
920
|
accessory.context.deviceId = device.deviceId;
|
|
902
921
|
accessory.context.deviceType = device.deviceType;
|
|
903
922
|
accessory.context.model = SwitchBotModel.Bot;
|
|
904
|
-
accessory.displayName = device.configDeviceName
|
|
923
|
+
accessory.displayName = device.configDeviceName
|
|
924
|
+
? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
|
|
925
|
+
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName);
|
|
926
|
+
accessory.context.connectionType = await this.connectionType(device);
|
|
905
927
|
accessory.context.connectionType = await this.connectionType(device);
|
|
906
928
|
accessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
|
|
907
929
|
const newOrExternal = !device.external ? 'Adding new' : 'Loading external';
|
|
@@ -932,7 +954,9 @@ export class SwitchBotPlatform {
|
|
|
932
954
|
existingAccessory.context.model = SwitchBotModel.Meter;
|
|
933
955
|
existingAccessory.context.deviceId = device.deviceId;
|
|
934
956
|
existingAccessory.context.deviceType = device.deviceType;
|
|
935
|
-
existingAccessory.displayName = device.configDeviceName
|
|
957
|
+
existingAccessory.displayName = device.configDeviceName
|
|
958
|
+
? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
|
|
959
|
+
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName);
|
|
936
960
|
existingAccessory.context.connectionType = await this.connectionType(device);
|
|
937
961
|
existingAccessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
|
|
938
962
|
this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`);
|
|
@@ -948,14 +972,19 @@ export class SwitchBotPlatform {
|
|
|
948
972
|
}
|
|
949
973
|
else if (await this.registerDevice(device)) {
|
|
950
974
|
// create a new accessory
|
|
951
|
-
const accessory = new this.api.platformAccessory(device.
|
|
975
|
+
const accessory = new this.api.platformAccessory(device.configDeviceName
|
|
976
|
+
? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
|
|
977
|
+
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName), uuid);
|
|
952
978
|
// store a copy of the device object in the `accessory.context`
|
|
953
979
|
// the `context` property can be used to store any data about the accessory you may need
|
|
954
980
|
accessory.context.device = device;
|
|
955
981
|
accessory.context.model = SwitchBotModel.Meter;
|
|
956
982
|
accessory.context.deviceId = device.deviceId;
|
|
957
983
|
accessory.context.deviceType = device.deviceType;
|
|
958
|
-
accessory.displayName = device.configDeviceName
|
|
984
|
+
accessory.displayName = device.configDeviceName
|
|
985
|
+
? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
|
|
986
|
+
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName);
|
|
987
|
+
accessory.context.connectionType = await this.connectionType(device);
|
|
959
988
|
accessory.context.connectionType = await this.connectionType(device);
|
|
960
989
|
accessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
|
|
961
990
|
const newOrExternal = !device.external ? 'Adding new' : 'Loading external';
|
|
@@ -986,7 +1015,9 @@ export class SwitchBotPlatform {
|
|
|
986
1015
|
existingAccessory.context.model = SwitchBotModel.MeterPlusUS ?? SwitchBotModel.MeterPlusJP;
|
|
987
1016
|
existingAccessory.context.deviceId = device.deviceId;
|
|
988
1017
|
existingAccessory.context.deviceType = device.deviceType;
|
|
989
|
-
existingAccessory.displayName = device.configDeviceName
|
|
1018
|
+
existingAccessory.displayName = device.configDeviceName
|
|
1019
|
+
? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
|
|
1020
|
+
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName);
|
|
990
1021
|
existingAccessory.context.connectionType = await this.connectionType(device);
|
|
991
1022
|
existingAccessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
|
|
992
1023
|
this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`);
|
|
@@ -1002,14 +1033,19 @@ export class SwitchBotPlatform {
|
|
|
1002
1033
|
}
|
|
1003
1034
|
else if (await this.registerDevice(device)) {
|
|
1004
1035
|
// create a new accessory
|
|
1005
|
-
const accessory = new this.api.platformAccessory(device.
|
|
1036
|
+
const accessory = new this.api.platformAccessory(device.configDeviceName
|
|
1037
|
+
? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
|
|
1038
|
+
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName), uuid);
|
|
1006
1039
|
// store a copy of the device object in the `accessory.context`
|
|
1007
1040
|
// the `context` property can be used to store any data about the accessory you may need
|
|
1008
1041
|
accessory.context.device = device;
|
|
1009
1042
|
accessory.context.model = SwitchBotModel.MeterPlusUS ?? SwitchBotModel.MeterPlusJP;
|
|
1010
1043
|
accessory.context.deviceId = device.deviceId;
|
|
1011
1044
|
accessory.context.deviceType = device.deviceType;
|
|
1012
|
-
accessory.displayName = device.configDeviceName
|
|
1045
|
+
accessory.displayName = device.configDeviceName
|
|
1046
|
+
? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
|
|
1047
|
+
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName);
|
|
1048
|
+
accessory.context.connectionType = await this.connectionType(device);
|
|
1013
1049
|
accessory.context.connectionType = await this.connectionType(device);
|
|
1014
1050
|
accessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
|
|
1015
1051
|
const newOrExternal = !device.external ? 'Adding new' : 'Loading external';
|
|
@@ -1040,7 +1076,9 @@ export class SwitchBotPlatform {
|
|
|
1040
1076
|
existingAccessory.context.model = SwitchBotModel.Hub2;
|
|
1041
1077
|
existingAccessory.context.deviceId = device.deviceId;
|
|
1042
1078
|
existingAccessory.context.deviceType = device.deviceType;
|
|
1043
|
-
existingAccessory.displayName = device.configDeviceName
|
|
1079
|
+
existingAccessory.displayName = device.configDeviceName
|
|
1080
|
+
? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
|
|
1081
|
+
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName);
|
|
1044
1082
|
existingAccessory.context.connectionType = await this.connectionType(device);
|
|
1045
1083
|
existingAccessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
|
|
1046
1084
|
this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`);
|
|
@@ -1056,14 +1094,19 @@ export class SwitchBotPlatform {
|
|
|
1056
1094
|
}
|
|
1057
1095
|
else if (await this.registerDevice(device)) {
|
|
1058
1096
|
// create a new accessory
|
|
1059
|
-
const accessory = new this.api.platformAccessory(device.
|
|
1097
|
+
const accessory = new this.api.platformAccessory(device.configDeviceName
|
|
1098
|
+
? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
|
|
1099
|
+
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName), uuid);
|
|
1060
1100
|
// store a copy of the device object in the `accessory.context`
|
|
1061
1101
|
// the `context` property can be used to store any data about the accessory you may need
|
|
1062
1102
|
accessory.context.device = device;
|
|
1063
1103
|
accessory.context.model = SwitchBotModel.Hub2;
|
|
1064
1104
|
accessory.context.deviceId = device.deviceId;
|
|
1065
1105
|
accessory.context.deviceType = device.deviceType;
|
|
1066
|
-
accessory.displayName = device.configDeviceName
|
|
1106
|
+
accessory.displayName = device.configDeviceName
|
|
1107
|
+
? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
|
|
1108
|
+
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName);
|
|
1109
|
+
accessory.context.connectionType = await this.connectionType(device);
|
|
1067
1110
|
accessory.context.connectionType = await this.connectionType(device);
|
|
1068
1111
|
accessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
|
|
1069
1112
|
const newOrExternal = !device.external ? 'Adding new' : 'Loading external';
|
|
@@ -1093,7 +1136,9 @@ export class SwitchBotPlatform {
|
|
|
1093
1136
|
existingAccessory.context.model = SwitchBotModel.OutdoorMeter;
|
|
1094
1137
|
existingAccessory.context.deviceId = device.deviceId;
|
|
1095
1138
|
existingAccessory.context.deviceType = device.deviceType;
|
|
1096
|
-
existingAccessory.displayName = device.configDeviceName
|
|
1139
|
+
existingAccessory.displayName = device.configDeviceName
|
|
1140
|
+
? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
|
|
1141
|
+
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName);
|
|
1097
1142
|
existingAccessory.context.connectionType = await this.connectionType(device);
|
|
1098
1143
|
existingAccessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
|
|
1099
1144
|
await this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`);
|
|
@@ -1109,14 +1154,19 @@ export class SwitchBotPlatform {
|
|
|
1109
1154
|
}
|
|
1110
1155
|
else if (await this.registerDevice(device)) {
|
|
1111
1156
|
// create a new accessory
|
|
1112
|
-
const accessory = new this.api.platformAccessory(device.
|
|
1157
|
+
const accessory = new this.api.platformAccessory(device.configDeviceName
|
|
1158
|
+
? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
|
|
1159
|
+
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName), uuid);
|
|
1113
1160
|
// store a copy of the device object in the `accessory.context`
|
|
1114
1161
|
// the `context` property can be used to store any data about the accessory you may need
|
|
1115
1162
|
accessory.context.device = device;
|
|
1116
1163
|
accessory.context.model = SwitchBotModel.OutdoorMeter;
|
|
1117
1164
|
accessory.context.deviceId = device.deviceId;
|
|
1118
1165
|
accessory.context.deviceType = device.deviceType;
|
|
1119
|
-
accessory.displayName = device.configDeviceName
|
|
1166
|
+
accessory.displayName = device.configDeviceName
|
|
1167
|
+
? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
|
|
1168
|
+
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName);
|
|
1169
|
+
accessory.context.connectionType = await this.connectionType(device);
|
|
1120
1170
|
accessory.context.connectionType = await this.connectionType(device);
|
|
1121
1171
|
accessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
|
|
1122
1172
|
const newOrExternal = !device.external ? 'Adding new' : 'Loading external';
|
|
@@ -1146,7 +1196,9 @@ export class SwitchBotPlatform {
|
|
|
1146
1196
|
existingAccessory.context.deviceId = device.deviceId;
|
|
1147
1197
|
existingAccessory.context.deviceType = device.deviceType;
|
|
1148
1198
|
existingAccessory.context.model = SwitchBotModel.WaterDetector;
|
|
1149
|
-
existingAccessory.displayName = device.configDeviceName
|
|
1199
|
+
existingAccessory.displayName = device.configDeviceName
|
|
1200
|
+
? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
|
|
1201
|
+
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName);
|
|
1150
1202
|
existingAccessory.context.connectionType = await this.connectionType(device);
|
|
1151
1203
|
existingAccessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
|
|
1152
1204
|
this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`);
|
|
@@ -1162,14 +1214,19 @@ export class SwitchBotPlatform {
|
|
|
1162
1214
|
}
|
|
1163
1215
|
else if (await this.registerDevice(device)) {
|
|
1164
1216
|
// create a new accessory
|
|
1165
|
-
const accessory = new this.api.platformAccessory(device.
|
|
1217
|
+
const accessory = new this.api.platformAccessory(device.configDeviceName
|
|
1218
|
+
? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
|
|
1219
|
+
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName), uuid);
|
|
1166
1220
|
// store a copy of the device object in the `accessory.context`
|
|
1167
1221
|
// the `context` property can be used to store any data about the accessory you may need
|
|
1168
1222
|
accessory.context.device = device;
|
|
1169
1223
|
accessory.context.deviceId = device.deviceId;
|
|
1170
1224
|
accessory.context.deviceType = device.deviceType;
|
|
1171
1225
|
accessory.context.model = SwitchBotModel.WaterDetector;
|
|
1172
|
-
accessory.displayName = device.configDeviceName
|
|
1226
|
+
accessory.displayName = device.configDeviceName
|
|
1227
|
+
? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
|
|
1228
|
+
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName);
|
|
1229
|
+
accessory.context.connectionType = await this.connectionType(device);
|
|
1173
1230
|
accessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
|
|
1174
1231
|
accessory.context.connectionType = await this.connectionType(device);
|
|
1175
1232
|
const newOrExternal = !device.external ? 'Adding new' : 'Loading external';
|
|
@@ -1199,7 +1256,9 @@ export class SwitchBotPlatform {
|
|
|
1199
1256
|
existingAccessory.context.deviceId = device.deviceId;
|
|
1200
1257
|
existingAccessory.context.deviceType = device.deviceType;
|
|
1201
1258
|
existingAccessory.context.model = SwitchBotModel.MotionSensor;
|
|
1202
|
-
existingAccessory.displayName = device.configDeviceName
|
|
1259
|
+
existingAccessory.displayName = device.configDeviceName
|
|
1260
|
+
? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
|
|
1261
|
+
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName);
|
|
1203
1262
|
existingAccessory.context.connectionType = await this.connectionType(device);
|
|
1204
1263
|
existingAccessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
|
|
1205
1264
|
this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`);
|
|
@@ -1215,14 +1274,19 @@ export class SwitchBotPlatform {
|
|
|
1215
1274
|
}
|
|
1216
1275
|
else if (await this.registerDevice(device)) {
|
|
1217
1276
|
// create a new accessory
|
|
1218
|
-
const accessory = new this.api.platformAccessory(device.
|
|
1277
|
+
const accessory = new this.api.platformAccessory(device.configDeviceName
|
|
1278
|
+
? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
|
|
1279
|
+
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName), uuid);
|
|
1219
1280
|
// store a copy of the device object in the `accessory.context`
|
|
1220
1281
|
// the `context` property can be used to store any data about the accessory you may need
|
|
1221
1282
|
accessory.context.device = device;
|
|
1222
1283
|
accessory.context.deviceId = device.deviceId;
|
|
1223
1284
|
accessory.context.deviceType = device.deviceType;
|
|
1224
1285
|
accessory.context.model = SwitchBotModel.MotionSensor;
|
|
1225
|
-
accessory.displayName = device.configDeviceName
|
|
1286
|
+
accessory.displayName = device.configDeviceName
|
|
1287
|
+
? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
|
|
1288
|
+
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName);
|
|
1289
|
+
accessory.context.connectionType = await this.connectionType(device);
|
|
1226
1290
|
accessory.context.connectionType = await this.connectionType(device);
|
|
1227
1291
|
accessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
|
|
1228
1292
|
const newOrExternal = !device.external ? 'Adding new' : 'Loading external';
|
|
@@ -1252,7 +1316,9 @@ export class SwitchBotPlatform {
|
|
|
1252
1316
|
existingAccessory.context.deviceId = device.deviceId;
|
|
1253
1317
|
existingAccessory.context.deviceType = device.deviceType;
|
|
1254
1318
|
existingAccessory.context.model = SwitchBotModel.ContactSensor;
|
|
1255
|
-
existingAccessory.displayName = device.configDeviceName
|
|
1319
|
+
existingAccessory.displayName = device.configDeviceName
|
|
1320
|
+
? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
|
|
1321
|
+
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName);
|
|
1256
1322
|
existingAccessory.context.connectionType = await this.connectionType(device);
|
|
1257
1323
|
existingAccessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
|
|
1258
1324
|
this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`);
|
|
@@ -1268,14 +1334,19 @@ export class SwitchBotPlatform {
|
|
|
1268
1334
|
}
|
|
1269
1335
|
else if (await this.registerDevice(device)) {
|
|
1270
1336
|
// create a new accessory
|
|
1271
|
-
const accessory = new this.api.platformAccessory(device.
|
|
1337
|
+
const accessory = new this.api.platformAccessory(device.configDeviceName
|
|
1338
|
+
? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
|
|
1339
|
+
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName), uuid);
|
|
1272
1340
|
// store a copy of the device object in the `accessory.context`
|
|
1273
1341
|
// the `context` property can be used to store any data about the accessory you may need
|
|
1274
1342
|
accessory.context.device = device;
|
|
1275
1343
|
accessory.context.deviceId = device.deviceId;
|
|
1276
1344
|
accessory.context.deviceType = device.deviceType;
|
|
1277
1345
|
accessory.context.model = SwitchBotModel.ContactSensor;
|
|
1278
|
-
accessory.displayName = device.configDeviceName
|
|
1346
|
+
accessory.displayName = device.configDeviceName
|
|
1347
|
+
? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
|
|
1348
|
+
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName);
|
|
1349
|
+
accessory.context.connectionType = await this.connectionType(device);
|
|
1279
1350
|
accessory.context.connectionType = await this.connectionType(device);
|
|
1280
1351
|
accessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
|
|
1281
1352
|
const newOrExternal = !device.external ? 'Adding new' : 'Loading external';
|
|
@@ -1305,7 +1376,9 @@ export class SwitchBotPlatform {
|
|
|
1305
1376
|
existingAccessory.context.deviceId = device.deviceId;
|
|
1306
1377
|
existingAccessory.context.deviceType = device.deviceType;
|
|
1307
1378
|
existingAccessory.context.model = SwitchBotModel.BlindTilt;
|
|
1308
|
-
existingAccessory.displayName = device.configDeviceName
|
|
1379
|
+
existingAccessory.displayName = device.configDeviceName
|
|
1380
|
+
? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
|
|
1381
|
+
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName);
|
|
1309
1382
|
existingAccessory.context.connectionType = await this.connectionType(device);
|
|
1310
1383
|
existingAccessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
|
|
1311
1384
|
this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`);
|
|
@@ -1335,7 +1408,9 @@ export class SwitchBotPlatform {
|
|
|
1335
1408
|
}
|
|
1336
1409
|
}
|
|
1337
1410
|
// create a new accessory
|
|
1338
|
-
const accessory = new this.api.platformAccessory(device.
|
|
1411
|
+
const accessory = new this.api.platformAccessory(device.configDeviceName
|
|
1412
|
+
? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
|
|
1413
|
+
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName), uuid);
|
|
1339
1414
|
// store a copy of the device object in the `accessory.context`
|
|
1340
1415
|
// the `context` property can be used to store any data about the accessory you may need
|
|
1341
1416
|
accessory.context.device = device;
|
|
@@ -1343,7 +1418,10 @@ export class SwitchBotPlatform {
|
|
|
1343
1418
|
accessory.context.deviceId = device.deviceId;
|
|
1344
1419
|
accessory.context.deviceType = device.deviceType;
|
|
1345
1420
|
accessory.context.model = SwitchBotModel.BlindTilt;
|
|
1346
|
-
accessory.displayName = device.configDeviceName
|
|
1421
|
+
accessory.displayName = device.configDeviceName
|
|
1422
|
+
? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
|
|
1423
|
+
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName);
|
|
1424
|
+
accessory.context.connectionType = await this.connectionType(device);
|
|
1347
1425
|
accessory.context.connectionType = await this.connectionType(device);
|
|
1348
1426
|
accessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
|
|
1349
1427
|
const newOrExternal = !device.external ? 'Adding new' : 'Loading external';
|
|
@@ -1373,7 +1451,9 @@ export class SwitchBotPlatform {
|
|
|
1373
1451
|
existingAccessory.context.deviceId = device.deviceId;
|
|
1374
1452
|
existingAccessory.context.deviceType = device.deviceType;
|
|
1375
1453
|
existingAccessory.context.model = device.deviceType === 'Curtain3' ? SwitchBotModel.Curtain3 : SwitchBotModel.Curtain;
|
|
1376
|
-
existingAccessory.displayName = device.configDeviceName
|
|
1454
|
+
existingAccessory.displayName = device.configDeviceName
|
|
1455
|
+
? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
|
|
1456
|
+
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName);
|
|
1377
1457
|
existingAccessory.context.connectionType = await this.connectionType(device);
|
|
1378
1458
|
existingAccessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
|
|
1379
1459
|
await this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`);
|
|
@@ -1403,14 +1483,19 @@ export class SwitchBotPlatform {
|
|
|
1403
1483
|
}
|
|
1404
1484
|
}
|
|
1405
1485
|
// create a new accessory
|
|
1406
|
-
const accessory = new this.api.platformAccessory(device.
|
|
1486
|
+
const accessory = new this.api.platformAccessory(device.configDeviceName
|
|
1487
|
+
? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
|
|
1488
|
+
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName), uuid);
|
|
1407
1489
|
// store a copy of the device object in the `accessory.context`
|
|
1408
1490
|
// the `context` property can be used to store any data about the accessory you may need
|
|
1409
1491
|
accessory.context.device = device;
|
|
1410
1492
|
accessory.context.deviceId = device.deviceId;
|
|
1411
1493
|
accessory.context.deviceType = device.deviceType;
|
|
1412
1494
|
accessory.context.model = device.deviceType === 'Curtain3' ? SwitchBotModel.Curtain3 : SwitchBotModel.Curtain;
|
|
1413
|
-
accessory.displayName = device.configDeviceName
|
|
1495
|
+
accessory.displayName = device.configDeviceName
|
|
1496
|
+
? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
|
|
1497
|
+
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName);
|
|
1498
|
+
accessory.context.connectionType = await this.connectionType(device);
|
|
1414
1499
|
accessory.context.connectionType = await this.connectionType(device);
|
|
1415
1500
|
accessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
|
|
1416
1501
|
const newOrExternal = !device.external ? 'Adding new' : 'Loading external';
|
|
@@ -1441,7 +1526,9 @@ export class SwitchBotPlatform {
|
|
|
1441
1526
|
existingAccessory.context.deviceType = device.deviceType;
|
|
1442
1527
|
existingAccessory.context.model = device.deviceType === 'Plug Mini (US)' ? SwitchBotModel.PlugMiniUS : device.deviceType === 'Plug Mini (JP)'
|
|
1443
1528
|
? SwitchBotModel.PlugMiniJP : SwitchBotModel.Plug;
|
|
1444
|
-
existingAccessory.displayName = device.configDeviceName
|
|
1529
|
+
existingAccessory.displayName = device.configDeviceName
|
|
1530
|
+
? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
|
|
1531
|
+
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName);
|
|
1445
1532
|
existingAccessory.context.connectionType = await this.connectionType(device);
|
|
1446
1533
|
existingAccessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
|
|
1447
1534
|
await this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`);
|
|
@@ -1457,7 +1544,9 @@ export class SwitchBotPlatform {
|
|
|
1457
1544
|
}
|
|
1458
1545
|
else if (await this.registerDevice(device)) {
|
|
1459
1546
|
// create a new accessory
|
|
1460
|
-
const accessory = new this.api.platformAccessory(device.
|
|
1547
|
+
const accessory = new this.api.platformAccessory(device.configDeviceName
|
|
1548
|
+
? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
|
|
1549
|
+
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName), uuid);
|
|
1461
1550
|
// store a copy of the device object in the `accessory.context`
|
|
1462
1551
|
// the `context` property can be used to store any data about the accessory you may need
|
|
1463
1552
|
accessory.context.device = device;
|
|
@@ -1465,7 +1554,10 @@ export class SwitchBotPlatform {
|
|
|
1465
1554
|
accessory.context.deviceType = device.deviceType;
|
|
1466
1555
|
accessory.context.model = device.deviceType === 'Plug Mini (US)' ? SwitchBotModel.PlugMiniUS : device.deviceType === 'Plug Mini (JP)'
|
|
1467
1556
|
? SwitchBotModel.PlugMiniJP : SwitchBotModel.Plug;
|
|
1468
|
-
accessory.displayName = device.configDeviceName
|
|
1557
|
+
accessory.displayName = device.configDeviceName
|
|
1558
|
+
? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
|
|
1559
|
+
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName);
|
|
1560
|
+
accessory.context.connectionType = await this.connectionType(device);
|
|
1469
1561
|
accessory.context.connectionType = await this.connectionType(device);
|
|
1470
1562
|
accessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
|
|
1471
1563
|
const newOrExternal = !device.external ? 'Adding new' : 'Loading external';
|
|
@@ -1495,7 +1587,9 @@ export class SwitchBotPlatform {
|
|
|
1495
1587
|
existingAccessory.context.deviceId = device.deviceId;
|
|
1496
1588
|
existingAccessory.context.deviceType = device.deviceType;
|
|
1497
1589
|
existingAccessory.context.model = device.deviceType === 'Smart Lock Pro' ? SwitchBotModel.LockPro : SwitchBotModel.Lock;
|
|
1498
|
-
existingAccessory.displayName = device.configDeviceName
|
|
1590
|
+
existingAccessory.displayName = device.configDeviceName
|
|
1591
|
+
? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
|
|
1592
|
+
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName);
|
|
1499
1593
|
existingAccessory.context.connectionType = await this.connectionType(device);
|
|
1500
1594
|
existingAccessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
|
|
1501
1595
|
this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`);
|
|
@@ -1511,14 +1605,19 @@ export class SwitchBotPlatform {
|
|
|
1511
1605
|
}
|
|
1512
1606
|
else if (await this.registerDevice(device)) {
|
|
1513
1607
|
// create a new accessory
|
|
1514
|
-
const accessory = new this.api.platformAccessory(device.
|
|
1608
|
+
const accessory = new this.api.platformAccessory(device.configDeviceName
|
|
1609
|
+
? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
|
|
1610
|
+
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName), uuid);
|
|
1515
1611
|
// store a copy of the device object in the `accessory.context`
|
|
1516
1612
|
// the `context` property can be used to store any data about the accessory you may need
|
|
1517
1613
|
accessory.context.device = device;
|
|
1518
1614
|
accessory.context.deviceId = device.deviceId;
|
|
1519
1615
|
accessory.context.deviceType = device.deviceType;
|
|
1520
1616
|
accessory.context.model = device.deviceType === 'Smart Lock Pro' ? SwitchBotModel.LockPro : SwitchBotModel.Lock;
|
|
1521
|
-
accessory.displayName = device.configDeviceName
|
|
1617
|
+
accessory.displayName = device.configDeviceName
|
|
1618
|
+
? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
|
|
1619
|
+
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName);
|
|
1620
|
+
accessory.context.connectionType = await this.connectionType(device);
|
|
1522
1621
|
accessory.context.connectionType = await this.connectionType(device);
|
|
1523
1622
|
accessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
|
|
1524
1623
|
const newOrExternal = !device.external ? 'Adding new' : 'Loading external';
|
|
@@ -1548,7 +1647,9 @@ export class SwitchBotPlatform {
|
|
|
1548
1647
|
existingAccessory.context.deviceId = device.deviceId;
|
|
1549
1648
|
existingAccessory.context.deviceType = device.deviceType;
|
|
1550
1649
|
existingAccessory.context.model = SwitchBotModel.ColorBulb;
|
|
1551
|
-
existingAccessory.displayName = device.configDeviceName
|
|
1650
|
+
existingAccessory.displayName = device.configDeviceName
|
|
1651
|
+
? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
|
|
1652
|
+
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName);
|
|
1552
1653
|
existingAccessory.context.connectionType = await this.connectionType(device);
|
|
1553
1654
|
existingAccessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
|
|
1554
1655
|
await this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`);
|
|
@@ -1564,14 +1665,19 @@ export class SwitchBotPlatform {
|
|
|
1564
1665
|
}
|
|
1565
1666
|
else if (await this.registerDevice(device)) {
|
|
1566
1667
|
// create a new accessory
|
|
1567
|
-
const accessory = new this.api.platformAccessory(device.
|
|
1668
|
+
const accessory = new this.api.platformAccessory(device.configDeviceName
|
|
1669
|
+
? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
|
|
1670
|
+
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName), uuid);
|
|
1568
1671
|
// store a copy of the device object in the `accessory.context`
|
|
1569
1672
|
// the `context` property can be used to store any data about the accessory you may need
|
|
1570
1673
|
accessory.context.device = device;
|
|
1571
1674
|
accessory.context.deviceId = device.deviceId;
|
|
1572
1675
|
accessory.context.deviceType = device.deviceType;
|
|
1573
1676
|
accessory.context.model = SwitchBotModel.ColorBulb;
|
|
1574
|
-
accessory.displayName = device.configDeviceName
|
|
1677
|
+
accessory.displayName = device.configDeviceName
|
|
1678
|
+
? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
|
|
1679
|
+
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName);
|
|
1680
|
+
accessory.context.connectionType = await this.connectionType(device);
|
|
1575
1681
|
accessory.context.connectionType = await this.connectionType(device);
|
|
1576
1682
|
accessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
|
|
1577
1683
|
const newOrExternal = !device.external ? 'Adding new' : 'Loading external';
|
|
@@ -1601,7 +1707,9 @@ export class SwitchBotPlatform {
|
|
|
1601
1707
|
existingAccessory.context.deviceId = device.deviceId;
|
|
1602
1708
|
existingAccessory.context.deviceType = device.deviceType;
|
|
1603
1709
|
existingAccessory.context.model = device.deviceType === 'Ceiling Light Pro' ? SwitchBotModel.CeilingLightPro : SwitchBotModel.CeilingLight;
|
|
1604
|
-
existingAccessory.displayName = device.configDeviceName
|
|
1710
|
+
existingAccessory.displayName = device.configDeviceName
|
|
1711
|
+
? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
|
|
1712
|
+
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName);
|
|
1605
1713
|
existingAccessory.context.connectionType = await this.connectionType(device);
|
|
1606
1714
|
existingAccessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
|
|
1607
1715
|
await this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`);
|
|
@@ -1617,14 +1725,19 @@ export class SwitchBotPlatform {
|
|
|
1617
1725
|
}
|
|
1618
1726
|
else if (await this.registerDevice(device)) {
|
|
1619
1727
|
// create a new accessory
|
|
1620
|
-
const accessory = new this.api.platformAccessory(device.
|
|
1728
|
+
const accessory = new this.api.platformAccessory(device.configDeviceName
|
|
1729
|
+
? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
|
|
1730
|
+
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName), uuid);
|
|
1621
1731
|
// store a copy of the device object in the `accessory.context`
|
|
1622
1732
|
// the `context` property can be used to store any data about the accessory you may need
|
|
1623
1733
|
accessory.context.device = device;
|
|
1624
1734
|
accessory.context.deviceId = device.deviceId;
|
|
1625
1735
|
accessory.context.deviceType = device.deviceType;
|
|
1626
1736
|
accessory.context.model = device.deviceType === 'Ceiling Light Pro' ? SwitchBotModel.CeilingLightPro : SwitchBotModel.CeilingLight;
|
|
1627
|
-
accessory.displayName = device.configDeviceName
|
|
1737
|
+
accessory.displayName = device.configDeviceName
|
|
1738
|
+
? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
|
|
1739
|
+
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName);
|
|
1740
|
+
accessory.context.connectionType = await this.connectionType(device);
|
|
1628
1741
|
accessory.context.connectionType = await this.connectionType(device);
|
|
1629
1742
|
accessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
|
|
1630
1743
|
const newOrExternal = !device.external ? 'Adding new' : 'Loading external';
|
|
@@ -1654,7 +1767,9 @@ export class SwitchBotPlatform {
|
|
|
1654
1767
|
existingAccessory.context.deviceId = device.deviceId;
|
|
1655
1768
|
existingAccessory.context.deviceType = device.deviceType;
|
|
1656
1769
|
existingAccessory.context.model = SwitchBotModel.StripLight;
|
|
1657
|
-
existingAccessory.displayName = device.configDeviceName
|
|
1770
|
+
existingAccessory.displayName = device.configDeviceName
|
|
1771
|
+
? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
|
|
1772
|
+
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName);
|
|
1658
1773
|
existingAccessory.context.connectionType = await this.connectionType(device);
|
|
1659
1774
|
existingAccessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
|
|
1660
1775
|
await this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`);
|
|
@@ -1670,14 +1785,19 @@ export class SwitchBotPlatform {
|
|
|
1670
1785
|
}
|
|
1671
1786
|
else if (await this.registerDevice(device)) {
|
|
1672
1787
|
// create a new accessory
|
|
1673
|
-
const accessory = new this.api.platformAccessory(device.
|
|
1788
|
+
const accessory = new this.api.platformAccessory(device.configDeviceName
|
|
1789
|
+
? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
|
|
1790
|
+
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName), uuid);
|
|
1674
1791
|
// store a copy of the device object in the `accessory.context`
|
|
1675
1792
|
// the `context` property can be used to store any data about the accessory you may need
|
|
1676
1793
|
accessory.context.device = device;
|
|
1677
1794
|
accessory.context.deviceId = device.deviceId;
|
|
1678
1795
|
accessory.context.deviceType = device.deviceType;
|
|
1679
1796
|
accessory.context.model = SwitchBotModel.StripLight;
|
|
1680
|
-
accessory.displayName = device.configDeviceName
|
|
1797
|
+
accessory.displayName = device.configDeviceName
|
|
1798
|
+
? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
|
|
1799
|
+
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName);
|
|
1800
|
+
accessory.context.connectionType = await this.connectionType(device);
|
|
1681
1801
|
accessory.context.connectionType = await this.connectionType(device);
|
|
1682
1802
|
accessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
|
|
1683
1803
|
const newOrExternal = !device.external ? 'Adding new' : 'Loading external';
|
|
@@ -1707,7 +1827,9 @@ export class SwitchBotPlatform {
|
|
|
1707
1827
|
existingAccessory.context.deviceId = device.deviceId;
|
|
1708
1828
|
existingAccessory.context.deviceType = device.deviceType;
|
|
1709
1829
|
existingAccessory.context.model = SwitchBotModel.BatteryCirculatorFan;
|
|
1710
|
-
existingAccessory.displayName = device.configDeviceName
|
|
1830
|
+
existingAccessory.displayName = device.configDeviceName
|
|
1831
|
+
? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
|
|
1832
|
+
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName);
|
|
1711
1833
|
existingAccessory.context.connectionType = await this.connectionType(device);
|
|
1712
1834
|
existingAccessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
|
|
1713
1835
|
await this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`);
|
|
@@ -1723,14 +1845,19 @@ export class SwitchBotPlatform {
|
|
|
1723
1845
|
}
|
|
1724
1846
|
else if (await this.registerDevice(device)) {
|
|
1725
1847
|
// create a new accessory
|
|
1726
|
-
const accessory = new this.api.platformAccessory(device.
|
|
1848
|
+
const accessory = new this.api.platformAccessory(device.configDeviceName
|
|
1849
|
+
? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
|
|
1850
|
+
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName), uuid);
|
|
1727
1851
|
// store a copy of the device object in the `accessory.context`
|
|
1728
1852
|
// the `context` property can be used to store any data about the accessory you may need
|
|
1729
1853
|
accessory.context.device = device;
|
|
1730
1854
|
accessory.context.deviceId = device.deviceId;
|
|
1731
1855
|
accessory.context.deviceType = device.deviceType;
|
|
1732
1856
|
accessory.context.model = SwitchBotModel.BatteryCirculatorFan;
|
|
1733
|
-
accessory.displayName = device.configDeviceName
|
|
1857
|
+
accessory.displayName = device.configDeviceName
|
|
1858
|
+
? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
|
|
1859
|
+
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName);
|
|
1860
|
+
accessory.context.connectionType = await this.connectionType(device);
|
|
1734
1861
|
accessory.context.connectionType = await this.connectionType(device);
|
|
1735
1862
|
accessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
|
|
1736
1863
|
const newOrExternal = !device.external ? 'Adding new' : 'Loading external';
|
|
@@ -1764,7 +1891,9 @@ export class SwitchBotPlatform {
|
|
|
1764
1891
|
: device.deviceType === 'Robot Vacuum Cleaner S10' ? SwitchBotModel.RobotVacuumCleanerS10
|
|
1765
1892
|
: device.deviceType === 'WoSweeper' ? SwitchBotModel.WoSweeper : device.deviceType === 'WoSweeperMini' ? SwitchBotModel.WoSweeperMini
|
|
1766
1893
|
: SwitchBotModel.Unknown;
|
|
1767
|
-
existingAccessory.displayName = device.configDeviceName
|
|
1894
|
+
existingAccessory.displayName = device.configDeviceName
|
|
1895
|
+
? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
|
|
1896
|
+
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName);
|
|
1768
1897
|
existingAccessory.context.connectionType = await this.connectionType(device);
|
|
1769
1898
|
existingAccessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
|
|
1770
1899
|
await this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`);
|
|
@@ -1780,7 +1909,9 @@ export class SwitchBotPlatform {
|
|
|
1780
1909
|
}
|
|
1781
1910
|
else if (await this.registerDevice(device)) {
|
|
1782
1911
|
// create a new accessory
|
|
1783
|
-
const accessory = new this.api.platformAccessory(device.
|
|
1912
|
+
const accessory = new this.api.platformAccessory(device.configDeviceName
|
|
1913
|
+
? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
|
|
1914
|
+
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName), uuid);
|
|
1784
1915
|
// store a copy of the device object in the `accessory.context`
|
|
1785
1916
|
// the `context` property can be used to store any data about the accessory you may need
|
|
1786
1917
|
accessory.context.device = device;
|
|
@@ -1791,7 +1922,10 @@ export class SwitchBotPlatform {
|
|
|
1791
1922
|
: device.deviceType === 'Robot Vacuum Cleaner S10' ? SwitchBotModel.RobotVacuumCleanerS10
|
|
1792
1923
|
: device.deviceType === 'WoSweeper' ? SwitchBotModel.WoSweeper : device.deviceType === 'WoSweeperMini' ? SwitchBotModel.WoSweeperMini
|
|
1793
1924
|
: SwitchBotModel.Unknown;
|
|
1794
|
-
accessory.displayName = device.configDeviceName
|
|
1925
|
+
accessory.displayName = device.configDeviceName
|
|
1926
|
+
? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
|
|
1927
|
+
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName);
|
|
1928
|
+
accessory.context.connectionType = await this.connectionType(device);
|
|
1795
1929
|
accessory.context.connectionType = await this.connectionType(device);
|
|
1796
1930
|
accessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
|
|
1797
1931
|
const newOrExternal = !device.external ? 'Adding new' : 'Loading external';
|
|
@@ -1819,7 +1953,9 @@ export class SwitchBotPlatform {
|
|
|
1819
1953
|
existingAccessory.context.deviceId = device.deviceId;
|
|
1820
1954
|
existingAccessory.context.deviceType = `IR: ${device.remoteType}`;
|
|
1821
1955
|
existingAccessory.context.model = device.remoteType;
|
|
1822
|
-
existingAccessory.displayName = device.configDeviceName
|
|
1956
|
+
existingAccessory.displayName = device.configDeviceName
|
|
1957
|
+
? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
|
|
1958
|
+
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName);
|
|
1823
1959
|
await this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`);
|
|
1824
1960
|
existingAccessory.context.connectionType = device.connectionType;
|
|
1825
1961
|
this.api.updatePlatformAccessories([existingAccessory]);
|
|
@@ -1830,14 +1966,19 @@ export class SwitchBotPlatform {
|
|
|
1830
1966
|
}
|
|
1831
1967
|
else if (!device.hide_device && device.hubDeviceId) {
|
|
1832
1968
|
// create a new accessory
|
|
1833
|
-
const accessory = new this.api.platformAccessory(device.
|
|
1969
|
+
const accessory = new this.api.platformAccessory(device.configDeviceName
|
|
1970
|
+
? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
|
|
1971
|
+
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName), uuid);
|
|
1834
1972
|
// store a copy of the device object in the `accessory.context`
|
|
1835
1973
|
// the `context` property can be used to store any data about the accessory you may need
|
|
1836
1974
|
accessory.context.device = device;
|
|
1837
1975
|
accessory.context.deviceId = device.deviceId;
|
|
1838
1976
|
accessory.context.deviceType = `IR: ${device.remoteType}`;
|
|
1839
1977
|
accessory.context.model = device.remoteType;
|
|
1840
|
-
accessory.displayName = device.configDeviceName
|
|
1978
|
+
accessory.displayName = device.configDeviceName
|
|
1979
|
+
? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
|
|
1980
|
+
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName);
|
|
1981
|
+
accessory.context.connectionType = await this.connectionType(device);
|
|
1841
1982
|
accessory.context.connectionType = device.connectionType;
|
|
1842
1983
|
accessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
|
|
1843
1984
|
const newOrExternal = !device.external ? 'Adding new' : 'Loading external';
|
|
@@ -1866,7 +2007,9 @@ export class SwitchBotPlatform {
|
|
|
1866
2007
|
existingAccessory.context.deviceId = device.deviceId;
|
|
1867
2008
|
existingAccessory.context.deviceType = `IR: ${device.remoteType}`;
|
|
1868
2009
|
existingAccessory.context.model = device.remoteType;
|
|
1869
|
-
existingAccessory.displayName = device.configDeviceName
|
|
2010
|
+
existingAccessory.displayName = device.configDeviceName
|
|
2011
|
+
? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
|
|
2012
|
+
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName);
|
|
1870
2013
|
await this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`);
|
|
1871
2014
|
existingAccessory.context.connectionType = device.connectionType;
|
|
1872
2015
|
this.api.updatePlatformAccessories([existingAccessory]);
|
|
@@ -1881,14 +2024,19 @@ export class SwitchBotPlatform {
|
|
|
1881
2024
|
}
|
|
1882
2025
|
else if (!device.hide_device && device.hubDeviceId) {
|
|
1883
2026
|
// create a new accessory
|
|
1884
|
-
const accessory = new this.api.platformAccessory(device.
|
|
2027
|
+
const accessory = new this.api.platformAccessory(device.configDeviceName
|
|
2028
|
+
? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
|
|
2029
|
+
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName), uuid);
|
|
1885
2030
|
// store a copy of the device object in the `accessory.context`
|
|
1886
2031
|
// the `context` property can be used to store any data about the accessory you may need
|
|
1887
2032
|
accessory.context.device = device;
|
|
1888
2033
|
accessory.context.deviceId = device.deviceId;
|
|
1889
2034
|
accessory.context.deviceType = `IR: ${device.remoteType}`;
|
|
1890
2035
|
accessory.context.model = device.remoteType;
|
|
1891
|
-
accessory.displayName = device.configDeviceName
|
|
2036
|
+
accessory.displayName = device.configDeviceName
|
|
2037
|
+
? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
|
|
2038
|
+
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName);
|
|
2039
|
+
accessory.context.connectionType = await this.connectionType(device);
|
|
1892
2040
|
accessory.context.connectionType = device.connectionType;
|
|
1893
2041
|
accessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
|
|
1894
2042
|
const newOrExternal = !device.external ? 'Adding new' : 'Loading external';
|
|
@@ -1918,7 +2066,9 @@ export class SwitchBotPlatform {
|
|
|
1918
2066
|
existingAccessory.context.deviceId = device.deviceId;
|
|
1919
2067
|
existingAccessory.context.deviceType = `IR: ${device.remoteType}`;
|
|
1920
2068
|
existingAccessory.context.model = device.remoteType;
|
|
1921
|
-
existingAccessory.displayName = device.configDeviceName
|
|
2069
|
+
existingAccessory.displayName = device.configDeviceName
|
|
2070
|
+
? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
|
|
2071
|
+
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName);
|
|
1922
2072
|
await this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`);
|
|
1923
2073
|
existingAccessory.context.connectionType = device.connectionType;
|
|
1924
2074
|
this.api.updatePlatformAccessories([existingAccessory]);
|
|
@@ -1933,14 +2083,19 @@ export class SwitchBotPlatform {
|
|
|
1933
2083
|
}
|
|
1934
2084
|
else if (!device.hide_device && device.hubDeviceId) {
|
|
1935
2085
|
// create a new accessory
|
|
1936
|
-
const accessory = new this.api.platformAccessory(device.
|
|
2086
|
+
const accessory = new this.api.platformAccessory(device.configDeviceName
|
|
2087
|
+
? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
|
|
2088
|
+
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName), uuid);
|
|
1937
2089
|
// store a copy of the device object in the `accessory.context`
|
|
1938
2090
|
// the `context` property can be used to store any data about the accessory you may need
|
|
1939
2091
|
accessory.context.device = device;
|
|
1940
2092
|
accessory.context.deviceId = device.deviceId;
|
|
1941
2093
|
accessory.context.deviceType = `IR: ${device.remoteType}`;
|
|
1942
2094
|
accessory.context.model = device.remoteType;
|
|
1943
|
-
accessory.displayName = device.configDeviceName
|
|
2095
|
+
accessory.displayName = device.configDeviceName
|
|
2096
|
+
? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
|
|
2097
|
+
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName);
|
|
2098
|
+
accessory.context.connectionType = await this.connectionType(device);
|
|
1944
2099
|
accessory.context.connectionType = device.connectionType;
|
|
1945
2100
|
accessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
|
|
1946
2101
|
const newOrExternal = !device.external ? 'Adding new' : 'Loading external';
|
|
@@ -1970,7 +2125,9 @@ export class SwitchBotPlatform {
|
|
|
1970
2125
|
existingAccessory.context.deviceId = device.deviceId;
|
|
1971
2126
|
existingAccessory.context.deviceType = `IR: ${device.remoteType}`;
|
|
1972
2127
|
existingAccessory.context.model = device.remoteType;
|
|
1973
|
-
existingAccessory.displayName = device.configDeviceName
|
|
2128
|
+
existingAccessory.displayName = device.configDeviceName
|
|
2129
|
+
? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
|
|
2130
|
+
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName);
|
|
1974
2131
|
await this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`);
|
|
1975
2132
|
existingAccessory.context.connectionType = device.connectionType;
|
|
1976
2133
|
this.api.updatePlatformAccessories([existingAccessory]);
|
|
@@ -1985,14 +2142,19 @@ export class SwitchBotPlatform {
|
|
|
1985
2142
|
}
|
|
1986
2143
|
else if (!device.hide_device && device.hubDeviceId) {
|
|
1987
2144
|
// create a new accessory
|
|
1988
|
-
const accessory = new this.api.platformAccessory(device.
|
|
2145
|
+
const accessory = new this.api.platformAccessory(device.configDeviceName
|
|
2146
|
+
? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
|
|
2147
|
+
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName), uuid);
|
|
1989
2148
|
// store a copy of the device object in the `accessory.context`
|
|
1990
2149
|
// the `context` property can be used to store any data about the accessory you may need
|
|
1991
2150
|
accessory.context.device = device;
|
|
1992
2151
|
accessory.context.deviceId = device.deviceId;
|
|
1993
2152
|
accessory.context.deviceType = `IR: ${device.remoteType}`;
|
|
1994
2153
|
accessory.context.model = device.remoteType;
|
|
1995
|
-
accessory.displayName = device.configDeviceName
|
|
2154
|
+
accessory.displayName = device.configDeviceName
|
|
2155
|
+
? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
|
|
2156
|
+
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName);
|
|
2157
|
+
accessory.context.connectionType = await this.connectionType(device);
|
|
1996
2158
|
accessory.context.connectionType = device.connectionType;
|
|
1997
2159
|
accessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
|
|
1998
2160
|
const newOrExternal = !device.external ? 'Adding new' : 'Loading external';
|
|
@@ -2022,7 +2184,9 @@ export class SwitchBotPlatform {
|
|
|
2022
2184
|
existingAccessory.context.deviceId = device.deviceId;
|
|
2023
2185
|
existingAccessory.context.deviceType = `IR: ${device.remoteType}`;
|
|
2024
2186
|
existingAccessory.context.model = device.remoteType;
|
|
2025
|
-
existingAccessory.displayName = device.configDeviceName
|
|
2187
|
+
existingAccessory.displayName = device.configDeviceName
|
|
2188
|
+
? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
|
|
2189
|
+
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName);
|
|
2026
2190
|
await this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`);
|
|
2027
2191
|
existingAccessory.context.connectionType = device.connectionType;
|
|
2028
2192
|
this.api.updatePlatformAccessories([existingAccessory]);
|
|
@@ -2037,14 +2201,19 @@ export class SwitchBotPlatform {
|
|
|
2037
2201
|
}
|
|
2038
2202
|
else if (!device.hide_device && device.hubDeviceId) {
|
|
2039
2203
|
// create a new accessory
|
|
2040
|
-
const accessory = new this.api.platformAccessory(device.
|
|
2204
|
+
const accessory = new this.api.platformAccessory(device.configDeviceName
|
|
2205
|
+
? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
|
|
2206
|
+
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName), uuid);
|
|
2041
2207
|
// store a copy of the device object in the `accessory.context`
|
|
2042
2208
|
// the `context` property can be used to store any data about the accessory you may need
|
|
2043
2209
|
accessory.context.device = device;
|
|
2044
2210
|
accessory.context.deviceId = device.deviceId;
|
|
2045
2211
|
accessory.context.deviceType = `IR: ${device.remoteType}`;
|
|
2046
2212
|
accessory.context.model = device.remoteType;
|
|
2047
|
-
accessory.displayName = device.configDeviceName
|
|
2213
|
+
accessory.displayName = device.configDeviceName
|
|
2214
|
+
? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
|
|
2215
|
+
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName);
|
|
2216
|
+
accessory.context.connectionType = await this.connectionType(device);
|
|
2048
2217
|
accessory.context.connectionType = device.connectionType;
|
|
2049
2218
|
accessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
|
|
2050
2219
|
const newOrExternal = !device.external ? 'Adding new' : 'Loading external';
|
|
@@ -2074,7 +2243,9 @@ export class SwitchBotPlatform {
|
|
|
2074
2243
|
existingAccessory.context.deviceId = device.deviceId;
|
|
2075
2244
|
existingAccessory.context.deviceType = `IR: ${device.remoteType}`;
|
|
2076
2245
|
existingAccessory.context.model = device.remoteType;
|
|
2077
|
-
existingAccessory.displayName = device.configDeviceName
|
|
2246
|
+
existingAccessory.displayName = device.configDeviceName
|
|
2247
|
+
? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
|
|
2248
|
+
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName);
|
|
2078
2249
|
await this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`);
|
|
2079
2250
|
existingAccessory.context.connectionType = device.connectionType;
|
|
2080
2251
|
this.api.updatePlatformAccessories([existingAccessory]);
|
|
@@ -2089,14 +2260,19 @@ export class SwitchBotPlatform {
|
|
|
2089
2260
|
}
|
|
2090
2261
|
else if (!device.hide_device && device.hubDeviceId) {
|
|
2091
2262
|
// create a new accessory
|
|
2092
|
-
const accessory = new this.api.platformAccessory(device.
|
|
2263
|
+
const accessory = new this.api.platformAccessory(device.configDeviceName
|
|
2264
|
+
? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
|
|
2265
|
+
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName), uuid);
|
|
2093
2266
|
// store a copy of the device object in the `accessory.context`
|
|
2094
2267
|
// the `context` property can be used to store any data about the accessory you may need
|
|
2095
2268
|
accessory.context.device = device;
|
|
2096
2269
|
accessory.context.deviceId = device.deviceId;
|
|
2097
2270
|
accessory.context.deviceType = `IR: ${device.remoteType}`;
|
|
2098
2271
|
accessory.context.model = device.remoteType;
|
|
2099
|
-
accessory.displayName = device.configDeviceName
|
|
2272
|
+
accessory.displayName = device.configDeviceName
|
|
2273
|
+
? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
|
|
2274
|
+
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName);
|
|
2275
|
+
accessory.context.connectionType = await this.connectionType(device);
|
|
2100
2276
|
accessory.context.connectionType = device.connectionType;
|
|
2101
2277
|
accessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
|
|
2102
2278
|
const newOrExternal = !device.external ? 'Adding new' : 'Loading external';
|
|
@@ -2126,7 +2302,9 @@ export class SwitchBotPlatform {
|
|
|
2126
2302
|
existingAccessory.context.deviceId = device.deviceId;
|
|
2127
2303
|
existingAccessory.context.deviceType = `IR: ${device.remoteType}`;
|
|
2128
2304
|
existingAccessory.context.model = device.remoteType;
|
|
2129
|
-
existingAccessory.displayName = device.configDeviceName
|
|
2305
|
+
existingAccessory.displayName = device.configDeviceName
|
|
2306
|
+
? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
|
|
2307
|
+
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName);
|
|
2130
2308
|
await this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`);
|
|
2131
2309
|
existingAccessory.context.connectionType = device.connectionType;
|
|
2132
2310
|
this.api.updatePlatformAccessories([existingAccessory]);
|
|
@@ -2141,14 +2319,19 @@ export class SwitchBotPlatform {
|
|
|
2141
2319
|
}
|
|
2142
2320
|
else if (!device.hide_device && device.hubDeviceId) {
|
|
2143
2321
|
// create a new accessory
|
|
2144
|
-
const accessory = new this.api.platformAccessory(device.
|
|
2322
|
+
const accessory = new this.api.platformAccessory(device.configDeviceName
|
|
2323
|
+
? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
|
|
2324
|
+
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName), uuid);
|
|
2145
2325
|
// store a copy of the device object in the `accessory.context`
|
|
2146
2326
|
// the `context` property can be used to store any data about the accessory you may need
|
|
2147
2327
|
accessory.context.device = device;
|
|
2148
2328
|
accessory.context.deviceId = device.deviceId;
|
|
2149
2329
|
accessory.context.deviceType = `IR: ${device.remoteType}`;
|
|
2150
2330
|
accessory.context.model = device.remoteType;
|
|
2151
|
-
accessory.displayName = device.configDeviceName
|
|
2331
|
+
accessory.displayName = device.configDeviceName
|
|
2332
|
+
? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
|
|
2333
|
+
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName);
|
|
2334
|
+
accessory.context.connectionType = await this.connectionType(device);
|
|
2152
2335
|
accessory.context.connectionType = device.connectionType;
|
|
2153
2336
|
accessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
|
|
2154
2337
|
const newOrExternal = !device.external ? 'Adding new' : 'Loading external';
|
|
@@ -2178,7 +2361,9 @@ export class SwitchBotPlatform {
|
|
|
2178
2361
|
existingAccessory.context.deviceId = device.deviceId;
|
|
2179
2362
|
existingAccessory.context.deviceType = `IR: ${device.remoteType}`;
|
|
2180
2363
|
existingAccessory.context.model = device.remoteType;
|
|
2181
|
-
existingAccessory.displayName = device.configDeviceName
|
|
2364
|
+
existingAccessory.displayName = device.configDeviceName
|
|
2365
|
+
? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
|
|
2366
|
+
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName);
|
|
2182
2367
|
await this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`);
|
|
2183
2368
|
existingAccessory.context.connectionType = device.connectionType;
|
|
2184
2369
|
this.api.updatePlatformAccessories([existingAccessory]);
|
|
@@ -2193,14 +2378,19 @@ export class SwitchBotPlatform {
|
|
|
2193
2378
|
}
|
|
2194
2379
|
else if (!device.hide_device && device.hubDeviceId) {
|
|
2195
2380
|
// create a new accessory
|
|
2196
|
-
const accessory = new this.api.platformAccessory(device.
|
|
2381
|
+
const accessory = new this.api.platformAccessory(device.configDeviceName
|
|
2382
|
+
? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
|
|
2383
|
+
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName), uuid);
|
|
2197
2384
|
// store a copy of the device object in the `accessory.context`
|
|
2198
2385
|
// the `context` property can be used to store any data about the accessory you may need
|
|
2199
2386
|
accessory.context.device = device;
|
|
2200
2387
|
accessory.context.deviceId = device.deviceId;
|
|
2201
2388
|
accessory.context.deviceType = `IR: ${device.remoteType}`;
|
|
2202
2389
|
accessory.context.model = device.remoteType;
|
|
2203
|
-
accessory.displayName = device.configDeviceName
|
|
2390
|
+
accessory.displayName = device.configDeviceName
|
|
2391
|
+
? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
|
|
2392
|
+
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName);
|
|
2393
|
+
accessory.context.connectionType = await this.connectionType(device);
|
|
2204
2394
|
accessory.context.connectionType = device.connectionType;
|
|
2205
2395
|
accessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
|
|
2206
2396
|
const newOrExternal = !device.external ? 'Adding new' : 'Loading external';
|
|
@@ -2230,7 +2420,9 @@ export class SwitchBotPlatform {
|
|
|
2230
2420
|
existingAccessory.context.deviceId = device.deviceId;
|
|
2231
2421
|
existingAccessory.context.deviceType = `IR: ${device.remoteType}`;
|
|
2232
2422
|
existingAccessory.context.model = device.remoteType;
|
|
2233
|
-
existingAccessory.displayName = device.configDeviceName
|
|
2423
|
+
existingAccessory.displayName = device.configDeviceName
|
|
2424
|
+
? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
|
|
2425
|
+
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName);
|
|
2234
2426
|
await this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`);
|
|
2235
2427
|
existingAccessory.context.connectionType = device.connectionType;
|
|
2236
2428
|
this.api.updatePlatformAccessories([existingAccessory]);
|
|
@@ -2245,14 +2437,19 @@ export class SwitchBotPlatform {
|
|
|
2245
2437
|
}
|
|
2246
2438
|
else if (!device.hide_device && device.hubDeviceId) {
|
|
2247
2439
|
// create a new accessory
|
|
2248
|
-
const accessory = new this.api.platformAccessory(device.
|
|
2440
|
+
const accessory = new this.api.platformAccessory(device.configDeviceName
|
|
2441
|
+
? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
|
|
2442
|
+
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName), uuid);
|
|
2249
2443
|
// store a copy of the device object in the `accessory.context`
|
|
2250
2444
|
// the `context` property can be used to store any data about the accessory you may need
|
|
2251
2445
|
accessory.context.device = device;
|
|
2252
2446
|
accessory.context.deviceId = device.deviceId;
|
|
2253
2447
|
accessory.context.deviceType = `IR: ${device.remoteType}`;
|
|
2254
2448
|
accessory.context.model = device.remoteType;
|
|
2255
|
-
accessory.displayName = device.configDeviceName
|
|
2449
|
+
accessory.displayName = device.configDeviceName
|
|
2450
|
+
? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
|
|
2451
|
+
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName);
|
|
2452
|
+
accessory.context.connectionType = await this.connectionType(device);
|
|
2256
2453
|
accessory.context.connectionType = device.connectionType;
|
|
2257
2454
|
accessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
|
|
2258
2455
|
const newOrExternal = !device.external ? 'Adding new' : 'Loading external';
|
|
@@ -2615,7 +2812,7 @@ export class SwitchBotPlatform {
|
|
|
2615
2812
|
}
|
|
2616
2813
|
}
|
|
2617
2814
|
async getPlatformLogSettings() {
|
|
2618
|
-
this.debugMode = process.argv.includes('-D')
|
|
2815
|
+
this.debugMode = process.argv.includes('-D') ?? process.argv.includes('--debug');
|
|
2619
2816
|
if (this.config.options?.logging === 'debug' || this.config.options?.logging === 'standard' || this.config.options?.logging === 'none') {
|
|
2620
2817
|
this.platformLogging = this.config.options.logging;
|
|
2621
2818
|
await this.debugWarnLog(`Using Config Logging: ${this.platformLogging}`);
|
|
@@ -2629,6 +2826,34 @@ export class SwitchBotPlatform {
|
|
|
2629
2826
|
await this.debugWarnLog(`Using ${this.platformLogging} Logging`);
|
|
2630
2827
|
}
|
|
2631
2828
|
}
|
|
2829
|
+
/**
|
|
2830
|
+
* Validate and clean a string value for a Name Characteristic.
|
|
2831
|
+
* @param displayName
|
|
2832
|
+
* @param name
|
|
2833
|
+
* @param value
|
|
2834
|
+
* @returns string value
|
|
2835
|
+
*/
|
|
2836
|
+
async validateAndCleanDisplayName(displayName, name, value) {
|
|
2837
|
+
const validPattern = /^[a-zA-Z0-9][a-zA-Z0-9 ']*[a-zA-Z0-9]$/;
|
|
2838
|
+
const invalidCharsPattern = /[^a-zA-Z0-9 ']/g;
|
|
2839
|
+
const invalidStartEndPattern = /^[^a-zA-Z0-9]+|[^a-zA-Z0-9]+$/g;
|
|
2840
|
+
if (!validPattern.test(value)) {
|
|
2841
|
+
this.warnLog(`WARNING: The accessory '${displayName}' has an invalid '${name}' characteristic ('${value}'). Please use only alphanumeric,`
|
|
2842
|
+
+ ' space, and apostrophe characters. Ensure it starts and ends with an alphabetic or numeric character, and avoid emojis. This may'
|
|
2843
|
+
+ ' prevent the accessory from being added in the Home App or cause unresponsiveness.');
|
|
2844
|
+
// Remove invalid characters
|
|
2845
|
+
if (invalidCharsPattern.test(value)) {
|
|
2846
|
+
this.warnLog(`Removing invalid characters from '${name}' characteristic`);
|
|
2847
|
+
value = value.replace(invalidCharsPattern, '');
|
|
2848
|
+
}
|
|
2849
|
+
// Ensure it starts and ends with an alphanumeric character
|
|
2850
|
+
if (invalidStartEndPattern.test(value)) {
|
|
2851
|
+
this.warnLog(`Removing invalid starting or ending characters from '${name}' characteristic`);
|
|
2852
|
+
value = value.replace(invalidStartEndPattern, '');
|
|
2853
|
+
}
|
|
2854
|
+
}
|
|
2855
|
+
return value;
|
|
2856
|
+
}
|
|
2632
2857
|
/**
|
|
2633
2858
|
* If device level logging is turned on, log to log.warn
|
|
2634
2859
|
* Otherwise send debug logs to log.debug
|
|
@@ -2645,7 +2870,7 @@ export class SwitchBotPlatform {
|
|
|
2645
2870
|
}
|
|
2646
2871
|
async debugSuccessLog(...log) {
|
|
2647
2872
|
if (await this.enablingPlatformLogging()) {
|
|
2648
|
-
if (this.
|
|
2873
|
+
if (await this.loggingIsDebug()) {
|
|
2649
2874
|
this.log.success('[DEBUG]', String(...log));
|
|
2650
2875
|
}
|
|
2651
2876
|
}
|
|
@@ -2657,7 +2882,7 @@ export class SwitchBotPlatform {
|
|
|
2657
2882
|
}
|
|
2658
2883
|
async debugWarnLog(...log) {
|
|
2659
2884
|
if (await this.enablingPlatformLogging()) {
|
|
2660
|
-
if (this.
|
|
2885
|
+
if (await this.loggingIsDebug()) {
|
|
2661
2886
|
this.log.warn('[DEBUG]', String(...log));
|
|
2662
2887
|
}
|
|
2663
2888
|
}
|
|
@@ -2669,23 +2894,26 @@ export class SwitchBotPlatform {
|
|
|
2669
2894
|
}
|
|
2670
2895
|
async debugErrorLog(...log) {
|
|
2671
2896
|
if (await this.enablingPlatformLogging()) {
|
|
2672
|
-
if (this.
|
|
2897
|
+
if (await this.loggingIsDebug()) {
|
|
2673
2898
|
this.log.error('[DEBUG]', String(...log));
|
|
2674
2899
|
}
|
|
2675
2900
|
}
|
|
2676
2901
|
}
|
|
2677
2902
|
async debugLog(...log) {
|
|
2678
2903
|
if (await this.enablingPlatformLogging()) {
|
|
2679
|
-
if (this.platformLogging === '
|
|
2680
|
-
this.log.debug(String(...log));
|
|
2681
|
-
}
|
|
2682
|
-
else if (this.platformLogging === 'debug') {
|
|
2904
|
+
if (this.platformLogging === 'debug') {
|
|
2683
2905
|
this.log.info('[DEBUG]', String(...log));
|
|
2684
2906
|
}
|
|
2907
|
+
else if (this.platformLogging === 'debugMode') {
|
|
2908
|
+
this.log.debug(String(...log));
|
|
2909
|
+
}
|
|
2685
2910
|
}
|
|
2686
2911
|
}
|
|
2912
|
+
async loggingIsDebug() {
|
|
2913
|
+
return this.platformLogging === 'debugMode' || this.platformLogging === 'debug';
|
|
2914
|
+
}
|
|
2687
2915
|
async enablingPlatformLogging() {
|
|
2688
|
-
return this.platformLogging
|
|
2916
|
+
return this.platformLogging === 'debugMode' || this.platformLogging === 'debug' || this.platformLogging === 'standard';
|
|
2689
2917
|
}
|
|
2690
2918
|
}
|
|
2691
2919
|
//# sourceMappingURL=platform.js.map
|