node-switchbot 1.2.1-beta.9 → 1.3.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.
Files changed (3) hide show
  1. package/CHANGELOG.md +9 -0
  2. package/README.md +87 -22
  3. package/package.json +40 -40
package/CHANGELOG.md CHANGED
@@ -2,6 +2,15 @@
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.3.0](https://github.com/OpenWonderLabs/node-switchbot/releases/tag/v1.2.0) (2022-06-25)
6
+
7
+ ### Changes
8
+
9
+ - Added more Device Types, not all supported though.
10
+ - Housekeeping and update dependencies
11
+
12
+ **Full Changelog**: https://github.com/OpenWonderLabs/node-switchbot/compare/v1.2.0...v1.3.0
13
+
5
14
  ## [Version 1.2.0](https://github.com/OpenWonderLabs/node-switchbot/releases/tag/v1.2.0) (2022-03-04)
6
15
 
7
16
  ### Changes
package/README.md CHANGED
@@ -4,14 +4,17 @@
4
4
 
5
5
  <a href="https://www.npmjs.com/package/node-switchbot"><img title="npm version" src="https://badgen.net/npm/v/node-switchbot" ></a>
6
6
  <a href="https://www.npmjs.com/package/node-switchbot"><img title="npm downloads" src="https://badgen.net/npm/dt/node-switchbot" ></a>
7
-
8
- </p>
9
7
 
10
8
  </span>
11
9
 
12
- The node-switchbot is a Node.js module which allows you to move your [Switchbot (Bot)](https://www.switch-bot.com/bot)'s arm and [Switchbot Curtain(Curtain)](https://www.switch-bot.com/products/switchbot-curtain), also monitor the temperature/humidity from [SwitchBot Thermometer & Hygrometer (Meter)](https://www.switch-bot.com/meter).
10
+ The node-switchbot is a Node.js module which allows you to move your [Switchbot (Bot)'s](https://www.switch-bot.com/bot) arm
11
+ and [Switchbot Curtain](https://www.switch-bot.com/products/switchbot-curtain),
12
+ also monitor the temperature/humidity from [SwitchBot Thermometer & Hygrometer (Meter)](https://www.switch-bot.com/meter)
13
+ as well as the status from [SwitchBot Motion Sensor](https://www.switch-bot.com/products/motion-sensor)
14
+ and [SwitchBot Contact Sensor](https://www.switch-bot.com/products/contact-sensor)
13
15
 
14
- This module is unofficial. It was developed by reference to [the official python code](https://github.com/OpenWonderLabs/python-host). But some functionalities of this module were developed through trial and error. So some information obtained from this module might be wrong.
16
+ This module is unofficial. It was developed by reference to [the official python code](https://github.com/OpenWonderLabs/python-host).
17
+ But some functionalities of this module were developed through trial and error. So some information obtained from this module might be wrong.
15
18
 
16
19
  ---------------------------------------
17
20
  ## Table of Contents
@@ -26,7 +29,7 @@ This module is unofficial. It was developed by reference to [the official python
26
29
  - [Moving the arm of the Bot](#moving-the-arm-of-the-bot)
27
30
  - [`Switchbot` object](#switchbot-object)
28
31
  - [`discover()` method](#discover-method)
29
- - [`ondiscover` event hander](#ondiscover-event-hander)
32
+ - [`ondiscover` event handler](#ondiscover-event-hander)
30
33
  - [`startScan()` method](#startscan-method)
31
34
  - [`stopScan()` method](#stopscan-method)
32
35
  - [`onadvertisement` event handler](#onadvertisement-event-handler)
@@ -54,6 +57,8 @@ This module is unofficial. It was developed by reference to [the official python
54
57
  - [Bot (WoHand)](#bot-wohand)
55
58
  - [Meter (WoSensorTH)](#meter-wosensorth)
56
59
  - [Curtain (WoCurtain)](#curtain-wocurtain)
60
+ - [Contact (WoContact)](#contact-wocontact)
61
+ - [Motion (WoMotion)](#motion-womotion)
57
62
  - [Release Note](#release-note)
58
63
  - [References](#references)
59
64
  - [License](#license)
@@ -120,7 +125,7 @@ const switchbot = new Switchbot();
120
125
 
121
126
  The [`startScan()`](#startscan-method) methods starts to monitor advertisement packets. In order to receive the packets, you have to assign a callback function to the [`onadvertisement`](#Switchbot-onadvertisement-event-handler).
122
127
 
123
- The [`wait()`](#Switchbot-wait-method) method is just an utility method, which wait for the specified milliseconds.
128
+ The [`wait()`](#Switchbot-wait-method) method is just a utility method, which wait for the specified milliseconds.
124
129
 
125
130
  The [`startScan()`](#startscan-method) and [`wait()`](#Switchbot-wait-method) methods are asynchronous, they return a `Promise` object. You can write code in promise style as well. What the code below does is as same as what the code above does:
126
131
 
@@ -300,7 +305,7 @@ switchbot.discover({
300
305
 
301
306
  As the `quick` property is set to `true`, the `resolve()` function will be called immediately after a device is found regardless the value of the `duration` property.
302
307
 
303
- ### `ondiscover` event hander
308
+ ### `ondiscover` event handler
304
309
 
305
310
  The `ondiscover` property on the [`Switchbot`](#Switchbot-object) object is an event handler called whenever a device is newly found in the discovery process. A [`SwitchbotDevice`](#SwitchbotDevice-object) object is passed to the callback function set to the `ondiscover` property.
306
311
 
@@ -391,16 +396,16 @@ See the section "[`startScan()` method](#startscan-method)" for details.
391
396
 
392
397
  The `wait()` method waits for the specified milliseconds. This method takes an integer representing the duration (millisecond). This method returns a `Promise` object.
393
398
 
394
- This method has nothing to do with Switchbot devices. It's just an utility method. See the section "[Quick Start](#Quick-Start)" for details of the usage of this method.
399
+ This method has nothing to do with Switchbot devices. It's just a utility method. See the section "[Quick Start](#Quick-Start)" for details of the usage of this method.
395
400
 
396
401
  ---------------------------------------
397
402
  ## `SwitchbotDevice` object
398
403
 
399
- The `SwitchbotDevice` object represents a Switchbot device (Bot or Meter), which is created through the discovery process triggered by the [`Switchbot.discover()`](#Switchbot-discover-method) method.
404
+ The `SwitchbotDevice` object represents a Switchbot device (Bot, Meter, Curtain, Contact or Motion), which is created through the discovery process triggered by the [`Switchbot.discover()`](#Switchbot-discover-method) method.
400
405
 
401
- Actually, the `SwitchbotDevice` object is an super class of the [`SwitchbotDeviceWoHand`](#SwitchbotDeviceWoHand-object) and `SwitchbotDeviceWoSensorTH` objects. The [`SwitchbotDeviceWoHand`](#SwitchbotDeviceWoHand-object) object represents a Bot, the `SwitchbotDeviceWoSensorTH` object represents a Meter.
406
+ Actually, the `SwitchbotDevice` object is a super class of the [`SwitchbotDeviceWoHand`](#SwitchbotDeviceWoHand-object) and `SwitchbotDeviceWoSensorTH` objects. The [`SwitchbotDeviceWoHand`](#SwitchbotDeviceWoHand-object) object represents a Bot, the `SwitchbotDeviceWoSensorTH` object represents a Meter.
402
407
 
403
- You can use the properties and methods described in this section on both Bot and Meter. See the section "[`SwitchbotDeviceWoHand` object](#SwitchbotDeviceWoHand-object)" for the details of the functionalities available only on Bot. For now, `SwitchbotDeviceWoSensorTH` object has no additional functionality.
408
+ You can use the properties and methods described in this section on Bot, Meter, Curtain, Contact and Motion. See the section "[`SwitchbotDeviceWoHand` object](#SwitchbotDeviceWoHand-object)" for the details of the functionalities available only on Bot. For now, `SwitchbotDeviceWoSensorTH` object has no additional functionality.
404
409
 
405
410
  ### Properties
406
411
 
@@ -410,8 +415,8 @@ Property | Type | Description
410
415
  :----------------|:---------|:-----------
411
416
  `id` | String | ID of the device. (e.g., `"cb4eb903c96d"`)
412
417
  `address` | String | MAC address of the device. Basically it is as same as the value of the `id` except that this value includes `:` in the string. (e.g., `"cb:4e:b9:03:c9:6d"`)
413
- `model` | String | This value is `"H"` which means "Bot (WoHand)", `"T"` which means "Meter (WoSensorTH)" or `"c"` which means "Curtain (WoCurtain)".
414
- `modelName` | String | This value is `"WoHand"` or `"WoSensorTH"`.
418
+ `model` | String | This value is `"H"` "Bot (WoHand)", `"T"` "Meter (WoSensorTH)", `"c"` "Curtain (WoCurtain)", `"d"` "Contact (WoContact)" or `"s"` "Motion (WoMotion)".
419
+ `modelName` | String | This value is `"WoHand"`, `"WoSensorTH"`, `WoCurtain`, `WoContect` or `WoMotion`.
415
420
  `connectionState` | String | This value indicates the BLE connection state. `"connecting"`, `"connected"`, `"disconnecting"`, or `"disconnected"`.
416
421
  `onconnect` | Function | See the section "[`onconnect` event handler](#SwitchbotDevice-onconnect-event-handler)" for details.
417
422
  `ondisconnect` | Function | See the section "[`ondisconnect` event handler](#SwitchbotDevice-ondisconnect-event-handler)" for details.
@@ -448,7 +453,7 @@ The `setDeviceName()` method update the device name saved in the device with the
448
453
 
449
454
  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.
450
455
 
451
- The character set of the device name saved in the device is UTF-8. The byte length of the name must be less than or equal to 20 bytes. If the name consists of only ASCII characters, up to 20 characters would be allowed. But if the name consists of multi-byte characters, the upper limit of characters would be fewer than half. For example, Japanese characters could be saved at most 6 characters because most of Japanese characters consume 3 byte per each character.
456
+ The character set of the device name saved in the device is UTF-8. The byte length of the name must be less than or equal to 20 bytes. If the name consists of only ASCII characters, up to 20 characters would be allowed. But if the name consists of multibyte characters, the upper limit of characters would be fewer than half. For example, Japanese characters could be saved at most 6 characters because most of Japanese characters consume 3 byte per each character.
452
457
 
453
458
  ```javascript
454
459
  switchbot.discover({ model: 'H', quick: true }).then((device_list) => {
@@ -525,7 +530,7 @@ See the [previous section](#SwitchbotDevice-connect-method) for more details.
525
530
 
526
531
  ### `onconnect` event handler
527
532
 
528
- The `onconnect` event hander will be called when the connection with the device is established. Nothing will be passed to the hander.
533
+ The `onconnect` event handler will be called when the connection with the device is established. Nothing will be passed to the handler.
529
534
 
530
535
  The code below calls the [`press()`](#SwitchbotDeviceWoHand-press-method) method, while callback functions are attached to the `onconnect` and `ondisconnect`.
531
536
 
@@ -571,12 +576,12 @@ Seeing the result, you would find the [`press()`](#SwitchbotDeviceWoHand-press-m
571
576
 
572
577
  ### `ondisconnect` event handler
573
578
 
574
- The `ondisconnect` event hander will be called when the connection with the device is closed. Nothing will be passed to the hander. See the previous section "[`onconnect` event handler](#SwitchbotDevice-onconnect-event-handler)" for more details.
579
+ The `ondisconnect` event handler will be called when the connection with the device is closed. Nothing will be passed to the handler. See the previous section "[`onconnect` event handler](#SwitchbotDevice-onconnect-event-handler)" for more details.
575
580
 
576
581
  ---------------------------------------
577
582
  ## `SwitchbotDeviceWoHand` object
578
583
 
579
- The `SwitchbotDeviceWoHand` object represents an Bot, which is created through the discovery process triggered by the [`Switchbot.discover()`](#Switchbot-discover-method) method.
584
+ The `SwitchbotDeviceWoHand` object represents a Bot, which is created through the discovery process triggered by the [`Switchbot.discover()`](#Switchbot-discover-method) method.
580
585
 
581
586
  Actually, the `SwitchbotDeviceWoHand` is an object inherited from the [`SwitchbotDevice`](#SwitchbotDevice-object). You can use not only the method described in this section but also the properties and methods implemented in the [`SwitchbotDevice`](#SwitchbotDevice-object) object.
582
587
 
@@ -685,7 +690,7 @@ switchbot.discover({ model: 'H', quick: true }).then((device_list) => {
685
690
  ---------------------------------------
686
691
  ## `SwitchbotDeviceWoCurtain` object
687
692
 
688
- The `SwitchbotDeviceWoCurtain` object represents an Curtain, which is created through the discovery process triggered by the [`Switchbot.discover()`](#Switchbot-discover-method) method.
693
+ The `SwitchbotDeviceWoCurtain` object represents a Curtain, which is created through the discovery process triggered by the [`Switchbot.discover()`](#Switchbot-discover-method) method.
689
694
 
690
695
  Actually, the `SwitchbotDeviceWoCurtain` is an object inherited from the [`SwitchbotDevice`](#SwitchbotDevice-object). You can use not only the method described in this section but also the properties and methods implemented in the [`SwitchbotDevice`](#SwitchbotDevice-object) object.
691
696
 
@@ -746,7 +751,7 @@ If no connection is established with the device, this method automatically estab
746
751
  When the Curtain receives this command, the Curtain will run to the percentage position. If not calibrated, the Curtain does not move.
747
752
 
748
753
 
749
- The `open()` method sends a open command to the Curtain. This method returns a `Promise` object. Nothing will be passed to the `resove()`.
754
+ The `open()` method sends an open command to the Curtain. This method returns a `Promise` object. Nothing will be passed to the `resove()`.
750
755
 
751
756
  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.
752
757
 
@@ -755,7 +760,7 @@ When the Curtain receives this command, the Curtain will open the curtain (0% po
755
760
  Property | Type | Required | Description
756
761
  :------------|:--------|:---------|:------------
757
762
  `percent` | Integer | Required | The percentage of target position (`0-100`). (e.g., `50`)
758
- `mode` | Integer | Optional | The running mode of Curtain. <br/>`0x00` - Performance mode.<br/> `0x01` - Slient mode. <br/>`0xff` - Default. Unspecified, from Curtain's settings.
763
+ `mode` | Integer | Optional | The running mode of Curtain. <br/>`0x00` - Performance mode.<br/> `0x01` - Silent mode. <br/>`0xff` - Default. Unspecified, from Curtain's settings.
759
764
 
760
765
  ```javascript
761
766
  switchbot.discover({ model: 'c', quick: true }).then((device_list) => {
@@ -860,7 +865,7 @@ Property | Type | Description
860
865
  `humidity` | Integer | Humidity (`%`)
861
866
  `battery` | Integer | (**experimental**) This value indicates the battery level (`%`).
862
867
 
863
- The `fahrenheit` indicates the setting on the device. Note that it does *not* indicate the setting on the official smartphone app. The setting of the temperature unit on the device and the setting on the app are independent.
868
+ The `fahrenheit` indicates the setting on the device. Note that it does *not* indicate the setting on the official smartphone app. The setting of the temperature unit on the device and the setting on the app are independent.
864
869
 
865
870
  The `battery` is *experimental* for now. I'm not sure whether the value is correct or not. Never trust this value for now.
866
871
 
@@ -895,8 +900,68 @@ Property | Type | Description
895
900
  `position` | Integer | This value indicates the percentage of current position (`0-100`, 0 is open, `%`).
896
901
  `lightLevel` | Integer | This value indicates the light level of the light source currently set (`1-10`).
897
902
 
903
+ ### Contact (WoContact)
904
+
905
+ Example of the advertisement data:
906
+
907
+ ```json
908
+ {
909
+ "id": "f0cda125e3ec",
910
+ "address": "f0:cd:a1:25:e3:ec",
911
+ "rssi": -56,
912
+ "serviceData": {
913
+ "model": "d",
914
+ "modelName": "WoContact",
915
+ "movement": false,
916
+ "battery": 95,
917
+ "doorState": "close",
918
+ "lightLevel": "bright"
919
+ }
920
+ }
921
+ ```
922
+
923
+ Structure of the `serviceData`:
924
+
925
+ Property | Type | Description
926
+ :-------------|:--------|:-----------
927
+ `model` | String | This value is always `"c"`, which means "Contact (WoContact)".
928
+ `modelName` | String | This value is always `"WoContact"`, which means "Contact".
929
+ `movement` | Boolean | This value indicates the motion status (`true` or `false`).
930
+ `battery` | Integer | This value indicates the battery level (`1-100`, `%`).
931
+ `doorState` | String | This value indicates the door Status (`close`, `open`, `timeout no closed`).
932
+ `lightLevel` | String | This value indicates the light level (`dark`, `bright`).
933
+
934
+ ### Motion (WoMotion)
935
+
936
+ Example of the advertisement data:
937
+
938
+ ```json
939
+ {
940
+ "id": "e7216fa344a9",
941
+ "address": "e7:21:6f:a3:44:a9",
942
+ "rssi": -53,
943
+ "serviceData": {
944
+ "model": "s",
945
+ "modelName": "WoMotion",
946
+ "movement": false,
947
+ "battery": 96,
948
+ "lightLevel": "bright"
949
+ }
950
+ }
951
+ ```
952
+
953
+ Structure of the `serviceData`:
954
+
955
+ Property | Type | Description
956
+ :-------------|:--------|:-----------
957
+ `model` | String | This value is always `"s"`, which means "Motion (WoMotion)".
958
+ `modelName` | String | This value is always `"WoMotion"`, which means "Motion".
959
+ `movement` | Boolean | This value indicates the motion status (`true` or `false`).
960
+ `battery` | Integer | This value indicates the battery level (`1-100`, `%`).
961
+ `lightLevel` | String | This value indicates the light level (`dark`, `bright`).
962
+
898
963
  ---------------------------------------
899
964
  ## References
900
965
 
901
966
  * [Switchbot official global site](https://www.switch-bot.com/)
902
- * [Github - OpenWonderLabs/python-host](https://github.com/OpenWonderLabs/python-host)
967
+ * [GitHub - OpenWonderLabs/SwitchBotAPI-BLE](https://github.com/OpenWonderLabs/SwitchBotAPI-BLE)
package/package.json CHANGED
@@ -1,42 +1,42 @@
1
1
  {
2
- "name": "node-switchbot",
3
- "version": "1.2.1-beta.9",
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
- "main": "./lib/switchbot.js",
6
- "files": [
7
- "lib"
8
- ],
9
- "directories": {
10
- "lib": "./lib"
11
- },
12
- "scripts": {
13
- "check": "npm install && npm outdated",
14
- "update": "ncu -u && npm update && npm install"
15
- },
16
- "keywords": [
17
- "switchbot",
18
- "bot",
19
- "meter",
20
- "temperature",
21
- "humidity",
22
- "curtain",
23
- "BLE",
24
- "Bluetooth Low Energy",
25
- "Bluetooth smart",
26
- "Bluetooth"
27
- ],
28
- "homepage": "https://github.com/OpenWonderLabs",
29
- "author": "OpenWonderLabs (https://github.com/OpenWonderLabs)",
30
- "license": "MIT",
31
- "repository": {
32
- "type": "git",
33
- "url": "https://github.com/OpenWonderLabs/node-switchbot.git"
34
- },
35
- "readmeFilename": "README.md",
36
- "dependencies": {
37
- "@abandonware/noble": "^1.9.2-15"
38
- },
39
- "devDependencies": {
40
- "npm-check-updates": "^12.5.3"
41
- }
2
+ "name": "node-switchbot",
3
+ "version": "1.3.0",
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
+ "main": "./lib/switchbot.js",
6
+ "files": [
7
+ "lib"
8
+ ],
9
+ "directories": {
10
+ "lib": "./lib"
11
+ },
12
+ "scripts": {
13
+ "check": "npm install && npm outdated",
14
+ "update": "ncu -u && npm update && npm install"
15
+ },
16
+ "keywords": [
17
+ "switchbot",
18
+ "bot",
19
+ "meter",
20
+ "temperature",
21
+ "humidity",
22
+ "curtain",
23
+ "BLE",
24
+ "Bluetooth Low Energy",
25
+ "Bluetooth smart",
26
+ "Bluetooth"
27
+ ],
28
+ "homepage": "https://github.com/OpenWonderLabs",
29
+ "author": "OpenWonderLabs (https://github.com/OpenWonderLabs)",
30
+ "license": "MIT",
31
+ "repository": {
32
+ "type": "git",
33
+ "url": "https://github.com/OpenWonderLabs/node-switchbot.git"
34
+ },
35
+ "readmeFilename": "README.md",
36
+ "dependencies": {
37
+ "@abandonware/noble": "^1.9.2-15"
38
+ },
39
+ "devDependencies": {
40
+ "npm-check-updates": "^14.1.1"
41
+ }
42
42
  }