node-switchbot 1.9.2-beta.0 → 1.9.2-beta.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.
package/README.md CHANGED
@@ -749,6 +749,14 @@ Actually, the `SwitchbotDeviceWoCurtain` is an object inherited from the [`Switc
749
749
 
750
750
  ### `open()` method
751
751
 
752
+ The `open()` method sends a open command to the Curtain. This method returns a `Promise` object. Nothing will be passed to the `resove()`.
753
+
754
+ If no connection is established with the device, this method automatically establishes a connection with the device, then finally closes the connection. You don't have to call the [`connect()`](#SwitchbotDevice-connect-method) method in advance.
755
+
756
+ When the Curtain receives this command, the Curtain will open the curtain (0% position). If not calibrated, the Curtain does not move.
757
+
758
+ The `open()` method receives an optional `mode` parameter. (See [`runToPos()`](#runtopos-method))
759
+
752
760
  ```javascript
753
761
  switchbot
754
762
  .discover({ model: "c", quick: true })
@@ -771,6 +779,8 @@ If no connection is established with the device, this method automatically estab
771
779
 
772
780
  When the Curtain receives this command, the Curtain will close the curtain (100% position). If not calibrated, the Curtain does not move.
773
781
 
782
+ The `close()` method receives an optional `mode` parameter. (See [`runToPos()`](#runtopos-method))
783
+
774
784
  ```javascript
775
785
  switchbot
776
786
  .discover({ model: "c", quick: true })
@@ -986,7 +996,8 @@ Structure of the `serviceData`:
986
996
 
987
997
  | Property | Type | Description |
988
998
  | :------------ | :------ | :--------------------------------------------------------------------------------- |
989
- | `model` | String | This value is always `"c"`, which means "Curtain (WoCurtain)". |
999
+ | `model` | String | This value is `"c"`, which means "Curtain (WoCurtain)". |
1000
+ | | | or `"{"`, which means "Curtain 3 (WoCurtain)". |
990
1001
  | `modelName` | String | This value is always `"WoCurtain"`, which means "Curtain". |
991
1002
  | `calibration` | Boolean | This value indicates the calibration status (`true` or `false`). |
992
1003
  | `battery` | Integer | This value indicates the battery level (`1-100`, `%`). |
@@ -1086,7 +1097,7 @@ Structure of the `serviceData`:
1086
1097
  | `delay` | Boolean | Indicates whether a delay is present. |
1087
1098
  | `timer` | Boolean | Indicates whether a timer is present. |
1088
1099
  | `syncUtcTime` | boolean | Indicates whether the UTC time has been synchronized. |
1089
- | `overload` | boolean | Indicates whether the Plug Mini is overloaded, more than 15A current overload. |
1100
+ | `overload` | boolean | Indicates whether the Plug Mini is overloaded, more than 15A current overload. |
1090
1101
  | `currentPower`| Float | Current power consumption in Watts. |
1091
1102
 
1092
1103
  ---
@@ -94,7 +94,7 @@ class SwitchbotAdvertising {
94
94
  sd = this._parseServiceDataForWoPresence(buf, onlog);//WoPresence
95
95
  } else if (model === "d") {
96
96
  sd = this._parseServiceDataForWoContact(buf, onlog);//WoContact
97
- } else if (model === "c") {
97
+ } else if (model === "c" || model === "{") {
98
98
  sd = this._parseServiceDataForWoCurtain(buf, onlog);// WoCurtain
99
99
  } else if (model === "x") {
100
100
  sd = this._parseServiceDataForWoBlindTilt(buf, onlog);// WoBlindTilt
@@ -174,8 +174,8 @@ class SwitchbotAdvertising {
174
174
  const byte1 = buf.readUInt8(1);
175
175
  const byte2 = buf.readUInt8(2);
176
176
 
177
- const mode = byte1 & 0b10000000 ? true : false; // Whether the light switch Add-on is used or not
178
- const state = byte1 & 0b01000000 ? true : false; // Whether the switch status is ON or OFF
177
+ const mode = byte1 & 0b10000000 ? true : false; // Whether the light switch Add-on is used or not. 0 = press, 1 = switch
178
+ const state = byte1 & 0b01000000 ? false : true; // Whether the switch status is ON or OFF. 0 = on, 1 = off
179
179
  const battery = byte2 & 0b01111111; // %
180
180
 
181
181
  const data = {
@@ -233,7 +233,7 @@ class SwitchbotAdvertising {
233
233
  }
234
234
  const byte1 = buf.readUInt8(1);
235
235
  const byte4 = buf.readUInt8(4);
236
-
236
+
237
237
 
238
238
  const onState = byte1 & 0b10000000 ? true : false; // 1 - on
239
239
  const autoMode = byte4 & 0b10000000 ? true : false; // 1 - auto
@@ -355,9 +355,10 @@ class SwitchbotAdvertising {
355
355
  const currPosition = byte3 & 0b01111111; // current positon %
356
356
  const lightLevel = (byte4 >> 4) & 0b00001111; // light sensor level (1-10)
357
357
  const deviceChain = byte4 & 0b00000111;
358
+ const model = buf.slice(0, 1).toString("utf8");
358
359
 
359
360
  const data = {
360
- model: "c",
361
+ model: model,
361
362
  modelName: "WoCurtain",
362
363
  calibration: calibration,
363
364
  battery: battery,
@@ -545,7 +546,7 @@ class SwitchbotAdvertising {
545
546
  const byte7 = manufacturerData.readUInt8(7);
546
547
  const byte8 = manufacturerData.readUInt8(8);
547
548
 
548
-
549
+
549
550
  const LockStatus = {
550
551
  LOCKED: 0b0000000,
551
552
  UNLOCKED: 0b0010000,
@@ -10,14 +10,14 @@ class SwitchbotDeviceWoCurtain extends SwitchbotDevice {
10
10
  * - Open the curtain
11
11
  *
12
12
  * [Arguments]
13
- * - none
13
+ * - mode | number | Opetional | runing mode (0x01 = QuietDrift, 0xff = Default)
14
14
  *
15
15
  * [Return value]
16
16
  * - Promise object
17
17
  * Nothing will be passed to the `resolve()`.
18
18
  * ---------------------------------------------------------------- */
19
- open() {
20
- return this._operateCurtain([0x57, 0x0f, 0x45, 0x01, 0x05, 0xff, 0x00]);
19
+ open(mode) {
20
+ return this.runToPos(0, mode);
21
21
  }
22
22
 
23
23
  /* ------------------------------------------------------------------
@@ -25,14 +25,14 @@ class SwitchbotDeviceWoCurtain extends SwitchbotDevice {
25
25
  * - close the curtain
26
26
  *
27
27
  * [Arguments]
28
- * - none
28
+ * - mode | number | Opetional | runing mode (0x01 = QuietDrift, 0xff = Default)
29
29
  *
30
30
  * [Return value]
31
31
  * - Promise object
32
32
  * Nothing will be passed to the `resolve()`.
33
33
  * ---------------------------------------------------------------- */
34
- close() {
35
- return this._operateCurtain([0x57, 0x0f, 0x45, 0x01, 0x05, 0xff, 0x64]);
34
+ close(mode) {
35
+ return this.runToPos(100, mode);
36
36
  }
37
37
 
38
38
  /* ------------------------------------------------------------------
@@ -55,13 +55,14 @@ class SwitchbotDeviceWoCurtain extends SwitchbotDevice {
55
55
  * - run to the target position
56
56
  *
57
57
  * [Arguments]
58
- * - percent | number | Required | the percentage of target position
58
+ * - percent | number | Required | the percentage of target position
59
+ * - mode | number | Opetional | runing mode (0x01 = QuietDrift, 0xff = Default)
59
60
  *
60
61
  * [Return value]
61
62
  * - Promise object
62
63
  * Nothing will be passed to the `resolve()`.
63
64
  * ---------------------------------------------------------------- */
64
- runToPos(percent, mode) {
65
+ runToPos(percent, mode = 0xff) {
65
66
  if (typeof percent != "number") {
66
67
  return new Promise((resolve, reject) => {
67
68
  reject(
@@ -72,19 +73,15 @@ class SwitchbotDeviceWoCurtain extends SwitchbotDevice {
72
73
  );
73
74
  });
74
75
  }
75
- if (mode == null) {
76
+ if (typeof mode != "number") {
77
+ return new Promise((resolve, reject) => {
78
+ reject(
79
+ new Error("The type of running mode is incorrect: " + typeof mode)
80
+ );
81
+ });
82
+ }
83
+ if (mode > 1) {
76
84
  mode = 0xff;
77
- } else {
78
- if (typeof mode != "number") {
79
- return new Promise((resolve, reject) => {
80
- reject(
81
- new Error("The type of running mode is incorrect: " + typeof mode)
82
- );
83
- });
84
- }
85
- if (mode > 1) {
86
- mode = 0xff;
87
- }
88
85
  }
89
86
  if (percent > 100) {
90
87
  percent = 100;
package/lib/switchbot.js CHANGED
@@ -56,13 +56,14 @@ class Switchbot {
56
56
  * - duration | Integer | Optional | Duration for discovery process (msec).
57
57
  * | | | The value must be in the range of 1 to 60000.
58
58
  * | | | The default value is 5000 (msec).
59
- * - model | String | Optional | "H", "T", "e", "s", "d", "c", "u", "g", "o", "i", or "r".
59
+ * - model | String | Optional | "H", "T", "e", "s", "d", "c", "{", "u", "g", "o", "i", or "r".
60
60
  * | | | If "H" is specified, this method will discover only Bots.
61
61
  * | | | If "T" is specified, this method will discover only Meters.
62
62
  * | | | If "e" is specified, this method will discover only Humidifiers.
63
63
  * | | | If "s" is specified, this method will discover only Motion Sensors.
64
64
  * | | | If "d" is specified, this method will discover only Contact Sensors.
65
65
  * | | | If "c" is specified, this method will discover only Curtains.
66
+ * | | | If "{" is specified, this method will discover only Curtain 3.
66
67
  * | | | If "u" is specified, this method will discover only Color Bulbs.
67
68
  * | | | If "g" is specified, this method will discover only Plugs.
68
69
  * | | | If "o" is specified, this method will discover only Locks.
@@ -101,6 +102,7 @@ class Switchbot {
101
102
  "s",
102
103
  "d",
103
104
  "c",
105
+ "{",
104
106
  "u",
105
107
  "g",
106
108
  "j",
@@ -252,6 +254,7 @@ class Switchbot {
252
254
  device = new SwitchbotDeviceWoContact(peripheral, this.noble);
253
255
  break;
254
256
  case "c":
257
+ case "{":
255
258
  device = new SwitchbotDeviceWoCurtain(peripheral, this.noble);
256
259
  break;
257
260
  case "x":
@@ -310,7 +313,7 @@ class Switchbot {
310
313
  *
311
314
  * [Arguments]
312
315
  * - params | Object | Optional |
313
- * - model | String | Optional | "H", "T", "e", "s", "d", "c", "u", "g", "o", "i", "x", or "r".
316
+ * - model | String | Optional | "H", "T", "e", "s", "d", "c", "{", "u", "g", "o", "i", "x", or "r".
314
317
  * | | | If "H" is specified, the `onadvertisement`
315
318
  * | | | event handler will be called only when advertising
316
319
  * | | | packets comes from Bots.
@@ -329,6 +332,9 @@ class Switchbot {
329
332
  * | | | If "c" is specified, the `onadvertisement`
330
333
  * | | | event handler will be called only when advertising
331
334
  * | | | packets comes from Curtains.
335
+ * | | | If "{" is specified, the `onadvertisement`
336
+ * | | | event handler will be called only when advertising
337
+ * | | | packets comes from Curtain 3.
332
338
  * | | | If "x" is specified, the `onadvertisement`
333
339
  * | | | event handler will be called only when advertising
334
340
  * | | | packets comes from BlindTilt.
@@ -375,6 +381,7 @@ class Switchbot {
375
381
  "s",
376
382
  "d",
377
383
  "c",
384
+ "{",
378
385
  "u",
379
386
  "g",
380
387
  "j",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-switchbot",
3
- "version": "1.9.2-beta.0",
3
+ "version": "1.9.2-beta.2",
4
4
  "description": "The node-switchbot is a Node.js module which allows you to control your Switchbot Devices through Bluetooth (BLE).",
5
5
  "main": "./lib/switchbot.js",
6
6
  "files": [