node-switchbot 2.5.0-beta.9 → 3.0.0
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 +14 -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 +41 -0
- package/dist/settings.d.ts.map +1 -1
- package/dist/settings.js +43 -0
- package/dist/settings.js.map +1 -1
- package/dist/{switchbot.d.ts → switchbot-ble.d.ts} +13 -8
- package/dist/switchbot-ble.d.ts.map +1 -0
- package/dist/switchbot-ble.js +427 -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 +23 -0
- 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 +64 -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/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 +1109 -0
- package/docs/media/OpenAPI.md +185 -0
- package/docs/modules.html +136 -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 +13 -11
- 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
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wohumi.d.ts","sourceRoot":"","sources":["../../src/device/wohumi.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"wohumi.d.ts","sourceRoot":"","sources":["../../src/device/wohumi.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;IAyBzB;;;;OAIG;IACU,WAAW,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAUxD;;;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/wohumi.js
CHANGED
|
@@ -1,16 +1,24 @@
|
|
|
1
|
-
import { Buffer } from 'node:buffer';
|
|
2
1
|
/* Copyright(C) 2024, donavanbecker (https://github.com/donavanbecker). All rights reserved.
|
|
3
2
|
*
|
|
4
3
|
* wohumi.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 WoHumi device.
|
|
10
|
+
* @see https://github.com/OpenWonderLabs/SwitchBotAPI-BLE/tree/latest/devicetypes
|
|
11
|
+
*/
|
|
8
12
|
export class WoHumi extends SwitchbotDevice {
|
|
9
|
-
|
|
13
|
+
/**
|
|
14
|
+
* Parses the service data for WoHumi.
|
|
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 !== 8) {
|
|
11
|
-
|
|
12
|
-
onlog(`[parseServiceDataForWoHumi] Buffer length ${serviceData.length} !== 8!`);
|
|
13
|
-
}
|
|
21
|
+
emitLog('debugerror', `[parseServiceDataForWoHumi] Buffer length ${serviceData.length} !== 8!`);
|
|
14
22
|
return null;
|
|
15
23
|
}
|
|
16
24
|
const byte1 = serviceData.readUInt8(1);
|
|
@@ -19,7 +27,7 @@ export class WoHumi extends SwitchbotDevice {
|
|
|
19
27
|
const autoMode = !!(byte4 & 0b10000000); // 1 - auto
|
|
20
28
|
const percentage = byte4 & 0b01111111; // 0-100%, 101/102/103 - Quick gear 1/2/3
|
|
21
29
|
const humidity = autoMode ? 0 : percentage === 101 ? 33 : percentage === 102 ? 66 : percentage === 103 ? 100 : percentage;
|
|
22
|
-
|
|
30
|
+
return {
|
|
23
31
|
model: SwitchBotBLEModel.Humidifier,
|
|
24
32
|
modelName: SwitchBotBLEModelName.Humidifier,
|
|
25
33
|
modelFriendlyName: SwitchBotBLEModelFriendlyName.Humidifier,
|
|
@@ -28,93 +36,54 @@ export class WoHumi extends SwitchbotDevice {
|
|
|
28
36
|
percentage: autoMode ? 0 : percentage,
|
|
29
37
|
humidity,
|
|
30
38
|
};
|
|
31
|
-
return data;
|
|
32
39
|
}
|
|
33
|
-
|
|
34
|
-
*
|
|
35
|
-
* -
|
|
36
|
-
*
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
40
|
+
/**
|
|
41
|
+
* Sends a command to the humidifier.
|
|
42
|
+
* @param {number[]} bytes - The command bytes.
|
|
43
|
+
* @returns {Promise<void>}
|
|
44
|
+
*/
|
|
45
|
+
async operateHumi(bytes) {
|
|
46
|
+
const reqBuf = Buffer.from(bytes);
|
|
47
|
+
const resBuf = await this.command(reqBuf);
|
|
48
|
+
const code = resBuf.readUInt8(0);
|
|
49
|
+
if (resBuf.length !== 3 || (code !== 0x01 && code !== 0x05)) {
|
|
50
|
+
throw new Error(`The device returned an error: 0x${resBuf.toString('hex')}`);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Presses the humidifier button.
|
|
55
|
+
* @returns {Promise<void>}
|
|
56
|
+
*/
|
|
44
57
|
async press() {
|
|
45
|
-
|
|
58
|
+
await this.operateHumi([0x57, 0x01, 0x00]);
|
|
46
59
|
}
|
|
47
|
-
|
|
48
|
-
*
|
|
49
|
-
*
|
|
50
|
-
|
|
51
|
-
* [Arguments]
|
|
52
|
-
* - none
|
|
53
|
-
*
|
|
54
|
-
* [Return value]
|
|
55
|
-
* - Promise object
|
|
56
|
-
* Nothing will be passed to the `resolve()`.
|
|
57
|
-
* ---------------------------------------------------------------- */
|
|
60
|
+
/**
|
|
61
|
+
* Turns on the humidifier.
|
|
62
|
+
* @returns {Promise<void>}
|
|
63
|
+
*/
|
|
58
64
|
async turnOn() {
|
|
59
|
-
|
|
65
|
+
await this.operateHumi([0x57, 0x01, 0x01]);
|
|
60
66
|
}
|
|
61
|
-
|
|
62
|
-
*
|
|
63
|
-
*
|
|
64
|
-
|
|
65
|
-
* [Arguments]
|
|
66
|
-
* - none
|
|
67
|
-
*
|
|
68
|
-
* [Return value]
|
|
69
|
-
* - Promise object
|
|
70
|
-
* Nothing will be passed to the `resolve()`.
|
|
71
|
-
* ---------------------------------------------------------------- */
|
|
67
|
+
/**
|
|
68
|
+
* Turns off the humidifier.
|
|
69
|
+
* @returns {Promise<void>}
|
|
70
|
+
*/
|
|
72
71
|
async turnOff() {
|
|
73
|
-
|
|
72
|
+
await this.operateHumi([0x57, 0x01, 0x02]);
|
|
74
73
|
}
|
|
75
|
-
|
|
76
|
-
*
|
|
77
|
-
*
|
|
78
|
-
|
|
79
|
-
* [Arguments]
|
|
80
|
-
* - none
|
|
81
|
-
*
|
|
82
|
-
* [Return value]
|
|
83
|
-
* - Promise object
|
|
84
|
-
* Nothing will be passed to the `resolve()`.
|
|
85
|
-
* ---------------------------------------------------------------- */
|
|
74
|
+
/**
|
|
75
|
+
* Decreases the humidifier setting.
|
|
76
|
+
* @returns {Promise<void>}
|
|
77
|
+
*/
|
|
86
78
|
async down() {
|
|
87
|
-
|
|
79
|
+
await this.operateHumi([0x57, 0x01, 0x03]);
|
|
88
80
|
}
|
|
89
|
-
|
|
90
|
-
*
|
|
91
|
-
*
|
|
92
|
-
|
|
93
|
-
* [Arguments]
|
|
94
|
-
* - none
|
|
95
|
-
*
|
|
96
|
-
* [Return value]
|
|
97
|
-
* - Promise object
|
|
98
|
-
* Nothing will be passed to the `resolve()`.
|
|
99
|
-
* ---------------------------------------------------------------- */
|
|
81
|
+
/**
|
|
82
|
+
* Increases the humidifier setting.
|
|
83
|
+
* @returns {Promise<void>}
|
|
84
|
+
*/
|
|
100
85
|
async up() {
|
|
101
|
-
|
|
102
|
-
}
|
|
103
|
-
async operateHumi(bytes) {
|
|
104
|
-
const req_buf = Buffer.from(bytes);
|
|
105
|
-
await this.command(req_buf)
|
|
106
|
-
.then((res_buf) => {
|
|
107
|
-
const code = res_buf.readUInt8(0);
|
|
108
|
-
if (res_buf.length === 3 && (code === 0x01 || code === 0x05)) {
|
|
109
|
-
// Intentionally left empty
|
|
110
|
-
}
|
|
111
|
-
else {
|
|
112
|
-
throw new Error(`The device returned an error: 0x${res_buf.toString('hex')}`);
|
|
113
|
-
}
|
|
114
|
-
})
|
|
115
|
-
.catch((error) => {
|
|
116
|
-
throw error;
|
|
117
|
-
});
|
|
86
|
+
await this.operateHumi([0x57, 0x01, 0x04]);
|
|
118
87
|
}
|
|
119
88
|
}
|
|
120
89
|
//# sourceMappingURL=wohumi.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wohumi.js","sourceRoot":"","sources":["../../src/device/wohumi.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AAEpC
|
|
1
|
+
{"version":3,"file":"wohumi.js","sourceRoot":"","sources":["../../src/device/wohumi.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,6CAA6C,WAAW,CAAC,MAAM,SAAS,CAAC,CAAA;YAC/F,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,CAAC,CAAA;QAEtC,MAAM,OAAO,GAAG,CAAC,CAAC,CAAC,KAAK,GAAG,UAAU,CAAC,CAAA,CAAC,SAAS;QAChD,MAAM,QAAQ,GAAG,CAAC,CAAC,CAAC,KAAK,GAAG,UAAU,CAAC,CAAA,CAAC,WAAW;QACnD,MAAM,UAAU,GAAG,KAAK,GAAG,UAAU,CAAA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,WAAW,CAAC,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC,CAAA;IAC5C,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,OAAO;QACX,MAAM,IAAI,CAAC,WAAW,CAAC,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC,CAAA;IAC5C,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,IAAI;QACR,MAAM,IAAI,CAAC,WAAW,CAAC,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC,CAAA;IAC5C,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,EAAE;QACN,MAAM,IAAI,CAAC,WAAW,CAAC,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC,CAAA;IAC5C,CAAC;CACF"}
|
|
@@ -1,6 +1,17 @@
|
|
|
1
1
|
import type { Buffer } from 'node:buffer';
|
|
2
2
|
import { SwitchbotDevice } from '../device.js';
|
|
3
|
+
/**
|
|
4
|
+
* Class representing a WoIOSensorTH device.
|
|
5
|
+
* @see https://github.com/OpenWonderLabs/SwitchBotAPI-BLE/blob/latest/devicetypes/meter.md#outdoor-temperaturehumidity-sensor
|
|
6
|
+
*/
|
|
3
7
|
export declare class WoIOSensorTH extends SwitchbotDevice {
|
|
4
|
-
|
|
8
|
+
/**
|
|
9
|
+
* Parses the service data for WoIOSensorTH.
|
|
10
|
+
* @param {Buffer} serviceData - The service data buffer.
|
|
11
|
+
* @param {Buffer} manufacturerData - The manufacturer data buffer.
|
|
12
|
+
* @param {Function} emitLog - The function to emit log messages.
|
|
13
|
+
* @returns {Promise<object | null>} - Parsed service data or null if invalid.
|
|
14
|
+
*/
|
|
15
|
+
static parseServiceData(serviceData: Buffer, manufacturerData: Buffer, emitLog: (level: string, message: string) => void): Promise<object | null>;
|
|
5
16
|
}
|
|
6
17
|
//# sourceMappingURL=woiosensorth.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"woiosensorth.d.ts","sourceRoot":"","sources":["../../src/device/woiosensorth.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"woiosensorth.d.ts","sourceRoot":"","sources":["../../src/device/woiosensorth.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AAEzC,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAA;AAG9C;;;GAGG;AACH,qBAAa,YAAa,SAAQ,eAAe;IAC/C;;;;;;OAMG;WACU,gBAAgB,CAC3B,WAAW,EAAE,MAAM,EACnB,gBAAgB,EAAE,MAAM,EACxB,OAAO,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,KAAK,IAAI,GAChD,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;CAgC1B"}
|
|
@@ -1,49 +1,45 @@
|
|
|
1
|
-
/* Copyright(C) 2024, donavanbecker (https://github.com/donavanbecker). All rights reserved.
|
|
2
|
-
*
|
|
3
|
-
* woiosensorth.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 WoIOSensorTH device.
|
|
5
|
+
* @see https://github.com/OpenWonderLabs/SwitchBotAPI-BLE/blob/latest/devicetypes/meter.md#outdoor-temperaturehumidity-sensor
|
|
6
|
+
*/
|
|
7
7
|
export class WoIOSensorTH extends SwitchbotDevice {
|
|
8
|
-
|
|
8
|
+
/**
|
|
9
|
+
* Parses the service data for WoIOSensorTH.
|
|
10
|
+
* @param {Buffer} serviceData - The service data buffer.
|
|
11
|
+
* @param {Buffer} manufacturerData - The manufacturer data buffer.
|
|
12
|
+
* @param {Function} emitLog - The function to emit log messages.
|
|
13
|
+
* @returns {Promise<object | null>} - Parsed service data or null if invalid.
|
|
14
|
+
*/
|
|
15
|
+
static async parseServiceData(serviceData, manufacturerData, emitLog) {
|
|
9
16
|
if (serviceData.length !== 3) {
|
|
10
|
-
|
|
11
|
-
onlog(`[parseServiceDataForWoIOSensorTH] Service Data Buffer length ${serviceData.length} !== 3!`);
|
|
12
|
-
}
|
|
17
|
+
emitLog('debugerror', `[parseServiceDataForWoIOSensorTH] Service Data Buffer length ${serviceData.length} !== 3!`);
|
|
13
18
|
return null;
|
|
14
19
|
}
|
|
15
20
|
if (manufacturerData.length !== 14) {
|
|
16
|
-
|
|
17
|
-
onlog(`[parseServiceDataForWoIOSensorTH] Manufacturer Data Buffer length ${manufacturerData.length} !== 14!`);
|
|
18
|
-
}
|
|
21
|
+
emitLog('debugerror', `[parseServiceDataForWoIOSensorTH] Manufacturer Data Buffer length ${manufacturerData.length} !== 14!`);
|
|
19
22
|
return null;
|
|
20
23
|
}
|
|
21
|
-
const mdByte10 =
|
|
22
|
-
|
|
23
|
-
|
|
24
|
+
const [mdByte10, mdByte11, mdByte12] = [
|
|
25
|
+
manufacturerData.readUInt8(10),
|
|
26
|
+
manufacturerData.readUInt8(11),
|
|
27
|
+
manufacturerData.readUInt8(12),
|
|
28
|
+
];
|
|
24
29
|
const sdByte2 = serviceData.readUInt8(2);
|
|
25
|
-
const
|
|
26
|
-
const
|
|
27
|
-
const
|
|
28
|
-
|
|
30
|
+
const tempSign = mdByte11 & 0b10000000 ? 1 : -1;
|
|
31
|
+
const tempC = tempSign * ((mdByte11 & 0b01111111) + (mdByte10 & 0b00001111) / 10);
|
|
32
|
+
const tempF = Math.round(((tempC * 9) / 5 + 32) * 10) / 10;
|
|
33
|
+
return {
|
|
29
34
|
model: SwitchBotBLEModel.OutdoorMeter,
|
|
30
35
|
modelName: SwitchBotBLEModelName.OutdoorMeter,
|
|
31
36
|
modelFriendlyName: SwitchBotBLEModelFriendlyName.OutdoorMeter,
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
* Use the `celsius` and `fahrenheit` properties directly instead.
|
|
35
|
-
*/
|
|
36
|
-
temperature: {
|
|
37
|
-
c: temp_c,
|
|
38
|
-
f: temp_f,
|
|
39
|
-
},
|
|
40
|
-
celsius: temp_c,
|
|
41
|
-
fahrenheit: temp_f,
|
|
37
|
+
celsius: tempC,
|
|
38
|
+
fahrenheit: tempF,
|
|
42
39
|
fahrenheit_mode: !!(mdByte12 & 0b10000000),
|
|
43
40
|
humidity: mdByte12 & 0b01111111,
|
|
44
41
|
battery: sdByte2 & 0b01111111,
|
|
45
42
|
};
|
|
46
|
-
return data;
|
|
47
43
|
}
|
|
48
44
|
}
|
|
49
45
|
//# sourceMappingURL=woiosensorth.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"woiosensorth.js","sourceRoot":"","sources":["../../src/device/woiosensorth.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"woiosensorth.js","sourceRoot":"","sources":["../../src/device/woiosensorth.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAA;AAC9C,OAAO,EAAE,iBAAiB,EAAE,6BAA6B,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAA;AAE3G;;;GAGG;AACH,MAAM,OAAO,YAAa,SAAQ,eAAe;IAC/C;;;;;;OAMG;IACH,MAAM,CAAC,KAAK,CAAC,gBAAgB,CAC3B,WAAmB,EACnB,gBAAwB,EACxB,OAAiD;QAEjD,IAAI,WAAW,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YAC7B,OAAO,CAAC,YAAY,EAAE,gEAAgE,WAAW,CAAC,MAAM,SAAS,CAAC,CAAA;YAClH,OAAO,IAAI,CAAA;QACb,CAAC;QACD,IAAI,gBAAgB,CAAC,MAAM,KAAK,EAAE,EAAE,CAAC;YACnC,OAAO,CAAC,YAAY,EAAE,qEAAqE,gBAAgB,CAAC,MAAM,UAAU,CAAC,CAAA;YAC7H,OAAO,IAAI,CAAA;QACb,CAAC;QAED,MAAM,CAAC,QAAQ,EAAE,QAAQ,EAAE,QAAQ,CAAC,GAAG;YACrC,gBAAgB,CAAC,SAAS,CAAC,EAAE,CAAC;YAC9B,gBAAgB,CAAC,SAAS,CAAC,EAAE,CAAC;YAC9B,gBAAgB,CAAC,SAAS,CAAC,EAAE,CAAC;SAC/B,CAAA;QACD,MAAM,OAAO,GAAG,WAAW,CAAC,SAAS,CAAC,CAAC,CAAC,CAAA;QAExC,MAAM,QAAQ,GAAG,QAAQ,GAAG,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;QAC/C,MAAM,KAAK,GAAG,QAAQ,GAAG,CAAC,CAAC,QAAQ,GAAG,UAAU,CAAC,GAAG,CAAC,QAAQ,GAAG,UAAU,CAAC,GAAG,EAAE,CAAC,CAAA;QACjF,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,GAAG,CAAC,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC,GAAG,EAAE,CAAC,GAAG,EAAE,CAAA;QAE1D,OAAO;YACL,KAAK,EAAE,iBAAiB,CAAC,YAAY;YACrC,SAAS,EAAE,qBAAqB,CAAC,YAAY;YAC7C,iBAAiB,EAAE,6BAA6B,CAAC,YAAY;YAC7D,OAAO,EAAE,KAAK;YACd,UAAU,EAAE,KAAK;YACjB,eAAe,EAAE,CAAC,CAAC,CAAC,QAAQ,GAAG,UAAU,CAAC;YAC1C,QAAQ,EAAE,QAAQ,GAAG,UAAU;YAC/B,OAAO,EAAE,OAAO,GAAG,UAAU;SAC9B,CAAA;IACH,CAAC;CACF"}
|
|
@@ -1,31 +1,64 @@
|
|
|
1
1
|
import { Buffer } from 'node:buffer';
|
|
2
2
|
import { SwitchbotDevice } from '../device.js';
|
|
3
3
|
/**
|
|
4
|
+
* Class representing a WoPlugMini device.
|
|
4
5
|
* @see https://github.com/OpenWonderLabs/SwitchBotAPI-BLE/blob/latest/devicetypes/plugmini.md
|
|
5
6
|
*/
|
|
6
7
|
export declare class WoPlugMini extends SwitchbotDevice {
|
|
7
|
-
static parseServiceData_US(manufacturerData: Buffer, onlog: ((message: string) => void) | undefined): Promise<object | null>;
|
|
8
|
-
static parseServiceData_JP(manufacturerData: Buffer, onlog: ((message: string) => void) | undefined): Promise<object | null>;
|
|
9
8
|
/**
|
|
10
|
-
*
|
|
9
|
+
* Parses the service data for WoPlugMini US.
|
|
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.
|
|
11
13
|
*/
|
|
12
|
-
|
|
14
|
+
static parseServiceData_US(manufacturerData: Buffer, emitLog: (level: string, message: string) => void): Promise<object | null>;
|
|
13
15
|
/**
|
|
16
|
+
* Parses the service data for WoPlugMini JP.
|
|
17
|
+
* @param {Buffer} manufacturerData - The manufacturer data buffer.
|
|
18
|
+
* @param {Function} emitLog - The function to emit log messages.
|
|
19
|
+
* @returns {Promise<object | null>} - Parsed service data or null if invalid.
|
|
20
|
+
*/
|
|
21
|
+
static parseServiceData_JP(manufacturerData: Buffer, emitLog: (level: string, message: string) => void): Promise<object | null>;
|
|
22
|
+
/**
|
|
23
|
+
* Parses the service data for WoPlugMini.
|
|
24
|
+
* @param {Buffer} manufacturerData - The manufacturer data buffer.
|
|
25
|
+
* @param {SwitchBotBLEModel} model - The model of the plug mini.
|
|
26
|
+
* @param {Function} emitLog - The function to emit log messages.
|
|
27
|
+
* @returns {Promise<object | null>} - Parsed service data or null if invalid.
|
|
28
|
+
*/
|
|
29
|
+
private static parseServiceData;
|
|
30
|
+
/**
|
|
31
|
+
* Reads the state of the plug.
|
|
32
|
+
* @returns {Promise<boolean>} - Resolves with a boolean that tells whether the plug is ON (true) or OFF (false).
|
|
33
|
+
*/
|
|
34
|
+
readState(): Promise<boolean>;
|
|
35
|
+
/**
|
|
36
|
+
* Sets the state of the plug.
|
|
14
37
|
* @private
|
|
38
|
+
* @param {number[]} reqByteArray - The request byte array.
|
|
39
|
+
* @returns {Promise<boolean>} - Resolves with a boolean that tells whether the plug is ON (true) or OFF (false).
|
|
40
|
+
*/
|
|
41
|
+
private setState;
|
|
42
|
+
/**
|
|
43
|
+
* Turns on the plug.
|
|
44
|
+
* @returns {Promise<boolean>} - Resolves with a boolean that tells whether the plug is ON (true) or OFF (false).
|
|
15
45
|
*/
|
|
16
|
-
|
|
46
|
+
turnOn(): Promise<boolean>;
|
|
17
47
|
/**
|
|
18
|
-
*
|
|
48
|
+
* Turns off the plug.
|
|
49
|
+
* @returns {Promise<boolean>} - Resolves with a boolean that tells whether the plug is ON (true) or OFF (false).
|
|
19
50
|
*/
|
|
20
|
-
|
|
51
|
+
turnOff(): Promise<boolean>;
|
|
21
52
|
/**
|
|
22
|
-
*
|
|
53
|
+
* Toggles the state of the plug.
|
|
54
|
+
* @returns {Promise<boolean>} - Resolves with a boolean that tells whether the plug is ON (true) or OFF (false).
|
|
23
55
|
*/
|
|
24
|
-
|
|
56
|
+
toggle(): Promise<boolean>;
|
|
25
57
|
/**
|
|
26
|
-
*
|
|
58
|
+
* Operates the plug with the given bytes.
|
|
59
|
+
* @param {number[]} bytes - The byte array to send to the plug.
|
|
60
|
+
* @returns {Promise<boolean>} - Resolves with a boolean that tells whether the plug is ON (true) or OFF (false).
|
|
27
61
|
*/
|
|
28
|
-
|
|
29
|
-
operatePlug(bytes: number[]): Promise<void>;
|
|
62
|
+
operatePlug(bytes: number[]): Promise<boolean>;
|
|
30
63
|
}
|
|
31
64
|
//# sourceMappingURL=woplugmini.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"woplugmini.d.ts","sourceRoot":"","sources":["../../src/device/woplugmini.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"woplugmini.d.ts","sourceRoot":"","sources":["../../src/device/woplugmini.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AAEpC,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAA;AAG9C;;;GAGG;AACH,qBAAa,UAAW,SAAQ,eAAe;IAC7C;;;;;OAKG;WACU,mBAAmB,CAC9B,gBAAgB,EAAE,MAAM,EACxB,OAAO,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,KAAK,IAAI,GAChD,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;IAIzB;;;;;OAKG;WACU,mBAAmB,CAC9B,gBAAgB,EAAE,MAAM,EACxB,OAAO,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,KAAK,IAAI,GAChD,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;IAIzB;;;;;;OAMG;mBACkB,gBAAgB;IAwCrC;;;OAGG;IACG,SAAS,IAAI,OAAO,CAAC,OAAO,CAAC;IAInC;;;;;OAKG;YACW,QAAQ;IAKtB;;;OAGG;IACG,MAAM,IAAI,OAAO,CAAC,OAAO,CAAC;IAIhC;;;OAGG;IACG,OAAO,IAAI,OAAO,CAAC,OAAO,CAAC;IAIjC;;;OAGG;IACG,MAAM,IAAI,OAAO,CAAC,OAAO,CAAC;IAIhC;;;;OAIG;IACU,WAAW,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,OAAO,CAAC;CAgB5D"}
|
|
@@ -1,60 +1,52 @@
|
|
|
1
|
-
import { Buffer } from 'node:buffer';
|
|
2
1
|
/* Copyright(C) 2024, donavanbecker (https://github.com/donavanbecker). All rights reserved.
|
|
3
2
|
*
|
|
4
3
|
* woplugmini.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
8
|
/**
|
|
9
|
+
* Class representing a WoPlugMini device.
|
|
9
10
|
* @see https://github.com/OpenWonderLabs/SwitchBotAPI-BLE/blob/latest/devicetypes/plugmini.md
|
|
10
11
|
*/
|
|
11
12
|
export class WoPlugMini extends SwitchbotDevice {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
const byte10 = manufacturerData.readUInt8(10); // byte10: bit0: 0=no delay,1=delay, bit1:0=no timer, 1=timer; bit2:0=no sync time, 1=sync'ed time
|
|
21
|
-
const byte11 = manufacturerData.readUInt8(11); // byte11: wifi rssi
|
|
22
|
-
const byte12 = manufacturerData.readUInt8(12); // byte12: bit7: overload?
|
|
23
|
-
const byte13 = manufacturerData.readUInt8(13); // byte12[bit0~6] + byte13: current power value
|
|
24
|
-
const state = byte9 === 0x00 ? 'off' : byte9 === 0x80 ? 'on' : null;
|
|
25
|
-
const delay = !!(byte10 & 0b00000001);
|
|
26
|
-
const timer = !!(byte10 & 0b00000010);
|
|
27
|
-
const syncUtcTime = !!(byte10 & 0b00000100);
|
|
28
|
-
const wifiRssi = byte11;
|
|
29
|
-
const overload = !!(byte12 & 0b10000000);
|
|
30
|
-
const currentPower = (((byte12 & 0b01111111) << 8) + byte13) / 10; // in watt
|
|
31
|
-
// TODO: voltage ???
|
|
32
|
-
const data = {
|
|
33
|
-
model: SwitchBotBLEModel.PlugMiniUS,
|
|
34
|
-
modelName: SwitchBotBLEModelName.PlugMini,
|
|
35
|
-
modelFriendlyName: SwitchBotBLEModelFriendlyName.PlugMini,
|
|
36
|
-
state,
|
|
37
|
-
delay,
|
|
38
|
-
timer,
|
|
39
|
-
syncUtcTime,
|
|
40
|
-
wifiRssi,
|
|
41
|
-
overload,
|
|
42
|
-
currentPower,
|
|
43
|
-
};
|
|
44
|
-
return data;
|
|
13
|
+
/**
|
|
14
|
+
* Parses the service data for WoPlugMini US.
|
|
15
|
+
* @param {Buffer} manufacturerData - The manufacturer 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_US(manufacturerData, emitLog) {
|
|
20
|
+
return this.parseServiceData(manufacturerData, SwitchBotBLEModel.PlugMiniUS, emitLog);
|
|
45
21
|
}
|
|
46
|
-
|
|
22
|
+
/**
|
|
23
|
+
* Parses the service data for WoPlugMini JP.
|
|
24
|
+
* @param {Buffer} manufacturerData - The manufacturer data buffer.
|
|
25
|
+
* @param {Function} emitLog - The function to emit log messages.
|
|
26
|
+
* @returns {Promise<object | null>} - Parsed service data or null if invalid.
|
|
27
|
+
*/
|
|
28
|
+
static async parseServiceData_JP(manufacturerData, emitLog) {
|
|
29
|
+
return this.parseServiceData(manufacturerData, SwitchBotBLEModel.PlugMiniJP, emitLog);
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Parses the service data for WoPlugMini.
|
|
33
|
+
* @param {Buffer} manufacturerData - The manufacturer data buffer.
|
|
34
|
+
* @param {SwitchBotBLEModel} model - The model of the plug mini.
|
|
35
|
+
* @param {Function} emitLog - The function to emit log messages.
|
|
36
|
+
* @returns {Promise<object | null>} - Parsed service data or null if invalid.
|
|
37
|
+
*/
|
|
38
|
+
static async parseServiceData(manufacturerData, model, emitLog) {
|
|
47
39
|
if (manufacturerData.length !== 14) {
|
|
48
|
-
|
|
49
|
-
onlog(`[parseServiceDataForWoPlugMiniJP] Buffer length ${manufacturerData.length} should be 14`);
|
|
50
|
-
}
|
|
40
|
+
emitLog('debugerror', `[parseServiceDataForWoPlugMini] Buffer length ${manufacturerData.length} should be 14`);
|
|
51
41
|
return null;
|
|
52
42
|
}
|
|
53
|
-
const byte9
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
43
|
+
const [byte9, byte10, byte11, byte12, byte13] = [
|
|
44
|
+
manufacturerData.readUInt8(9),
|
|
45
|
+
manufacturerData.readUInt8(10),
|
|
46
|
+
manufacturerData.readUInt8(11),
|
|
47
|
+
manufacturerData.readUInt8(12),
|
|
48
|
+
manufacturerData.readUInt8(13),
|
|
49
|
+
];
|
|
58
50
|
const state = byte9 === 0x00 ? 'off' : byte9 === 0x80 ? 'on' : null;
|
|
59
51
|
const delay = !!(byte10 & 0b00000001);
|
|
60
52
|
const timer = !!(byte10 & 0b00000010);
|
|
@@ -62,9 +54,8 @@ export class WoPlugMini extends SwitchbotDevice {
|
|
|
62
54
|
const wifiRssi = byte11;
|
|
63
55
|
const overload = !!(byte12 & 0b10000000);
|
|
64
56
|
const currentPower = (((byte12 & 0b01111111) << 8) + byte13) / 10; // in watt
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
model: SwitchBotBLEModel.PlugMiniJP,
|
|
57
|
+
return {
|
|
58
|
+
model,
|
|
68
59
|
modelName: SwitchBotBLEModelName.PlugMini,
|
|
69
60
|
modelFriendlyName: SwitchBotBLEModelFriendlyName.PlugMini,
|
|
70
61
|
state,
|
|
@@ -75,61 +66,64 @@ export class WoPlugMini extends SwitchbotDevice {
|
|
|
75
66
|
overload,
|
|
76
67
|
currentPower,
|
|
77
68
|
};
|
|
78
|
-
return data;
|
|
79
69
|
}
|
|
80
70
|
/**
|
|
81
|
-
*
|
|
71
|
+
* Reads the state of the plug.
|
|
72
|
+
* @returns {Promise<boolean>} - Resolves with a boolean that tells whether the plug is ON (true) or OFF (false).
|
|
82
73
|
*/
|
|
83
74
|
async readState() {
|
|
84
|
-
return
|
|
75
|
+
return this.operatePlug([0x57, 0x0F, 0x51, 0x01]);
|
|
85
76
|
}
|
|
86
77
|
/**
|
|
78
|
+
* Sets the state of the plug.
|
|
87
79
|
* @private
|
|
80
|
+
* @param {number[]} reqByteArray - The request byte array.
|
|
81
|
+
* @returns {Promise<boolean>} - Resolves with a boolean that tells whether the plug is ON (true) or OFF (false).
|
|
88
82
|
*/
|
|
89
83
|
async setState(reqByteArray) {
|
|
90
84
|
const base = [0x57, 0x0F, 0x50, 0x01];
|
|
91
|
-
return
|
|
85
|
+
return this.operatePlug([...base, ...reqByteArray]);
|
|
92
86
|
}
|
|
93
87
|
/**
|
|
94
|
-
*
|
|
88
|
+
* Turns on the plug.
|
|
89
|
+
* @returns {Promise<boolean>} - Resolves with a boolean that tells whether the plug is ON (true) or OFF (false).
|
|
95
90
|
*/
|
|
96
91
|
async turnOn() {
|
|
97
|
-
return
|
|
92
|
+
return this.setState([0x01, 0x80]);
|
|
98
93
|
}
|
|
99
94
|
/**
|
|
100
|
-
*
|
|
95
|
+
* Turns off the plug.
|
|
96
|
+
* @returns {Promise<boolean>} - Resolves with a boolean that tells whether the plug is ON (true) or OFF (false).
|
|
101
97
|
*/
|
|
102
98
|
async turnOff() {
|
|
103
|
-
return
|
|
99
|
+
return this.setState([0x01, 0x00]);
|
|
104
100
|
}
|
|
105
101
|
/**
|
|
106
|
-
*
|
|
102
|
+
* Toggles the state of the plug.
|
|
103
|
+
* @returns {Promise<boolean>} - Resolves with a boolean that tells whether the plug is ON (true) or OFF (false).
|
|
107
104
|
*/
|
|
108
105
|
async toggle() {
|
|
109
|
-
return
|
|
106
|
+
return this.setState([0x02, 0x80]);
|
|
110
107
|
}
|
|
108
|
+
/**
|
|
109
|
+
* Operates the plug with the given bytes.
|
|
110
|
+
* @param {number[]} bytes - The byte array to send to the plug.
|
|
111
|
+
* @returns {Promise<boolean>} - Resolves with a boolean that tells whether the plug is ON (true) or OFF (false).
|
|
112
|
+
*/
|
|
111
113
|
async operatePlug(bytes) {
|
|
112
|
-
const
|
|
113
|
-
await this.command(
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
}
|
|
126
|
-
else {
|
|
127
|
-
throw new Error(`Expecting a 2-byte response, got instead: 0x${res_buf.toString('hex')}`);
|
|
128
|
-
}
|
|
129
|
-
})
|
|
130
|
-
.catch((error) => {
|
|
131
|
-
throw error;
|
|
132
|
-
});
|
|
114
|
+
const reqBuf = Buffer.from(bytes);
|
|
115
|
+
const resBytes = await this.command(reqBuf);
|
|
116
|
+
const resBuf = Buffer.from(resBytes);
|
|
117
|
+
if (resBuf.length !== 2) {
|
|
118
|
+
throw new Error(`Expecting a 2-byte response, got instead: 0x${resBuf.toString('hex')}`);
|
|
119
|
+
}
|
|
120
|
+
const code = resBuf.readUInt8(1);
|
|
121
|
+
if (code === 0x00 || code === 0x80) {
|
|
122
|
+
return code === 0x80;
|
|
123
|
+
}
|
|
124
|
+
else {
|
|
125
|
+
throw new Error(`The device returned an error: 0x${resBuf.toString('hex')}`);
|
|
126
|
+
}
|
|
133
127
|
}
|
|
134
128
|
}
|
|
135
129
|
//# sourceMappingURL=woplugmini.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"woplugmini.js","sourceRoot":"","sources":["../../src/device/woplugmini.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AAEpC
|
|
1
|
+
{"version":3,"file":"woplugmini.js","sourceRoot":"","sources":["../../src/device/woplugmini.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,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,UAAW,SAAQ,eAAe;IAC7C;;;;;OAKG;IACH,MAAM,CAAC,KAAK,CAAC,mBAAmB,CAC9B,gBAAwB,EACxB,OAAiD;QAEjD,OAAO,IAAI,CAAC,gBAAgB,CAAC,gBAAgB,EAAE,iBAAiB,CAAC,UAAU,EAAE,OAAO,CAAC,CAAA;IACvF,CAAC;IAED;;;;;OAKG;IACH,MAAM,C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