@switchbot/homebridge-switchbot 2.5.3-beta.13 → 2.5.3-beta.14

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/src/platform.ts CHANGED
@@ -5,6 +5,7 @@ import { Meter } from './device/meter';
5
5
  import { Motion } from './device/motion';
6
6
  import { Contact } from './device/contact';
7
7
  import { Curtain } from './device/curtain';
8
+ import { IOSensor } from './device/iosensor';
8
9
  import { MeterPlus } from './device/meterplus';
9
10
  import { ColorBulb } from './device/colorbulb';
10
11
  import { CeilingLight } from './device/ceilinglight';
@@ -423,10 +424,13 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
423
424
  this.createMeter(device);
424
425
  break;
425
426
  case 'MeterPlus':
426
- case 'WoIOSensor':
427
427
  this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId}`);
428
428
  this.createMeterPlus(device);
429
429
  break;
430
+ case 'WoIOSensor':
431
+ this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId}`);
432
+ this.createIOSensor(device);
433
+ break;
430
434
  case 'Motion Sensor':
431
435
  this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId}`);
432
436
  this.createMotion(device);
@@ -782,6 +786,62 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
782
786
  }
783
787
  }
784
788
 
789
+ private async createIOSensor(device: device & devicesConfig) {
790
+ const uuid = this.api.hap.uuid.generate(`${device.deviceId}-${device.deviceType}`);
791
+
792
+ // see if an accessory with the same uuid has already been registered and restored from
793
+ // the cached devices we stored in the `configureAccessory` method above
794
+ const existingAccessory = this.accessories.find((accessory) => accessory.UUID === uuid);
795
+
796
+ if (existingAccessory) {
797
+ // the accessory already exists
798
+ if (await this.registerDevice(device)) {
799
+ // if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
800
+ existingAccessory.context.model = device.deviceType;
801
+ existingAccessory.context.deviceID = device.deviceId;
802
+ existingAccessory.displayName = device.configDeviceName || device.deviceName;
803
+ existingAccessory.context.firmwareRevision = device.firmware;
804
+ existingAccessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
805
+ this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
806
+ existingAccessory.context.connectionType = await this.connectionType(device);
807
+ this.api.updatePlatformAccessories([existingAccessory]);
808
+ // create the accessory handler for the restored accessory
809
+ // this is imported from `platformAccessory.ts`
810
+ new IOSensor(this, existingAccessory, device);
811
+ this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${existingAccessory.UUID})`);
812
+ } else {
813
+ this.unregisterPlatformAccessories(existingAccessory);
814
+ }
815
+ } else if (await this.registerDevice(device)) {
816
+ // the accessory does not yet exist, so we need to create it
817
+ if (!device.external) {
818
+ this.infoLog(`Adding new accessory: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
819
+ }
820
+
821
+ // create a new accessory
822
+ const accessory = new this.api.platformAccessory(device.deviceName, uuid);
823
+
824
+ // store a copy of the device object in the `accessory.context`
825
+ // the `context` property can be used to store any data about the accessory you may need
826
+ accessory.context.device = device;
827
+ accessory.context.model = device.deviceType;
828
+ accessory.context.deviceID = device.deviceId;
829
+ accessory.context.firmwareRevision = device.firmware;
830
+ accessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
831
+ accessory.context.connectionType = await this.connectionType(device);
832
+ // create the accessory handler for the newly create accessory
833
+ // this is imported from `platformAccessory.ts`
834
+ new IOSensor(this, accessory, device);
835
+ this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`);
836
+
837
+ // publish device externally or link the accessory to your platform
838
+ this.externalOrPlatform(device, accessory);
839
+ this.accessories.push(accessory);
840
+ } else {
841
+ this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
842
+ }
843
+ }
844
+
785
845
  private async createMotion(device: device & devicesConfig) {
786
846
  const uuid = this.api.hap.uuid.generate(`${device.deviceId}-${device.deviceType}`);
787
847