@switchbot/homebridge-switchbot 3.5.1-beta.17 → 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 +6 -28
  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 +5 -33
  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 +6 -24
  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 +5 -28
  71. package/src/platform.ts +397 -528
package/dist/platform.js CHANGED
@@ -40,6 +40,7 @@ import { readFileSync, writeFileSync } from 'fs';
40
40
  import { EveHomeKitTypes } from 'homebridge-lib/EveHomeKitTypes';
41
41
  import { PLATFORM_NAME, PLUGIN_NAME, Devices, deleteWebhook, queryWebhook, setupWebhook, updateWebhook } from './settings.js';
42
42
  import { isBlindTiltDevice, isCurtainDevice, sleep } from './utils.js';
43
+ import { SwitchBotModel } from 'node-switchbot';
43
44
  /**
44
45
  * HomebridgePlatform
45
46
  * This class is the main constructor for your plugin, this is where you should
@@ -788,15 +789,14 @@ export class SwitchBotPlatform {
788
789
  // the accessory already exists
789
790
  if (await this.registerDevice(device)) {
790
791
  // if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
791
- existingAccessory.context.model = device.deviceType;
792
- existingAccessory.context.deviceID = device.deviceId;
793
- existingAccessory.displayName = device.configDeviceName || device.deviceName;
794
- if (device.firmware) {
795
- existingAccessory.context.version = device.firmware;
796
- }
797
- existingAccessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
798
- this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
792
+ existingAccessory.context.device = device;
793
+ existingAccessory.context.deviceId = device.deviceId;
794
+ existingAccessory.context.deviceType = device.deviceType;
795
+ existingAccessory.context.model = SwitchBotModel.Humidifier;
796
+ existingAccessory.displayName = device.configDeviceName ?? device.deviceName;
799
797
  existingAccessory.context.connectionType = await this.connectionType(device);
798
+ existingAccessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
799
+ await this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`);
800
800
  this.api.updatePlatformAccessories([existingAccessory]);
801
801
  // create the accessory handler for the restored accessory
802
802
  // this is imported from `platformAccessory.ts`
@@ -808,22 +808,19 @@ export class SwitchBotPlatform {
808
808
  }
809
809
  }
810
810
  else if (await this.registerDevice(device)) {
811
- // the accessory does not yet exist, so we need to create it
812
- if (!device.external) {
813
- this.infoLog(`Adding new accessory: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
814
- }
815
811
  // create a new accessory
816
812
  const accessory = new this.api.platformAccessory(device.deviceName, uuid);
817
813
  // store a copy of the device object in the `accessory.context`
818
814
  // the `context` property can be used to store any data about the accessory you may need
819
815
  accessory.context.device = device;
820
- accessory.context.model = device.deviceType;
821
- accessory.context.deviceID = device.deviceId;
822
- if (device.firmware) {
823
- accessory.context.version = device.firmware;
824
- }
825
- accessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
816
+ accessory.context.deviceId = device.deviceId;
817
+ accessory.context.deviceType = device.deviceType;
818
+ accessory.context.model = SwitchBotModel.Humidifier;
819
+ accessory.displayName = device.configDeviceName ?? device.deviceName;
826
820
  accessory.context.connectionType = await this.connectionType(device);
821
+ accessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
822
+ const newOrExternal = !device.external ? 'Adding new' : 'Loading external';
823
+ await this.infoLog(`${newOrExternal} accessory: ${accessory.displayName} deviceId: ${device.deviceId}`);
827
824
  // create the accessory handler for the newly create accessory
828
825
  // this is imported from `platformAccessory.ts`
829
826
  new Humidifier(this, accessory, device);
@@ -833,7 +830,7 @@ export class SwitchBotPlatform {
833
830
  this.accessories.push(accessory);
834
831
  }
835
832
  else {
836
- await this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
833
+ await this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} deviceId: ${device.deviceId}`);
837
834
  }
838
835
  }
839
836
  async createBot(device) {
@@ -845,15 +842,14 @@ export class SwitchBotPlatform {
845
842
  // the accessory already exists
846
843
  if (await this.registerDevice(device)) {
847
844
  // if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
848
- existingAccessory.context.model = device.deviceType;
849
- existingAccessory.context.deviceID = device.deviceId;
850
- existingAccessory.displayName = device.configDeviceName || device.deviceName;
851
- if (device.firmware) {
852
- existingAccessory.context.version = device.firmware;
853
- }
854
- existingAccessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
855
- this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
845
+ existingAccessory.context.device = device;
846
+ existingAccessory.context.deviceId = device.deviceId;
847
+ existingAccessory.context.deviceType = device.deviceType;
848
+ existingAccessory.context.model = SwitchBotModel.Bot;
849
+ existingAccessory.displayName = device.configDeviceName ?? device.deviceName;
856
850
  existingAccessory.context.connectionType = await this.connectionType(device);
851
+ existingAccessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
852
+ this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`);
857
853
  this.api.updatePlatformAccessories([existingAccessory]);
858
854
  // create the accessory handler for the restored accessory
859
855
  // this is imported from `platformAccessory.ts`
@@ -865,22 +861,19 @@ export class SwitchBotPlatform {
865
861
  }
866
862
  }
867
863
  else if (await this.registerDevice(device)) {
868
- // the accessory does not yet exist, so we need to create it
869
- if (!device.external) {
870
- this.infoLog(`Adding new accessory: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
871
- }
872
864
  // create a new accessory
873
865
  const accessory = new this.api.platformAccessory(device.deviceName, uuid);
874
866
  // store a copy of the device object in the `accessory.context`
875
867
  // the `context` property can be used to store any data about the accessory you may need
876
868
  accessory.context.device = device;
877
- accessory.context.model = device.deviceType;
878
- accessory.context.deviceID = device.deviceId;
879
- if (device.firmware) {
880
- accessory.context.version = device.firmware;
881
- }
882
- accessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
869
+ accessory.context.deviceId = device.deviceId;
870
+ accessory.context.deviceType = device.deviceType;
871
+ accessory.context.model = SwitchBotModel.Bot;
872
+ accessory.displayName = device.configDeviceName ?? device.deviceName;
883
873
  accessory.context.connectionType = await this.connectionType(device);
874
+ accessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
875
+ const newOrExternal = !device.external ? 'Adding new' : 'Loading external';
876
+ await this.infoLog(`${newOrExternal} accessory: ${accessory.displayName} deviceId: ${device.deviceId}`);
884
877
  // accessory.context.version = findaccessories.accessoryAttribute.softwareRevision;
885
878
  // create the accessory handler for the newly create accessory
886
879
  // this is imported from `platformAccessory.ts`
@@ -891,7 +884,7 @@ export class SwitchBotPlatform {
891
884
  this.accessories.push(accessory);
892
885
  }
893
886
  else {
894
- await this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
887
+ await this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} deviceId: ${device.deviceId}`);
895
888
  }
896
889
  }
897
890
  async createMeter(device) {
@@ -903,15 +896,14 @@ export class SwitchBotPlatform {
903
896
  // the accessory already exists
904
897
  if (await this.registerDevice(device)) {
905
898
  // if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
906
- existingAccessory.context.model = device.deviceType;
907
- existingAccessory.context.deviceID = device.deviceId;
908
- existingAccessory.displayName = device.configDeviceName || device.deviceName;
909
- if (device.firmware) {
910
- existingAccessory.context.version = device.firmware;
911
- }
912
- existingAccessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
913
- this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
899
+ existingAccessory.context.device = device;
900
+ existingAccessory.context.model = SwitchBotModel.Meter;
901
+ existingAccessory.context.deviceId = device.deviceId;
902
+ existingAccessory.context.deviceType = device.deviceType;
903
+ existingAccessory.displayName = device.configDeviceName ?? device.deviceName;
914
904
  existingAccessory.context.connectionType = await this.connectionType(device);
905
+ existingAccessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
906
+ this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`);
915
907
  this.api.updatePlatformAccessories([existingAccessory]);
916
908
  // create the accessory handler for the restored accessory
917
909
  // this is imported from `platformAccessory.ts`
@@ -923,22 +915,19 @@ export class SwitchBotPlatform {
923
915
  }
924
916
  }
925
917
  else if (await this.registerDevice(device)) {
926
- // the accessory does not yet exist, so we need to create it
927
- if (!device.external) {
928
- this.infoLog(`Adding new accessory: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
929
- }
930
918
  // create a new accessory
931
919
  const accessory = new this.api.platformAccessory(device.deviceName, uuid);
932
920
  // store a copy of the device object in the `accessory.context`
933
921
  // the `context` property can be used to store any data about the accessory you may need
934
922
  accessory.context.device = device;
935
- accessory.context.model = device.deviceType;
936
- accessory.context.deviceID = device.deviceId;
937
- if (device.firmware) {
938
- accessory.context.version = device.firmware;
939
- }
940
- accessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
923
+ accessory.context.model = SwitchBotModel.Meter;
924
+ accessory.context.deviceId = device.deviceId;
925
+ accessory.context.deviceType = device.deviceType;
926
+ accessory.displayName = device.configDeviceName ?? device.deviceName;
941
927
  accessory.context.connectionType = await this.connectionType(device);
928
+ accessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
929
+ const newOrExternal = !device.external ? 'Adding new' : 'Loading external';
930
+ await this.infoLog(`${newOrExternal} accessory: ${accessory.displayName} deviceId: ${device.deviceId}`);
942
931
  // create the accessory handler for the newly create accessory
943
932
  // this is imported from `platformAccessory.ts`
944
933
  new Meter(this, accessory, device);
@@ -948,7 +937,7 @@ export class SwitchBotPlatform {
948
937
  this.accessories.push(accessory);
949
938
  }
950
939
  else {
951
- await this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
940
+ await this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} deviceId: ${device.deviceId}`);
952
941
  }
953
942
  }
954
943
  async createMeterPlus(device) {
@@ -961,15 +950,14 @@ export class SwitchBotPlatform {
961
950
  if (await this.registerDevice(device)) {
962
951
  // console.log("existingAccessory", existingAccessory);
963
952
  // if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
964
- existingAccessory.context.model = device.deviceType;
965
- existingAccessory.context.deviceID = device.deviceId;
966
- existingAccessory.displayName = device.configDeviceName || device.deviceName;
967
- if (device.firmware) {
968
- existingAccessory.context.version = device.firmware;
969
- }
970
- existingAccessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
971
- this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
953
+ existingAccessory.context.device = device;
954
+ existingAccessory.context.model = SwitchBotModel.MeterPlusUS ?? SwitchBotModel.MeterPlusJP;
955
+ existingAccessory.context.deviceId = device.deviceId;
956
+ existingAccessory.context.deviceType = device.deviceType;
957
+ existingAccessory.displayName = device.configDeviceName ?? device.deviceName;
972
958
  existingAccessory.context.connectionType = await this.connectionType(device);
959
+ existingAccessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
960
+ this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`);
973
961
  this.api.updatePlatformAccessories([existingAccessory]);
974
962
  // create the accessory handler for the restored accessory
975
963
  // this is imported from `platformAccessory.ts`
@@ -981,22 +969,19 @@ export class SwitchBotPlatform {
981
969
  }
982
970
  }
983
971
  else if (await this.registerDevice(device)) {
984
- // the accessory does not yet exist, so we need to create it
985
- if (!device.external) {
986
- this.infoLog(`Adding new accessory: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
987
- }
988
972
  // create a new accessory
989
973
  const accessory = new this.api.platformAccessory(device.deviceName, uuid);
990
974
  // store a copy of the device object in the `accessory.context`
991
975
  // the `context` property can be used to store any data about the accessory you may need
992
976
  accessory.context.device = device;
993
- accessory.context.model = device.deviceType;
994
- accessory.context.deviceID = device.deviceId;
995
- if (device.firmware) {
996
- accessory.context.version = device.firmware;
997
- }
998
- accessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
977
+ accessory.context.model = SwitchBotModel.MeterPlusUS ?? SwitchBotModel.MeterPlusJP;
978
+ accessory.context.deviceId = device.deviceId;
979
+ accessory.context.deviceType = device.deviceType;
980
+ accessory.displayName = device.configDeviceName ?? device.deviceName;
999
981
  accessory.context.connectionType = await this.connectionType(device);
982
+ accessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
983
+ const newOrExternal = !device.external ? 'Adding new' : 'Loading external';
984
+ await this.infoLog(`${newOrExternal} accessory: ${accessory.displayName} deviceId: ${device.deviceId}`);
1000
985
  // create the accessory handler for the newly create accessory
1001
986
  // this is imported from `platformAccessory.ts`
1002
987
  new MeterPlus(this, accessory, device);
@@ -1006,7 +991,7 @@ export class SwitchBotPlatform {
1006
991
  this.accessories.push(accessory);
1007
992
  }
1008
993
  else {
1009
- await this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
994
+ await this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} deviceId: ${device.deviceId}`);
1010
995
  }
1011
996
  }
1012
997
  async createHub2(device) {
@@ -1019,15 +1004,14 @@ export class SwitchBotPlatform {
1019
1004
  if (await this.registerDevice(device)) {
1020
1005
  // console.log("existingAccessory", existingAccessory);
1021
1006
  // if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
1022
- existingAccessory.context.model = device.deviceType;
1023
- existingAccessory.context.deviceID = device.deviceId;
1024
- existingAccessory.displayName = device.configDeviceName || device.deviceName;
1025
- if (device.firmware) {
1026
- existingAccessory.context.version = device.firmware;
1027
- }
1028
- existingAccessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
1029
- this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
1007
+ existingAccessory.context.device = device;
1008
+ existingAccessory.context.model = SwitchBotModel.Hub2;
1009
+ existingAccessory.context.deviceId = device.deviceId;
1010
+ existingAccessory.context.deviceType = device.deviceType;
1011
+ existingAccessory.displayName = device.configDeviceName ?? device.deviceName;
1030
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}`);
1031
1015
  this.api.updatePlatformAccessories([existingAccessory]);
1032
1016
  // create the accessory handler for the restored accessory
1033
1017
  // this is imported from `platformAccessory.ts`
@@ -1039,22 +1023,19 @@ export class SwitchBotPlatform {
1039
1023
  }
1040
1024
  }
1041
1025
  else if (await this.registerDevice(device)) {
1042
- // the accessory does not yet exist, so we need to create it
1043
- if (!device.external) {
1044
- this.infoLog(`Adding new accessory: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
1045
- }
1046
1026
  // create a new accessory
1047
1027
  const accessory = new this.api.platformAccessory(device.deviceName, uuid);
1048
1028
  // store a copy of the device object in the `accessory.context`
1049
1029
  // the `context` property can be used to store any data about the accessory you may need
1050
1030
  accessory.context.device = device;
1051
- accessory.context.model = device.deviceType;
1052
- accessory.context.deviceID = device.deviceId;
1053
- if (device.firmware) {
1054
- accessory.context.version = device.firmware;
1055
- }
1056
- accessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
1031
+ accessory.context.model = SwitchBotModel.Hub2;
1032
+ accessory.context.deviceId = device.deviceId;
1033
+ accessory.context.deviceType = device.deviceType;
1034
+ accessory.displayName = device.configDeviceName ?? device.deviceName;
1057
1035
  accessory.context.connectionType = await this.connectionType(device);
1036
+ accessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
1037
+ const newOrExternal = !device.external ? 'Adding new' : 'Loading external';
1038
+ await this.infoLog(`${newOrExternal} accessory: ${accessory.displayName} deviceId: ${device.deviceId}`);
1058
1039
  // create the accessory handler for the newly create accessory
1059
1040
  // this is imported from `platformAccessory.ts`
1060
1041
  new Hub(this, accessory, device);
@@ -1064,7 +1045,7 @@ export class SwitchBotPlatform {
1064
1045
  this.accessories.push(accessory);
1065
1046
  }
1066
1047
  else {
1067
- await this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
1048
+ await this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} deviceId: ${device.deviceId}`);
1068
1049
  }
1069
1050
  }
1070
1051
  async createIOSensor(device) {
@@ -1076,15 +1057,14 @@ export class SwitchBotPlatform {
1076
1057
  // the accessory already exists
1077
1058
  if (await this.registerDevice(device)) {
1078
1059
  // if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
1079
- existingAccessory.context.model = device.deviceType;
1080
- existingAccessory.context.deviceID = device.deviceId;
1081
- existingAccessory.displayName = device.configDeviceName || device.deviceName;
1082
- if (device.firmware) {
1083
- existingAccessory.context.version = device.firmware;
1084
- }
1085
- existingAccessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
1086
- this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
1060
+ existingAccessory.context.device = device;
1061
+ existingAccessory.context.model = SwitchBotModel.OutdoorMeter;
1062
+ existingAccessory.context.deviceId = device.deviceId;
1063
+ existingAccessory.context.deviceType = device.deviceType;
1064
+ existingAccessory.displayName = device.configDeviceName ?? device.deviceName;
1087
1065
  existingAccessory.context.connectionType = await this.connectionType(device);
1066
+ existingAccessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
1067
+ await this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`);
1088
1068
  this.api.updatePlatformAccessories([existingAccessory]);
1089
1069
  // create the accessory handler for the restored accessory
1090
1070
  // this is imported from `platformAccessory.ts`
@@ -1096,22 +1076,19 @@ export class SwitchBotPlatform {
1096
1076
  }
1097
1077
  }
1098
1078
  else if (await this.registerDevice(device)) {
1099
- // the accessory does not yet exist, so we need to create it
1100
- if (!device.external) {
1101
- this.infoLog(`Adding new accessory: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
1102
- }
1103
1079
  // create a new accessory
1104
1080
  const accessory = new this.api.platformAccessory(device.deviceName, uuid);
1105
1081
  // store a copy of the device object in the `accessory.context`
1106
1082
  // the `context` property can be used to store any data about the accessory you may need
1107
1083
  accessory.context.device = device;
1108
- accessory.context.model = device.deviceType;
1109
- accessory.context.deviceID = device.deviceId;
1110
- if (device.firmware) {
1111
- accessory.context.version = device.firmware;
1112
- }
1113
- accessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
1084
+ accessory.context.model = SwitchBotModel.OutdoorMeter;
1085
+ accessory.context.deviceId = device.deviceId;
1086
+ accessory.context.deviceType = device.deviceType;
1087
+ accessory.displayName = device.configDeviceName ?? device.deviceName;
1114
1088
  accessory.context.connectionType = await this.connectionType(device);
1089
+ accessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
1090
+ const newOrExternal = !device.external ? 'Adding new' : 'Loading external';
1091
+ await this.infoLog(`${newOrExternal} accessory: ${accessory.displayName} deviceId: ${device.deviceId}`);
1115
1092
  // create the accessory handler for the newly create accessory
1116
1093
  // this is imported from `platformAccessory.ts`
1117
1094
  new IOSensor(this, accessory, device);
@@ -1121,7 +1098,7 @@ export class SwitchBotPlatform {
1121
1098
  this.accessories.push(accessory);
1122
1099
  }
1123
1100
  else {
1124
- await this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
1101
+ await this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} deviceId: ${device.deviceId}`);
1125
1102
  }
1126
1103
  }
1127
1104
  async createWaterDetector(device) {
@@ -1133,15 +1110,14 @@ export class SwitchBotPlatform {
1133
1110
  // the accessory already exists
1134
1111
  if (await this.registerDevice(device)) {
1135
1112
  // if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
1136
- existingAccessory.context.model = device.deviceType;
1137
- existingAccessory.context.deviceID = device.deviceId;
1138
- existingAccessory.displayName = device.configDeviceName || device.deviceName;
1139
- if (device.firmware) {
1140
- existingAccessory.context.version = device.firmware;
1141
- }
1142
- existingAccessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
1143
- this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
1113
+ existingAccessory.context.device = device;
1114
+ existingAccessory.context.deviceId = device.deviceId;
1115
+ existingAccessory.context.deviceType = device.deviceType;
1116
+ existingAccessory.context.model = SwitchBotModel.WaterDetector;
1117
+ existingAccessory.displayName = device.configDeviceName ?? device.deviceName;
1144
1118
  existingAccessory.context.connectionType = await this.connectionType(device);
1119
+ existingAccessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
1120
+ this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`);
1145
1121
  this.api.updatePlatformAccessories([existingAccessory]);
1146
1122
  // create the accessory handler for the restored accessory
1147
1123
  // this is imported from `platformAccessory.ts`
@@ -1153,22 +1129,19 @@ export class SwitchBotPlatform {
1153
1129
  }
1154
1130
  }
1155
1131
  else if (await this.registerDevice(device)) {
1156
- // the accessory does not yet exist, so we need to create it
1157
- if (!device.external) {
1158
- this.infoLog(`Adding new accessory: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
1159
- }
1160
1132
  // create a new accessory
1161
1133
  const accessory = new this.api.platformAccessory(device.deviceName, uuid);
1162
1134
  // store a copy of the device object in the `accessory.context`
1163
1135
  // the `context` property can be used to store any data about the accessory you may need
1164
1136
  accessory.context.device = device;
1165
- accessory.context.model = device.deviceType;
1166
- accessory.context.deviceID = device.deviceId;
1167
- if (device.firmware) {
1168
- accessory.context.version = device.firmware;
1169
- }
1170
- accessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
1137
+ accessory.context.deviceId = device.deviceId;
1138
+ accessory.context.deviceType = device.deviceType;
1139
+ accessory.context.model = SwitchBotModel.WaterDetector;
1140
+ accessory.displayName = device.configDeviceName ?? device.deviceName;
1141
+ accessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
1171
1142
  accessory.context.connectionType = await this.connectionType(device);
1143
+ const newOrExternal = !device.external ? 'Adding new' : 'Loading external';
1144
+ await this.infoLog(`${newOrExternal} accessory: ${accessory.displayName} deviceId: ${device.deviceId}`);
1172
1145
  // create the accessory handler for the newly create accessory
1173
1146
  // this is imported from `platformAccessory.ts`
1174
1147
  new WaterDetector(this, accessory, device);
@@ -1178,7 +1151,7 @@ export class SwitchBotPlatform {
1178
1151
  this.accessories.push(accessory);
1179
1152
  }
1180
1153
  else {
1181
- await this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
1154
+ await this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} deviceId: ${device.deviceId}`);
1182
1155
  }
1183
1156
  }
1184
1157
  async createMotion(device) {
@@ -1190,15 +1163,14 @@ export class SwitchBotPlatform {
1190
1163
  // the accessory already exists
1191
1164
  if (await this.registerDevice(device)) {
1192
1165
  // if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
1193
- existingAccessory.context.model = device.deviceType;
1194
- existingAccessory.context.deviceID = device.deviceId;
1195
- existingAccessory.displayName = device.configDeviceName || device.deviceName;
1196
- if (device.firmware) {
1197
- existingAccessory.context.version = device.firmware;
1198
- }
1199
- existingAccessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
1200
- this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
1166
+ existingAccessory.context.device = device;
1167
+ existingAccessory.context.deviceId = device.deviceId;
1168
+ existingAccessory.context.deviceType = device.deviceType;
1169
+ existingAccessory.context.model = SwitchBotModel.MotionSensor;
1170
+ existingAccessory.displayName = device.configDeviceName ?? device.deviceName;
1201
1171
  existingAccessory.context.connectionType = await this.connectionType(device);
1172
+ existingAccessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
1173
+ this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`);
1202
1174
  this.api.updatePlatformAccessories([existingAccessory]);
1203
1175
  // create the accessory handler for the restored accessory
1204
1176
  // this is imported from `platformAccessory.ts`
@@ -1210,22 +1182,19 @@ export class SwitchBotPlatform {
1210
1182
  }
1211
1183
  }
1212
1184
  else if (await this.registerDevice(device)) {
1213
- // the accessory does not yet exist, so we need to create it
1214
- if (!device.external) {
1215
- this.infoLog(`Adding new accessory: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
1216
- }
1217
1185
  // create a new accessory
1218
1186
  const accessory = new this.api.platformAccessory(device.deviceName, uuid);
1219
1187
  // store a copy of the device object in the `accessory.context`
1220
1188
  // the `context` property can be used to store any data about the accessory you may need
1221
1189
  accessory.context.device = device;
1222
- accessory.context.model = device.deviceType;
1223
- accessory.context.deviceID = device.deviceId;
1224
- if (device.firmware) {
1225
- accessory.context.version = device.firmware;
1226
- }
1227
- accessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
1190
+ accessory.context.deviceId = device.deviceId;
1191
+ accessory.context.deviceType = device.deviceType;
1192
+ accessory.context.model = SwitchBotModel.MotionSensor;
1193
+ accessory.displayName = device.configDeviceName ?? device.deviceName;
1228
1194
  accessory.context.connectionType = await this.connectionType(device);
1195
+ accessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
1196
+ const newOrExternal = !device.external ? 'Adding new' : 'Loading external';
1197
+ await this.infoLog(`${newOrExternal} accessory: ${accessory.displayName} deviceId: ${device.deviceId}`);
1229
1198
  // create the accessory handler for the newly create accessory
1230
1199
  // this is imported from `platformAccessory.ts`
1231
1200
  new Motion(this, accessory, device);
@@ -1235,7 +1204,7 @@ export class SwitchBotPlatform {
1235
1204
  this.accessories.push(accessory);
1236
1205
  }
1237
1206
  else {
1238
- await this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
1207
+ await this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} deviceId: ${device.deviceId}`);
1239
1208
  }
1240
1209
  }
1241
1210
  async createContact(device) {
@@ -1247,15 +1216,14 @@ export class SwitchBotPlatform {
1247
1216
  // the accessory already exists
1248
1217
  if (await this.registerDevice(device)) {
1249
1218
  // if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
1250
- existingAccessory.context.model = device.deviceType;
1251
- existingAccessory.context.deviceID = device.deviceId;
1252
- existingAccessory.displayName = device.configDeviceName || device.deviceName;
1253
- if (device.firmware) {
1254
- existingAccessory.context.version = device.firmware;
1255
- }
1256
- existingAccessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
1257
- this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
1219
+ existingAccessory.context.device = device;
1220
+ existingAccessory.context.deviceId = device.deviceId;
1221
+ existingAccessory.context.deviceType = device.deviceType;
1222
+ existingAccessory.context.model = SwitchBotModel.ContactSensor;
1223
+ existingAccessory.displayName = device.configDeviceName ?? device.deviceName;
1258
1224
  existingAccessory.context.connectionType = await this.connectionType(device);
1225
+ existingAccessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
1226
+ this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`);
1259
1227
  this.api.updatePlatformAccessories([existingAccessory]);
1260
1228
  // create the accessory handler for the restored accessory
1261
1229
  // this is imported from `platformAccessory.ts`
@@ -1267,22 +1235,19 @@ export class SwitchBotPlatform {
1267
1235
  }
1268
1236
  }
1269
1237
  else if (await this.registerDevice(device)) {
1270
- // the accessory does not yet exist, so we need to create it
1271
- if (!device.external) {
1272
- this.infoLog(`Adding new accessory: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
1273
- }
1274
1238
  // create a new accessory
1275
1239
  const accessory = new this.api.platformAccessory(device.deviceName, uuid);
1276
1240
  // store a copy of the device object in the `accessory.context`
1277
1241
  // the `context` property can be used to store any data about the accessory you may need
1278
1242
  accessory.context.device = device;
1279
- accessory.context.model = device.deviceType;
1280
- accessory.context.deviceID = device.deviceId;
1281
- if (device.firmware) {
1282
- accessory.context.version = device.firmware;
1283
- }
1284
- accessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
1243
+ accessory.context.deviceId = device.deviceId;
1244
+ accessory.context.deviceType = device.deviceType;
1245
+ accessory.context.model = SwitchBotModel.ContactSensor;
1246
+ accessory.displayName = device.configDeviceName ?? device.deviceName;
1285
1247
  accessory.context.connectionType = await this.connectionType(device);
1248
+ accessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
1249
+ const newOrExternal = !device.external ? 'Adding new' : 'Loading external';
1250
+ await this.infoLog(`${newOrExternal} accessory: ${accessory.displayName} deviceId: ${device.deviceId}`);
1286
1251
  // create the accessory handler for the newly create accessory
1287
1252
  // this is imported from `platformAccessory.ts`
1288
1253
  new Contact(this, accessory, device);
@@ -1292,7 +1257,7 @@ export class SwitchBotPlatform {
1292
1257
  this.accessories.push(accessory);
1293
1258
  }
1294
1259
  else {
1295
- await this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
1260
+ await this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} deviceId: ${device.deviceId}`);
1296
1261
  }
1297
1262
  }
1298
1263
  async createBlindTilt(device) {
@@ -1304,15 +1269,14 @@ export class SwitchBotPlatform {
1304
1269
  // the accessory already exists
1305
1270
  if (await this.registerDevice(device)) {
1306
1271
  // if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
1307
- existingAccessory.context.model = device.deviceType;
1308
- existingAccessory.context.deviceID = device.deviceId;
1309
- existingAccessory.displayName = device.configDeviceName || device.deviceName;
1310
- if (device.firmware) {
1311
- existingAccessory.context.version = device.firmware;
1312
- }
1313
- existingAccessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
1314
- this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
1272
+ existingAccessory.context.device = device;
1273
+ existingAccessory.context.deviceId = device.deviceId;
1274
+ existingAccessory.context.deviceType = device.deviceType;
1275
+ existingAccessory.context.model = SwitchBotModel.BlindTilt;
1276
+ existingAccessory.displayName = device.configDeviceName ?? device.deviceName;
1315
1277
  existingAccessory.context.connectionType = await this.connectionType(device);
1278
+ existingAccessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
1279
+ this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`);
1316
1280
  this.api.updatePlatformAccessories([existingAccessory]);
1317
1281
  // create the accessory handler for the restored accessory
1318
1282
  // this is imported from `platformAccessory.ts`
@@ -1324,21 +1288,17 @@ export class SwitchBotPlatform {
1324
1288
  }
1325
1289
  }
1326
1290
  else if (await this.registerDevice(device)) {
1327
- // the accessory does not yet exist, so we need to create it
1328
- if (!device.external) {
1329
- this.infoLog(`Adding new accessory: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
1330
- }
1331
1291
  if (isBlindTiltDevice(device)) {
1332
1292
  if (device.group && !device.curtain?.disable_group) {
1333
1293
  this.debugLog('Your Curtains are grouped, ' +
1334
- `, Secondary curtain automatically hidden. Main Curtain: ${device.deviceName}, DeviceID: ${device.deviceId}`);
1294
+ `, Secondary curtain automatically hidden. Main Curtain: ${device.deviceName}, deviceId: ${device.deviceId}`);
1335
1295
  }
1336
1296
  else {
1337
1297
  if (device.master) {
1338
- this.warnLog(`Main Curtain: ${device.deviceName}, DeviceID: ${device.deviceId}`);
1298
+ this.warnLog(`Main Curtain: ${device.deviceName}, deviceId: ${device.deviceId}`);
1339
1299
  }
1340
1300
  else {
1341
- this.errorLog(`Secondary Curtain: ${device.deviceName}, DeviceID: ${device.deviceId}`);
1301
+ this.errorLog(`Secondary Curtain: ${device.deviceName}, deviceId: ${device.deviceId}`);
1342
1302
  }
1343
1303
  }
1344
1304
  }
@@ -1347,13 +1307,15 @@ export class SwitchBotPlatform {
1347
1307
  // store a copy of the device object in the `accessory.context`
1348
1308
  // the `context` property can be used to store any data about the accessory you may need
1349
1309
  accessory.context.device = device;
1350
- accessory.context.model = device.deviceType;
1351
- accessory.context.deviceID = device.deviceId;
1352
- if (device.firmware) {
1353
- accessory.context.version = device.firmware;
1354
- }
1355
- accessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
1310
+ ;
1311
+ accessory.context.deviceId = device.deviceId;
1312
+ accessory.context.deviceType = device.deviceType;
1313
+ accessory.context.model = SwitchBotModel.BlindTilt;
1314
+ accessory.displayName = device.configDeviceName ?? device.deviceName;
1356
1315
  accessory.context.connectionType = await this.connectionType(device);
1316
+ accessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
1317
+ const newOrExternal = !device.external ? 'Adding new' : 'Loading external';
1318
+ await this.infoLog(`${newOrExternal} accessory: ${accessory.displayName} deviceId: ${device.deviceId}`);
1357
1319
  // create the accessory handler for the newly create accessory
1358
1320
  // this is imported from `platformAccessory.ts`
1359
1321
  new BlindTilt(this, accessory, device);
@@ -1363,7 +1325,7 @@ export class SwitchBotPlatform {
1363
1325
  this.accessories.push(accessory);
1364
1326
  }
1365
1327
  else {
1366
- await this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
1328
+ await this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} deviceId: ${device.deviceId}`);
1367
1329
  }
1368
1330
  }
1369
1331
  async createCurtain(device) {
@@ -1375,15 +1337,14 @@ export class SwitchBotPlatform {
1375
1337
  // the accessory already exists
1376
1338
  if (await this.registerDevice(device)) {
1377
1339
  // if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
1378
- existingAccessory.context.model = device.deviceType;
1379
- existingAccessory.context.deviceID = device.deviceId;
1380
- existingAccessory.displayName = device.configDeviceName || device.deviceName;
1381
- if (device.firmware) {
1382
- existingAccessory.context.version = device.firmware;
1383
- }
1384
- existingAccessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
1385
- this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
1340
+ existingAccessory.context.device = device;
1341
+ existingAccessory.context.deviceId = device.deviceId;
1342
+ existingAccessory.context.deviceType = device.deviceType;
1343
+ existingAccessory.context.model = device.deviceType === 'Curtain3' ? SwitchBotModel.Curtain3 : SwitchBotModel.Curtain;
1344
+ existingAccessory.displayName = device.configDeviceName ?? device.deviceName;
1386
1345
  existingAccessory.context.connectionType = await this.connectionType(device);
1346
+ existingAccessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
1347
+ await this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`);
1387
1348
  this.api.updatePlatformAccessories([existingAccessory]);
1388
1349
  // create the accessory handler for the restored accessory
1389
1350
  // this is imported from `platformAccessory.ts`
@@ -1395,21 +1356,17 @@ export class SwitchBotPlatform {
1395
1356
  }
1396
1357
  }
1397
1358
  else if (await this.registerDevice(device)) {
1398
- // the accessory does not yet exist, so we need to create it
1399
- if (!device.external) {
1400
- this.infoLog(`Adding new accessory: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
1401
- }
1402
1359
  if (isCurtainDevice(device)) {
1403
1360
  if (device.group && !device.curtain?.disable_group) {
1404
1361
  this.debugLog('Your Curtains are grouped, ' +
1405
- `, Secondary curtain automatically hidden. Main Curtain: ${device.deviceName}, DeviceID: ${device.deviceId}`);
1362
+ `, Secondary curtain automatically hidden. Main Curtain: ${device.deviceName}, deviceId: ${device.deviceId}`);
1406
1363
  }
1407
1364
  else {
1408
1365
  if (device.master) {
1409
- this.warnLog(`Main Curtain: ${device.deviceName}, DeviceID: ${device.deviceId}`);
1366
+ this.warnLog(`Main Curtain: ${device.deviceName}, deviceId: ${device.deviceId}`);
1410
1367
  }
1411
1368
  else {
1412
- this.errorLog(`Secondary Curtain: ${device.deviceName}, DeviceID: ${device.deviceId}`);
1369
+ this.errorLog(`Secondary Curtain: ${device.deviceName}, deviceId: ${device.deviceId}`);
1413
1370
  }
1414
1371
  }
1415
1372
  }
@@ -1418,13 +1375,14 @@ export class SwitchBotPlatform {
1418
1375
  // store a copy of the device object in the `accessory.context`
1419
1376
  // the `context` property can be used to store any data about the accessory you may need
1420
1377
  accessory.context.device = device;
1421
- accessory.context.model = device.deviceType;
1422
- accessory.context.deviceID = device.deviceId;
1423
- if (device.firmware) {
1424
- accessory.context.version = device.firmware;
1425
- }
1426
- accessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
1378
+ accessory.context.deviceId = device.deviceId;
1379
+ accessory.context.deviceType = device.deviceType;
1380
+ accessory.context.model = device.deviceType === 'Curtain3' ? SwitchBotModel.Curtain3 : SwitchBotModel.Curtain;
1381
+ accessory.displayName = device.configDeviceName ?? device.deviceName;
1427
1382
  accessory.context.connectionType = await this.connectionType(device);
1383
+ accessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
1384
+ const newOrExternal = !device.external ? 'Adding new' : 'Loading external';
1385
+ await this.infoLog(`${newOrExternal} accessory: ${accessory.displayName} deviceId: ${device.deviceId}`);
1428
1386
  // create the accessory handler for the newly create accessory
1429
1387
  // this is imported from `platformAccessory.ts`
1430
1388
  new Curtain(this, accessory, device);
@@ -1434,7 +1392,7 @@ export class SwitchBotPlatform {
1434
1392
  this.accessories.push(accessory);
1435
1393
  }
1436
1394
  else {
1437
- await this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
1395
+ await this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} deviceId: ${device.deviceId}`);
1438
1396
  }
1439
1397
  }
1440
1398
  async createPlug(device) {
@@ -1446,15 +1404,15 @@ export class SwitchBotPlatform {
1446
1404
  // the accessory already exists
1447
1405
  if (await this.registerDevice(device)) {
1448
1406
  // if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
1449
- existingAccessory.context.model = device.deviceType;
1450
- existingAccessory.context.deviceID = device.deviceId;
1451
- existingAccessory.displayName = device.configDeviceName || device.deviceName;
1452
- if (device.firmware) {
1453
- existingAccessory.context.version = device.firmware;
1454
- }
1455
- existingAccessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
1456
- 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 === 'Plug Mini (US)' ? SwitchBotModel.PlugMiniUS : device.deviceType === 'Plug Mini (JP)'
1411
+ ? SwitchBotModel.PlugMiniJP : SwitchBotModel.Plug;
1412
+ existingAccessory.displayName = device.configDeviceName ?? device.deviceName;
1457
1413
  existingAccessory.context.connectionType = await this.connectionType(device);
1414
+ existingAccessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
1415
+ await this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`);
1458
1416
  this.api.updatePlatformAccessories([existingAccessory]);
1459
1417
  // create the accessory handler for the restored accessory
1460
1418
  // this is imported from `platformAccessory.ts`
@@ -1466,22 +1424,20 @@ export class SwitchBotPlatform {
1466
1424
  }
1467
1425
  }
1468
1426
  else if (await this.registerDevice(device)) {
1469
- // the accessory does not yet exist, so we need to create it
1470
- if (!device.external) {
1471
- this.infoLog(`Adding new accessory: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
1472
- }
1473
1427
  // create a new accessory
1474
1428
  const accessory = new this.api.platformAccessory(device.deviceName, uuid);
1475
1429
  // store a copy of the device object in the `accessory.context`
1476
1430
  // the `context` property can be used to store any data about the accessory you may need
1477
1431
  accessory.context.device = device;
1478
- accessory.context.model = device.deviceType;
1479
- accessory.context.deviceID = device.deviceId;
1480
- if (device.firmware) {
1481
- accessory.context.version = device.firmware;
1482
- }
1483
- accessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
1432
+ accessory.context.deviceId = device.deviceId;
1433
+ accessory.context.deviceType = device.deviceType;
1434
+ accessory.context.model = device.deviceType === 'Plug Mini (US)' ? SwitchBotModel.PlugMiniUS : device.deviceType === 'Plug Mini (JP)'
1435
+ ? SwitchBotModel.PlugMiniJP : SwitchBotModel.Plug;
1436
+ accessory.displayName = device.configDeviceName ?? device.deviceName;
1484
1437
  accessory.context.connectionType = await this.connectionType(device);
1438
+ accessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
1439
+ const newOrExternal = !device.external ? 'Adding new' : 'Loading external';
1440
+ await this.infoLog(`${newOrExternal} accessory: ${accessory.displayName} deviceId: ${device.deviceId}`);
1485
1441
  // create the accessory handler for the newly create accessory
1486
1442
  // this is imported from `platformAccessory.ts`
1487
1443
  new Plug(this, accessory, device);
@@ -1491,7 +1447,7 @@ export class SwitchBotPlatform {
1491
1447
  this.accessories.push(accessory);
1492
1448
  }
1493
1449
  else {
1494
- await this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
1450
+ await this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} deviceId: ${device.deviceId}`);
1495
1451
  }
1496
1452
  }
1497
1453
  async createLock(device) {
@@ -1503,15 +1459,14 @@ export class SwitchBotPlatform {
1503
1459
  // the accessory already exists
1504
1460
  if (await this.registerDevice(device)) {
1505
1461
  // if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
1506
- existingAccessory.context.model = device.deviceType;
1507
- existingAccessory.context.deviceID = device.deviceId;
1508
- existingAccessory.displayName = device.configDeviceName || device.deviceName;
1509
- if (device.firmware) {
1510
- existingAccessory.context.version = device.firmware;
1511
- }
1512
- existingAccessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
1513
- this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
1462
+ existingAccessory.context.device = device;
1463
+ existingAccessory.context.deviceId = device.deviceId;
1464
+ existingAccessory.context.deviceType = device.deviceType;
1465
+ existingAccessory.context.model = device.deviceType === 'Smart Lock Pro' ? SwitchBotModel.LockPro : SwitchBotModel.Lock;
1466
+ existingAccessory.displayName = device.configDeviceName ?? device.deviceName;
1514
1467
  existingAccessory.context.connectionType = await this.connectionType(device);
1468
+ existingAccessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
1469
+ this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`);
1515
1470
  this.api.updatePlatformAccessories([existingAccessory]);
1516
1471
  // create the accessory handler for the restored accessory
1517
1472
  // this is imported from `platformAccessory.ts`
@@ -1523,22 +1478,19 @@ export class SwitchBotPlatform {
1523
1478
  }
1524
1479
  }
1525
1480
  else if (await this.registerDevice(device)) {
1526
- // the accessory does not yet exist, so we need to create it
1527
- if (!device.external) {
1528
- this.infoLog(`Adding new accessory: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
1529
- }
1530
1481
  // create a new accessory
1531
1482
  const accessory = new this.api.platformAccessory(device.deviceName, uuid);
1532
1483
  // store a copy of the device object in the `accessory.context`
1533
1484
  // the `context` property can be used to store any data about the accessory you may need
1534
1485
  accessory.context.device = device;
1535
- accessory.context.model = device.deviceType;
1536
- accessory.context.deviceID = device.deviceId;
1537
- if (device.firmware) {
1538
- accessory.context.version = device.firmware;
1539
- }
1540
- accessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
1486
+ accessory.context.deviceId = device.deviceId;
1487
+ accessory.context.deviceType = device.deviceType;
1488
+ accessory.context.model = device.deviceType === 'Smart Lock Pro' ? SwitchBotModel.LockPro : SwitchBotModel.Lock;
1489
+ accessory.displayName = device.configDeviceName ?? device.deviceName;
1541
1490
  accessory.context.connectionType = await this.connectionType(device);
1491
+ accessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
1492
+ const newOrExternal = !device.external ? 'Adding new' : 'Loading external';
1493
+ await this.infoLog(`${newOrExternal} accessory: ${accessory.displayName} deviceId: ${device.deviceId}`);
1542
1494
  // create the accessory handler for the newly create accessory
1543
1495
  // this is imported from `platformAccessory.ts`
1544
1496
  new Lock(this, accessory, device);
@@ -1548,7 +1500,7 @@ export class SwitchBotPlatform {
1548
1500
  this.accessories.push(accessory);
1549
1501
  }
1550
1502
  else {
1551
- await this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
1503
+ await this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} deviceId: ${device.deviceId}`);
1552
1504
  }
1553
1505
  }
1554
1506
  async createColorBulb(device) {
@@ -1560,15 +1512,14 @@ export class SwitchBotPlatform {
1560
1512
  // the accessory already exists
1561
1513
  if (await this.registerDevice(device)) {
1562
1514
  // if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
1563
- existingAccessory.context.model = device.deviceType;
1564
- existingAccessory.context.deviceID = device.deviceId;
1565
- existingAccessory.displayName = device.configDeviceName || device.deviceName;
1566
- if (device.firmware) {
1567
- existingAccessory.context.version = device.firmware;
1568
- }
1569
- existingAccessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
1570
- this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
1515
+ existingAccessory.context.device = device;
1516
+ existingAccessory.context.deviceId = device.deviceId;
1517
+ existingAccessory.context.deviceType = device.deviceType;
1518
+ existingAccessory.context.model = SwitchBotModel.ColorBulb;
1519
+ existingAccessory.displayName = device.configDeviceName ?? device.deviceName;
1571
1520
  existingAccessory.context.connectionType = await this.connectionType(device);
1521
+ existingAccessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
1522
+ await this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`);
1572
1523
  this.api.updatePlatformAccessories([existingAccessory]);
1573
1524
  // create the accessory handler for the restored accessory
1574
1525
  // this is imported from `platformAccessory.ts`
@@ -1580,22 +1531,19 @@ export class SwitchBotPlatform {
1580
1531
  }
1581
1532
  }
1582
1533
  else if (await this.registerDevice(device)) {
1583
- // the accessory does not yet exist, so we need to create it
1584
- if (!device.external) {
1585
- this.infoLog(`Adding new accessory: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
1586
- }
1587
1534
  // create a new accessory
1588
1535
  const accessory = new this.api.platformAccessory(device.deviceName, uuid);
1589
1536
  // store a copy of the device object in the `accessory.context`
1590
1537
  // the `context` property can be used to store any data about the accessory you may need
1591
1538
  accessory.context.device = device;
1592
- accessory.context.model = device.deviceType;
1593
- accessory.context.deviceID = device.deviceId;
1594
- if (device.firmware) {
1595
- accessory.context.version = device.firmware;
1596
- }
1597
- accessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
1539
+ accessory.context.deviceId = device.deviceId;
1540
+ accessory.context.deviceType = device.deviceType;
1541
+ accessory.context.model = SwitchBotModel.ColorBulb;
1542
+ accessory.displayName = device.configDeviceName ?? device.deviceName;
1598
1543
  accessory.context.connectionType = await this.connectionType(device);
1544
+ accessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
1545
+ const newOrExternal = !device.external ? 'Adding new' : 'Loading external';
1546
+ await this.infoLog(`${newOrExternal} accessory: ${accessory.displayName} deviceId: ${device.deviceId}`);
1599
1547
  // create the accessory handler for the newly create accessory
1600
1548
  // this is imported from `platformAccessory.ts`
1601
1549
  new ColorBulb(this, accessory, device);
@@ -1605,7 +1553,7 @@ export class SwitchBotPlatform {
1605
1553
  this.accessories.push(accessory);
1606
1554
  }
1607
1555
  else {
1608
- await this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
1556
+ await this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} deviceId: ${device.deviceId}`);
1609
1557
  }
1610
1558
  }
1611
1559
  async createCeilingLight(device) {
@@ -1617,15 +1565,14 @@ export class SwitchBotPlatform {
1617
1565
  // the accessory already exists
1618
1566
  if (await this.registerDevice(device)) {
1619
1567
  // if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
1620
- existingAccessory.context.model = device.deviceType;
1621
- existingAccessory.context.deviceID = device.deviceId;
1622
- existingAccessory.displayName = device.configDeviceName || device.deviceName;
1623
- if (device.firmware) {
1624
- existingAccessory.context.version = device.firmware;
1625
- }
1626
- existingAccessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
1627
- this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
1568
+ existingAccessory.context.device = device;
1569
+ existingAccessory.context.deviceId = device.deviceId;
1570
+ existingAccessory.context.deviceType = device.deviceType;
1571
+ existingAccessory.context.model = device.deviceType === 'Ceiling Light Pro' ? SwitchBotModel.CeilingLightPro : SwitchBotModel.CeilingLight;
1572
+ existingAccessory.displayName = device.configDeviceName ?? device.deviceName;
1628
1573
  existingAccessory.context.connectionType = await this.connectionType(device);
1574
+ existingAccessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
1575
+ await this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`);
1629
1576
  this.api.updatePlatformAccessories([existingAccessory]);
1630
1577
  // create the accessory handler for the restored accessory
1631
1578
  // this is imported from `platformAccessory.ts`
@@ -1637,22 +1584,19 @@ export class SwitchBotPlatform {
1637
1584
  }
1638
1585
  }
1639
1586
  else if (await this.registerDevice(device)) {
1640
- // the accessory does not yet exist, so we need to create it
1641
- if (!device.external) {
1642
- this.infoLog(`Adding new accessory: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
1643
- }
1644
1587
  // create a new accessory
1645
1588
  const accessory = new this.api.platformAccessory(device.deviceName, uuid);
1646
1589
  // store a copy of the device object in the `accessory.context`
1647
1590
  // the `context` property can be used to store any data about the accessory you may need
1648
1591
  accessory.context.device = device;
1649
- accessory.context.model = device.deviceType;
1650
- accessory.context.deviceID = device.deviceId;
1651
- if (device.firmware) {
1652
- accessory.context.version = device.firmware;
1653
- }
1654
- accessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
1592
+ accessory.context.deviceId = device.deviceId;
1593
+ accessory.context.deviceType = device.deviceType;
1594
+ accessory.context.model = device.deviceType === 'Ceiling Light Pro' ? SwitchBotModel.CeilingLightPro : SwitchBotModel.CeilingLight;
1595
+ accessory.displayName = device.configDeviceName ?? device.deviceName;
1655
1596
  accessory.context.connectionType = await this.connectionType(device);
1597
+ accessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
1598
+ const newOrExternal = !device.external ? 'Adding new' : 'Loading external';
1599
+ await this.infoLog(`${newOrExternal} accessory: ${accessory.displayName} deviceId: ${device.deviceId}`);
1656
1600
  // create the accessory handler for the newly create accessory
1657
1601
  // this is imported from `platformAccessory.ts`
1658
1602
  new CeilingLight(this, accessory, device);
@@ -1662,7 +1606,7 @@ export class SwitchBotPlatform {
1662
1606
  this.accessories.push(accessory);
1663
1607
  }
1664
1608
  else {
1665
- await this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
1609
+ await this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} deviceId: ${device.deviceId}`);
1666
1610
  }
1667
1611
  }
1668
1612
  async createStripLight(device) {
@@ -1674,15 +1618,14 @@ export class SwitchBotPlatform {
1674
1618
  // the accessory already exists
1675
1619
  if (await this.registerDevice(device)) {
1676
1620
  // if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
1677
- existingAccessory.context.model = device.deviceType;
1678
- existingAccessory.context.deviceID = device.deviceId;
1679
- existingAccessory.displayName = device.configDeviceName || device.deviceName;
1680
- if (device.firmware) {
1681
- existingAccessory.context.version = device.firmware;
1682
- }
1683
- existingAccessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
1684
- this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
1621
+ existingAccessory.context.device = device;
1622
+ existingAccessory.context.deviceId = device.deviceId;
1623
+ existingAccessory.context.deviceType = device.deviceType;
1624
+ existingAccessory.context.model = SwitchBotModel.StripLight;
1625
+ existingAccessory.displayName = device.configDeviceName ?? device.deviceName;
1685
1626
  existingAccessory.context.connectionType = await this.connectionType(device);
1627
+ existingAccessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
1628
+ await this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`);
1686
1629
  this.api.updatePlatformAccessories([existingAccessory]);
1687
1630
  // create the accessory handler for the restored accessory
1688
1631
  // this is imported from `platformAccessory.ts`
@@ -1694,22 +1637,19 @@ export class SwitchBotPlatform {
1694
1637
  }
1695
1638
  }
1696
1639
  else if (await this.registerDevice(device)) {
1697
- // the accessory does not yet exist, so we need to create it
1698
- if (!device.external) {
1699
- this.infoLog(`Adding new accessory: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
1700
- }
1701
1640
  // create a new accessory
1702
1641
  const accessory = new this.api.platformAccessory(device.deviceName, uuid);
1703
1642
  // store a copy of the device object in the `accessory.context`
1704
1643
  // the `context` property can be used to store any data about the accessory you may need
1705
1644
  accessory.context.device = device;
1706
- accessory.context.model = device.deviceType;
1707
- accessory.context.deviceID = device.deviceId;
1708
- if (device.firmware) {
1709
- accessory.context.version = device.firmware;
1710
- }
1711
- accessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
1645
+ accessory.context.deviceId = device.deviceId;
1646
+ accessory.context.deviceType = device.deviceType;
1647
+ accessory.context.model = SwitchBotModel.StripLight;
1648
+ accessory.displayName = device.configDeviceName ?? device.deviceName;
1712
1649
  accessory.context.connectionType = await this.connectionType(device);
1650
+ accessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
1651
+ const newOrExternal = !device.external ? 'Adding new' : 'Loading external';
1652
+ await this.infoLog(`${newOrExternal} accessory: ${accessory.displayName} deviceId: ${device.deviceId}`);
1713
1653
  // create the accessory handler for the newly create accessory
1714
1654
  // this is imported from `platformAccessory.ts`
1715
1655
  new StripLight(this, accessory, device);
@@ -1719,7 +1659,7 @@ export class SwitchBotPlatform {
1719
1659
  this.accessories.push(accessory);
1720
1660
  }
1721
1661
  else {
1722
- await this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
1662
+ await this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} deviceId: ${device.deviceId}`);
1723
1663
  }
1724
1664
  }
1725
1665
  async createFan(device) {
@@ -1731,15 +1671,14 @@ export class SwitchBotPlatform {
1731
1671
  // the accessory already exists
1732
1672
  if (await this.registerDevice(device)) {
1733
1673
  // if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
1734
- existingAccessory.context.model = device.deviceType;
1735
- existingAccessory.context.deviceID = device.deviceId;
1736
- existingAccessory.displayName = device.configDeviceName || device.deviceName;
1737
- if (device.firmware) {
1738
- existingAccessory.context.version = device.firmware;
1739
- }
1740
- existingAccessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
1741
- this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
1674
+ existingAccessory.context.device = device;
1675
+ existingAccessory.context.deviceId = device.deviceId;
1676
+ existingAccessory.context.deviceType = device.deviceType;
1677
+ existingAccessory.context.model = SwitchBotModel.BatteryCirculatorFan;
1678
+ existingAccessory.displayName = device.configDeviceName ?? device.deviceName;
1742
1679
  existingAccessory.context.connectionType = await this.connectionType(device);
1680
+ existingAccessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
1681
+ await this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`);
1743
1682
  this.api.updatePlatformAccessories([existingAccessory]);
1744
1683
  // create the accessory handler for the restored accessory
1745
1684
  // this is imported from `platformAccessory.ts`
@@ -1751,22 +1690,19 @@ export class SwitchBotPlatform {
1751
1690
  }
1752
1691
  }
1753
1692
  else if (await this.registerDevice(device)) {
1754
- // the accessory does not yet exist, so we need to create it
1755
- if (!device.external) {
1756
- this.infoLog(`Adding new accessory: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
1757
- }
1758
1693
  // create a new accessory
1759
1694
  const accessory = new this.api.platformAccessory(device.deviceName, uuid);
1760
1695
  // store a copy of the device object in the `accessory.context`
1761
1696
  // the `context` property can be used to store any data about the accessory you may need
1762
1697
  accessory.context.device = device;
1763
- accessory.context.model = device.deviceType;
1764
- accessory.context.deviceID = device.deviceId;
1765
- if (device.firmware) {
1766
- accessory.context.version = device.firmware;
1767
- }
1768
- accessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
1698
+ accessory.context.deviceId = device.deviceId;
1699
+ accessory.context.deviceType = device.deviceType;
1700
+ accessory.context.model = SwitchBotModel.BatteryCirculatorFan;
1701
+ accessory.displayName = device.configDeviceName ?? device.deviceName;
1769
1702
  accessory.context.connectionType = await this.connectionType(device);
1703
+ accessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
1704
+ const newOrExternal = !device.external ? 'Adding new' : 'Loading external';
1705
+ await this.infoLog(`${newOrExternal} accessory: ${accessory.displayName} deviceId: ${device.deviceId}`);
1770
1706
  // create the accessory handler for the newly create accessory
1771
1707
  // this is imported from `platformAccessory.ts`
1772
1708
  new Fan(this, accessory, device);
@@ -1776,7 +1712,7 @@ export class SwitchBotPlatform {
1776
1712
  this.accessories.push(accessory);
1777
1713
  }
1778
1714
  else {
1779
- await this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
1715
+ await this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} deviceId: ${device.deviceId}`);
1780
1716
  }
1781
1717
  }
1782
1718
  async createRobotVacuumCleaner(device) {
@@ -1788,15 +1724,18 @@ export class SwitchBotPlatform {
1788
1724
  // the accessory already exists
1789
1725
  if (await this.registerDevice(device)) {
1790
1726
  // if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
1791
- existingAccessory.context.model = device.deviceType;
1792
- existingAccessory.context.deviceID = device.deviceId;
1793
- existingAccessory.displayName = device.configDeviceName || device.deviceName;
1794
- if (device.firmware) {
1795
- existingAccessory.context.version = device.firmware;
1796
- }
1797
- existingAccessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
1798
- this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
1727
+ existingAccessory.context.device = device;
1728
+ existingAccessory.context.deviceId = device.deviceId;
1729
+ existingAccessory.context.deviceType = device.deviceType;
1730
+ existingAccessory.context.model = device.deviceType === 'Robot Vacuum Cleaner S1' ? SwitchBotModel.RobotVacuumCleanerS1
1731
+ : device.deviceType === 'Robot Vacuum Cleaner S1 Plus' ? SwitchBotModel.RobotVacuumCleanerS1Plus
1732
+ : device.deviceType === 'Robot Vacuum Cleaner S10' ? SwitchBotModel.RobotVacuumCleanerS10
1733
+ : device.deviceType === 'WoSweeper' ? SwitchBotModel.WoSweeper : device.deviceType === 'WoSweeperMini' ? SwitchBotModel.WoSweeperMini
1734
+ : SwitchBotModel.Unknown;
1735
+ existingAccessory.displayName = device.configDeviceName ?? device.deviceName;
1799
1736
  existingAccessory.context.connectionType = await this.connectionType(device);
1737
+ existingAccessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
1738
+ await this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`);
1800
1739
  this.api.updatePlatformAccessories([existingAccessory]);
1801
1740
  // create the accessory handler for the restored accessory
1802
1741
  // this is imported from `platformAccessory.ts`
@@ -1808,22 +1747,23 @@ export class SwitchBotPlatform {
1808
1747
  }
1809
1748
  }
1810
1749
  else if (await this.registerDevice(device)) {
1811
- // the accessory does not yet exist, so we need to create it
1812
- if (!device.external) {
1813
- this.infoLog(`Adding new accessory: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
1814
- }
1815
1750
  // create a new accessory
1816
1751
  const accessory = new this.api.platformAccessory(device.deviceName, uuid);
1817
1752
  // store a copy of the device object in the `accessory.context`
1818
1753
  // the `context` property can be used to store any data about the accessory you may need
1819
1754
  accessory.context.device = device;
1820
- accessory.context.model = device.deviceType;
1821
- accessory.context.deviceID = device.deviceId;
1822
- if (device.firmware) {
1823
- accessory.context.version = device.firmware;
1824
- }
1825
- accessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
1755
+ accessory.context.deviceId = device.deviceId;
1756
+ accessory.context.deviceType = device.deviceType;
1757
+ accessory.context.model = device.deviceType === 'Robot Vacuum Cleaner S1' ? SwitchBotModel.RobotVacuumCleanerS1
1758
+ : device.deviceType === 'Robot Vacuum Cleaner S1 Plus' ? SwitchBotModel.RobotVacuumCleanerS1Plus
1759
+ : device.deviceType === 'Robot Vacuum Cleaner S10' ? SwitchBotModel.RobotVacuumCleanerS10
1760
+ : device.deviceType === 'WoSweeper' ? SwitchBotModel.WoSweeper : device.deviceType === 'WoSweeperMini' ? SwitchBotModel.WoSweeperMini
1761
+ : SwitchBotModel.Unknown;
1762
+ accessory.displayName = device.configDeviceName ?? device.deviceName;
1826
1763
  accessory.context.connectionType = await this.connectionType(device);
1764
+ accessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
1765
+ const newOrExternal = !device.external ? 'Adding new' : 'Loading external';
1766
+ await this.infoLog(`${newOrExternal} accessory: ${accessory.displayName} deviceId: ${device.deviceId}`);
1827
1767
  // create the accessory handler for the newly create accessory
1828
1768
  // this is imported from `platformAccessory.ts`
1829
1769
  new RobotVacuumCleaner(this, accessory, device);
@@ -1833,7 +1773,7 @@ export class SwitchBotPlatform {
1833
1773
  this.accessories.push(accessory);
1834
1774
  }
1835
1775
  else {
1836
- await this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
1776
+ await this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} deviceId: ${device.deviceId}`);
1837
1777
  }
1838
1778
  }
1839
1779
  async createTV(device) {
@@ -1843,11 +1783,12 @@ export class SwitchBotPlatform {
1843
1783
  const existingAccessory = this.accessories.find((accessory) => accessory.UUID === uuid);
1844
1784
  if (!device.hide_device && existingAccessory) {
1845
1785
  // if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
1846
- existingAccessory.context.model = device.remoteType;
1847
- existingAccessory.context.deviceID = device.deviceId;
1848
- existingAccessory.displayName = device.configDeviceName || device.deviceName;
1786
+ existingAccessory.context.device = device;
1787
+ existingAccessory.context.deviceId = device.deviceId;
1849
1788
  existingAccessory.context.deviceType = `IR: ${device.remoteType}`;
1850
- this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
1789
+ existingAccessory.context.model = device.remoteType;
1790
+ existingAccessory.displayName = device.configDeviceName ?? device.deviceName;
1791
+ await this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`);
1851
1792
  existingAccessory.context.connectionType = device.connectionType;
1852
1793
  this.api.updatePlatformAccessories([existingAccessory]);
1853
1794
  // create the accessory handler for the restored accessory
@@ -1856,22 +1797,19 @@ export class SwitchBotPlatform {
1856
1797
  await this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${existingAccessory.UUID})`);
1857
1798
  }
1858
1799
  else if (!device.hide_device && device.hubDeviceId) {
1859
- // the accessory does not yet exist, so we need to create it
1860
- if (!device.external) {
1861
- this.infoLog(`Adding new accessory: ${device.deviceName} ${device.remoteType} DeviceID: ${device.deviceId}`);
1862
- }
1863
1800
  // create a new accessory
1864
1801
  const accessory = new this.api.platformAccessory(device.deviceName, uuid);
1865
1802
  // store a copy of the device object in the `accessory.context`
1866
1803
  // the `context` property can be used to store any data about the accessory you may need
1867
1804
  accessory.context.device = device;
1868
- accessory.context.model = device.remoteType;
1869
- accessory.context.deviceID = device.deviceId;
1870
- if (device.firmware) {
1871
- accessory.context.version = device.firmware;
1872
- }
1805
+ accessory.context.deviceId = device.deviceId;
1873
1806
  accessory.context.deviceType = `IR: ${device.remoteType}`;
1807
+ accessory.context.model = device.remoteType;
1808
+ accessory.displayName = device.configDeviceName ?? device.deviceName;
1874
1809
  accessory.context.connectionType = device.connectionType;
1810
+ accessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
1811
+ const newOrExternal = !device.external ? 'Adding new' : 'Loading external';
1812
+ await this.infoLog(`${newOrExternal} accessory: ${accessory.displayName} deviceId: ${device.deviceId}`);
1875
1813
  // create the accessory handler for the newly create accessory
1876
1814
  // this is imported from `platformAccessory.ts`
1877
1815
  new TV(this, accessory, device);
@@ -1880,7 +1818,7 @@ export class SwitchBotPlatform {
1880
1818
  this.accessories.push(accessory);
1881
1819
  }
1882
1820
  else {
1883
- await this.debugLog(`Device not registered: ${device.deviceName} ${device.remoteType} DeviceID: ${device.deviceId}`);
1821
+ await this.debugLog(`Device not registered: ${device.deviceName} ${device.remoteType} deviceId: ${device.deviceId}`);
1884
1822
  }
1885
1823
  }
1886
1824
  async createIRFan(device) {
@@ -1892,14 +1830,12 @@ export class SwitchBotPlatform {
1892
1830
  // the accessory already exists
1893
1831
  if (!device.hide_device && device.hubDeviceId) {
1894
1832
  // if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
1895
- existingAccessory.context.model = device.remoteType;
1896
- existingAccessory.context.deviceID = device.deviceId;
1897
- existingAccessory.displayName = device.configDeviceName || device.deviceName;
1898
- if (device.firmware) {
1899
- existingAccessory.context.version = device.firmware;
1900
- }
1833
+ existingAccessory.context.device = device;
1834
+ existingAccessory.context.deviceId = device.deviceId;
1901
1835
  existingAccessory.context.deviceType = `IR: ${device.remoteType}`;
1902
- this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
1836
+ existingAccessory.context.model = device.remoteType;
1837
+ existingAccessory.displayName = device.configDeviceName ?? device.deviceName;
1838
+ await this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`);
1903
1839
  existingAccessory.context.connectionType = device.connectionType;
1904
1840
  this.api.updatePlatformAccessories([existingAccessory]);
1905
1841
  // create the accessory handler for the restored accessory
@@ -1912,22 +1848,19 @@ export class SwitchBotPlatform {
1912
1848
  }
1913
1849
  }
1914
1850
  else if (!device.hide_device && device.hubDeviceId) {
1915
- // the accessory does not yet exist, so we need to create it
1916
- if (!device.external) {
1917
- this.infoLog(`Adding new accessory: ${device.deviceName} ${device.remoteType} DeviceID: ${device.deviceId}`);
1918
- }
1919
1851
  // create a new accessory
1920
1852
  const accessory = new this.api.platformAccessory(device.deviceName, uuid);
1921
1853
  // store a copy of the device object in the `accessory.context`
1922
1854
  // the `context` property can be used to store any data about the accessory you may need
1923
1855
  accessory.context.device = device;
1924
- accessory.context.model = device.remoteType;
1925
- accessory.context.deviceID = device.deviceId;
1926
- if (device.firmware) {
1927
- accessory.context.version = device.firmware;
1928
- }
1856
+ accessory.context.deviceId = device.deviceId;
1929
1857
  accessory.context.deviceType = `IR: ${device.remoteType}`;
1858
+ accessory.context.model = device.remoteType;
1859
+ accessory.displayName = device.configDeviceName ?? device.deviceName;
1930
1860
  accessory.context.connectionType = device.connectionType;
1861
+ accessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
1862
+ const newOrExternal = !device.external ? 'Adding new' : 'Loading external';
1863
+ await this.infoLog(`${newOrExternal} accessory: ${accessory.displayName} deviceId: ${device.deviceId}`);
1931
1864
  // create the accessory handler for the newly create accessory
1932
1865
  // this is imported from `platformAccessory.ts`
1933
1866
  new IRFan(this, accessory, device);
@@ -1937,7 +1870,7 @@ export class SwitchBotPlatform {
1937
1870
  this.accessories.push(accessory);
1938
1871
  }
1939
1872
  else {
1940
- await this.debugLog(`Device not registered: ${device.deviceName} ${device.remoteType} DeviceID: ${device.deviceId}`);
1873
+ await this.debugLog(`Device not registered: ${device.deviceName} ${device.remoteType} deviceId: ${device.deviceId}`);
1941
1874
  }
1942
1875
  }
1943
1876
  async createLight(device) {
@@ -1949,14 +1882,12 @@ export class SwitchBotPlatform {
1949
1882
  // the accessory already exists
1950
1883
  if (!device.hide_device && device.hubDeviceId) {
1951
1884
  // if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
1952
- existingAccessory.context.model = device.remoteType;
1953
- existingAccessory.context.deviceID = device.deviceId;
1954
- existingAccessory.displayName = device.configDeviceName || device.deviceName;
1955
- if (device.firmware) {
1956
- existingAccessory.context.version = device.firmware;
1957
- }
1885
+ existingAccessory.context.device = device;
1886
+ existingAccessory.context.deviceId = device.deviceId;
1958
1887
  existingAccessory.context.deviceType = `IR: ${device.remoteType}`;
1959
- this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
1888
+ existingAccessory.context.model = device.remoteType;
1889
+ existingAccessory.displayName = device.configDeviceName ?? device.deviceName;
1890
+ await this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`);
1960
1891
  existingAccessory.context.connectionType = device.connectionType;
1961
1892
  this.api.updatePlatformAccessories([existingAccessory]);
1962
1893
  // create the accessory handler for the restored accessory
@@ -1969,22 +1900,19 @@ export class SwitchBotPlatform {
1969
1900
  }
1970
1901
  }
1971
1902
  else if (!device.hide_device && device.hubDeviceId) {
1972
- // the accessory does not yet exist, so we need to create it
1973
- if (!device.external) {
1974
- this.infoLog(`Adding new accessory: ${device.deviceName} ${device.remoteType} DeviceID: ${device.deviceId}`);
1975
- }
1976
1903
  // create a new accessory
1977
1904
  const accessory = new this.api.platformAccessory(device.deviceName, uuid);
1978
1905
  // store a copy of the device object in the `accessory.context`
1979
1906
  // the `context` property can be used to store any data about the accessory you may need
1980
1907
  accessory.context.device = device;
1981
- accessory.context.model = device.remoteType;
1982
- accessory.context.deviceID = device.deviceId;
1983
- if (device.firmware) {
1984
- accessory.context.version = device.firmware;
1985
- }
1908
+ accessory.context.deviceId = device.deviceId;
1986
1909
  accessory.context.deviceType = `IR: ${device.remoteType}`;
1910
+ accessory.context.model = device.remoteType;
1911
+ accessory.displayName = device.configDeviceName ?? device.deviceName;
1987
1912
  accessory.context.connectionType = device.connectionType;
1913
+ accessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
1914
+ const newOrExternal = !device.external ? 'Adding new' : 'Loading external';
1915
+ await this.infoLog(`${newOrExternal} accessory: ${accessory.displayName} deviceId: ${device.deviceId}`);
1988
1916
  // create the accessory handler for the newly create accessory
1989
1917
  // this is imported from `platformAccessory.ts`
1990
1918
  new Light(this, accessory, device);
@@ -1994,7 +1922,7 @@ export class SwitchBotPlatform {
1994
1922
  this.accessories.push(accessory);
1995
1923
  }
1996
1924
  else {
1997
- await this.debugLog(`Device not registered: ${device.deviceName} ${device.remoteType} DeviceID: ${device.deviceId}`);
1925
+ await this.debugLog(`Device not registered: ${device.deviceName} ${device.remoteType} deviceId: ${device.deviceId}`);
1998
1926
  }
1999
1927
  }
2000
1928
  async createAirConditioner(device) {
@@ -2006,14 +1934,12 @@ export class SwitchBotPlatform {
2006
1934
  // the accessory already exists
2007
1935
  if (!device.hide_device && device.hubDeviceId) {
2008
1936
  // if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
2009
- existingAccessory.context.model = device.remoteType;
2010
- existingAccessory.context.deviceID = device.deviceId;
2011
- existingAccessory.displayName = device.configDeviceName || device.deviceName;
2012
- if (device.firmware) {
2013
- existingAccessory.context.version = device.firmware;
2014
- }
1937
+ existingAccessory.context.device = device;
1938
+ existingAccessory.context.deviceId = device.deviceId;
2015
1939
  existingAccessory.context.deviceType = `IR: ${device.remoteType}`;
2016
- this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
1940
+ existingAccessory.context.model = device.remoteType;
1941
+ existingAccessory.displayName = device.configDeviceName ?? device.deviceName;
1942
+ await this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`);
2017
1943
  existingAccessory.context.connectionType = device.connectionType;
2018
1944
  this.api.updatePlatformAccessories([existingAccessory]);
2019
1945
  // create the accessory handler for the restored accessory
@@ -2026,22 +1952,19 @@ export class SwitchBotPlatform {
2026
1952
  }
2027
1953
  }
2028
1954
  else if (!device.hide_device && device.hubDeviceId) {
2029
- // the accessory does not yet exist, so we need to create it
2030
- if (!device.external) {
2031
- this.infoLog(`Adding new accessory: ${device.deviceName} ${device.remoteType} DeviceID: ${device.deviceId}`);
2032
- }
2033
1955
  // create a new accessory
2034
1956
  const accessory = new this.api.platformAccessory(device.deviceName, uuid);
2035
1957
  // store a copy of the device object in the `accessory.context`
2036
1958
  // the `context` property can be used to store any data about the accessory you may need
2037
1959
  accessory.context.device = device;
2038
- accessory.context.model = device.remoteType;
2039
- accessory.context.deviceID = device.deviceId;
2040
- if (device.firmware) {
2041
- accessory.context.version = device.firmware;
2042
- }
1960
+ accessory.context.deviceId = device.deviceId;
2043
1961
  accessory.context.deviceType = `IR: ${device.remoteType}`;
1962
+ accessory.context.model = device.remoteType;
1963
+ accessory.displayName = device.configDeviceName ?? device.deviceName;
2044
1964
  accessory.context.connectionType = device.connectionType;
1965
+ accessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
1966
+ const newOrExternal = !device.external ? 'Adding new' : 'Loading external';
1967
+ await this.infoLog(`${newOrExternal} accessory: ${accessory.displayName} deviceId: ${device.deviceId}`);
2045
1968
  // create the accessory handler for the newly create accessory
2046
1969
  // this is imported from `platformAccessory.ts`
2047
1970
  new AirConditioner(this, accessory, device);
@@ -2051,7 +1974,7 @@ export class SwitchBotPlatform {
2051
1974
  this.accessories.push(accessory);
2052
1975
  }
2053
1976
  else {
2054
- await this.debugLog(`Device not registered: ${device.deviceName} ${device.remoteType} DeviceID: ${device.deviceId}`);
1977
+ await this.debugLog(`Device not registered: ${device.deviceName} ${device.remoteType} deviceId: ${device.deviceId}`);
2055
1978
  }
2056
1979
  }
2057
1980
  async createAirPurifier(device) {
@@ -2063,14 +1986,12 @@ export class SwitchBotPlatform {
2063
1986
  // the accessory already exists
2064
1987
  if (!device.hide_device && device.hubDeviceId) {
2065
1988
  // if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
2066
- existingAccessory.context.model = device.remoteType;
2067
- existingAccessory.context.deviceID = device.deviceId;
2068
- existingAccessory.displayName = device.configDeviceName || device.deviceName;
2069
- if (device.firmware) {
2070
- existingAccessory.context.version = device.firmware;
2071
- }
1989
+ existingAccessory.context.device = device;
1990
+ existingAccessory.context.deviceId = device.deviceId;
2072
1991
  existingAccessory.context.deviceType = `IR: ${device.remoteType}`;
2073
- this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
1992
+ existingAccessory.context.model = device.remoteType;
1993
+ existingAccessory.displayName = device.configDeviceName ?? device.deviceName;
1994
+ await this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`);
2074
1995
  existingAccessory.context.connectionType = device.connectionType;
2075
1996
  this.api.updatePlatformAccessories([existingAccessory]);
2076
1997
  // create the accessory handler for the restored accessory
@@ -2083,22 +2004,19 @@ export class SwitchBotPlatform {
2083
2004
  }
2084
2005
  }
2085
2006
  else if (!device.hide_device && device.hubDeviceId) {
2086
- // the accessory does not yet exist, so we need to create it
2087
- if (!device.external) {
2088
- this.infoLog(`Adding new accessory: ${device.deviceName} ${device.remoteType} DeviceID: ${device.deviceId}`);
2089
- }
2090
2007
  // create a new accessory
2091
2008
  const accessory = new this.api.platformAccessory(device.deviceName, uuid);
2092
2009
  // store a copy of the device object in the `accessory.context`
2093
2010
  // the `context` property can be used to store any data about the accessory you may need
2094
2011
  accessory.context.device = device;
2095
- accessory.context.model = device.remoteType;
2096
- accessory.context.deviceID = device.deviceId;
2097
- if (device.firmware) {
2098
- accessory.context.version = device.firmware;
2099
- }
2012
+ accessory.context.deviceId = device.deviceId;
2100
2013
  accessory.context.deviceType = `IR: ${device.remoteType}`;
2014
+ accessory.context.model = device.remoteType;
2015
+ accessory.displayName = device.configDeviceName ?? device.deviceName;
2101
2016
  accessory.context.connectionType = device.connectionType;
2017
+ accessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
2018
+ const newOrExternal = !device.external ? 'Adding new' : 'Loading external';
2019
+ await this.infoLog(`${newOrExternal} accessory: ${accessory.displayName} deviceId: ${device.deviceId}`);
2102
2020
  // create the accessory handler for the newly create accessory
2103
2021
  // this is imported from `platformAccessory.ts`
2104
2022
  new AirPurifier(this, accessory, device);
@@ -2108,7 +2026,7 @@ export class SwitchBotPlatform {
2108
2026
  this.accessories.push(accessory);
2109
2027
  }
2110
2028
  else {
2111
- await this.debugLog(`Device not registered: ${device.deviceName} ${device.remoteType} DeviceID: ${device.deviceId}`);
2029
+ await this.debugLog(`Device not registered: ${device.deviceName} ${device.remoteType} deviceId: ${device.deviceId}`);
2112
2030
  }
2113
2031
  }
2114
2032
  async createWaterHeater(device) {
@@ -2120,14 +2038,12 @@ export class SwitchBotPlatform {
2120
2038
  // the accessory already exists
2121
2039
  if (!device.hide_device && device.hubDeviceId) {
2122
2040
  // if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
2123
- existingAccessory.context.model = device.remoteType;
2124
- existingAccessory.context.deviceID = device.deviceId;
2125
- existingAccessory.displayName = device.configDeviceName || device.deviceName;
2126
- if (device.firmware) {
2127
- existingAccessory.context.version = device.firmware;
2128
- }
2041
+ existingAccessory.context.device = device;
2042
+ existingAccessory.context.deviceId = device.deviceId;
2129
2043
  existingAccessory.context.deviceType = `IR: ${device.remoteType}`;
2130
- this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
2044
+ existingAccessory.context.model = device.remoteType;
2045
+ existingAccessory.displayName = device.configDeviceName ?? device.deviceName;
2046
+ await this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`);
2131
2047
  existingAccessory.context.connectionType = device.connectionType;
2132
2048
  this.api.updatePlatformAccessories([existingAccessory]);
2133
2049
  // create the accessory handler for the restored accessory
@@ -2140,22 +2056,19 @@ export class SwitchBotPlatform {
2140
2056
  }
2141
2057
  }
2142
2058
  else if (!device.hide_device && device.hubDeviceId) {
2143
- // the accessory does not yet exist, so we need to create it
2144
- if (!device.external) {
2145
- this.infoLog(`Adding new accessory: ${device.deviceName} ${device.remoteType} DeviceID: ${device.deviceId}`);
2146
- }
2147
2059
  // create a new accessory
2148
2060
  const accessory = new this.api.platformAccessory(device.deviceName, uuid);
2149
2061
  // store a copy of the device object in the `accessory.context`
2150
2062
  // the `context` property can be used to store any data about the accessory you may need
2151
2063
  accessory.context.device = device;
2152
- accessory.context.model = device.remoteType;
2153
- accessory.context.deviceID = device.deviceId;
2154
- if (device.firmware) {
2155
- accessory.context.version = device.firmware;
2156
- }
2064
+ accessory.context.deviceId = device.deviceId;
2157
2065
  accessory.context.deviceType = `IR: ${device.remoteType}`;
2066
+ accessory.context.model = device.remoteType;
2067
+ accessory.displayName = device.configDeviceName ?? device.deviceName;
2158
2068
  accessory.context.connectionType = device.connectionType;
2069
+ accessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
2070
+ const newOrExternal = !device.external ? 'Adding new' : 'Loading external';
2071
+ await this.infoLog(`${newOrExternal} accessory: ${accessory.displayName} deviceId: ${device.deviceId}`);
2159
2072
  // create the accessory handler for the newly create accessory
2160
2073
  // this is imported from `platformAccessory.ts`
2161
2074
  new WaterHeater(this, accessory, device);
@@ -2165,7 +2078,7 @@ export class SwitchBotPlatform {
2165
2078
  this.accessories.push(accessory);
2166
2079
  }
2167
2080
  else {
2168
- await this.debugLog(`Device not registered: ${device.deviceName} ${device.remoteType} DeviceID: ${device.deviceId}`);
2081
+ await this.debugLog(`Device not registered: ${device.deviceName} ${device.remoteType} deviceId: ${device.deviceId}`);
2169
2082
  }
2170
2083
  }
2171
2084
  async createVacuumCleaner(device) {
@@ -2177,14 +2090,12 @@ export class SwitchBotPlatform {
2177
2090
  // the accessory already exists
2178
2091
  if (!device.hide_device && device.hubDeviceId) {
2179
2092
  // if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
2180
- existingAccessory.context.model = device.remoteType;
2181
- existingAccessory.context.deviceID = device.deviceId;
2182
- existingAccessory.displayName = device.configDeviceName || device.deviceName;
2183
- if (device.firmware) {
2184
- existingAccessory.context.version = device.firmware;
2185
- }
2093
+ existingAccessory.context.device = device;
2094
+ existingAccessory.context.deviceId = device.deviceId;
2186
2095
  existingAccessory.context.deviceType = `IR: ${device.remoteType}`;
2187
- this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
2096
+ existingAccessory.context.model = device.remoteType;
2097
+ existingAccessory.displayName = device.configDeviceName ?? device.deviceName;
2098
+ await this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`);
2188
2099
  existingAccessory.context.connectionType = device.connectionType;
2189
2100
  this.api.updatePlatformAccessories([existingAccessory]);
2190
2101
  // create the accessory handler for the restored accessory
@@ -2197,22 +2108,19 @@ export class SwitchBotPlatform {
2197
2108
  }
2198
2109
  }
2199
2110
  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
2111
  // create a new accessory
2205
2112
  const accessory = new this.api.platformAccessory(device.deviceName, uuid);
2206
2113
  // store a copy of the device object in the `accessory.context`
2207
2114
  // the `context` property can be used to store any data about the accessory you may need
2208
2115
  accessory.context.device = device;
2209
- accessory.context.model = device.remoteType;
2210
- accessory.context.deviceID = device.deviceId;
2211
- if (device.firmware) {
2212
- accessory.context.version = device.firmware;
2213
- }
2116
+ accessory.context.deviceId = device.deviceId;
2214
2117
  accessory.context.deviceType = `IR: ${device.remoteType}`;
2118
+ accessory.context.model = device.remoteType;
2119
+ accessory.displayName = device.configDeviceName ?? device.deviceName;
2215
2120
  accessory.context.connectionType = device.connectionType;
2121
+ accessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
2122
+ const newOrExternal = !device.external ? 'Adding new' : 'Loading external';
2123
+ await this.infoLog(`${newOrExternal} accessory: ${accessory.displayName} deviceId: ${device.deviceId}`);
2216
2124
  // create the accessory handler for the newly create accessory
2217
2125
  // this is imported from `platformAccessory.ts`
2218
2126
  new VacuumCleaner(this, accessory, device);
@@ -2222,7 +2130,7 @@ export class SwitchBotPlatform {
2222
2130
  this.accessories.push(accessory);
2223
2131
  }
2224
2132
  else {
2225
- await this.debugLog(`Device not registered: ${device.deviceName} ${device.remoteType} DeviceID: ${device.deviceId}`);
2133
+ await this.debugLog(`Device not registered: ${device.deviceName} ${device.remoteType} deviceId: ${device.deviceId}`);
2226
2134
  }
2227
2135
  }
2228
2136
  async createCamera(device) {
@@ -2234,14 +2142,12 @@ export class SwitchBotPlatform {
2234
2142
  // the accessory already exists
2235
2143
  if (!device.hide_device && device.hubDeviceId) {
2236
2144
  // if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
2237
- existingAccessory.context.model = device.remoteType;
2238
- existingAccessory.context.deviceID = device.deviceId;
2239
- existingAccessory.displayName = device.configDeviceName || device.deviceName;
2240
- if (device.firmware) {
2241
- existingAccessory.context.version = device.firmware;
2242
- }
2145
+ existingAccessory.context.device = device;
2146
+ existingAccessory.context.deviceId = device.deviceId;
2243
2147
  existingAccessory.context.deviceType = `IR: ${device.remoteType}`;
2244
- this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
2148
+ existingAccessory.context.model = device.remoteType;
2149
+ existingAccessory.displayName = device.configDeviceName ?? device.deviceName;
2150
+ await this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`);
2245
2151
  existingAccessory.context.connectionType = device.connectionType;
2246
2152
  this.api.updatePlatformAccessories([existingAccessory]);
2247
2153
  // create the accessory handler for the restored accessory
@@ -2254,22 +2160,19 @@ export class SwitchBotPlatform {
2254
2160
  }
2255
2161
  }
2256
2162
  else if (!device.hide_device && device.hubDeviceId) {
2257
- // the accessory does not yet exist, so we need to create it
2258
- if (!device.external) {
2259
- this.infoLog(`Adding new accessory: ${device.deviceName} ${device.remoteType} DeviceID: ${device.deviceId}`);
2260
- }
2261
2163
  // create a new accessory
2262
2164
  const accessory = new this.api.platformAccessory(device.deviceName, uuid);
2263
2165
  // store a copy of the device object in the `accessory.context`
2264
2166
  // the `context` property can be used to store any data about the accessory you may need
2265
2167
  accessory.context.device = device;
2266
- accessory.context.model = device.remoteType;
2267
- accessory.context.deviceID = device.deviceId;
2268
- if (device.firmware) {
2269
- accessory.context.version = device.firmware;
2270
- }
2168
+ accessory.context.deviceId = device.deviceId;
2271
2169
  accessory.context.deviceType = `IR: ${device.remoteType}`;
2170
+ accessory.context.model = device.remoteType;
2171
+ accessory.displayName = device.configDeviceName ?? device.deviceName;
2272
2172
  accessory.context.connectionType = device.connectionType;
2173
+ accessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
2174
+ const newOrExternal = !device.external ? 'Adding new' : 'Loading external';
2175
+ await this.infoLog(`${newOrExternal} accessory: ${accessory.displayName} deviceId: ${device.deviceId}`);
2273
2176
  // create the accessory handler for the newly create accessory
2274
2177
  // this is imported from `platformAccessory.ts`
2275
2178
  new Camera(this, accessory, device);
@@ -2279,7 +2182,7 @@ export class SwitchBotPlatform {
2279
2182
  this.accessories.push(accessory);
2280
2183
  }
2281
2184
  else {
2282
- await this.debugLog(`Device not registered: ${device.deviceName} ${device.remoteType} DeviceID: ${device.deviceId}`);
2185
+ await this.debugLog(`Device not registered: ${device.deviceName} ${device.remoteType} deviceId: ${device.deviceId}`);
2283
2186
  }
2284
2187
  }
2285
2188
  async createOthers(device) {
@@ -2291,14 +2194,12 @@ export class SwitchBotPlatform {
2291
2194
  // the accessory already exists
2292
2195
  if (!device.hide_device && device.hubDeviceId) {
2293
2196
  // if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
2294
- existingAccessory.context.model = device.remoteType;
2295
- existingAccessory.context.deviceID = device.deviceId;
2296
- existingAccessory.displayName = device.configDeviceName || device.deviceName;
2297
- if (device.firmware) {
2298
- existingAccessory.context.version = device.firmware;
2299
- }
2197
+ existingAccessory.context.device = device;
2198
+ existingAccessory.context.deviceId = device.deviceId;
2300
2199
  existingAccessory.context.deviceType = `IR: ${device.remoteType}`;
2301
- this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
2200
+ existingAccessory.context.model = device.remoteType;
2201
+ existingAccessory.displayName = device.configDeviceName ?? device.deviceName;
2202
+ await this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`);
2302
2203
  existingAccessory.context.connectionType = device.connectionType;
2303
2204
  this.api.updatePlatformAccessories([existingAccessory]);
2304
2205
  // create the accessory handler for the restored accessory
@@ -2311,22 +2212,19 @@ export class SwitchBotPlatform {
2311
2212
  }
2312
2213
  }
2313
2214
  else if (!device.hide_device && device.hubDeviceId) {
2314
- // the accessory does not yet exist, so we need to create it
2315
- if (!device.external) {
2316
- this.infoLog(`Adding new accessory: ${device.deviceName} ${device.remoteType} DeviceID: ${device.deviceId}`);
2317
- }
2318
2215
  // create a new accessory
2319
2216
  const accessory = new this.api.platformAccessory(device.deviceName, uuid);
2320
2217
  // store a copy of the device object in the `accessory.context`
2321
2218
  // the `context` property can be used to store any data about the accessory you may need
2322
2219
  accessory.context.device = device;
2323
- accessory.context.model = device.remoteType;
2324
- accessory.context.deviceID = device.deviceId;
2325
- if (device.firmware) {
2326
- accessory.context.version = device.firmware;
2327
- }
2220
+ accessory.context.deviceId = device.deviceId;
2328
2221
  accessory.context.deviceType = `IR: ${device.remoteType}`;
2222
+ accessory.context.model = device.remoteType;
2223
+ accessory.displayName = device.configDeviceName ?? device.deviceName;
2329
2224
  accessory.context.connectionType = device.connectionType;
2225
+ accessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
2226
+ const newOrExternal = !device.external ? 'Adding new' : 'Loading external';
2227
+ await this.infoLog(`${newOrExternal} accessory: ${accessory.displayName} deviceId: ${device.deviceId}`);
2330
2228
  // create the accessory handler for the newly create accessory
2331
2229
  // this is imported from `platformAccessory.ts`
2332
2230
  new Others(this, accessory, device);
@@ -2336,7 +2234,7 @@ export class SwitchBotPlatform {
2336
2234
  this.accessories.push(accessory);
2337
2235
  }
2338
2236
  else {
2339
- await this.debugLog(`Device not registered: ${device.deviceName} ${device.remoteType} DeviceID: ${device.deviceId}`);
2237
+ await this.debugLog(`Device not registered: ${device.deviceName} ${device.remoteType} deviceId: ${device.deviceId}`);
2340
2238
  }
2341
2239
  }
2342
2240
  async registerCurtains(device) {