node-switchbot 1.0.9-beta.4 → 1.1.3-beta.0

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 CHANGED
@@ -2,95 +2,115 @@
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
- ## [Version 1.0.8](https://github.com/OpenWonderLabs/homebridge-switchbot/releases/tag/v1.0.48) (2021-09-30)
5
+ ## [Version 1.1.2](https://github.com/OpenWonderLabs/node-switchbot/releases/tag/v1.1.2) (2021-11-13)
6
+
7
+ ### Changes
8
+
9
+ - Housekeeping and update dependencies
10
+
11
+ ## [Version 1.1.1](https://github.com/OpenWonderLabs/node-switchbot/releases/tag/v1.1.1) (2021-11-02)
12
+
13
+ ### Changes
14
+
15
+ - Change back from @node/noble to @abandonware/noble
16
+
17
+ ## [Version 1.1.0](https://github.com/OpenWonderLabs/node-switchbot/releases/tag/v1.1.0) (2021-10-26)
18
+
19
+ ### Changes
20
+
21
+ - Add Contact/Motion Sensor advertisement
22
+ - Add Humidifier advertisement
23
+ - Correct Model for advertisement
24
+
25
+ ## [Version 1.0.8](https://github.com/OpenWonderLabs/node-switchbot/releases/tag/v1.0.8) (2021-09-30)
6
26
 
7
27
  ### Changes
8
28
 
9
29
  - fix extra trace of old noble from @abandonware/noble
10
30
 
11
- ## [Version 1.0.7](https://github.com/OpenWonderLabs/homebridge-switchbot/releases/tag/v1.0.7) (2021-09-24)
31
+ ## [Version 1.0.7](https://github.com/OpenWonderLabs/node-switchbot/releases/tag/v1.0.7) (2021-09-24)
12
32
 
13
33
  ### Changes
14
34
 
15
35
  - Change from @abandonware/noble to @homebridge/noble
16
36
 
17
- ## [Version 1.0.6](https://github.com/OpenWonderLabs/homebridge-switchbot/releases/tag/v1.0.6) (2021-08-29)
37
+ ## [Version 1.0.6](https://github.com/OpenWonderLabs/node-switchbot/releases/tag/v1.0.6) (2021-08-29)
18
38
 
19
39
  ### Changes
20
40
 
21
41
  - Fixes FATAL ERROR: ad_id is not defined
22
42
 
23
- ## [Version 1.0.5](https://github.com/OpenWonderLabs/homebridge-switchbot/releases/tag/v1.0.5) (2021-08-04)
43
+ ## [Version 1.0.5](https://github.com/OpenWonderLabs/node-switchbot/releases/tag/v1.0.5) (2021-08-04)
24
44
 
25
45
  ### Changes
26
46
 
27
47
  - Adding code for Contact and Motion Sensors
28
48
  - Not Ready to be used yet though
29
49
 
30
- ## [Version 1.0.4](https://github.com/OpenWonderLabs/homebridge-switchbot/releases/tag/v1.0.4) (2021-08-03)
50
+ ## [Version 1.0.4](https://github.com/OpenWonderLabs/node-switchbot/releases/tag/v1.0.4) (2021-08-03)
31
51
 
32
52
  ### Changes
33
53
 
34
54
  - Support for the discover method with id on macOS
35
55
 
36
- ## [Version 1.0.3](https://github.com/OpenWonderLabs/homebridge-switchbot/releases/tag/v1.0.3) (2021-07-30)
56
+ ## [Version 1.0.3](https://github.com/OpenWonderLabs/node-switchbot/releases/tag/v1.0.3) (2021-07-30)
37
57
 
38
58
  ### Changes
39
59
 
40
60
  - Fixed misspelling.
41
61
 
42
- ## [Version 1.0.2](https://github.com/OpenWonderLabs/homebridge-switchbot/releases/tag/v1.0.2) (2021-07-29)
62
+ ## [Version 1.0.2](https://github.com/OpenWonderLabs/node-switchbot/releases/tag/v1.0.2) (2021-07-29)
43
63
 
44
64
  ### Changes
45
65
 
46
66
  - Housekeeping and update dependencies
47
67
 
48
- ## [Version 1.0.1](https://github.com/OpenWonderLabs/homebridge-switchbot/releases/tag/v1.0.1) (2021-07-29)
68
+ ## [Version 1.0.1](https://github.com/OpenWonderLabs/node-switchbot/releases/tag/v1.0.1) (2021-07-29)
49
69
 
50
70
  ### Changes
51
71
 
52
72
  - Fixed issue where after switching Bluetooth off and on, would not work properly.
53
73
 
54
- ## [Version 1.0.0](https://github.com/OpenWonderLabs/homebridge-switchbot/releases/tag/v1.0.0) (2021-01-21)
74
+ ## [Version 1.0.0](https://github.com/OpenWonderLabs/node-switchbot/releases/tag/v1.0.0) (2021-01-21)
55
75
 
56
76
  ### Changes
57
77
 
58
78
  - * fix "No device was found" in MacOS
59
79
 
60
- ## [Version 0.2.0](https://github.com/OpenWonderLabs/homebridge-switchbot/releases/tag/v0.2.0) (2020-11-05)
80
+ ## [Version 0.2.0](https://github.com/OpenWonderLabs/node-switchbot/releases/tag/v0.2.0) (2020-11-05)
61
81
 
62
82
  ### Changes
63
83
 
64
84
  - Modify Curtain's action command to support group and running mode. (Thanks to [@SwitchBot-Wonderlabs](https://github.com/OpenWonderLabs/node-switchbot/pull/7/))
65
85
 
66
- ## [Version 0.1.0](https://github.com/OpenWonderLabs/homebridge-switchbot/releases/tag/v0.1.0) (2020-10-28)
86
+ ## [Version 0.1.0](https://github.com/OpenWonderLabs/node-switchbot/releases/tag/v0.1.0) (2020-10-28)
67
87
 
68
88
  ### Changes
69
89
 
70
90
  - Added support for SwitchBot Curtain. (Thanks to [@SwitchBot-Wonderlabs](https://github.com/OpenWonderLabs/node-switchbot/pull/6/))
71
91
  - Added support for running on the Raspberry Pi Zero W. (Thanks to [@zizi4n5](https://github.com/OpenWonderLabs/node-switchbot/pull/5))
72
92
 
73
- ## [Version 0.0.5](https://github.com/OpenWonderLabs/homebridge-switchbot/releases/tag/v0.0.5) (2020-02-19)
93
+ ## [Version 0.0.5](https://github.com/OpenWonderLabs/node-switchbot/releases/tag/v0.0.5) (2020-02-19)
74
94
 
75
95
  ### Changes
76
96
 
77
97
  - Improved the stability of discovering the BLE characteristics. (Thanks to [@dnicolson](https://github.com/OpenWonderLabs/node-switchbot/issues/3))
78
98
 
79
- ## [Version 0.0.4](https://github.com/OpenWonderLabs/homebridge-switchbot/releases/tag/v0.0.4) (2020-02-11)
99
+ ## [Version 0.0.4](https://github.com/OpenWonderLabs/node-switchbot/releases/tag/v0.0.4) (2020-02-11)
80
100
 
81
101
  ### Changes
82
102
 
83
103
  - Fixed the bug that temperature value lower than 0 degC could not be handled. (Thanks to [@musimasami](https://github.com/OpenWonderLabs/node-switchbot/issues/2))
84
104
 
85
- ## [Version 0.0.3](https://github.com/OpenWonderLabs/homebridge-switchbot/releases/tag/v0.0.3) (2020-02-10)
105
+ ## [Version 0.0.3](https://github.com/OpenWonderLabs/node-switchbot/releases/tag/v0.0.3) (2020-02-10)
86
106
 
87
107
  ### Changes
88
108
 
89
109
  - Now the characteristic UUID `0x2a00` (Device Name) is not mandatory. Some models of Bot don't seem to support the characteristic. (Thanks to [@dnicolson](https://github.com/OpenWonderLabs/node-switchbot/issues/1))
90
110
  - Fixed the bug that the `turnOn()` method returns an error if the "Press mode" is selected on the Bot.
91
111
 
92
- ## [Version 0.0.2](https://github.com/OpenWonderLabs/homebridge-switchbot/releases/tag/v0.0.2) (2019-11-20)
112
+ ## [Version 0.0.2](https://github.com/OpenWonderLabs/node-switchbot/releases/tag/v0.0.2) (2019-11-20)
93
113
 
94
114
  ### Changes
95
115
 
96
- - First public release
116
+ - First public release
package/README.md CHANGED
@@ -60,33 +60,33 @@ This module is unofficial. It was developed by reference to [the official python
60
60
 
61
61
  ## Supported OS
62
62
 
63
- The node-switchbot supports only Linux-based OSes, such as Raspbian, Ubuntu, and so on. This module does not support Windows and macOS for now. (If [@homebridge/noble](https://github.com/homebridge/noble) is installed properly, this module might work well on such OSes.)
63
+ The node-switchbot supports only Linux-based OSes, such as Raspbian, Ubuntu, and so on. This module does not support Windows and macOS for now. (If [@abandonware/noble](https://github.com/abandonware/noble) is installed properly, this module might work well on such OSes.)
64
64
 
65
65
  ## Dependencies
66
66
 
67
67
  * [Node.js](https://nodejs.org/en/) 10 +
68
- * [@homebridge/noble](https://github.com/homebridge/noble)
68
+ * [@abandonware/noble](https://github.com/abandonware/noble)
69
69
 
70
70
 
71
- See the document of the [@homebridge/noble](https://github.com/homebridge/noble) for details on installing the [@homebridge/noble](https://github.com/homebridge/noble).
71
+ See the document of the [@abandonware/noble](https://github.com/abandonware/noble) for details on installing the [@abandonware/noble](https://github.com/abandonware/noble).
72
72
 
73
- Note that the noble must be run as root on most of Linux environments. See the document of the [@homebridge/noble](https://github.com/homebridge/noble) for details.
73
+ Note that the noble must be run as root on most of Linux environments. See the document of the [@abandonware/noble](https://github.com/abandonware/noble) for details.
74
74
 
75
75
  ## Installation
76
76
 
77
- Before installing the [@homebridge/noble](https://github.com/homebridge/noble), some linux libraries related Bluetooth as follows if the OS is Ubuntu/Debian/Raspbian.
77
+ Before installing the [@abandonware/noble](https://github.com/abandonware/noble), some linux libraries related Bluetooth as follows if the OS is Ubuntu/Debian/Raspbian.
78
78
 
79
79
  ```
80
80
  $ sudo apt-get install bluetooth bluez libbluetooth-dev libudev-dev
81
81
  ```
82
82
 
83
- If you use other OS, follow the instructions described in the document of the [@homebridge/noble](https://github.com/homebridge/noble).
83
+ If you use other OS, follow the instructions described in the document of the [@abandonware/noble](https://github.com/abandonware/noble).
84
84
 
85
- After installing the libraries above, install the [@homebridge/noble](https://github.com/homebridge/noble) and the node-switchbot (this module) as follows:
85
+ After installing the libraries above, install the [@abandonware/noble](https://github.com/abandonware/noble) and the node-switchbot (this module) as follows:
86
86
 
87
87
  ```
88
88
  $ cd ~
89
- $ npm install @homebridge/noble
89
+ $ npm install @abandonware/noble
90
90
  $ npm install node-switchbot
91
91
  ```
92
92
 
@@ -244,15 +244,15 @@ The `Switchbot` constructor takes an argument optionally. It must be a hash obje
244
244
 
245
245
  Property | Type | Required | Description
246
246
  :--------|:-------|:---------|:-----------
247
- `noble` | Noble | option | a Noble object of the [`@homebridge/noble`](https://github.com/homebridge/noble) module
247
+ `noble` | Noble | option | a Noble object of the [`@abandonware/noble`](https://github.com/abandonware/noble) module
248
248
 
249
- The node-switchbot module uses the [`@homebridge/noble`](https://github.com/homebridge/noble) module in order to interact with BLE devices. If you want to interact other BLE devices using the `@homebridge/noble` module, you can create an `Noble` object by yourself, then pass it to this module. If you don't specify a `Noble` object to the `noble` property, this module automatically create a `Noble` object internally.
249
+ The node-switchbot module uses the [`@abandonware/noble`](https://github.com/abandonware/noble) module in order to interact with BLE devices. If you want to interact other BLE devices using the `@abandonware/noble` module, you can create an `Noble` object by yourself, then pass it to this module. If you don't specify a `Noble` object to the `noble` property, this module automatically create a `Noble` object internally.
250
250
 
251
251
  The sample code below shows how to pass a `Nobel` object to the `Switchbot` constructor.
252
252
 
253
253
  ```JavaScript
254
254
  // Create a Noble object
255
- const noble = require('@homebridge/noble');
255
+ const noble = require('@abandonware/noble');
256
256
 
257
257
  // Create a Switchbot object
258
258
  const Switchbot = require('node-switchbot');
@@ -379,7 +379,7 @@ The `serviceData` property depends on the model of the device. See the section "
379
379
 
380
380
  ### `stopScan()` method
381
381
 
382
- The `stopScan()` method stops to scan advertising packets coming from devices. This mothod returns nothing. Note that this method is *not* asynchronous but synchronous unlike the other methods. See the section "[`startScan()` method](#startscan-method)" for details.
382
+ The `stopScan()` method stops to scan advertising packets coming from devices. This method returns nothing. Note that this method is *not* asynchronous but synchronous unlike the other methods. See the section "[`startScan()` method](#startscan-method)" for details.
383
383
 
384
384
  ### `onadvertisement` event handler
385
385
 
@@ -899,4 +899,4 @@ Property | Type | Description
899
899
  ## References
900
900
 
901
901
  * [Switchbot official global site](https://www.switch-bot.com/)
902
- * [Github - OpenWonderLabs/python-host](https://github.com/OpenWonderLabs/python-host)
902
+ * [Github - OpenWonderLabs/python-host](https://github.com/OpenWonderLabs/python-host)
@@ -78,13 +78,15 @@ class SwitchbotAdvertising {
78
78
 
79
79
  if (model === 'H') { // WoHand
80
80
  sd = this._parseServiceDataForWoHand(buf);
81
+ } else if (model === 'e') { // WoHumi
82
+ sd = this._parseServiceDataForWoHumi(buf);
81
83
  } else if (model === 'T') { // WoSensorTH
82
84
  sd = this._parseServiceDataForWoSensorTH(buf);
83
85
  } else if (model === 'c') { // WoCurtain
84
86
  sd = this._parseServiceDataForWoCurtain(buf);
85
- } else if (model === 'P') { // WoPresence
87
+ } else if (model === 's') { // WoMotion
86
88
  sd = this._parseServiceDataForWoPresence(buf);
87
- } else if (model === 'C') { // WoContact
89
+ } else if (model === 'd') { // WoContact
88
90
  sd = this._parseServiceDataForWoContact(buf);
89
91
  } else {
90
92
  return null;
@@ -139,6 +141,31 @@ class SwitchbotAdvertising {
139
141
  return data;
140
142
  }
141
143
 
144
+ _parseServiceDataForWoHumi(buf) {
145
+ if (buf.length !== 8) {
146
+ return null;
147
+ }
148
+ let byte1 = buf.readUInt8(1);
149
+ // let byte2 = buf.readUInt8(2);
150
+ let byte3 = buf.readUInt8(3);
151
+ let byte4 = buf.readUInt8(4);
152
+ let byte5 = buf.readUInt8(5);
153
+
154
+ let onState = (byte1 & 0b10000000) ? true : false; // 1 - on
155
+ let autoMode = (byte4 & 0b10000000) ? true : false; // 1 - auto
156
+ let percentage = byte4 & 0b01111111; // 0-100%, 101/102/103 - Quick gear 1/2/3
157
+
158
+ let data = {
159
+ model: 'e',
160
+ modelName: 'WoHumi',
161
+ onState: onState,
162
+ autoMode: autoMode,
163
+ percentage: autoMode ? 0 : percentage,
164
+ };
165
+
166
+ return data;
167
+ }
168
+
142
169
  _parseServiceDataForWoSensorTH(buf) {
143
170
  if (buf.length !== 6) {
144
171
  return null;
@@ -172,66 +199,53 @@ class SwitchbotAdvertising {
172
199
  if (buf.length !== 6) {
173
200
  return null;
174
201
  }
202
+ let byte1 = buf.readUInt8(1);
203
+ let byte2 = buf.readUInt8(2);
204
+ // let byte3 = buf.readUInt8(3);
205
+ // let byte4 = buf.readUInt8(4);
206
+ let byte5 = buf.readUInt8(5);
175
207
 
176
- const byte1 = buf.readUInt8(1);
177
- const byte2 = buf.readUInt8(2);
178
- const byte3 = buf.readUInt8(3);
179
- const byte4 = buf.readUInt8(4);
180
- const byte5 = buf.readUInt8(5);
181
-
182
- const motion = byte1 & 0b01000000; // Whether the calibration is completed
183
- const battery = byte2 & 0b01111111; // %
184
- const pir_trigger3 = byte3 & 0b00001111; //
185
- const pir_trigger4 = byte4 & 0b01000000; //
186
- const state = byte5 & 0b01111111; // %
208
+ let pirState = (byte1 & 0b01000000) ? true : false; // 1 - Movement detected
209
+ let battery = byte2 & 0b01111111; // %
210
+ let lightLevel = byte5 & 0b00000011;
187
211
 
188
- const data = {
212
+ let data = {
189
213
  model: 's',
190
- modelName: 'WoPresence',
191
- motion: motion ? true : false,
214
+ modelName: 'WoMotion',
215
+ movement: pirState,
192
216
  battery: battery,
193
- pir_trigger3: pir_trigger3,
194
- pir_trigger4: pir_trigger4,
195
- state: state ? true : false,
217
+ lightLevel: (lightLevel == 1) ? 'dark' : ((lightLevel == 2) ? 'bright' : 'unknown'),
196
218
  };
197
219
 
198
220
  return data;
199
221
  }
200
222
 
201
223
  _parseServiceDataForWoContact(buf) {
202
- if (buf.length !== 6) {
224
+ if (buf.length !== 9) {
203
225
  return null;
204
226
  }
205
227
 
206
- const byte1 = buf.readUInt8(1);
207
- const byte2 = buf.readUInt8(2);
208
- const byte3 = buf.readUInt8(3);
209
- const byte4 = buf.readUInt8(4);
210
- const byte5 = buf.readUInt8(5);
211
- const byte6 = buf.readUInt8(6);
212
- const byte7 = buf.readUInt8(7);
213
- const byte8 = buf.readUInt8(8);
228
+ let byte1 = buf.readUInt8(1);
229
+ let byte2 = buf.readUInt8(2);
230
+ let byte3 = buf.readUInt8(3);
231
+ // let byte4 = buf.readUInt8(4);
232
+ // let byte5 = buf.readUInt8(5);
233
+ // let byte6 = buf.readUInt8(6);
234
+ // let byte7 = buf.readUInt8(7);
235
+ // let byte8 = buf.readUInt8(8);
214
236
 
215
- const motion = byte1 & 0b01000000; // Whether there is motion
216
- const battery = byte2 & 0b01111111; // %
217
- const state = byte3 & 0b01111111; // current state
218
- const pir_trigger4 = byte4 & 0b00001111; //
219
- const pir_trigger5 = byte5 & 0b01000000; //
220
- const hal_trigger6 = byte6 & 0b01111111; //
221
- const hal_trigger7 = byte7 & 0b01111111; //
222
- const act_counter = byte8 & 0b00001111; //
237
+ let pirState = (byte1 & 0b01000000) ? true : false; // 1 - Movement detected
238
+ let battery = byte2 & 0b01111111; // %
239
+ let hallState = (byte3 >> 1) & 0b00000011;
240
+ let lightLevel = byte3 & 0b00000001;
223
241
 
224
- const data = {
242
+ let data = {
225
243
  model: 'd',
226
244
  modelName: 'WoContact',
227
- motion: motion ? true : false,
245
+ movement: pirState,
228
246
  battery: battery,
229
- state: state ? true : false,
230
- pir_trigger4: pir_trigger4,
231
- pir_trigger5: pir_trigger5,
232
- hal_trigger6: hal_trigger6,
233
- hal_trigger7: hal_trigger7,
234
- act_counter: act_counter,
247
+ doorState: (hallState == 0) ? 'close' : ((hallState == 1) ? 'open' : 'timeout no closed'),
248
+ lightLevel: (lightLevel == 0) ? 'dark' : 'bright',
235
249
  };
236
250
 
237
251
  return data;
@@ -246,7 +260,7 @@ class SwitchbotAdvertising {
246
260
  let byte3 = buf.readUInt8(3);
247
261
  let byte4 = buf.readUInt8(4);
248
262
 
249
- let calibration = byte1 & 0b01000000; // Whether the calibration is completed
263
+ let calibration = (byte1 & 0b01000000) ? true : false; // Whether the calibration is completed
250
264
  let battery = byte2 & 0b01111111; // %
251
265
  let currPosition = byte3 & 0b01111111; // current positon %
252
266
  let lightLevel = (byte4 >> 4) & 0b00001111; // light sensor level (1-10)
@@ -254,7 +268,7 @@ class SwitchbotAdvertising {
254
268
  let data = {
255
269
  model: 'c',
256
270
  modelName: 'WoCurtain',
257
- calibration: calibration ? true : false,
271
+ calibration: calibration,
258
272
  battery: battery,
259
273
  position: currPosition,
260
274
  lightLevel: lightLevel
@@ -264,4 +278,4 @@ class SwitchbotAdvertising {
264
278
  }
265
279
  }
266
280
 
267
- module.exports = new SwitchbotAdvertising();
281
+ module.exports = new SwitchbotAdvertising();
@@ -0,0 +1,114 @@
1
+ 'use strict';
2
+ const SwitchbotDevice = require('./switchbot-device.js');
3
+
4
+ class SwitchbotDeviceWoHumi extends SwitchbotDevice {
5
+
6
+ /* ------------------------------------------------------------------
7
+ * Auto()
8
+ * - Set Mode to Auto
9
+ *
10
+ * [Arguments]
11
+ * - none
12
+ *
13
+ * [Returen value]
14
+ * - Promise object
15
+ * Nothing will be passed to the `resolve()`.
16
+ * ---------------------------------------------------------------- */
17
+ Auto() {
18
+ return this._operateHumi([0x57, 0x01, 0x80]);
19
+ }
20
+
21
+ /* ------------------------------------------------------------------
22
+ * First()
23
+ * - Set Mode to First
24
+ *
25
+ * [Arguments]
26
+ * - none
27
+ *
28
+ * [Returen value]
29
+ * - Promise object
30
+ * Nothing will be passed to the `resolve()`.
31
+ * ---------------------------------------------------------------- */
32
+ First() {
33
+ return this._operateHumi([0x57, 0x01, 0x65]);
34
+ }
35
+
36
+ /* ------------------------------------------------------------------
37
+ * Second()
38
+ * - Set Mode to Second
39
+ *
40
+ * [Arguments]
41
+ * - none
42
+ *
43
+ * [Returen value]
44
+ * - Promise object
45
+ * Nothing will be passed to the `resolve()`.
46
+ * ---------------------------------------------------------------- */
47
+ Second() {
48
+ return this._operateHumi([0x57, 0x01, 0x66]);
49
+ }
50
+
51
+ /* ------------------------------------------------------------------
52
+ * Third()
53
+ * - Set Mode to Third
54
+ *
55
+ * [Arguments]
56
+ * - none
57
+ *
58
+ * [Returen value]
59
+ * - Promise object
60
+ * Nothing will be passed to the `resolve()`.
61
+ * ---------------------------------------------------------------- */
62
+ Third() {
63
+ return this._operateHumi([0x57, 0x01, 0x67]);
64
+ }
65
+
66
+ /* ------------------------------------------------------------------
67
+ * up()
68
+ * - Up
69
+ *
70
+ * [Arguments]
71
+ * - none
72
+ *
73
+ * [Returen value]
74
+ * - Promise object
75
+ * Nothing will be passed to the `resolve()`.
76
+ * ---------------------------------------------------------------- */
77
+ percentage() {
78
+ return this._operateHumi([0x57, 0x01, 0x01]);
79
+ }
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) {
97
+ return new Promise((resolve, reject) => {
98
+ let req_buf = Buffer.from(bytes);
99
+ this._command(req_buf).then((res_buf) => {
100
+ let code = res_buf.readUInt8(0);
101
+ if (res_buf.length === 3 && (code === 0x01 || code === 0x05)) {
102
+ resolve();
103
+ } else {
104
+ reject(new Error('The device returned an error: 0x' + res_buf.toString('hex')));
105
+ }
106
+ }).catch((error) => {
107
+ reject(error);
108
+ });
109
+ });
110
+ }
111
+
112
+ }
113
+
114
+ module.exports = SwitchbotDeviceWoHumi;
package/lib/switchbot.js CHANGED
@@ -8,6 +8,7 @@ const SwitchbotDeviceWoCurtain = require('./switchbot-device-wocurtain.js');
8
8
  const SwitchbotDeviceWoPresence = require('./switchbot-device-wopresence.js');
9
9
  const SwitchbotDeviceWoContact = require('./switchbot-device-wocontact.js');
10
10
  const SwitchbotDeviceWoSensorTH = require('./switchbot-device-wosensorth.js');
11
+ const SwitchbotDeviceWoHumi = require('./switchbot-device-wohumi.js');
11
12
 
12
13
  class Switchbot {
13
14
  /* ------------------------------------------------------------------
@@ -26,7 +27,7 @@ class Switchbot {
26
27
  if (params && params.noble) {
27
28
  noble = params.noble;
28
29
  } else {
29
- noble = require('@homebridge/noble');
30
+ noble = require('@abandonware/noble');
30
31
  }
31
32
 
32
33
  // Plublic properties
@@ -49,12 +50,13 @@ class Switchbot {
49
50
  * - duration | Integer | Optional | Duration for discovery process (msec).
50
51
  * | | | The value must be in the range of 1 to 60000.
51
52
  * | | | The default value is 5000 (msec).
52
- * - model | String | Optional | "H", "T", "M", "D", or "S".
53
+ * - model | String | Optional | "H", "T", "e", "s", "d", or "c".
53
54
  * | | | If "H" is specified, this method will discover only Bots.
54
55
  * | | | If "T" is specified, this method will discover only Meters.
55
- * | | | If "S" is specified, this method will discover only Motion Sensors.
56
- * | | | If "D" is specified, this method will discover only Contact Sensors.
57
- * | | | If "C" is specified, this method will discover only Curtains.
56
+ * | | | If "e" is specified, this method will discover only Humidifiers.
57
+ * | | | If "s" is specified, this method will discover only Motion Sensors.
58
+ * | | | If "d" is specified, this method will discover only Contact Sensors.
59
+ * | | | If "c" is specified, this method will discover only Curtains.
58
60
  * - id | String | Optional | If this value is set, this method willl discover
59
61
  * | | | only a device whose ID is as same as this value.
60
62
  * | | | The ID is identical to the MAC address.
@@ -76,7 +78,7 @@ class Switchbot {
76
78
  // Check the parameters
77
79
  let valid = parameterChecker.check(params, {
78
80
  duration: { required: false, type: 'integer', min: 1, max: 60000 },
79
- model: { required: false, type: 'string', enum: ['H', 'h','T', 'P', 'S', 'D', 'C', 'c'] },
81
+ model: { required: false, type: 'string', enum: ['H', 'T', 'e', 's', 'd', 'c'] },
80
82
  id: { required: false, type: 'string', min: 12, max: 17 },
81
83
  quick: { required: false, type: 'boolean' }
82
84
  }, false);
@@ -183,13 +185,16 @@ class Switchbot {
183
185
  case 'H':
184
186
  device = new SwitchbotDeviceWoHand(peripheral, this.noble);
185
187
  break;
188
+ case 'e':
189
+ device = new SwitchbotDeviceWoHumi(peripheral, this.noble);
190
+ break;
186
191
  case 'T':
187
192
  device = new SwitchbotDeviceWoSensorTH(peripheral, this.noble);
188
193
  break;
189
- case 'S':
194
+ case 's':
190
195
  device = new SwitchbotDeviceWoPresence(peripheral, this.noble);
191
196
  break;
192
- case 'D':
197
+ case 'd':
193
198
  device = new SwitchbotDeviceWoContact(peripheral, this.noble);
194
199
  break;
195
200
  case 'c':
@@ -229,20 +234,23 @@ class Switchbot {
229
234
  *
230
235
  * [Arguments]
231
236
  * - params | Object | Optional |
232
- * - model | String | Optional | "H", "T", "M", "CS", or "C".
237
+ * - model | String | Optional | "H", "T", "e", "s", "d", or "c".
233
238
  * | | | If "H" is specified, the `onadvertisement`
234
239
  * | | | event hander will be called only when advertising
235
240
  * | | | packets comes from Bots.
236
241
  * | | | If "T" is specified, the `onadvertisement`
237
242
  * | | | event hander will be called only when advertising
238
243
  * | | | packets comes from Meters.
239
- * | | | If "S" is specified, the `onadvertisement`
244
+ * | | | If "e" is specified, the `onadvertisement`
245
+ * | | | event hander will be called only when advertising
246
+ * | | | packets comes from Humidifiers.
247
+ * | | | If "s" is specified, the `onadvertisement`
240
248
  * | | | event hander will be called only when advertising
241
249
  * | | | packets comes from Motion Sensor.
242
- * | | | If "D" is specified, the `onadvertisement`
250
+ * | | | If "d" is specified, the `onadvertisement`
243
251
  * | | | event hander will be called only when advertising
244
252
  * | | | packets comes from Contact Sensor.
245
- * | | | If "C" is specified, the `onadvertisement`
253
+ * | | | If "c" is specified, the `onadvertisement`
246
254
  * | | | event hander will be called only when advertising
247
255
  * | | | packets comes from Curtains.
248
256
  * - id | String | Optional | If this value is set, the `onadvertisement`
@@ -261,7 +269,7 @@ class Switchbot {
261
269
  let promise = new Promise((resolve, reject) => {
262
270
  // Check the parameters
263
271
  let valid = parameterChecker.check(params, {
264
- model: { required: false, type: 'string', enum: ['H', 'h','T', 'P', 'S', 'D', 'C', 'c'] },
272
+ model: { required: false, type: 'string', enum: ['H', 'T', 'e', 's', 'd', 'c'] },
265
273
  id: { required: false, type: 'string', min: 12, max: 17 },
266
274
  }, false);
267
275
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-switchbot",
3
- "version": "1.0.9-beta.4",
3
+ "version": "1.1.3-beta.0",
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": [
@@ -30,13 +30,13 @@
30
30
  "license": "MIT",
31
31
  "repository": {
32
32
  "type": "git",
33
- "url": "https://github.com/futomi/node-switchbot.git"
33
+ "url": "https://github.com/OpenWonderLabs/node-switchbot.git"
34
34
  },
35
35
  "readmeFilename": "README.md",
36
36
  "dependencies": {
37
- "@homebridge/noble": "^1.9.3"
37
+ "@abandonware/noble": "^1.9.2-15"
38
38
  },
39
39
  "devDependencies": {
40
- "npm-check-updates": "^11.8.5"
40
+ "npm-check-updates": "^12.0.2"
41
41
  }
42
42
  }