Skip to content

Commit 27b33fe

Browse files
v1.9.0 (#201)
## [Version 1.9.0](https://github.com/OpenWonderLabs/node-switchbot/releases/tag/v1.9.0) (2023-09-16) ## What's Changed - Add support for the Indoor/Outdoor Thermo-Hygrometer (WoIOSensorTH), Thanks [@moritzmhmk](https://github.com/moritzmhmk) [#200](#200) - Handle noble not being "poweredOn" on init, Thanks [@moritzmhmk](https://github.com/moritzmhmk) [#199](#199) - Housekeeping and update dependencies **Full Changelog**: v1.8.2...v1.9.0
1 parent b59e1db commit 27b33fe

File tree

9 files changed

+341
-186
lines changed

9 files changed

+341
-186
lines changed

.github/dependabot.yml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55

66
version: 2
77
updates:
8-
- package-ecosystem: "npm" # See documentation for possible values
9-
directory: "/" # Location of package manifests
10-
target-branch: "beta"
8+
- package-ecosystem: 'npm' # See documentation for possible values
9+
directory: '/' # Location of package manifests
10+
target-branch: 'beta-*.*.*'
1111
schedule:
12-
interval: "daily"
13-
- package-ecosystem: "github-actions" # See documentation for possible values
14-
directory: "/" # Location of package manifests
15-
target-branch: "beta"
12+
interval: 'daily'
13+
- package-ecosystem: 'github-actions' # See documentation for possible values
14+
directory: '/' # Location of package manifests
15+
target-branch: 'beta-*.*.*'
1616
schedule:
17-
interval: "daily"
17+
interval: 'daily'

.github/workflows/dependabot.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,15 @@ on:
44
pull_request:
55
push:
66
branches:
7-
- beta
7+
- beta-*.*.*
88

99
jobs:
1010
automerge:
11-
name: Auto-merge dependabot updates
11+
name: Auto-merge patch updates
1212
runs-on: ubuntu-latest
1313
steps:
1414
- uses: mitto98/dependabot-automerge-action@master
1515
with:
1616
token: ${{ github.token }}
17-
merge: true
17+
merge-patch: true
18+

.github/workflows/old-workflow.zip

-6.38 KB
Binary file not shown.

CHANGELOG.md

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

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

5+
## [Version 1.9.0](https://github.com/OpenWonderLabs/node-switchbot/releases/tag/v1.9.0) (2023-09-16)
6+
7+
## What's Changed
8+
- Add support for the Indoor/Outdoor Thermo-Hygrometer (WoIOSensorTH), Thanks [@moritzmhmk](https://github.com/moritzmhmk) [#200](https://github.com/OpenWonderLabs/node-switchbot/pull/200)
9+
- Handle noble not being "poweredOn" on init, Thanks [@moritzmhmk](https://github.com/moritzmhmk) [#199](https://github.com/OpenWonderLabs/node-switchbot/pull/199)
10+
- Housekeeping and update dependencies
11+
12+
**Full Changelog**: https://github.com/OpenWonderLabs/node-switchbot/compare/v1.8.2...v1.9.0
13+
514
## [Version 1.8.2](https://github.com/OpenWonderLabs/node-switchbot/releases/tag/v1.8.2) (2023-07-25)
615

716
## What's Changed

lib/switchbot-advertising.js

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,8 @@ class SwitchbotAdvertising {
110110
sd = this._parseServiceDataForWoSensorTHPlus(buf, onlog);// WoMeterPlus
111111
} else if (model === "r") {
112112
sd = this._parseServiceDataForWoStrip(buf, onlog);// WoStrip
113+
} else if (model === "w") {
114+
sd = this._parseServiceDataForWoIOSensorTH(buf, manufacturerData, onlog); // Indoor/Outdoor Thermo-Hygrometer
113115
} else {
114116
if (onlog && typeof onlog === "function") {
115117
onlog(
@@ -662,6 +664,49 @@ class SwitchbotAdvertising {
662664

663665
return data;
664666
}
667+
668+
_parseServiceDataForWoIOSensorTH(serviceDataBuf, manufacturerDataBuf, onlog) {
669+
if (serviceDataBuf.length !== 3) {
670+
if (onlog && typeof onlog === "function") {
671+
onlog(
672+
`[_parseServiceDataForWoIOSensorTH] Service Data Buffer length ${serviceDataBuf.length} !== 3!`
673+
);
674+
}
675+
return null;
676+
}
677+
if (manufacturerDataBuf.length !== 14) {
678+
if (onlog && typeof onlog === "function") {
679+
onlog(
680+
`[_parseServiceDataForWoIOSensorTH] Manufacturer Data Buffer length ${manufacturerDataBuf.length} !== 14!`
681+
);
682+
}
683+
return null;
684+
}
685+
const mdByte10 = manufacturerDataBuf.readUInt8(10);
686+
const mdByte11 = manufacturerDataBuf.readUInt8(11);
687+
const mdByte12 = manufacturerDataBuf.readUInt8(12);
688+
689+
const sdByte2 = serviceDataBuf.readUInt8(2);
690+
691+
const temp_sign = mdByte11 & 0b10000000 ? 1 : -1;
692+
const temp_c = temp_sign * ((mdByte11 & 0b01111111) + (mdByte10 & 0b00001111) / 10);
693+
const temp_f = Math.round(((temp_c * 9 / 5) + 32) * 10) / 10;
694+
695+
const data = {
696+
model: "w",
697+
modelName: "WoIOSensorTH",
698+
temperature: {
699+
c: temp_c,
700+
f: temp_f,
701+
},
702+
fahrenheit: mdByte12 & 0b10000000 ? true : false, // needs to be confirmed!
703+
humidity: mdByte12 & 0b01111111,
704+
battery: sdByte2 & 0b01111111,
705+
};
706+
707+
console.log(data);
708+
return data;
709+
}
665710
}
666711

667712
module.exports = new SwitchbotAdvertising();
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
"use strict";
2+
const SwitchbotDevice = require("./switchbot-device.js");
3+
4+
class SwitchbotDeviceWoIOSensorTH extends SwitchbotDevice {}
5+
6+
module.exports = SwitchbotDeviceWoIOSensorTH;

lib/switchbot.js

Lines changed: 34 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ const SwitchbotDeviceWoBlindTilt = require("./switchbot-device-woblindtilt.js");
99
const SwitchbotDeviceWoPresence = require("./switchbot-device-wopresence.js");
1010
const SwitchbotDeviceWoContact = require("./switchbot-device-wocontact.js");
1111
const SwitchbotDeviceWoSensorTH = require("./switchbot-device-wosensorth.js");
12+
const SwitchbotDeviceWoIOSensorTH = require("./switchbot-device-woiosensorth.js");
1213
const SwitchbotDeviceWoHumi = require("./switchbot-device-wohumi.js");
1314
const SwitchbotDeviceWoPlugMini = require("./switchbot-device-woplugmini.js");
1415
const SwitchbotDeviceWoBulb = require("./switchbot-device-wobulb.js");
@@ -107,6 +108,7 @@ class Switchbot {
107108
"i",
108109
"r",
109110
"x",
111+
"w",
110112
],
111113
},
112114
id: { required: false, type: "string", min: 12, max: 17 },
@@ -196,29 +198,35 @@ class Switchbot {
196198
_init() {
197199
const promise = new Promise((resolve, reject) => {
198200
let err;
199-
switch (this.noble.state) {
200-
case ("unsupported", "unauthorized", "poweredOff"):
201-
err = new Error(
202-
"Failed to initialize the Noble object: " + this.noble.state
203-
);
204-
reject(err);
205-
return;
206-
case ("resetting", "unknown"):
207-
err = new Error(
208-
"Adapter is not ready: " + this.noble.state
209-
);
210-
reject(err);
211-
return;
212-
case "poweredOn":
213-
resolve();
214-
return;
215-
default:
216-
err = new Error(
217-
"Uknown state: " + this.noble.state
218-
);
219-
reject(err);
220-
return;
201+
if (this.noble.state === "poweredOn") {
202+
resolve();
203+
return;
221204
}
205+
this.noble.once('stateChange', state => {
206+
switch (state) {
207+
case ("unsupported", "unauthorized", "poweredOff"):
208+
err = new Error(
209+
"Failed to initialize the Noble object: " + this.noble.state
210+
);
211+
reject(err);
212+
return;
213+
case ("resetting", "unknown"):
214+
err = new Error(
215+
"Adapter is not ready: " + this.noble.state
216+
);
217+
reject(err);
218+
return;
219+
case "poweredOn":
220+
resolve();
221+
return;
222+
default:
223+
err = new Error(
224+
"Uknown state: " + this.noble.state
225+
);
226+
reject(err);
227+
return;
228+
}
229+
});
222230
});
223231
return promise;
224232
}
@@ -262,6 +270,9 @@ class Switchbot {
262270
case "i":
263271
device = new SwitchbotDeviceWoSensorTH(peripheral, this.noble);
264272
break;
273+
case "w":
274+
device = new SwitchbotDeviceWoIOSensorTH(peripheral, this.noble);
275+
break;
265276
case "r":
266277
device = new SwitchbotDeviceWoStrip(peripheral, this.noble);
267278
break;
@@ -371,6 +382,7 @@ class Switchbot {
371382
"i",
372383
"r",
373384
"x",
385+
"w",
374386
],
375387
},
376388
id: { required: false, type: "string", min: 12, max: 17 },

0 commit comments

Comments
 (0)