@switchbot/homebridge-switchbot 2.8.2-beta.2 → 2.8.2

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.
@@ -27,7 +27,7 @@ export class Curtain {
27
27
 
28
28
  // OpenAPI Status
29
29
  OpenAPI_InMotion: deviceStatus['moving'];
30
- OpenAPI_BatterLevel: deviceStatus['battery'];
30
+ OpenAPI_BatteryLevel: deviceStatus['battery'];
31
31
  OpenAPI_FirmwareRevision: deviceStatus['version'];
32
32
  OpenAPI_CurrentPosition: deviceStatus['slidePosition'];
33
33
  OpenAPI_CurrentAmbientLightLevel: deviceStatus['brightness'];
@@ -37,8 +37,8 @@ export class Curtain {
37
37
  setPositionMode?: string | number;
38
38
 
39
39
  // BLE Status
40
- BLE_Battery: serviceData['battery'];
41
40
  BLE_InMotion: serviceData['inMotion'];
41
+ BLE_BatteryLevel: serviceData['battery'];
42
42
  BLE_Calibration: serviceData['calibration'];
43
43
  BLE_CurrentPosition: serviceData['position'];
44
44
  BLE_CurrentAmbientLightLevel: serviceData['lightLevel'];
@@ -392,7 +392,7 @@ export class Curtain {
392
392
  );
393
393
  }
394
394
  // Battery
395
- this.BatteryLevel = Number(this.BLE_Battery);
395
+ this.BatteryLevel = Number(this.BLE_BatteryLevel);
396
396
  if (this.BatteryLevel < 10) {
397
397
  this.StatusLowBattery = this.platform.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW;
398
398
  } else {
@@ -442,10 +442,10 @@ export class Curtain {
442
442
  ` TargetPosition: ${this.TargetPosition}, PositionState: ${this.PositionState},`,
443
443
  );
444
444
 
445
+ // Brightness
445
446
  if (!this.device.curtain?.hide_lightsensor) {
446
447
  this.set_minLux = this.minLux();
447
448
  this.set_maxLux = this.maxLux();
448
- // Brightness
449
449
  switch (this.OpenAPI_CurrentAmbientLightLevel) {
450
450
  case 'dim':
451
451
  this.CurrentAmbientLightLevel = this.set_minLux;
@@ -457,6 +457,19 @@ export class Curtain {
457
457
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} CurrentAmbientLightLevel: ${this.CurrentAmbientLightLevel}`);
458
458
  }
459
459
 
460
+ // BatteryLevel
461
+ this.BatteryLevel = Number(this.OpenAPI_BatteryLevel);
462
+ if (this.BatteryLevel < 10) {
463
+ this.StatusLowBattery = this.platform.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW;
464
+ } else {
465
+ this.StatusLowBattery = this.platform.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL;
466
+ }
467
+ if (Number.isNaN(this.BatteryLevel)) {
468
+ this.BatteryLevel = 100;
469
+ }
470
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BatteryLevel: ${this.BatteryLevel},`
471
+ + ` StatusLowBattery: ${this.StatusLowBattery}`);
472
+
460
473
  // FirmwareRevision
461
474
  this.FirmwareRevision = JSON.stringify(this.OpenAPI_FirmwareRevision);
462
475
  }
@@ -502,7 +515,7 @@ export class Curtain {
502
515
  ` BLE Address Found: ${ad.address}`,
503
516
  );
504
517
  this.BLE_Calibration = ad.serviceData.calibration;
505
- this.BLE_Battery = ad.serviceData.battery;
518
+ this.BLE_BatteryLevel = ad.serviceData.battery;
506
519
  this.BLE_InMotion = ad.serviceData.inMotion;
507
520
  this.BLE_CurrentPosition = ad.serviceData.position;
508
521
  this.BLE_CurrentAmbientLightLevel = ad.serviceData.lightLevel;
@@ -561,7 +574,7 @@ export class Curtain {
561
574
  this.OpenAPI_CurrentPosition = deviceStatus.body.slidePosition;
562
575
  this.OpenAPI_InMotion = deviceStatus.body.moving;
563
576
  this.OpenAPI_CurrentAmbientLightLevel = deviceStatus.body.brightness;
564
- this.OpenAPI_BatterLevel = deviceStatus.body.battery;
577
+ this.OpenAPI_BatteryLevel = deviceStatus.body.battery;
565
578
  this.OpenAPI_FirmwareRevision = deviceStatus.body.version;
566
579
  this.openAPIparseStatus();
567
580
  this.updateHomeKitCharacteristics();
@@ -240,6 +240,19 @@ export class IOSensor {
240
240
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Temperature: ${this.CurrentTemperature}°c`);
241
241
  }
242
242
 
243
+ // BatteryLevel
244
+ this.BatteryLevel = Number(this.OpenAPI_BatteryLevel);
245
+ if (this.BatteryLevel < 10) {
246
+ this.StatusLowBattery = this.platform.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW;
247
+ } else {
248
+ this.StatusLowBattery = this.platform.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL;
249
+ }
250
+ if (Number.isNaN(this.BatteryLevel)) {
251
+ this.BatteryLevel = 100;
252
+ }
253
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BatteryLevel: ${this.BatteryLevel},`
254
+ + ` StatusLowBattery: ${this.StatusLowBattery}`);
255
+
243
256
  // FirmwareRevision
244
257
  this.FirmwareRevision = JSON.stringify(this.OpenAPI_FirmwareRevision);
245
258
  }
@@ -236,7 +236,8 @@ export class Lock {
236
236
  if (Number.isNaN(this.BatteryLevel)) {
237
237
  this.BatteryLevel = 100;
238
238
  }
239
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BatteryLevel: ${this.BatteryLevel}`);
239
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BatteryLevel: ${this.BatteryLevel},`
240
+ + ` StatusLowBattery: ${this.StatusLowBattery}`);
240
241
 
241
242
  // FirmwareRevision
242
243
  this.FirmwareRevision = JSON.stringify(this.OpenAPI_FirmwareRevision);
@@ -241,6 +241,19 @@ export class Meter {
241
241
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Temperature: ${this.CurrentTemperature}°c`);
242
242
  }
243
243
 
244
+ // Battery
245
+ this.BatteryLevel = Number(this.OpenAPI_BatteryLevel);
246
+ if (this.BatteryLevel < 10) {
247
+ this.StatusLowBattery = this.platform.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW;
248
+ } else {
249
+ this.StatusLowBattery = this.platform.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL;
250
+ }
251
+ if (Number.isNaN(this.BatteryLevel)) {
252
+ this.BatteryLevel = 100;
253
+ }
254
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BatteryLevel: ${this.BatteryLevel},`
255
+ + ` StatusLowBattery: ${this.StatusLowBattery}`);
256
+
244
257
  // FirmwareRevision
245
258
  this.FirmwareRevision = JSON.stringify(this.OpenAPI_FirmwareRevision);
246
259
  }
@@ -241,6 +241,19 @@ export class MeterPlus {
241
241
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Temperature: ${this.CurrentTemperature}°c`);
242
242
  }
243
243
 
244
+ // Battery
245
+ this.BatteryLevel = Number(this.OpenAPI_BatteryLevel);
246
+ if (this.BatteryLevel < 10) {
247
+ this.StatusLowBattery = this.platform.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW;
248
+ } else {
249
+ this.StatusLowBattery = this.platform.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL;
250
+ }
251
+ if (Number.isNaN(this.BatteryLevel)) {
252
+ this.BatteryLevel = 100;
253
+ }
254
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BatteryLevel: ${this.BatteryLevel},`
255
+ + ` StatusLowBattery: ${this.StatusLowBattery}`);
256
+
244
257
  // FirmwareRevision
245
258
  this.FirmwareRevision = JSON.stringify(this.OpenAPI_FirmwareRevision);
246
259
  }
@@ -214,19 +214,19 @@ export class Motion {
214
214
  }
215
215
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} CurrentAmbientLightLevel: ${this.CurrentAmbientLightLevel}`);
216
216
  }
217
+
217
218
  // Battery
218
- if (this.OpenAPI_BatteryLevel === undefined) {
219
- this.OpenAPI_BatteryLevel = 100;
220
- }
221
- this.BatteryLevel = this.OpenAPI_BatteryLevel!;
219
+ this.BatteryLevel = Number(this.OpenAPI_BatteryLevel);
222
220
  if (this.BatteryLevel < 10) {
223
221
  this.StatusLowBattery = this.platform.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW;
224
222
  } else {
225
223
  this.StatusLowBattery = this.platform.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL;
226
224
  }
227
- this.debugLog(
228
- `${this.device.deviceType}: ${this.accessory.displayName} BatteryLevel: ${this.BatteryLevel},` + ` StatusLowBattery: ${this.StatusLowBattery}`,
229
- );
225
+ if (Number.isNaN(this.BatteryLevel)) {
226
+ this.BatteryLevel = 100;
227
+ }
228
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BatteryLevel: ${this.BatteryLevel},`
229
+ + ` StatusLowBattery: ${this.StatusLowBattery}`);
230
230
 
231
231
  // FirmwareRevision
232
232
  this.FirmwareRevision = JSON.stringify(this.OpenAPI_FirmwareRevision);
@@ -1,81 +0,0 @@
1
- #!/bin/env node
2
-
3
- /**
4
- * This scripts queries the npm registry to pull out the latest version for a given tag.
5
- */
6
-
7
- const fs = require("fs");
8
- const semver = require("semver");
9
- const child_process = require("child_process");
10
- const assert = require("assert");
11
-
12
- const BRANCH_VERSION_PATTERN = /^([A-Za-z]*)-(\d+.\d+.\d+)$/
13
-
14
- // Load the contents of the package.json file
15
- const packageJSON = JSON.parse(fs.readFileSync("package.json", "utf8"));
16
-
17
- let refArgument = process.argv[2];
18
- let tagArgument = process.argv[3] || "latest";
19
-
20
- if (refArgument == null) {
21
- console.error("ref argument is missing");
22
- console.error("Usage: npm-version-script.js <ref> [tag]");
23
- process.exit(1);
24
- }
25
-
26
- /**
27
- * Queries the NPM registry for the latest version for the provided tag.
28
- * @param tag The tag to query for.
29
- * @returns {string} Returns the version.
30
- */
31
- function getTagVersionFromNpm(tag) {
32
- try {
33
- return child_process.execSync(`npm info ${packageJSON.name} version --tag="${tag}"`).toString("utf8").trim();
34
- } catch (e) {
35
- throw e;
36
- }
37
- }
38
-
39
- function desiredTargetVersion(ref) {
40
- // ref is a GitHub action ref string
41
- if (ref.startsWith("refs/pull/")) {
42
- throw Error("The version script was executed inside a PR!");
43
- }
44
-
45
- assert(ref.startsWith("refs/heads/"))
46
- let branchName = ref.slice("refs/heads/".length);
47
-
48
- let results = branchName.match(BRANCH_VERSION_PATTERN);
49
- if (results != null) {
50
- if (results[1] !== tagArgument) {
51
- console.warn(`The base branch name (${results[1]}) differs from the tag name ${tagArgument}`);
52
- }
53
-
54
- return results[2];
55
- }
56
-
57
- // legacy mode were we use the `betaVersion` property in the package.json
58
- if (branchName === "beta" && packageJSON.betaVersion) {
59
- return packageJSON.betaVersion
60
- }
61
-
62
- throw new Error("Malformed branch name for ref: " + ref + ". Can't derive the base version. Use a branch name like: beta-x.x.x!");
63
- }
64
-
65
- // derive the base version from the branch ref
66
- const baseVersion = desiredTargetVersion(refArgument);
67
-
68
- // query the npm registry for the latest version of the provided tag name
69
- const latestReleasedVersion = getTagVersionFromNpm(tagArgument); // e.g. 0.7.0-beta.12
70
- const latestReleaseBase = semver.inc(latestReleasedVersion, "patch"); // will produce 0.7.0 (removing the preid, needed for the equality check below)
71
-
72
- let publishTag;
73
- if (semver.eq(baseVersion, latestReleaseBase)) { // check if we are releasing another version for the latest beta
74
- publishTag = latestReleasedVersion; // set the current latest beta to be incremented
75
- } else {
76
- publishTag = baseVersion; // start of with a new beta version
77
- }
78
-
79
- // save the package.json
80
- packageJSON.version = publishTag;
81
- fs.writeFileSync("package.json", JSON.stringify(packageJSON, null, 2));