Skip to content

Commit

Permalink
v1.9.0 (#201)
Browse files Browse the repository at this point in the history
## [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
  • Loading branch information
donavanbecker committed Sep 16, 2023
1 parent b59e1db commit 27b33fe
Show file tree
Hide file tree
Showing 9 changed files with 341 additions and 186 deletions.
16 changes: 8 additions & 8 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@

version: 2
updates:
- package-ecosystem: "npm" # See documentation for possible values
directory: "/" # Location of package manifests
target-branch: "beta"
- package-ecosystem: 'npm' # See documentation for possible values
directory: '/' # Location of package manifests
target-branch: 'beta-*.*.*'
schedule:
interval: "daily"
- package-ecosystem: "github-actions" # See documentation for possible values
directory: "/" # Location of package manifests
target-branch: "beta"
interval: 'daily'
- package-ecosystem: 'github-actions' # See documentation for possible values
directory: '/' # Location of package manifests
target-branch: 'beta-*.*.*'
schedule:
interval: "daily"
interval: 'daily'
7 changes: 4 additions & 3 deletions .github/workflows/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@ on:
pull_request:
push:
branches:
- beta
- beta-*.*.*

jobs:
automerge:
name: Auto-merge dependabot updates
name: Auto-merge patch updates
runs-on: ubuntu-latest
steps:
- uses: mitto98/dependabot-automerge-action@master
with:
token: ${{ github.token }}
merge: true
merge-patch: true

Binary file removed .github/workflows/old-workflow.zip
Binary file not shown.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@

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

## [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](https://github.com/OpenWonderLabs/node-switchbot/pull/200)
- Handle noble not being "poweredOn" on init, Thanks [@moritzmhmk](https://github.com/moritzmhmk) [#199](https://github.com/OpenWonderLabs/node-switchbot/pull/199)
- Housekeeping and update dependencies

**Full Changelog**: https://github.com/OpenWonderLabs/node-switchbot/compare/v1.8.2...v1.9.0

## [Version 1.8.2](https://github.com/OpenWonderLabs/node-switchbot/releases/tag/v1.8.2) (2023-07-25)

## What's Changed
Expand Down
45 changes: 45 additions & 0 deletions lib/switchbot-advertising.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ class SwitchbotAdvertising {
sd = this._parseServiceDataForWoSensorTHPlus(buf, onlog);// WoMeterPlus
} else if (model === "r") {
sd = this._parseServiceDataForWoStrip(buf, onlog);// WoStrip
} else if (model === "w") {
sd = this._parseServiceDataForWoIOSensorTH(buf, manufacturerData, onlog); // Indoor/Outdoor Thermo-Hygrometer
} else {
if (onlog && typeof onlog === "function") {
onlog(
Expand Down Expand Up @@ -662,6 +664,49 @@ class SwitchbotAdvertising {

return data;
}

_parseServiceDataForWoIOSensorTH(serviceDataBuf, manufacturerDataBuf, onlog) {
if (serviceDataBuf.length !== 3) {
if (onlog && typeof onlog === "function") {
onlog(
`[_parseServiceDataForWoIOSensorTH] Service Data Buffer length ${serviceDataBuf.length} !== 3!`
);
}
return null;
}
if (manufacturerDataBuf.length !== 14) {
if (onlog && typeof onlog === "function") {
onlog(
`[_parseServiceDataForWoIOSensorTH] Manufacturer Data Buffer length ${manufacturerDataBuf.length} !== 14!`
);
}
return null;
}
const mdByte10 = manufacturerDataBuf.readUInt8(10);
const mdByte11 = manufacturerDataBuf.readUInt8(11);
const mdByte12 = manufacturerDataBuf.readUInt8(12);

const sdByte2 = serviceDataBuf.readUInt8(2);

const temp_sign = mdByte11 & 0b10000000 ? 1 : -1;
const temp_c = temp_sign * ((mdByte11 & 0b01111111) + (mdByte10 & 0b00001111) / 10);
const temp_f = Math.round(((temp_c * 9 / 5) + 32) * 10) / 10;

const data = {
model: "w",
modelName: "WoIOSensorTH",
temperature: {
c: temp_c,
f: temp_f,
},
fahrenheit: mdByte12 & 0b10000000 ? true : false, // needs to be confirmed!
humidity: mdByte12 & 0b01111111,
battery: sdByte2 & 0b01111111,
};

console.log(data);
return data;
}
}

module.exports = new SwitchbotAdvertising();
6 changes: 6 additions & 0 deletions lib/switchbot-device-woiosensorth.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
"use strict";
const SwitchbotDevice = require("./switchbot-device.js");

class SwitchbotDeviceWoIOSensorTH extends SwitchbotDevice {}

module.exports = SwitchbotDeviceWoIOSensorTH;
56 changes: 34 additions & 22 deletions lib/switchbot.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const SwitchbotDeviceWoBlindTilt = require("./switchbot-device-woblindtilt.js");
const SwitchbotDeviceWoPresence = require("./switchbot-device-wopresence.js");
const SwitchbotDeviceWoContact = require("./switchbot-device-wocontact.js");
const SwitchbotDeviceWoSensorTH = require("./switchbot-device-wosensorth.js");
const SwitchbotDeviceWoIOSensorTH = require("./switchbot-device-woiosensorth.js");
const SwitchbotDeviceWoHumi = require("./switchbot-device-wohumi.js");
const SwitchbotDeviceWoPlugMini = require("./switchbot-device-woplugmini.js");
const SwitchbotDeviceWoBulb = require("./switchbot-device-wobulb.js");
Expand Down Expand Up @@ -107,6 +108,7 @@ class Switchbot {
"i",
"r",
"x",
"w",
],
},
id: { required: false, type: "string", min: 12, max: 17 },
Expand Down Expand Up @@ -196,29 +198,35 @@ class Switchbot {
_init() {
const promise = new Promise((resolve, reject) => {
let err;
switch (this.noble.state) {
case ("unsupported", "unauthorized", "poweredOff"):
err = new Error(
"Failed to initialize the Noble object: " + this.noble.state
);
reject(err);
return;
case ("resetting", "unknown"):
err = new Error(
"Adapter is not ready: " + this.noble.state
);
reject(err);
return;
case "poweredOn":
resolve();
return;
default:
err = new Error(
"Uknown state: " + this.noble.state
);
reject(err);
return;
if (this.noble.state === "poweredOn") {
resolve();
return;
}
this.noble.once('stateChange', state => {
switch (state) {
case ("unsupported", "unauthorized", "poweredOff"):
err = new Error(
"Failed to initialize the Noble object: " + this.noble.state
);
reject(err);
return;
case ("resetting", "unknown"):
err = new Error(
"Adapter is not ready: " + this.noble.state
);
reject(err);
return;
case "poweredOn":
resolve();
return;
default:
err = new Error(
"Uknown state: " + this.noble.state
);
reject(err);
return;
}
});
});
return promise;
}
Expand Down Expand Up @@ -262,6 +270,9 @@ class Switchbot {
case "i":
device = new SwitchbotDeviceWoSensorTH(peripheral, this.noble);
break;
case "w":
device = new SwitchbotDeviceWoIOSensorTH(peripheral, this.noble);
break;
case "r":
device = new SwitchbotDeviceWoStrip(peripheral, this.noble);
break;
Expand Down Expand Up @@ -371,6 +382,7 @@ class Switchbot {
"i",
"r",
"x",
"w",
],
},
id: { required: false, type: "string", min: 12, max: 17 },
Expand Down

0 comments on commit 27b33fe

Please sign in to comment.