@switchbot/homebridge-switchbot 3.5.1-beta.18 → 3.5.1-beta.19

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.
Files changed (71) hide show
  1. package/dist/device/blindtilt.js +8 -8
  2. package/dist/device/blindtilt.js.map +1 -1
  3. package/dist/device/bot.js +2 -2
  4. package/dist/device/bot.js.map +1 -1
  5. package/dist/device/ceilinglight.js +2 -2
  6. package/dist/device/ceilinglight.js.map +1 -1
  7. package/dist/device/colorbulb.js +2 -2
  8. package/dist/device/colorbulb.js.map +1 -1
  9. package/dist/device/contact.js +2 -2
  10. package/dist/device/contact.js.map +1 -1
  11. package/dist/device/curtain.js +2 -2
  12. package/dist/device/curtain.js.map +1 -1
  13. package/dist/device/device.d.ts.map +1 -1
  14. package/dist/device/device.js +4 -26
  15. package/dist/device/device.js.map +1 -1
  16. package/dist/device/fan.js +6 -6
  17. package/dist/device/fan.js.map +1 -1
  18. package/dist/device/hub.js +2 -2
  19. package/dist/device/hub.js.map +1 -1
  20. package/dist/device/humidifier.js +2 -2
  21. package/dist/device/humidifier.js.map +1 -1
  22. package/dist/device/iosensor.js +2 -2
  23. package/dist/device/iosensor.js.map +1 -1
  24. package/dist/device/lightstrip.js +2 -2
  25. package/dist/device/lightstrip.js.map +1 -1
  26. package/dist/device/lock.js +2 -2
  27. package/dist/device/lock.js.map +1 -1
  28. package/dist/device/meter.js +2 -2
  29. package/dist/device/meter.js.map +1 -1
  30. package/dist/device/meterplus.js +2 -2
  31. package/dist/device/meterplus.js.map +1 -1
  32. package/dist/device/motion.js +2 -2
  33. package/dist/device/motion.js.map +1 -1
  34. package/dist/device/plug.js +2 -2
  35. package/dist/device/plug.js.map +1 -1
  36. package/dist/device/robotvacuumcleaner.js +2 -2
  37. package/dist/device/robotvacuumcleaner.js.map +1 -1
  38. package/dist/device/waterdetector.js +2 -2
  39. package/dist/device/waterdetector.js.map +1 -1
  40. package/dist/homebridge-ui/public/index.html +2 -2
  41. package/dist/irdevice/airconditioner.js +2 -2
  42. package/dist/irdevice/irdevice.d.ts.map +1 -1
  43. package/dist/irdevice/irdevice.js +3 -31
  44. package/dist/irdevice/irdevice.js.map +1 -1
  45. package/dist/platform.d.ts.map +1 -1
  46. package/dist/platform.js +396 -498
  47. package/dist/platform.js.map +1 -1
  48. package/package.json +1 -1
  49. package/src/device/blindtilt.ts +8 -8
  50. package/src/device/bot.ts +2 -2
  51. package/src/device/ceilinglight.ts +2 -2
  52. package/src/device/colorbulb.ts +2 -2
  53. package/src/device/contact.ts +2 -2
  54. package/src/device/curtain.ts +2 -2
  55. package/src/device/device.ts +4 -22
  56. package/src/device/fan.ts +6 -6
  57. package/src/device/hub.ts +2 -2
  58. package/src/device/humidifier.ts +2 -2
  59. package/src/device/iosensor.ts +2 -2
  60. package/src/device/lightstrip.ts +2 -2
  61. package/src/device/lock.ts +2 -2
  62. package/src/device/meter.ts +2 -2
  63. package/src/device/meterplus.ts +2 -2
  64. package/src/device/motion.ts +2 -2
  65. package/src/device/plug.ts +2 -2
  66. package/src/device/robotvacuumcleaner.ts +2 -2
  67. package/src/device/waterdetector.ts +2 -2
  68. package/src/homebridge-ui/public/index.html +2 -2
  69. package/src/irdevice/airconditioner.ts +2 -2
  70. package/src/irdevice/irdevice.ts +3 -26
  71. package/src/platform.ts +397 -528
package/src/platform.ts CHANGED
@@ -51,6 +51,7 @@ import type { blindTilt, curtain, curtain3, device } from './types/devicelist.js
51
51
  import type { API, DynamicPlatformPlugin, Logging, PlatformAccessory } from 'homebridge';
52
52
  import type { SwitchBotPlatformConfig, devicesConfig, irDevicesConfig } from './settings.js';
53
53
  import type { IncomingMessage, Server, ServerResponse } from 'http';
54
+ import { SwitchBotModel } from 'node-switchbot';
54
55
 
55
56
  /**
56
57
  * HomebridgePlatform
@@ -836,15 +837,14 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
836
837
  // the accessory already exists
837
838
  if (await this.registerDevice(device)) {
838
839
  // if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
839
- existingAccessory.context.model = device.deviceType;
840
- existingAccessory.context.deviceID = device.deviceId;
841
- existingAccessory.displayName = device.configDeviceName || device.deviceName;
842
- if (device.firmware) {
843
- existingAccessory.context.version = device.firmware;
844
- }
845
- existingAccessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
846
- this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
840
+ existingAccessory.context.device = device;
841
+ existingAccessory.context.deviceId = device.deviceId;
842
+ existingAccessory.context.deviceType = device.deviceType;
843
+ existingAccessory.context.model = SwitchBotModel.Humidifier;
844
+ existingAccessory.displayName = device.configDeviceName ?? device.deviceName;
847
845
  existingAccessory.context.connectionType = await this.connectionType(device);
846
+ existingAccessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
847
+ await this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`);
848
848
  this.api.updatePlatformAccessories([existingAccessory]);
849
849
  // create the accessory handler for the restored accessory
850
850
  // this is imported from `platformAccessory.ts`
@@ -854,24 +854,20 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
854
854
  this.unregisterPlatformAccessories(existingAccessory);
855
855
  }
856
856
  } else if (await this.registerDevice(device)) {
857
- // the accessory does not yet exist, so we need to create it
858
- if (!device.external) {
859
- this.infoLog(`Adding new accessory: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
860
- }
861
-
862
857
  // create a new accessory
863
858
  const accessory = new this.api.platformAccessory(device.deviceName, uuid);
864
859
 
865
860
  // store a copy of the device object in the `accessory.context`
866
861
  // the `context` property can be used to store any data about the accessory you may need
867
862
  accessory.context.device = device;
868
- accessory.context.model = device.deviceType;
869
- accessory.context.deviceID = device.deviceId;
870
- if (device.firmware) {
871
- accessory.context.version = device.firmware;
872
- }
873
- accessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
863
+ accessory.context.deviceId = device.deviceId;
864
+ accessory.context.deviceType = device.deviceType;
865
+ accessory.context.model = SwitchBotModel.Humidifier;
866
+ accessory.displayName = device.configDeviceName ?? device.deviceName;
874
867
  accessory.context.connectionType = await this.connectionType(device);
868
+ accessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
869
+ const newOrExternal = !device.external ? 'Adding new' : 'Loading external';
870
+ await this.infoLog(`${newOrExternal} accessory: ${accessory.displayName} deviceId: ${device.deviceId}`);
875
871
  // create the accessory handler for the newly create accessory
876
872
  // this is imported from `platformAccessory.ts`
877
873
  new Humidifier(this, accessory, device);
@@ -881,7 +877,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
881
877
  this.externalOrPlatform(device, accessory);
882
878
  this.accessories.push(accessory);
883
879
  } else {
884
- await this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
880
+ await this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} deviceId: ${device.deviceId}`);
885
881
  }
886
882
  }
887
883
 
@@ -896,15 +892,14 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
896
892
  // the accessory already exists
897
893
  if (await this.registerDevice(device)) {
898
894
  // if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
899
- existingAccessory.context.model = device.deviceType;
900
- existingAccessory.context.deviceID = device.deviceId;
901
- existingAccessory.displayName = device.configDeviceName || device.deviceName;
902
- if (device.firmware) {
903
- existingAccessory.context.version = device.firmware;
904
- }
905
- existingAccessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
906
- this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
895
+ existingAccessory.context.device = device;
896
+ existingAccessory.context.deviceId = device.deviceId;
897
+ existingAccessory.context.deviceType = device.deviceType;
898
+ existingAccessory.context.model = SwitchBotModel.Bot;
899
+ existingAccessory.displayName = device.configDeviceName ?? device.deviceName;
907
900
  existingAccessory.context.connectionType = await this.connectionType(device);
901
+ existingAccessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
902
+ this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`);
908
903
  this.api.updatePlatformAccessories([existingAccessory]);
909
904
  // create the accessory handler for the restored accessory
910
905
  // this is imported from `platformAccessory.ts`
@@ -914,24 +909,20 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
914
909
  this.unregisterPlatformAccessories(existingAccessory);
915
910
  }
916
911
  } else if (await this.registerDevice(device)) {
917
- // the accessory does not yet exist, so we need to create it
918
- if (!device.external) {
919
- this.infoLog(`Adding new accessory: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
920
- }
921
-
922
912
  // create a new accessory
923
913
  const accessory = new this.api.platformAccessory(device.deviceName, uuid);
924
914
 
925
915
  // store a copy of the device object in the `accessory.context`
926
916
  // the `context` property can be used to store any data about the accessory you may need
927
917
  accessory.context.device = device;
928
- accessory.context.model = device.deviceType;
929
- accessory.context.deviceID = device.deviceId;
930
- if (device.firmware) {
931
- accessory.context.version = device.firmware;
932
- }
933
- accessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
918
+ accessory.context.deviceId = device.deviceId;
919
+ accessory.context.deviceType = device.deviceType;
920
+ accessory.context.model = SwitchBotModel.Bot;
921
+ accessory.displayName = device.configDeviceName ?? device.deviceName;
934
922
  accessory.context.connectionType = await this.connectionType(device);
923
+ accessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
924
+ const newOrExternal = !device.external ? 'Adding new' : 'Loading external';
925
+ await this.infoLog(`${newOrExternal} accessory: ${accessory.displayName} deviceId: ${device.deviceId}`);
935
926
  // accessory.context.version = findaccessories.accessoryAttribute.softwareRevision;
936
927
  // create the accessory handler for the newly create accessory
937
928
  // this is imported from `platformAccessory.ts`
@@ -942,7 +933,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
942
933
  this.externalOrPlatform(device, accessory);
943
934
  this.accessories.push(accessory);
944
935
  } else {
945
- await this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
936
+ await this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} deviceId: ${device.deviceId}`);
946
937
  }
947
938
  }
948
939
 
@@ -957,15 +948,14 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
957
948
  // the accessory already exists
958
949
  if (await this.registerDevice(device)) {
959
950
  // if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
960
- existingAccessory.context.model = device.deviceType;
961
- existingAccessory.context.deviceID = device.deviceId;
962
- existingAccessory.displayName = device.configDeviceName || device.deviceName;
963
- if (device.firmware) {
964
- existingAccessory.context.version = device.firmware;
965
- }
966
- existingAccessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
967
- this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
951
+ existingAccessory.context.device = device;
952
+ existingAccessory.context.model = SwitchBotModel.Meter;
953
+ existingAccessory.context.deviceId = device.deviceId;
954
+ existingAccessory.context.deviceType = device.deviceType;
955
+ existingAccessory.displayName = device.configDeviceName ?? device.deviceName;
968
956
  existingAccessory.context.connectionType = await this.connectionType(device);
957
+ existingAccessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
958
+ this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`);
969
959
  this.api.updatePlatformAccessories([existingAccessory]);
970
960
  // create the accessory handler for the restored accessory
971
961
  // this is imported from `platformAccessory.ts`
@@ -975,24 +965,20 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
975
965
  this.unregisterPlatformAccessories(existingAccessory);
976
966
  }
977
967
  } else if (await this.registerDevice(device)) {
978
- // the accessory does not yet exist, so we need to create it
979
- if (!device.external) {
980
- this.infoLog(`Adding new accessory: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
981
- }
982
-
983
968
  // create a new accessory
984
969
  const accessory = new this.api.platformAccessory(device.deviceName, uuid);
985
970
 
986
971
  // store a copy of the device object in the `accessory.context`
987
972
  // the `context` property can be used to store any data about the accessory you may need
988
973
  accessory.context.device = device;
989
- accessory.context.model = device.deviceType;
990
- accessory.context.deviceID = device.deviceId;
991
- if (device.firmware) {
992
- accessory.context.version = device.firmware;
993
- }
994
- accessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
974
+ accessory.context.model = SwitchBotModel.Meter;
975
+ accessory.context.deviceId = device.deviceId;
976
+ accessory.context.deviceType = device.deviceType;
977
+ accessory.displayName = device.configDeviceName ?? device.deviceName;
995
978
  accessory.context.connectionType = await this.connectionType(device);
979
+ accessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
980
+ const newOrExternal = !device.external ? 'Adding new' : 'Loading external';
981
+ await this.infoLog(`${newOrExternal} accessory: ${accessory.displayName} deviceId: ${device.deviceId}`);
996
982
  // create the accessory handler for the newly create accessory
997
983
  // this is imported from `platformAccessory.ts`
998
984
  new Meter(this, accessory, device);
@@ -1002,7 +988,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
1002
988
  this.externalOrPlatform(device, accessory);
1003
989
  this.accessories.push(accessory);
1004
990
  } else {
1005
- await this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
991
+ await this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} deviceId: ${device.deviceId}`);
1006
992
  }
1007
993
  }
1008
994
 
@@ -1018,15 +1004,14 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
1018
1004
  if (await this.registerDevice(device)) {
1019
1005
  // console.log("existingAccessory", existingAccessory);
1020
1006
  // if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
1021
- existingAccessory.context.model = device.deviceType;
1022
- existingAccessory.context.deviceID = device.deviceId;
1023
- existingAccessory.displayName = device.configDeviceName || device.deviceName;
1024
- if (device.firmware) {
1025
- existingAccessory.context.version = device.firmware;
1026
- }
1027
- existingAccessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
1028
- this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
1007
+ existingAccessory.context.device = device;
1008
+ existingAccessory.context.model = SwitchBotModel.MeterPlusUS ?? SwitchBotModel.MeterPlusJP;
1009
+ existingAccessory.context.deviceId = device.deviceId;
1010
+ existingAccessory.context.deviceType = device.deviceType;
1011
+ existingAccessory.displayName = device.configDeviceName ?? device.deviceName;
1029
1012
  existingAccessory.context.connectionType = await this.connectionType(device);
1013
+ existingAccessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
1014
+ this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`);
1030
1015
  this.api.updatePlatformAccessories([existingAccessory]);
1031
1016
  // create the accessory handler for the restored accessory
1032
1017
  // this is imported from `platformAccessory.ts`
@@ -1036,24 +1021,20 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
1036
1021
  this.unregisterPlatformAccessories(existingAccessory);
1037
1022
  }
1038
1023
  } else if (await this.registerDevice(device)) {
1039
- // the accessory does not yet exist, so we need to create it
1040
- if (!device.external) {
1041
- this.infoLog(`Adding new accessory: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
1042
- }
1043
-
1044
1024
  // create a new accessory
1045
1025
  const accessory = new this.api.platformAccessory(device.deviceName, uuid);
1046
1026
 
1047
1027
  // store a copy of the device object in the `accessory.context`
1048
1028
  // the `context` property can be used to store any data about the accessory you may need
1049
1029
  accessory.context.device = device;
1050
- accessory.context.model = device.deviceType;
1051
- accessory.context.deviceID = device.deviceId;
1052
- if (device.firmware) {
1053
- accessory.context.version = device.firmware;
1054
- }
1055
- accessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
1030
+ accessory.context.model = SwitchBotModel.MeterPlusUS ?? SwitchBotModel.MeterPlusJP;
1031
+ accessory.context.deviceId = device.deviceId;
1032
+ accessory.context.deviceType = device.deviceType;
1033
+ accessory.displayName = device.configDeviceName ?? device.deviceName;
1056
1034
  accessory.context.connectionType = await this.connectionType(device);
1035
+ accessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
1036
+ const newOrExternal = !device.external ? 'Adding new' : 'Loading external';
1037
+ await this.infoLog(`${newOrExternal} accessory: ${accessory.displayName} deviceId: ${device.deviceId}`);
1057
1038
  // create the accessory handler for the newly create accessory
1058
1039
  // this is imported from `platformAccessory.ts`
1059
1040
  new MeterPlus(this, accessory, device);
@@ -1063,7 +1044,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
1063
1044
  this.externalOrPlatform(device, accessory);
1064
1045
  this.accessories.push(accessory);
1065
1046
  } else {
1066
- await this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
1047
+ await this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} deviceId: ${device.deviceId}`);
1067
1048
  }
1068
1049
  }
1069
1050
 
@@ -1079,15 +1060,14 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
1079
1060
  if (await this.registerDevice(device)) {
1080
1061
  // console.log("existingAccessory", existingAccessory);
1081
1062
  // if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
1082
- existingAccessory.context.model = device.deviceType;
1083
- existingAccessory.context.deviceID = device.deviceId;
1084
- existingAccessory.displayName = device.configDeviceName || device.deviceName;
1085
- if (device.firmware) {
1086
- existingAccessory.context.version = device.firmware;
1087
- }
1088
- existingAccessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
1089
- this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
1063
+ existingAccessory.context.device = device;
1064
+ existingAccessory.context.model = SwitchBotModel.Hub2;
1065
+ existingAccessory.context.deviceId = device.deviceId;
1066
+ existingAccessory.context.deviceType = device.deviceType;
1067
+ existingAccessory.displayName = device.configDeviceName ?? device.deviceName;
1090
1068
  existingAccessory.context.connectionType = await this.connectionType(device);
1069
+ existingAccessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
1070
+ this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`);
1091
1071
  this.api.updatePlatformAccessories([existingAccessory]);
1092
1072
  // create the accessory handler for the restored accessory
1093
1073
  // this is imported from `platformAccessory.ts`
@@ -1097,24 +1077,20 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
1097
1077
  this.unregisterPlatformAccessories(existingAccessory);
1098
1078
  }
1099
1079
  } else if (await this.registerDevice(device)) {
1100
- // the accessory does not yet exist, so we need to create it
1101
- if (!device.external) {
1102
- this.infoLog(`Adding new accessory: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
1103
- }
1104
-
1105
1080
  // create a new accessory
1106
1081
  const accessory = new this.api.platformAccessory(device.deviceName, uuid);
1107
1082
 
1108
1083
  // store a copy of the device object in the `accessory.context`
1109
1084
  // the `context` property can be used to store any data about the accessory you may need
1110
1085
  accessory.context.device = device;
1111
- accessory.context.model = device.deviceType;
1112
- accessory.context.deviceID = device.deviceId;
1113
- if (device.firmware) {
1114
- accessory.context.version = device.firmware;
1115
- }
1116
- accessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
1086
+ accessory.context.model = SwitchBotModel.Hub2;
1087
+ accessory.context.deviceId = device.deviceId;
1088
+ accessory.context.deviceType = device.deviceType;
1089
+ accessory.displayName = device.configDeviceName ?? device.deviceName;
1117
1090
  accessory.context.connectionType = await this.connectionType(device);
1091
+ accessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
1092
+ const newOrExternal = !device.external ? 'Adding new' : 'Loading external';
1093
+ await this.infoLog(`${newOrExternal} accessory: ${accessory.displayName} deviceId: ${device.deviceId}`);
1118
1094
  // create the accessory handler for the newly create accessory
1119
1095
  // this is imported from `platformAccessory.ts`
1120
1096
  new Hub(this, accessory, device);
@@ -1124,7 +1100,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
1124
1100
  this.externalOrPlatform(device, accessory);
1125
1101
  this.accessories.push(accessory);
1126
1102
  } else {
1127
- await this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
1103
+ await this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} deviceId: ${device.deviceId}`);
1128
1104
  }
1129
1105
  }
1130
1106
 
@@ -1139,15 +1115,14 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
1139
1115
  // the accessory already exists
1140
1116
  if (await this.registerDevice(device)) {
1141
1117
  // if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
1142
- existingAccessory.context.model = device.deviceType;
1143
- existingAccessory.context.deviceID = device.deviceId;
1144
- existingAccessory.displayName = device.configDeviceName || device.deviceName;
1145
- if (device.firmware) {
1146
- existingAccessory.context.version = device.firmware;
1147
- }
1148
- existingAccessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
1149
- this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
1118
+ existingAccessory.context.device = device;
1119
+ existingAccessory.context.model = SwitchBotModel.OutdoorMeter;
1120
+ existingAccessory.context.deviceId = device.deviceId;
1121
+ existingAccessory.context.deviceType = device.deviceType;
1122
+ existingAccessory.displayName = device.configDeviceName ?? device.deviceName;
1150
1123
  existingAccessory.context.connectionType = await this.connectionType(device);
1124
+ existingAccessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
1125
+ await this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`);
1151
1126
  this.api.updatePlatformAccessories([existingAccessory]);
1152
1127
  // create the accessory handler for the restored accessory
1153
1128
  // this is imported from `platformAccessory.ts`
@@ -1157,24 +1132,20 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
1157
1132
  this.unregisterPlatformAccessories(existingAccessory);
1158
1133
  }
1159
1134
  } else if (await this.registerDevice(device)) {
1160
- // the accessory does not yet exist, so we need to create it
1161
- if (!device.external) {
1162
- this.infoLog(`Adding new accessory: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
1163
- }
1164
-
1165
1135
  // create a new accessory
1166
1136
  const accessory = new this.api.platformAccessory(device.deviceName, uuid);
1167
1137
 
1168
1138
  // store a copy of the device object in the `accessory.context`
1169
1139
  // the `context` property can be used to store any data about the accessory you may need
1170
1140
  accessory.context.device = device;
1171
- accessory.context.model = device.deviceType;
1172
- accessory.context.deviceID = device.deviceId;
1173
- if (device.firmware) {
1174
- accessory.context.version = device.firmware;
1175
- }
1176
- accessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
1141
+ accessory.context.model = SwitchBotModel.OutdoorMeter;
1142
+ accessory.context.deviceId = device.deviceId;
1143
+ accessory.context.deviceType = device.deviceType;
1144
+ accessory.displayName = device.configDeviceName ?? device.deviceName;
1177
1145
  accessory.context.connectionType = await this.connectionType(device);
1146
+ accessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
1147
+ const newOrExternal = !device.external ? 'Adding new' : 'Loading external';
1148
+ await this.infoLog(`${newOrExternal} accessory: ${accessory.displayName} deviceId: ${device.deviceId}`);
1178
1149
  // create the accessory handler for the newly create accessory
1179
1150
  // this is imported from `platformAccessory.ts`
1180
1151
  new IOSensor(this, accessory, device);
@@ -1184,7 +1155,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
1184
1155
  this.externalOrPlatform(device, accessory);
1185
1156
  this.accessories.push(accessory);
1186
1157
  } else {
1187
- await this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
1158
+ await this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} deviceId: ${device.deviceId}`);
1188
1159
  }
1189
1160
  }
1190
1161
 
@@ -1199,15 +1170,14 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
1199
1170
  // the accessory already exists
1200
1171
  if (await this.registerDevice(device)) {
1201
1172
  // if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
1202
- existingAccessory.context.model = device.deviceType;
1203
- existingAccessory.context.deviceID = device.deviceId;
1204
- existingAccessory.displayName = device.configDeviceName || device.deviceName;
1205
- if (device.firmware) {
1206
- existingAccessory.context.version = device.firmware;
1207
- }
1208
- existingAccessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
1209
- this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
1173
+ existingAccessory.context.device = device;
1174
+ existingAccessory.context.deviceId = device.deviceId;
1175
+ existingAccessory.context.deviceType = device.deviceType;
1176
+ existingAccessory.context.model = SwitchBotModel.WaterDetector;
1177
+ existingAccessory.displayName = device.configDeviceName ?? device.deviceName;
1210
1178
  existingAccessory.context.connectionType = await this.connectionType(device);
1179
+ existingAccessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
1180
+ this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`);
1211
1181
  this.api.updatePlatformAccessories([existingAccessory]);
1212
1182
  // create the accessory handler for the restored accessory
1213
1183
  // this is imported from `platformAccessory.ts`
@@ -1217,24 +1187,20 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
1217
1187
  this.unregisterPlatformAccessories(existingAccessory);
1218
1188
  }
1219
1189
  } else if (await this.registerDevice(device)) {
1220
- // the accessory does not yet exist, so we need to create it
1221
- if (!device.external) {
1222
- this.infoLog(`Adding new accessory: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
1223
- }
1224
-
1225
1190
  // create a new accessory
1226
1191
  const accessory = new this.api.platformAccessory(device.deviceName, uuid);
1227
1192
 
1228
1193
  // store a copy of the device object in the `accessory.context`
1229
1194
  // the `context` property can be used to store any data about the accessory you may need
1230
1195
  accessory.context.device = device;
1231
- accessory.context.model = device.deviceType;
1232
- accessory.context.deviceID = device.deviceId;
1233
- if (device.firmware) {
1234
- accessory.context.version = device.firmware;
1235
- }
1236
- accessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
1196
+ accessory.context.deviceId = device.deviceId;
1197
+ accessory.context.deviceType = device.deviceType;
1198
+ accessory.context.model = SwitchBotModel.WaterDetector;
1199
+ accessory.displayName = device.configDeviceName ?? device.deviceName;
1200
+ accessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
1237
1201
  accessory.context.connectionType = await this.connectionType(device);
1202
+ const newOrExternal = !device.external ? 'Adding new' : 'Loading external';
1203
+ await this.infoLog(`${newOrExternal} accessory: ${accessory.displayName} deviceId: ${device.deviceId}`);
1238
1204
  // create the accessory handler for the newly create accessory
1239
1205
  // this is imported from `platformAccessory.ts`
1240
1206
  new WaterDetector(this, accessory, device);
@@ -1244,7 +1210,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
1244
1210
  this.externalOrPlatform(device, accessory);
1245
1211
  this.accessories.push(accessory);
1246
1212
  } else {
1247
- await this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
1213
+ await this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} deviceId: ${device.deviceId}`);
1248
1214
  }
1249
1215
  }
1250
1216
 
@@ -1259,15 +1225,14 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
1259
1225
  // the accessory already exists
1260
1226
  if (await this.registerDevice(device)) {
1261
1227
  // if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
1262
- existingAccessory.context.model = device.deviceType;
1263
- existingAccessory.context.deviceID = device.deviceId;
1264
- existingAccessory.displayName = device.configDeviceName || device.deviceName;
1265
- if (device.firmware) {
1266
- existingAccessory.context.version = device.firmware;
1267
- }
1268
- existingAccessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
1269
- this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
1228
+ existingAccessory.context.device = device;
1229
+ existingAccessory.context.deviceId = device.deviceId;
1230
+ existingAccessory.context.deviceType = device.deviceType;
1231
+ existingAccessory.context.model = SwitchBotModel.MotionSensor;
1232
+ existingAccessory.displayName = device.configDeviceName ?? device.deviceName;
1270
1233
  existingAccessory.context.connectionType = await this.connectionType(device);
1234
+ existingAccessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
1235
+ this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`);
1271
1236
  this.api.updatePlatformAccessories([existingAccessory]);
1272
1237
  // create the accessory handler for the restored accessory
1273
1238
  // this is imported from `platformAccessory.ts`
@@ -1277,24 +1242,20 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
1277
1242
  this.unregisterPlatformAccessories(existingAccessory);
1278
1243
  }
1279
1244
  } else if (await this.registerDevice(device)) {
1280
- // the accessory does not yet exist, so we need to create it
1281
- if (!device.external) {
1282
- this.infoLog(`Adding new accessory: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
1283
- }
1284
-
1285
1245
  // create a new accessory
1286
1246
  const accessory = new this.api.platformAccessory(device.deviceName, uuid);
1287
1247
 
1288
1248
  // store a copy of the device object in the `accessory.context`
1289
1249
  // the `context` property can be used to store any data about the accessory you may need
1290
1250
  accessory.context.device = device;
1291
- accessory.context.model = device.deviceType;
1292
- accessory.context.deviceID = device.deviceId;
1293
- if (device.firmware) {
1294
- accessory.context.version = device.firmware;
1295
- }
1296
- accessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
1251
+ accessory.context.deviceId = device.deviceId;
1252
+ accessory.context.deviceType = device.deviceType;
1253
+ accessory.context.model = SwitchBotModel.MotionSensor;
1254
+ accessory.displayName = device.configDeviceName ?? device.deviceName;
1297
1255
  accessory.context.connectionType = await this.connectionType(device);
1256
+ accessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
1257
+ const newOrExternal = !device.external ? 'Adding new' : 'Loading external';
1258
+ await this.infoLog(`${newOrExternal} accessory: ${accessory.displayName} deviceId: ${device.deviceId}`);
1298
1259
  // create the accessory handler for the newly create accessory
1299
1260
  // this is imported from `platformAccessory.ts`
1300
1261
  new Motion(this, accessory, device);
@@ -1304,7 +1265,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
1304
1265
  this.externalOrPlatform(device, accessory);
1305
1266
  this.accessories.push(accessory);
1306
1267
  } else {
1307
- await this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
1268
+ await this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} deviceId: ${device.deviceId}`);
1308
1269
  }
1309
1270
  }
1310
1271
 
@@ -1319,15 +1280,14 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
1319
1280
  // the accessory already exists
1320
1281
  if (await this.registerDevice(device)) {
1321
1282
  // if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
1322
- existingAccessory.context.model = device.deviceType;
1323
- existingAccessory.context.deviceID = device.deviceId;
1324
- existingAccessory.displayName = device.configDeviceName || device.deviceName;
1325
- if (device.firmware) {
1326
- existingAccessory.context.version = device.firmware;
1327
- }
1328
- existingAccessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
1329
- this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
1283
+ existingAccessory.context.device = device;
1284
+ existingAccessory.context.deviceId = device.deviceId;
1285
+ existingAccessory.context.deviceType = device.deviceType;
1286
+ existingAccessory.context.model = SwitchBotModel.ContactSensor;
1287
+ existingAccessory.displayName = device.configDeviceName ?? device.deviceName;
1330
1288
  existingAccessory.context.connectionType = await this.connectionType(device);
1289
+ existingAccessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
1290
+ this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`);
1331
1291
  this.api.updatePlatformAccessories([existingAccessory]);
1332
1292
  // create the accessory handler for the restored accessory
1333
1293
  // this is imported from `platformAccessory.ts`
@@ -1337,24 +1297,20 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
1337
1297
  this.unregisterPlatformAccessories(existingAccessory);
1338
1298
  }
1339
1299
  } else if (await this.registerDevice(device)) {
1340
- // the accessory does not yet exist, so we need to create it
1341
- if (!device.external) {
1342
- this.infoLog(`Adding new accessory: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
1343
- }
1344
-
1345
1300
  // create a new accessory
1346
1301
  const accessory = new this.api.platformAccessory(device.deviceName, uuid);
1347
1302
 
1348
1303
  // store a copy of the device object in the `accessory.context`
1349
1304
  // the `context` property can be used to store any data about the accessory you may need
1350
1305
  accessory.context.device = device;
1351
- accessory.context.model = device.deviceType;
1352
- accessory.context.deviceID = device.deviceId;
1353
- if (device.firmware) {
1354
- accessory.context.version = device.firmware;
1355
- }
1356
- accessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
1306
+ accessory.context.deviceId = device.deviceId;
1307
+ accessory.context.deviceType = device.deviceType;
1308
+ accessory.context.model = SwitchBotModel.ContactSensor;
1309
+ accessory.displayName = device.configDeviceName ?? device.deviceName;
1357
1310
  accessory.context.connectionType = await this.connectionType(device);
1311
+ accessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
1312
+ const newOrExternal = !device.external ? 'Adding new' : 'Loading external';
1313
+ await this.infoLog(`${newOrExternal} accessory: ${accessory.displayName} deviceId: ${device.deviceId}`);
1358
1314
  // create the accessory handler for the newly create accessory
1359
1315
  // this is imported from `platformAccessory.ts`
1360
1316
  new Contact(this, accessory, device);
@@ -1364,7 +1320,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
1364
1320
  this.externalOrPlatform(device, accessory);
1365
1321
  this.accessories.push(accessory);
1366
1322
  } else {
1367
- await this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
1323
+ await this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} deviceId: ${device.deviceId}`);
1368
1324
  }
1369
1325
  }
1370
1326
 
@@ -1379,15 +1335,14 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
1379
1335
  // the accessory already exists
1380
1336
  if (await this.registerDevice(device)) {
1381
1337
  // if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
1382
- existingAccessory.context.model = device.deviceType;
1383
- existingAccessory.context.deviceID = device.deviceId;
1384
- existingAccessory.displayName = device.configDeviceName || device.deviceName;
1385
- if (device.firmware) {
1386
- existingAccessory.context.version = device.firmware;
1387
- }
1388
- existingAccessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
1389
- this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
1338
+ existingAccessory.context.device = device;
1339
+ existingAccessory.context.deviceId = device.deviceId;
1340
+ existingAccessory.context.deviceType = device.deviceType;
1341
+ existingAccessory.context.model = SwitchBotModel.BlindTilt;
1342
+ existingAccessory.displayName = device.configDeviceName ?? device.deviceName;
1390
1343
  existingAccessory.context.connectionType = await this.connectionType(device);
1344
+ existingAccessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
1345
+ this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`);
1391
1346
  this.api.updatePlatformAccessories([existingAccessory]);
1392
1347
  // create the accessory handler for the restored accessory
1393
1348
  // this is imported from `platformAccessory.ts`
@@ -1397,21 +1352,16 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
1397
1352
  this.unregisterPlatformAccessories(existingAccessory);
1398
1353
  }
1399
1354
  } else if (await this.registerDevice(device)) {
1400
- // the accessory does not yet exist, so we need to create it
1401
- if (!device.external) {
1402
- this.infoLog(`Adding new accessory: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
1403
- }
1404
-
1405
1355
  if (isBlindTiltDevice(device)) {
1406
1356
  if (device.group && !device.curtain?.disable_group) {
1407
1357
  this.debugLog(
1408
1358
  'Your Curtains are grouped, ' +
1409
- `, Secondary curtain automatically hidden. Main Curtain: ${device.deviceName}, DeviceID: ${device.deviceId}`);
1359
+ `, Secondary curtain automatically hidden. Main Curtain: ${device.deviceName}, deviceId: ${device.deviceId}`);
1410
1360
  } else {
1411
1361
  if (device.master) {
1412
- this.warnLog(`Main Curtain: ${device.deviceName}, DeviceID: ${device.deviceId}`);
1362
+ this.warnLog(`Main Curtain: ${device.deviceName}, deviceId: ${device.deviceId}`);
1413
1363
  } else {
1414
- this.errorLog(`Secondary Curtain: ${device.deviceName}, DeviceID: ${device.deviceId}`);
1364
+ this.errorLog(`Secondary Curtain: ${device.deviceName}, deviceId: ${device.deviceId}`);
1415
1365
  }
1416
1366
  }
1417
1367
  }
@@ -1421,14 +1371,15 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
1421
1371
 
1422
1372
  // store a copy of the device object in the `accessory.context`
1423
1373
  // the `context` property can be used to store any data about the accessory you may need
1424
- accessory.context.device = device;
1425
- accessory.context.model = device.deviceType;
1426
- accessory.context.deviceID = device.deviceId;
1427
- if (device.firmware) {
1428
- accessory.context.version = device.firmware;
1429
- }
1430
- accessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
1374
+ accessory.context.device = device;;
1375
+ accessory.context.deviceId = device.deviceId;
1376
+ accessory.context.deviceType = device.deviceType;
1377
+ accessory.context.model = SwitchBotModel.BlindTilt;
1378
+ accessory.displayName = device.configDeviceName ?? device.deviceName;
1431
1379
  accessory.context.connectionType = await this.connectionType(device);
1380
+ accessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
1381
+ const newOrExternal = !device.external ? 'Adding new' : 'Loading external';
1382
+ await this.infoLog(`${newOrExternal} accessory: ${accessory.displayName} deviceId: ${device.deviceId}`);
1432
1383
  // create the accessory handler for the newly create accessory
1433
1384
  // this is imported from `platformAccessory.ts`
1434
1385
  new BlindTilt(this, accessory, device);
@@ -1438,7 +1389,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
1438
1389
  this.externalOrPlatform(device, accessory);
1439
1390
  this.accessories.push(accessory);
1440
1391
  } else {
1441
- await this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
1392
+ await this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} deviceId: ${device.deviceId}`);
1442
1393
  }
1443
1394
  }
1444
1395
 
@@ -1453,15 +1404,14 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
1453
1404
  // the accessory already exists
1454
1405
  if (await this.registerDevice(device)) {
1455
1406
  // if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
1456
- existingAccessory.context.model = device.deviceType;
1457
- existingAccessory.context.deviceID = device.deviceId;
1458
- existingAccessory.displayName = device.configDeviceName || device.deviceName;
1459
- if (device.firmware) {
1460
- existingAccessory.context.version = device.firmware;
1461
- }
1462
- existingAccessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
1463
- this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
1407
+ existingAccessory.context.device = device;
1408
+ existingAccessory.context.deviceId = device.deviceId;
1409
+ existingAccessory.context.deviceType = device.deviceType;
1410
+ existingAccessory.context.model = device.deviceType === 'Curtain3' ? SwitchBotModel.Curtain3 : SwitchBotModel.Curtain;
1411
+ existingAccessory.displayName = device.configDeviceName ?? device.deviceName;
1464
1412
  existingAccessory.context.connectionType = await this.connectionType(device);
1413
+ existingAccessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
1414
+ await this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`);
1465
1415
  this.api.updatePlatformAccessories([existingAccessory]);
1466
1416
  // create the accessory handler for the restored accessory
1467
1417
  // this is imported from `platformAccessory.ts`
@@ -1471,22 +1421,16 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
1471
1421
  this.unregisterPlatformAccessories(existingAccessory);
1472
1422
  }
1473
1423
  } else if (await this.registerDevice(device)) {
1474
- // the accessory does not yet exist, so we need to create it
1475
- if (!device.external) {
1476
- this.infoLog(`Adding new accessory: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
1477
- }
1478
-
1479
-
1480
1424
  if (isCurtainDevice(device)) {
1481
1425
  if (device.group && !device.curtain?.disable_group) {
1482
1426
  this.debugLog(
1483
1427
  'Your Curtains are grouped, ' +
1484
- `, Secondary curtain automatically hidden. Main Curtain: ${device.deviceName}, DeviceID: ${device.deviceId}`);
1428
+ `, Secondary curtain automatically hidden. Main Curtain: ${device.deviceName}, deviceId: ${device.deviceId}`);
1485
1429
  } else {
1486
1430
  if (device.master) {
1487
- this.warnLog(`Main Curtain: ${device.deviceName}, DeviceID: ${device.deviceId}`);
1431
+ this.warnLog(`Main Curtain: ${device.deviceName}, deviceId: ${device.deviceId}`);
1488
1432
  } else {
1489
- this.errorLog(`Secondary Curtain: ${device.deviceName}, DeviceID: ${device.deviceId}`);
1433
+ this.errorLog(`Secondary Curtain: ${device.deviceName}, deviceId: ${device.deviceId}`);
1490
1434
  }
1491
1435
  }
1492
1436
  }
@@ -1497,13 +1441,14 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
1497
1441
  // store a copy of the device object in the `accessory.context`
1498
1442
  // the `context` property can be used to store any data about the accessory you may need
1499
1443
  accessory.context.device = device;
1500
- accessory.context.model = device.deviceType;
1501
- accessory.context.deviceID = device.deviceId;
1502
- if (device.firmware) {
1503
- accessory.context.version = device.firmware;
1504
- }
1505
- accessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
1444
+ accessory.context.deviceId = device.deviceId;
1445
+ accessory.context.deviceType = device.deviceType;
1446
+ accessory.context.model = device.deviceType === 'Curtain3' ? SwitchBotModel.Curtain3 : SwitchBotModel.Curtain;
1447
+ accessory.displayName = device.configDeviceName ?? device.deviceName;
1506
1448
  accessory.context.connectionType = await this.connectionType(device);
1449
+ accessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
1450
+ const newOrExternal = !device.external ? 'Adding new' : 'Loading external';
1451
+ await this.infoLog(`${newOrExternal} accessory: ${accessory.displayName} deviceId: ${device.deviceId}`);
1507
1452
  // create the accessory handler for the newly create accessory
1508
1453
  // this is imported from `platformAccessory.ts`
1509
1454
  new Curtain(this, accessory, device);
@@ -1513,7 +1458,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
1513
1458
  this.externalOrPlatform(device, accessory);
1514
1459
  this.accessories.push(accessory);
1515
1460
  } else {
1516
- await this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
1461
+ await this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} deviceId: ${device.deviceId}`);
1517
1462
  }
1518
1463
  }
1519
1464
 
@@ -1528,15 +1473,15 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
1528
1473
  // the accessory already exists
1529
1474
  if (await this.registerDevice(device)) {
1530
1475
  // if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
1531
- existingAccessory.context.model = device.deviceType;
1532
- existingAccessory.context.deviceID = device.deviceId;
1533
- existingAccessory.displayName = device.configDeviceName || device.deviceName;
1534
- if (device.firmware) {
1535
- existingAccessory.context.version = device.firmware;
1536
- }
1537
- existingAccessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
1538
- this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
1476
+ existingAccessory.context.device = device;
1477
+ existingAccessory.context.deviceId = device.deviceId;
1478
+ existingAccessory.context.deviceType = device.deviceType;
1479
+ existingAccessory.context.model = device.deviceType === 'Plug Mini (US)' ? SwitchBotModel.PlugMiniUS : device.deviceType === 'Plug Mini (JP)'
1480
+ ? SwitchBotModel.PlugMiniJP : SwitchBotModel.Plug;
1481
+ existingAccessory.displayName = device.configDeviceName ?? device.deviceName;
1539
1482
  existingAccessory.context.connectionType = await this.connectionType(device);
1483
+ existingAccessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
1484
+ await this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`);
1540
1485
  this.api.updatePlatformAccessories([existingAccessory]);
1541
1486
  // create the accessory handler for the restored accessory
1542
1487
  // this is imported from `platformAccessory.ts`
@@ -1546,24 +1491,21 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
1546
1491
  this.unregisterPlatformAccessories(existingAccessory);
1547
1492
  }
1548
1493
  } else if (await this.registerDevice(device)) {
1549
- // the accessory does not yet exist, so we need to create it
1550
- if (!device.external) {
1551
- this.infoLog(`Adding new accessory: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
1552
- }
1553
-
1554
1494
  // create a new accessory
1555
1495
  const accessory = new this.api.platformAccessory(device.deviceName, uuid);
1556
1496
 
1557
1497
  // store a copy of the device object in the `accessory.context`
1558
1498
  // the `context` property can be used to store any data about the accessory you may need
1559
1499
  accessory.context.device = device;
1560
- accessory.context.model = device.deviceType;
1561
- accessory.context.deviceID = device.deviceId;
1562
- if (device.firmware) {
1563
- accessory.context.version = device.firmware;
1564
- }
1565
- accessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
1500
+ accessory.context.deviceId = device.deviceId;
1501
+ accessory.context.deviceType = device.deviceType;
1502
+ accessory.context.model = device.deviceType === 'Plug Mini (US)' ? SwitchBotModel.PlugMiniUS : device.deviceType === 'Plug Mini (JP)'
1503
+ ? SwitchBotModel.PlugMiniJP : SwitchBotModel.Plug;
1504
+ accessory.displayName = device.configDeviceName ?? device.deviceName;
1566
1505
  accessory.context.connectionType = await this.connectionType(device);
1506
+ accessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
1507
+ const newOrExternal = !device.external ? 'Adding new' : 'Loading external';
1508
+ await this.infoLog(`${newOrExternal} accessory: ${accessory.displayName} deviceId: ${device.deviceId}`);
1567
1509
  // create the accessory handler for the newly create accessory
1568
1510
  // this is imported from `platformAccessory.ts`
1569
1511
  new Plug(this, accessory, device);
@@ -1573,7 +1515,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
1573
1515
  this.externalOrPlatform(device, accessory);
1574
1516
  this.accessories.push(accessory);
1575
1517
  } else {
1576
- await this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
1518
+ await this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} deviceId: ${device.deviceId}`);
1577
1519
  }
1578
1520
  }
1579
1521
 
@@ -1588,15 +1530,14 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
1588
1530
  // the accessory already exists
1589
1531
  if (await this.registerDevice(device)) {
1590
1532
  // if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
1591
- existingAccessory.context.model = device.deviceType;
1592
- existingAccessory.context.deviceID = device.deviceId;
1593
- existingAccessory.displayName = device.configDeviceName || device.deviceName;
1594
- if (device.firmware) {
1595
- existingAccessory.context.version = device.firmware;
1596
- }
1597
- existingAccessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
1598
- this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
1533
+ existingAccessory.context.device = device;
1534
+ existingAccessory.context.deviceId = device.deviceId;
1535
+ existingAccessory.context.deviceType = device.deviceType;
1536
+ existingAccessory.context.model = device.deviceType === 'Smart Lock Pro' ? SwitchBotModel.LockPro : SwitchBotModel.Lock;
1537
+ existingAccessory.displayName = device.configDeviceName ?? device.deviceName;
1599
1538
  existingAccessory.context.connectionType = await this.connectionType(device);
1539
+ existingAccessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
1540
+ this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`);
1600
1541
  this.api.updatePlatformAccessories([existingAccessory]);
1601
1542
  // create the accessory handler for the restored accessory
1602
1543
  // this is imported from `platformAccessory.ts`
@@ -1606,24 +1547,20 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
1606
1547
  this.unregisterPlatformAccessories(existingAccessory);
1607
1548
  }
1608
1549
  } else if (await this.registerDevice(device)) {
1609
- // the accessory does not yet exist, so we need to create it
1610
- if (!device.external) {
1611
- this.infoLog(`Adding new accessory: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
1612
- }
1613
-
1614
1550
  // create a new accessory
1615
1551
  const accessory = new this.api.platformAccessory(device.deviceName, uuid);
1616
1552
 
1617
1553
  // store a copy of the device object in the `accessory.context`
1618
1554
  // the `context` property can be used to store any data about the accessory you may need
1619
1555
  accessory.context.device = device;
1620
- accessory.context.model = device.deviceType;
1621
- accessory.context.deviceID = device.deviceId;
1622
- if (device.firmware) {
1623
- accessory.context.version = device.firmware;
1624
- }
1625
- accessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
1556
+ accessory.context.deviceId = device.deviceId;
1557
+ accessory.context.deviceType = device.deviceType;
1558
+ accessory.context.model = device.deviceType === 'Smart Lock Pro' ? SwitchBotModel.LockPro : SwitchBotModel.Lock;
1559
+ accessory.displayName = device.configDeviceName ?? device.deviceName;
1626
1560
  accessory.context.connectionType = await this.connectionType(device);
1561
+ accessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
1562
+ const newOrExternal = !device.external ? 'Adding new' : 'Loading external';
1563
+ await this.infoLog(`${newOrExternal} accessory: ${accessory.displayName} deviceId: ${device.deviceId}`);
1627
1564
  // create the accessory handler for the newly create accessory
1628
1565
  // this is imported from `platformAccessory.ts`
1629
1566
  new Lock(this, accessory, device);
@@ -1633,7 +1570,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
1633
1570
  this.externalOrPlatform(device, accessory);
1634
1571
  this.accessories.push(accessory);
1635
1572
  } else {
1636
- await this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
1573
+ await this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} deviceId: ${device.deviceId}`);
1637
1574
  }
1638
1575
  }
1639
1576
 
@@ -1648,15 +1585,14 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
1648
1585
  // the accessory already exists
1649
1586
  if (await this.registerDevice(device)) {
1650
1587
  // if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
1651
- existingAccessory.context.model = device.deviceType;
1652
- existingAccessory.context.deviceID = device.deviceId;
1653
- existingAccessory.displayName = device.configDeviceName || device.deviceName;
1654
- if (device.firmware) {
1655
- existingAccessory.context.version = device.firmware;
1656
- }
1657
- existingAccessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
1658
- this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
1588
+ existingAccessory.context.device = device;
1589
+ existingAccessory.context.deviceId = device.deviceId;
1590
+ existingAccessory.context.deviceType = device.deviceType;
1591
+ existingAccessory.context.model = SwitchBotModel.ColorBulb;
1592
+ existingAccessory.displayName = device.configDeviceName ?? device.deviceName;
1659
1593
  existingAccessory.context.connectionType = await this.connectionType(device);
1594
+ existingAccessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
1595
+ await this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`);
1660
1596
  this.api.updatePlatformAccessories([existingAccessory]);
1661
1597
  // create the accessory handler for the restored accessory
1662
1598
  // this is imported from `platformAccessory.ts`
@@ -1666,24 +1602,20 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
1666
1602
  this.unregisterPlatformAccessories(existingAccessory);
1667
1603
  }
1668
1604
  } else if (await this.registerDevice(device)) {
1669
- // the accessory does not yet exist, so we need to create it
1670
- if (!device.external) {
1671
- this.infoLog(`Adding new accessory: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
1672
- }
1673
-
1674
1605
  // create a new accessory
1675
1606
  const accessory = new this.api.platformAccessory(device.deviceName, uuid);
1676
1607
 
1677
1608
  // store a copy of the device object in the `accessory.context`
1678
1609
  // the `context` property can be used to store any data about the accessory you may need
1679
1610
  accessory.context.device = device;
1680
- accessory.context.model = device.deviceType;
1681
- accessory.context.deviceID = device.deviceId;
1682
- if (device.firmware) {
1683
- accessory.context.version = device.firmware;
1684
- }
1685
- accessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
1611
+ accessory.context.deviceId = device.deviceId;
1612
+ accessory.context.deviceType = device.deviceType;
1613
+ accessory.context.model = SwitchBotModel.ColorBulb;
1614
+ accessory.displayName = device.configDeviceName ?? device.deviceName;
1686
1615
  accessory.context.connectionType = await this.connectionType(device);
1616
+ accessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
1617
+ const newOrExternal = !device.external ? 'Adding new' : 'Loading external';
1618
+ await this.infoLog(`${newOrExternal} accessory: ${accessory.displayName} deviceId: ${device.deviceId}`);
1687
1619
  // create the accessory handler for the newly create accessory
1688
1620
  // this is imported from `platformAccessory.ts`
1689
1621
  new ColorBulb(this, accessory, device);
@@ -1693,7 +1625,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
1693
1625
  this.externalOrPlatform(device, accessory);
1694
1626
  this.accessories.push(accessory);
1695
1627
  } else {
1696
- await this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
1628
+ await this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} deviceId: ${device.deviceId}`);
1697
1629
  }
1698
1630
  }
1699
1631
 
@@ -1708,15 +1640,14 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
1708
1640
  // the accessory already exists
1709
1641
  if (await this.registerDevice(device)) {
1710
1642
  // if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
1711
- existingAccessory.context.model = device.deviceType;
1712
- existingAccessory.context.deviceID = device.deviceId;
1713
- existingAccessory.displayName = device.configDeviceName || device.deviceName;
1714
- if (device.firmware) {
1715
- existingAccessory.context.version = device.firmware;
1716
- }
1717
- existingAccessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
1718
- this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
1643
+ existingAccessory.context.device = device;
1644
+ existingAccessory.context.deviceId = device.deviceId;
1645
+ existingAccessory.context.deviceType = device.deviceType;
1646
+ existingAccessory.context.model = device.deviceType === 'Ceiling Light Pro' ? SwitchBotModel.CeilingLightPro : SwitchBotModel.CeilingLight;
1647
+ existingAccessory.displayName = device.configDeviceName ?? device.deviceName;
1719
1648
  existingAccessory.context.connectionType = await this.connectionType(device);
1649
+ existingAccessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
1650
+ await this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`);
1720
1651
  this.api.updatePlatformAccessories([existingAccessory]);
1721
1652
  // create the accessory handler for the restored accessory
1722
1653
  // this is imported from `platformAccessory.ts`
@@ -1726,24 +1657,20 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
1726
1657
  this.unregisterPlatformAccessories(existingAccessory);
1727
1658
  }
1728
1659
  } else if (await this.registerDevice(device)) {
1729
- // the accessory does not yet exist, so we need to create it
1730
- if (!device.external) {
1731
- this.infoLog(`Adding new accessory: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
1732
- }
1733
-
1734
1660
  // create a new accessory
1735
1661
  const accessory = new this.api.platformAccessory(device.deviceName, uuid);
1736
1662
 
1737
1663
  // store a copy of the device object in the `accessory.context`
1738
1664
  // the `context` property can be used to store any data about the accessory you may need
1739
1665
  accessory.context.device = device;
1740
- accessory.context.model = device.deviceType;
1741
- accessory.context.deviceID = device.deviceId;
1742
- if (device.firmware) {
1743
- accessory.context.version = device.firmware;
1744
- }
1745
- accessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
1666
+ accessory.context.deviceId = device.deviceId;
1667
+ accessory.context.deviceType = device.deviceType;
1668
+ accessory.context.model = device.deviceType === 'Ceiling Light Pro' ? SwitchBotModel.CeilingLightPro : SwitchBotModel.CeilingLight;
1669
+ accessory.displayName = device.configDeviceName ?? device.deviceName;
1746
1670
  accessory.context.connectionType = await this.connectionType(device);
1671
+ accessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
1672
+ const newOrExternal = !device.external ? 'Adding new' : 'Loading external';
1673
+ await this.infoLog(`${newOrExternal} accessory: ${accessory.displayName} deviceId: ${device.deviceId}`);
1747
1674
  // create the accessory handler for the newly create accessory
1748
1675
  // this is imported from `platformAccessory.ts`
1749
1676
  new CeilingLight(this, accessory, device);
@@ -1753,7 +1680,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
1753
1680
  this.externalOrPlatform(device, accessory);
1754
1681
  this.accessories.push(accessory);
1755
1682
  } else {
1756
- await this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
1683
+ await this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} deviceId: ${device.deviceId}`);
1757
1684
  }
1758
1685
  }
1759
1686
 
@@ -1768,15 +1695,14 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
1768
1695
  // the accessory already exists
1769
1696
  if (await this.registerDevice(device)) {
1770
1697
  // if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
1771
- existingAccessory.context.model = device.deviceType;
1772
- existingAccessory.context.deviceID = device.deviceId;
1773
- existingAccessory.displayName = device.configDeviceName || device.deviceName;
1774
- if (device.firmware) {
1775
- existingAccessory.context.version = device.firmware;
1776
- }
1777
- existingAccessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
1778
- this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
1698
+ existingAccessory.context.device = device;
1699
+ existingAccessory.context.deviceId = device.deviceId;
1700
+ existingAccessory.context.deviceType = device.deviceType;
1701
+ existingAccessory.context.model = SwitchBotModel.StripLight;
1702
+ existingAccessory.displayName = device.configDeviceName ?? device.deviceName;
1779
1703
  existingAccessory.context.connectionType = await this.connectionType(device);
1704
+ existingAccessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
1705
+ await this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`);
1780
1706
  this.api.updatePlatformAccessories([existingAccessory]);
1781
1707
  // create the accessory handler for the restored accessory
1782
1708
  // this is imported from `platformAccessory.ts`
@@ -1786,24 +1712,20 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
1786
1712
  this.unregisterPlatformAccessories(existingAccessory);
1787
1713
  }
1788
1714
  } else if (await this.registerDevice(device)) {
1789
- // the accessory does not yet exist, so we need to create it
1790
- if (!device.external) {
1791
- this.infoLog(`Adding new accessory: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
1792
- }
1793
-
1794
1715
  // create a new accessory
1795
1716
  const accessory = new this.api.platformAccessory(device.deviceName, uuid);
1796
1717
 
1797
1718
  // store a copy of the device object in the `accessory.context`
1798
1719
  // the `context` property can be used to store any data about the accessory you may need
1799
1720
  accessory.context.device = device;
1800
- accessory.context.model = device.deviceType;
1801
- accessory.context.deviceID = device.deviceId;
1802
- if (device.firmware) {
1803
- accessory.context.version = device.firmware;
1804
- }
1805
- accessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
1721
+ accessory.context.deviceId = device.deviceId;
1722
+ accessory.context.deviceType = device.deviceType;
1723
+ accessory.context.model = SwitchBotModel.StripLight;
1724
+ accessory.displayName = device.configDeviceName ?? device.deviceName;
1806
1725
  accessory.context.connectionType = await this.connectionType(device);
1726
+ accessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
1727
+ const newOrExternal = !device.external ? 'Adding new' : 'Loading external';
1728
+ await this.infoLog(`${newOrExternal} accessory: ${accessory.displayName} deviceId: ${device.deviceId}`);
1807
1729
  // create the accessory handler for the newly create accessory
1808
1730
  // this is imported from `platformAccessory.ts`
1809
1731
  new StripLight(this, accessory, device);
@@ -1813,7 +1735,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
1813
1735
  this.externalOrPlatform(device, accessory);
1814
1736
  this.accessories.push(accessory);
1815
1737
  } else {
1816
- await this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
1738
+ await this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} deviceId: ${device.deviceId}`);
1817
1739
  }
1818
1740
  }
1819
1741
 
@@ -1828,15 +1750,14 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
1828
1750
  // the accessory already exists
1829
1751
  if (await this.registerDevice(device)) {
1830
1752
  // if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
1831
- existingAccessory.context.model = device.deviceType;
1832
- existingAccessory.context.deviceID = device.deviceId;
1833
- existingAccessory.displayName = device.configDeviceName || device.deviceName;
1834
- if (device.firmware) {
1835
- existingAccessory.context.version = device.firmware;
1836
- }
1837
- existingAccessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
1838
- this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
1753
+ existingAccessory.context.device = device;
1754
+ existingAccessory.context.deviceId = device.deviceId;
1755
+ existingAccessory.context.deviceType = device.deviceType;
1756
+ existingAccessory.context.model = SwitchBotModel.BatteryCirculatorFan;
1757
+ existingAccessory.displayName = device.configDeviceName ?? device.deviceName;
1839
1758
  existingAccessory.context.connectionType = await this.connectionType(device);
1759
+ existingAccessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
1760
+ await this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`);
1840
1761
  this.api.updatePlatformAccessories([existingAccessory]);
1841
1762
  // create the accessory handler for the restored accessory
1842
1763
  // this is imported from `platformAccessory.ts`
@@ -1846,24 +1767,20 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
1846
1767
  this.unregisterPlatformAccessories(existingAccessory);
1847
1768
  }
1848
1769
  } else if (await this.registerDevice(device)) {
1849
- // the accessory does not yet exist, so we need to create it
1850
- if (!device.external) {
1851
- this.infoLog(`Adding new accessory: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
1852
- }
1853
-
1854
1770
  // create a new accessory
1855
1771
  const accessory = new this.api.platformAccessory(device.deviceName, uuid);
1856
1772
 
1857
1773
  // store a copy of the device object in the `accessory.context`
1858
1774
  // the `context` property can be used to store any data about the accessory you may need
1859
1775
  accessory.context.device = device;
1860
- accessory.context.model = device.deviceType;
1861
- accessory.context.deviceID = device.deviceId;
1862
- if (device.firmware) {
1863
- accessory.context.version = device.firmware;
1864
- }
1865
- accessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
1776
+ accessory.context.deviceId = device.deviceId;
1777
+ accessory.context.deviceType = device.deviceType;
1778
+ accessory.context.model = SwitchBotModel.BatteryCirculatorFan;
1779
+ accessory.displayName = device.configDeviceName ?? device.deviceName;
1866
1780
  accessory.context.connectionType = await this.connectionType(device);
1781
+ accessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
1782
+ const newOrExternal = !device.external ? 'Adding new' : 'Loading external';
1783
+ await this.infoLog(`${newOrExternal} accessory: ${accessory.displayName} deviceId: ${device.deviceId}`);
1867
1784
  // create the accessory handler for the newly create accessory
1868
1785
  // this is imported from `platformAccessory.ts`
1869
1786
  new Fan(this, accessory, device);
@@ -1873,7 +1790,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
1873
1790
  this.externalOrPlatform(device, accessory);
1874
1791
  this.accessories.push(accessory);
1875
1792
  } else {
1876
- await this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
1793
+ await this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} deviceId: ${device.deviceId}`);
1877
1794
  }
1878
1795
  }
1879
1796
 
@@ -1888,15 +1805,18 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
1888
1805
  // the accessory already exists
1889
1806
  if (await this.registerDevice(device)) {
1890
1807
  // if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
1891
- existingAccessory.context.model = device.deviceType;
1892
- existingAccessory.context.deviceID = device.deviceId;
1893
- existingAccessory.displayName = device.configDeviceName || device.deviceName;
1894
- if (device.firmware) {
1895
- existingAccessory.context.version = device.firmware;
1896
- }
1897
- existingAccessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
1898
- this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
1808
+ existingAccessory.context.device = device;
1809
+ existingAccessory.context.deviceId = device.deviceId;
1810
+ existingAccessory.context.deviceType = device.deviceType;
1811
+ existingAccessory.context.model = device.deviceType === 'Robot Vacuum Cleaner S1' ? SwitchBotModel.RobotVacuumCleanerS1
1812
+ : device.deviceType === 'Robot Vacuum Cleaner S1 Plus' ? SwitchBotModel.RobotVacuumCleanerS1Plus
1813
+ : device.deviceType === 'Robot Vacuum Cleaner S10' ? SwitchBotModel.RobotVacuumCleanerS10
1814
+ : device.deviceType === 'WoSweeper' ? SwitchBotModel.WoSweeper : device.deviceType === 'WoSweeperMini' ? SwitchBotModel.WoSweeperMini
1815
+ : SwitchBotModel.Unknown;
1816
+ existingAccessory.displayName = device.configDeviceName ?? device.deviceName;
1899
1817
  existingAccessory.context.connectionType = await this.connectionType(device);
1818
+ existingAccessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
1819
+ await this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`);
1900
1820
  this.api.updatePlatformAccessories([existingAccessory]);
1901
1821
  // create the accessory handler for the restored accessory
1902
1822
  // this is imported from `platformAccessory.ts`
@@ -1906,24 +1826,24 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
1906
1826
  this.unregisterPlatformAccessories(existingAccessory);
1907
1827
  }
1908
1828
  } else if (await this.registerDevice(device)) {
1909
- // the accessory does not yet exist, so we need to create it
1910
- if (!device.external) {
1911
- this.infoLog(`Adding new accessory: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
1912
- }
1913
-
1914
1829
  // create a new accessory
1915
1830
  const accessory = new this.api.platformAccessory(device.deviceName, uuid);
1916
1831
 
1917
1832
  // store a copy of the device object in the `accessory.context`
1918
1833
  // the `context` property can be used to store any data about the accessory you may need
1919
1834
  accessory.context.device = device;
1920
- accessory.context.model = device.deviceType;
1921
- accessory.context.deviceID = device.deviceId;
1922
- if (device.firmware) {
1923
- accessory.context.version = device.firmware;
1924
- }
1925
- accessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
1835
+ accessory.context.deviceId = device.deviceId;
1836
+ accessory.context.deviceType = device.deviceType;
1837
+ accessory.context.model = device.deviceType === 'Robot Vacuum Cleaner S1' ? SwitchBotModel.RobotVacuumCleanerS1
1838
+ : device.deviceType === 'Robot Vacuum Cleaner S1 Plus' ? SwitchBotModel.RobotVacuumCleanerS1Plus
1839
+ : device.deviceType === 'Robot Vacuum Cleaner S10' ? SwitchBotModel.RobotVacuumCleanerS10
1840
+ : device.deviceType === 'WoSweeper' ? SwitchBotModel.WoSweeper : device.deviceType === 'WoSweeperMini' ? SwitchBotModel.WoSweeperMini
1841
+ : SwitchBotModel.Unknown;
1842
+ accessory.displayName = device.configDeviceName ?? device.deviceName;
1926
1843
  accessory.context.connectionType = await this.connectionType(device);
1844
+ accessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
1845
+ const newOrExternal = !device.external ? 'Adding new' : 'Loading external';
1846
+ await this.infoLog(`${newOrExternal} accessory: ${accessory.displayName} deviceId: ${device.deviceId}`);
1927
1847
  // create the accessory handler for the newly create accessory
1928
1848
  // this is imported from `platformAccessory.ts`
1929
1849
  new RobotVacuumCleaner(this, accessory, device);
@@ -1933,7 +1853,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
1933
1853
  this.externalOrPlatform(device, accessory);
1934
1854
  this.accessories.push(accessory);
1935
1855
  } else {
1936
- await this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
1856
+ await this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} deviceId: ${device.deviceId}`);
1937
1857
  }
1938
1858
  }
1939
1859
 
@@ -1946,11 +1866,12 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
1946
1866
 
1947
1867
  if (!device.hide_device && existingAccessory) {
1948
1868
  // if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
1949
- existingAccessory.context.model = device.remoteType;
1950
- existingAccessory.context.deviceID = device.deviceId;
1951
- existingAccessory.displayName = device.configDeviceName || device.deviceName;
1869
+ existingAccessory.context.device = device;
1870
+ existingAccessory.context.deviceId = device.deviceId;
1952
1871
  existingAccessory.context.deviceType = `IR: ${device.remoteType}`;
1953
- this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
1872
+ existingAccessory.context.model = device.remoteType;
1873
+ existingAccessory.displayName = device.configDeviceName ?? device.deviceName;
1874
+ await this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`);
1954
1875
  existingAccessory.context.connectionType = device.connectionType;
1955
1876
  this.api.updatePlatformAccessories([existingAccessory]);
1956
1877
  // create the accessory handler for the restored accessory
@@ -1958,24 +1879,20 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
1958
1879
  new TV(this, existingAccessory, device);
1959
1880
  await this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${existingAccessory.UUID})`);
1960
1881
  } else if (!device.hide_device && device.hubDeviceId) {
1961
- // the accessory does not yet exist, so we need to create it
1962
- if (!device.external) {
1963
- this.infoLog(`Adding new accessory: ${device.deviceName} ${device.remoteType} DeviceID: ${device.deviceId}`);
1964
- }
1965
-
1966
1882
  // create a new accessory
1967
1883
  const accessory = new this.api.platformAccessory(device.deviceName, uuid);
1968
1884
 
1969
1885
  // store a copy of the device object in the `accessory.context`
1970
1886
  // the `context` property can be used to store any data about the accessory you may need
1971
1887
  accessory.context.device = device;
1972
- accessory.context.model = device.remoteType;
1973
- accessory.context.deviceID = device.deviceId;
1974
- if (device.firmware) {
1975
- accessory.context.version = device.firmware;
1976
- }
1888
+ accessory.context.deviceId = device.deviceId;
1977
1889
  accessory.context.deviceType = `IR: ${device.remoteType}`;
1890
+ accessory.context.model = device.remoteType;
1891
+ accessory.displayName = device.configDeviceName ?? device.deviceName;
1978
1892
  accessory.context.connectionType = device.connectionType;
1893
+ accessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
1894
+ const newOrExternal = !device.external ? 'Adding new' : 'Loading external';
1895
+ await this.infoLog(`${newOrExternal} accessory: ${accessory.displayName} deviceId: ${device.deviceId}`);
1979
1896
  // create the accessory handler for the newly create accessory
1980
1897
  // this is imported from `platformAccessory.ts`
1981
1898
  new TV(this, accessory, device);
@@ -1984,7 +1901,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
1984
1901
  this.externalOrPlatformIR(device, accessory);
1985
1902
  this.accessories.push(accessory);
1986
1903
  } else {
1987
- await this.debugLog(`Device not registered: ${device.deviceName} ${device.remoteType} DeviceID: ${device.deviceId}`);
1904
+ await this.debugLog(`Device not registered: ${device.deviceName} ${device.remoteType} deviceId: ${device.deviceId}`);
1988
1905
  }
1989
1906
  }
1990
1907
 
@@ -1999,14 +1916,12 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
1999
1916
  // the accessory already exists
2000
1917
  if (!device.hide_device && device.hubDeviceId) {
2001
1918
  // if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
2002
- existingAccessory.context.model = device.remoteType;
2003
- existingAccessory.context.deviceID = device.deviceId;
2004
- existingAccessory.displayName = device.configDeviceName || device.deviceName;
2005
- if (device.firmware) {
2006
- existingAccessory.context.version = device.firmware;
2007
- }
1919
+ existingAccessory.context.device = device;
1920
+ existingAccessory.context.deviceId = device.deviceId;
2008
1921
  existingAccessory.context.deviceType = `IR: ${device.remoteType}`;
2009
- this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
1922
+ existingAccessory.context.model = device.remoteType;
1923
+ existingAccessory.displayName = device.configDeviceName ?? device.deviceName;
1924
+ await this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`);
2010
1925
  existingAccessory.context.connectionType = device.connectionType;
2011
1926
  this.api.updatePlatformAccessories([existingAccessory]);
2012
1927
  // create the accessory handler for the restored accessory
@@ -2017,24 +1932,20 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
2017
1932
  this.unregisterPlatformAccessories(existingAccessory);
2018
1933
  }
2019
1934
  } else if (!device.hide_device && device.hubDeviceId) {
2020
- // the accessory does not yet exist, so we need to create it
2021
- if (!device.external) {
2022
- this.infoLog(`Adding new accessory: ${device.deviceName} ${device.remoteType} DeviceID: ${device.deviceId}`);
2023
- }
2024
-
2025
1935
  // create a new accessory
2026
1936
  const accessory = new this.api.platformAccessory(device.deviceName, uuid);
2027
1937
 
2028
1938
  // store a copy of the device object in the `accessory.context`
2029
1939
  // the `context` property can be used to store any data about the accessory you may need
2030
1940
  accessory.context.device = device;
2031
- accessory.context.model = device.remoteType;
2032
- accessory.context.deviceID = device.deviceId;
2033
- if (device.firmware) {
2034
- accessory.context.version = device.firmware;
2035
- }
1941
+ accessory.context.deviceId = device.deviceId;
2036
1942
  accessory.context.deviceType = `IR: ${device.remoteType}`;
1943
+ accessory.context.model = device.remoteType;
1944
+ accessory.displayName = device.configDeviceName ?? device.deviceName;
2037
1945
  accessory.context.connectionType = device.connectionType;
1946
+ accessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
1947
+ const newOrExternal = !device.external ? 'Adding new' : 'Loading external';
1948
+ await this.infoLog(`${newOrExternal} accessory: ${accessory.displayName} deviceId: ${device.deviceId}`);
2038
1949
  // create the accessory handler for the newly create accessory
2039
1950
  // this is imported from `platformAccessory.ts`
2040
1951
  new IRFan(this, accessory, device);
@@ -2044,7 +1955,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
2044
1955
  this.externalOrPlatformIR(device, accessory);
2045
1956
  this.accessories.push(accessory);
2046
1957
  } else {
2047
- await this.debugLog(`Device not registered: ${device.deviceName} ${device.remoteType} DeviceID: ${device.deviceId}`);
1958
+ await this.debugLog(`Device not registered: ${device.deviceName} ${device.remoteType} deviceId: ${device.deviceId}`);
2048
1959
  }
2049
1960
  }
2050
1961
 
@@ -2059,14 +1970,12 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
2059
1970
  // the accessory already exists
2060
1971
  if (!device.hide_device && device.hubDeviceId) {
2061
1972
  // if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
2062
- existingAccessory.context.model = device.remoteType;
2063
- existingAccessory.context.deviceID = device.deviceId;
2064
- existingAccessory.displayName = device.configDeviceName || device.deviceName;
2065
- if (device.firmware) {
2066
- existingAccessory.context.version = device.firmware;
2067
- }
1973
+ existingAccessory.context.device = device;
1974
+ existingAccessory.context.deviceId = device.deviceId;
2068
1975
  existingAccessory.context.deviceType = `IR: ${device.remoteType}`;
2069
- this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
1976
+ existingAccessory.context.model = device.remoteType;
1977
+ existingAccessory.displayName = device.configDeviceName ?? device.deviceName;
1978
+ await this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`);
2070
1979
  existingAccessory.context.connectionType = device.connectionType;
2071
1980
  this.api.updatePlatformAccessories([existingAccessory]);
2072
1981
  // create the accessory handler for the restored accessory
@@ -2077,24 +1986,20 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
2077
1986
  this.unregisterPlatformAccessories(existingAccessory);
2078
1987
  }
2079
1988
  } else if (!device.hide_device && device.hubDeviceId) {
2080
- // the accessory does not yet exist, so we need to create it
2081
- if (!device.external) {
2082
- this.infoLog(`Adding new accessory: ${device.deviceName} ${device.remoteType} DeviceID: ${device.deviceId}`);
2083
- }
2084
-
2085
1989
  // create a new accessory
2086
1990
  const accessory = new this.api.platformAccessory(device.deviceName, uuid);
2087
1991
 
2088
1992
  // store a copy of the device object in the `accessory.context`
2089
1993
  // the `context` property can be used to store any data about the accessory you may need
2090
1994
  accessory.context.device = device;
2091
- accessory.context.model = device.remoteType;
2092
- accessory.context.deviceID = device.deviceId;
2093
- if (device.firmware) {
2094
- accessory.context.version = device.firmware;
2095
- }
1995
+ accessory.context.deviceId = device.deviceId;
2096
1996
  accessory.context.deviceType = `IR: ${device.remoteType}`;
1997
+ accessory.context.model = device.remoteType;
1998
+ accessory.displayName = device.configDeviceName ?? device.deviceName;
2097
1999
  accessory.context.connectionType = device.connectionType;
2000
+ accessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
2001
+ const newOrExternal = !device.external ? 'Adding new' : 'Loading external';
2002
+ await this.infoLog(`${newOrExternal} accessory: ${accessory.displayName} deviceId: ${device.deviceId}`);
2098
2003
  // create the accessory handler for the newly create accessory
2099
2004
  // this is imported from `platformAccessory.ts`
2100
2005
  new Light(this, accessory, device);
@@ -2104,7 +2009,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
2104
2009
  this.externalOrPlatformIR(device, accessory);
2105
2010
  this.accessories.push(accessory);
2106
2011
  } else {
2107
- await this.debugLog(`Device not registered: ${device.deviceName} ${device.remoteType} DeviceID: ${device.deviceId}`);
2012
+ await this.debugLog(`Device not registered: ${device.deviceName} ${device.remoteType} deviceId: ${device.deviceId}`);
2108
2013
  }
2109
2014
  }
2110
2015
 
@@ -2119,14 +2024,12 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
2119
2024
  // the accessory already exists
2120
2025
  if (!device.hide_device && device.hubDeviceId) {
2121
2026
  // if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
2122
- existingAccessory.context.model = device.remoteType;
2123
- existingAccessory.context.deviceID = device.deviceId;
2124
- existingAccessory.displayName = device.configDeviceName || device.deviceName;
2125
- if (device.firmware) {
2126
- existingAccessory.context.version = device.firmware;
2127
- }
2027
+ existingAccessory.context.device = device;
2028
+ existingAccessory.context.deviceId = device.deviceId;
2128
2029
  existingAccessory.context.deviceType = `IR: ${device.remoteType}`;
2129
- this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
2030
+ existingAccessory.context.model = device.remoteType;
2031
+ existingAccessory.displayName = device.configDeviceName ?? device.deviceName;
2032
+ await this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`);
2130
2033
  existingAccessory.context.connectionType = device.connectionType;
2131
2034
  this.api.updatePlatformAccessories([existingAccessory]);
2132
2035
  // create the accessory handler for the restored accessory
@@ -2137,24 +2040,20 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
2137
2040
  this.unregisterPlatformAccessories(existingAccessory);
2138
2041
  }
2139
2042
  } else if (!device.hide_device && device.hubDeviceId) {
2140
- // the accessory does not yet exist, so we need to create it
2141
- if (!device.external) {
2142
- this.infoLog(`Adding new accessory: ${device.deviceName} ${device.remoteType} DeviceID: ${device.deviceId}`);
2143
- }
2144
-
2145
2043
  // create a new accessory
2146
2044
  const accessory = new this.api.platformAccessory(device.deviceName, uuid);
2147
2045
 
2148
2046
  // store a copy of the device object in the `accessory.context`
2149
2047
  // the `context` property can be used to store any data about the accessory you may need
2150
2048
  accessory.context.device = device;
2151
- accessory.context.model = device.remoteType;
2152
- accessory.context.deviceID = device.deviceId;
2153
- if (device.firmware) {
2154
- accessory.context.version = device.firmware;
2155
- }
2049
+ accessory.context.deviceId = device.deviceId;
2156
2050
  accessory.context.deviceType = `IR: ${device.remoteType}`;
2051
+ accessory.context.model = device.remoteType;
2052
+ accessory.displayName = device.configDeviceName ?? device.deviceName;
2157
2053
  accessory.context.connectionType = device.connectionType;
2054
+ accessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
2055
+ const newOrExternal = !device.external ? 'Adding new' : 'Loading external';
2056
+ await this.infoLog(`${newOrExternal} accessory: ${accessory.displayName} deviceId: ${device.deviceId}`);
2158
2057
  // create the accessory handler for the newly create accessory
2159
2058
  // this is imported from `platformAccessory.ts`
2160
2059
  new AirConditioner(this, accessory, device);
@@ -2164,7 +2063,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
2164
2063
  this.externalOrPlatformIR(device, accessory);
2165
2064
  this.accessories.push(accessory);
2166
2065
  } else {
2167
- await this.debugLog(`Device not registered: ${device.deviceName} ${device.remoteType} DeviceID: ${device.deviceId}`);
2066
+ await this.debugLog(`Device not registered: ${device.deviceName} ${device.remoteType} deviceId: ${device.deviceId}`);
2168
2067
  }
2169
2068
  }
2170
2069
 
@@ -2179,14 +2078,12 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
2179
2078
  // the accessory already exists
2180
2079
  if (!device.hide_device && device.hubDeviceId) {
2181
2080
  // if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
2182
- existingAccessory.context.model = device.remoteType;
2183
- existingAccessory.context.deviceID = device.deviceId;
2184
- existingAccessory.displayName = device.configDeviceName || device.deviceName;
2185
- if (device.firmware) {
2186
- existingAccessory.context.version = device.firmware;
2187
- }
2081
+ existingAccessory.context.device = device;
2082
+ existingAccessory.context.deviceId = device.deviceId;
2188
2083
  existingAccessory.context.deviceType = `IR: ${device.remoteType}`;
2189
- this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
2084
+ existingAccessory.context.model = device.remoteType;
2085
+ existingAccessory.displayName = device.configDeviceName ?? device.deviceName;
2086
+ await this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`);
2190
2087
  existingAccessory.context.connectionType = device.connectionType;
2191
2088
  this.api.updatePlatformAccessories([existingAccessory]);
2192
2089
  // create the accessory handler for the restored accessory
@@ -2197,24 +2094,20 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
2197
2094
  this.unregisterPlatformAccessories(existingAccessory);
2198
2095
  }
2199
2096
  } else if (!device.hide_device && device.hubDeviceId) {
2200
- // the accessory does not yet exist, so we need to create it
2201
- if (!device.external) {
2202
- this.infoLog(`Adding new accessory: ${device.deviceName} ${device.remoteType} DeviceID: ${device.deviceId}`);
2203
- }
2204
-
2205
2097
  // create a new accessory
2206
2098
  const accessory = new this.api.platformAccessory(device.deviceName, uuid);
2207
2099
 
2208
2100
  // store a copy of the device object in the `accessory.context`
2209
2101
  // the `context` property can be used to store any data about the accessory you may need
2210
2102
  accessory.context.device = device;
2211
- accessory.context.model = device.remoteType;
2212
- accessory.context.deviceID = device.deviceId;
2213
- if (device.firmware) {
2214
- accessory.context.version = device.firmware;
2215
- }
2103
+ accessory.context.deviceId = device.deviceId;
2216
2104
  accessory.context.deviceType = `IR: ${device.remoteType}`;
2105
+ accessory.context.model = device.remoteType;
2106
+ accessory.displayName = device.configDeviceName ?? device.deviceName;
2217
2107
  accessory.context.connectionType = device.connectionType;
2108
+ accessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
2109
+ const newOrExternal = !device.external ? 'Adding new' : 'Loading external';
2110
+ await this.infoLog(`${newOrExternal} accessory: ${accessory.displayName} deviceId: ${device.deviceId}`);
2218
2111
  // create the accessory handler for the newly create accessory
2219
2112
  // this is imported from `platformAccessory.ts`
2220
2113
  new AirPurifier(this, accessory, device);
@@ -2224,7 +2117,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
2224
2117
  this.externalOrPlatformIR(device, accessory);
2225
2118
  this.accessories.push(accessory);
2226
2119
  } else {
2227
- await this.debugLog(`Device not registered: ${device.deviceName} ${device.remoteType} DeviceID: ${device.deviceId}`);
2120
+ await this.debugLog(`Device not registered: ${device.deviceName} ${device.remoteType} deviceId: ${device.deviceId}`);
2228
2121
  }
2229
2122
  }
2230
2123
 
@@ -2239,14 +2132,12 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
2239
2132
  // the accessory already exists
2240
2133
  if (!device.hide_device && device.hubDeviceId) {
2241
2134
  // if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
2242
- existingAccessory.context.model = device.remoteType;
2243
- existingAccessory.context.deviceID = device.deviceId;
2244
- existingAccessory.displayName = device.configDeviceName || device.deviceName;
2245
- if (device.firmware) {
2246
- existingAccessory.context.version = device.firmware;
2247
- }
2135
+ existingAccessory.context.device = device;
2136
+ existingAccessory.context.deviceId = device.deviceId;
2248
2137
  existingAccessory.context.deviceType = `IR: ${device.remoteType}`;
2249
- this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
2138
+ existingAccessory.context.model = device.remoteType;
2139
+ existingAccessory.displayName = device.configDeviceName ?? device.deviceName;
2140
+ await this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`);
2250
2141
  existingAccessory.context.connectionType = device.connectionType;
2251
2142
  this.api.updatePlatformAccessories([existingAccessory]);
2252
2143
  // create the accessory handler for the restored accessory
@@ -2257,24 +2148,20 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
2257
2148
  this.unregisterPlatformAccessories(existingAccessory);
2258
2149
  }
2259
2150
  } else if (!device.hide_device && device.hubDeviceId) {
2260
- // the accessory does not yet exist, so we need to create it
2261
- if (!device.external) {
2262
- this.infoLog(`Adding new accessory: ${device.deviceName} ${device.remoteType} DeviceID: ${device.deviceId}`);
2263
- }
2264
-
2265
2151
  // create a new accessory
2266
2152
  const accessory = new this.api.platformAccessory(device.deviceName, uuid);
2267
2153
 
2268
2154
  // store a copy of the device object in the `accessory.context`
2269
2155
  // the `context` property can be used to store any data about the accessory you may need
2270
2156
  accessory.context.device = device;
2271
- accessory.context.model = device.remoteType;
2272
- accessory.context.deviceID = device.deviceId;
2273
- if (device.firmware) {
2274
- accessory.context.version = device.firmware;
2275
- }
2157
+ accessory.context.deviceId = device.deviceId;
2276
2158
  accessory.context.deviceType = `IR: ${device.remoteType}`;
2159
+ accessory.context.model = device.remoteType;
2160
+ accessory.displayName = device.configDeviceName ?? device.deviceName;
2277
2161
  accessory.context.connectionType = device.connectionType;
2162
+ accessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
2163
+ const newOrExternal = !device.external ? 'Adding new' : 'Loading external';
2164
+ await this.infoLog(`${newOrExternal} accessory: ${accessory.displayName} deviceId: ${device.deviceId}`);
2278
2165
  // create the accessory handler for the newly create accessory
2279
2166
  // this is imported from `platformAccessory.ts`
2280
2167
  new WaterHeater(this, accessory, device);
@@ -2284,7 +2171,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
2284
2171
  this.externalOrPlatformIR(device, accessory);
2285
2172
  this.accessories.push(accessory);
2286
2173
  } else {
2287
- await this.debugLog(`Device not registered: ${device.deviceName} ${device.remoteType} DeviceID: ${device.deviceId}`);
2174
+ await this.debugLog(`Device not registered: ${device.deviceName} ${device.remoteType} deviceId: ${device.deviceId}`);
2288
2175
  }
2289
2176
  }
2290
2177
 
@@ -2299,14 +2186,12 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
2299
2186
  // the accessory already exists
2300
2187
  if (!device.hide_device && device.hubDeviceId) {
2301
2188
  // if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
2302
- existingAccessory.context.model = device.remoteType;
2303
- existingAccessory.context.deviceID = device.deviceId;
2304
- existingAccessory.displayName = device.configDeviceName || device.deviceName;
2305
- if (device.firmware) {
2306
- existingAccessory.context.version = device.firmware;
2307
- }
2189
+ existingAccessory.context.device = device;
2190
+ existingAccessory.context.deviceId = device.deviceId;
2308
2191
  existingAccessory.context.deviceType = `IR: ${device.remoteType}`;
2309
- this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
2192
+ existingAccessory.context.model = device.remoteType;
2193
+ existingAccessory.displayName = device.configDeviceName ?? device.deviceName;
2194
+ await this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`);
2310
2195
  existingAccessory.context.connectionType = device.connectionType;
2311
2196
  this.api.updatePlatformAccessories([existingAccessory]);
2312
2197
  // create the accessory handler for the restored accessory
@@ -2317,24 +2202,20 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
2317
2202
  this.unregisterPlatformAccessories(existingAccessory);
2318
2203
  }
2319
2204
  } else if (!device.hide_device && device.hubDeviceId) {
2320
- // the accessory does not yet exist, so we need to create it
2321
- if (!device.external) {
2322
- this.infoLog(`Adding new accessory: ${device.deviceName} ${device.remoteType} DeviceID: ${device.deviceId}`);
2323
- }
2324
-
2325
2205
  // create a new accessory
2326
2206
  const accessory = new this.api.platformAccessory(device.deviceName, uuid);
2327
2207
 
2328
2208
  // store a copy of the device object in the `accessory.context`
2329
2209
  // the `context` property can be used to store any data about the accessory you may need
2330
2210
  accessory.context.device = device;
2331
- accessory.context.model = device.remoteType;
2332
- accessory.context.deviceID = device.deviceId;
2333
- if (device.firmware) {
2334
- accessory.context.version = device.firmware;
2335
- }
2211
+ accessory.context.deviceId = device.deviceId;
2336
2212
  accessory.context.deviceType = `IR: ${device.remoteType}`;
2213
+ accessory.context.model = device.remoteType;
2214
+ accessory.displayName = device.configDeviceName ?? device.deviceName;
2337
2215
  accessory.context.connectionType = device.connectionType;
2216
+ accessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
2217
+ const newOrExternal = !device.external ? 'Adding new' : 'Loading external';
2218
+ await this.infoLog(`${newOrExternal} accessory: ${accessory.displayName} deviceId: ${device.deviceId}`);
2338
2219
  // create the accessory handler for the newly create accessory
2339
2220
  // this is imported from `platformAccessory.ts`
2340
2221
  new VacuumCleaner(this, accessory, device);
@@ -2344,7 +2225,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
2344
2225
  this.externalOrPlatformIR(device, accessory);
2345
2226
  this.accessories.push(accessory);
2346
2227
  } else {
2347
- await this.debugLog(`Device not registered: ${device.deviceName} ${device.remoteType} DeviceID: ${device.deviceId}`);
2228
+ await this.debugLog(`Device not registered: ${device.deviceName} ${device.remoteType} deviceId: ${device.deviceId}`);
2348
2229
  }
2349
2230
  }
2350
2231
 
@@ -2359,14 +2240,12 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
2359
2240
  // the accessory already exists
2360
2241
  if (!device.hide_device && device.hubDeviceId) {
2361
2242
  // if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
2362
- existingAccessory.context.model = device.remoteType;
2363
- existingAccessory.context.deviceID = device.deviceId;
2364
- existingAccessory.displayName = device.configDeviceName || device.deviceName;
2365
- if (device.firmware) {
2366
- existingAccessory.context.version = device.firmware;
2367
- }
2243
+ existingAccessory.context.device = device;
2244
+ existingAccessory.context.deviceId = device.deviceId;
2368
2245
  existingAccessory.context.deviceType = `IR: ${device.remoteType}`;
2369
- this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
2246
+ existingAccessory.context.model = device.remoteType;
2247
+ existingAccessory.displayName = device.configDeviceName ?? device.deviceName;
2248
+ await this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`);
2370
2249
  existingAccessory.context.connectionType = device.connectionType;
2371
2250
  this.api.updatePlatformAccessories([existingAccessory]);
2372
2251
  // create the accessory handler for the restored accessory
@@ -2377,24 +2256,20 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
2377
2256
  this.unregisterPlatformAccessories(existingAccessory);
2378
2257
  }
2379
2258
  } else if (!device.hide_device && device.hubDeviceId) {
2380
- // the accessory does not yet exist, so we need to create it
2381
- if (!device.external) {
2382
- this.infoLog(`Adding new accessory: ${device.deviceName} ${device.remoteType} DeviceID: ${device.deviceId}`);
2383
- }
2384
-
2385
2259
  // create a new accessory
2386
2260
  const accessory = new this.api.platformAccessory(device.deviceName, uuid);
2387
2261
 
2388
2262
  // store a copy of the device object in the `accessory.context`
2389
2263
  // the `context` property can be used to store any data about the accessory you may need
2390
2264
  accessory.context.device = device;
2391
- accessory.context.model = device.remoteType;
2392
- accessory.context.deviceID = device.deviceId;
2393
- if (device.firmware) {
2394
- accessory.context.version = device.firmware;
2395
- }
2265
+ accessory.context.deviceId = device.deviceId;
2396
2266
  accessory.context.deviceType = `IR: ${device.remoteType}`;
2267
+ accessory.context.model = device.remoteType;
2268
+ accessory.displayName = device.configDeviceName ?? device.deviceName;
2397
2269
  accessory.context.connectionType = device.connectionType;
2270
+ accessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
2271
+ const newOrExternal = !device.external ? 'Adding new' : 'Loading external';
2272
+ await this.infoLog(`${newOrExternal} accessory: ${accessory.displayName} deviceId: ${device.deviceId}`);
2398
2273
  // create the accessory handler for the newly create accessory
2399
2274
  // this is imported from `platformAccessory.ts`
2400
2275
  new Camera(this, accessory, device);
@@ -2404,7 +2279,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
2404
2279
  this.externalOrPlatformIR(device, accessory);
2405
2280
  this.accessories.push(accessory);
2406
2281
  } else {
2407
- await this.debugLog(`Device not registered: ${device.deviceName} ${device.remoteType} DeviceID: ${device.deviceId}`);
2282
+ await this.debugLog(`Device not registered: ${device.deviceName} ${device.remoteType} deviceId: ${device.deviceId}`);
2408
2283
  }
2409
2284
  }
2410
2285
 
@@ -2419,14 +2294,12 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
2419
2294
  // the accessory already exists
2420
2295
  if (!device.hide_device && device.hubDeviceId) {
2421
2296
  // if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
2422
- existingAccessory.context.model = device.remoteType;
2423
- existingAccessory.context.deviceID = device.deviceId;
2424
- existingAccessory.displayName = device.configDeviceName || device.deviceName;
2425
- if (device.firmware) {
2426
- existingAccessory.context.version = device.firmware;
2427
- }
2297
+ existingAccessory.context.device = device;
2298
+ existingAccessory.context.deviceId = device.deviceId;
2428
2299
  existingAccessory.context.deviceType = `IR: ${device.remoteType}`;
2429
- this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
2300
+ existingAccessory.context.model = device.remoteType;
2301
+ existingAccessory.displayName = device.configDeviceName ?? device.deviceName;
2302
+ await this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`);
2430
2303
  existingAccessory.context.connectionType = device.connectionType;
2431
2304
  this.api.updatePlatformAccessories([existingAccessory]);
2432
2305
  // create the accessory handler for the restored accessory
@@ -2437,24 +2310,20 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
2437
2310
  this.unregisterPlatformAccessories(existingAccessory);
2438
2311
  }
2439
2312
  } else if (!device.hide_device && device.hubDeviceId) {
2440
- // the accessory does not yet exist, so we need to create it
2441
- if (!device.external) {
2442
- this.infoLog(`Adding new accessory: ${device.deviceName} ${device.remoteType} DeviceID: ${device.deviceId}`);
2443
- }
2444
-
2445
2313
  // create a new accessory
2446
2314
  const accessory = new this.api.platformAccessory(device.deviceName, uuid);
2447
2315
 
2448
2316
  // store a copy of the device object in the `accessory.context`
2449
2317
  // the `context` property can be used to store any data about the accessory you may need
2450
2318
  accessory.context.device = device;
2451
- accessory.context.model = device.remoteType;
2452
- accessory.context.deviceID = device.deviceId;
2453
- if (device.firmware) {
2454
- accessory.context.version = device.firmware;
2455
- }
2319
+ accessory.context.deviceId = device.deviceId;
2456
2320
  accessory.context.deviceType = `IR: ${device.remoteType}`;
2321
+ accessory.context.model = device.remoteType;
2322
+ accessory.displayName = device.configDeviceName ?? device.deviceName;
2457
2323
  accessory.context.connectionType = device.connectionType;
2324
+ accessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
2325
+ const newOrExternal = !device.external ? 'Adding new' : 'Loading external';
2326
+ await this.infoLog(`${newOrExternal} accessory: ${accessory.displayName} deviceId: ${device.deviceId}`);
2458
2327
  // create the accessory handler for the newly create accessory
2459
2328
  // this is imported from `platformAccessory.ts`
2460
2329
  new Others(this, accessory, device);
@@ -2464,7 +2333,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
2464
2333
  this.externalOrPlatformIR(device, accessory);
2465
2334
  this.accessories.push(accessory);
2466
2335
  } else {
2467
- await this.debugLog(`Device not registered: ${device.deviceName} ${device.remoteType} DeviceID: ${device.deviceId}`);
2336
+ await this.debugLog(`Device not registered: ${device.deviceName} ${device.remoteType} deviceId: ${device.deviceId}`);
2468
2337
  }
2469
2338
  }
2470
2339
 
@@ -2486,7 +2355,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
2486
2355
  await this.debugWarnLog(`deviceName: ${device.deviceName} deviceId: ${device.deviceId}, blindTiltDevicesIds: ${device.blindTiltDevicesIds},`
2487
2356
  + ` master: ${device.master}, group: ${device.group}, disable_group: ${device.curtain?.disable_group},`
2488
2357
  + ` connectionType: ${device.connectionType}`);
2489
- registerWindowCovering =await this.registerWindowCovering(device);
2358
+ registerWindowCovering = await this.registerWindowCovering(device);
2490
2359
  } else {
2491
2360
  registerWindowCovering = false;
2492
2361
  }