@switchbot/homebridge-switchbot 3.6.1-beta.9 → 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 +310 -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 +315 -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}`);
|
|
@@ -834,7 +834,9 @@ export class SwitchBotPlatform {
|
|
|
834
834
|
existingAccessory.context.deviceId = device.deviceId;
|
|
835
835
|
existingAccessory.context.deviceType = device.deviceType;
|
|
836
836
|
existingAccessory.context.model = SwitchBotModel.Humidifier;
|
|
837
|
-
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);
|
|
838
840
|
existingAccessory.context.connectionType = await this.connectionType(device);
|
|
839
841
|
existingAccessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
|
|
840
842
|
await this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`);
|
|
@@ -850,14 +852,18 @@ export class SwitchBotPlatform {
|
|
|
850
852
|
}
|
|
851
853
|
else if (await this.registerDevice(device)) {
|
|
852
854
|
// create a new accessory
|
|
853
|
-
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);
|
|
854
858
|
// store a copy of the device object in the `accessory.context`
|
|
855
859
|
// the `context` property can be used to store any data about the accessory you may need
|
|
856
860
|
accessory.context.device = device;
|
|
857
861
|
accessory.context.deviceId = device.deviceId;
|
|
858
862
|
accessory.context.deviceType = device.deviceType;
|
|
859
863
|
accessory.context.model = SwitchBotModel.Humidifier;
|
|
860
|
-
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);
|
|
861
867
|
accessory.context.connectionType = await this.connectionType(device);
|
|
862
868
|
accessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
|
|
863
869
|
const newOrExternal = !device.external ? 'Adding new' : 'Loading external';
|
|
@@ -887,7 +893,9 @@ export class SwitchBotPlatform {
|
|
|
887
893
|
existingAccessory.context.deviceId = device.deviceId;
|
|
888
894
|
existingAccessory.context.deviceType = device.deviceType;
|
|
889
895
|
existingAccessory.context.model = SwitchBotModel.Bot;
|
|
890
|
-
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);
|
|
891
899
|
existingAccessory.context.connectionType = await this.connectionType(device);
|
|
892
900
|
existingAccessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
|
|
893
901
|
this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`);
|
|
@@ -903,14 +911,19 @@ export class SwitchBotPlatform {
|
|
|
903
911
|
}
|
|
904
912
|
else if (await this.registerDevice(device)) {
|
|
905
913
|
// create a new accessory
|
|
906
|
-
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);
|
|
907
917
|
// store a copy of the device object in the `accessory.context`
|
|
908
918
|
// the `context` property can be used to store any data about the accessory you may need
|
|
909
919
|
accessory.context.device = device;
|
|
910
920
|
accessory.context.deviceId = device.deviceId;
|
|
911
921
|
accessory.context.deviceType = device.deviceType;
|
|
912
922
|
accessory.context.model = SwitchBotModel.Bot;
|
|
913
|
-
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);
|
|
914
927
|
accessory.context.connectionType = await this.connectionType(device);
|
|
915
928
|
accessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
|
|
916
929
|
const newOrExternal = !device.external ? 'Adding new' : 'Loading external';
|
|
@@ -941,7 +954,9 @@ export class SwitchBotPlatform {
|
|
|
941
954
|
existingAccessory.context.model = SwitchBotModel.Meter;
|
|
942
955
|
existingAccessory.context.deviceId = device.deviceId;
|
|
943
956
|
existingAccessory.context.deviceType = device.deviceType;
|
|
944
|
-
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);
|
|
945
960
|
existingAccessory.context.connectionType = await this.connectionType(device);
|
|
946
961
|
existingAccessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
|
|
947
962
|
this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`);
|
|
@@ -957,14 +972,19 @@ export class SwitchBotPlatform {
|
|
|
957
972
|
}
|
|
958
973
|
else if (await this.registerDevice(device)) {
|
|
959
974
|
// create a new accessory
|
|
960
|
-
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);
|
|
961
978
|
// store a copy of the device object in the `accessory.context`
|
|
962
979
|
// the `context` property can be used to store any data about the accessory you may need
|
|
963
980
|
accessory.context.device = device;
|
|
964
981
|
accessory.context.model = SwitchBotModel.Meter;
|
|
965
982
|
accessory.context.deviceId = device.deviceId;
|
|
966
983
|
accessory.context.deviceType = device.deviceType;
|
|
967
|
-
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);
|
|
968
988
|
accessory.context.connectionType = await this.connectionType(device);
|
|
969
989
|
accessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
|
|
970
990
|
const newOrExternal = !device.external ? 'Adding new' : 'Loading external';
|
|
@@ -995,7 +1015,9 @@ export class SwitchBotPlatform {
|
|
|
995
1015
|
existingAccessory.context.model = SwitchBotModel.MeterPlusUS ?? SwitchBotModel.MeterPlusJP;
|
|
996
1016
|
existingAccessory.context.deviceId = device.deviceId;
|
|
997
1017
|
existingAccessory.context.deviceType = device.deviceType;
|
|
998
|
-
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);
|
|
999
1021
|
existingAccessory.context.connectionType = await this.connectionType(device);
|
|
1000
1022
|
existingAccessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
|
|
1001
1023
|
this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`);
|
|
@@ -1011,14 +1033,19 @@ export class SwitchBotPlatform {
|
|
|
1011
1033
|
}
|
|
1012
1034
|
else if (await this.registerDevice(device)) {
|
|
1013
1035
|
// create a new accessory
|
|
1014
|
-
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);
|
|
1015
1039
|
// store a copy of the device object in the `accessory.context`
|
|
1016
1040
|
// the `context` property can be used to store any data about the accessory you may need
|
|
1017
1041
|
accessory.context.device = device;
|
|
1018
1042
|
accessory.context.model = SwitchBotModel.MeterPlusUS ?? SwitchBotModel.MeterPlusJP;
|
|
1019
1043
|
accessory.context.deviceId = device.deviceId;
|
|
1020
1044
|
accessory.context.deviceType = device.deviceType;
|
|
1021
|
-
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);
|
|
1022
1049
|
accessory.context.connectionType = await this.connectionType(device);
|
|
1023
1050
|
accessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
|
|
1024
1051
|
const newOrExternal = !device.external ? 'Adding new' : 'Loading external';
|
|
@@ -1049,7 +1076,9 @@ export class SwitchBotPlatform {
|
|
|
1049
1076
|
existingAccessory.context.model = SwitchBotModel.Hub2;
|
|
1050
1077
|
existingAccessory.context.deviceId = device.deviceId;
|
|
1051
1078
|
existingAccessory.context.deviceType = device.deviceType;
|
|
1052
|
-
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);
|
|
1053
1082
|
existingAccessory.context.connectionType = await this.connectionType(device);
|
|
1054
1083
|
existingAccessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
|
|
1055
1084
|
this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`);
|
|
@@ -1065,14 +1094,19 @@ export class SwitchBotPlatform {
|
|
|
1065
1094
|
}
|
|
1066
1095
|
else if (await this.registerDevice(device)) {
|
|
1067
1096
|
// create a new accessory
|
|
1068
|
-
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);
|
|
1069
1100
|
// store a copy of the device object in the `accessory.context`
|
|
1070
1101
|
// the `context` property can be used to store any data about the accessory you may need
|
|
1071
1102
|
accessory.context.device = device;
|
|
1072
1103
|
accessory.context.model = SwitchBotModel.Hub2;
|
|
1073
1104
|
accessory.context.deviceId = device.deviceId;
|
|
1074
1105
|
accessory.context.deviceType = device.deviceType;
|
|
1075
|
-
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);
|
|
1076
1110
|
accessory.context.connectionType = await this.connectionType(device);
|
|
1077
1111
|
accessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
|
|
1078
1112
|
const newOrExternal = !device.external ? 'Adding new' : 'Loading external';
|
|
@@ -1102,7 +1136,9 @@ export class SwitchBotPlatform {
|
|
|
1102
1136
|
existingAccessory.context.model = SwitchBotModel.OutdoorMeter;
|
|
1103
1137
|
existingAccessory.context.deviceId = device.deviceId;
|
|
1104
1138
|
existingAccessory.context.deviceType = device.deviceType;
|
|
1105
|
-
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);
|
|
1106
1142
|
existingAccessory.context.connectionType = await this.connectionType(device);
|
|
1107
1143
|
existingAccessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
|
|
1108
1144
|
await this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`);
|
|
@@ -1118,14 +1154,19 @@ export class SwitchBotPlatform {
|
|
|
1118
1154
|
}
|
|
1119
1155
|
else if (await this.registerDevice(device)) {
|
|
1120
1156
|
// create a new accessory
|
|
1121
|
-
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);
|
|
1122
1160
|
// store a copy of the device object in the `accessory.context`
|
|
1123
1161
|
// the `context` property can be used to store any data about the accessory you may need
|
|
1124
1162
|
accessory.context.device = device;
|
|
1125
1163
|
accessory.context.model = SwitchBotModel.OutdoorMeter;
|
|
1126
1164
|
accessory.context.deviceId = device.deviceId;
|
|
1127
1165
|
accessory.context.deviceType = device.deviceType;
|
|
1128
|
-
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);
|
|
1129
1170
|
accessory.context.connectionType = await this.connectionType(device);
|
|
1130
1171
|
accessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
|
|
1131
1172
|
const newOrExternal = !device.external ? 'Adding new' : 'Loading external';
|
|
@@ -1155,7 +1196,9 @@ export class SwitchBotPlatform {
|
|
|
1155
1196
|
existingAccessory.context.deviceId = device.deviceId;
|
|
1156
1197
|
existingAccessory.context.deviceType = device.deviceType;
|
|
1157
1198
|
existingAccessory.context.model = SwitchBotModel.WaterDetector;
|
|
1158
|
-
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);
|
|
1159
1202
|
existingAccessory.context.connectionType = await this.connectionType(device);
|
|
1160
1203
|
existingAccessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
|
|
1161
1204
|
this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`);
|
|
@@ -1171,14 +1214,19 @@ export class SwitchBotPlatform {
|
|
|
1171
1214
|
}
|
|
1172
1215
|
else if (await this.registerDevice(device)) {
|
|
1173
1216
|
// create a new accessory
|
|
1174
|
-
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);
|
|
1175
1220
|
// store a copy of the device object in the `accessory.context`
|
|
1176
1221
|
// the `context` property can be used to store any data about the accessory you may need
|
|
1177
1222
|
accessory.context.device = device;
|
|
1178
1223
|
accessory.context.deviceId = device.deviceId;
|
|
1179
1224
|
accessory.context.deviceType = device.deviceType;
|
|
1180
1225
|
accessory.context.model = SwitchBotModel.WaterDetector;
|
|
1181
|
-
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);
|
|
1182
1230
|
accessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
|
|
1183
1231
|
accessory.context.connectionType = await this.connectionType(device);
|
|
1184
1232
|
const newOrExternal = !device.external ? 'Adding new' : 'Loading external';
|
|
@@ -1208,7 +1256,9 @@ export class SwitchBotPlatform {
|
|
|
1208
1256
|
existingAccessory.context.deviceId = device.deviceId;
|
|
1209
1257
|
existingAccessory.context.deviceType = device.deviceType;
|
|
1210
1258
|
existingAccessory.context.model = SwitchBotModel.MotionSensor;
|
|
1211
|
-
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);
|
|
1212
1262
|
existingAccessory.context.connectionType = await this.connectionType(device);
|
|
1213
1263
|
existingAccessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
|
|
1214
1264
|
this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`);
|
|
@@ -1224,14 +1274,19 @@ export class SwitchBotPlatform {
|
|
|
1224
1274
|
}
|
|
1225
1275
|
else if (await this.registerDevice(device)) {
|
|
1226
1276
|
// create a new accessory
|
|
1227
|
-
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);
|
|
1228
1280
|
// store a copy of the device object in the `accessory.context`
|
|
1229
1281
|
// the `context` property can be used to store any data about the accessory you may need
|
|
1230
1282
|
accessory.context.device = device;
|
|
1231
1283
|
accessory.context.deviceId = device.deviceId;
|
|
1232
1284
|
accessory.context.deviceType = device.deviceType;
|
|
1233
1285
|
accessory.context.model = SwitchBotModel.MotionSensor;
|
|
1234
|
-
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);
|
|
1235
1290
|
accessory.context.connectionType = await this.connectionType(device);
|
|
1236
1291
|
accessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
|
|
1237
1292
|
const newOrExternal = !device.external ? 'Adding new' : 'Loading external';
|
|
@@ -1261,7 +1316,9 @@ export class SwitchBotPlatform {
|
|
|
1261
1316
|
existingAccessory.context.deviceId = device.deviceId;
|
|
1262
1317
|
existingAccessory.context.deviceType = device.deviceType;
|
|
1263
1318
|
existingAccessory.context.model = SwitchBotModel.ContactSensor;
|
|
1264
|
-
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);
|
|
1265
1322
|
existingAccessory.context.connectionType = await this.connectionType(device);
|
|
1266
1323
|
existingAccessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
|
|
1267
1324
|
this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`);
|
|
@@ -1277,14 +1334,19 @@ export class SwitchBotPlatform {
|
|
|
1277
1334
|
}
|
|
1278
1335
|
else if (await this.registerDevice(device)) {
|
|
1279
1336
|
// create a new accessory
|
|
1280
|
-
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);
|
|
1281
1340
|
// store a copy of the device object in the `accessory.context`
|
|
1282
1341
|
// the `context` property can be used to store any data about the accessory you may need
|
|
1283
1342
|
accessory.context.device = device;
|
|
1284
1343
|
accessory.context.deviceId = device.deviceId;
|
|
1285
1344
|
accessory.context.deviceType = device.deviceType;
|
|
1286
1345
|
accessory.context.model = SwitchBotModel.ContactSensor;
|
|
1287
|
-
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);
|
|
1288
1350
|
accessory.context.connectionType = await this.connectionType(device);
|
|
1289
1351
|
accessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
|
|
1290
1352
|
const newOrExternal = !device.external ? 'Adding new' : 'Loading external';
|
|
@@ -1314,7 +1376,9 @@ export class SwitchBotPlatform {
|
|
|
1314
1376
|
existingAccessory.context.deviceId = device.deviceId;
|
|
1315
1377
|
existingAccessory.context.deviceType = device.deviceType;
|
|
1316
1378
|
existingAccessory.context.model = SwitchBotModel.BlindTilt;
|
|
1317
|
-
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);
|
|
1318
1382
|
existingAccessory.context.connectionType = await this.connectionType(device);
|
|
1319
1383
|
existingAccessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
|
|
1320
1384
|
this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`);
|
|
@@ -1344,7 +1408,9 @@ export class SwitchBotPlatform {
|
|
|
1344
1408
|
}
|
|
1345
1409
|
}
|
|
1346
1410
|
// create a new accessory
|
|
1347
|
-
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);
|
|
1348
1414
|
// store a copy of the device object in the `accessory.context`
|
|
1349
1415
|
// the `context` property can be used to store any data about the accessory you may need
|
|
1350
1416
|
accessory.context.device = device;
|
|
@@ -1352,7 +1418,10 @@ export class SwitchBotPlatform {
|
|
|
1352
1418
|
accessory.context.deviceId = device.deviceId;
|
|
1353
1419
|
accessory.context.deviceType = device.deviceType;
|
|
1354
1420
|
accessory.context.model = SwitchBotModel.BlindTilt;
|
|
1355
|
-
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);
|
|
1356
1425
|
accessory.context.connectionType = await this.connectionType(device);
|
|
1357
1426
|
accessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
|
|
1358
1427
|
const newOrExternal = !device.external ? 'Adding new' : 'Loading external';
|
|
@@ -1382,7 +1451,9 @@ export class SwitchBotPlatform {
|
|
|
1382
1451
|
existingAccessory.context.deviceId = device.deviceId;
|
|
1383
1452
|
existingAccessory.context.deviceType = device.deviceType;
|
|
1384
1453
|
existingAccessory.context.model = device.deviceType === 'Curtain3' ? SwitchBotModel.Curtain3 : SwitchBotModel.Curtain;
|
|
1385
|
-
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);
|
|
1386
1457
|
existingAccessory.context.connectionType = await this.connectionType(device);
|
|
1387
1458
|
existingAccessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
|
|
1388
1459
|
await this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`);
|
|
@@ -1412,14 +1483,19 @@ export class SwitchBotPlatform {
|
|
|
1412
1483
|
}
|
|
1413
1484
|
}
|
|
1414
1485
|
// create a new accessory
|
|
1415
|
-
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);
|
|
1416
1489
|
// store a copy of the device object in the `accessory.context`
|
|
1417
1490
|
// the `context` property can be used to store any data about the accessory you may need
|
|
1418
1491
|
accessory.context.device = device;
|
|
1419
1492
|
accessory.context.deviceId = device.deviceId;
|
|
1420
1493
|
accessory.context.deviceType = device.deviceType;
|
|
1421
1494
|
accessory.context.model = device.deviceType === 'Curtain3' ? SwitchBotModel.Curtain3 : SwitchBotModel.Curtain;
|
|
1422
|
-
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);
|
|
1423
1499
|
accessory.context.connectionType = await this.connectionType(device);
|
|
1424
1500
|
accessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
|
|
1425
1501
|
const newOrExternal = !device.external ? 'Adding new' : 'Loading external';
|
|
@@ -1450,7 +1526,9 @@ export class SwitchBotPlatform {
|
|
|
1450
1526
|
existingAccessory.context.deviceType = device.deviceType;
|
|
1451
1527
|
existingAccessory.context.model = device.deviceType === 'Plug Mini (US)' ? SwitchBotModel.PlugMiniUS : device.deviceType === 'Plug Mini (JP)'
|
|
1452
1528
|
? SwitchBotModel.PlugMiniJP : SwitchBotModel.Plug;
|
|
1453
|
-
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);
|
|
1454
1532
|
existingAccessory.context.connectionType = await this.connectionType(device);
|
|
1455
1533
|
existingAccessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
|
|
1456
1534
|
await this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`);
|
|
@@ -1466,7 +1544,9 @@ export class SwitchBotPlatform {
|
|
|
1466
1544
|
}
|
|
1467
1545
|
else if (await this.registerDevice(device)) {
|
|
1468
1546
|
// create a new accessory
|
|
1469
|
-
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);
|
|
1470
1550
|
// store a copy of the device object in the `accessory.context`
|
|
1471
1551
|
// the `context` property can be used to store any data about the accessory you may need
|
|
1472
1552
|
accessory.context.device = device;
|
|
@@ -1474,7 +1554,10 @@ export class SwitchBotPlatform {
|
|
|
1474
1554
|
accessory.context.deviceType = device.deviceType;
|
|
1475
1555
|
accessory.context.model = device.deviceType === 'Plug Mini (US)' ? SwitchBotModel.PlugMiniUS : device.deviceType === 'Plug Mini (JP)'
|
|
1476
1556
|
? SwitchBotModel.PlugMiniJP : SwitchBotModel.Plug;
|
|
1477
|
-
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);
|
|
1478
1561
|
accessory.context.connectionType = await this.connectionType(device);
|
|
1479
1562
|
accessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
|
|
1480
1563
|
const newOrExternal = !device.external ? 'Adding new' : 'Loading external';
|
|
@@ -1504,7 +1587,9 @@ export class SwitchBotPlatform {
|
|
|
1504
1587
|
existingAccessory.context.deviceId = device.deviceId;
|
|
1505
1588
|
existingAccessory.context.deviceType = device.deviceType;
|
|
1506
1589
|
existingAccessory.context.model = device.deviceType === 'Smart Lock Pro' ? SwitchBotModel.LockPro : SwitchBotModel.Lock;
|
|
1507
|
-
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);
|
|
1508
1593
|
existingAccessory.context.connectionType = await this.connectionType(device);
|
|
1509
1594
|
existingAccessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
|
|
1510
1595
|
this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`);
|
|
@@ -1520,14 +1605,19 @@ export class SwitchBotPlatform {
|
|
|
1520
1605
|
}
|
|
1521
1606
|
else if (await this.registerDevice(device)) {
|
|
1522
1607
|
// create a new accessory
|
|
1523
|
-
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);
|
|
1524
1611
|
// store a copy of the device object in the `accessory.context`
|
|
1525
1612
|
// the `context` property can be used to store any data about the accessory you may need
|
|
1526
1613
|
accessory.context.device = device;
|
|
1527
1614
|
accessory.context.deviceId = device.deviceId;
|
|
1528
1615
|
accessory.context.deviceType = device.deviceType;
|
|
1529
1616
|
accessory.context.model = device.deviceType === 'Smart Lock Pro' ? SwitchBotModel.LockPro : SwitchBotModel.Lock;
|
|
1530
|
-
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);
|
|
1531
1621
|
accessory.context.connectionType = await this.connectionType(device);
|
|
1532
1622
|
accessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
|
|
1533
1623
|
const newOrExternal = !device.external ? 'Adding new' : 'Loading external';
|
|
@@ -1557,7 +1647,9 @@ export class SwitchBotPlatform {
|
|
|
1557
1647
|
existingAccessory.context.deviceId = device.deviceId;
|
|
1558
1648
|
existingAccessory.context.deviceType = device.deviceType;
|
|
1559
1649
|
existingAccessory.context.model = SwitchBotModel.ColorBulb;
|
|
1560
|
-
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);
|
|
1561
1653
|
existingAccessory.context.connectionType = await this.connectionType(device);
|
|
1562
1654
|
existingAccessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
|
|
1563
1655
|
await this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`);
|
|
@@ -1573,14 +1665,19 @@ export class SwitchBotPlatform {
|
|
|
1573
1665
|
}
|
|
1574
1666
|
else if (await this.registerDevice(device)) {
|
|
1575
1667
|
// create a new accessory
|
|
1576
|
-
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);
|
|
1577
1671
|
// store a copy of the device object in the `accessory.context`
|
|
1578
1672
|
// the `context` property can be used to store any data about the accessory you may need
|
|
1579
1673
|
accessory.context.device = device;
|
|
1580
1674
|
accessory.context.deviceId = device.deviceId;
|
|
1581
1675
|
accessory.context.deviceType = device.deviceType;
|
|
1582
1676
|
accessory.context.model = SwitchBotModel.ColorBulb;
|
|
1583
|
-
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);
|
|
1584
1681
|
accessory.context.connectionType = await this.connectionType(device);
|
|
1585
1682
|
accessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
|
|
1586
1683
|
const newOrExternal = !device.external ? 'Adding new' : 'Loading external';
|
|
@@ -1610,7 +1707,9 @@ export class SwitchBotPlatform {
|
|
|
1610
1707
|
existingAccessory.context.deviceId = device.deviceId;
|
|
1611
1708
|
existingAccessory.context.deviceType = device.deviceType;
|
|
1612
1709
|
existingAccessory.context.model = device.deviceType === 'Ceiling Light Pro' ? SwitchBotModel.CeilingLightPro : SwitchBotModel.CeilingLight;
|
|
1613
|
-
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);
|
|
1614
1713
|
existingAccessory.context.connectionType = await this.connectionType(device);
|
|
1615
1714
|
existingAccessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
|
|
1616
1715
|
await this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`);
|
|
@@ -1626,14 +1725,19 @@ export class SwitchBotPlatform {
|
|
|
1626
1725
|
}
|
|
1627
1726
|
else if (await this.registerDevice(device)) {
|
|
1628
1727
|
// create a new accessory
|
|
1629
|
-
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);
|
|
1630
1731
|
// store a copy of the device object in the `accessory.context`
|
|
1631
1732
|
// the `context` property can be used to store any data about the accessory you may need
|
|
1632
1733
|
accessory.context.device = device;
|
|
1633
1734
|
accessory.context.deviceId = device.deviceId;
|
|
1634
1735
|
accessory.context.deviceType = device.deviceType;
|
|
1635
1736
|
accessory.context.model = device.deviceType === 'Ceiling Light Pro' ? SwitchBotModel.CeilingLightPro : SwitchBotModel.CeilingLight;
|
|
1636
|
-
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);
|
|
1637
1741
|
accessory.context.connectionType = await this.connectionType(device);
|
|
1638
1742
|
accessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
|
|
1639
1743
|
const newOrExternal = !device.external ? 'Adding new' : 'Loading external';
|
|
@@ -1663,7 +1767,9 @@ export class SwitchBotPlatform {
|
|
|
1663
1767
|
existingAccessory.context.deviceId = device.deviceId;
|
|
1664
1768
|
existingAccessory.context.deviceType = device.deviceType;
|
|
1665
1769
|
existingAccessory.context.model = SwitchBotModel.StripLight;
|
|
1666
|
-
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);
|
|
1667
1773
|
existingAccessory.context.connectionType = await this.connectionType(device);
|
|
1668
1774
|
existingAccessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
|
|
1669
1775
|
await this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`);
|
|
@@ -1679,14 +1785,19 @@ export class SwitchBotPlatform {
|
|
|
1679
1785
|
}
|
|
1680
1786
|
else if (await this.registerDevice(device)) {
|
|
1681
1787
|
// create a new accessory
|
|
1682
|
-
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);
|
|
1683
1791
|
// store a copy of the device object in the `accessory.context`
|
|
1684
1792
|
// the `context` property can be used to store any data about the accessory you may need
|
|
1685
1793
|
accessory.context.device = device;
|
|
1686
1794
|
accessory.context.deviceId = device.deviceId;
|
|
1687
1795
|
accessory.context.deviceType = device.deviceType;
|
|
1688
1796
|
accessory.context.model = SwitchBotModel.StripLight;
|
|
1689
|
-
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);
|
|
1690
1801
|
accessory.context.connectionType = await this.connectionType(device);
|
|
1691
1802
|
accessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
|
|
1692
1803
|
const newOrExternal = !device.external ? 'Adding new' : 'Loading external';
|
|
@@ -1716,7 +1827,9 @@ export class SwitchBotPlatform {
|
|
|
1716
1827
|
existingAccessory.context.deviceId = device.deviceId;
|
|
1717
1828
|
existingAccessory.context.deviceType = device.deviceType;
|
|
1718
1829
|
existingAccessory.context.model = SwitchBotModel.BatteryCirculatorFan;
|
|
1719
|
-
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);
|
|
1720
1833
|
existingAccessory.context.connectionType = await this.connectionType(device);
|
|
1721
1834
|
existingAccessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
|
|
1722
1835
|
await this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`);
|
|
@@ -1732,14 +1845,19 @@ export class SwitchBotPlatform {
|
|
|
1732
1845
|
}
|
|
1733
1846
|
else if (await this.registerDevice(device)) {
|
|
1734
1847
|
// create a new accessory
|
|
1735
|
-
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);
|
|
1736
1851
|
// store a copy of the device object in the `accessory.context`
|
|
1737
1852
|
// the `context` property can be used to store any data about the accessory you may need
|
|
1738
1853
|
accessory.context.device = device;
|
|
1739
1854
|
accessory.context.deviceId = device.deviceId;
|
|
1740
1855
|
accessory.context.deviceType = device.deviceType;
|
|
1741
1856
|
accessory.context.model = SwitchBotModel.BatteryCirculatorFan;
|
|
1742
|
-
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);
|
|
1743
1861
|
accessory.context.connectionType = await this.connectionType(device);
|
|
1744
1862
|
accessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
|
|
1745
1863
|
const newOrExternal = !device.external ? 'Adding new' : 'Loading external';
|
|
@@ -1773,7 +1891,9 @@ export class SwitchBotPlatform {
|
|
|
1773
1891
|
: device.deviceType === 'Robot Vacuum Cleaner S10' ? SwitchBotModel.RobotVacuumCleanerS10
|
|
1774
1892
|
: device.deviceType === 'WoSweeper' ? SwitchBotModel.WoSweeper : device.deviceType === 'WoSweeperMini' ? SwitchBotModel.WoSweeperMini
|
|
1775
1893
|
: SwitchBotModel.Unknown;
|
|
1776
|
-
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);
|
|
1777
1897
|
existingAccessory.context.connectionType = await this.connectionType(device);
|
|
1778
1898
|
existingAccessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
|
|
1779
1899
|
await this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`);
|
|
@@ -1789,7 +1909,9 @@ export class SwitchBotPlatform {
|
|
|
1789
1909
|
}
|
|
1790
1910
|
else if (await this.registerDevice(device)) {
|
|
1791
1911
|
// create a new accessory
|
|
1792
|
-
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);
|
|
1793
1915
|
// store a copy of the device object in the `accessory.context`
|
|
1794
1916
|
// the `context` property can be used to store any data about the accessory you may need
|
|
1795
1917
|
accessory.context.device = device;
|
|
@@ -1800,7 +1922,10 @@ export class SwitchBotPlatform {
|
|
|
1800
1922
|
: device.deviceType === 'Robot Vacuum Cleaner S10' ? SwitchBotModel.RobotVacuumCleanerS10
|
|
1801
1923
|
: device.deviceType === 'WoSweeper' ? SwitchBotModel.WoSweeper : device.deviceType === 'WoSweeperMini' ? SwitchBotModel.WoSweeperMini
|
|
1802
1924
|
: SwitchBotModel.Unknown;
|
|
1803
|
-
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);
|
|
1804
1929
|
accessory.context.connectionType = await this.connectionType(device);
|
|
1805
1930
|
accessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
|
|
1806
1931
|
const newOrExternal = !device.external ? 'Adding new' : 'Loading external';
|
|
@@ -1828,7 +1953,9 @@ export class SwitchBotPlatform {
|
|
|
1828
1953
|
existingAccessory.context.deviceId = device.deviceId;
|
|
1829
1954
|
existingAccessory.context.deviceType = `IR: ${device.remoteType}`;
|
|
1830
1955
|
existingAccessory.context.model = device.remoteType;
|
|
1831
|
-
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);
|
|
1832
1959
|
await this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`);
|
|
1833
1960
|
existingAccessory.context.connectionType = device.connectionType;
|
|
1834
1961
|
this.api.updatePlatformAccessories([existingAccessory]);
|
|
@@ -1839,14 +1966,19 @@ export class SwitchBotPlatform {
|
|
|
1839
1966
|
}
|
|
1840
1967
|
else if (!device.hide_device && device.hubDeviceId) {
|
|
1841
1968
|
// create a new accessory
|
|
1842
|
-
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);
|
|
1843
1972
|
// store a copy of the device object in the `accessory.context`
|
|
1844
1973
|
// the `context` property can be used to store any data about the accessory you may need
|
|
1845
1974
|
accessory.context.device = device;
|
|
1846
1975
|
accessory.context.deviceId = device.deviceId;
|
|
1847
1976
|
accessory.context.deviceType = `IR: ${device.remoteType}`;
|
|
1848
1977
|
accessory.context.model = device.remoteType;
|
|
1849
|
-
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);
|
|
1850
1982
|
accessory.context.connectionType = device.connectionType;
|
|
1851
1983
|
accessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
|
|
1852
1984
|
const newOrExternal = !device.external ? 'Adding new' : 'Loading external';
|
|
@@ -1875,7 +2007,9 @@ export class SwitchBotPlatform {
|
|
|
1875
2007
|
existingAccessory.context.deviceId = device.deviceId;
|
|
1876
2008
|
existingAccessory.context.deviceType = `IR: ${device.remoteType}`;
|
|
1877
2009
|
existingAccessory.context.model = device.remoteType;
|
|
1878
|
-
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);
|
|
1879
2013
|
await this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`);
|
|
1880
2014
|
existingAccessory.context.connectionType = device.connectionType;
|
|
1881
2015
|
this.api.updatePlatformAccessories([existingAccessory]);
|
|
@@ -1890,14 +2024,19 @@ export class SwitchBotPlatform {
|
|
|
1890
2024
|
}
|
|
1891
2025
|
else if (!device.hide_device && device.hubDeviceId) {
|
|
1892
2026
|
// create a new accessory
|
|
1893
|
-
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);
|
|
1894
2030
|
// store a copy of the device object in the `accessory.context`
|
|
1895
2031
|
// the `context` property can be used to store any data about the accessory you may need
|
|
1896
2032
|
accessory.context.device = device;
|
|
1897
2033
|
accessory.context.deviceId = device.deviceId;
|
|
1898
2034
|
accessory.context.deviceType = `IR: ${device.remoteType}`;
|
|
1899
2035
|
accessory.context.model = device.remoteType;
|
|
1900
|
-
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);
|
|
1901
2040
|
accessory.context.connectionType = device.connectionType;
|
|
1902
2041
|
accessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
|
|
1903
2042
|
const newOrExternal = !device.external ? 'Adding new' : 'Loading external';
|
|
@@ -1927,7 +2066,9 @@ export class SwitchBotPlatform {
|
|
|
1927
2066
|
existingAccessory.context.deviceId = device.deviceId;
|
|
1928
2067
|
existingAccessory.context.deviceType = `IR: ${device.remoteType}`;
|
|
1929
2068
|
existingAccessory.context.model = device.remoteType;
|
|
1930
|
-
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);
|
|
1931
2072
|
await this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`);
|
|
1932
2073
|
existingAccessory.context.connectionType = device.connectionType;
|
|
1933
2074
|
this.api.updatePlatformAccessories([existingAccessory]);
|
|
@@ -1942,14 +2083,19 @@ export class SwitchBotPlatform {
|
|
|
1942
2083
|
}
|
|
1943
2084
|
else if (!device.hide_device && device.hubDeviceId) {
|
|
1944
2085
|
// create a new accessory
|
|
1945
|
-
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);
|
|
1946
2089
|
// store a copy of the device object in the `accessory.context`
|
|
1947
2090
|
// the `context` property can be used to store any data about the accessory you may need
|
|
1948
2091
|
accessory.context.device = device;
|
|
1949
2092
|
accessory.context.deviceId = device.deviceId;
|
|
1950
2093
|
accessory.context.deviceType = `IR: ${device.remoteType}`;
|
|
1951
2094
|
accessory.context.model = device.remoteType;
|
|
1952
|
-
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);
|
|
1953
2099
|
accessory.context.connectionType = device.connectionType;
|
|
1954
2100
|
accessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
|
|
1955
2101
|
const newOrExternal = !device.external ? 'Adding new' : 'Loading external';
|
|
@@ -1979,7 +2125,9 @@ export class SwitchBotPlatform {
|
|
|
1979
2125
|
existingAccessory.context.deviceId = device.deviceId;
|
|
1980
2126
|
existingAccessory.context.deviceType = `IR: ${device.remoteType}`;
|
|
1981
2127
|
existingAccessory.context.model = device.remoteType;
|
|
1982
|
-
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);
|
|
1983
2131
|
await this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`);
|
|
1984
2132
|
existingAccessory.context.connectionType = device.connectionType;
|
|
1985
2133
|
this.api.updatePlatformAccessories([existingAccessory]);
|
|
@@ -1994,14 +2142,19 @@ export class SwitchBotPlatform {
|
|
|
1994
2142
|
}
|
|
1995
2143
|
else if (!device.hide_device && device.hubDeviceId) {
|
|
1996
2144
|
// create a new accessory
|
|
1997
|
-
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);
|
|
1998
2148
|
// store a copy of the device object in the `accessory.context`
|
|
1999
2149
|
// the `context` property can be used to store any data about the accessory you may need
|
|
2000
2150
|
accessory.context.device = device;
|
|
2001
2151
|
accessory.context.deviceId = device.deviceId;
|
|
2002
2152
|
accessory.context.deviceType = `IR: ${device.remoteType}`;
|
|
2003
2153
|
accessory.context.model = device.remoteType;
|
|
2004
|
-
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);
|
|
2005
2158
|
accessory.context.connectionType = device.connectionType;
|
|
2006
2159
|
accessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
|
|
2007
2160
|
const newOrExternal = !device.external ? 'Adding new' : 'Loading external';
|
|
@@ -2031,7 +2184,9 @@ export class SwitchBotPlatform {
|
|
|
2031
2184
|
existingAccessory.context.deviceId = device.deviceId;
|
|
2032
2185
|
existingAccessory.context.deviceType = `IR: ${device.remoteType}`;
|
|
2033
2186
|
existingAccessory.context.model = device.remoteType;
|
|
2034
|
-
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);
|
|
2035
2190
|
await this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`);
|
|
2036
2191
|
existingAccessory.context.connectionType = device.connectionType;
|
|
2037
2192
|
this.api.updatePlatformAccessories([existingAccessory]);
|
|
@@ -2046,14 +2201,19 @@ export class SwitchBotPlatform {
|
|
|
2046
2201
|
}
|
|
2047
2202
|
else if (!device.hide_device && device.hubDeviceId) {
|
|
2048
2203
|
// create a new accessory
|
|
2049
|
-
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);
|
|
2050
2207
|
// store a copy of the device object in the `accessory.context`
|
|
2051
2208
|
// the `context` property can be used to store any data about the accessory you may need
|
|
2052
2209
|
accessory.context.device = device;
|
|
2053
2210
|
accessory.context.deviceId = device.deviceId;
|
|
2054
2211
|
accessory.context.deviceType = `IR: ${device.remoteType}`;
|
|
2055
2212
|
accessory.context.model = device.remoteType;
|
|
2056
|
-
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);
|
|
2057
2217
|
accessory.context.connectionType = device.connectionType;
|
|
2058
2218
|
accessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
|
|
2059
2219
|
const newOrExternal = !device.external ? 'Adding new' : 'Loading external';
|
|
@@ -2083,7 +2243,9 @@ export class SwitchBotPlatform {
|
|
|
2083
2243
|
existingAccessory.context.deviceId = device.deviceId;
|
|
2084
2244
|
existingAccessory.context.deviceType = `IR: ${device.remoteType}`;
|
|
2085
2245
|
existingAccessory.context.model = device.remoteType;
|
|
2086
|
-
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);
|
|
2087
2249
|
await this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`);
|
|
2088
2250
|
existingAccessory.context.connectionType = device.connectionType;
|
|
2089
2251
|
this.api.updatePlatformAccessories([existingAccessory]);
|
|
@@ -2098,14 +2260,19 @@ export class SwitchBotPlatform {
|
|
|
2098
2260
|
}
|
|
2099
2261
|
else if (!device.hide_device && device.hubDeviceId) {
|
|
2100
2262
|
// create a new accessory
|
|
2101
|
-
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);
|
|
2102
2266
|
// store a copy of the device object in the `accessory.context`
|
|
2103
2267
|
// the `context` property can be used to store any data about the accessory you may need
|
|
2104
2268
|
accessory.context.device = device;
|
|
2105
2269
|
accessory.context.deviceId = device.deviceId;
|
|
2106
2270
|
accessory.context.deviceType = `IR: ${device.remoteType}`;
|
|
2107
2271
|
accessory.context.model = device.remoteType;
|
|
2108
|
-
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);
|
|
2109
2276
|
accessory.context.connectionType = device.connectionType;
|
|
2110
2277
|
accessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
|
|
2111
2278
|
const newOrExternal = !device.external ? 'Adding new' : 'Loading external';
|
|
@@ -2135,7 +2302,9 @@ export class SwitchBotPlatform {
|
|
|
2135
2302
|
existingAccessory.context.deviceId = device.deviceId;
|
|
2136
2303
|
existingAccessory.context.deviceType = `IR: ${device.remoteType}`;
|
|
2137
2304
|
existingAccessory.context.model = device.remoteType;
|
|
2138
|
-
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);
|
|
2139
2308
|
await this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`);
|
|
2140
2309
|
existingAccessory.context.connectionType = device.connectionType;
|
|
2141
2310
|
this.api.updatePlatformAccessories([existingAccessory]);
|
|
@@ -2150,14 +2319,19 @@ export class SwitchBotPlatform {
|
|
|
2150
2319
|
}
|
|
2151
2320
|
else if (!device.hide_device && device.hubDeviceId) {
|
|
2152
2321
|
// create a new accessory
|
|
2153
|
-
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);
|
|
2154
2325
|
// store a copy of the device object in the `accessory.context`
|
|
2155
2326
|
// the `context` property can be used to store any data about the accessory you may need
|
|
2156
2327
|
accessory.context.device = device;
|
|
2157
2328
|
accessory.context.deviceId = device.deviceId;
|
|
2158
2329
|
accessory.context.deviceType = `IR: ${device.remoteType}`;
|
|
2159
2330
|
accessory.context.model = device.remoteType;
|
|
2160
|
-
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);
|
|
2161
2335
|
accessory.context.connectionType = device.connectionType;
|
|
2162
2336
|
accessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
|
|
2163
2337
|
const newOrExternal = !device.external ? 'Adding new' : 'Loading external';
|
|
@@ -2187,7 +2361,9 @@ export class SwitchBotPlatform {
|
|
|
2187
2361
|
existingAccessory.context.deviceId = device.deviceId;
|
|
2188
2362
|
existingAccessory.context.deviceType = `IR: ${device.remoteType}`;
|
|
2189
2363
|
existingAccessory.context.model = device.remoteType;
|
|
2190
|
-
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);
|
|
2191
2367
|
await this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`);
|
|
2192
2368
|
existingAccessory.context.connectionType = device.connectionType;
|
|
2193
2369
|
this.api.updatePlatformAccessories([existingAccessory]);
|
|
@@ -2202,14 +2378,19 @@ export class SwitchBotPlatform {
|
|
|
2202
2378
|
}
|
|
2203
2379
|
else if (!device.hide_device && device.hubDeviceId) {
|
|
2204
2380
|
// create a new accessory
|
|
2205
|
-
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);
|
|
2206
2384
|
// store a copy of the device object in the `accessory.context`
|
|
2207
2385
|
// the `context` property can be used to store any data about the accessory you may need
|
|
2208
2386
|
accessory.context.device = device;
|
|
2209
2387
|
accessory.context.deviceId = device.deviceId;
|
|
2210
2388
|
accessory.context.deviceType = `IR: ${device.remoteType}`;
|
|
2211
2389
|
accessory.context.model = device.remoteType;
|
|
2212
|
-
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);
|
|
2213
2394
|
accessory.context.connectionType = device.connectionType;
|
|
2214
2395
|
accessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
|
|
2215
2396
|
const newOrExternal = !device.external ? 'Adding new' : 'Loading external';
|
|
@@ -2239,7 +2420,9 @@ export class SwitchBotPlatform {
|
|
|
2239
2420
|
existingAccessory.context.deviceId = device.deviceId;
|
|
2240
2421
|
existingAccessory.context.deviceType = `IR: ${device.remoteType}`;
|
|
2241
2422
|
existingAccessory.context.model = device.remoteType;
|
|
2242
|
-
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);
|
|
2243
2426
|
await this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`);
|
|
2244
2427
|
existingAccessory.context.connectionType = device.connectionType;
|
|
2245
2428
|
this.api.updatePlatformAccessories([existingAccessory]);
|
|
@@ -2254,14 +2437,19 @@ export class SwitchBotPlatform {
|
|
|
2254
2437
|
}
|
|
2255
2438
|
else if (!device.hide_device && device.hubDeviceId) {
|
|
2256
2439
|
// create a new accessory
|
|
2257
|
-
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);
|
|
2258
2443
|
// store a copy of the device object in the `accessory.context`
|
|
2259
2444
|
// the `context` property can be used to store any data about the accessory you may need
|
|
2260
2445
|
accessory.context.device = device;
|
|
2261
2446
|
accessory.context.deviceId = device.deviceId;
|
|
2262
2447
|
accessory.context.deviceType = `IR: ${device.remoteType}`;
|
|
2263
2448
|
accessory.context.model = device.remoteType;
|
|
2264
|
-
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);
|
|
2265
2453
|
accessory.context.connectionType = device.connectionType;
|
|
2266
2454
|
accessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
|
|
2267
2455
|
const newOrExternal = !device.external ? 'Adding new' : 'Loading external';
|
|
@@ -2624,7 +2812,7 @@ export class SwitchBotPlatform {
|
|
|
2624
2812
|
}
|
|
2625
2813
|
}
|
|
2626
2814
|
async getPlatformLogSettings() {
|
|
2627
|
-
this.debugMode = process.argv.includes('-D')
|
|
2815
|
+
this.debugMode = process.argv.includes('-D') ?? process.argv.includes('--debug');
|
|
2628
2816
|
if (this.config.options?.logging === 'debug' || this.config.options?.logging === 'standard' || this.config.options?.logging === 'none') {
|
|
2629
2817
|
this.platformLogging = this.config.options.logging;
|
|
2630
2818
|
await this.debugWarnLog(`Using Config Logging: ${this.platformLogging}`);
|
|
@@ -2638,6 +2826,34 @@ export class SwitchBotPlatform {
|
|
|
2638
2826
|
await this.debugWarnLog(`Using ${this.platformLogging} Logging`);
|
|
2639
2827
|
}
|
|
2640
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
|
+
}
|
|
2641
2857
|
/**
|
|
2642
2858
|
* If device level logging is turned on, log to log.warn
|
|
2643
2859
|
* Otherwise send debug logs to log.debug
|
|
@@ -2654,7 +2870,7 @@ export class SwitchBotPlatform {
|
|
|
2654
2870
|
}
|
|
2655
2871
|
async debugSuccessLog(...log) {
|
|
2656
2872
|
if (await this.enablingPlatformLogging()) {
|
|
2657
|
-
if (this.
|
|
2873
|
+
if (await this.loggingIsDebug()) {
|
|
2658
2874
|
this.log.success('[DEBUG]', String(...log));
|
|
2659
2875
|
}
|
|
2660
2876
|
}
|
|
@@ -2666,7 +2882,7 @@ export class SwitchBotPlatform {
|
|
|
2666
2882
|
}
|
|
2667
2883
|
async debugWarnLog(...log) {
|
|
2668
2884
|
if (await this.enablingPlatformLogging()) {
|
|
2669
|
-
if (this.
|
|
2885
|
+
if (await this.loggingIsDebug()) {
|
|
2670
2886
|
this.log.warn('[DEBUG]', String(...log));
|
|
2671
2887
|
}
|
|
2672
2888
|
}
|
|
@@ -2678,23 +2894,26 @@ export class SwitchBotPlatform {
|
|
|
2678
2894
|
}
|
|
2679
2895
|
async debugErrorLog(...log) {
|
|
2680
2896
|
if (await this.enablingPlatformLogging()) {
|
|
2681
|
-
if (this.
|
|
2897
|
+
if (await this.loggingIsDebug()) {
|
|
2682
2898
|
this.log.error('[DEBUG]', String(...log));
|
|
2683
2899
|
}
|
|
2684
2900
|
}
|
|
2685
2901
|
}
|
|
2686
2902
|
async debugLog(...log) {
|
|
2687
2903
|
if (await this.enablingPlatformLogging()) {
|
|
2688
|
-
if (this.platformLogging === '
|
|
2689
|
-
this.log.debug(String(...log));
|
|
2690
|
-
}
|
|
2691
|
-
else if (this.platformLogging === 'debug') {
|
|
2904
|
+
if (this.platformLogging === 'debug') {
|
|
2692
2905
|
this.log.info('[DEBUG]', String(...log));
|
|
2693
2906
|
}
|
|
2907
|
+
else if (this.platformLogging === 'debugMode') {
|
|
2908
|
+
this.log.debug(String(...log));
|
|
2909
|
+
}
|
|
2694
2910
|
}
|
|
2695
2911
|
}
|
|
2912
|
+
async loggingIsDebug() {
|
|
2913
|
+
return this.platformLogging === 'debugMode' || this.platformLogging === 'debug';
|
|
2914
|
+
}
|
|
2696
2915
|
async enablingPlatformLogging() {
|
|
2697
|
-
return this.platformLogging
|
|
2916
|
+
return this.platformLogging === 'debugMode' || this.platformLogging === 'debug' || this.platformLogging === 'standard';
|
|
2698
2917
|
}
|
|
2699
2918
|
}
|
|
2700
2919
|
//# sourceMappingURL=platform.js.map
|