node-switchbot 1.1.3-beta.3 → 1.1.3-beta.7
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/CHANGELOG.md +7 -0
- package/lib/switchbot-advertising.js +5 -7
- package/lib/switchbot-device-wocurtain.js +4 -4
- package/lib/switchbot-device-wohand.js +5 -5
- package/lib/switchbot-device-wohumi.js +24 -39
- package/lib/switchbot-device.js +5 -5
- package/lib/switchbot.js +20 -20
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,13 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file. This project uses [Semantic Versioning](https://semver.org/)
|
|
4
4
|
|
|
5
|
+
## [Beta - Version 1.2.0](https://github.com/OpenWonderLabs/node-switchbot/releases/tag/v1.1.2) (2021-11-13)
|
|
6
|
+
|
|
7
|
+
### Changes
|
|
8
|
+
|
|
9
|
+
- Added support for SwitchBot "Contact" and "Motion"
|
|
10
|
+
- Housekeeping and update dependencies
|
|
11
|
+
|
|
5
12
|
## [Version 1.1.2](https://github.com/OpenWonderLabs/node-switchbot/releases/tag/v1.1.2) (2021-11-13)
|
|
6
13
|
|
|
7
14
|
### Changes
|
|
@@ -10,10 +10,10 @@ class SwitchbotAdvertising {
|
|
|
10
10
|
* [Arguments]
|
|
11
11
|
* - peripheral | Object | Required | A `Peripheral` object of noble
|
|
12
12
|
*
|
|
13
|
-
* [
|
|
13
|
+
* [Return value]
|
|
14
14
|
* - An object as follows:
|
|
15
15
|
*
|
|
16
|
-
* WoHand
|
|
16
|
+
* WoHand
|
|
17
17
|
* {
|
|
18
18
|
* id: 'c12e453e2008',
|
|
19
19
|
* address: 'c1:2e:45:3e:20:08',
|
|
@@ -56,7 +56,7 @@ class SwitchbotAdvertising {
|
|
|
56
56
|
* lightLevel: 1
|
|
57
57
|
* }
|
|
58
58
|
* }
|
|
59
|
-
*
|
|
59
|
+
*
|
|
60
60
|
* If the specified `Peripheral` does not represent any switchbot
|
|
61
61
|
* device, this method will return `null`.
|
|
62
62
|
* ---------------------------------------------------------------- */
|
|
@@ -65,10 +65,8 @@ class SwitchbotAdvertising {
|
|
|
65
65
|
if (!ad || !ad.serviceData) {
|
|
66
66
|
return null;
|
|
67
67
|
}
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
}
|
|
71
|
-
let buf = ad.serviceData[0].data;
|
|
68
|
+
let serviceData = ad.serviceData[0] || ad.serviceData;
|
|
69
|
+
let buf = serviceData.data;
|
|
72
70
|
if (!buf || !Buffer.isBuffer(buf) || buf.length < 3) {
|
|
73
71
|
return null;
|
|
74
72
|
}
|
|
@@ -10,7 +10,7 @@ class SwitchbotDeviceWoCurtain extends SwitchbotDevice {
|
|
|
10
10
|
* [Arguments]
|
|
11
11
|
* - none
|
|
12
12
|
*
|
|
13
|
-
* [
|
|
13
|
+
* [Return value]
|
|
14
14
|
* - Promise object
|
|
15
15
|
* Nothing will be passed to the `resolve()`.
|
|
16
16
|
* ---------------------------------------------------------------- */
|
|
@@ -25,7 +25,7 @@ class SwitchbotDeviceWoCurtain extends SwitchbotDevice {
|
|
|
25
25
|
* [Arguments]
|
|
26
26
|
* - none
|
|
27
27
|
*
|
|
28
|
-
* [
|
|
28
|
+
* [Return value]
|
|
29
29
|
* - Promise object
|
|
30
30
|
* Nothing will be passed to the `resolve()`.
|
|
31
31
|
* ---------------------------------------------------------------- */
|
|
@@ -40,7 +40,7 @@ class SwitchbotDeviceWoCurtain extends SwitchbotDevice {
|
|
|
40
40
|
* [Arguments]
|
|
41
41
|
* - none
|
|
42
42
|
*
|
|
43
|
-
* [
|
|
43
|
+
* [Return value]
|
|
44
44
|
* - Promise object
|
|
45
45
|
* Nothing will be passed to the `resolve()`.
|
|
46
46
|
* ---------------------------------------------------------------- */
|
|
@@ -55,7 +55,7 @@ class SwitchbotDeviceWoCurtain extends SwitchbotDevice {
|
|
|
55
55
|
* [Arguments]
|
|
56
56
|
* - percent | number | Required | the percentage of target position
|
|
57
57
|
*
|
|
58
|
-
* [
|
|
58
|
+
* [Return value]
|
|
59
59
|
* - Promise object
|
|
60
60
|
* Nothing will be passed to the `resolve()`.
|
|
61
61
|
* ---------------------------------------------------------------- */
|
|
@@ -10,7 +10,7 @@ class SwitchbotDeviceWoHand extends SwitchbotDevice {
|
|
|
10
10
|
* [Arguments]
|
|
11
11
|
* - none
|
|
12
12
|
*
|
|
13
|
-
* [
|
|
13
|
+
* [Return value]
|
|
14
14
|
* - Promise object
|
|
15
15
|
* Nothing will be passed to the `resolve()`.
|
|
16
16
|
* ---------------------------------------------------------------- */
|
|
@@ -25,7 +25,7 @@ class SwitchbotDeviceWoHand extends SwitchbotDevice {
|
|
|
25
25
|
* [Arguments]
|
|
26
26
|
* - none
|
|
27
27
|
*
|
|
28
|
-
* [
|
|
28
|
+
* [Return value]
|
|
29
29
|
* - Promise object
|
|
30
30
|
* Nothing will be passed to the `resolve()`.
|
|
31
31
|
* ---------------------------------------------------------------- */
|
|
@@ -40,7 +40,7 @@ class SwitchbotDeviceWoHand extends SwitchbotDevice {
|
|
|
40
40
|
* [Arguments]
|
|
41
41
|
* - none
|
|
42
42
|
*
|
|
43
|
-
* [
|
|
43
|
+
* [Return value]
|
|
44
44
|
* - Promise object
|
|
45
45
|
* Nothing will be passed to the `resolve()`.
|
|
46
46
|
* ---------------------------------------------------------------- */
|
|
@@ -55,7 +55,7 @@ class SwitchbotDeviceWoHand extends SwitchbotDevice {
|
|
|
55
55
|
* [Arguments]
|
|
56
56
|
* - none
|
|
57
57
|
*
|
|
58
|
-
* [
|
|
58
|
+
* [Return value]
|
|
59
59
|
* - Promise object
|
|
60
60
|
* Nothing will be passed to the `resolve()`.
|
|
61
61
|
* ---------------------------------------------------------------- */
|
|
@@ -70,7 +70,7 @@ class SwitchbotDeviceWoHand extends SwitchbotDevice {
|
|
|
70
70
|
* [Arguments]
|
|
71
71
|
* - none
|
|
72
72
|
*
|
|
73
|
-
* [
|
|
73
|
+
* [Return value]
|
|
74
74
|
* - Promise object
|
|
75
75
|
* Nothing will be passed to the `resolve()`.
|
|
76
76
|
* ---------------------------------------------------------------- */
|
|
@@ -4,63 +4,63 @@ const SwitchbotDevice = require('./switchbot-device.js');
|
|
|
4
4
|
class SwitchbotDeviceWoHumi extends SwitchbotDevice {
|
|
5
5
|
|
|
6
6
|
/* ------------------------------------------------------------------
|
|
7
|
-
*
|
|
8
|
-
* -
|
|
7
|
+
* press()
|
|
8
|
+
* - Press
|
|
9
9
|
*
|
|
10
10
|
* [Arguments]
|
|
11
11
|
* - none
|
|
12
12
|
*
|
|
13
|
-
* [
|
|
13
|
+
* [Return value]
|
|
14
14
|
* - Promise object
|
|
15
15
|
* Nothing will be passed to the `resolve()`.
|
|
16
16
|
* ---------------------------------------------------------------- */
|
|
17
|
-
|
|
18
|
-
return this.
|
|
17
|
+
press() {
|
|
18
|
+
return this._operateBot([0x57, 0x01, 0x00]);
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
/* ------------------------------------------------------------------
|
|
22
|
-
*
|
|
23
|
-
* -
|
|
22
|
+
* turnOn()
|
|
23
|
+
* - Turn on
|
|
24
24
|
*
|
|
25
25
|
* [Arguments]
|
|
26
26
|
* - none
|
|
27
27
|
*
|
|
28
|
-
* [
|
|
28
|
+
* [Return value]
|
|
29
29
|
* - Promise object
|
|
30
30
|
* Nothing will be passed to the `resolve()`.
|
|
31
31
|
* ---------------------------------------------------------------- */
|
|
32
|
-
|
|
33
|
-
return this.
|
|
32
|
+
turnOn() {
|
|
33
|
+
return this._operateBot([0x57, 0x01, 0x01]);
|
|
34
34
|
}
|
|
35
35
|
|
|
36
36
|
/* ------------------------------------------------------------------
|
|
37
|
-
*
|
|
38
|
-
* -
|
|
37
|
+
* turnOff()
|
|
38
|
+
* - Turn off
|
|
39
39
|
*
|
|
40
40
|
* [Arguments]
|
|
41
41
|
* - none
|
|
42
42
|
*
|
|
43
|
-
* [
|
|
43
|
+
* [Return value]
|
|
44
44
|
* - Promise object
|
|
45
45
|
* Nothing will be passed to the `resolve()`.
|
|
46
46
|
* ---------------------------------------------------------------- */
|
|
47
|
-
|
|
48
|
-
return this.
|
|
47
|
+
turnOff() {
|
|
48
|
+
return this._operateBot([0x57, 0x01, 0x02]);
|
|
49
49
|
}
|
|
50
50
|
|
|
51
51
|
/* ------------------------------------------------------------------
|
|
52
|
-
*
|
|
53
|
-
* -
|
|
52
|
+
* down()
|
|
53
|
+
* - Down
|
|
54
54
|
*
|
|
55
55
|
* [Arguments]
|
|
56
56
|
* - none
|
|
57
57
|
*
|
|
58
|
-
* [
|
|
58
|
+
* [Return value]
|
|
59
59
|
* - Promise object
|
|
60
60
|
* Nothing will be passed to the `resolve()`.
|
|
61
61
|
* ---------------------------------------------------------------- */
|
|
62
|
-
|
|
63
|
-
return this.
|
|
62
|
+
down() {
|
|
63
|
+
return this._operateBot([0x57, 0x01, 0x03]);
|
|
64
64
|
}
|
|
65
65
|
|
|
66
66
|
/* ------------------------------------------------------------------
|
|
@@ -70,30 +70,15 @@ class SwitchbotDeviceWoHumi extends SwitchbotDevice {
|
|
|
70
70
|
* [Arguments]
|
|
71
71
|
* - none
|
|
72
72
|
*
|
|
73
|
-
* [
|
|
73
|
+
* [Return value]
|
|
74
74
|
* - Promise object
|
|
75
75
|
* Nothing will be passed to the `resolve()`.
|
|
76
76
|
* ---------------------------------------------------------------- */
|
|
77
|
-
|
|
78
|
-
return this.
|
|
77
|
+
up() {
|
|
78
|
+
return this._operateBot([0x57, 0x01, 0x04]);
|
|
79
79
|
}
|
|
80
80
|
|
|
81
|
-
|
|
82
|
-
* turnOff()
|
|
83
|
-
* - Turn off
|
|
84
|
-
*
|
|
85
|
-
* [Arguments]
|
|
86
|
-
* - none
|
|
87
|
-
*
|
|
88
|
-
* [Returen value]
|
|
89
|
-
* - Promise object
|
|
90
|
-
* Nothing will be passed to the `resolve()`.
|
|
91
|
-
* ---------------------------------------------------------------- */
|
|
92
|
-
turnOff() {
|
|
93
|
-
return this._operateHumi([0x57, 0x01, 0x02]);
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
_operateHumi(bytes) {
|
|
81
|
+
_operateBot(bytes) {
|
|
97
82
|
return new Promise((resolve, reject) => {
|
|
98
83
|
let req_buf = Buffer.from(bytes);
|
|
99
84
|
this._command(req_buf).then((res_buf) => {
|
package/lib/switchbot-device.js
CHANGED
|
@@ -5,7 +5,7 @@ const switchbotAdvertising = require('./switchbot-advertising.js');
|
|
|
5
5
|
class SwitchbotDevice {
|
|
6
6
|
/* ------------------------------------------------------------------
|
|
7
7
|
* Constructor
|
|
8
|
-
*
|
|
8
|
+
*
|
|
9
9
|
* [Arguments]
|
|
10
10
|
* - peripheral | Object | Required | The `peripheral` object of noble,
|
|
11
11
|
* | | | which represents this device
|
|
@@ -83,7 +83,7 @@ class SwitchbotDevice {
|
|
|
83
83
|
* [Arguments]
|
|
84
84
|
* - none
|
|
85
85
|
*
|
|
86
|
-
* [
|
|
86
|
+
* [Return value]
|
|
87
87
|
* - Promise object
|
|
88
88
|
* Nothing will be passed to the `resolve()`.
|
|
89
89
|
* ---------------------------------------------------------------- */
|
|
@@ -285,7 +285,7 @@ class SwitchbotDevice {
|
|
|
285
285
|
* [Arguments]
|
|
286
286
|
* - none
|
|
287
287
|
*
|
|
288
|
-
* [
|
|
288
|
+
* [Return value]
|
|
289
289
|
* - Promise object
|
|
290
290
|
* Nothing will be passed to the `resolve()`.
|
|
291
291
|
* ---------------------------------------------------------------- */
|
|
@@ -329,7 +329,7 @@ class SwitchbotDevice {
|
|
|
329
329
|
* [Arguments]
|
|
330
330
|
* - none
|
|
331
331
|
*
|
|
332
|
-
* [
|
|
332
|
+
* [Return value]
|
|
333
333
|
* - Promise object
|
|
334
334
|
* The device name will be passed to the `resolve()`.
|
|
335
335
|
* ---------------------------------------------------------------- */
|
|
@@ -361,7 +361,7 @@ class SwitchbotDevice {
|
|
|
361
361
|
* - name | String | Required | Device name. The bytes length of the name
|
|
362
362
|
* | | | must be in the range of 1 to 20 bytes.
|
|
363
363
|
*
|
|
364
|
-
* [
|
|
364
|
+
* [Return value]
|
|
365
365
|
* - Promise object
|
|
366
366
|
* Nothing will be passed to the `resolve()`.
|
|
367
367
|
* ---------------------------------------------------------------- */
|
package/lib/switchbot.js
CHANGED
|
@@ -13,7 +13,7 @@ const SwitchbotDeviceWoHumi = require('./switchbot-device-wohumi.js');
|
|
|
13
13
|
class Switchbot {
|
|
14
14
|
/* ------------------------------------------------------------------
|
|
15
15
|
* Constructor
|
|
16
|
-
*
|
|
16
|
+
*
|
|
17
17
|
* [Arguments]
|
|
18
18
|
* - params | Object | Optional |
|
|
19
19
|
* - noble | Noble | Optional | The Nobel object created by the noble module.
|
|
@@ -30,7 +30,7 @@ class Switchbot {
|
|
|
30
30
|
noble = require('@abandonware/noble');
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
-
//
|
|
33
|
+
// Public properties
|
|
34
34
|
this.noble = noble;
|
|
35
35
|
this.ondiscover = null;
|
|
36
36
|
this.onadvertisement = null;
|
|
@@ -38,7 +38,7 @@ class Switchbot {
|
|
|
38
38
|
// Private properties
|
|
39
39
|
this._scanning = false;
|
|
40
40
|
this._DEFAULT_DISCOVERY_DURATION = 5000
|
|
41
|
-
this._PRIMARY_SERVICE_UUID_LIST = [
|
|
41
|
+
this._PRIMARY_SERVICE_UUID_LIST = [];
|
|
42
42
|
};
|
|
43
43
|
|
|
44
44
|
/* ------------------------------------------------------------------
|
|
@@ -57,7 +57,7 @@ class Switchbot {
|
|
|
57
57
|
* | | | If "s" is specified, this method will discover only Motion Sensors.
|
|
58
58
|
* | | | If "d" is specified, this method will discover only Contact Sensors.
|
|
59
59
|
* | | | If "c" is specified, this method will discover only Curtains.
|
|
60
|
-
* - id | String | Optional | If this value is set, this method
|
|
60
|
+
* - id | String | Optional | If this value is set, this method will discover
|
|
61
61
|
* | | | only a device whose ID is as same as this value.
|
|
62
62
|
* | | | The ID is identical to the MAC address.
|
|
63
63
|
* | | | This parameter is case-insensitive, and
|
|
@@ -68,7 +68,7 @@ class Switchbot {
|
|
|
68
68
|
* | | | without waiting the specified duration.
|
|
69
69
|
* | | | The default value is false.
|
|
70
70
|
*
|
|
71
|
-
* [
|
|
71
|
+
* [Return value]
|
|
72
72
|
* - Promise object
|
|
73
73
|
* An array will be passed to the `resolve()`, which includes
|
|
74
74
|
* `SwitchbotDevice` objects representing the found devices.
|
|
@@ -117,7 +117,7 @@ class Switchbot {
|
|
|
117
117
|
resolve(device_list);
|
|
118
118
|
};
|
|
119
119
|
|
|
120
|
-
// Set
|
|
120
|
+
// Set a handler for the 'discover' event
|
|
121
121
|
this.noble.on('discover', (peripheral) => {
|
|
122
122
|
let device = this._getDeviceObject(peripheral, p.id, p.model);
|
|
123
123
|
if (!device) {
|
|
@@ -136,7 +136,7 @@ class Switchbot {
|
|
|
136
136
|
}
|
|
137
137
|
});
|
|
138
138
|
|
|
139
|
-
// Start
|
|
139
|
+
// Start scanning
|
|
140
140
|
this.noble.startScanning(this._PRIMARY_SERVICE_UUID_LIST, false, (error) => {
|
|
141
141
|
if (error) {
|
|
142
142
|
reject(error);
|
|
@@ -236,32 +236,32 @@ class Switchbot {
|
|
|
236
236
|
* - params | Object | Optional |
|
|
237
237
|
* - model | String | Optional | "H", "T", "e", "s", "d", or "c".
|
|
238
238
|
* | | | If "H" is specified, the `onadvertisement`
|
|
239
|
-
* | | | event
|
|
239
|
+
* | | | event handler will be called only when advertising
|
|
240
240
|
* | | | packets comes from Bots.
|
|
241
241
|
* | | | If "T" is specified, the `onadvertisement`
|
|
242
|
-
* | | | event
|
|
242
|
+
* | | | event handler will be called only when advertising
|
|
243
243
|
* | | | packets comes from Meters.
|
|
244
244
|
* | | | If "e" is specified, the `onadvertisement`
|
|
245
|
-
* | | | event
|
|
245
|
+
* | | | event handler will be called only when advertising
|
|
246
246
|
* | | | packets comes from Humidifiers.
|
|
247
247
|
* | | | If "s" is specified, the `onadvertisement`
|
|
248
|
-
* | | | event
|
|
248
|
+
* | | | event handler will be called only when advertising
|
|
249
249
|
* | | | packets comes from Motion Sensor.
|
|
250
250
|
* | | | If "d" is specified, the `onadvertisement`
|
|
251
|
-
* | | | event
|
|
251
|
+
* | | | event handler will be called only when advertising
|
|
252
252
|
* | | | packets comes from Contact Sensor.
|
|
253
253
|
* | | | If "c" is specified, the `onadvertisement`
|
|
254
|
-
* | | | event
|
|
254
|
+
* | | | event handler will be called only when advertising
|
|
255
255
|
* | | | packets comes from Curtains.
|
|
256
256
|
* - id | String | Optional | If this value is set, the `onadvertisement`
|
|
257
|
-
* | | | event
|
|
257
|
+
* | | | event handler will be called only when advertising
|
|
258
258
|
* | | | packets comes from devices whose ID is as same as
|
|
259
259
|
* | | | this value.
|
|
260
260
|
* | | | The ID is identical to the MAC address.
|
|
261
261
|
* | | | This parameter is case-insensitive, and
|
|
262
262
|
* | | | colons are ignored.
|
|
263
263
|
*
|
|
264
|
-
* [
|
|
264
|
+
* [Return value]
|
|
265
265
|
* - Promise object
|
|
266
266
|
* Nothing will be passed to the `resolve()`.
|
|
267
267
|
* ---------------------------------------------------------------- */
|
|
@@ -291,7 +291,7 @@ class Switchbot {
|
|
|
291
291
|
id: params.id || ''
|
|
292
292
|
};
|
|
293
293
|
|
|
294
|
-
// Set
|
|
294
|
+
// Set a handler for the 'discover' event
|
|
295
295
|
this.noble.on('discover', (peripheral) => {
|
|
296
296
|
let ad = switchbotAdvertising.parse(peripheral);
|
|
297
297
|
if (this._filterAdvertising(ad, p.id, p.model)) {
|
|
@@ -301,7 +301,7 @@ class Switchbot {
|
|
|
301
301
|
}
|
|
302
302
|
});
|
|
303
303
|
|
|
304
|
-
// Start
|
|
304
|
+
// Start scanning
|
|
305
305
|
this.noble.startScanning(this._PRIMARY_SERVICE_UUID_LIST, true, (error) => {
|
|
306
306
|
if (error) {
|
|
307
307
|
reject(error);
|
|
@@ -323,7 +323,7 @@ class Switchbot {
|
|
|
323
323
|
* [Arguments]
|
|
324
324
|
* - none
|
|
325
325
|
*
|
|
326
|
-
* [
|
|
326
|
+
* [Return value]
|
|
327
327
|
* - none
|
|
328
328
|
* ---------------------------------------------------------------- */
|
|
329
329
|
stopScan() {
|
|
@@ -338,7 +338,7 @@ class Switchbot {
|
|
|
338
338
|
* [Arguments]
|
|
339
339
|
* - msec | Integer | Required | Msec.
|
|
340
340
|
*
|
|
341
|
-
* [
|
|
341
|
+
* [Return value]
|
|
342
342
|
* - Promise object
|
|
343
343
|
* Nothing will be passed to the `resolve()`.
|
|
344
344
|
* ---------------------------------------------------------------- */
|
|
@@ -360,4 +360,4 @@ class Switchbot {
|
|
|
360
360
|
|
|
361
361
|
}
|
|
362
362
|
|
|
363
|
-
module.exports = Switchbot;
|
|
363
|
+
module.exports = Switchbot;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "node-switchbot",
|
|
3
|
-
"version": "1.1.3-beta.
|
|
3
|
+
"version": "1.1.3-beta.7",
|
|
4
4
|
"description": "The node-switchbot is a Node.js module which allows you to move your Switchbot (Bot)'s arm and Switchbot Curtain(Curtain), also monitor the temperature/humidity from SwitchBot Thermometer & Hygrometer (Meter).",
|
|
5
5
|
"main": "./lib/switchbot.js",
|
|
6
6
|
"files": [
|
|
@@ -37,6 +37,6 @@
|
|
|
37
37
|
"@abandonware/noble": "^1.9.2-15"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
|
-
"npm-check-updates": "^12.0
|
|
40
|
+
"npm-check-updates": "^12.4.0"
|
|
41
41
|
}
|
|
42
42
|
}
|