Skip to content

Commit 57e788d

Browse files
v2.0.1 (#221)
## [2.0.1](https://github.com/OpenWonderLabs/node-switchbot/releases/tag/v2.0.1) (2024-02-06) ### What's Changed - Fix async constructor, Thanks [@dnicolson](https://github.com/dnicolson) [#229](#220) - Housekeeping and update dependencies **Full Changelog**: v2.0.0...v2.0.1
1 parent 7a8e59c commit 57e788d

File tree

5 files changed

+96
-84
lines changed

5 files changed

+96
-84
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,14 @@
22

33
All notable changes to this project will be documented in this file. This project uses [Semantic Versioning](https://semver.org/)
44

5+
## [2.0.1](https://github.com/OpenWonderLabs/node-switchbot/releases/tag/v2.0.1) (2024-02-06)
6+
7+
### What's Changed
8+
- Fix async constructor, Thanks [@dnicolson](https://github.com/dnicolson) [#229](https://github.com/OpenWonderLabs/node-switchbot/pull/220)
9+
- Housekeeping and update dependencies
10+
11+
**Full Changelog**: https://github.com/OpenWonderLabs/node-switchbot/compare/v2.0.0...v2.0.1
12+
513
## [2.0.0](https://github.com/OpenWonderLabs/node-switchbot/releases/tag/v2.0.0) (2024-02-05)
614

715
### What's Changed

README.md

Lines changed: 51 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -43,18 +43,18 @@ But some functionalities of this module were developed through trial and error.
4343
- [`disconnect()` method](#disconnect-method)
4444
- [`onconnect` event handler](#onconnect-event-handler)
4545
- [`ondisconnect` event handler](#ondisconnect-event-handler)
46-
- [`SwitchbotDeviceWoHand` object](#switchbotdevicewohand-object)
46+
- [`WoHand` object](#switchbotdevicewohand-object)
4747
- [`press()` method](#press-method)
4848
- [`turnOn()` method](#turnon-method)
4949
- [`turnOff()` method](#turnoff-method)
5050
- [`down()` method](#down-method)
5151
- [`up()` method](#up-method)
52-
- [`SwitchbotDeviceWoCurtain` object](#switchbotdevicewocurtain-object)
52+
- [`WoCurtain` object](#switchbotdevicewocurtain-object)
5353
- [`open()` method](#open-method)
5454
- [`close()` method](#close-method)
5555
- [`pause()` method](#pause-method)
5656
- [`runToPos()` method](#runtopos-method)
57-
- [`SwitchbotDeviceWoPlugMini` object](#switchbotdevicewoplugmini-object)
57+
- [`WoPlugMini` object](#switchbotdevicewoplugmini-object)
5858
- [`turnOn()` method](#turnon-method)
5959
- [`turnOff()` method](#turnoff-method)
6060
- [`toggle()` method](#toggle-method)
@@ -108,11 +108,11 @@ $ npm install node-switchbot
108108

109109
Monitoring the advertising packets, you can find your devices and know the latest state of each device. The packet contains the settings of the device, the arm position of the Bot, the temperature and humidity of the Meter, and so on.
110110

111-
```JavaScript
111+
```Typescript
112112
// Load the node-switchbot and get a `Switchbot` constructor object
113-
const Switchbot = require('node-switchbot');
113+
import { SwitchBot } from 'node-switchbot';
114114
// Create an `Switchbot` object
115-
const switchbot = new Switchbot();
115+
const switchbot = new SwitchBot();
116116

117117
(async () => {
118118
// Start to monitor advertisement packets
@@ -135,7 +135,7 @@ The [`wait()`](#Switchbot-wait-method) method is just a utility method, which wa
135135

136136
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:
137137

138-
```javascript
138+
```Typescript
139139
// Load the node-switchbot and get a `Switchbot` constructor object
140140
const Switchbot = require("node-switchbot");
141141
// Create an `Switchbot` object
@@ -211,19 +211,19 @@ See the section "[Advertisement data](#Advertisement-data)" for the details of t
211211

212212
This sample discovers a Bot (WoHand), then put the Bot's arm down, finally put it up in 5 seconds.
213213

214-
```javascript
214+
```Typescript
215215
// Load the node-switchbot and get a `Switchbot` constructor object
216-
const Switchbot = require("node-switchbot");
216+
import { SwitchBot } from 'node-switchbot';
217217
// Create an `Switchbot` object
218-
const switchbot = new Switchbot();
218+
const switchbot = new SwitchBot();
219219

220220
(async () => {
221221
// Find a Bot (WoHand)
222222
const bot_list = await switchbot.discover({ model: "H", quick: true });
223223
if (bot_list.length === 0) {
224224
throw new Error("No device was found.");
225225
}
226-
// The `SwitchbotDeviceWoHand` object representing the found Bot.
226+
// The `WoHand` object representing the found Bot.
227227
const device = bot_list[0];
228228
// Put the Bot's arm down (stretch the arm)
229229
await device.down();
@@ -237,25 +237,25 @@ const switchbot = new Switchbot();
237237

238238
In order to manipulate the arm of your Bot, you have to discover your Bot using the [`discover()`](#Switchbot-discover-method) method. The object `{ model: 'H' }` passed to the method means that only Bots will be discovered. That is, Meters will be ignored.
239239

240-
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.
240+
In this code, you can get a [`WoHand`](#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.
241241

242242
---
243243

244244
## `Switchbot` object
245245

246246
In order to use the node-switchbot, you have to load the node-switchbot module as follows:
247247

248-
```JavaScript
249-
const Switchbot = require('node-switchbot');
248+
```Typescript
249+
import { SwitchBot } from 'node-switchbot';
250250
```
251251

252-
You can get an `Switchbot` constructor from the code above. Then you have to create an `Switchbot` object from the `Switchbot` constructor as follows:
252+
You can get an `SwitchBot` constructor from the code above. Then you have to create an `SwitchBot` object from the `SwitchBot` constructor as follows:
253253

254-
```javascript
255-
const switchbot = new Switchbot();
254+
```typescript
255+
const switchbot = new SwitchBot();
256256
```
257257

258-
The `Switchbot` constructor takes an argument optionally. It must be a hash object containing the properties as follows:
258+
The `SwitchBot` constructor takes an argument optionally. It must be a hash object containing the properties as follows:
259259

260260
| Property | Type | Required | Description |
261261
| :------- | :---- | :------- | :---------------------------------------------------------------------------------------- |
@@ -265,16 +265,16 @@ The node-switchbot module uses the [`@abandonware/noble`](https://github.com/aba
265265

266266
The sample code below shows how to pass a `Noble` object to the `Switchbot` constructor.
267267

268-
```JavaScript
268+
```Typescript
269269
// Create a Noble object
270270
const noble = require('@abandonware/noble');
271271

272272
// Create a Switchbot object
273-
const Switchbot = require('node-switchbot');
274-
const switchbot = new Switchbot({'noble': noble});
273+
import { SwitchBot } from 'node-switchbot';
274+
const switchbot = new SwitchBot({ 'noble': noble })
275275
```
276276

277-
In the code snippet above, the variable `switchbot` is an `Switchbot` object. The `Switchbot` object has a lot of methods as described in sections below.
277+
In the code snippet above, the variable `switchbot` is an `SwitchBot` object. The `SwitchBot` object has a lot of methods as described in sections below.
278278

279279
### `discover()` method
280280

@@ -289,7 +289,7 @@ The `discover` method finds devices. This method returns a `Promise` object. Thi
289289

290290
In the code snippet below, no parameter is passed to the method:
291291

292-
```JavaScript
292+
```Typescript
293293
switchbot.discover().then((device_list) => {
294294
// Do something...
295295
}).catch((error) => {
@@ -301,7 +301,7 @@ If no parameter is passed to the method as the code above, an `Array` object wil
301301

302302
If you want a quick response, you can set the `quick` property to `true`.
303303

304-
```JavaScript
304+
```Typescript
305305
switchbot.discover({
306306
duration: 5000,
307307
quick: true
@@ -319,7 +319,7 @@ As the `quick` property is set to `true`, the `resolve()` function will be calle
319319

320320
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.
321321

322-
```JavaScript
322+
```Typescript
323323
switchbot.ondiscover = (device) => {
324324
console.log(device.id + ' (' + device.modelName + ')');
325325
};
@@ -350,7 +350,7 @@ The `startScan()` method starts to scan advertising packets coming from devices.
350350

351351
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.
352352

353-
```JavaScript
353+
```Typescript
354354
// Set a callback function called when a packet is received
355355
switchbot.onadvertisement = (ad) => {
356356
console.log(ad);
@@ -414,9 +414,9 @@ This method has nothing to do with Switchbot devices. It's just a utility method
414414

415415
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.
416416

417-
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.
417+
Actually, the `SwitchbotDevice` object is a super class of the [`WoHand`](#SwitchbotDeviceWoHand-object) and `WoSensorTH` objects. The [`WoHand`](#SwitchbotDeviceWoHand-object) object represents a Bot, the `WoSensorTH` object represents a Meter.
418418

419-
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.
419+
You can use the properties and methods described in this section on Bot, Meter, Curtain, Contact and Motion. See the section "[`WoHand` object](#SwitchbotDeviceWoHand-object)" for the details of the functionalities available only on Bot. For now, `WoSensorTH` object has no additional functionality.
420420

421421
### Properties
422422

@@ -440,7 +440,7 @@ If no connection is established with the device, this method automatically estab
440440

441441
If the device name is fetched successfully, the device name will be passed to the `resolve()`.
442442

443-
```javascript
443+
```Typescript
444444
switchbot
445445
.discover({ model: "H", quick: true })
446446
.then((device_list) => {
@@ -458,7 +458,7 @@ switchbot
458458

459459
The code above will output the result as follows:
460460

461-
```javascript
461+
```Typescript
462462
WoHand;
463463
```
464464

@@ -470,7 +470,7 @@ If no connection is established with the device, this method automatically estab
470470

471471
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.
472472

473-
```javascript
473+
```Typescript
474474
switchbot
475475
.discover({ model: "H", quick: true })
476476
.then((device_list) => {
@@ -496,7 +496,7 @@ The connection established using the `connect()` method is not disconnected auto
496496

497497
The code snippet below establishes a connection with the Bot using the `connect()` method, then puts the Bot's arm down, then waits for 5 seconds, then puts the arm down, finally disconnects the device using the [`disconnect()`](#SwitchbotDevice-disconnect-method) method:
498498

499-
```javascript
499+
```Typescript
500500
let device = null;
501501

502502
switchbot
@@ -561,7 +561,7 @@ The `onconnect` event handler will be called when the connection with the device
561561

562562
The code below calls the [`press()`](#SwitchbotDeviceWoHand-press-method) method, while callback functions are attached to the `onconnect` and `ondisconnect`.
563563

564-
```javascript
564+
```Typescript
565565
switchbot
566566
.discover({ model: "H", quick: true })
567567
.then((device_list) => {
@@ -611,19 +611,19 @@ The `ondisconnect` event handler will be called when the connection with the dev
611611

612612
---
613613

614-
## `SwitchbotDeviceWoHand` object
614+
## `WoHand` object
615615

616-
The `SwitchbotDeviceWoHand` object represents a Bot, which is created through the discovery process triggered by the [`Switchbot.discover()`](#Switchbot-discover-method) method.
616+
The `WoHand` object represents a Bot, which is created through the discovery process triggered by the [`Switchbot.discover()`](#Switchbot-discover-method) method.
617617

618-
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.
618+
Actually, the `WoHand` 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.
619619

620620
### `press()` method
621621

622622
The `press()` method sends a press command to the Bot. This method returns a `Promise` object. Nothing will be passed to the `resove()`.
623623

624624
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.
625625

626-
```javascript
626+
```Typescript
627627
switchbot
628628
.discover({ model: "H", quick: true })
629629
.then((device_list) => {
@@ -653,7 +653,7 @@ When the Bot receives this command, the Bot's arm will be put down (stretched) o
653653
| Switch mode | Disabled | Down (stretched) |
654654
|   | Enabled | Up (retracted) |
655655

656-
```javascript
656+
```Typescript
657657
switchbot
658658
.discover({ model: "H", quick: true })
659659
.then((device_list) => {
@@ -681,7 +681,7 @@ When the Bot receives this command, the Bot's arm will be put down (stretched) o
681681
| Switch mode | Disabled | Up (retracted) |
682682
|   | Enabled | Down (stretched) |
683683

684-
```javascript
684+
```Typescript
685685
switchbot
686686
.discover({ model: "H", quick: true })
687687
.then((device_list) => {
@@ -703,7 +703,7 @@ If no connection is established with the device, this method automatically estab
703703

704704
When the Bot receives this command, the Bot's arm will be put down (stretched) regardless of the mode setting.
705705

706-
```javascript
706+
```Typescript
707707
switchbot
708708
.discover({ model: "H", quick: true })
709709
.then((device_list) => {
@@ -725,7 +725,7 @@ If no connection is established with the device, this method automatically estab
725725

726726
When the Bot receives this command, the Bot's arm will be put up (retracted) regardless of the mode setting.
727727

728-
```javascript
728+
```Typescript
729729
switchbot
730730
.discover({ model: "H", quick: true })
731731
.then((device_list) => {
@@ -741,11 +741,11 @@ switchbot
741741

742742
---
743743

744-
## `SwitchbotDeviceWoCurtain` object
744+
## `WoCurtain` object
745745

746-
The `SwitchbotDeviceWoCurtain` object represents a Curtain, which is created through the discovery process triggered by the [`Switchbot.discover()`](#Switchbot-discover-method) method.
746+
The `WoCurtain` object represents a Curtain, which is created through the discovery process triggered by the [`Switchbot.discover()`](#Switchbot-discover-method) method.
747747

748-
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.
748+
Actually, the `WoCurtain` 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.
749749

750750
### `open()` method
751751

@@ -757,7 +757,7 @@ When the Curtain receives this command, the Curtain will open the curtain (0% po
757757

758758
The `open()` method receives an optional `mode` parameter. (See [`runToPos()`](#runtopos-method))
759759

760-
```javascript
760+
```Typescript
761761
switchbot
762762
.discover({ model: "c", quick: true })
763763
.then((device_list) => {
@@ -781,7 +781,7 @@ When the Curtain receives this command, the Curtain will close the curtain (100%
781781

782782
The `close()` method receives an optional `mode` parameter. (See [`runToPos()`](#runtopos-method))
783783

784-
```javascript
784+
```Typescript
785785
switchbot
786786
.discover({ model: "c", quick: true })
787787
.then((device_list) => {
@@ -803,7 +803,7 @@ If no connection is established with the device, this method automatically estab
803803

804804
When the Curtain receives this command, the Curtain will pause.
805805

806-
```javascript
806+
```Typescript
807807
switchbot
808808
.discover({ model: "c", quick: true })
809809
.then((device_list) => {
@@ -836,7 +836,7 @@ When the Curtain receives this command, the Curtain will open the curtain (0% po
836836
| `percent` | Integer | Required | The percentage of target position (`0-100`). (e.g., `50`) |
837837
| `mode` | Integer | Optional | The running mode of Curtain. <br/>`0x00` - Performance mode.<br/> `0x01` - Silent mode. <br/>`0xff` - Default. Unspecified, from Curtain's settings. |
838838

839-
```javascript
839+
```Typescript
840840
switchbot
841841
.discover({ model: "c", quick: true })
842842
.then((device_list) => {
@@ -851,11 +851,11 @@ switchbot
851851
```
852852

853853
---
854-
## `SwitchbotDeviceWoPlugMini` object
854+
## `WoPlugMini` object
855855

856-
The `SwitchbotDeviceWoPlugMini ` object represents a PlugMini, which is created through the discovery process triggered by the [`Switchbot.discover()`](#Switchbot-discover-method) method.
856+
The `WoPlugMini ` object represents a PlugMini, which is created through the discovery process triggered by the [`Switchbot.discover()`](#Switchbot-discover-method) method.
857857

858-
Actually, the `SwitchbotDeviceWoPlugMini ` 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.
858+
Actually, the `WoPlugMini ` 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.
859859

860860
### `turnOn()` method
861861

0 commit comments

Comments
 (0)