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

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.
@@ -32,6 +32,7 @@ export class MeterPlus {
32
32
  StatusLowBattery?: CharacteristicValue;
33
33
 
34
34
  // OpenAPI Others
35
+ Battery: deviceStatus['battery'];
35
36
  Temperature: deviceStatus['temperature'];
36
37
  Humidity: deviceStatus['humidity'];
37
38
  deviceStatus!: any; //deviceStatusResponse;
@@ -356,11 +357,9 @@ export class MeterPlus {
356
357
  try {
357
358
  this.deviceStatus = JSON.parse(rawData);
358
359
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIRefreshStatus: ${superStringify(this.deviceStatus)}`);
359
- if (this.device.deviceType === 'WoIOSensor') {
360
- this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIRefreshStatus: ${superStringify(this.deviceStatus)}`);
361
- }
362
360
  this.Humidity = this.deviceStatus.body.humidity!;
363
361
  this.Temperature = this.deviceStatus.body.temperature!;
362
+ this.Battery = this.deviceStatus.body.battery!;
364
363
  this.parseStatus();
365
364
  this.updateHomeKitCharacteristics();
366
365
  } catch (e: any) {
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
 
package/src/settings.ts CHANGED
@@ -259,8 +259,8 @@ calibrate?: boolean; //determines if device has been calibrated or not. (Used by
259
259
  group?: boolean; //determines if a device is paired with or grouped with another device or not. (Used by the following deviceTypes: Curtain, Blind Tilt)
260
260
  moving?: boolean; //determines if a device is moving or not. (Used by the following deviceTypes: Curtain, Blind Tilt)
261
261
  slidePosition?: number;//the current position (0-100) the percentage of the distance between the calibrated open position and closed position. (Used by the following deviceTypes: Curtain, Blind Tilt)
262
- temperature?: number; //temperature in celsius (Used by the following deviceTypes: Meter, Meter Plus, Humidifier)
263
- humidity?: number; //humidity percentage. (Used by the following deviceTypes: Meter, Meter Plus, Humidifier)
262
+ temperature?: number; //temperature in celsius (Used by the following deviceTypes: Meter, Meter Plus, Humidifier, IOSensor)
263
+ humidity?: number; //humidity percentage. (Used by the following deviceTypes: Meter, Meter Plus, Humidifier, IOSensor)
264
264
  lockState?: string; //determines if locked or not. (Used by the following deviceTypes: Lock)
265
265
  doorState?: string; //determines if the door is closed or not. (Used by the following deviceTypes: Lock)
266
266
  moveDetected?: boolean; //determines if motion is detected. (Used by the following deviceTypes: Motion Sensor, Contact Sensor)
@@ -274,7 +274,7 @@ electricCurrent?: number; //the current of the device at the moment, measured in
274
274
  color?: string; //the color value, RGB "255:255:255". (Used by the following deviceTypes: Strip Light, Color Bulb)
275
275
  workingStatus?: string; //the working status of the device. StandBy, Clearing, Paused, GotoChargeBase, Charging, ChargeDone, Dormant, InTrouble, InRemoteControl, or InDustCollecting. (Used by the following deviceTypes: Robot Vacuum Cleaner S1, Robot Vacuum Cleaner S1 Plus)
276
276
  onlineStatus?: string; //the connection status of the device. online or offline. (Used by the following deviceTypes: Robot Vacuum Cleaner S1, Robot Vacuum Cleaner S1 Plus)
277
- battery?: number; //the current battery level. (Used by the following deviceTypes: Robot Vacuum Cleaner S1, Robot Vacuum Cleaner S1 Plus, Blind Tilt)
277
+ battery?: number; //the current battery level. (Used by the following deviceTypes: Robot Vacuum Cleaner S1, Robot Vacuum Cleaner S1 Plus, Blind Tilt, IOSensor)
278
278
  deviceName?: string; //device name. (Used by the following deviceTypes: Robot Vacuum Cleaner S1 Plus)
279
279
  nebulizationEfficiency?: number; //atomization efficiency percentage. (Used by the following deviceTypes: Humidifier)
280
280
  auto?: boolean; //determines if a Humidifier is in Auto Mode or not. (Used by the following deviceTypes: Humidifier)