node-switchbot 1.2.1-beta.9 → 1.4.1

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
@@ -4,16 +4,20 @@
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.
18
+
19
+ ---
15
20
 
16
- ---------------------------------------
17
21
  ## Table of Contents
18
22
 
19
23
  - [node-switchbot](#node-switchbot)
@@ -26,7 +30,7 @@ This module is unofficial. It was developed by reference to [the official python
26
30
  - [Moving the arm of the Bot](#moving-the-arm-of-the-bot)
27
31
  - [`Switchbot` object](#switchbot-object)
28
32
  - [`discover()` method](#discover-method)
29
- - [`ondiscover` event hander](#ondiscover-event-hander)
33
+ - [`ondiscover` event handler](#ondiscover-event-hander)
30
34
  - [`startScan()` method](#startscan-method)
31
35
  - [`stopScan()` method](#stopscan-method)
32
36
  - [`onadvertisement` event handler](#onadvertisement-event-handler)
@@ -54,6 +58,8 @@ This module is unofficial. It was developed by reference to [the official python
54
58
  - [Bot (WoHand)](#bot-wohand)
55
59
  - [Meter (WoSensorTH)](#meter-wosensorth)
56
60
  - [Curtain (WoCurtain)](#curtain-wocurtain)
61
+ - [Contact (WoContact)](#contact-wocontact)
62
+ - [Motion (WoMotion)](#motion-womotion)
57
63
  - [Release Note](#release-note)
58
64
  - [References](#references)
59
65
  - [License](#license)
@@ -64,9 +70,8 @@ The node-switchbot supports only Linux-based OSes, such as Raspbian, Ubuntu, and
64
70
 
65
71
  ## Dependencies
66
72
 
67
- * [Node.js](https://nodejs.org/en/) 10 +
68
- * [@abandonware/noble](https://github.com/abandonware/noble)
69
-
73
+ - [Node.js](https://nodejs.org/en/) 10 +
74
+ - [@abandonware/noble](https://github.com/abandonware/noble)
70
75
 
71
76
  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
77
 
@@ -90,7 +95,8 @@ $ npm install @abandonware/noble
90
95
  $ npm install node-switchbot
91
96
  ```
92
97
 
93
- ---------------------------------------
98
+ ---
99
+
94
100
  ## Quick Start
95
101
 
96
102
  ### Monitoring Advertising packets
@@ -120,29 +126,32 @@ const switchbot = new Switchbot();
120
126
 
121
127
  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
128
 
123
- The [`wait()`](#Switchbot-wait-method) method is just an utility method, which wait for the specified milliseconds.
129
+ The [`wait()`](#Switchbot-wait-method) method is just a utility method, which wait for the specified milliseconds.
124
130
 
125
131
  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
132
 
127
133
  ```javascript
128
134
  // Load the node-switchbot and get a `Switchbot` constructor object
129
- const Switchbot = require('node-switchbot');
135
+ const Switchbot = require("node-switchbot");
130
136
  // Create an `Switchbot` object
131
137
  let switchbot = new Switchbot();
132
138
 
133
139
  // Start to monitor advertisement packets
134
- switchbot.startScan().then(() => {
135
- // Set an event hander
136
- switchbot.onadvertisement = (ad) => {
137
- console.log(JSON.stringify(ad, null, ' '));
138
- };
139
- // Wait 10 seconds
140
- return switchbot.wait(10000);
141
- }).then(() => {
142
- // Stop to monitor
143
- switchbot.stopScan();
144
- process.exit();
145
- });
140
+ switchbot
141
+ .startScan()
142
+ .then(() => {
143
+ // Set an event hander
144
+ switchbot.onadvertisement = (ad) => {
145
+ console.log(JSON.stringify(ad, null, " "));
146
+ };
147
+ // Wait 10 seconds
148
+ return switchbot.wait(10000);
149
+ })
150
+ .then(() => {
151
+ // Stop to monitor
152
+ switchbot.stopScan();
153
+ process.exit();
154
+ });
146
155
  ```
147
156
 
148
157
  The sample codes above will output the result as follows:
@@ -199,15 +208,15 @@ This sample discovers a Bot (WoHand), then put the Bot's arm down, finally put i
199
208
 
200
209
  ```javascript
201
210
  // Load the node-switchbot and get a `Switchbot` constructor object
202
- const Switchbot = require('node-switchbot');
211
+ const Switchbot = require("node-switchbot");
203
212
  // Create an `Switchbot` object
204
213
  const switchbot = new Switchbot();
205
214
 
206
215
  (async () => {
207
216
  // Find a Bot (WoHand)
208
- const bot_list = await switchbot.discover({ model: 'H', quick: true });
217
+ const bot_list = await switchbot.discover({ model: "H", quick: true });
209
218
  if (bot_list.length === 0) {
210
- throw new Error('No device was found.');
219
+ throw new Error("No device was found.");
211
220
  }
212
221
  // The `SwitchbotDeviceWoHand` object representing the found Bot.
213
222
  let device = bot_list[0];
@@ -225,7 +234,8 @@ In order to manipulate the arm of your Bot, you have to discover your Bot using
225
234
 
226
235
  In this code, you can get a [`SwitchbotDeviceWoHand`](#SwitchbotDeviceWoHand-object) object representing the found Bot. Using the [`down()`](#SwitchbotDeviceWoHand-down-method) and [`up()`](#SwitchbotDeviceWoHand-up-method) methods of the object, you can move the arm. In addition to these methods, you can use the [`press()`](#SwitchbotDeviceWoHand-press-method), [`turnOn()`](#SwitchbotDeviceWoHand-turnOn-method), and [`turnOff()`](#SwitchbotDeviceWoHand-turnOff-method) methods as well.
227
236
 
228
- ---------------------------------------
237
+ ---
238
+
229
239
  ## `Switchbot` object
230
240
 
231
241
  In order to use the node-switchbot, you have to load the node-switchbot module as follows:
@@ -242,9 +252,9 @@ const switchbot = new Switchbot();
242
252
 
243
253
  The `Switchbot` constructor takes an argument optionally. It must be a hash object containing the properties as follows:
244
254
 
245
- Property | Type | Required | Description
246
- :--------|:-------|:---------|:-----------
247
- `noble` | Noble | option | a Noble object of the [`@abandonware/noble`](https://github.com/abandonware/noble) module
255
+ | Property | Type | Required | Description |
256
+ | :------- | :---- | :------- | :---------------------------------------------------------------------------------------- |
257
+ | `noble` | Noble | option | a Noble object of the [`@abandonware/noble`](https://github.com/abandonware/noble) module |
248
258
 
249
259
  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
260
 
@@ -265,12 +275,12 @@ In the code snippet above, the variable `switchbot` is an `Switchbot` object. Th
265
275
 
266
276
  The `discover` method finds devices. This method returns a `Promise` object. This method takes an argument which is a hash object containing parameters as follows:
267
277
 
268
- Property | Type | Required | Description
269
- :------------|:--------|:---------|:------------
270
- `duration` | Integer | Optional | Duration for discovery process (msec). The default value is 5000 (msec).
271
- `model` | String | Optional | `"H"`, `"T"` or `"c"`. If `"H"` is specified, this method will discover only Bots. If `"T"` is specified, this method will discover only Meters. If `"c"` is specified, this method will discover only Curtains.
272
- `id` | String | Optional | If this value is set, this method will discover only a device whose ID is as same as this value. The ID is identical to the MAC address. This parameter is case-insensitive, and colons are ignored.
273
- `quick` | Boolean | Optional | If this value is `true`, this method finishes the discovery process when the first device is found, then calls the `resolve()` function without waiting the specified `duration`. The default value is `false`.
278
+ | Property | Type | Required | Description |
279
+ | :--------- | :------ | :------- | :--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
280
+ | `duration` | Integer | Optional | Duration for discovery process (msec). The default value is 5000 (msec). |
281
+ | `model` | String | Optional | `"H"`, `"T"` or `"c"`. If `"H"` is specified, this method will discover only Bots. If `"T"` is specified, this method will discover only Meters. If `"c"` is specified, this method will discover only Curtains. |
282
+ | `id` | String | Optional | If this value is set, this method will discover only a device whose ID is as same as this value. The ID is identical to the MAC address. This parameter is case-insensitive, and colons are ignored. |
283
+ | `quick` | Boolean | Optional | If this value is `true`, this method finishes the discovery process when the first device is found, then calls the `resolve()` function without waiting the specified `duration`. The default value is `false`. |
274
284
 
275
285
  In the code snippet below, no parameter is passed to the method:
276
286
 
@@ -282,7 +292,7 @@ switchbot.discover().then((device_list) => {
282
292
  });
283
293
  ```
284
294
 
285
- If no parameter is passed to the method as the code above, an `Array` object will be passed to the `resolve()` function in 5 seconds. The `Array` object contains [`SwitchbotDevice`](#SwitchbotDevice-object) objects representing the found devices. See the section "[`SwitchbotDevice`](#SwitchbotDevice-object) objects" for more details.
295
+ If no parameter is passed to the method as the code above, an `Array` object will be passed to the `resolve()` function in 5 seconds. The `Array` object contains [`SwitchbotDevice`](#SwitchbotDevice-object) objects representing the found devices. See the section "[`SwitchbotDevice`](#SwitchbotDevice-object) objects" for more details.
286
296
 
287
297
  If you want a quick response, you can set the `quick` property to `true`.
288
298
 
@@ -300,7 +310,7 @@ switchbot.discover({
300
310
 
301
311
  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
312
 
303
- ### `ondiscover` event hander
313
+ ### `ondiscover` event handler
304
314
 
305
315
  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
316
 
@@ -328,10 +338,10 @@ The discovery process was finished.
328
338
 
329
339
  The `startScan()` method starts to scan advertising packets coming from devices. This method takes an argument which is a hash object containing the parameters as follows:
330
340
 
331
- Property | Type | Required | Description
332
- :------------|:-------|:---------|:------------
333
- `model` | String | Optional | `"H"`, `"T"` or `"c"`. If `"H"` is specified, this method will discover only Bots. If `"T"` is specified, this method will discover only Meters. If `"c"` is specified, this method will discover only Curtains.
334
- `id` | String | Optional | If this value is set, this method will discover only a device whose ID is as same as this value. The ID is identical to the MAC address. This value is case-insensitive, and colons are ignored.
341
+ | Property | Type | Required | Description |
342
+ | :------- | :----- | :------- | :--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
343
+ | `model` | String | Optional | `"H"`, `"T"` or `"c"`. If `"H"` is specified, this method will discover only Bots. If `"T"` is specified, this method will discover only Meters. If `"c"` is specified, this method will discover only Curtains. |
344
+ | `id` | String | Optional | If this value is set, this method will discover only a device whose ID is as same as this value. The ID is identical to the MAC address. This value is case-insensitive, and colons are ignored. |
335
345
 
336
346
  Whenever a packet is received, the callback function set to the [`onadvertisement`](#Switchbot-onadvertisement-event-handler) property of the [`Switchbot`](#Switchbot-object) object will be called. When a packet is received, a hash object representing the packet will be passed to the callback function.
337
347
 
@@ -379,7 +389,7 @@ The `serviceData` property depends on the model of the device. See the section "
379
389
 
380
390
  ### `stopScan()` method
381
391
 
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.
392
+ 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
393
 
384
394
  ### `onadvertisement` event handler
385
395
 
@@ -391,30 +401,31 @@ See the section "[`startScan()` method](#startscan-method)" for details.
391
401
 
392
402
  The `wait()` method waits for the specified milliseconds. This method takes an integer representing the duration (millisecond). This method returns a `Promise` object.
393
403
 
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.
404
+ 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.
405
+
406
+ ---
395
407
 
396
- ---------------------------------------
397
408
  ## `SwitchbotDevice` object
398
409
 
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.
410
+ 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
411
 
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.
412
+ 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
413
 
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.
414
+ 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
415
 
405
416
  ### Properties
406
417
 
407
418
  The `SwitchbotDevice` object supports the properties as follows:
408
419
 
409
- Property | Type | Description
410
- :----------------|:---------|:-----------
411
- `id` | String | ID of the device. (e.g., `"cb4eb903c96d"`)
412
- `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"`.
415
- `connectionState` | String | This value indicates the BLE connection state. `"connecting"`, `"connected"`, `"disconnecting"`, or `"disconnected"`.
416
- `onconnect` | Function | See the section "[`onconnect` event handler](#SwitchbotDevice-onconnect-event-handler)" for details.
417
- `ondisconnect` | Function | See the section "[`ondisconnect` event handler](#SwitchbotDevice-ondisconnect-event-handler)" for details.
420
+ | Property | Type | Description |
421
+ | :---------------- | :------- | :----------------------------------------------------------------------------------------------------------------------------------------------------------- |
422
+ | `id` | String | ID of the device. (e.g., `"cb4eb903c96d"`) |
423
+ | `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"`) |
424
+ | `model` | String | This value is `"H"` "Bot (WoHand)", `"T"` "Meter (WoSensorTH)", `"c"` "Curtain (WoCurtain)", `"d"` "Contact (WoContact)" or `"s"` "Motion (WoMotion)". |
425
+ | `modelName` | String | This value is `"WoHand"`, `"WoSensorTH"`, `WoCurtain`, `WoContect` or `WoMotion`. |
426
+ | `connectionState` | String | This value indicates the BLE connection state. `"connecting"`, `"connected"`, `"disconnecting"`, or `"disconnected"`. |
427
+ | `onconnect` | Function | See the section "[`onconnect` event handler](#SwitchbotDevice-onconnect-event-handler)" for details. |
428
+ | `ondisconnect` | Function | See the section "[`ondisconnect` event handler](#SwitchbotDevice-ondisconnect-event-handler)" for details. |
418
429
 
419
430
  ### `getDeviceName()` method
420
431
 
@@ -425,21 +436,25 @@ If no connection is established with the device, this method automatically estab
425
436
  If the device name is fetched successfully, the device name will be passed to the `resolve()`.
426
437
 
427
438
  ```javascript
428
- switchbot.discover({ model: 'H', quick: true }).then((device_list) => {
429
- return device_list[0].getDeviceName();
430
- }).then((name) => {
431
- console.log(name);
432
- process.exit();
433
- }).catch((error) => {
434
- console.error(error);
435
- process.exit();
436
- });
439
+ switchbot
440
+ .discover({ model: "H", quick: true })
441
+ .then((device_list) => {
442
+ return device_list[0].getDeviceName();
443
+ })
444
+ .then((name) => {
445
+ console.log(name);
446
+ process.exit();
447
+ })
448
+ .catch((error) => {
449
+ console.error(error);
450
+ process.exit();
451
+ });
437
452
  ```
438
453
 
439
454
  The code above will output the result as follows:
440
455
 
441
456
  ```javascript
442
- WoHand
457
+ WoHand;
443
458
  ```
444
459
 
445
460
  ### `setDeviceName()` method
@@ -448,18 +463,22 @@ The `setDeviceName()` method update the device name saved in the device with the
448
463
 
449
464
  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
465
 
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.
466
+ 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
467
 
453
468
  ```javascript
454
- switchbot.discover({ model: 'H', quick: true }).then((device_list) => {
455
- return device_list[0].setDeviceName('Bot in kitchen');
456
- }).then(() => {
457
- console.log('Done.');
458
- process.exit();
459
- }).catch((error) => {
460
- console.error(error);
461
- process.exit();
462
- });
469
+ switchbot
470
+ .discover({ model: "H", quick: true })
471
+ .then((device_list) => {
472
+ return device_list[0].setDeviceName("Bot in kitchen");
473
+ })
474
+ .then(() => {
475
+ console.log("Done.");
476
+ process.exit();
477
+ })
478
+ .catch((error) => {
479
+ console.error(error);
480
+ process.exit();
481
+ });
463
482
  ```
464
483
 
465
484
  ### `connect()` method
@@ -475,34 +494,42 @@ The code snippet below establishes a connection with the Bot using the `connect(
475
494
  ```javascript
476
495
  let device = null;
477
496
 
478
- switchbot.discover({ model: 'H', quick: true }).then((device_list) => {
479
- device = device_list[0];
480
- if (!device) {
481
- console.log('No device was found.');
497
+ switchbot
498
+ .discover({ model: "H", quick: true })
499
+ .then((device_list) => {
500
+ device = device_list[0];
501
+ if (!device) {
502
+ console.log("No device was found.");
503
+ process.exit();
504
+ }
505
+ console.log(device.modelName + " (" + device.address + ") was found.");
506
+ console.log("Connecting...");
507
+ return device.connect();
508
+ })
509
+ .then(() => {
510
+ console.log("Putting the arm down...");
511
+ return device.down();
512
+ })
513
+ .then(() => {
514
+ console.log("Waiting for 5 seconds...");
515
+ return switchbot.wait(5000);
516
+ })
517
+ .then(() => {
518
+ console.log("Putting the arm up...");
519
+ return device.up();
520
+ })
521
+ .then(() => {
522
+ console.log("Disconnecting...");
523
+ return device.disconnect();
524
+ })
525
+ .then(() => {
526
+ console.log("Done.");
482
527
  process.exit();
483
- }
484
- console.log(device.modelName + ' (' + device.address + ') was found.');
485
- console.log('Connecting...');
486
- return device.connect();
487
- }).then(() => {
488
- console.log('Putting the arm down...');
489
- return device.down();
490
- }).then(() => {
491
- console.log('Waiting for 5 seconds...');
492
- return switchbot.wait(5000);
493
- }).then(() => {
494
- console.log('Putting the arm up...');
495
- return device.up();
496
- }).then(() => {
497
- console.log('Disconnecting...');
498
- return device.disconnect();
499
- }).then(() => {
500
- console.log('Done.');
501
- process.exit();
502
- }).catch((error) => {
503
- console.error(error);
504
- process.exit();
505
- });
528
+ })
529
+ .catch((error) => {
530
+ console.error(error);
531
+ process.exit();
532
+ });
506
533
  ```
507
534
 
508
535
  The result will be as follows:
@@ -525,36 +552,40 @@ See the [previous section](#SwitchbotDevice-connect-method) for more details.
525
552
 
526
553
  ### `onconnect` event handler
527
554
 
528
- The `onconnect` event hander will be called when the connection with the device is established. Nothing will be passed to the hander.
555
+ The `onconnect` event handler will be called when the connection with the device is established. Nothing will be passed to the handler.
529
556
 
530
557
  The code below calls the [`press()`](#SwitchbotDeviceWoHand-press-method) method, while callback functions are attached to the `onconnect` and `ondisconnect`.
531
558
 
532
559
  ```javascript
533
- switchbot.discover({ model: 'H', quick: true }).then((device_list) => {
534
- let device = device_list[0];
535
- if (!device) {
536
- console.log('No device was found.');
560
+ switchbot
561
+ .discover({ model: "H", quick: true })
562
+ .then((device_list) => {
563
+ let device = device_list[0];
564
+ if (!device) {
565
+ console.log("No device was found.");
566
+ process.exit();
567
+ }
568
+ console.log(device.modelName + " (" + device.address + ") was found.");
569
+
570
+ // Set event handers
571
+ device.onconnect = () => {
572
+ console.log("Connected.");
573
+ };
574
+ device.ondisconnect = () => {
575
+ console.log("Disconnected.");
576
+ };
577
+
578
+ console.log("Pressing the switch...");
579
+ return device.press();
580
+ })
581
+ .then(() => {
582
+ console.log("Done.");
537
583
  process.exit();
538
- }
539
- console.log(device.modelName + ' (' + device.address + ') was found.');
540
-
541
- // Set event handers
542
- device.onconnect = () => {
543
- console.log('Connected.');
544
- };
545
- device.ondisconnect = () => {
546
- console.log('Disconnected.');
547
- };
548
-
549
- console.log('Pressing the switch...');
550
- return device.press();
551
- }).then(() => {
552
- console.log('Done.');
553
- process.exit();
554
- }).catch((error) => {
555
- console.error(error);
556
- process.exit();
557
- });
584
+ })
585
+ .catch((error) => {
586
+ console.error(error);
587
+ process.exit();
588
+ });
558
589
  ```
559
590
 
560
591
  The code above will output the result as follows:
@@ -571,12 +602,13 @@ Seeing the result, you would find the [`press()`](#SwitchbotDeviceWoHand-press-m
571
602
 
572
603
  ### `ondisconnect` event handler
573
604
 
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.
605
+ 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.
606
+
607
+ ---
575
608
 
576
- ---------------------------------------
577
609
  ## `SwitchbotDeviceWoHand` object
578
610
 
579
- The `SwitchbotDeviceWoHand` object represents an Bot, which is created through the discovery process triggered by the [`Switchbot.discover()`](#Switchbot-discover-method) method.
611
+ The `SwitchbotDeviceWoHand` object represents a Bot, which is created through the discovery process triggered by the [`Switchbot.discover()`](#Switchbot-discover-method) method.
580
612
 
581
613
  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
614
 
@@ -587,13 +619,17 @@ The `press()` method sends a press command to the Bot. This method returns a `Pr
587
619
  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.
588
620
 
589
621
  ```javascript
590
- switchbot.discover({ model: 'H', quick: true }).then((device_list) => {
591
- return device_list[0].press();
592
- }).then(() => {
593
- console.log('Done.');
594
- }).catch((error) => {
595
- console.error(error);
596
- });
622
+ switchbot
623
+ .discover({ model: "H", quick: true })
624
+ .then((device_list) => {
625
+ return device_list[0].press();
626
+ })
627
+ .then(() => {
628
+ console.log("Done.");
629
+ })
630
+ .catch((error) => {
631
+ console.error(error);
632
+ });
597
633
  ```
598
634
 
599
635
  When the Bot receives this command, the Bot's arm will be put down (stretched), then put up (retracted) in a few seconds.
@@ -606,20 +642,24 @@ If no connection is established with the device, this method automatically estab
606
642
 
607
643
  When the Bot receives this command, the Bot's arm will be put down (stretched) or put up (retracted) depending on the mode setting.
608
644
 
609
- Mode | Inverse the on/off direction | Physical position of the arm
610
- :-------------------|:-----------------------------|:----------------------------
611
- Press mode | N/A | Down (stretched), then Up (retracted)
612
- Switch mode | Disabled | Down (stretched)
613
- &nbsp; | Enabled | Up (retracted)
645
+ | Mode | Inverse the on/off direction | Physical position of the arm |
646
+ | :---------- | :--------------------------- | :------------------------------------ |
647
+ | Press mode | N/A | Down (stretched), then Up (retracted) |
648
+ | Switch mode | Disabled | Down (stretched) |
649
+ | &nbsp; | Enabled | Up (retracted) |
614
650
 
615
651
  ```javascript
616
- switchbot.discover({ model: 'H', quick: true }).then((device_list) => {
617
- return device_list[0].turnOn();
618
- }).then(() => {
619
- console.log('Done.');
620
- }).catch((error) => {
621
- console.error(error);
622
- });
652
+ switchbot
653
+ .discover({ model: "H", quick: true })
654
+ .then((device_list) => {
655
+ return device_list[0].turnOn();
656
+ })
657
+ .then(() => {
658
+ console.log("Done.");
659
+ })
660
+ .catch((error) => {
661
+ console.error(error);
662
+ });
623
663
  ```
624
664
 
625
665
  ### `turnOff()` method
@@ -630,20 +670,24 @@ If no connection is established with the device, this method automatically estab
630
670
 
631
671
  When the Bot receives this command, the Bot's arm will be put down (stretched) or put up (retracted) depending on the mode setting.
632
672
 
633
- Mode | Inverse the on/off direction | Physical position of the arm
634
- :-------------------|:-----------------------------|:----------------------------
635
- Press mode | N/A | Down (stretched), then Up (retracted)
636
- Switch mode | Disabled | Up (retracted)
637
- &nbsp; | Enabled | Down (stretched)
673
+ | Mode | Inverse the on/off direction | Physical position of the arm |
674
+ | :---------- | :--------------------------- | :------------------------------------ |
675
+ | Press mode | N/A | Down (stretched), then Up (retracted) |
676
+ | Switch mode | Disabled | Up (retracted) |
677
+ | &nbsp; | Enabled | Down (stretched) |
638
678
 
639
679
  ```javascript
640
- switchbot.discover({ model: 'H', quick: true }).then((device_list) => {
641
- return device_list[0].turnOff();
642
- }).then(() => {
643
- console.log('Done.');
644
- }).catch((error) => {
645
- console.error(error);
646
- });
680
+ switchbot
681
+ .discover({ model: "H", quick: true })
682
+ .then((device_list) => {
683
+ return device_list[0].turnOff();
684
+ })
685
+ .then(() => {
686
+ console.log("Done.");
687
+ })
688
+ .catch((error) => {
689
+ console.error(error);
690
+ });
647
691
  ```
648
692
 
649
693
  ### `down()` method
@@ -655,13 +699,17 @@ If no connection is established with the device, this method automatically estab
655
699
  When the Bot receives this command, the Bot's arm will be put down (stretched) regardless of the mode setting.
656
700
 
657
701
  ```javascript
658
- switchbot.discover({ model: 'H', quick: true }).then((device_list) => {
659
- return device_list[0].down();
660
- }).then(() => {
661
- console.log('Done.');
662
- }).catch((error) => {
663
- console.error(error);
664
- });
702
+ switchbot
703
+ .discover({ model: "H", quick: true })
704
+ .then((device_list) => {
705
+ return device_list[0].down();
706
+ })
707
+ .then(() => {
708
+ console.log("Done.");
709
+ })
710
+ .catch((error) => {
711
+ console.error(error);
712
+ });
665
713
  ```
666
714
 
667
715
  ### `up()` method
@@ -673,32 +721,41 @@ If no connection is established with the device, this method automatically estab
673
721
  When the Bot receives this command, the Bot's arm will be put up (retracted) regardless of the mode setting.
674
722
 
675
723
  ```javascript
676
- switchbot.discover({ model: 'H', quick: true }).then((device_list) => {
677
- return device_list[0].up();
678
- }).then(() => {
679
- console.log('Done.');
680
- }).catch((error) => {
681
- console.error(error);
682
- });
724
+ switchbot
725
+ .discover({ model: "H", quick: true })
726
+ .then((device_list) => {
727
+ return device_list[0].up();
728
+ })
729
+ .then(() => {
730
+ console.log("Done.");
731
+ })
732
+ .catch((error) => {
733
+ console.error(error);
734
+ });
683
735
  ```
684
736
 
685
- ---------------------------------------
737
+ ---
738
+
686
739
  ## `SwitchbotDeviceWoCurtain` object
687
740
 
688
- The `SwitchbotDeviceWoCurtain` object represents an Curtain, which is created through the discovery process triggered by the [`Switchbot.discover()`](#Switchbot-discover-method) method.
741
+ The `SwitchbotDeviceWoCurtain` object represents a Curtain, which is created through the discovery process triggered by the [`Switchbot.discover()`](#Switchbot-discover-method) method.
689
742
 
690
743
  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
744
 
692
745
  ### `open()` method
693
746
 
694
747
  ```javascript
695
- switchbot.discover({ model: 'c', quick: true }).then((device_list) => {
696
- return device_list[0].open();
697
- }).then(() => {
698
- console.log('Done.');
699
- }).catch((error) => {
700
- console.error(error);
701
- });
748
+ switchbot
749
+ .discover({ model: "c", quick: true })
750
+ .then((device_list) => {
751
+ return device_list[0].open();
752
+ })
753
+ .then(() => {
754
+ console.log("Done.");
755
+ })
756
+ .catch((error) => {
757
+ console.error(error);
758
+ });
702
759
  ```
703
760
 
704
761
  ### `close()` method
@@ -710,13 +767,17 @@ If no connection is established with the device, this method automatically estab
710
767
  When the Curtain receives this command, the Curtain will close the curtain (100% position). If not calibrated, the Curtain does not move.
711
768
 
712
769
  ```javascript
713
- switchbot.discover({ model: 'c', quick: true }).then((device_list) => {
714
- return device_list[0].close();
715
- }).then(() => {
716
- console.log('Done.');
717
- }).catch((error) => {
718
- console.error(error);
719
- });
770
+ switchbot
771
+ .discover({ model: "c", quick: true })
772
+ .then((device_list) => {
773
+ return device_list[0].close();
774
+ })
775
+ .then(() => {
776
+ console.log("Done.");
777
+ })
778
+ .catch((error) => {
779
+ console.error(error);
780
+ });
720
781
  ```
721
782
 
722
783
  ### `pause()` method
@@ -728,13 +789,17 @@ If no connection is established with the device, this method automatically estab
728
789
  When the Curtain receives this command, the Curtain will pause.
729
790
 
730
791
  ```javascript
731
- switchbot.discover({ model: 'c', quick: true }).then((device_list) => {
732
- return device_list[0].pause();
733
- }).then(() => {
734
- console.log('Done.');
735
- }).catch((error) => {
736
- console.error(error);
737
- });
792
+ switchbot
793
+ .discover({ model: "c", quick: true })
794
+ .then((device_list) => {
795
+ return device_list[0].pause();
796
+ })
797
+ .then(() => {
798
+ console.log("Done.");
799
+ })
800
+ .catch((error) => {
801
+ console.error(error);
802
+ });
738
803
  ```
739
804
 
740
805
  ### `runToPos()` method
@@ -745,39 +810,43 @@ If no connection is established with the device, this method automatically estab
745
810
 
746
811
  When the Curtain receives this command, the Curtain will run to the percentage position. If not calibrated, the Curtain does not move.
747
812
 
748
-
749
- The `open()` method sends a open command to the Curtain. This method returns a `Promise` object. Nothing will be passed to the `resove()`.
813
+ The `open()` method sends an open command to the Curtain. This method returns a `Promise` object. Nothing will be passed to the `resove()`.
750
814
 
751
815
  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
816
 
753
817
  When the Curtain receives this command, the Curtain will open the curtain (0% position). If not calibrated, the Curtain does not move.
754
818
 
755
- Property | Type | Required | Description
756
- :------------|:--------|:---------|:------------
757
- `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.
819
+ | Property | Type | Required | Description |
820
+ | :-------- | :------ | :------- | :--------------------------------------------------------------------------------------------------------------------------------------------------- |
821
+ | `percent` | Integer | Required | The percentage of target position (`0-100`). (e.g., `50`) |
822
+ | `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
823
 
760
824
  ```javascript
761
- switchbot.discover({ model: 'c', quick: true }).then((device_list) => {
762
- return device_list[0].runToPos(50);
763
- }).then(() => {
764
- console.log('Done.');
765
- }).catch((error) => {
766
- console.error(error);
767
- });
825
+ switchbot
826
+ .discover({ model: "c", quick: true })
827
+ .then((device_list) => {
828
+ return device_list[0].runToPos(50);
829
+ })
830
+ .then(() => {
831
+ console.log("Done.");
832
+ })
833
+ .catch((error) => {
834
+ console.error(error);
835
+ });
768
836
  ```
769
837
 
770
- ---------------------------------------
838
+ ---
839
+
771
840
  ## Advertisement data
772
841
 
773
842
  After the [`startScan()`](#startscan-method) method is invoked, the [`onadvertisement`](#Switchbot-onadvertisement-event-handler) event handler will be called whenever an advertising packet comes from the switchbot devices. An object containing the properties as follows will be passed to the event handler:
774
843
 
775
- Property | Type | Description
776
- :-------------|:--------|:-----------
777
- `id` | String | ID of the device. (e.g., `"cb4eb903c96d"`)
778
- `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"`)
779
- `rssi` | Integer | RSSI. (e.g., `-62`)
780
- `serviceData` | Object | An object including the device-specific data.
844
+ | Property | Type | Description |
845
+ | :------------ | :------ | :----------------------------------------------------------------------------------------------------------------------------------------------------------- |
846
+ | `id` | String | ID of the device. (e.g., `"cb4eb903c96d"`) |
847
+ | `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"`) |
848
+ | `rssi` | Integer | RSSI. (e.g., `-62`) |
849
+ | `serviceData` | Object | An object including the device-specific data. |
781
850
 
782
851
  The structures of the `serviceData` are described in the following sections.
783
852
 
@@ -802,27 +871,26 @@ Example of the advertisement data:
802
871
 
803
872
  Structure of the `serviceData`:
804
873
 
805
- Property | Type | Description
806
- :-----------|:--------|:-----------
807
- `model` | String | This value is always `"H"`, which means "Bot (WoHand)".
808
- `modelName` | String | This value is always `"WoHand"`, which means "Bot".
809
- `mode` | Boolean | This indicates the mode setting. When the mode is "Switch mode", this value is `true`. When the mode is "Press mode", this value is `false`.
810
- `state` | Boolean | This value indicates whether the switch status is ON or OFF.
811
- `battery` | Integer | (**experimental**) This value indicates the battery level (`%`).
874
+ | Property | Type | Description |
875
+ | :---------- | :------ | :------------------------------------------------------------------------------------------------------------------------------------------- |
876
+ | `model` | String | This value is always `"H"`, which means "Bot (WoHand)". |
877
+ | `modelName` | String | This value is always `"WoHand"`, which means "Bot". |
878
+ | `mode` | Boolean | This indicates the mode setting. When the mode is "Switch mode", this value is `true`. When the mode is "Press mode", this value is `false`. |
879
+ | `state` | Boolean | This value indicates whether the switch status is ON or OFF. |
880
+ | `battery` | Integer | (**experimental**) This value indicates the battery level (`%`). |
812
881
 
813
882
  The `mode` can be changed only using the official smartphone app. The node-switchbot does not support changing the mode because the BLE protocol is non-public.
814
883
 
815
- If the `mode` is `false`, which means the "Press mode" is selected, the `state` is always `false`. If the `mode` is `true`, which means the "Switch mode" is selected, the `state` represents the logical state (ON or OFF). Note that it does *not* mean the physical arm position. The physical arm position depends on the setting "Inverse the on/off direction" on the official smartphone app.
816
-
817
- "Inverse the on/off direction" | Value of the `state` | Logical state | Physical arm position
818
- :------------------------------|:---------------------|:--------------|:------------
819
- disabled | `true` | OFF | Up (retracted)
820
- &nbsp; | `false` | ON | Down (stretched)
821
- enabled | `true` | OFF | Down (stretched)
822
- &nbsp; | `false` | ON | Up (retracted)
884
+ If the `mode` is `false`, which means the "Press mode" is selected, the `state` is always `false`. If the `mode` is `true`, which means the "Switch mode" is selected, the `state` represents the logical state (ON or OFF). Note that it does _not_ mean the physical arm position. The physical arm position depends on the setting "Inverse the on/off direction" on the official smartphone app.
823
885
 
824
- The `battery` is *experimental* for now. I'm not sure whether the value is correct or not. Never trust this value for now.
886
+ | "Inverse the on/off direction" | Value of the `state` | Logical state | Physical arm position |
887
+ | :----------------------------- | :------------------- | :------------ | :-------------------- |
888
+ | disabled | `true` | OFF | Up (retracted) |
889
+ | &nbsp; | `false` | ON | Down (stretched) |
890
+ | enabled | `true` | OFF | Down (stretched) |
891
+ | &nbsp; | `false` | ON | Up (retracted) |
825
892
 
893
+ The `battery` is _experimental_ for now. I'm not sure whether the value is correct or not. Never trust this value for now.
826
894
 
827
895
  ### Meter (WoSensorTH)
828
896
 
@@ -849,20 +917,20 @@ Example of the advertisement data:
849
917
 
850
918
  Structure of the `data`:
851
919
 
852
- Property | Type | Description
853
- :-------------|:--------|:-----------
854
- `model` | String | This value is always `"T"`, which means "Meter (WoSensorTH)".
855
- `modelName` | String | This value is always `"WoSensorTH"`, which means "Meter".
856
- `temperature` | Object |
857
- &nbsp;&nbsp; `c` | Float | Temperature (degree Celsius/°C)
858
- &nbsp;&nbsp; `f` | Float | Temperature (degree Fahrenheit/℉)
859
- `fahrenheit` | Boolean | The flag whether the Meter shows Fahrenheit (`true`) or Celsius (`false`) for the temperature on the display
860
- `humidity` | Integer | Humidity (`%`)
861
- `battery` | Integer | (**experimental**) This value indicates the battery level (`%`).
920
+ | Property | Type | Description |
921
+ | :--------------- | :------ | :----------------------------------------------------------------------------------------------------------- |
922
+ | `model` | String | This value is always `"T"`, which means "Meter (WoSensorTH)". |
923
+ | `modelName` | String | This value is always `"WoSensorTH"`, which means "Meter". |
924
+ | `temperature` | Object |
925
+ | &nbsp;&nbsp; `c` | Float | Temperature (degree Celsius/°C) |
926
+ | &nbsp;&nbsp; `f` | Float | Temperature (degree Fahrenheit/℉) |
927
+ | `fahrenheit` | Boolean | The flag whether the Meter shows Fahrenheit (`true`) or Celsius (`false`) for the temperature on the display |
928
+ | `humidity` | Integer | Humidity (`%`) |
929
+ | `battery` | Integer | (**experimental**) This value indicates the battery level (`%`). |
862
930
 
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.
931
+ 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
932
 
865
- The `battery` is *experimental* for now. I'm not sure whether the value is correct or not. Never trust this value for now.
933
+ The `battery` is _experimental_ for now. I'm not sure whether the value is correct or not. Never trust this value for now.
866
934
 
867
935
  ### Curtain (WoCurtain)
868
936
 
@@ -886,17 +954,78 @@ Example of the advertisement data:
886
954
 
887
955
  Structure of the `serviceData`:
888
956
 
889
- Property | Type | Description
890
- :-------------|:--------|:-----------
891
- `model` | String | This value is always `"c"`, which means "Curtain (WoCurtain)".
892
- `modelName` | String | This value is always `"WoCurtain"`, which means "Curtain".
893
- `calibration` | Boolean | This value indicates the calibration status (`true` or `false`).
894
- `battery` | Integer | This value indicates the battery level (`1-100`, `%`).
895
- `position` | Integer | This value indicates the percentage of current position (`0-100`, 0 is open, `%`).
896
- `lightLevel` | Integer | This value indicates the light level of the light source currently set (`1-10`).
957
+ | Property | Type | Description |
958
+ | :------------ | :------ | :--------------------------------------------------------------------------------- |
959
+ | `model` | String | This value is always `"c"`, which means "Curtain (WoCurtain)". |
960
+ | `modelName` | String | This value is always `"WoCurtain"`, which means "Curtain". |
961
+ | `calibration` | Boolean | This value indicates the calibration status (`true` or `false`). |
962
+ | `battery` | Integer | This value indicates the battery level (`1-100`, `%`). |
963
+ | `position` | Integer | This value indicates the percentage of current position (`0-100`, 0 is open, `%`). |
964
+ | `lightLevel` | Integer | This value indicates the light level of the light source currently set (`1-10`). |
965
+
966
+ ### Contact (WoContact)
967
+
968
+ Example of the advertisement data:
969
+
970
+ ```json
971
+ {
972
+ "id": "f0cda125e3ec",
973
+ "address": "f0:cd:a1:25:e3:ec",
974
+ "rssi": -56,
975
+ "serviceData": {
976
+ "model": "d",
977
+ "modelName": "WoContact",
978
+ "movement": false,
979
+ "battery": 95,
980
+ "doorState": "close",
981
+ "lightLevel": "bright"
982
+ }
983
+ }
984
+ ```
985
+
986
+ Structure of the `serviceData`:
987
+
988
+ | Property | Type | Description |
989
+ | :----------- | :------ | :--------------------------------------------------------------------------- |
990
+ | `model` | String | This value is always `"c"`, which means "Contact (WoContact)". |
991
+ | `modelName` | String | This value is always `"WoContact"`, which means "Contact". |
992
+ | `movement` | Boolean | This value indicates the motion status (`true` or `false`). |
993
+ | `battery` | Integer | This value indicates the battery level (`1-100`, `%`). |
994
+ | `doorState` | String | This value indicates the door Status (`close`, `open`, `timeout no closed`). |
995
+ | `lightLevel` | String | This value indicates the light level (`dark`, `bright`). |
996
+
997
+ ### Motion (WoMotion)
998
+
999
+ Example of the advertisement data:
1000
+
1001
+ ```json
1002
+ {
1003
+ "id": "e7216fa344a9",
1004
+ "address": "e7:21:6f:a3:44:a9",
1005
+ "rssi": -53,
1006
+ "serviceData": {
1007
+ "model": "s",
1008
+ "modelName": "WoMotion",
1009
+ "movement": false,
1010
+ "battery": 96,
1011
+ "lightLevel": "bright"
1012
+ }
1013
+ }
1014
+ ```
1015
+
1016
+ Structure of the `serviceData`:
1017
+
1018
+ | Property | Type | Description |
1019
+ | :----------- | :------ | :----------------------------------------------------------- |
1020
+ | `model` | String | This value is always `"s"`, which means "Motion (WoMotion)". |
1021
+ | `modelName` | String | This value is always `"WoMotion"`, which means "Motion". |
1022
+ | `movement` | Boolean | This value indicates the motion status (`true` or `false`). |
1023
+ | `battery` | Integer | This value indicates the battery level (`1-100`, `%`). |
1024
+ | `lightLevel` | String | This value indicates the light level (`dark`, `bright`). |
1025
+
1026
+ ---
897
1027
 
898
- ---------------------------------------
899
1028
  ## References
900
1029
 
901
- * [Switchbot official global site](https://www.switch-bot.com/)
902
- * [Github - OpenWonderLabs/python-host](https://github.com/OpenWonderLabs/python-host)
1030
+ - [Switchbot official global site](https://www.switch-bot.com/)
1031
+ - [GitHub - OpenWonderLabs/SwitchBotAPI-BLE](https://github.com/OpenWonderLabs/SwitchBotAPI-BLE)