Skip to content

Commit 3877620

Browse files
committed
v2.0.1 (#221)
- 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 3877620

File tree

7 files changed

+100
-92
lines changed

7 files changed

+100
-92
lines changed

.github/workflows/changerelease.yml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
name: Changelog to Release
22

33
on:
4-
workflow_dispatch:
5-
push:
6-
paths: [CHANGELOG.md]
7-
branches: [latest]
4+
release:
5+
types: [published]
86

97
jobs:
108
changerelease:

.github/workflows/release.yml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
name: Node Release
22

33
on:
4-
push:
5-
tags:
6-
- 'v*.*.*'
7-
workflow_dispatch:
4+
release:
5+
types: [published]
86

97
jobs:
108
build_and_test:

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
Large diffs are not rendered by default.

package-lock.json

Lines changed: 11 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "node-switchbot",
3-
"version": "2.0.0",
3+
"version": "2.0.1",
44
"description": "The node-switchbot is a Node.js module which allows you to control your Switchbot Devices through Bluetooth (BLE).",
55
"homepage": "https://github.com/OpenWonderLabs/node-switchbot",
66
"author": "OpenWonderLabs (https://github.com/OpenWonderLabs)",
@@ -36,7 +36,7 @@
3636
],
3737
"readmeFilename": "README.md",
3838
"dependencies": {
39-
"@abandonware/noble": "^1.9.2-23"
39+
"@abandonware/noble": "^1.9.2-24"
4040
},
4141
"optionalDependencies": {
4242
"@abandonware/bluetooth-hci-socket": "^0.5.3-10"

src/switchbot.ts

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ type peripherals = {
2727
}
2828

2929
export class SwitchBot {
30+
private ready: Promise<void>;
3031
noble;
3132
ondiscover;
3233
onadvertisement;
@@ -48,27 +49,29 @@ export class SwitchBot {
4849
* ---------------------------------------------------------------- */
4950

5051

51-
constructor(params: params = {}) {
52-
// Check parameters
53-
(async () => {
54-
let noble: any;
55-
if (params && params.noble) {
56-
noble = params.noble;
57-
} else {
58-
noble = (await import('@abandonware/noble')).default;
59-
}
60-
61-
// Public properties
62-
this.noble = noble;
63-
this.ondiscover = null;
64-
this.onadvertisement = null;
65-
this.onlog = null;
66-
67-
// Private properties
68-
this.scanning = false;
69-
})();
52+
constructor(params?: params) {
7053
this.DEFAULT_DISCOVERY_DURATION = 5000;
7154
this.PRIMARY_SERVICE_UUID_LIST = [];
55+
this.ready = this.init(params);
56+
}
57+
58+
// Check parameters
59+
async init(params?: params) {
60+
let noble: any;
61+
if (params && params.noble) {
62+
noble = params.noble;
63+
} else {
64+
noble = (await import('@abandonware/noble')).default;
65+
}
66+
67+
// Public properties
68+
this.noble = noble;
69+
this.ondiscover = null;
70+
this.onadvertisement = null;
71+
this.onlog = null;
72+
73+
// Private properties
74+
this.scanning = false;
7275
}
7376

7477
/* ------------------------------------------------------------------
@@ -221,7 +224,8 @@ export class SwitchBot {
221224
return promise;
222225
}
223226

224-
_init() {
227+
async _init() {
228+
await this.ready;
225229
const promise = new Promise<void>((resolve, reject) => {
226230
let err;
227231
if (this.noble.state === 'poweredOn') {

0 commit comments

Comments
 (0)