node-switchbot 2.5.0-beta.3 → 2.5.0-beta.31
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 +1109 -0
- package/CHANGELOG.md +14 -0
- package/OpenAPI.md +172 -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 +32 -21
- package/dist/advertising.d.ts.map +1 -1
- package/dist/advertising.js +72 -76
- package/dist/advertising.js.map +1 -1
- package/dist/device/woblindtilt.d.ts +21 -51
- package/dist/device/woblindtilt.d.ts.map +1 -1
- package/dist/device/woblindtilt.js +40 -103
- package/dist/device/woblindtilt.js.map +1 -1
- package/dist/device/wobulb.d.ts +42 -15
- package/dist/device/wobulb.d.ts.map +1 -1
- package/dist/device/wobulb.js +71 -131
- 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 +94 -174
- package/dist/device/woceilinglight.js.map +1 -1
- package/dist/device/wocontact.d.ts +12 -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 +40 -1
- package/dist/device/wocurtain.d.ts.map +1 -1
- package/dist/device/wocurtain.js +68 -106
- package/dist/device/wocurtain.js.map +1 -1
- package/dist/device/wohand.d.ts +38 -2
- package/dist/device/wohand.d.ts.map +1 -1
- package/dist/device/wohand.js +54 -92
- package/dist/device/wohand.js.map +1 -1
- package/dist/device/wohub2.d.ts +12 -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 +38 -2
- package/dist/device/wohumi.d.ts.map +1 -1
- package/dist/device/wohumi.js +51 -86
- package/dist/device/wohumi.js.map +1 -1
- package/dist/device/woiosensorth.d.ts +13 -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 +44 -12
- package/dist/device/woplugmini.d.ts.map +1 -1
- package/dist/device/woplugmini.js +68 -80
- package/dist/device/woplugmini.js.map +1 -1
- package/dist/device/wopresence.d.ts +12 -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 +33 -50
- package/dist/device/wosensorth.js.map +1 -1
- package/dist/device/wosmartlock.d.ts +58 -13
- package/dist/device/wosmartlock.d.ts.map +1 -1
- package/dist/device/wosmartlock.js +108 -195
- package/dist/device/wosmartlock.js.map +1 -1
- package/dist/device/wosmartlockpro.d.ts +63 -18
- package/dist/device/wosmartlockpro.d.ts.map +1 -1
- package/dist/device/wosmartlockpro.js +116 -204
- package/dist/device/wosmartlockpro.js.map +1 -1
- package/dist/device/wostrip.d.ts +38 -18
- package/dist/device/wostrip.d.ts.map +1 -1
- package/dist/device/wostrip.js +79 -125
- package/dist/device/wostrip.js.map +1 -1
- package/dist/device.d.ts +85 -222
- package/dist/device.d.ts.map +1 -1
- package/dist/device.js +123 -407
- 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 +79 -19
- package/dist/parameter-checker.d.ts.map +1 -1
- package/dist/parameter-checker.js +140 -335
- package/dist/parameter-checker.js.map +1 -1
- package/dist/settings.d.ts +46 -0
- package/dist/settings.d.ts.map +1 -1
- package/dist/settings.js +46 -2
- package/dist/settings.js.map +1 -1
- package/dist/{switchbot.d.ts → switchbot-ble.d.ts} +14 -8
- package/dist/switchbot-ble.d.ts.map +1 -0
- package/dist/switchbot-ble.js +428 -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 +96 -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.d.ts.map +1 -0
- package/dist/test/woblindtilt.test.js +2 -0
- package/dist/test/woblindtilt.test.js.map +1 -0
- package/dist/{device → test}/wobulb.test.d.ts.map +1 -1
- package/dist/test/wobulb.test.js +2 -0
- package/dist/test/wobulb.test.js.map +1 -0
- package/dist/test/woceilinglight.test.d.ts.map +1 -0
- package/dist/test/woceilinglight.test.js +2 -0
- package/dist/test/woceilinglight.test.js.map +1 -0
- package/dist/test/wocontact.test.d.ts.map +1 -0
- package/dist/test/wocontact.test.js +2 -0
- package/dist/test/wocontact.test.js.map +1 -0
- package/dist/test/wocurtain.test.d.ts.map +1 -0
- package/dist/test/wocurtain.test.js +2 -0
- package/dist/test/wocurtain.test.js.map +1 -0
- package/dist/{device → test}/wohand.test.d.ts.map +1 -1
- package/dist/test/wohand.test.js +2 -0
- package/dist/test/wohand.test.js.map +1 -0
- 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 +2 -0
- package/dist/test/wohub2.test.js.map +1 -0
- package/dist/{device → test}/wohumi.test.d.ts.map +1 -1
- package/dist/test/wohumi.test.js +2 -0
- package/dist/test/wohumi.test.js.map +1 -0
- package/dist/test/woiosensorth.test.d.ts.map +1 -0
- package/dist/test/woiosensorth.test.js +2 -0
- package/dist/test/woiosensorth.test.js.map +1 -0
- package/dist/test/woplugmini.test.d.ts.map +1 -0
- package/dist/test/woplugmini.test.js +2 -0
- package/dist/test/woplugmini.test.js.map +1 -0
- package/dist/test/wopresence.test.d.ts.map +1 -0
- package/dist/test/wopresence.test.js +2 -0
- package/dist/test/wopresence.test.js.map +1 -0
- package/dist/test/wosensorth.test.d.ts.map +1 -0
- package/dist/test/wosensorth.test.js +2 -0
- package/dist/test/wosensorth.test.js.map +1 -0
- package/dist/test/wosmartlock.test.d.ts.map +1 -0
- package/dist/test/wosmartlock.test.js +2 -0
- package/dist/test/wosmartlock.test.js.map +1 -0
- package/dist/test/wosmartlockpro.test.d.ts.map +1 -0
- package/dist/test/wosmartlockpro.test.js +2 -0
- package/dist/test/wosmartlockpro.test.js.map +1 -0
- package/dist/{device → test}/wostrip.test.d.ts.map +1 -1
- package/dist/test/wostrip.test.js +2 -0
- package/dist/test/wostrip.test.js.map +1 -0
- 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 +61 -120
- package/dist/types/types.d.ts.map +1 -1
- package/dist/types/types.js +10 -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 +61 -0
- package/docs/classes/SwitchBotOpenAPI.html +47 -0
- package/docs/classes/SwitchbotDevice.html +28 -33
- package/docs/enums/LogLevel.html +6 -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 +172 -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 +12 -10
- package/dist/device/woblindtilt.test.d.ts.map +0 -1
- package/dist/device/woblindtilt.test.js +0 -26
- package/dist/device/woblindtilt.test.js.map +0 -1
- package/dist/device/wobulb.test.js +0 -52
- package/dist/device/wobulb.test.js.map +0 -1
- package/dist/device/woceilinglight.test.d.ts.map +0 -1
- package/dist/device/woceilinglight.test.js +0 -63
- package/dist/device/woceilinglight.test.js.map +0 -1
- package/dist/device/wocontact.test.d.ts.map +0 -1
- package/dist/device/wocontact.test.js +0 -34
- package/dist/device/wocontact.test.js.map +0 -1
- package/dist/device/wocurtain.test.d.ts.map +0 -1
- package/dist/device/wocurtain.test.js +0 -33
- package/dist/device/wocurtain.test.js.map +0 -1
- package/dist/device/wohand.test.js +0 -62
- package/dist/device/wohand.test.js.map +0 -1
- package/dist/device/wohand2.test.d.ts +0 -2
- package/dist/device/wohand2.test.d.ts.map +0 -1
- package/dist/device/wohand2.test.js +0 -50
- package/dist/device/wohand2.test.js.map +0 -1
- package/dist/device/wohumi.test.js +0 -61
- package/dist/device/wohumi.test.js.map +0 -1
- package/dist/device/woiosensorth.test.d.ts.map +0 -1
- package/dist/device/woiosensorth.test.js +0 -39
- package/dist/device/woiosensorth.test.js.map +0 -1
- package/dist/device/woplugmini.test.d.ts.map +0 -1
- package/dist/device/woplugmini.test.js +0 -91
- package/dist/device/woplugmini.test.js.map +0 -1
- package/dist/device/wopresence.test.d.ts.map +0 -1
- package/dist/device/wopresence.test.js +0 -42
- package/dist/device/wopresence.test.js.map +0 -1
- package/dist/device/wosensorth.test.d.ts.map +0 -1
- package/dist/device/wosensorth.test.js +0 -59
- package/dist/device/wosensorth.test.js.map +0 -1
- package/dist/device/wosmartlock.test.d.ts.map +0 -1
- package/dist/device/wosmartlock.test.js +0 -84
- package/dist/device/wosmartlock.test.js.map +0 -1
- package/dist/device/wosmartlockpro.test.d.ts.map +0 -1
- package/dist/device/wosmartlockpro.test.js +0 -124
- package/dist/device/wosmartlockpro.test.js.map +0 -1
- package/dist/device/wostrip.test.js +0 -115
- package/dist/device/wostrip.test.js.map +0 -1
- package/dist/switchbot.d.ts.map +0 -1
- package/dist/switchbot.js +0 -259
- package/dist/switchbot.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 → test}/woblindtilt.test.d.ts +0 -0
- /package/dist/{device → test}/wobulb.test.d.ts +0 -0
- /package/dist/{device → test}/woceilinglight.test.d.ts +0 -0
- /package/dist/{device → test}/wocontact.test.d.ts +0 -0
- /package/dist/{device → test}/wocurtain.test.d.ts +0 -0
- /package/dist/{device → test}/wohand.test.d.ts +0 -0
- /package/dist/{device → test}/wohumi.test.d.ts +0 -0
- /package/dist/{device → test}/woiosensorth.test.d.ts +0 -0
- /package/dist/{device → test}/woplugmini.test.d.ts +0 -0
- /package/dist/{device → test}/wopresence.test.d.ts +0 -0
- /package/dist/{device → test}/wosensorth.test.d.ts +0 -0
- /package/dist/{device → test}/wosmartlock.test.d.ts +0 -0
- /package/dist/{device → test}/wosmartlockpro.test.d.ts +0 -0
- /package/dist/{device → test}/wostrip.test.d.ts +0 -0
|
@@ -1,130 +1,102 @@
|
|
|
1
1
|
import { Buffer } from 'node:buffer';
|
|
2
|
-
/* Copyright(C) 2024, donavanbecker (https://github.com/donavanbecker). All rights reserved.
|
|
3
|
-
*
|
|
4
|
-
* woblindtilt.ts: Switchbot BLE API registration.
|
|
5
|
-
*/
|
|
6
2
|
import { SwitchbotDevice } from '../device.js';
|
|
7
3
|
import { SwitchBotBLEModel, SwitchBotBLEModelFriendlyName, SwitchBotBLEModelName } from '../types/types.js';
|
|
4
|
+
/**
|
|
5
|
+
* Class representing a WoBlindTilt device.
|
|
6
|
+
* @see https://github.com/OpenWonderLabs/SwitchBotAPI-BLE/blob/latest/devicetypes/curtain.md
|
|
7
|
+
*/
|
|
8
8
|
export class WoBlindTilt extends SwitchbotDevice {
|
|
9
9
|
_reverse = false;
|
|
10
|
+
static switchBotBLE;
|
|
10
11
|
/**
|
|
11
12
|
* Parses the service data and manufacturer data for the WoBlindTilt device.
|
|
12
|
-
*
|
|
13
13
|
* @param {Buffer} serviceData - The service data buffer.
|
|
14
14
|
* @param {Buffer} manufacturerData - The manufacturer data buffer.
|
|
15
|
-
* @param {(message: string) => void} [onlog] - Optional logging function.
|
|
16
15
|
* @param {boolean} [reverse] - Whether to reverse the tilt percentage.
|
|
17
|
-
* @returns {object | null} The parsed data object or null if the data is invalid.
|
|
16
|
+
* @returns {Promise<object | null>} - The parsed data object or null if the data is invalid.
|
|
18
17
|
*/
|
|
19
|
-
static async parseServiceData(serviceData, manufacturerData,
|
|
20
|
-
if (
|
|
21
|
-
|
|
22
|
-
onlog(`[parseServiceDataForWoBlindTilt] Buffer length ${manufacturerData.length} !== 5 or 6!`);
|
|
23
|
-
}
|
|
18
|
+
static async parseServiceData(serviceData, manufacturerData, reverse = false) {
|
|
19
|
+
if (![5, 6].includes(manufacturerData.length)) {
|
|
20
|
+
this.switchBotBLE.emitLog('error', `[parseServiceDataForWoBlindTilt] Buffer length ${manufacturerData.length} !== 5 or 6!`);
|
|
24
21
|
return null;
|
|
25
22
|
}
|
|
26
|
-
// const byte1 = serviceData.readUInt8(1)
|
|
27
23
|
const byte2 = serviceData.readUInt8(2);
|
|
28
24
|
const byte6 = manufacturerData.subarray(6);
|
|
29
|
-
const tilt = Math.max(Math.min(byte6.readUInt8(2) & 0b01111111, 100), 0);
|
|
25
|
+
const tilt = Math.max(Math.min(byte6.readUInt8(2) & 0b01111111, 100), 0);
|
|
30
26
|
const inMotion = !!(byte2 & 0b10000000);
|
|
31
|
-
const lightLevel = (byte6.readUInt8(1) >> 4) & 0b00001111;
|
|
32
|
-
const calibration = !!(byte6.readUInt8(1) & 0b00000001);
|
|
27
|
+
const lightLevel = (byte6.readUInt8(1) >> 4) & 0b00001111;
|
|
28
|
+
const calibration = !!(byte6.readUInt8(1) & 0b00000001);
|
|
33
29
|
const sequenceNumber = byte6.readUInt8(0);
|
|
34
30
|
const battery = serviceData.length > 2 ? byte2 & 0b01111111 : null;
|
|
35
|
-
|
|
31
|
+
return {
|
|
36
32
|
model: SwitchBotBLEModel.BlindTilt,
|
|
37
33
|
modelName: SwitchBotBLEModelName.BlindTilt,
|
|
38
34
|
modelFriendlyName: SwitchBotBLEModelFriendlyName.BlindTilt,
|
|
39
35
|
calibration,
|
|
40
36
|
battery,
|
|
41
37
|
inMotion,
|
|
42
|
-
tilt: reverse ?
|
|
38
|
+
tilt: reverse ? 100 - tilt : tilt,
|
|
43
39
|
lightLevel,
|
|
44
40
|
sequenceNumber,
|
|
45
41
|
};
|
|
46
|
-
return data;
|
|
47
42
|
}
|
|
48
43
|
/**
|
|
49
|
-
* open
|
|
50
|
-
*
|
|
51
44
|
* Opens the blind tilt to the fully open position.
|
|
52
|
-
*
|
|
53
|
-
* @returns {Promise<void>} - A promise that resolves when the operation is complete. Nothing will be passed to the `resolve()`.
|
|
45
|
+
* @returns {Promise<void>}
|
|
54
46
|
*/
|
|
55
47
|
async open() {
|
|
56
|
-
|
|
48
|
+
await this.operateBlindTilt([0x57, 0x0F, 0x45, 0x01, 0x05, 0xFF, 0x32]);
|
|
57
49
|
}
|
|
58
50
|
/**
|
|
59
|
-
* closeUp
|
|
60
|
-
*
|
|
61
51
|
* Closes the blind tilt up to the nearest endpoint.
|
|
62
|
-
*
|
|
63
|
-
* @returns {Promise<void>} - A promise that resolves when the operation is complete. Nothing will be passed to the `resolve()`.
|
|
52
|
+
* @returns {Promise<void>}
|
|
64
53
|
*/
|
|
65
54
|
async closeUp() {
|
|
66
|
-
|
|
55
|
+
await this.operateBlindTilt([0x57, 0x0F, 0x45, 0x01, 0x05, 0xFF, 0x64]);
|
|
67
56
|
}
|
|
68
57
|
/**
|
|
69
|
-
* closeDown
|
|
70
|
-
*
|
|
71
58
|
* Closes the blind tilt down to the nearest endpoint.
|
|
72
|
-
*
|
|
73
|
-
* @returns {Promise<void>} - A promise that resolves when the operation is complete. Nothing will be passed to the `resolve()`.
|
|
59
|
+
* @returns {Promise<void>}
|
|
74
60
|
*/
|
|
75
61
|
async closeDown() {
|
|
76
|
-
|
|
62
|
+
await this.operateBlindTilt([0x57, 0x0F, 0x45, 0x01, 0x05, 0xFF, 0x00]);
|
|
77
63
|
}
|
|
78
64
|
/**
|
|
79
|
-
* close
|
|
80
|
-
*
|
|
81
65
|
* Closes the blind tilt to the nearest endpoint.
|
|
82
|
-
*
|
|
83
|
-
* @returns {Promise<void>} - A promise that resolves when the operation is complete. Nothing will be passed to the `resolve()`.
|
|
66
|
+
* @returns {Promise<void>}
|
|
84
67
|
*/
|
|
85
68
|
async close() {
|
|
86
69
|
const position = await this.getPosition();
|
|
87
70
|
if (position > 50) {
|
|
88
|
-
|
|
71
|
+
await this.closeUp();
|
|
89
72
|
}
|
|
90
73
|
else {
|
|
91
|
-
|
|
74
|
+
await this.closeDown();
|
|
92
75
|
}
|
|
93
76
|
}
|
|
94
77
|
/**
|
|
95
|
-
* getPosition
|
|
96
|
-
*
|
|
97
78
|
* Retrieves the current position of the blind tilt.
|
|
98
|
-
*
|
|
99
|
-
* @returns {number} - The current position of the blind tilt (0-100).
|
|
79
|
+
* @returns {Promise<number>} - The current position of the blind tilt (0-100).
|
|
100
80
|
*/
|
|
101
81
|
async getPosition() {
|
|
102
|
-
// Retrieve the current tilt position using the _getAdvValue method
|
|
103
82
|
const tiltPosition = await this._getAdvValue('tilt');
|
|
104
|
-
// Ensure the tilt position is within the valid range (0-100)
|
|
105
83
|
return Math.max(0, Math.min(tiltPosition, 100));
|
|
106
84
|
}
|
|
107
85
|
/**
|
|
108
|
-
* _getAdvValue
|
|
109
|
-
*
|
|
110
86
|
* Retrieves the advertised value for a given key.
|
|
111
|
-
*
|
|
112
87
|
* @param {string} key - The key for the advertised value.
|
|
113
88
|
* @returns {Promise<number>} - The advertised value.
|
|
89
|
+
* @private
|
|
114
90
|
*/
|
|
115
91
|
async _getAdvValue(key) {
|
|
116
|
-
// Mock implementation, replace with actual logic to retrieve the advertised value
|
|
117
92
|
if (key === 'tilt') {
|
|
118
93
|
return 50; // Example value
|
|
119
94
|
}
|
|
120
95
|
throw new Error(`Unknown key: ${key}`);
|
|
121
96
|
}
|
|
122
97
|
/**
|
|
123
|
-
* getBasicInfo
|
|
124
|
-
*
|
|
125
98
|
* Retrieves the basic information of the blind tilt.
|
|
126
|
-
*
|
|
127
|
-
* @returns {Promise<object>} - A promise that resolves to an object containing the basic information of the blind tilt.
|
|
99
|
+
* @returns {Promise<object | null>} - A promise that resolves to an object containing the basic information of the blind tilt.
|
|
128
100
|
*/
|
|
129
101
|
async getBasicInfo() {
|
|
130
102
|
const data = await this.getBasicInfo();
|
|
@@ -168,73 +140,38 @@ export class WoBlindTilt extends SwitchbotDevice {
|
|
|
168
140
|
}
|
|
169
141
|
/**
|
|
170
142
|
* Pauses the blind tilt operation.
|
|
171
|
-
*
|
|
172
|
-
* This method sends a command to pause the current operation of the blind tilt.
|
|
173
|
-
*
|
|
174
|
-
* @returns {Promise<void>} A promise that resolves when the operation is complete.
|
|
175
|
-
* No value is passed to the `resolve()` function.
|
|
143
|
+
* @returns {Promise<void>}
|
|
176
144
|
*/
|
|
177
145
|
async pause() {
|
|
178
146
|
await this.operateBlindTilt([0x57, 0x0F, 0x45, 0x01, 0x00, 0xFF]);
|
|
179
147
|
}
|
|
180
148
|
/**
|
|
181
|
-
*
|
|
182
|
-
*
|
|
183
|
-
* This method sends a command to run the blind tilt to the specified position.
|
|
184
|
-
*
|
|
149
|
+
* Runs the blind tilt to the specified position.
|
|
185
150
|
* @param {number} percent - The target position percentage (0-100).
|
|
186
151
|
* @param {number} mode - The running mode (0 or 1).
|
|
187
|
-
* @returns {Promise<void>}
|
|
152
|
+
* @returns {Promise<void>}
|
|
188
153
|
*/
|
|
189
154
|
async runToPos(percent, mode) {
|
|
190
|
-
if (typeof percent !== 'number') {
|
|
191
|
-
throw new
|
|
192
|
-
}
|
|
193
|
-
if (mode === null) {
|
|
194
|
-
mode = 0xFF;
|
|
195
|
-
}
|
|
196
|
-
else {
|
|
197
|
-
if (typeof mode !== 'number') {
|
|
198
|
-
throw new TypeError(`The type of running mode is incorrect: ${typeof mode}`);
|
|
199
|
-
}
|
|
200
|
-
if (mode > 1) {
|
|
201
|
-
mode = 0xFF;
|
|
202
|
-
}
|
|
155
|
+
if (typeof percent !== 'number' || percent < 0 || percent > 100) {
|
|
156
|
+
throw new RangeError('Percent must be a number between 0 and 100');
|
|
203
157
|
}
|
|
204
|
-
if (
|
|
205
|
-
|
|
206
|
-
}
|
|
207
|
-
else if (percent < 0) {
|
|
208
|
-
percent = 0;
|
|
158
|
+
if (typeof mode !== 'number' || mode < 0 || mode > 1) {
|
|
159
|
+
throw new RangeError('Mode must be a number between 0 and 1');
|
|
209
160
|
}
|
|
210
161
|
await this.operateBlindTilt([0x57, 0x0F, 0x45, 0x01, 0x05, mode, percent]);
|
|
211
162
|
}
|
|
212
163
|
/**
|
|
213
164
|
* Sends a command to operate the blind tilt and handles the response.
|
|
214
|
-
*
|
|
215
|
-
* This method constructs a buffer from the provided byte array and sends it as a command to the device.
|
|
216
|
-
* It returns a promise that resolves if the device responds with a success code (0x01) and rejects if the device
|
|
217
|
-
* returns an error or if the command fails.
|
|
218
|
-
*
|
|
219
165
|
* @param {number[]} bytes - The byte array representing the command to be sent to the device.
|
|
220
|
-
* @returns {Promise<void>}
|
|
221
|
-
*
|
|
222
|
-
*
|
|
223
|
-
* @throws {Error} Throws an error if the device returns an error code or if the command fails.
|
|
166
|
+
* @returns {Promise<void>}
|
|
167
|
+
* @private
|
|
224
168
|
*/
|
|
225
169
|
async operateBlindTilt(bytes) {
|
|
226
|
-
const
|
|
227
|
-
this.command(
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
}
|
|
232
|
-
else {
|
|
233
|
-
throw new Error(`The device returned an error: 0x${res_buf.toString('hex')}`);
|
|
234
|
-
}
|
|
235
|
-
}).catch((error) => {
|
|
236
|
-
throw error;
|
|
237
|
-
});
|
|
170
|
+
const reqBuf = Buffer.from(bytes);
|
|
171
|
+
const resBuf = await this.command(reqBuf);
|
|
172
|
+
if (resBuf.length !== 3 || resBuf.readUInt8(0) !== 0x01) {
|
|
173
|
+
throw new Error(`The device returned an error: 0x${resBuf.toString('hex')}`);
|
|
174
|
+
}
|
|
238
175
|
}
|
|
239
176
|
}
|
|
240
177
|
//# sourceMappingURL=woblindtilt.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"woblindtilt.js","sourceRoot":"","sources":["../../src/device/woblindtilt.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"woblindtilt.js","sourceRoot":"","sources":["../../src/device/woblindtilt.ts"],"names":[],"mappings":"AAMA,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,WAAY,SAAQ,eAAe;IACtC,QAAQ,GAAY,KAAK,CAAA;IACjC,MAAM,CAAC,YAAY,CAAc;IAEjC;;;;;;OAMG;IACH,MAAM,CAAC,KAAK,CAAC,gBAAgB,CAC3B,WAAmB,EACnB,gBAAwB,EACxB,UAAmB,KAAK;QAExB,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,gBAAgB,CAAC,MAAM,CAAC,EAAE,CAAC;YAC9C,IAAI,CAAC,YAAY,CAAC,OAAO,CAAC,OAAO,EAAE,kDAAkD,gBAAgB,CAAC,MAAM,cAAc,CAAC,CAAA;YAC3H,OAAO,IAAI,CAAA;QACb,CAAC;Q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OAAO,CAAC,CAAC,CAAA;IAC5E,CAAC;IAED;;;;;OAKG;IACK,KAAK,CAAC,gBAAgB,CAAC,KAAe;QAC5C,MAAM,MAAM,GAAG,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;QACjC,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,CAAA;QACzC,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC,IAAI,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC,KAAK,IAAI,EAAE,CAAC;YACxD,MAAM,IAAI,KAAK,CAAC,mCAAmC,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC,CAAA;QAC9E,CAAC;IACH,CAAC;CACF"}
|
package/dist/device/wobulb.d.ts
CHANGED
|
@@ -1,41 +1,68 @@
|
|
|
1
|
+
import type { SwitchBotBLE } from '../switchbot-ble.js';
|
|
1
2
|
import { Buffer } from 'node:buffer';
|
|
2
3
|
import { SwitchbotDevice } from '../device.js';
|
|
3
4
|
/**
|
|
5
|
+
* Class representing a WoBulb device.
|
|
4
6
|
* @see https://github.com/OpenWonderLabs/SwitchBotAPI-BLE/blob/latest/devicetypes/colorbulb.md
|
|
5
7
|
*/
|
|
6
8
|
export declare class WoBulb extends SwitchbotDevice {
|
|
7
|
-
static
|
|
9
|
+
static switchBotBLE: SwitchBotBLE;
|
|
8
10
|
/**
|
|
9
|
-
*
|
|
11
|
+
* Parses the service data for WoBulb.
|
|
12
|
+
* @param {Buffer} serviceData - The service data buffer.
|
|
13
|
+
* @param {Buffer} manufacturerData - The manufacturer data buffer.
|
|
14
|
+
* @returns {Promise<object | null>} - Parsed service data or null if invalid.
|
|
10
15
|
*/
|
|
11
|
-
|
|
16
|
+
static parseServiceData(serviceData: Buffer, manufacturerData: Buffer): Promise<object | null>;
|
|
12
17
|
/**
|
|
18
|
+
* Reads the state of the bulb.
|
|
19
|
+
* @returns {Promise<boolean>} - Resolves with a boolean indicating whether the bulb is ON (true) or OFF (false).
|
|
20
|
+
*/
|
|
21
|
+
readState(): Promise<boolean>;
|
|
22
|
+
/**
|
|
23
|
+
* Sets the state of the bulb.
|
|
24
|
+
* @param {number[]} reqByteArray - The request byte array.
|
|
25
|
+
* @returns {Promise<boolean>} - Resolves with a boolean indicating whether the operation was successful.
|
|
13
26
|
* @private
|
|
14
27
|
*/
|
|
15
|
-
setState(reqByteArray: number[]): Promise<
|
|
28
|
+
setState(reqByteArray: number[]): Promise<boolean>;
|
|
16
29
|
/**
|
|
17
|
-
*
|
|
30
|
+
* Turns on the bulb.
|
|
31
|
+
* @returns {Promise<boolean>} - Resolves with a boolean indicating whether the bulb is ON (true).
|
|
18
32
|
*/
|
|
19
|
-
turnOn(): Promise<
|
|
33
|
+
turnOn(): Promise<boolean>;
|
|
20
34
|
/**
|
|
21
|
-
*
|
|
35
|
+
* Turns off the bulb.
|
|
36
|
+
* @returns {Promise<boolean>} - Resolves with a boolean indicating whether the bulb is OFF (false).
|
|
22
37
|
*/
|
|
23
|
-
turnOff(): Promise<
|
|
38
|
+
turnOff(): Promise<boolean>;
|
|
24
39
|
/**
|
|
25
|
-
*
|
|
40
|
+
* Sets the brightness of the bulb.
|
|
41
|
+
* @param {number} brightness - The brightness percentage (0-100).
|
|
42
|
+
* @returns {Promise<boolean>} - Resolves with a boolean indicating whether the operation was successful.
|
|
26
43
|
*/
|
|
27
|
-
setBrightness(brightness: number): Promise<
|
|
44
|
+
setBrightness(brightness: number): Promise<boolean>;
|
|
28
45
|
/**
|
|
29
|
-
*
|
|
46
|
+
* Sets the color temperature of the bulb.
|
|
47
|
+
* @param {number} color_temperature - The color temperature percentage (0-100).
|
|
48
|
+
* @returns {Promise<boolean>} - Resolves with a boolean indicating whether the operation was successful.
|
|
30
49
|
*/
|
|
31
|
-
setColorTemperature(color_temperature: number): Promise<
|
|
50
|
+
setColorTemperature(color_temperature: number): Promise<boolean>;
|
|
32
51
|
/**
|
|
33
|
-
*
|
|
52
|
+
* Sets the RGB color of the bulb.
|
|
53
|
+
* @param {number} brightness - The brightness percentage (0-100).
|
|
54
|
+
* @param {number} red - The red color value (0-255).
|
|
55
|
+
* @param {number} green - The green color value (0-255).
|
|
56
|
+
* @param {number} blue - The blue color value (0-255).
|
|
57
|
+
* @returns {Promise<boolean>} - Resolves with a boolean indicating whether the operation was successful.
|
|
34
58
|
*/
|
|
35
|
-
setRGB(brightness: number, red: number, green: number, blue: number): Promise<
|
|
59
|
+
setRGB(brightness: number, red: number, green: number, blue: number): Promise<boolean>;
|
|
36
60
|
/**
|
|
61
|
+
* Sends a command to the bulb.
|
|
62
|
+
* @param {number[]} bytes - The command bytes.
|
|
63
|
+
* @returns {Promise<boolean>} - Resolves with a boolean indicating whether the operation was successful.
|
|
37
64
|
* @private
|
|
38
65
|
*/
|
|
39
|
-
operateBulb
|
|
66
|
+
private operateBulb;
|
|
40
67
|
}
|
|
41
68
|
//# sourceMappingURL=wobulb.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wobulb.d.ts","sourceRoot":"","sources":["../../src/device/wobulb.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"wobulb.d.ts","sourceRoot":"","sources":["../../src/device/wobulb.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAA;AAEvD,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AAEpC,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAA;AAG9C;;;GAGG;AACH,qBAAa,MAAO,SAAQ,eAAe;IACzC,MAAM,CAAC,YAAY,EAAE,YAAY,CAAA;IACjC;;;;;OAKG;WACU,gBAAgB,CAC3B,WAAW,EAAE,MAAM,EACnB,gBAAgB,EAAE,MAAM,GACvB,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;IAyCzB;;;OAGG;IACG,SAAS,IAAI,OAAO,CAAC,OAAO,CAAC;IAInC;;;;;OAKG;IACU,QAAQ,CAAC,YAAY,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,OAAO,CAAC;IAK/D;;;OAGG;IACG,MAAM,IAAI,OAAO,CAAC,OAAO,CAAC;IAIhC;;;OAGG;IACG,OAAO,IAAI,OAAO,CAAC,OAAO,CAAC;IAIjC;;;;OAIG;IACG,aAAa,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAOzD;;;;OAIG;IACG,mBAAmB,CAAC,iBAAiB,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAOtE;;;;;;;OAOG;IACG,MAAM,CAAC,UAAU,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAO5F;;;;;OAKG;YACW,WAAW;CAY1B"}
|
package/dist/device/wobulb.js
CHANGED
|
@@ -1,190 +1,130 @@
|
|
|
1
1
|
import { Buffer } from 'node:buffer';
|
|
2
|
-
/* Copyright(C) 2024, donavanbecker (https://github.com/donavanbecker). All rights reserved.
|
|
3
|
-
*
|
|
4
|
-
* wobulb.ts: Switchbot BLE API registration.
|
|
5
|
-
*/
|
|
6
2
|
import { SwitchbotDevice } from '../device.js';
|
|
7
3
|
import { SwitchBotBLEModel, SwitchBotBLEModelFriendlyName, SwitchBotBLEModelName } from '../types/types.js';
|
|
8
4
|
/**
|
|
5
|
+
* Class representing a WoBulb device.
|
|
9
6
|
* @see https://github.com/OpenWonderLabs/SwitchBotAPI-BLE/blob/latest/devicetypes/colorbulb.md
|
|
10
7
|
*/
|
|
11
8
|
export class WoBulb extends SwitchbotDevice {
|
|
12
|
-
static
|
|
9
|
+
static switchBotBLE;
|
|
10
|
+
/**
|
|
11
|
+
* Parses the service data for WoBulb.
|
|
12
|
+
* @param {Buffer} serviceData - The service data buffer.
|
|
13
|
+
* @param {Buffer} manufacturerData - The manufacturer data buffer.
|
|
14
|
+
* @returns {Promise<object | null>} - Parsed service data or null if invalid.
|
|
15
|
+
*/
|
|
16
|
+
static async parseServiceData(serviceData, manufacturerData) {
|
|
13
17
|
if (serviceData.length !== 18) {
|
|
14
|
-
|
|
15
|
-
onlog(`[parseServiceDataForWoBulb] Buffer length ${serviceData.length} !== 18!`);
|
|
16
|
-
}
|
|
18
|
+
this.switchBotBLE.emitLog('error', `[parseServiceDataForWoBulb] Buffer length ${serviceData.length} !== 18!`);
|
|
17
19
|
return null;
|
|
18
20
|
}
|
|
19
21
|
if (manufacturerData.length !== 13) {
|
|
20
|
-
|
|
21
|
-
onlog(`[parseServiceDataForWoBulb] Buffer length ${manufacturerData.length} !== 13!`);
|
|
22
|
-
}
|
|
22
|
+
this.switchBotBLE.emitLog('error', `[parseServiceDataForWoBulb] Buffer length ${manufacturerData.length} !== 13!`);
|
|
23
23
|
return null;
|
|
24
24
|
}
|
|
25
|
-
const byte1
|
|
26
|
-
|
|
27
|
-
const byte3 = manufacturerData.readUInt8(3); // bulb R
|
|
28
|
-
const byte4 = manufacturerData.readUInt8(4); // bulb G
|
|
29
|
-
const byte5 = manufacturerData.readUInt8(5); // bulb B
|
|
30
|
-
const byte6 = manufacturerData.readUInt8(6); // bulb temperature
|
|
31
|
-
const byte7 = manufacturerData.readUInt8(7);
|
|
32
|
-
const byte8 = manufacturerData.readUInt8(8);
|
|
33
|
-
const byte9 = manufacturerData.readUInt8(9);
|
|
34
|
-
const byte10 = manufacturerData.readUInt8(10); // bulb mode
|
|
35
|
-
const power = byte1;
|
|
36
|
-
const red = byte3;
|
|
37
|
-
const green = byte4;
|
|
38
|
-
const blue = byte5;
|
|
39
|
-
const color_temperature = byte6;
|
|
40
|
-
const state = !!(byte7 & 0b01111111);
|
|
41
|
-
const brightness = byte7 & 0b01111111;
|
|
42
|
-
const delay = byte8 & 0b10000000;
|
|
43
|
-
const preset = byte8 & 0b00001000;
|
|
44
|
-
const color_mode = byte8 & 0b00000111;
|
|
45
|
-
const speed = byte9 & 0b01111111;
|
|
46
|
-
const loop_index = byte10 & 0b11111110;
|
|
47
|
-
const data = {
|
|
25
|
+
const [, byte1, , byte3, byte4, byte5, byte6, byte7, byte8, byte9, byte10,] = manufacturerData;
|
|
26
|
+
return {
|
|
48
27
|
model: SwitchBotBLEModel.ColorBulb,
|
|
49
28
|
modelName: SwitchBotBLEModelName.ColorBulb,
|
|
50
29
|
modelFriendlyName: SwitchBotBLEModelFriendlyName.ColorBulb,
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
brightness,
|
|
58
|
-
delay,
|
|
59
|
-
preset,
|
|
60
|
-
color_mode,
|
|
61
|
-
speed,
|
|
62
|
-
loop_index,
|
|
30
|
+
power: byte1,
|
|
31
|
+
red: byte3,
|
|
32
|
+
green: byte4,
|
|
33
|
+
blue: byte5,
|
|
34
|
+
color_temperature: byte6,
|
|
35
|
+
state: !!(byte7 & 0b01111111),
|
|
36
|
+
brightness: byte7 & 0b01111111,
|
|
37
|
+
delay: !!(byte8 & 0b10000000),
|
|
38
|
+
preset: !!(byte8 & 0b00001000),
|
|
39
|
+
color_mode: byte8 & 0b00000111,
|
|
40
|
+
speed: byte9 & 0b01111111,
|
|
41
|
+
loop_index: byte10 & 0b11111110,
|
|
63
42
|
};
|
|
64
|
-
return data;
|
|
65
43
|
}
|
|
66
44
|
/**
|
|
67
|
-
*
|
|
45
|
+
* Reads the state of the bulb.
|
|
46
|
+
* @returns {Promise<boolean>} - Resolves with a boolean indicating whether the bulb is ON (true) or OFF (false).
|
|
68
47
|
*/
|
|
69
48
|
async readState() {
|
|
70
|
-
return
|
|
49
|
+
return this.operateBulb([0x57, 0x0F, 0x48, 0x01]);
|
|
71
50
|
}
|
|
72
51
|
/**
|
|
52
|
+
* Sets the state of the bulb.
|
|
53
|
+
* @param {number[]} reqByteArray - The request byte array.
|
|
54
|
+
* @returns {Promise<boolean>} - Resolves with a boolean indicating whether the operation was successful.
|
|
73
55
|
* @private
|
|
74
56
|
*/
|
|
75
57
|
async setState(reqByteArray) {
|
|
76
58
|
const base = [0x57, 0x0F, 0x47, 0x01];
|
|
77
|
-
return
|
|
59
|
+
return this.operateBulb(base.concat(reqByteArray));
|
|
78
60
|
}
|
|
79
61
|
/**
|
|
80
|
-
*
|
|
62
|
+
* Turns on the bulb.
|
|
63
|
+
* @returns {Promise<boolean>} - Resolves with a boolean indicating whether the bulb is ON (true).
|
|
81
64
|
*/
|
|
82
65
|
async turnOn() {
|
|
83
|
-
return
|
|
66
|
+
return this.setState([0x01, 0x01]);
|
|
84
67
|
}
|
|
85
68
|
/**
|
|
86
|
-
*
|
|
69
|
+
* Turns off the bulb.
|
|
70
|
+
* @returns {Promise<boolean>} - Resolves with a boolean indicating whether the bulb is OFF (false).
|
|
87
71
|
*/
|
|
88
72
|
async turnOff() {
|
|
89
|
-
return
|
|
73
|
+
return this.setState([0x01, 0x02]);
|
|
90
74
|
}
|
|
91
75
|
/**
|
|
92
|
-
*
|
|
76
|
+
* Sets the brightness of the bulb.
|
|
77
|
+
* @param {number} brightness - The brightness percentage (0-100).
|
|
78
|
+
* @returns {Promise<boolean>} - Resolves with a boolean indicating whether the operation was successful.
|
|
93
79
|
*/
|
|
94
80
|
async setBrightness(brightness) {
|
|
95
|
-
if (
|
|
96
|
-
throw new
|
|
97
|
-
}
|
|
98
|
-
if (brightness > 100) {
|
|
99
|
-
brightness = 100;
|
|
81
|
+
if (brightness < 0 || brightness > 100) {
|
|
82
|
+
throw new RangeError('Brightness must be between 0 and 100');
|
|
100
83
|
}
|
|
101
|
-
|
|
102
|
-
brightness = 0;
|
|
103
|
-
}
|
|
104
|
-
return await this.setState([0x02, 0x14, brightness]);
|
|
84
|
+
return this.setState([0x02, 0x14, brightness]);
|
|
105
85
|
}
|
|
106
86
|
/**
|
|
107
|
-
*
|
|
87
|
+
* Sets the color temperature of the bulb.
|
|
88
|
+
* @param {number} color_temperature - The color temperature percentage (0-100).
|
|
89
|
+
* @returns {Promise<boolean>} - Resolves with a boolean indicating whether the operation was successful.
|
|
108
90
|
*/
|
|
109
91
|
async setColorTemperature(color_temperature) {
|
|
110
|
-
if (
|
|
111
|
-
throw new
|
|
112
|
-
}
|
|
113
|
-
else if (color_temperature > 100) {
|
|
114
|
-
color_temperature = 100;
|
|
115
|
-
}
|
|
116
|
-
else if (color_temperature < 0) {
|
|
117
|
-
color_temperature = 0;
|
|
92
|
+
if (color_temperature < 0 || color_temperature > 100) {
|
|
93
|
+
throw new RangeError('Color temperature must be between 0 and 100');
|
|
118
94
|
}
|
|
119
|
-
return
|
|
95
|
+
return this.setState([0x02, 0x17, color_temperature]);
|
|
120
96
|
}
|
|
121
97
|
/**
|
|
122
|
-
*
|
|
98
|
+
* Sets the RGB color of the bulb.
|
|
99
|
+
* @param {number} brightness - The brightness percentage (0-100).
|
|
100
|
+
* @param {number} red - The red color value (0-255).
|
|
101
|
+
* @param {number} green - The green color value (0-255).
|
|
102
|
+
* @param {number} blue - The blue color value (0-255).
|
|
103
|
+
* @returns {Promise<boolean>} - Resolves with a boolean indicating whether the operation was successful.
|
|
123
104
|
*/
|
|
124
105
|
async setRGB(brightness, red, green, blue) {
|
|
125
|
-
if (
|
|
126
|
-
throw new
|
|
127
|
-
}
|
|
128
|
-
if (typeof red !== 'number') {
|
|
129
|
-
throw new TypeError(`The type of target red is incorrect: ${typeof red}`);
|
|
130
|
-
}
|
|
131
|
-
if (typeof green !== 'number') {
|
|
132
|
-
throw new TypeError(`The type of target green is incorrect: ${typeof green}`);
|
|
106
|
+
if (brightness < 0 || brightness > 100 || red < 0 || red > 255 || green < 0 || green > 255 || blue < 0 || blue > 255) {
|
|
107
|
+
throw new RangeError('Invalid RGB or brightness values');
|
|
133
108
|
}
|
|
134
|
-
|
|
135
|
-
throw new TypeError(`The type of target blue is incorrect: ${typeof blue}`);
|
|
136
|
-
}
|
|
137
|
-
if (brightness > 100) {
|
|
138
|
-
brightness = 100;
|
|
139
|
-
}
|
|
140
|
-
else if (brightness < 0) {
|
|
141
|
-
brightness = 0;
|
|
142
|
-
}
|
|
143
|
-
if (red > 255) {
|
|
144
|
-
red = 255;
|
|
145
|
-
}
|
|
146
|
-
else if (red < 0) {
|
|
147
|
-
red = 0;
|
|
148
|
-
}
|
|
149
|
-
if (green > 255) {
|
|
150
|
-
green = 255;
|
|
151
|
-
}
|
|
152
|
-
else if (green < 0) {
|
|
153
|
-
green = 0;
|
|
154
|
-
}
|
|
155
|
-
if (blue > 255) {
|
|
156
|
-
blue = 255;
|
|
157
|
-
}
|
|
158
|
-
else if (blue < 0) {
|
|
159
|
-
blue = 0;
|
|
160
|
-
}
|
|
161
|
-
return await this.setState([0x02, 0x12, brightness, red, green, blue]);
|
|
109
|
+
return this.setState([0x02, 0x12, brightness, red, green, blue]);
|
|
162
110
|
}
|
|
163
111
|
/**
|
|
112
|
+
* Sends a command to the bulb.
|
|
113
|
+
* @param {number[]} bytes - The command bytes.
|
|
114
|
+
* @returns {Promise<boolean>} - Resolves with a boolean indicating whether the operation was successful.
|
|
164
115
|
* @private
|
|
165
116
|
*/
|
|
166
117
|
async operateBulb(bytes) {
|
|
167
|
-
const
|
|
168
|
-
await this.command(
|
|
169
|
-
|
|
170
|
-
const
|
|
171
|
-
if (
|
|
172
|
-
|
|
173
|
-
if (code === 0x00 || code === 0x80) {
|
|
174
|
-
const is_on = code === 0x80;
|
|
175
|
-
return is_on;
|
|
176
|
-
}
|
|
177
|
-
else {
|
|
178
|
-
throw new Error(`The device returned an error: 0x${res_buf.toString('hex')}`);
|
|
179
|
-
}
|
|
118
|
+
const reqBuf = Buffer.from(bytes);
|
|
119
|
+
const resBuf = await this.command(reqBuf);
|
|
120
|
+
if (resBuf.length === 2) {
|
|
121
|
+
const code = resBuf.readUInt8(1);
|
|
122
|
+
if (code === 0x00 || code === 0x80) {
|
|
123
|
+
return code === 0x80;
|
|
180
124
|
}
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
})
|
|
185
|
-
.catch((error) => {
|
|
186
|
-
throw error;
|
|
187
|
-
});
|
|
125
|
+
throw new Error(`The device returned an error: 0x${resBuf.toString('hex')}`);
|
|
126
|
+
}
|
|
127
|
+
throw new Error(`Expecting a 2-byte response, got instead: 0x${resBuf.toString('hex')}`);
|
|
188
128
|
}
|
|
189
129
|
}
|
|
190
130
|
//# sourceMappingURL=wobulb.js.map
|