-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f9fcd5c
commit 8d8564c
Showing
1 changed file
with
40 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* Copyright(C) 2024, donavanbecker (https://github.com/donavanbecker). All rights reserved. | ||
* | ||
* wohub2.ts: Switchbot BLE API registration. | ||
*/ | ||
import { SwitchbotDevice } from '../device.js'; | ||
|
||
export class WoHub2 extends SwitchbotDevice { | ||
static parseServiceData(buf: Buffer, onlog: ((message: string) => void) | undefined) { | ||
if (buf.length !== 6) { | ||
if (onlog && typeof onlog === 'function') { | ||
onlog( | ||
`[parseServiceDataForWoSensorTH] Buffer length ${buf.length} !== 6!`, | ||
); | ||
} | ||
return null; | ||
} | ||
const byte2 = buf.readUInt8(2); | ||
const byte3 = buf.readUInt8(3); | ||
const byte4 = buf.readUInt8(4); | ||
const byte5 = buf.readUInt8(5); | ||
|
||
const temp_sign = byte4 & 0b10000000 ? 1 : -1; | ||
const temp_c = temp_sign * ((byte4 & 0b01111111) + (byte3 & 0b00001111) / 10); | ||
const temp_f = Math.round(((temp_c * 9 / 5) + 32) * 10) / 10; | ||
|
||
const data = { | ||
model: 'v', | ||
modelName: 'WoHub2', | ||
temperature: { | ||
c: temp_c, | ||
f: temp_f, | ||
}, | ||
fahrenheit: byte5 & 0b10000000 ? true : false, | ||
humidity: byte5 & 0b01111111, | ||
battery: byte2 & 0b01111111, | ||
}; | ||
|
||
return data; | ||
} | ||
} |