@switchbot/homebridge-switchbot 4.0.1-beta.4 → 4.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/platform.js CHANGED
@@ -19,6 +19,7 @@ import { StripLight } from './device/lightstrip.js';
19
19
  import { Lock } from './device/lock.js';
20
20
  import { Meter } from './device/meter.js';
21
21
  import { MeterPlus } from './device/meterplus.js';
22
+ import { MeterPro } from './device/meterpro.js';
22
23
  import { Motion } from './device/motion.js';
23
24
  import { Plug } from './device/plug.js';
24
25
  import { RobotVacuumCleaner } from './device/robotvacuumcleaner.js';
@@ -579,6 +580,7 @@ export class SwitchBotPlatform {
579
580
  'Meter': this.createMeter.bind(this),
580
581
  'MeterPlus': this.createMeterPlus.bind(this),
581
582
  'Meter Plus (JP)': this.createMeterPlus.bind(this),
583
+ 'Meter Pro': this.createMeterPro.bind(this),
582
584
  'WoIOSensor': this.createIOSensor.bind(this),
583
585
  'Water Detector': this.createWaterDetector.bind(this),
584
586
  'Motion Sensor': this.createMotion.bind(this),
@@ -900,6 +902,67 @@ export class SwitchBotPlatform {
900
902
  await this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} deviceId: ${device.deviceId}`);
901
903
  }
902
904
  }
905
+ async createMeterPro(device) {
906
+ const uuid = this.api.hap.uuid.generate(`${device.deviceId}-${device.deviceType}`);
907
+ // see if an accessory with the same uuid has already been registered and restored from
908
+ // the cached devices we stored in the `configureAccessory` method above
909
+ const existingAccessory = this.accessories.find(accessory => accessory.UUID === uuid);
910
+ if (existingAccessory) {
911
+ // the accessory already exists
912
+ if (await this.registerDevice(device)) {
913
+ // console.log("existingAccessory", existingAccessory);
914
+ // if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
915
+ existingAccessory.context.device = device;
916
+ existingAccessory.context.model = SwitchBotModel.MeterPro ?? SwitchBotModel.MeterProCO2;
917
+ existingAccessory.context.deviceId = device.deviceId;
918
+ existingAccessory.context.deviceType = device.deviceType;
919
+ existingAccessory.displayName = device.configDeviceName
920
+ ? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
921
+ : await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName);
922
+ existingAccessory.context.connectionType = await this.connectionType(device);
923
+ existingAccessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
924
+ this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`);
925
+ this.api.updatePlatformAccessories([existingAccessory]);
926
+ // create the accessory handler for the restored accessory
927
+ // this is imported from `platformAccessory.ts`
928
+ new MeterPro(this, existingAccessory, device);
929
+ await this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${existingAccessory.UUID})`);
930
+ }
931
+ else {
932
+ this.unregisterPlatformAccessories(existingAccessory);
933
+ }
934
+ }
935
+ else if (await this.registerDevice(device)) {
936
+ // create a new accessory
937
+ const accessory = new this.api.platformAccessory(device.configDeviceName
938
+ ? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
939
+ : await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName), uuid);
940
+ // store a copy of the device object in the `accessory.context`
941
+ // the `context` property can be used to store any data about the accessory you may need
942
+ accessory.context.device = device;
943
+ accessory.context.model = SwitchBotModel.MeterPro ?? SwitchBotModel.MeterProCO2;
944
+ accessory.context.deviceId = device.deviceId;
945
+ accessory.context.deviceType = device.deviceType;
946
+ accessory.displayName = device.configDeviceName
947
+ ? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
948
+ : await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName);
949
+ accessory.context.connectionType = await this.connectionType(device);
950
+ accessory.context.connectionType = await this.connectionType(device);
951
+ accessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
952
+ const newOrExternal = !device.external ? 'Adding new' : 'Loading external';
953
+ await this.infoLog(`${newOrExternal} accessory: ${accessory.displayName} deviceId: ${device.deviceId}`);
954
+ // create the accessory handler for the newly create accessory
955
+ // this is imported from `platformAccessory.ts`
956
+ new MeterPro(this, accessory, device);
957
+ await this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`);
958
+ // publish device externally or link the accessory to your platform
959
+ this.externalOrPlatform(device, accessory);
960
+ this.accessories.push(accessory);
961
+ }
962
+ else {
963
+ await this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} deviceId: ${device.deviceId}`);
964
+ }
965
+ }
903
966
  async createHub2(device) {
904
967
  const uuid = this.api.hap.uuid.generate(`${device.deviceId}-${device.deviceType}`);
905
968
  // see if an accessory with the same uuid has already been registered and restored from