node-switchbot 2.5.0-beta.9 → 3.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/workflows/beta-release.yml +25 -2
- package/.github/workflows/release.yml +13 -0
- package/BLE.md +1144 -0
- package/CHANGELOG.md +22 -0
- package/OpenAPI.md +185 -0
- package/README.md +20 -1189
- package/branding/Node_x_SwitchBot.svg +9 -0
- package/branding/icon.png +0 -0
- package/branding/switchbot.png +0 -0
- package/dist/advertising.d.ts +3 -3
- package/dist/advertising.d.ts.map +1 -1
- package/dist/advertising.js +26 -26
- package/dist/advertising.js.map +1 -1
- package/dist/device/woblindtilt.d.ts +19 -50
- package/dist/device/woblindtilt.d.ts.map +1 -1
- package/dist/device/woblindtilt.js +41 -100
- package/dist/device/woblindtilt.js.map +1 -1
- package/dist/device/wobulb.d.ts +41 -15
- package/dist/device/wobulb.d.ts.map +1 -1
- package/dist/device/wobulb.js +72 -128
- package/dist/device/wobulb.js.map +1 -1
- package/dist/device/woceilinglight.d.ts +47 -21
- package/dist/device/woceilinglight.d.ts.map +1 -1
- package/dist/device/woceilinglight.js +96 -171
- package/dist/device/woceilinglight.js.map +1 -1
- package/dist/device/wocontact.d.ts +11 -1
- package/dist/device/wocontact.d.ts.map +1 -1
- package/dist/device/wocontact.js +23 -22
- package/dist/device/wocontact.js.map +1 -1
- package/dist/device/wocurtain.d.ts +39 -1
- package/dist/device/wocurtain.d.ts.map +1 -1
- package/dist/device/wocurtain.js +69 -103
- package/dist/device/wocurtain.js.map +1 -1
- package/dist/device/wohand.d.ts +37 -2
- package/dist/device/wohand.d.ts.map +1 -1
- package/dist/device/wohand.js +55 -89
- package/dist/device/wohand.js.map +1 -1
- package/dist/device/wohub2.d.ts +11 -1
- package/dist/device/wohub2.d.ts.map +1 -1
- package/dist/device/wohub2.js +21 -29
- package/dist/device/wohub2.js.map +1 -1
- package/dist/device/wohumi.d.ts +37 -2
- package/dist/device/wohumi.d.ts.map +1 -1
- package/dist/device/wohumi.js +52 -83
- package/dist/device/wohumi.js.map +1 -1
- package/dist/device/woiosensorth.d.ts +12 -1
- package/dist/device/woiosensorth.d.ts.map +1 -1
- package/dist/device/woiosensorth.js +25 -29
- package/dist/device/woiosensorth.js.map +1 -1
- package/dist/device/woplugmini.d.ts +45 -12
- package/dist/device/woplugmini.d.ts.map +1 -1
- package/dist/device/woplugmini.js +71 -77
- package/dist/device/woplugmini.js.map +1 -1
- package/dist/device/wopresence.d.ts +11 -1
- package/dist/device/wopresence.d.ts.map +1 -1
- package/dist/device/wopresence.js +21 -27
- package/dist/device/wopresence.js.map +1 -1
- package/dist/device/wosensorth.d.ts +18 -2
- package/dist/device/wosensorth.d.ts.map +1 -1
- package/dist/device/wosensorth.js +34 -50
- package/dist/device/wosensorth.js.map +1 -1
- package/dist/device/wosmartlock.d.ts +63 -13
- package/dist/device/wosmartlock.d.ts.map +1 -1
- package/dist/device/wosmartlock.js +114 -195
- package/dist/device/wosmartlock.js.map +1 -1
- package/dist/device/wosmartlockpro.d.ts +16 -12
- package/dist/device/wosmartlockpro.d.ts.map +1 -1
- package/dist/device/wosmartlockpro.js +34 -29
- package/dist/device/wosmartlockpro.js.map +1 -1
- package/dist/device/wostrip.d.ts +4 -3
- package/dist/device/wostrip.d.ts.map +1 -1
- package/dist/device/wostrip.js +5 -4
- package/dist/device/wostrip.js.map +1 -1
- package/dist/device.d.ts +13 -5
- package/dist/device.d.ts.map +1 -1
- package/dist/device.js +13 -2
- package/dist/device.js.map +1 -1
- package/dist/index.d.ts +9 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +9 -1
- package/dist/index.js.map +1 -1
- package/dist/parameter-checker.d.ts +10 -13
- package/dist/parameter-checker.d.ts.map +1 -1
- package/dist/parameter-checker.js +16 -1
- package/dist/parameter-checker.js.map +1 -1
- package/dist/settings.d.ts +47 -0
- package/dist/settings.d.ts.map +1 -1
- package/dist/settings.js +49 -0
- package/dist/settings.js.map +1 -1
- package/dist/{switchbot.d.ts → switchbot-ble.d.ts} +12 -9
- package/dist/switchbot-ble.d.ts.map +1 -0
- package/dist/switchbot-ble.js +426 -0
- package/dist/switchbot-ble.js.map +1 -0
- package/dist/switchbot-openapi.d.ts +131 -0
- package/dist/switchbot-openapi.d.ts.map +1 -0
- package/dist/switchbot-openapi.js +311 -0
- package/dist/switchbot-openapi.js.map +1 -0
- package/dist/test/advertising.test.d.ts +2 -0
- package/dist/test/advertising.test.d.ts.map +1 -0
- package/dist/test/advertising.test.js +99 -0
- package/dist/test/advertising.test.js.map +1 -0
- package/dist/test/device.test.d.ts +2 -0
- package/dist/test/device.test.d.ts.map +1 -0
- package/dist/test/device.test.js +38 -0
- package/dist/test/device.test.js.map +1 -0
- package/dist/test/index.test.d.ts +2 -0
- package/dist/test/index.test.d.ts.map +1 -0
- package/dist/test/index.test.js +35 -0
- package/dist/test/index.test.js.map +1 -0
- package/dist/test/parameter-checker.test.d.ts +2 -0
- package/dist/test/parameter-checker.test.d.ts.map +1 -0
- package/dist/test/parameter-checker.test.js +108 -0
- package/dist/test/parameter-checker.test.js.map +1 -0
- package/dist/test/settings.test.d.ts +2 -0
- package/dist/test/settings.test.d.ts.map +1 -0
- package/dist/test/settings.test.js +49 -0
- package/dist/test/settings.test.js.map +1 -0
- package/dist/test/switchbot-openapi.test.d.ts +2 -0
- package/dist/test/switchbot-openapi.test.d.ts.map +1 -0
- package/dist/test/switchbot-openapi.test.js +96 -0
- package/dist/test/switchbot-openapi.test.js.map +1 -0
- package/dist/test/switchbot.test.d.ts +2 -0
- package/dist/test/switchbot.test.d.ts.map +1 -0
- package/dist/test/switchbot.test.js +106 -0
- package/dist/test/switchbot.test.js.map +1 -0
- package/dist/test/woblindtilt.test.js +70 -20
- package/dist/test/woblindtilt.test.js.map +1 -1
- package/dist/test/wobulb.test.js +87 -44
- package/dist/test/wobulb.test.js.map +1 -1
- package/dist/test/woceilinglight.test.js +72 -54
- package/dist/test/woceilinglight.test.js.map +1 -1
- package/dist/test/wocontact.test.js +51 -20
- package/dist/test/wocontact.test.js.map +1 -1
- package/dist/test/wocurtain.test.js +65 -23
- package/dist/test/wocurtain.test.js.map +1 -1
- package/dist/test/wohand.test.js +34 -40
- package/dist/test/wohand.test.js.map +1 -1
- package/dist/test/wohub2.test.d.ts +2 -0
- package/dist/test/wohub2.test.d.ts.map +1 -0
- package/dist/test/wohub2.test.js +80 -0
- package/dist/test/wohub2.test.js.map +1 -0
- package/dist/test/wohumi.test.js +70 -49
- package/dist/test/wohumi.test.js.map +1 -1
- package/dist/test/woiosensorth.test.js +33 -32
- package/dist/test/woiosensorth.test.js.map +1 -1
- package/dist/test/woplugmini.test.js +80 -57
- package/dist/test/woplugmini.test.js.map +1 -1
- package/dist/test/wopresence.test.js +44 -18
- package/dist/test/wopresence.test.js.map +1 -1
- package/dist/test/wosensorth.test.js +44 -52
- package/dist/test/wosensorth.test.js.map +1 -1
- package/dist/test/wosmartlock.test.js +126 -59
- package/dist/test/wosmartlock.test.js.map +1 -1
- package/dist/test/wosmartlockpro.test.js +96 -69
- package/dist/test/wosmartlockpro.test.js.map +1 -1
- package/dist/test/wostrip.test.js +70 -83
- package/dist/test/wostrip.test.js.map +1 -1
- package/dist/types/bledevicestatus.d.ts +4 -12
- package/dist/types/bledevicestatus.d.ts.map +1 -1
- package/dist/types/devicelist.d.ts.map +1 -1
- package/dist/types/devicelist.js +0 -4
- package/dist/types/devicelist.js.map +1 -1
- package/dist/types/devicepush.d.ts +13 -0
- package/dist/types/devicepush.d.ts.map +1 -0
- package/dist/types/devicepush.js +2 -0
- package/dist/types/devicepush.js.map +1 -0
- package/dist/types/deviceresponse.d.ts +2 -3
- package/dist/types/deviceresponse.d.ts.map +1 -1
- package/dist/types/devicestatus.d.ts.map +1 -1
- package/dist/types/devicewebhookstatus.d.ts +32 -0
- package/dist/types/devicewebhookstatus.d.ts.map +1 -1
- package/dist/types/irdevicelist.d.ts.map +1 -1
- package/dist/types/types.d.ts +24 -1
- package/dist/types/types.d.ts.map +1 -1
- package/dist/types/types.js +14 -0
- package/dist/types/types.js.map +1 -1
- package/docs/assets/highlight.css +12 -47
- package/docs/assets/main.js +1 -1
- package/docs/assets/navigation.js +1 -1
- package/docs/assets/search.js +1 -1
- package/docs/classes/SwitchBotBLE.html +62 -0
- package/docs/classes/SwitchBotOpenAPI.html +47 -0
- package/docs/classes/SwitchbotDevice.html +32 -33
- package/docs/enums/LogLevel.html +10 -0
- package/docs/enums/SwitchBotBLEModel.html +2 -2
- package/docs/enums/SwitchBotBLEModelFriendlyName.html +2 -2
- package/docs/enums/SwitchBotBLEModelName.html +2 -2
- package/docs/enums/SwitchBotModel.html +2 -2
- package/docs/hierarchy.html +1 -0
- package/docs/index.html +16 -993
- package/docs/interfaces/Ad-1.html +5 -0
- package/docs/interfaces/AdvertisementData.html +3 -0
- package/docs/interfaces/Chars.html +4 -0
- package/docs/interfaces/ErrorObject.html +3 -0
- package/docs/interfaces/Params.html +6 -0
- package/docs/interfaces/Rule.html +9 -0
- package/docs/interfaces/ServiceData.html +2 -0
- package/docs/interfaces/SwitchBotBLEDevice.html +21 -0
- package/docs/interfaces/WebhookDetail.html +6 -0
- package/docs/interfaces/ad.html +5 -0
- package/docs/interfaces/body.html +3 -0
- package/docs/interfaces/bodyChange.html +4 -0
- package/docs/interfaces/deleteWebhookResponse.html +4 -0
- package/docs/interfaces/device.html +7 -0
- package/docs/interfaces/deviceList.html +2 -0
- package/docs/interfaces/deviceStatus.html +7 -0
- package/docs/interfaces/deviceStatusRequest.html +4 -0
- package/docs/interfaces/deviceWebhook.html +4 -0
- package/docs/interfaces/deviceWebhookContext.html +4 -0
- package/docs/interfaces/devices.html +4 -0
- package/docs/interfaces/infraredRemoteList.html +2 -0
- package/docs/interfaces/irdevice.html +5 -0
- package/docs/interfaces/pushResponse.html +4 -0
- package/docs/interfaces/queryWebhookResponse.html +4 -0
- package/docs/interfaces/setupWebhookResponse.html +4 -0
- package/docs/interfaces/switchbot.html +3 -0
- package/docs/interfaces/updateWebhookResponse.html +4 -0
- package/docs/interfaces/webhookRequest.html +4 -0
- package/docs/media/BLE.md +1144 -0
- package/docs/media/OpenAPI.md +185 -0
- package/docs/modules.html +137 -3
- package/docs/types/MacAddress.html +1 -0
- package/docs/types/batteryCirculatorFan.html +1 -0
- package/docs/types/batteryCirculatorFanServiceData.html +1 -0
- package/docs/types/batteryCirculatorFanStatus.html +1 -0
- package/docs/types/batteryCirculatorFanWebhookContext.html +1 -0
- package/docs/types/blindTilt.html +1 -0
- package/docs/types/blindTiltServiceData.html +1 -0
- package/docs/types/blindTiltStatus.html +1 -0
- package/docs/types/blindTiltWebhookContext.html +1 -0
- package/docs/types/bot.html +1 -0
- package/docs/types/botServiceData.html +1 -0
- package/docs/types/botStatus.html +1 -0
- package/docs/types/botWebhookContext.html +1 -0
- package/docs/types/ceilingLight.html +1 -0
- package/docs/types/ceilingLightPro.html +1 -0
- package/docs/types/ceilingLightProServiceData.html +1 -0
- package/docs/types/ceilingLightProStatus.html +1 -0
- package/docs/types/ceilingLightProWebhookContext.html +1 -0
- package/docs/types/ceilingLightServiceData.html +1 -0
- package/docs/types/ceilingLightStatus.html +1 -0
- package/docs/types/ceilingLightWebhookContext.html +1 -0
- package/docs/types/colorBulb.html +1 -0
- package/docs/types/colorBulbServiceData.html +1 -0
- package/docs/types/colorBulbStatus.html +1 -0
- package/docs/types/colorBulbWebhookContext.html +1 -0
- package/docs/types/contactSensor.html +1 -0
- package/docs/types/contactSensorServiceData.html +1 -0
- package/docs/types/contactSensorStatus.html +1 -0
- package/docs/types/contactSensorWebhookContext.html +1 -0
- package/docs/types/curtain.html +1 -0
- package/docs/types/curtain3.html +1 -0
- package/docs/types/curtain3ServiceData.html +1 -0
- package/docs/types/curtain3WebhookContext.html +1 -0
- package/docs/types/curtainServiceData.html +1 -0
- package/docs/types/curtainStatus.html +1 -0
- package/docs/types/curtainWebhookContext.html +1 -0
- package/docs/types/floorCleaningRobotS10.html +1 -0
- package/docs/types/floorCleaningRobotS10Status.html +1 -0
- package/docs/types/floorCleaningRobotS10WebhookContext.html +1 -0
- package/docs/types/hub2.html +1 -0
- package/docs/types/hub2ServiceData.html +1 -0
- package/docs/types/hub2Status.html +1 -0
- package/docs/types/hub2WebhookContext.html +1 -0
- package/docs/types/humidifier.html +1 -0
- package/docs/types/humidifierServiceData.html +1 -0
- package/docs/types/humidifierStatus.html +1 -0
- package/docs/types/humidifierWebhookContext.html +1 -0
- package/docs/types/indoorCam.html +1 -0
- package/docs/types/indoorCameraWebhookContext.html +1 -0
- package/docs/types/keypad.html +1 -0
- package/docs/types/keypadTouch.html +1 -0
- package/docs/types/keypadTouchWebhookContext.html +1 -0
- package/docs/types/keypadWebhookContext.html +1 -0
- package/docs/types/lock.html +1 -0
- package/docs/types/lockPro.html +1 -0
- package/docs/types/lockProServiceData.html +1 -0
- package/docs/types/lockProStatus.html +1 -0
- package/docs/types/lockProWebhookContext.html +1 -0
- package/docs/types/lockServiceData.html +1 -0
- package/docs/types/lockStatus.html +1 -0
- package/docs/types/lockWebhookContext.html +1 -0
- package/docs/types/meter.html +1 -0
- package/docs/types/meterPlus.html +1 -0
- package/docs/types/meterPlusServiceData.html +1 -0
- package/docs/types/meterPlusStatus.html +1 -0
- package/docs/types/meterPlusWebhookContext.html +1 -0
- package/docs/types/meterServiceData.html +1 -0
- package/docs/types/meterStatus.html +1 -0
- package/docs/types/meterWebhookContext.html +1 -0
- package/docs/types/motionSensor.html +1 -0
- package/docs/types/motionSensorServiceData.html +1 -0
- package/docs/types/motionSensorStatus.html +1 -0
- package/docs/types/motionSensorWebhookContext.html +1 -0
- package/docs/types/outdoorMeter.html +1 -0
- package/docs/types/outdoorMeterServiceData.html +1 -0
- package/docs/types/outdoorMeterStatus.html +1 -0
- package/docs/types/outdoorMeterWebhookContext.html +1 -0
- package/docs/types/panTiltCamWebhookContext.html +1 -0
- package/docs/types/pantiltCam.html +1 -0
- package/docs/types/pantiltCam2k.html +1 -0
- package/docs/types/plug.html +1 -0
- package/docs/types/plugMini.html +1 -0
- package/docs/types/plugMiniJPServiceData.html +1 -0
- package/docs/types/plugMiniJPWebhookContext.html +1 -0
- package/docs/types/plugMiniStatus.html +1 -0
- package/docs/types/plugMiniUSServiceData.html +1 -0
- package/docs/types/plugMiniUSWebhookContext.html +1 -0
- package/docs/types/plugStatus.html +1 -0
- package/docs/types/plugWebhookContext.html +1 -0
- package/docs/types/remote.html +1 -0
- package/docs/types/robotVacuumCleanerS1.html +1 -0
- package/docs/types/robotVacuumCleanerS1Plus.html +1 -0
- package/docs/types/robotVacuumCleanerS1PlusStatus.html +1 -0
- package/docs/types/robotVacuumCleanerS1PlusWebhookContext.html +1 -0
- package/docs/types/robotVacuumCleanerS1Status.html +1 -0
- package/docs/types/robotVacuumCleanerS1WebhookContext.html +1 -0
- package/docs/types/robotVacuumCleanerServiceData.html +1 -0
- package/docs/types/stripLight.html +1 -0
- package/docs/types/stripLightServiceData.html +1 -0
- package/docs/types/stripLightStatus.html +1 -0
- package/docs/types/stripLightWebhookContext.html +1 -0
- package/docs/types/waterLeakDetector.html +1 -0
- package/docs/types/waterLeakDetectorServiceData.html +1 -0
- package/docs/types/waterLeakDetectorStatus.html +1 -0
- package/docs/types/waterLeakDetectorWebhookContext.html +1 -0
- package/package.json +15 -13
- package/.github/npm-version-script.cjs +0 -81
- package/dist/switchbot.d.ts.map +0 -1
- package/dist/switchbot.js +0 -259
- package/dist/switchbot.js.map +0 -1
- package/dist/test/wohand2.test.d.ts +0 -2
- package/dist/test/wohand2.test.d.ts.map +0 -1
- package/dist/test/wohand2.test.js +0 -50
- package/dist/test/wohand2.test.js.map +0 -1
- package/dist/types/pushbody.d.ts +0 -6
- package/dist/types/pushbody.d.ts.map +0 -1
- package/dist/types/pushbody.js +0 -2
- package/dist/types/pushbody.js.map +0 -1
- package/docs/classes/SwitchBot.html +0 -16
- package/docs/types/SwitchBotBLEDevice.html +0 -1
package/dist/device/wocurtain.js
CHANGED
|
@@ -1,148 +1,114 @@
|
|
|
1
|
-
import { Buffer } from 'node:buffer';
|
|
2
1
|
/* Copyright(C) 2024, donavanbecker (https://github.com/donavanbecker). All rights reserved.
|
|
3
2
|
*
|
|
4
3
|
* wocurtain.ts: Switchbot BLE API registration.
|
|
5
4
|
*/
|
|
5
|
+
import { Buffer } from 'node:buffer';
|
|
6
6
|
import { SwitchbotDevice } from '../device.js';
|
|
7
7
|
import { SwitchBotBLEModelFriendlyName, SwitchBotBLEModelName } from '../types/types.js';
|
|
8
|
+
/**
|
|
9
|
+
* Class representing a WoCurtain device.
|
|
10
|
+
* @see https://github.com/OpenWonderLabs/SwitchBotAPI-BLE/blob/latest/devicetypes/curtain.md
|
|
11
|
+
* @see https://github.com/OpenWonderLabs/SwitchBotAPI-BLE/blob/latest/devicetypes/curtain3.md
|
|
12
|
+
*/
|
|
8
13
|
export class WoCurtain extends SwitchbotDevice {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
+
/**
|
|
15
|
+
* Parses the service data for WoCurtain.
|
|
16
|
+
* @param {Buffer} serviceData - The service data buffer.
|
|
17
|
+
* @param {Buffer} manufacturerData - The manufacturer data buffer.
|
|
18
|
+
* @param {Function} emitLog - The function to emit log messages.
|
|
19
|
+
* @param {boolean} [reverse] - Whether to reverse the position.
|
|
20
|
+
* @returns {Promise<object | null>} - Parsed service data or null if invalid.
|
|
21
|
+
*/
|
|
22
|
+
static async parseServiceData(serviceData, manufacturerData, emitLog, reverse = false) {
|
|
23
|
+
if (![5, 6].includes(serviceData.length)) {
|
|
24
|
+
emitLog('debugerror', `[parseServiceDataForWoCurtain] Buffer length ${serviceData.length} !== 5 or 6!`);
|
|
14
25
|
return null;
|
|
15
26
|
}
|
|
16
27
|
const byte1 = serviceData.readUInt8(1);
|
|
17
28
|
const byte2 = serviceData.readUInt8(2);
|
|
18
|
-
// const byte3 = serviceData.readUInt8(3)
|
|
19
|
-
// const byte4 = serviceData.readUInt8(4)
|
|
20
29
|
let deviceData;
|
|
21
30
|
let batteryData = null;
|
|
22
|
-
if (manufacturerData
|
|
31
|
+
if (manufacturerData.length >= 13) {
|
|
23
32
|
deviceData = manufacturerData.subarray(8, 11);
|
|
24
33
|
batteryData = manufacturerData.readUInt8(12);
|
|
25
34
|
}
|
|
26
|
-
else if (manufacturerData
|
|
35
|
+
else if (manufacturerData.length >= 11) {
|
|
27
36
|
deviceData = manufacturerData.subarray(8, 11);
|
|
28
|
-
batteryData = serviceData ? byte2 : null;
|
|
29
|
-
}
|
|
30
|
-
else if (serviceData) {
|
|
31
|
-
deviceData = serviceData.subarray(3, 6);
|
|
32
37
|
batteryData = byte2;
|
|
33
38
|
}
|
|
34
39
|
else {
|
|
35
|
-
|
|
40
|
+
deviceData = serviceData.subarray(3, 6);
|
|
41
|
+
batteryData = byte2;
|
|
36
42
|
}
|
|
37
43
|
const model = serviceData.subarray(0, 1).toString('utf8');
|
|
38
44
|
const modelName = model === 'c' ? SwitchBotBLEModelName.Curtain : SwitchBotBLEModelName.Curtain3;
|
|
39
45
|
const modelFriendlyName = model === 'c' ? SwitchBotBLEModelFriendlyName.Curtain : SwitchBotBLEModelFriendlyName.Curtain3;
|
|
40
|
-
const calibration =
|
|
41
|
-
const position = Math.max(Math.min(deviceData.readUInt8(0) & 0b01111111, 100), 0);
|
|
42
|
-
const inMotion = Boolean(deviceData.readUInt8(0) & 0b10000000);
|
|
43
|
-
const lightLevel = (deviceData.readUInt8(1) >> 4) & 0b00001111;
|
|
44
|
-
const deviceChain = deviceData.readUInt8(1) & 0b00000111;
|
|
45
|
-
const battery = batteryData !== null ? batteryData & 0b01111111 : null;
|
|
46
|
-
|
|
46
|
+
const calibration = Boolean(byte1 & 0b01000000);
|
|
47
|
+
const position = Math.max(Math.min(deviceData.readUInt8(0) & 0b01111111, 100), 0);
|
|
48
|
+
const inMotion = Boolean(deviceData.readUInt8(0) & 0b10000000);
|
|
49
|
+
const lightLevel = (deviceData.readUInt8(1) >> 4) & 0b00001111;
|
|
50
|
+
const deviceChain = deviceData.readUInt8(1) & 0b00000111;
|
|
51
|
+
const battery = batteryData !== null ? batteryData & 0b01111111 : null;
|
|
52
|
+
return {
|
|
47
53
|
model,
|
|
48
54
|
modelName,
|
|
49
55
|
modelFriendlyName,
|
|
50
56
|
calibration,
|
|
51
57
|
battery,
|
|
52
58
|
inMotion,
|
|
53
|
-
position: reverse ? 100 - position : position,
|
|
59
|
+
position: reverse ? 100 - position : position,
|
|
54
60
|
lightLevel,
|
|
55
61
|
deviceChain,
|
|
56
62
|
};
|
|
57
|
-
return data;
|
|
58
63
|
}
|
|
59
|
-
|
|
60
|
-
*
|
|
61
|
-
* -
|
|
62
|
-
*
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
* [Return value]
|
|
67
|
-
* - Promise object
|
|
68
|
-
* Nothing will be passed to the `resolve()`.
|
|
69
|
-
* ---------------------------------------------------------------- */
|
|
70
|
-
async open(mode) {
|
|
71
|
-
return await this.runToPos(0, mode);
|
|
64
|
+
/**
|
|
65
|
+
* Opens the curtain.
|
|
66
|
+
* @param {number} [mode] - Running mode (0x01 = QuietDrift, 0xFF = Default).
|
|
67
|
+
* @returns {Promise<void>}
|
|
68
|
+
*/
|
|
69
|
+
async open(mode = 0xFF) {
|
|
70
|
+
await this.runToPos(0, mode);
|
|
72
71
|
}
|
|
73
|
-
|
|
74
|
-
*
|
|
75
|
-
* -
|
|
76
|
-
*
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
* [Return value]
|
|
81
|
-
* - Promise object
|
|
82
|
-
* Nothing will be passed to the `resolve()`.
|
|
83
|
-
* ---------------------------------------------------------------- */
|
|
84
|
-
async close(mode) {
|
|
85
|
-
return await this.runToPos(100, mode);
|
|
72
|
+
/**
|
|
73
|
+
* Closes the curtain.
|
|
74
|
+
* @param {number} [mode] - Running mode (0x01 = QuietDrift, 0xFF = Default).
|
|
75
|
+
* @returns {Promise<void>}
|
|
76
|
+
*/
|
|
77
|
+
async close(mode = 0xFF) {
|
|
78
|
+
await this.runToPos(100, mode);
|
|
86
79
|
}
|
|
87
|
-
|
|
88
|
-
*
|
|
89
|
-
*
|
|
90
|
-
|
|
91
|
-
* [Arguments]
|
|
92
|
-
* - none
|
|
93
|
-
*
|
|
94
|
-
* [Return value]
|
|
95
|
-
* - Promise object
|
|
96
|
-
* Nothing will be passed to the `resolve()`.
|
|
97
|
-
* ---------------------------------------------------------------- */
|
|
80
|
+
/**
|
|
81
|
+
* Pauses the curtain.
|
|
82
|
+
* @returns {Promise<void>}
|
|
83
|
+
*/
|
|
98
84
|
async pause() {
|
|
99
|
-
|
|
85
|
+
await this.operateCurtain([0x57, 0x0F, 0x45, 0x01, 0x00, 0xFF]);
|
|
100
86
|
}
|
|
101
|
-
|
|
102
|
-
*
|
|
103
|
-
* -
|
|
104
|
-
*
|
|
105
|
-
*
|
|
106
|
-
|
|
107
|
-
* - mode | number | Optional | runing mode (0x01 = QuietDrift, 0xff = Default)
|
|
108
|
-
*
|
|
109
|
-
* [Return value]
|
|
110
|
-
* - Promise object
|
|
111
|
-
* Nothing will be passed to the `resolve()`.
|
|
112
|
-
* ---------------------------------------------------------------- */
|
|
87
|
+
/**
|
|
88
|
+
* Runs the curtain to the target position.
|
|
89
|
+
* @param {number} percent - The percentage of the target position.
|
|
90
|
+
* @param {number} [mode] - Running mode (0x01 = QuietDrift, 0xFF = Default).
|
|
91
|
+
* @returns {Promise<void>}
|
|
92
|
+
*/
|
|
113
93
|
async runToPos(percent, mode = 0xFF) {
|
|
114
|
-
if (typeof percent !== 'number') {
|
|
115
|
-
throw new TypeError(
|
|
116
|
-
}
|
|
117
|
-
if (typeof mode !== 'number') {
|
|
118
|
-
throw new TypeError(`The type of running mode is incorrect: ${typeof mode}`);
|
|
119
|
-
}
|
|
120
|
-
if (mode > 1) {
|
|
121
|
-
mode = 0xFF;
|
|
94
|
+
if (typeof percent !== 'number' || typeof mode !== 'number') {
|
|
95
|
+
throw new TypeError('Invalid type for percent or mode');
|
|
122
96
|
}
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
}
|
|
126
|
-
else if (percent < 0) {
|
|
127
|
-
percent = 0;
|
|
128
|
-
}
|
|
129
|
-
return await this.operateCurtain([0x57, 0x0F, 0x45, 0x01, 0x05, mode, percent]);
|
|
97
|
+
percent = Math.max(0, Math.min(100, percent));
|
|
98
|
+
await this.operateCurtain([0x57, 0x0F, 0x45, 0x01, 0x05, mode, percent]);
|
|
130
99
|
}
|
|
100
|
+
/**
|
|
101
|
+
* Sends a command to the curtain.
|
|
102
|
+
* @param {number[]} bytes - The command bytes.
|
|
103
|
+
* @returns {Promise<void>}
|
|
104
|
+
*/
|
|
131
105
|
async operateCurtain(bytes) {
|
|
132
|
-
const
|
|
133
|
-
await this.command(
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
}
|
|
139
|
-
else {
|
|
140
|
-
throw new Error(`The device returned an error: 0x${res_buf.toString('hex')}`);
|
|
141
|
-
}
|
|
142
|
-
})
|
|
143
|
-
.catch((error) => {
|
|
144
|
-
throw error;
|
|
145
|
-
});
|
|
106
|
+
const reqBuf = Buffer.from(bytes);
|
|
107
|
+
const resBuf = await this.command(reqBuf);
|
|
108
|
+
const code = resBuf.readUInt8(0);
|
|
109
|
+
if (resBuf.length !== 3 || code !== 0x01) {
|
|
110
|
+
throw new Error(`The device returned an error: 0x${resBuf.toString('hex')}`);
|
|
111
|
+
}
|
|
146
112
|
}
|
|
147
113
|
}
|
|
148
114
|
//# sourceMappingURL=wocurtain.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wocurtain.js","sourceRoot":"","sources":["../../src/device/wocurtain.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AAEpC
|
|
1
|
+
{"version":3,"file":"wocurtain.js","sourceRoot":"","sources":["../../src/device/wocurtain.ts"],"names":[],"mappings":"AAAA;;;GAG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AK,IAAI,EAAE,CAAC;YACzC,MAAM,IAAI,KAAK,CAAC,mCAAmC,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC,CAAA;QAC9E,CAAC;IACH,CAAC;CACF"}
|
package/dist/device/wohand.d.ts
CHANGED
|
@@ -1,12 +1,47 @@
|
|
|
1
1
|
import { Buffer } from 'node:buffer';
|
|
2
2
|
import { SwitchbotDevice } from '../device.js';
|
|
3
|
+
/**
|
|
4
|
+
* Class representing a WoHand device.
|
|
5
|
+
* @see https://github.com/OpenWonderLabs/SwitchBotAPI-BLE/blob/latest/devicetypes/bot.md
|
|
6
|
+
*/
|
|
3
7
|
export declare class WoHand extends SwitchbotDevice {
|
|
4
|
-
|
|
8
|
+
/**
|
|
9
|
+
* Parses the service data for WoHand.
|
|
10
|
+
* @param {Buffer} serviceData - The service data buffer.
|
|
11
|
+
* @param {Function} emitLog - The function to emit log messages.
|
|
12
|
+
* @returns {Promise<object | null>} - Parsed service data or null if invalid.
|
|
13
|
+
*/
|
|
14
|
+
static parseServiceData(serviceData: Buffer, emitLog: (level: string, message: string) => void): Promise<object | null>;
|
|
15
|
+
/**
|
|
16
|
+
* Sends a command to the bot.
|
|
17
|
+
* @param {number[]} bytes - The command bytes.
|
|
18
|
+
* @returns {Promise<void>}
|
|
19
|
+
*/
|
|
20
|
+
private operateBot;
|
|
21
|
+
/**
|
|
22
|
+
* Presses the bot.
|
|
23
|
+
* @returns {Promise<void>}
|
|
24
|
+
*/
|
|
5
25
|
press(): Promise<void>;
|
|
26
|
+
/**
|
|
27
|
+
* Turns on the bot.
|
|
28
|
+
* @returns {Promise<void>}
|
|
29
|
+
*/
|
|
6
30
|
turnOn(): Promise<void>;
|
|
31
|
+
/**
|
|
32
|
+
* Turns off the bot.
|
|
33
|
+
* @returns {Promise<void>}
|
|
34
|
+
*/
|
|
7
35
|
turnOff(): Promise<void>;
|
|
36
|
+
/**
|
|
37
|
+
* Moves the bot down.
|
|
38
|
+
* @returns {Promise<void>}
|
|
39
|
+
*/
|
|
8
40
|
down(): Promise<void>;
|
|
41
|
+
/**
|
|
42
|
+
* Moves the bot up.
|
|
43
|
+
* @returns {Promise<void>}
|
|
44
|
+
*/
|
|
9
45
|
up(): Promise<void>;
|
|
10
|
-
operateBot(bytes: number[]): Promise<void>;
|
|
11
46
|
}
|
|
12
47
|
//# sourceMappingURL=wohand.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wohand.d.ts","sourceRoot":"","sources":["../../src/device/wohand.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"wohand.d.ts","sourceRoot":"","sources":["../../src/device/wohand.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AAEpC,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAA;AAG9C;;;GAGG;AACH,qBAAa,MAAO,SAAQ,eAAe;IACzC;;;;;OAKG;WACU,gBAAgB,CAC3B,WAAW,EAAE,MAAM,EACnB,OAAO,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,KAAK,IAAI,GAChD,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;IAmBzB;;;;OAIG;YACW,UAAU;IAUxB;;;OAGG;IACG,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAI5B;;;OAGG;IACG,MAAM,IAAI,OAAO,CAAC,IAAI,CAAC;IAI7B;;;OAGG;IACG,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAI9B;;;OAGG;IACG,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAI3B;;;OAGG;IACG,EAAE,IAAI,OAAO,CAAC,IAAI,CAAC;CAG1B"}
|
package/dist/device/wohand.js
CHANGED
|
@@ -1,118 +1,84 @@
|
|
|
1
|
-
import { Buffer } from 'node:buffer';
|
|
2
1
|
/* Copyright(C) 2024, donavanbecker (https://github.com/donavanbecker). All rights reserved.
|
|
3
2
|
*
|
|
4
3
|
* wohand.ts: Switchbot BLE API registration.
|
|
5
4
|
*/
|
|
5
|
+
import { Buffer } from 'node:buffer';
|
|
6
6
|
import { SwitchbotDevice } from '../device.js';
|
|
7
7
|
import { SwitchBotBLEModel, SwitchBotBLEModelFriendlyName, SwitchBotBLEModelName } from '../types/types.js';
|
|
8
|
+
/**
|
|
9
|
+
* Class representing a WoHand device.
|
|
10
|
+
* @see https://github.com/OpenWonderLabs/SwitchBotAPI-BLE/blob/latest/devicetypes/bot.md
|
|
11
|
+
*/
|
|
8
12
|
export class WoHand extends SwitchbotDevice {
|
|
9
|
-
|
|
13
|
+
/**
|
|
14
|
+
* Parses the service data for WoHand.
|
|
15
|
+
* @param {Buffer} serviceData - The service data buffer.
|
|
16
|
+
* @param {Function} emitLog - The function to emit log messages.
|
|
17
|
+
* @returns {Promise<object | null>} - Parsed service data or null if invalid.
|
|
18
|
+
*/
|
|
19
|
+
static async parseServiceData(serviceData, emitLog) {
|
|
10
20
|
if (serviceData.length !== 3) {
|
|
11
|
-
|
|
12
|
-
onlog(`[parseServiceData] Buffer length ${serviceData.length} !== 3!`);
|
|
13
|
-
}
|
|
21
|
+
emitLog('debugerror', `[parseServiceData] Buffer length ${serviceData.length} !== 3!`);
|
|
14
22
|
return null;
|
|
15
23
|
}
|
|
16
24
|
const byte1 = serviceData.readUInt8(1);
|
|
17
25
|
const byte2 = serviceData.readUInt8(2);
|
|
18
|
-
|
|
19
|
-
const state = !(byte1 & 0b01000000); // Whether the switch status is ON or OFF. 0 = on, 1 = off
|
|
20
|
-
const battery = byte2 & 0b01111111; // %
|
|
21
|
-
const data = {
|
|
26
|
+
return {
|
|
22
27
|
model: SwitchBotBLEModel.Bot,
|
|
23
28
|
modelName: SwitchBotBLEModelName.Bot,
|
|
24
29
|
modelFriendlyName: SwitchBotBLEModelFriendlyName.Bot,
|
|
25
|
-
mode,
|
|
26
|
-
state,
|
|
27
|
-
battery,
|
|
30
|
+
mode: !!(byte1 & 0b10000000), // Whether the light switch Add-on is used or not. 0 = press, 1 = switch
|
|
31
|
+
state: !(byte1 & 0b01000000), // Whether the switch status is ON or OFF. 0 = on, 1 = off
|
|
32
|
+
battery: byte2 & 0b01111111, // %
|
|
28
33
|
};
|
|
29
|
-
return data;
|
|
30
34
|
}
|
|
31
|
-
|
|
32
|
-
*
|
|
33
|
-
* -
|
|
34
|
-
*
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
35
|
+
/**
|
|
36
|
+
* Sends a command to the bot.
|
|
37
|
+
* @param {number[]} bytes - The command bytes.
|
|
38
|
+
* @returns {Promise<void>}
|
|
39
|
+
*/
|
|
40
|
+
async operateBot(bytes) {
|
|
41
|
+
const reqBuf = Buffer.from(bytes);
|
|
42
|
+
const resBuf = await this.command(reqBuf);
|
|
43
|
+
const code = resBuf.readUInt8(0);
|
|
44
|
+
if (resBuf.length !== 3 || (code !== 0x01 && code !== 0x05)) {
|
|
45
|
+
throw new Error(`The device returned an error: 0x${resBuf.toString('hex')}`);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Presses the bot.
|
|
50
|
+
* @returns {Promise<void>}
|
|
51
|
+
*/
|
|
42
52
|
async press() {
|
|
43
|
-
|
|
53
|
+
await this.operateBot([0x57, 0x01, 0x00]);
|
|
44
54
|
}
|
|
45
|
-
|
|
46
|
-
*
|
|
47
|
-
*
|
|
48
|
-
|
|
49
|
-
* [Arguments]
|
|
50
|
-
* - none
|
|
51
|
-
*
|
|
52
|
-
* [Return value]
|
|
53
|
-
* - Promise object
|
|
54
|
-
* Nothing will be passed to the `resolve()`.
|
|
55
|
-
* ---------------------------------------------------------------- */
|
|
55
|
+
/**
|
|
56
|
+
* Turns on the bot.
|
|
57
|
+
* @returns {Promise<void>}
|
|
58
|
+
*/
|
|
56
59
|
async turnOn() {
|
|
57
|
-
|
|
60
|
+
await this.operateBot([0x57, 0x01, 0x01]);
|
|
58
61
|
}
|
|
59
|
-
|
|
60
|
-
*
|
|
61
|
-
*
|
|
62
|
-
|
|
63
|
-
* [Arguments]
|
|
64
|
-
* - none
|
|
65
|
-
*
|
|
66
|
-
* [Return value]
|
|
67
|
-
* - Promise object
|
|
68
|
-
* Nothing will be passed to the `resolve()`.
|
|
69
|
-
* ---------------------------------------------------------------- */
|
|
62
|
+
/**
|
|
63
|
+
* Turns off the bot.
|
|
64
|
+
* @returns {Promise<void>}
|
|
65
|
+
*/
|
|
70
66
|
async turnOff() {
|
|
71
|
-
|
|
67
|
+
await this.operateBot([0x57, 0x01, 0x02]);
|
|
72
68
|
}
|
|
73
|
-
|
|
74
|
-
* down
|
|
75
|
-
*
|
|
76
|
-
|
|
77
|
-
* [Arguments]
|
|
78
|
-
* - none
|
|
79
|
-
*
|
|
80
|
-
* [Return value]
|
|
81
|
-
* - Promise object
|
|
82
|
-
* Nothing will be passed to the `resolve()`.
|
|
83
|
-
* ---------------------------------------------------------------- */
|
|
69
|
+
/**
|
|
70
|
+
* Moves the bot down.
|
|
71
|
+
* @returns {Promise<void>}
|
|
72
|
+
*/
|
|
84
73
|
async down() {
|
|
85
|
-
|
|
74
|
+
await this.operateBot([0x57, 0x01, 0x03]);
|
|
86
75
|
}
|
|
87
|
-
|
|
88
|
-
* up
|
|
89
|
-
*
|
|
90
|
-
|
|
91
|
-
* [Arguments]
|
|
92
|
-
* - none
|
|
93
|
-
*
|
|
94
|
-
* [Return value]
|
|
95
|
-
* - Promise object
|
|
96
|
-
* Nothing will be passed to the `resolve()`.
|
|
97
|
-
* ---------------------------------------------------------------- */
|
|
76
|
+
/**
|
|
77
|
+
* Moves the bot up.
|
|
78
|
+
* @returns {Promise<void>}
|
|
79
|
+
*/
|
|
98
80
|
async up() {
|
|
99
|
-
|
|
100
|
-
}
|
|
101
|
-
async operateBot(bytes) {
|
|
102
|
-
const req_buf = Buffer.from(bytes);
|
|
103
|
-
await this.command(req_buf)
|
|
104
|
-
.then((res_buf) => {
|
|
105
|
-
const code = res_buf.readUInt8(0);
|
|
106
|
-
if (res_buf.length === 3 && (code === 0x01 || code === 0x05)) {
|
|
107
|
-
// Successful operation, no further action needed
|
|
108
|
-
}
|
|
109
|
-
else {
|
|
110
|
-
throw new Error(`The device returned an error: 0x${res_buf.toString('hex')}`);
|
|
111
|
-
}
|
|
112
|
-
})
|
|
113
|
-
.catch((error) => {
|
|
114
|
-
throw error;
|
|
115
|
-
});
|
|
81
|
+
await this.operateBot([0x57, 0x01, 0x04]);
|
|
116
82
|
}
|
|
117
83
|
}
|
|
118
84
|
//# sourceMappingURL=wohand.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wohand.js","sourceRoot":"","sources":["../../src/device/wohand.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AAEpC
|
|
1
|
+
{"version":3,"file":"wohand.js","sourceRoot":"","sources":["../../src/device/wohand.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AAEpC,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAA;AAC9C,OAAO,EAAE,iBAAiB,EAAE,6BAA6B,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAA;AAE3G;;;GAGG;AACH,MAAM,OAAO,MAAO,SAAQ,eAAe;IACzC;;;;;OAKG;IACH,MAAM,CAAC,KAAK,CAAC,gBAAgB,CAC3B,WAAmB,EACnB,OAAiD;QAEjD,IAAI,WAAW,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YAC7B,OAAO,CAAC,YAAY,EAAE,oCAAoC,WAAW,CAAC,MAAM,SAAS,CAAC,CAAA;YACtF,OAAO,IAAI,CAAA;QACb,CAAC;QAED,MAAM,KAAK,GAAG,WAAW,CAAC,SAAS,CAAC,CAAC,CAAC,CAAA;QACtC,MAAM,KAAK,GAAG,WAAW,CAAC,SAAS,CAAC,CAAC,CA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,CAAC,CAAA;IAC3C,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,IAAI;QACR,MAAM,IAAI,CAAC,UAAU,CAAC,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC,CAAA;IAC3C,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,EAAE;QACN,MAAM,IAAI,CAAC,UAAU,CAAC,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC,CAAA;IAC3C,CAAC;CACF"}
|
package/dist/device/wohub2.d.ts
CHANGED
|
@@ -1,6 +1,16 @@
|
|
|
1
1
|
import type { Buffer } from 'node:buffer';
|
|
2
2
|
import { SwitchbotDevice } from '../device.js';
|
|
3
|
+
/**
|
|
4
|
+
* Class representing a WoHub2 device.
|
|
5
|
+
* @see https://github.com/OpenWonderLabs/SwitchBotAPI-BLE/blob/latest/devicetypes/meter.md
|
|
6
|
+
*/
|
|
3
7
|
export declare class WoHub2 extends SwitchbotDevice {
|
|
4
|
-
|
|
8
|
+
/**
|
|
9
|
+
* Parses the service data for WoHub2.
|
|
10
|
+
* @param {Buffer} manufacturerData - The manufacturer data buffer.
|
|
11
|
+
* @param {Function} emitLog - The function to emit log messages.
|
|
12
|
+
* @returns {Promise<object | null>} - Parsed service data or null if invalid.
|
|
13
|
+
*/
|
|
14
|
+
static parseServiceData(manufacturerData: Buffer, emitLog: (level: string, message: string) => void): Promise<object | null>;
|
|
5
15
|
}
|
|
6
16
|
//# sourceMappingURL=wohub2.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wohub2.d.ts","sourceRoot":"","sources":["../../src/device/wohub2.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"wohub2.d.ts","sourceRoot":"","sources":["../../src/device/wohub2.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AAEzC,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAA;AAG9C;;;GAGG;AACH,qBAAa,MAAO,SAAQ,eAAe;IACzC;;;;;OAKG;WACU,gBAAgB,CAC3B,gBAAgB,EAAE,MAAM,EACxB,OAAO,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,KAAK,IAAI,GAChD,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;CAwB1B"}
|
package/dist/device/wohub2.js
CHANGED
|
@@ -1,44 +1,36 @@
|
|
|
1
|
-
/* Copyright(C) 2024, donavanbecker (https://github.com/donavanbecker). All rights reserved.
|
|
2
|
-
*
|
|
3
|
-
* wohub2.ts: Switchbot BLE API registration.
|
|
4
|
-
*/
|
|
5
1
|
import { SwitchbotDevice } from '../device.js';
|
|
6
2
|
import { SwitchBotBLEModel, SwitchBotBLEModelFriendlyName, SwitchBotBLEModelName } from '../types/types.js';
|
|
3
|
+
/**
|
|
4
|
+
* Class representing a WoHub2 device.
|
|
5
|
+
* @see https://github.com/OpenWonderLabs/SwitchBotAPI-BLE/blob/latest/devicetypes/meter.md
|
|
6
|
+
*/
|
|
7
7
|
export class WoHub2 extends SwitchbotDevice {
|
|
8
|
-
|
|
8
|
+
/**
|
|
9
|
+
* Parses the service data for WoHub2.
|
|
10
|
+
* @param {Buffer} manufacturerData - The manufacturer data buffer.
|
|
11
|
+
* @param {Function} emitLog - The function to emit log messages.
|
|
12
|
+
* @returns {Promise<object | null>} - Parsed service data or null if invalid.
|
|
13
|
+
*/
|
|
14
|
+
static async parseServiceData(manufacturerData, emitLog) {
|
|
9
15
|
if (manufacturerData.length !== 16) {
|
|
10
|
-
|
|
11
|
-
onlog(`[parseServiceDataForWoSensorTH] Buffer length ${manufacturerData.length} !== 16!`);
|
|
12
|
-
}
|
|
16
|
+
emitLog('debugerror', `[parseServiceDataForWoHub2] Buffer length ${manufacturerData.length} !== 16!`);
|
|
13
17
|
return null;
|
|
14
18
|
}
|
|
15
|
-
const byte0 = manufacturerData
|
|
16
|
-
const
|
|
17
|
-
const
|
|
18
|
-
const
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
const temp_f = Math.round(((temp_c * 9 / 5) + 32) * 10) / 10;
|
|
22
|
-
const light_level = byte12 & 0b11111;
|
|
23
|
-
const data = {
|
|
19
|
+
const [byte0, byte1, byte2, , , , , , , , , , byte12] = manufacturerData;
|
|
20
|
+
const tempSign = byte1 & 0b10000000 ? 1 : -1;
|
|
21
|
+
const tempC = tempSign * ((byte1 & 0b01111111) + (byte0 & 0b00001111) / 10);
|
|
22
|
+
const tempF = Math.round(((tempC * 9) / 5 + 32) * 10) / 10;
|
|
23
|
+
const lightLevel = byte12 & 0b11111;
|
|
24
|
+
return {
|
|
24
25
|
model: SwitchBotBLEModel.Hub2,
|
|
25
26
|
modelName: SwitchBotBLEModelName.Hub2,
|
|
26
27
|
modelFriendlyName: SwitchBotBLEModelFriendlyName.Hub2,
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
* Use the `celsius` and `fahrenheit` properties directly instead.
|
|
30
|
-
*/
|
|
31
|
-
temperature: {
|
|
32
|
-
c: temp_c,
|
|
33
|
-
f: temp_f,
|
|
34
|
-
},
|
|
35
|
-
celsius: temp_c,
|
|
36
|
-
fahrenheit: temp_f,
|
|
28
|
+
celsius: tempC,
|
|
29
|
+
fahrenheit: tempF,
|
|
37
30
|
fahrenheit_mode: !!(byte2 & 0b10000000),
|
|
38
31
|
humidity: byte2 & 0b01111111,
|
|
39
|
-
lightLevel
|
|
32
|
+
lightLevel,
|
|
40
33
|
};
|
|
41
|
-
return data;
|
|
42
34
|
}
|
|
43
35
|
}
|
|
44
36
|
//# sourceMappingURL=wohub2.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wohub2.js","sourceRoot":"","sources":["../../src/device/wohub2.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"wohub2.js","sourceRoot":"","sources":["../../src/device/wohub2.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,eAAe,EAAE,MAAM,c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,CAAC,CAAC,KAAK,GAAG,UAAU,CAAC;YACvC,QAAQ,EAAE,KAAK,GAAG,UAAU;YAC5B,UAAU;SACX,CAAA;IACH,CAAC;CACF"}
|
package/dist/device/wohumi.d.ts
CHANGED
|
@@ -1,12 +1,47 @@
|
|
|
1
1
|
import { Buffer } from 'node:buffer';
|
|
2
2
|
import { SwitchbotDevice } from '../device.js';
|
|
3
|
+
/**
|
|
4
|
+
* Class representing a WoHumi device.
|
|
5
|
+
* @see https://github.com/OpenWonderLabs/SwitchBotAPI-BLE/tree/latest/devicetypes
|
|
6
|
+
*/
|
|
3
7
|
export declare class WoHumi extends SwitchbotDevice {
|
|
4
|
-
|
|
8
|
+
/**
|
|
9
|
+
* Parses the service data for WoHumi.
|
|
10
|
+
* @param {Buffer} serviceData - The service data buffer.
|
|
11
|
+
* @param {Function} emitLog - The function to emit log messages.
|
|
12
|
+
* @returns {Promise<object | null>} - Parsed service data or null if invalid.
|
|
13
|
+
*/
|
|
14
|
+
static parseServiceData(serviceData: Buffer, emitLog: (level: string, message: string) => void): Promise<object | null>;
|
|
15
|
+
/**
|
|
16
|
+
* Sends a command to the humidifier.
|
|
17
|
+
* @param {number[]} bytes - The command bytes.
|
|
18
|
+
* @returns {Promise<void>}
|
|
19
|
+
*/
|
|
20
|
+
operateHumi(bytes: number[]): Promise<void>;
|
|
21
|
+
/**
|
|
22
|
+
* Presses the humidifier button.
|
|
23
|
+
* @returns {Promise<void>}
|
|
24
|
+
*/
|
|
5
25
|
press(): Promise<void>;
|
|
26
|
+
/**
|
|
27
|
+
* Turns on the humidifier.
|
|
28
|
+
* @returns {Promise<void>}
|
|
29
|
+
*/
|
|
6
30
|
turnOn(): Promise<void>;
|
|
31
|
+
/**
|
|
32
|
+
* Turns off the humidifier.
|
|
33
|
+
* @returns {Promise<void>}
|
|
34
|
+
*/
|
|
7
35
|
turnOff(): Promise<void>;
|
|
36
|
+
/**
|
|
37
|
+
* Decreases the humidifier setting.
|
|
38
|
+
* @returns {Promise<void>}
|
|
39
|
+
*/
|
|
8
40
|
down(): Promise<void>;
|
|
41
|
+
/**
|
|
42
|
+
* Increases the humidifier setting.
|
|
43
|
+
* @returns {Promise<void>}
|
|
44
|
+
*/
|
|
9
45
|
up(): Promise<void>;
|
|
10
|
-
operateHumi(bytes: number[]): Promise<void>;
|
|
11
46
|
}
|
|
12
47
|
//# sourceMappingURL=wohumi.d.ts.map
|