node-switchbot 2.5.0-beta.3 → 2.5.0-beta.30
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 +31 -20
- package/dist/advertising.d.ts.map +1 -1
- package/dist/advertising.js +72 -75
- 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 +39 -98
- 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 +71 -127
- 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 -169
- 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 +22 -21
- 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 +68 -102
- 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 +54 -88
- 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 +20 -28
- 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 +51 -82
- 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 +24 -28
- 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 +69 -75
- 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 +20 -26
- 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 +32 -48
- package/dist/device/wosensorth.js.map +1 -1
- package/dist/device/wosmartlock.d.ts +56 -13
- package/dist/device/wosmartlock.d.ts.map +1 -1
- package/dist/device/wosmartlock.js +106 -194
- package/dist/device/wosmartlock.js.map +1 -1
- package/dist/device/wosmartlockpro.d.ts +61 -18
- package/dist/device/wosmartlockpro.d.ts.map +1 -1
- package/dist/device/wosmartlockpro.js +114 -203
- package/dist/device/wosmartlockpro.js.map +1 -1
- package/dist/device/wostrip.d.ts +37 -18
- package/dist/device/wostrip.d.ts.map +1 -1
- package/dist/device/wostrip.js +78 -124
- 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} +7 -8
- package/dist/switchbot-ble.d.ts.map +1 -0
- package/dist/switchbot-ble.js +412 -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 +60 -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 +34 -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 +48 -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 +95 -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 +97 -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 +104 -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 +95 -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 +38 -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 +76 -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 +76 -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/{device/wohand2.test.js → test/wohub2.test.js} +10 -8
- package/dist/test/wohub2.test.js.map +1 -0
- package/dist/{device → test}/wohumi.test.d.ts.map +1 -1
- package/dist/{device → test}/wohumi.test.js +5 -2
- package/dist/test/wohumi.test.js.map +1 -0
- package/dist/test/woiosensorth.test.d.ts.map +1 -0
- package/dist/{device → test}/woiosensorth.test.js +11 -9
- package/dist/test/woiosensorth.test.js.map +1 -0
- package/dist/test/woplugmini.test.d.ts.map +1 -0
- package/dist/{device → test}/woplugmini.test.js +10 -5
- package/dist/test/woplugmini.test.js.map +1 -0
- package/dist/test/wopresence.test.d.ts.map +1 -0
- package/dist/{device → test}/wopresence.test.js +5 -1
- package/dist/test/wopresence.test.js.map +1 -0
- package/dist/test/wosensorth.test.d.ts.map +1 -0
- package/dist/{device → test}/wosensorth.test.js +5 -14
- 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 +147 -0
- package/dist/test/wosmartlock.test.js.map +1 -0
- package/dist/test/wosmartlockpro.test.d.ts.map +1 -0
- package/dist/{device → test}/wosmartlockpro.test.js +30 -26
- package/dist/test/wosmartlockpro.test.js.map +1 -0
- package/dist/{device → test}/wostrip.test.d.ts.map +1 -1
- package/dist/{device → test}/wostrip.test.js +18 -19
- 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 +8 -6
- 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.map +0 -1
- 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.map +0 -1
- package/dist/device/woplugmini.test.d.ts.map +0 -1
- 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.map +0 -1
- package/dist/device/wosensorth.test.d.ts.map +0 -1
- 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.map +0 -1
- 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
package/dist/device/wostrip.js
CHANGED
|
@@ -1,174 +1,128 @@
|
|
|
1
1
|
import { Buffer } from 'node:buffer';
|
|
2
|
-
/* Copyright(C) 2024, donavanbecker (https://github.com/donavanbecker). All rights reserved.
|
|
3
|
-
*
|
|
4
|
-
* wostrip.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
|
/**
|
|
9
|
-
*
|
|
5
|
+
* Class representing a WoStrip device.
|
|
6
|
+
* @see https://github.com/OpenWonderLabs/SwitchBotAPI-BLE/blob/latest/devicetypes/ledstriplight.md
|
|
10
7
|
*/
|
|
11
8
|
export class WoStrip extends SwitchbotDevice {
|
|
9
|
+
/**
|
|
10
|
+
* Parses the service data from the SwitchBot Strip Light.
|
|
11
|
+
* @param {Buffer} serviceData - The service data buffer.
|
|
12
|
+
* @param {(message: string) => void} [onlog] - Optional logging function.
|
|
13
|
+
* @returns {Promise<stripLightServiceData | null>} - Parsed service data or null if invalid.
|
|
14
|
+
*/
|
|
12
15
|
static async parseServiceData(serviceData, onlog) {
|
|
13
16
|
if (serviceData.length !== 18) {
|
|
14
|
-
|
|
15
|
-
onlog(`[parseServiceDataForWoStrip] Buffer length ${serviceData.length} !== 18!`);
|
|
16
|
-
}
|
|
17
|
+
onlog?.(`[parseServiceDataForWoStrip] Buffer length ${serviceData.length} !== 18!`);
|
|
17
18
|
return null;
|
|
18
19
|
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
const power = !!(byte7 & 0b10000000);
|
|
29
|
-
const state = !!(byte7 & 0b10000000);
|
|
30
|
-
const brightness = byte7 & 0b01111111;
|
|
31
|
-
const red = byte3;
|
|
32
|
-
const green = byte4;
|
|
33
|
-
const blue = byte5;
|
|
34
|
-
const delay = byte8 & 0b10000000;
|
|
35
|
-
const preset = byte8 & 0b00001000;
|
|
36
|
-
const color_mode = byte8 & 0b00000111;
|
|
37
|
-
const speed = byte9 & 0b01111111;
|
|
38
|
-
const loop_index = byte10 & 0b11111110;
|
|
20
|
+
const [byte3, byte4, byte5, byte7, byte8, byte9, byte10] = [
|
|
21
|
+
serviceData.readUInt8(3),
|
|
22
|
+
serviceData.readUInt8(4),
|
|
23
|
+
serviceData.readUInt8(5),
|
|
24
|
+
serviceData.readUInt8(7),
|
|
25
|
+
serviceData.readUInt8(8),
|
|
26
|
+
serviceData.readUInt8(9),
|
|
27
|
+
serviceData.readUInt8(10),
|
|
28
|
+
];
|
|
39
29
|
const data = {
|
|
40
30
|
model: SwitchBotBLEModel.StripLight,
|
|
41
31
|
modelName: SwitchBotBLEModelName.StripLight,
|
|
42
32
|
modelFriendlyName: SwitchBotBLEModelFriendlyName.StripLight,
|
|
43
|
-
power,
|
|
44
|
-
state,
|
|
45
|
-
brightness,
|
|
46
|
-
red,
|
|
47
|
-
green,
|
|
48
|
-
blue,
|
|
49
|
-
delay,
|
|
50
|
-
preset,
|
|
51
|
-
color_mode,
|
|
52
|
-
speed,
|
|
53
|
-
loop_index,
|
|
33
|
+
power: !!(byte7 & 0b10000000),
|
|
34
|
+
state: !!(byte7 & 0b10000000),
|
|
35
|
+
brightness: byte7 & 0b01111111,
|
|
36
|
+
red: byte3,
|
|
37
|
+
green: byte4,
|
|
38
|
+
blue: byte5,
|
|
39
|
+
delay: byte8 & 0b10000000,
|
|
40
|
+
preset: byte8 & 0b00001000,
|
|
41
|
+
color_mode: byte8 & 0b00000111,
|
|
42
|
+
speed: byte9 & 0b01111111,
|
|
43
|
+
loop_index: byte10 & 0b11111110,
|
|
54
44
|
};
|
|
55
45
|
return data;
|
|
56
46
|
}
|
|
57
47
|
/**
|
|
58
|
-
*
|
|
48
|
+
* Reads the state of the strip light.
|
|
49
|
+
* @returns {Promise<boolean>} - Resolves with true if the strip light is ON, false otherwise.
|
|
59
50
|
*/
|
|
60
51
|
async readState() {
|
|
61
|
-
return
|
|
52
|
+
return this.operateStripLight([0x57, 0x0F, 0x4A, 0x01]);
|
|
62
53
|
}
|
|
63
54
|
/**
|
|
64
|
-
*
|
|
55
|
+
* Sets the state of the strip light.
|
|
56
|
+
* @public
|
|
57
|
+
* @param {number[]} reqByteArray - The request byte array.
|
|
58
|
+
* @returns {Promise<boolean>} - Resolves with true if the operation was successful.
|
|
65
59
|
*/
|
|
66
60
|
async setState(reqByteArray) {
|
|
67
61
|
const base = [0x57, 0x0F, 0x49, 0x01];
|
|
68
|
-
return
|
|
62
|
+
return this.operateStripLight([...base, ...reqByteArray]);
|
|
69
63
|
}
|
|
70
64
|
/**
|
|
71
|
-
*
|
|
65
|
+
* Turns the strip light on.
|
|
66
|
+
* @returns {Promise<boolean>} - Resolves with true if the strip light is ON.
|
|
72
67
|
*/
|
|
73
68
|
async turnOn() {
|
|
74
|
-
return
|
|
69
|
+
return this.setState([0x01, 0x01]);
|
|
75
70
|
}
|
|
76
71
|
/**
|
|
77
|
-
*
|
|
72
|
+
* Turns the strip light off.
|
|
73
|
+
* @returns {Promise<boolean>} - Resolves with true if the strip light is OFF.
|
|
78
74
|
*/
|
|
79
75
|
async turnOff() {
|
|
80
|
-
return
|
|
76
|
+
return this.setState([0x01, 0x02]);
|
|
81
77
|
}
|
|
82
78
|
/**
|
|
83
|
-
*
|
|
79
|
+
* Sets the brightness of the strip light.
|
|
80
|
+
* @param {number} brightness - The brightness percentage (0-100).
|
|
81
|
+
* @returns {Promise<boolean>} - Resolves with true if the operation was successful.
|
|
84
82
|
*/
|
|
85
83
|
async setBrightness(brightness) {
|
|
86
|
-
if (typeof brightness !== 'number') {
|
|
87
|
-
throw new TypeError(`
|
|
88
|
-
}
|
|
89
|
-
if (brightness > 100) {
|
|
90
|
-
brightness = 100;
|
|
91
|
-
}
|
|
92
|
-
else if (brightness < 0) {
|
|
93
|
-
brightness = 0;
|
|
94
|
-
}
|
|
95
|
-
return await this.setState([0x02, 0x14]);
|
|
96
|
-
}
|
|
97
|
-
/**
|
|
98
|
-
* @returns resolves with color temperature
|
|
99
|
-
*/
|
|
100
|
-
async setColorTemperature(color_temperature) {
|
|
101
|
-
if (color_temperature) {
|
|
102
|
-
throw new Error(`Strip Light Doesn't Support Color temperature: ${typeof color_temperature}`);
|
|
84
|
+
if (typeof brightness !== 'number' || brightness < 0 || brightness > 100) {
|
|
85
|
+
throw new TypeError(`Invalid brightness value: ${brightness}`);
|
|
103
86
|
}
|
|
87
|
+
return this.setState([0x02, 0x14, brightness]);
|
|
104
88
|
}
|
|
105
89
|
/**
|
|
106
|
-
*
|
|
90
|
+
* Sets the RGB values of the strip light.
|
|
91
|
+
* @param {number} brightness - The brightness percentage (0-100).
|
|
92
|
+
* @param {number} red - The red value (0-255).
|
|
93
|
+
* @param {number} green - The green value (0-255).
|
|
94
|
+
* @param {number} blue - The blue value (0-255).
|
|
95
|
+
* @returns {Promise<boolean>} - Resolves with true if the operation was successful.
|
|
107
96
|
*/
|
|
108
97
|
async setRGB(brightness, red, green, blue) {
|
|
109
|
-
if (typeof
|
|
110
|
-
throw new TypeError(
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
}
|
|
118
|
-
if (typeof blue !== 'number') {
|
|
119
|
-
throw new TypeError(`The type of target blue is incorrect: ${typeof blue}`);
|
|
120
|
-
}
|
|
121
|
-
if (brightness > 100) {
|
|
122
|
-
brightness = 100;
|
|
123
|
-
}
|
|
124
|
-
else if (brightness < 0) {
|
|
125
|
-
brightness = 0;
|
|
126
|
-
}
|
|
127
|
-
if (red > 255) {
|
|
128
|
-
red = 255;
|
|
129
|
-
}
|
|
130
|
-
else if (red < 0) {
|
|
131
|
-
red = 0;
|
|
132
|
-
}
|
|
133
|
-
if (green > 255) {
|
|
134
|
-
green = 255;
|
|
135
|
-
}
|
|
136
|
-
else if (green < 0) {
|
|
137
|
-
green = 0;
|
|
138
|
-
}
|
|
139
|
-
if (blue > 255) {
|
|
140
|
-
blue = 255;
|
|
141
|
-
}
|
|
142
|
-
else if (blue < 0) {
|
|
143
|
-
blue = 0;
|
|
144
|
-
}
|
|
145
|
-
return await this.setState([0x02, 0x12, brightness, red, green, blue]);
|
|
98
|
+
if (![brightness, red, green, blue].every(val => typeof val === 'number')) {
|
|
99
|
+
throw new TypeError('Invalid RGB or brightness value');
|
|
100
|
+
}
|
|
101
|
+
brightness = Math.max(0, Math.min(100, brightness));
|
|
102
|
+
red = Math.max(0, Math.min(255, red));
|
|
103
|
+
green = Math.max(0, Math.min(255, green));
|
|
104
|
+
blue = Math.max(0, Math.min(255, blue));
|
|
105
|
+
return this.setState([0x02, 0x12, brightness, red, green, blue]);
|
|
146
106
|
}
|
|
147
107
|
/**
|
|
148
|
-
*
|
|
108
|
+
* Operates the strip light with the given byte array.
|
|
109
|
+
* @public
|
|
110
|
+
* @param {number[]} bytes - The byte array to send.
|
|
111
|
+
* @returns {Promise<boolean>} - Resolves with true if the operation was successful.
|
|
149
112
|
*/
|
|
150
113
|
async operateStripLight(bytes) {
|
|
151
114
|
const req_buf = Buffer.from(bytes);
|
|
152
|
-
await this.command(req_buf)
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
else {
|
|
166
|
-
throw new Error(`Expecting a 2-byte response, got instead: 0x${res_buf.toString('hex')}`);
|
|
167
|
-
}
|
|
168
|
-
})
|
|
169
|
-
.catch((error) => {
|
|
170
|
-
throw error;
|
|
171
|
-
});
|
|
115
|
+
const res_buf = await this.command(req_buf);
|
|
116
|
+
if (res_buf.length !== 2) {
|
|
117
|
+
throw new Error(`Expecting a 2-byte response, got instead: 0x${res_buf.toString('hex')}`);
|
|
118
|
+
}
|
|
119
|
+
const code = res_buf.readUInt8(1);
|
|
120
|
+
if (code === 0x00 || code === 0x80) {
|
|
121
|
+
return code === 0x80;
|
|
122
|
+
}
|
|
123
|
+
else {
|
|
124
|
+
throw new Error(`The device returned an error: 0x${res_buf.toString('hex')}`);
|
|
125
|
+
}
|
|
172
126
|
}
|
|
173
127
|
}
|
|
174
128
|
//# sourceMappingURL=wostrip.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wostrip.js","sourceRoot":"","sources":["../../src/device/wostrip.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"wostrip.js","sourceRoot":"","sources":["../../src/device/wostrip.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AAEpC,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAA;AAC9C,OAAO,EAA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AI,KAAK,IAAI,IAAI,IAAI,KAAK,IAAI,EAAE,CAAC;YACnC,OAAO,IAAI,KAAK,IAAI,CAAA;QACtB,CAAC;aAAM,CAAC;YACN,MAAM,IAAI,KAAK,CAAC,mCAAmC,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC,CAAA;QAC/E,CAAC;IACH,CAAC;CACF"}
|
package/dist/device.d.ts
CHANGED
|
@@ -1,254 +1,117 @@
|
|
|
1
|
-
import { Buffer } from 'node:buffer';
|
|
2
1
|
import type * as Noble from '@stoprocent/noble';
|
|
3
|
-
import type { SwitchBotBLEModel, SwitchBotBLEModelName } from './types/types.js';
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
} | null;
|
|
2
|
+
import type { Chars, SwitchBotBLEModel, SwitchBotBLEModelName } from './types/types.js';
|
|
3
|
+
import { Buffer } from 'node:buffer';
|
|
4
|
+
/**
|
|
5
|
+
* Represents a Switchbot Device.
|
|
6
|
+
*/
|
|
9
7
|
export declare class SwitchbotDevice {
|
|
10
|
-
_noble
|
|
11
|
-
_peripheral
|
|
12
|
-
_characteristics
|
|
13
|
-
_id
|
|
14
|
-
_address
|
|
15
|
-
_model
|
|
16
|
-
_modelName
|
|
17
|
-
_explicitly
|
|
18
|
-
_connected
|
|
19
|
-
onnotify_internal
|
|
20
|
-
ondisconnect_internal
|
|
21
|
-
onconnect_internal
|
|
22
|
-
/**
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
* @param
|
|
26
|
-
* @param {Noble} noble - The Noble object created by the noble module.
|
|
27
|
-
*
|
|
28
|
-
* This constructor initializes a new instance of the Device class with the specified peripheral and noble objects.
|
|
8
|
+
private _noble;
|
|
9
|
+
private _peripheral;
|
|
10
|
+
private _characteristics;
|
|
11
|
+
private _id;
|
|
12
|
+
private _address;
|
|
13
|
+
private _model;
|
|
14
|
+
private _modelName;
|
|
15
|
+
private _explicitly;
|
|
16
|
+
private _connected;
|
|
17
|
+
private onnotify_internal;
|
|
18
|
+
private ondisconnect_internal;
|
|
19
|
+
private onconnect_internal;
|
|
20
|
+
/**
|
|
21
|
+
* Initializes a new instance of the SwitchbotDevice class.
|
|
22
|
+
* @param peripheral The peripheral object from noble.
|
|
23
|
+
* @param noble The Noble object.
|
|
29
24
|
*/
|
|
30
25
|
constructor(peripheral: Noble.Peripheral, noble: typeof Noble);
|
|
31
26
|
get id(): string;
|
|
32
27
|
get address(): string;
|
|
33
|
-
get model():
|
|
34
|
-
get modelName():
|
|
28
|
+
get model(): SwitchBotBLEModel;
|
|
29
|
+
get modelName(): SwitchBotBLEModelName;
|
|
35
30
|
get connectionState(): string;
|
|
36
|
-
get onconnect(): () => Promise<void
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
*
|
|
44
|
-
* @param func A function that returns a Promise, representing the asynchronous operation of connecting.
|
|
45
|
-
* This function is expected to be called without any arguments.
|
|
46
|
-
* @throws Error if the provided argument is not a function, ensuring type safety.
|
|
47
|
-
*/
|
|
48
|
-
set onconnect(func: () => Promise<void> | void);
|
|
49
|
-
get ondisconnect(): () => Promise<void> | void;
|
|
50
|
-
/**
|
|
51
|
-
* Sets the asynchronous disconnection handler.
|
|
52
|
-
*
|
|
53
|
-
* This setter configures a function to act as the asynchronous disconnection handler. The handler
|
|
54
|
-
* should be a function that returns a Promise, which resolves when the disconnection process
|
|
55
|
-
* is complete. The resolution of the Promise does not carry any value.
|
|
56
|
-
*
|
|
57
|
-
* @param func A function that returns a Promise, representing the asynchronous operation of disconnecting.
|
|
58
|
-
* This function is expected to be called without any arguments.
|
|
59
|
-
* @throws Error if the provided argument is not a function, to ensure that the handler is correctly typed.
|
|
60
|
-
*/
|
|
61
|
-
set ondisconnect(func: () => Promise<void> | void);
|
|
62
|
-
/**
|
|
63
|
-
* Initiates an asynchronous connection process.
|
|
64
|
-
*
|
|
65
|
-
* This method marks the device as being connected explicitly by setting a flag, then proceeds
|
|
66
|
-
* to initiate the actual connection process by calling an internal asynchronous method `connect_internalAsync`.
|
|
67
|
-
* The `connect_internalAsync` method is responsible for handling the low-level connection logic.
|
|
68
|
-
*
|
|
69
|
-
* @returns A Promise that resolves when the connection process initiated by `connect_internalAsync` completes.
|
|
70
|
-
* The resolution of this Promise does not carry any value, indicating that the focus is on
|
|
71
|
-
* the completion of the connection process rather than the result of the connection itself.
|
|
31
|
+
get onconnect(): () => Promise<void>;
|
|
32
|
+
set onconnect(func: () => Promise<void>);
|
|
33
|
+
get ondisconnect(): () => Promise<void>;
|
|
34
|
+
set ondisconnect(func: () => Promise<void>);
|
|
35
|
+
/**
|
|
36
|
+
* Connects to the device.
|
|
37
|
+
* @returns A Promise that resolves when the connection is complete.
|
|
72
38
|
*/
|
|
73
39
|
connect(): Promise<void>;
|
|
74
40
|
/**
|
|
75
|
-
*
|
|
76
|
-
*
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
*
|
|
81
|
-
*
|
|
82
|
-
|
|
83
|
-
* 2. Checks the current connection state of the device. If already connected, the promise resolves immediately.
|
|
84
|
-
* If in the process of connecting or disconnecting, the promise is rejected advising to wait.
|
|
85
|
-
* 3. Sets up event handlers for 'connect' and 'disconnect' events on the peripheral device to manage connection state.
|
|
86
|
-
* 4. Initiates the connection. If an error occurs during this step, the promise is rejected.
|
|
87
|
-
* 5. Once connected, retrieves the device's characteristics and subscribes to them. If this process fails, the device
|
|
88
|
-
* is disconnected, and the promise is rejected.
|
|
89
|
-
*
|
|
90
|
-
* @returns A Promise<void> that resolves when the device is connected or rejects with an error.
|
|
91
|
-
*/
|
|
92
|
-
connect_internal(): Promise<void>;
|
|
41
|
+
* Internal method to handle the connection process.
|
|
42
|
+
* @returns A Promise that resolves when the connection is complete.
|
|
43
|
+
*/
|
|
44
|
+
private connect_internal;
|
|
45
|
+
/**
|
|
46
|
+
* Retrieves the device characteristics.
|
|
47
|
+
* @returns A Promise that resolves with the device characteristics.
|
|
48
|
+
*/
|
|
93
49
|
getCharacteristics(): Promise<Chars>;
|
|
50
|
+
/**
|
|
51
|
+
* Discovers the device services.
|
|
52
|
+
* @returns A Promise that resolves with the list of services.
|
|
53
|
+
*/
|
|
94
54
|
discoverServices(): Promise<Noble.Service[]>;
|
|
95
55
|
/**
|
|
96
|
-
*
|
|
97
|
-
*
|
|
98
|
-
*
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
*
|
|
108
|
-
*
|
|
109
|
-
* (`this.chars`). If the characteristic is found, it proceeds to remove all event listeners attached to it
|
|
110
|
-
* to prevent any further handling of incoming data notifications. Then, it asynchronously unsubscribes from
|
|
111
|
-
* the notification characteristic using `unsubscribeAsync()`, effectively stopping the device from sending
|
|
112
|
-
* notifications to the client.
|
|
113
|
-
*
|
|
114
|
-
* If the notification characteristic is not found, the method simply returns without performing any action.
|
|
115
|
-
*
|
|
116
|
-
* @return A Promise that resolves to `void` upon successful unsubscription or if the characteristic is not found.
|
|
56
|
+
* Discovers the characteristics of a service.
|
|
57
|
+
* @param service The service to discover characteristics for.
|
|
58
|
+
* @returns A Promise that resolves with the list of characteristics.
|
|
59
|
+
*/
|
|
60
|
+
private discoverCharacteristics;
|
|
61
|
+
/**
|
|
62
|
+
* Subscribes to the notify characteristic.
|
|
63
|
+
* @returns A Promise that resolves when the subscription is complete.
|
|
64
|
+
*/
|
|
65
|
+
private subscribe;
|
|
66
|
+
/**
|
|
67
|
+
* Unsubscribes from the notify characteristic.
|
|
68
|
+
* @returns A Promise that resolves when the unsubscription is complete.
|
|
117
69
|
*/
|
|
118
70
|
unsubscribe(): Promise<void>;
|
|
119
71
|
/**
|
|
120
|
-
*
|
|
121
|
-
*
|
|
122
|
-
* This method handles the disconnection process by first checking the current
|
|
123
|
-
* connection state of the device. If the device is already disconnected, the
|
|
124
|
-
* method resolves immediately. If the device is in the process of connecting or
|
|
125
|
-
* disconnecting, it throws an error indicating that the operation should be retried
|
|
126
|
-
* after a brief wait. Otherwise, it proceeds to unsubscribe from any subscriptions
|
|
127
|
-
* and then initiates the disconnection process.
|
|
128
|
-
*
|
|
129
|
-
* Note: This method sets a flag to indicate that the disconnection was not initiated
|
|
130
|
-
* by the user explicitly.
|
|
131
|
-
*
|
|
132
|
-
* @returns A Promise that resolves when the disconnection process has completed.
|
|
133
|
-
* The Promise does not pass any value upon resolution.
|
|
72
|
+
* Disconnects from the device.
|
|
73
|
+
* @returns A Promise that resolves when the disconnection is complete.
|
|
134
74
|
*/
|
|
135
75
|
disconnect(): Promise<void>;
|
|
136
76
|
/**
|
|
137
|
-
*
|
|
138
|
-
*
|
|
139
|
-
* This method checks the `explicitly` flag to determine if the connection was initiated by the user.
|
|
140
|
-
* If not, it proceeds to disconnect from the device by calling `this.disconnectAsync()`. After the disconnection,
|
|
141
|
-
* it sets `explicitly` to true to prevent future disconnections when the connection is user-initiated.
|
|
142
|
-
*
|
|
143
|
-
* This approach ensures that automatic disconnections only occur when the user has not explicitly initiated the connection,
|
|
144
|
-
* avoiding unnecessary disconnections in user-initiated sessions.
|
|
145
|
-
*
|
|
146
|
-
* @returns A Promise that resolves once the device has been successfully disconnected, applicable only when the
|
|
147
|
-
* connection was not user-initiated.
|
|
148
|
-
*/
|
|
149
|
-
disconnect_internal(): Promise<void>;
|
|
150
|
-
/**
|
|
151
|
-
* Asynchronously retrieves the device name.
|
|
152
|
-
* This method is designed to fetch the name of the device asynchronously and return it as a promise.
|
|
153
|
-
* It is marked as deprecated and will be removed in a future version. Use `getDeviceNameAsync` instead.
|
|
154
|
-
*
|
|
155
|
-
* @deprecated since version 2.4.0. Will be removed in version 3.0.0. Use `getDeviceNameAsync()` instead.
|
|
156
|
-
* @returns A Promise that resolves with the device name.
|
|
77
|
+
* Internal method to handle disconnection if not explicitly initiated.
|
|
78
|
+
* @returns A Promise that resolves when the disconnection is complete.
|
|
157
79
|
*/
|
|
158
|
-
|
|
80
|
+
private disconnect_internal;
|
|
159
81
|
/**
|
|
160
|
-
*
|
|
161
|
-
*
|
|
162
|
-
* reads the characteristic to obtain the device name, and then disconnects from the device.
|
|
163
|
-
* It ensures that the device supports the required characteristic for fetching the name. If the characteristic
|
|
164
|
-
* is not supported, it throws an error. The method encapsulates the entire process of connecting, reading,
|
|
165
|
-
* and disconnecting, making it convenient to get the device name with a single call.
|
|
166
|
-
*
|
|
167
|
-
* @returns A Promise that resolves with the device name as a string.
|
|
82
|
+
* Retrieves the device name.
|
|
83
|
+
* @returns A Promise that resolves with the device name.
|
|
168
84
|
*/
|
|
169
|
-
|
|
85
|
+
getDeviceName(): Promise<string>;
|
|
170
86
|
/**
|
|
171
|
-
*
|
|
172
|
-
*
|
|
173
|
-
*
|
|
174
|
-
* Upon successful validation, the device name is updated, and the promise resolves without passing any value.
|
|
175
|
-
*
|
|
176
|
-
* @param name The new device name as a string. Must be 1 to 100 bytes in length.
|
|
177
|
-
* @returns A Promise that resolves to `void` upon successful update of the device name.
|
|
178
|
-
* @deprecated since version 2.4.0. Will be removed in version 3.0.0. Use `setDeviceNameAsync()` instead.
|
|
87
|
+
* Sets the device name.
|
|
88
|
+
* @param name The new device name.
|
|
89
|
+
* @returns A Promise that resolves when the name is set.
|
|
179
90
|
*/
|
|
180
91
|
setDeviceName(name: string): Promise<void>;
|
|
181
92
|
/**
|
|
182
|
-
*
|
|
183
|
-
*
|
|
184
|
-
*
|
|
185
|
-
* After passing validation, the method converts the name into a UTF-8 encoded buffer.
|
|
186
|
-
* It then initiates a connection to the device. If the device does not support the required characteristic UUID for setting the device name,
|
|
187
|
-
* an error is thrown indicating the lack of support.
|
|
188
|
-
* Upon successfully connecting and verifying support, the method writes the new name to the device using the appropriate characteristic.
|
|
189
|
-
* Finally, it disconnects from the device, completing the name update process.
|
|
190
|
-
*
|
|
191
|
-
* @param name The new device name as a string. Must be 1 to 100 bytes in length.
|
|
192
|
-
* @returns A Promise that resolves to `void` upon successful update of the device name.
|
|
193
|
-
*/
|
|
194
|
-
setDeviceNameAsync(name: string): Promise<void>;
|
|
195
|
-
/**
|
|
196
|
-
* Asynchronously sends a command to the device and awaits a response.
|
|
197
|
-
* This method encapsulates the process of sending a command encapsulated in a Buffer to the device,
|
|
198
|
-
* and then waiting for the device to respond. The method ensures that the device is connected before sending the command,
|
|
199
|
-
* writes the command to the device's write characteristic, waits for a response on the notify characteristic,
|
|
200
|
-
* and finally disconnects from the device. The response from the device is returned as a Buffer.
|
|
201
|
-
*
|
|
202
|
-
* @param req_buf A Buffer containing the command to be sent to the device.
|
|
203
|
-
* @returns A Promise that resolves with a Buffer containing the device's response to the command.
|
|
93
|
+
* Sends a command to the device and awaits a response.
|
|
94
|
+
* @param req_buf The command buffer.
|
|
95
|
+
* @returns A Promise that resolves with the response buffer.
|
|
204
96
|
*/
|
|
205
97
|
command(req_buf: Buffer): Promise<Buffer>;
|
|
206
98
|
/**
|
|
207
99
|
* Waits for a response from the device after sending a command.
|
|
208
|
-
*
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
*
|
|
213
|
-
* @
|
|
214
|
-
*
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
*
|
|
220
|
-
*
|
|
221
|
-
* A
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
* Once a response is received or a timeout occurs, the internal handler is reset to an empty function to prevent memory leaks.
|
|
225
|
-
*
|
|
226
|
-
* @returns A Promise that resolves with the received Buffer or rejects with an error if a timeout occurs.
|
|
227
|
-
*/
|
|
228
|
-
_waitCommandResponseAsync(): Promise<Buffer>;
|
|
229
|
-
/**
|
|
230
|
-
* Asynchronously reads data from the specified characteristic of the device with a timeout.
|
|
231
|
-
* This method attempts to read data from the device's characteristic and sets a timeout to handle cases where the read operation takes too long.
|
|
232
|
-
* If the read operation does not complete within the specified timeout period, an error is thrown.
|
|
233
|
-
* Once the read operation completes successfully, the timeout is cleared to prevent it from triggering.
|
|
234
|
-
*
|
|
235
|
-
* @param char The characteristic of the device from which data will be read.
|
|
236
|
-
* @returns A Promise that resolves with the data read from the characteristic or rejects with an error if a timeout occurs.
|
|
237
|
-
*
|
|
238
|
-
* @throws Error if the read operation fails or if a timeout occurs.
|
|
239
|
-
*/
|
|
240
|
-
read(char: Noble.Characteristic): Promise<Buffer>;
|
|
241
|
-
/**
|
|
242
|
-
* Asynchronously writes data to a specified characteristic of the device.
|
|
243
|
-
* This method sends a buffer of data to the device's characteristic and sets a timeout to handle cases where the write operation takes too long.
|
|
244
|
-
* If the write operation does not complete within the specified timeout period, an error is thrown.
|
|
245
|
-
* Once the write operation completes successfully, the timeout is cleared to prevent it from triggering.
|
|
246
|
-
*
|
|
247
|
-
* @param char The characteristic of the device to which the data will be written.
|
|
248
|
-
* @param buf A Buffer containing the data to be written to the device.
|
|
249
|
-
* @returns A Promise that resolves when the write operation completes successfully or rejects with an error if a timeout occurs.
|
|
250
|
-
*/
|
|
251
|
-
write(char: Noble.Characteristic, buf: Buffer): Promise<void | string>;
|
|
100
|
+
* @returns A Promise that resolves with the response buffer.
|
|
101
|
+
*/
|
|
102
|
+
private _waitCommandResponseAsync;
|
|
103
|
+
/**
|
|
104
|
+
* Reads data from a characteristic with a timeout.
|
|
105
|
+
* @param char The characteristic to read from.
|
|
106
|
+
* @returns A Promise that resolves with the data buffer.
|
|
107
|
+
*/
|
|
108
|
+
private read;
|
|
109
|
+
/**
|
|
110
|
+
* Writes data to a characteristic with a timeout.
|
|
111
|
+
* @param char The characteristic to write to.
|
|
112
|
+
* @param buf The data buffer.
|
|
113
|
+
* @returns A Promise that resolves when the write is complete.
|
|
114
|
+
*/
|
|
115
|
+
private write;
|
|
252
116
|
}
|
|
253
|
-
export {};
|
|
254
117
|
//# sourceMappingURL=device.d.ts.map
|