@switchbot/homebridge-switchbot 1.12.7-beta.6 → 1.12.7-beta.7

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,7 +5,9 @@ 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 { MeterPlus } from './device/meterplus';
8
9
  import { ColorBulb } from './device/colorbulb';
10
+ import { StripLight } from './device/striplight';
9
11
  import { Humidifier } from './device/humidifier';
10
12
  import { TV } from './irdevice/tv';
11
13
  import { Fan } from './irdevice/fan';
@@ -374,10 +376,13 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
374
376
  this.createBot(device);
375
377
  break;
376
378
  case 'Meter':
377
- case 'MeterPlus':
378
379
  this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId}`);
379
380
  this.createMeter(device);
380
381
  break;
382
+ case 'MeterPlus':
383
+ this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId}`);
384
+ this.createMeterPlus(device);
385
+ break;
381
386
  case 'Motion Sensor':
382
387
  this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId}`);
383
388
  this.createMotion(device);
@@ -401,10 +406,13 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
401
406
  this.createLock(device);
402
407
  break;
403
408
  case 'Color Bulb':
404
- case 'Strip Light':
405
409
  this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId}`);
406
410
  this.createColorBulb(device);
407
411
  break;
412
+ case 'Strip Light':
413
+ this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId}`);
414
+ this.createStripLight(device);
415
+ break;
408
416
  case 'Indoor Cam':
409
417
  this.deviceInfo(device);
410
418
  this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId}`);
@@ -671,6 +679,61 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
671
679
  }
672
680
  }
673
681
 
682
+ private async createMeterPlus(device: device & devicesConfig) {
683
+ const uuid = this.api.hap.uuid.generate(`${device.deviceId}-${device.deviceType}`);
684
+
685
+ // see if an accessory with the same uuid has already been registered and restored from
686
+ // the cached devices we stored in the `configureAccessory` method above
687
+ const existingAccessory = this.accessories.find((accessory) => accessory.UUID === uuid);
688
+
689
+ if (existingAccessory) {
690
+ // the accessory already exists
691
+ if (this.registerDevice(device)) {
692
+ this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
693
+
694
+ // if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
695
+ existingAccessory.context.model = device.deviceType;
696
+ existingAccessory.context.deviceID = device.deviceId;
697
+ existingAccessory.displayName = device.deviceName;
698
+ existingAccessory.context.firmwareRevision = this.version;
699
+ existingAccessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
700
+ await this.connectionTypeExistingAccessory(device, existingAccessory);
701
+ this.api.updatePlatformAccessories([existingAccessory]);
702
+ // create the accessory handler for the restored accessory
703
+ // this is imported from `platformAccessory.ts`
704
+ new MeterPlus(this, existingAccessory, device);
705
+ this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${existingAccessory.UUID})`);
706
+ } else {
707
+ this.unregisterPlatformAccessories(existingAccessory);
708
+ }
709
+ } else if (this.registerDevice(device)) {
710
+ // the accessory does not yet exist, so we need to create it
711
+ this.infoLog(`Adding new accessory: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
712
+
713
+ // create a new accessory
714
+ const accessory = new this.api.platformAccessory(device.deviceName, uuid);
715
+
716
+ // store a copy of the device object in the `accessory.context`
717
+ // the `context` property can be used to store any data about the accessory you may need
718
+ accessory.context.device = device;
719
+ accessory.context.model = device.deviceType;
720
+ accessory.context.deviceID = device.deviceId;
721
+ accessory.context.firmwareRevision = this.version;
722
+ accessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
723
+ await this.connectionTypeNewAccessory(device, accessory);
724
+ // create the accessory handler for the newly create accessory
725
+ // this is imported from `platformAccessory.ts`
726
+ new MeterPlus(this, accessory, device);
727
+ this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`);
728
+
729
+ // link the accessory to your platform
730
+ this.api.registerPlatformAccessories(PLUGIN_NAME, PLATFORM_NAME, [accessory]);
731
+ this.accessories.push(accessory);
732
+ } else {
733
+ this.debugLog(`Unable to Register new device: ${device.deviceName} ${device.deviceType} - ${device.deviceId}`);
734
+ }
735
+ }
736
+
674
737
  private async createMotion(device: device & devicesConfig) {
675
738
  const uuid = this.api.hap.uuid.generate(`${device.deviceId}-${device.deviceType}`);
676
739
 
@@ -1027,6 +1090,61 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
1027
1090
  }
1028
1091
  }
1029
1092
 
1093
+ private async createStripLight(device: device & devicesConfig) {
1094
+ const uuid = this.api.hap.uuid.generate(`${device.deviceId}-${device.deviceType}`);
1095
+
1096
+ // see if an accessory with the same uuid has already been registered and restored from
1097
+ // the cached devices we stored in the `configureAccessory` method above
1098
+ const existingAccessory = this.accessories.find((accessory) => accessory.UUID === uuid);
1099
+
1100
+ if (existingAccessory) {
1101
+ // the accessory already exists
1102
+ if (this.registerDevice(device)) {
1103
+ this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
1104
+
1105
+ // if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
1106
+ existingAccessory.context.model = device.deviceType;
1107
+ existingAccessory.context.deviceID = device.deviceId;
1108
+ existingAccessory.displayName = device.deviceName;
1109
+ existingAccessory.context.firmwareRevision = this.version;
1110
+ existingAccessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
1111
+ await this.connectionTypeExistingAccessory(device, existingAccessory);
1112
+ this.api.updatePlatformAccessories([existingAccessory]);
1113
+ // create the accessory handler for the restored accessory
1114
+ // this is imported from `platformAccessory.ts`
1115
+ new StripLight(this, existingAccessory, device);
1116
+ this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${existingAccessory.UUID})`);
1117
+ } else {
1118
+ this.unregisterPlatformAccessories(existingAccessory);
1119
+ }
1120
+ } else if (this.registerDevice(device)) {
1121
+ // the accessory does not yet exist, so we need to create it
1122
+ this.infoLog(`Adding new accessory: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
1123
+
1124
+ // create a new accessory
1125
+ const accessory = new this.api.platformAccessory(device.deviceName, uuid);
1126
+
1127
+ // store a copy of the device object in the `accessory.context`
1128
+ // the `context` property can be used to store any data about the accessory you may need
1129
+ accessory.context.device = device;
1130
+ accessory.context.model = device.deviceType;
1131
+ accessory.context.deviceID = device.deviceId;
1132
+ accessory.context.firmwareRevision = this.version;
1133
+ accessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
1134
+ await this.connectionTypeNewAccessory(device, accessory);
1135
+ // create the accessory handler for the newly create accessory
1136
+ // this is imported from `platformAccessory.ts`
1137
+ new StripLight(this, accessory, device);
1138
+ this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`);
1139
+
1140
+ // link the accessory to your platform
1141
+ this.api.registerPlatformAccessories(PLUGIN_NAME, PLATFORM_NAME, [accessory]);
1142
+ this.accessories.push(accessory);
1143
+ } else {
1144
+ this.debugLog(`Unable to Register new device: ${device.deviceName} ${device.deviceType} - ${device.deviceId}`);
1145
+ }
1146
+ }
1147
+
1030
1148
  private async createTV(device: irdevice & devicesConfig) {
1031
1149
  const uuid = this.api.hap.uuid.generate(`${device.deviceId}-${device.remoteType}`);
1032
1150