@switchbot/homebridge-switchbot 2.5.3-beta.12 → 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.
@@ -438,7 +438,7 @@ export class Meter {
438
438
  if (this.device.mqttURL) {
439
439
  this.mqttPublish(`{${mqttmessage.join(',')}}`);
440
440
  }
441
- if (this.CurrentRelativeHumidity > 0) {
441
+ if (Number(this.CurrentRelativeHumidity) > 0) {
442
442
  // reject unreliable data
443
443
  if (this.device.history) {
444
444
  this.historyService?.addEntry(entry);
@@ -356,6 +356,9 @@ export class MeterPlus {
356
356
  try {
357
357
  this.deviceStatus = JSON.parse(rawData);
358
358
  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
+ }
359
362
  this.Humidity = this.deviceStatus.body.humidity!;
360
363
  this.Temperature = this.deviceStatus.body.temperature!;
361
364
  this.parseStatus();
@@ -438,7 +441,7 @@ export class MeterPlus {
438
441
  if (this.device.mqttURL) {
439
442
  this.mqttPublish(`{${mqttmessage.join(',')}}`);
440
443
  }
441
- if (this.CurrentRelativeHumidity > 0) {
444
+ if (Number(this.CurrentRelativeHumidity) > 0) {
442
445
  // reject unreliable data
443
446
  if (this.device.history) {
444
447
  this.historyService?.addEntry(entry);
@@ -188,7 +188,7 @@ export class AirPurifier {
188
188
  'commandType': 'command',
189
189
  });
190
190
  if (this.Active === 1) {
191
- if ((this.CurrentTemperature || 24) < (this.LastTemperature || 30)) {
191
+ if ((Number(this.CurrentTemperature)|| 24) < (this.LastTemperature || 30)) {
192
192
  this.CurrentHeaterCoolerState = this.platform.Characteristic.CurrentHeaterCoolerState.COOLING;
193
193
  } else {
194
194
  this.CurrentHeaterCoolerState = this.platform.Characteristic.CurrentHeaterCoolerState.HEATING;
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';
@@ -426,6 +427,10 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
426
427
  this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId}`);
427
428
  this.createMeterPlus(device);
428
429
  break;
430
+ case 'WoIOSensor':
431
+ this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId}`);
432
+ this.createIOSensor(device);
433
+ break;
429
434
  case 'Motion Sensor':
430
435
  this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId}`);
431
436
  this.createMotion(device);
@@ -781,6 +786,62 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
781
786
  }
782
787
  }
783
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
+
784
845
  private async createMotion(device: device & devicesConfig) {
785
846
  const uuid = this.api.hap.uuid.generate(`${device.deviceId}-${device.deviceType}`);
786
847