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

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.
@@ -252,12 +252,12 @@ export class Curtain {
252
252
 
253
253
  if (this.setNewTarget && this.inMotion) {
254
254
  await this.setMinMax();
255
- if (this.TargetPosition > this.CurrentPosition) {
255
+ if (Number(this.TargetPosition) > this.CurrentPosition) {
256
256
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Closing, CurrentPosition: ${this.CurrentPosition}`);
257
257
  this.PositionState = this.platform.Characteristic.PositionState.INCREASING;
258
258
  this.windowCoveringService.getCharacteristic(this.platform.Characteristic.PositionState).updateValue(this.PositionState);
259
259
  this.debugLog(`${this.device.deviceType}: ${this.CurrentPosition} INCREASING PositionState: ${this.PositionState}`);
260
- } else if (this.TargetPosition < this.CurrentPosition) {
260
+ } else if (Number(this.TargetPosition) < this.CurrentPosition) {
261
261
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Opening, CurrentPosition: ${this.CurrentPosition}`);
262
262
  this.PositionState = this.platform.Characteristic.PositionState.DECREASING;
263
263
  this.windowCoveringService.getCharacteristic(this.platform.Characteristic.PositionState).updateValue(this.PositionState);
@@ -358,12 +358,12 @@ export class Curtain {
358
358
 
359
359
  if (this.setNewTarget && this.moving) {
360
360
  await this.setMinMax();
361
- if (this.TargetPosition > this.CurrentPosition) {
361
+ if (Number(this.TargetPosition) > this.CurrentPosition) {
362
362
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Closing, CurrentPosition: ${this.CurrentPosition} `);
363
363
  this.PositionState = this.platform.Characteristic.PositionState.INCREASING;
364
364
  this.windowCoveringService.getCharacteristic(this.platform.Characteristic.PositionState).updateValue(this.PositionState);
365
365
  this.debugLog(`${this.device.deviceType}: ${this.CurrentPosition} INCREASING PositionState: ${this.PositionState}`);
366
- } else if (this.TargetPosition < this.CurrentPosition) {
366
+ } else if (Number(this.TargetPosition) < this.CurrentPosition) {
367
367
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Opening, CurrentPosition: ${this.CurrentPosition} `);
368
368
  this.PositionState = this.platform.Characteristic.PositionState.DECREASING;
369
369
  this.windowCoveringService.getCharacteristic(this.platform.Characteristic.PositionState).updateValue(this.PositionState);
@@ -569,26 +569,27 @@ export class Curtain {
569
569
  }
570
570
  this.debugLog(`${this.accessory.displayName} Mode: ${this.Mode}`);
571
571
  if (switchbot !== false) {
572
- switchbot
573
- .discover({ model: 'c', quick: true, id: this.device.bleMac })
574
- .then(async (device_list: any) => {
575
- this.infoLog(`${this.accessory.displayName} Target Position: ${this.TargetPosition}`);
576
- return await this.retry({
577
- max: await this.maxRetry(),
578
- fn: async () => {
572
+ await this.retry({
573
+ max: await this.maxRetry(),
574
+ fn: () => {
575
+ return switchbot
576
+ .discover({ model: 'c', quick: true, id: this.device.bleMac })
577
+ .then(async (device_list: any) => {
578
+ this.infoLog(`${this.accessory.displayName} Target Position: ${this.TargetPosition}`);
579
579
  return await device_list[0].runToPos(100 - Number(this.TargetPosition), adjustedMode);
580
- },
581
- });
582
- })
583
- .then(() => {
584
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Done.`);
585
- })
586
- .catch(async (e: any) => {
587
- this.apiError(e);
588
- this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed BLEpushChanges with ${this.device.connectionType}`
589
- + ` Connection, Error Message: ${superStringify(e.message)}`);
590
- await this.BLEPushConnection();
591
- });
580
+ })
581
+ .then(() => {
582
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Done.`);
583
+ })
584
+ .catch(async (e: any) => {
585
+ this.apiError(e);
586
+ this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed BLEpushChanges with ${this.device.connectionType}`
587
+ + ` Connection, Error Message: ${superStringify(e.message)}`);
588
+ await this.BLEPushConnection();
589
+ throw new Error('Connection error');
590
+ });
591
+ },
592
+ });
592
593
  } else {
593
594
  this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} wasn't able to establish BLE Connection`);
594
595
  await this.BLEPushConnection();
@@ -637,7 +638,7 @@ export class Curtain {
637
638
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} sign: ${sign}`);
638
639
  this.debugLog(`Pushing ${this.TargetPosition}`);
639
640
  const adjustedTargetPosition = 100 - Number(this.TargetPosition);
640
- if (this.TargetPosition > 50) {
641
+ if (Number(this.TargetPosition) > 50) {
641
642
  this.setPositionMode = this.device.curtain?.setOpenMode;
642
643
  } else {
643
644
  this.setPositionMode = this.device.curtain?.setCloseMode;
@@ -889,7 +890,7 @@ export class Curtain {
889
890
  }
890
891
 
891
892
  async SilentPerformance() {
892
- if (this.TargetPosition > 50) {
893
+ if (Number(this.TargetPosition) > 50) {
893
894
  if (this.device.curtain?.setOpenMode === '1') {
894
895
  this.setPositionMode = 1;
895
896
  this.Mode = 'Silent Mode';
@@ -910,12 +911,12 @@ export class Curtain {
910
911
 
911
912
  async setMinMax(): Promise<void> {
912
913
  if (this.device.curtain?.set_min) {
913
- if (this.CurrentPosition <= this.device.curtain?.set_min) {
914
+ if (Number(this.CurrentPosition) <= this.device.curtain?.set_min) {
914
915
  this.CurrentPosition = 0;
915
916
  }
916
917
  }
917
918
  if (this.device.curtain?.set_max) {
918
- if (this.CurrentPosition >= this.device.curtain?.set_max) {
919
+ if (Number(this.CurrentPosition) >= this.device.curtain?.set_max) {
919
920
  this.CurrentPosition = 100;
920
921
  }
921
922
  }
@@ -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
@@ -423,6 +423,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
423
423
  this.createMeter(device);
424
424
  break;
425
425
  case 'MeterPlus':
426
+ case 'WoIOSensor':
426
427
  this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId}`);
427
428
  this.createMeterPlus(device);
428
429
  break;