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,23 +1,17 @@
|
|
|
1
1
|
import { Buffer } from 'node:buffer';
|
|
2
2
|
import * as Crypto from 'node:crypto';
|
|
3
|
-
/*
|
|
4
|
-
* wosmartlock.ts: Switchbot BLE API registration.
|
|
5
|
-
* adapted off the work done by [pySwitchbot](https://github.com/Danielhiversen/pySwitchbot)
|
|
6
|
-
*/
|
|
7
3
|
import { SwitchbotDevice } from '../device.js';
|
|
4
|
+
import { WoSmartLockCommands } from '../settings.js';
|
|
8
5
|
import { SwitchBotBLEModel, SwitchBotBLEModelFriendlyName, SwitchBotBLEModelName } from '../types/types.js';
|
|
9
|
-
|
|
6
|
+
/**
|
|
7
|
+
* Class representing a WoSmartLock device.
|
|
8
|
+
* @see https://github.com/OpenWonderLabs/SwitchBotAPI-BLE/blob/latest/devicetypes/lock.md
|
|
9
|
+
*/
|
|
10
10
|
export class WoSmartLock extends SwitchbotDevice {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
static COMMAND_LOCK_INFO = '570f4f8101';
|
|
16
|
-
static COMMAND_UNLOCK = '570f4e01011080';
|
|
17
|
-
static COMMAND_UNLOCK_NO_UNLATCH = '570f4e010110a0';
|
|
18
|
-
static COMMAND_LOCK = '570f4e01011000';
|
|
19
|
-
static COMMAND_ENABLE_NOTIFICATIONS = '570e01001e00008101';
|
|
20
|
-
static COMMAND_DISABLE_NOTIFICATIONS = '570e00';
|
|
11
|
+
static switchBotBLE;
|
|
12
|
+
iv = null;
|
|
13
|
+
key_id = '';
|
|
14
|
+
encryption_key = null;
|
|
21
15
|
static Result = {
|
|
22
16
|
ERROR: 0x00,
|
|
23
17
|
SUCCESS: 0x01,
|
|
@@ -25,227 +19,146 @@ export class WoSmartLock extends SwitchbotDevice {
|
|
|
25
19
|
};
|
|
26
20
|
static async validateResponse(res) {
|
|
27
21
|
if (res.length >= 3) {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
case WoSmartLock.Result.SUCCESS_LOW_BATTERY:
|
|
32
|
-
return WoSmartLock.Result.SUCCESS_LOW_BATTERY;
|
|
22
|
+
const result = res.readUInt8(0);
|
|
23
|
+
if (result === WoSmartLock.Result.SUCCESS || result === WoSmartLock.Result.SUCCESS_LOW_BATTERY) {
|
|
24
|
+
return result;
|
|
33
25
|
}
|
|
34
26
|
}
|
|
35
27
|
return WoSmartLock.Result.ERROR;
|
|
36
28
|
}
|
|
37
29
|
static getLockStatus(code) {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
return 'LOCKING_STOP';
|
|
49
|
-
case 0b1010000:
|
|
50
|
-
return 'UNLOCKING_STOP';
|
|
51
|
-
case 0b1100000: // Only EU lock type
|
|
52
|
-
return 'NOT_FULLY_LOCKED';
|
|
53
|
-
default:
|
|
54
|
-
return 'UNKNOWN';
|
|
55
|
-
}
|
|
30
|
+
const statusMap = {
|
|
31
|
+
0b0000000: 'LOCKED',
|
|
32
|
+
0b0010000: 'UNLOCKED',
|
|
33
|
+
0b0100000: 'LOCKING',
|
|
34
|
+
0b0110000: 'UNLOCKING',
|
|
35
|
+
0b1000000: 'LOCKING_STOP',
|
|
36
|
+
0b1010000: 'UNLOCKING_STOP',
|
|
37
|
+
0b1100000: 'NOT_FULLY_LOCKED', // Only EU lock type
|
|
38
|
+
};
|
|
39
|
+
return statusMap[code] || 'UNKNOWN';
|
|
56
40
|
}
|
|
57
|
-
static async parseServiceData(serviceData, manufacturerData
|
|
41
|
+
static async parseServiceData(serviceData, manufacturerData) {
|
|
58
42
|
if (manufacturerData.length < 11) {
|
|
59
|
-
|
|
60
|
-
onlog(`[parseServiceDataForWoSmartLock] Buffer length ${manufacturerData.length} is too short!`);
|
|
61
|
-
}
|
|
43
|
+
this.switchBotBLE.emitLog('error', `[parseServiceDataForWoSmartLock] Buffer length ${manufacturerData.length} is too short!`);
|
|
62
44
|
return null;
|
|
63
45
|
}
|
|
64
|
-
// adv data needs both service data and manufacturer data
|
|
65
|
-
// byte var names based on documentation
|
|
66
46
|
const byte2 = serviceData.readUInt8(2);
|
|
67
47
|
const byte15 = manufacturerData.readUInt8(9);
|
|
68
48
|
const byte16 = manufacturerData.readUInt8(10);
|
|
69
|
-
const battery = byte2 & 0b01111111; // %
|
|
70
|
-
const calibration = !!(byte15 & 0b10000000);
|
|
71
|
-
const status = WoSmartLock.getLockStatus(byte15 & 0b01110000);
|
|
72
|
-
const update_from_secondary_lock = !!(byte15 & 0b00001000);
|
|
73
|
-
const door_open = !!(byte15 & 0b00000100);
|
|
74
|
-
const double_lock_mode = !!(byte16 & 0b10000000);
|
|
75
|
-
const unclosed_alarm = !!(byte16 & 0b00100000);
|
|
76
|
-
const unlocked_alarm = !!(byte16 & 0b00010000);
|
|
77
|
-
const auto_lock_paused = !!(byte16 & 0b00000010);
|
|
78
|
-
const night_latch = !!(manufacturerData.length > 11 && manufacturerData.readUInt8(11) & 0b00000001);
|
|
79
49
|
const data = {
|
|
80
50
|
model: SwitchBotBLEModel.Lock,
|
|
81
51
|
modelName: SwitchBotBLEModelName.Lock,
|
|
82
52
|
modelFriendlyName: SwitchBotBLEModelFriendlyName.Lock,
|
|
83
|
-
battery,
|
|
84
|
-
calibration,
|
|
85
|
-
status,
|
|
86
|
-
update_from_secondary_lock,
|
|
87
|
-
door_open,
|
|
88
|
-
double_lock_mode,
|
|
89
|
-
unclosed_alarm,
|
|
90
|
-
unlocked_alarm,
|
|
91
|
-
auto_lock_paused,
|
|
92
|
-
night_latch,
|
|
53
|
+
battery: byte2 & 0b01111111,
|
|
54
|
+
calibration: !!(byte15 & 0b10000000),
|
|
55
|
+
status: WoSmartLock.getLockStatus(byte15 & 0b01110000),
|
|
56
|
+
update_from_secondary_lock: !!(byte15 & 0b00001000),
|
|
57
|
+
door_open: !!(byte15 & 0b00000100),
|
|
58
|
+
double_lock_mode: !!(byte16 & 0b10000000),
|
|
59
|
+
unclosed_alarm: !!(byte16 & 0b00100000),
|
|
60
|
+
unlocked_alarm: !!(byte16 & 0b00010000),
|
|
61
|
+
auto_lock_paused: !!(byte16 & 0b00000010),
|
|
62
|
+
night_latch: !!(manufacturerData.length > 11 && manufacturerData.readUInt8(11) & 0b00000001),
|
|
93
63
|
};
|
|
94
64
|
return data;
|
|
95
65
|
}
|
|
96
66
|
constructor(peripheral, noble) {
|
|
97
67
|
super(peripheral, noble);
|
|
98
|
-
this.iv = null;
|
|
99
|
-
this.key_id = '';
|
|
100
|
-
this.encryption_key = null;
|
|
101
68
|
}
|
|
102
|
-
|
|
103
|
-
*
|
|
104
|
-
*
|
|
105
|
-
*
|
|
106
|
-
|
|
107
|
-
* - keyId, encryptionKey
|
|
108
|
-
*
|
|
109
|
-
* [Return value]
|
|
110
|
-
* - void
|
|
111
|
-
* ---------------------------------------------------------------- */
|
|
69
|
+
/**
|
|
70
|
+
* Initializes the encryption key info for valid lock communication.
|
|
71
|
+
* @param {string} keyId - The key ID.
|
|
72
|
+
* @param {string} encryptionKey - The encryption key.
|
|
73
|
+
*/
|
|
112
74
|
async setKey(keyId, encryptionKey) {
|
|
113
75
|
this.iv = null;
|
|
114
76
|
this.key_id = keyId;
|
|
115
77
|
this.encryption_key = Buffer.from(encryptionKey, 'hex');
|
|
116
78
|
}
|
|
117
|
-
|
|
118
|
-
*
|
|
119
|
-
* -
|
|
120
|
-
|
|
121
|
-
* [Arguments]
|
|
122
|
-
* - none
|
|
123
|
-
*
|
|
124
|
-
* [Return value]
|
|
125
|
-
* - Promise object
|
|
126
|
-
* WoSmartLock.LockResult will be passed to the `resolve()`.
|
|
127
|
-
* ---------------------------------------------------------------- */
|
|
79
|
+
/**
|
|
80
|
+
* Unlocks the Smart Lock.
|
|
81
|
+
* @returns {Promise<number>} - The result of the unlock operation.
|
|
82
|
+
*/
|
|
128
83
|
async unlock() {
|
|
129
|
-
await this.operateLock(
|
|
130
|
-
|
|
131
|
-
if (resBuf) {
|
|
132
|
-
return WoSmartLock.validateResponse(resBuf);
|
|
133
|
-
}
|
|
134
|
-
else {
|
|
135
|
-
return WoSmartLockPro.Result.ERROR;
|
|
136
|
-
}
|
|
137
|
-
})
|
|
138
|
-
.catch((error) => {
|
|
139
|
-
return error;
|
|
140
|
-
});
|
|
84
|
+
const resBuf = await this.operateLock(WoSmartLockCommands.UNLOCK);
|
|
85
|
+
return resBuf ? WoSmartLock.validateResponse(resBuf) : WoSmartLock.Result.ERROR;
|
|
141
86
|
}
|
|
142
|
-
|
|
143
|
-
*
|
|
144
|
-
* -
|
|
145
|
-
|
|
146
|
-
* [Arguments]
|
|
147
|
-
* - none
|
|
148
|
-
*
|
|
149
|
-
* [Return value]
|
|
150
|
-
* - Promise object
|
|
151
|
-
* WoSmartLock.LockResult will be passed to the `resolve()`.
|
|
152
|
-
* ---------------------------------------------------------------- */
|
|
87
|
+
/**
|
|
88
|
+
* Unlocks the Smart Lock without unlatching the door.
|
|
89
|
+
* @returns {Promise<number>} - The result of the unlock operation.
|
|
90
|
+
*/
|
|
153
91
|
async unlockNoUnlatch() {
|
|
154
|
-
await this.operateLock(
|
|
155
|
-
|
|
156
|
-
if (resBuf) {
|
|
157
|
-
return WoSmartLock.validateResponse(resBuf);
|
|
158
|
-
}
|
|
159
|
-
else {
|
|
160
|
-
throw new Error('Failed to retrieve response buffer from the device.');
|
|
161
|
-
}
|
|
162
|
-
})
|
|
163
|
-
.catch((error) => {
|
|
164
|
-
return error;
|
|
165
|
-
});
|
|
92
|
+
const resBuf = await this.operateLock(WoSmartLockCommands.UNLOCK_NO_UNLATCH);
|
|
93
|
+
return resBuf ? WoSmartLock.validateResponse(resBuf) : WoSmartLock.Result.ERROR;
|
|
166
94
|
}
|
|
167
|
-
|
|
168
|
-
*
|
|
169
|
-
* -
|
|
170
|
-
|
|
171
|
-
* [Arguments]
|
|
172
|
-
* - none
|
|
173
|
-
*
|
|
174
|
-
* [Return value]
|
|
175
|
-
* - Promise object
|
|
176
|
-
* WoSmartLock.LockResult will be passed to the `resolve()`.
|
|
177
|
-
* ---------------------------------------------------------------- */
|
|
95
|
+
/**
|
|
96
|
+
* Locks the Smart Lock.
|
|
97
|
+
* @returns {Promise<number>} - The result of the lock operation.
|
|
98
|
+
*/
|
|
178
99
|
async lock() {
|
|
179
|
-
await this.operateLock(
|
|
180
|
-
|
|
181
|
-
if (resBuf) {
|
|
182
|
-
return WoSmartLock.validateResponse(resBuf);
|
|
183
|
-
}
|
|
184
|
-
else {
|
|
185
|
-
throw new Error('Failed to retrieve response buffer from the device.');
|
|
186
|
-
}
|
|
187
|
-
})
|
|
188
|
-
.catch((error) => {
|
|
189
|
-
return error;
|
|
190
|
-
});
|
|
100
|
+
const resBuf = await this.operateLock(WoSmartLockCommands.LOCK);
|
|
101
|
+
return resBuf ? WoSmartLock.validateResponse(resBuf) : WoSmartLock.Result.ERROR;
|
|
191
102
|
}
|
|
192
|
-
|
|
193
|
-
* info
|
|
194
|
-
* -
|
|
195
|
-
|
|
196
|
-
* [Arguments]
|
|
197
|
-
* - none
|
|
198
|
-
*
|
|
199
|
-
* [Return value]
|
|
200
|
-
* - Promise object
|
|
201
|
-
* state object will be passed to the `resolve()`
|
|
202
|
-
* ---------------------------------------------------------------- */
|
|
103
|
+
/**
|
|
104
|
+
* Gets general state info from the Smart Lock.
|
|
105
|
+
* @returns {Promise<object | null>} - The state object or null if an error occurred.
|
|
106
|
+
*/
|
|
203
107
|
async info() {
|
|
204
|
-
await this.operateLock(
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
}
|
|
216
|
-
else {
|
|
217
|
-
throw new Error('Failed to retrieve response buffer from the device.');
|
|
218
|
-
}
|
|
219
|
-
})
|
|
220
|
-
.catch((error) => {
|
|
221
|
-
return error;
|
|
222
|
-
});
|
|
108
|
+
const resBuf = await this.operateLock(WoSmartLockCommands.LOCK_INFO);
|
|
109
|
+
if (resBuf) {
|
|
110
|
+
return {
|
|
111
|
+
calibration: Boolean(resBuf[1] & 0b10000000),
|
|
112
|
+
status: WoSmartLock.getLockStatus((resBuf[1] & 0b01110000)),
|
|
113
|
+
door_open: Boolean(resBuf[1] & 0b00000100),
|
|
114
|
+
unclosed_alarm: Boolean(resBuf[2] & 0b00100000),
|
|
115
|
+
unlocked_alarm: Boolean(resBuf[2] & 0b00010000),
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
return null;
|
|
223
119
|
}
|
|
120
|
+
/**
|
|
121
|
+
* Encrypts a string using AES-128-CTR.
|
|
122
|
+
* @param {string} str - The string to encrypt.
|
|
123
|
+
* @returns {Promise<string>} - The encrypted string in hex format.
|
|
124
|
+
*/
|
|
224
125
|
async encrypt(str) {
|
|
225
126
|
const cipher = Crypto.createCipheriv('aes-128-ctr', this.encryption_key, this.iv);
|
|
226
127
|
return Buffer.concat([cipher.update(str, 'hex'), cipher.final()]).toString('hex');
|
|
227
128
|
}
|
|
129
|
+
/**
|
|
130
|
+
* Decrypts a buffer using AES-128-CTR.
|
|
131
|
+
* @param {Buffer} data - The data to decrypt.
|
|
132
|
+
* @returns {Promise<Buffer>} - The decrypted data.
|
|
133
|
+
*/
|
|
228
134
|
async decrypt(data) {
|
|
229
135
|
const decipher = Crypto.createDecipheriv('aes-128-ctr', this.encryption_key, this.iv);
|
|
230
136
|
return Buffer.concat([decipher.update(data), decipher.final()]);
|
|
231
137
|
}
|
|
138
|
+
/**
|
|
139
|
+
* Retrieves the IV from the device.
|
|
140
|
+
* @returns {Promise<Buffer>} - The IV buffer.
|
|
141
|
+
*/
|
|
232
142
|
async getIv() {
|
|
233
|
-
if (this.iv
|
|
234
|
-
const res = await this.operateLock(
|
|
143
|
+
if (!this.iv) {
|
|
144
|
+
const res = await this.operateLock(WoSmartLockCommands.GET_CKIV + this.key_id, false);
|
|
235
145
|
if (res) {
|
|
236
146
|
this.iv = res.subarray(4);
|
|
237
147
|
}
|
|
238
148
|
else {
|
|
239
|
-
// Handle the case when 'res' is undefined
|
|
240
|
-
// For example, you can throw an error or set a default value for 'this.iv'
|
|
241
149
|
throw new Error('Failed to retrieve IV from the device.');
|
|
242
150
|
}
|
|
243
151
|
}
|
|
244
152
|
return this.iv;
|
|
245
153
|
}
|
|
154
|
+
/**
|
|
155
|
+
* Sends an encrypted command to the device.
|
|
156
|
+
* @param {string} key - The command key.
|
|
157
|
+
* @returns {Promise<Buffer>} - The response buffer.
|
|
158
|
+
*/
|
|
246
159
|
async encryptedCommand(key) {
|
|
247
160
|
const iv = await this.getIv();
|
|
248
|
-
const req = Buffer.from(key.substring(0, 2) + this.key_id + Buffer.from(iv.subarray(0, 2)).toString('hex') + this.encrypt(key.substring(2)), 'hex');
|
|
161
|
+
const req = Buffer.from(key.substring(0, 2) + this.key_id + Buffer.from(iv.subarray(0, 2)).toString('hex') + await this.encrypt(key.substring(2)), 'hex');
|
|
249
162
|
const bytes = await this.command(req);
|
|
250
163
|
const buf = Buffer.from(bytes);
|
|
251
164
|
const code = WoSmartLock.validateResponse(buf);
|
|
@@ -256,24 +169,24 @@ export class WoSmartLock extends SwitchbotDevice {
|
|
|
256
169
|
throw new Error(`The device returned an error: 0x${buf.toString('hex')}`);
|
|
257
170
|
}
|
|
258
171
|
}
|
|
172
|
+
/**
|
|
173
|
+
* Operates the lock with the given command.
|
|
174
|
+
* @param {string} key - The command key.
|
|
175
|
+
* @param {boolean} [encrypt] - Whether to encrypt the command.
|
|
176
|
+
* @returns {Promise<Buffer>} - The response buffer.
|
|
177
|
+
*/
|
|
259
178
|
async operateLock(key, encrypt = true) {
|
|
260
|
-
// encrypted command
|
|
261
179
|
if (encrypt) {
|
|
262
|
-
return
|
|
180
|
+
return this.encryptedCommand(key);
|
|
263
181
|
}
|
|
264
182
|
const req = Buffer.from(`${key.substring(0, 2)}000000${key.substring(2)}`, 'hex');
|
|
265
|
-
await this.command(req)
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
return buf;
|
|
273
|
-
}
|
|
274
|
-
}).catch((error) => {
|
|
275
|
-
return error;
|
|
276
|
-
});
|
|
183
|
+
const bytes = await this.command(req);
|
|
184
|
+
const buf = Buffer.from(bytes);
|
|
185
|
+
const code = WoSmartLock.validateResponse(buf);
|
|
186
|
+
if (await code === WoSmartLock.Result.ERROR) {
|
|
187
|
+
throw new Error(`The device returned an error: 0x${buf.toString('hex')}`);
|
|
188
|
+
}
|
|
189
|
+
return buf;
|
|
277
190
|
}
|
|
278
191
|
}
|
|
279
192
|
//# sourceMappingURL=wosmartlock.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wosmartlock.js","sourceRoot":"","sources":["../../src/device/wosmartlock.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"wosmartlock.js","sourceRoot":"","sources":["../../src/device/wosmartlock.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AACpC,OAAO,KAAK,MAAM,MAAM,aAAa,CAAA;AAErC,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAA;AAC9C,OAAO,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAA;AACpD,OAAO,EAAE,iBAAiB,EAAE,6BAA6B,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAA;AAE3G;;;GAGG;AACH,MAAM,OAAO,WAAY,SAAQ,eAAe;IAC9C,MAAM,CAAC,YAAY,CAAc;IAC1B,EAAE,GAAkB,IAAI,CAAA;IACxB,MAAM,GAAW,EAAE,CAAA;IACnB,cAAc,GAAkB,IAAI,CAAA;IAE3C,MAAM,CAAC,MAAM,GAAG;QACd,KAAK,EAAE,IAAI;QACX,OAAO,EAAE,IAAI;QACb,mBAAmB,EAAE,IAAI;KAC1B,CAAA;IAED,MAAM,CAAC,KAAK,CAAC,gBAAgB,CAAC,GAAW;QACvC,IAAI,GAAG,CAAC,MAAM,IAAI,CAAC,EAAE,CAAC;YACpB,MAAM,MAAM,GAAG,GAAG,CAAC,SAAS,CAAC,CAAC,CAAC,CAAA;YAC/B,IAAI,MAAM,KAAK,WAAW,CAAC,MAAM,CAAC,OAAO,IAAI,MAAM,KAAK,WAAW,CAAC,MAAM,CAAC,mBAAmB,EAAE,CAAC;gBAC/F,OAAO,MAAM,CAAA;YACf,CAAC;QACH,CAAC;QACD,OAAO,WAAW,CAAC,MAAM,CAAC,KAAK,CAAA;IACjC,CAAC;IAED,MAAM,CAAC,aAAa,CAAC,IAAY;QA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5C,MAAM,IAAI,KAAK,CAAC,mCAAmC,GAAG,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC,CAAA;QAC3E,CAAC;QACD,OAAO,GAAG,CAAA;IACZ,CAAC"}
|
|
@@ -1,36 +1,81 @@
|
|
|
1
1
|
import type * as Noble from '@stoprocent/noble';
|
|
2
|
+
import type { SwitchBotBLE } from '../switchbot-ble.js';
|
|
2
3
|
import type { lockProServiceData } from '../types/bledevicestatus.js';
|
|
3
4
|
import { Buffer } from 'node:buffer';
|
|
4
5
|
import { SwitchbotDevice } from '../device.js';
|
|
6
|
+
/**
|
|
7
|
+
* Class representing a WoSmartLockPro device.
|
|
8
|
+
* @see https://github.com/OpenWonderLabs/SwitchBotAPI-BLE/blob/latest/devicetypes/lock.md
|
|
9
|
+
*/
|
|
5
10
|
export declare class WoSmartLockPro extends SwitchbotDevice {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
static COMMAND_LOCK_INFO: string;
|
|
11
|
-
static COMMAND_UNLOCK: string;
|
|
12
|
-
static COMMAND_UNLOCK_NO_UNLATCH: string;
|
|
13
|
-
static COMMAND_LOCK: string;
|
|
14
|
-
static COMMAND_ENABLE_NOTIFICATIONS: string;
|
|
15
|
-
static COMMAND_DISABLE_NOTIFICATIONS: string;
|
|
11
|
+
static switchBotBLE: SwitchBotBLE;
|
|
12
|
+
iv: Buffer | null;
|
|
13
|
+
key_id: string;
|
|
14
|
+
encryption_key: Buffer | null;
|
|
16
15
|
static Result: {
|
|
17
16
|
ERROR: number;
|
|
18
17
|
SUCCESS: number;
|
|
19
18
|
SUCCESS_LOW_BATTERY: number;
|
|
20
19
|
};
|
|
21
|
-
static validateResponse(res: Buffer): number
|
|
22
|
-
static getLockStatus(code: number):
|
|
23
|
-
static parseServiceData(serviceData: Buffer, manufacturerData: Buffer
|
|
20
|
+
static validateResponse(res: Buffer): Promise<number>;
|
|
21
|
+
static getLockStatus(code: number): string;
|
|
22
|
+
static parseServiceData(serviceData: Buffer, manufacturerData: Buffer): Promise<lockProServiceData | null>;
|
|
24
23
|
constructor(peripheral: Noble.Peripheral, noble: typeof Noble);
|
|
24
|
+
/**
|
|
25
|
+
* Initializes the encryption key info for valid lock communication.
|
|
26
|
+
* @param {string} keyId - The key ID.
|
|
27
|
+
* @param {string} encryptionKey - The encryption key.
|
|
28
|
+
*/
|
|
25
29
|
setKey(keyId: string, encryptionKey: string): Promise<void>;
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
+
/**
|
|
31
|
+
* Unlocks the Smart Lock.
|
|
32
|
+
* @returns {Promise<number>} - The result of the unlock operation.
|
|
33
|
+
*/
|
|
34
|
+
unlock(): Promise<number>;
|
|
35
|
+
/**
|
|
36
|
+
* Unlocks the Smart Lock without unlatching the door.
|
|
37
|
+
* @returns {Promise<number>} - The result of the unlock operation.
|
|
38
|
+
*/
|
|
39
|
+
unlockNoUnlatch(): Promise<number>;
|
|
40
|
+
/**
|
|
41
|
+
* Locks the Smart Lock.
|
|
42
|
+
* @returns {Promise<number>} - The result of the lock operation.
|
|
43
|
+
*/
|
|
44
|
+
lock(): Promise<number>;
|
|
45
|
+
/**
|
|
46
|
+
* Gets general state info from the Smart Lock.
|
|
47
|
+
* @returns {Promise<object | null>} - The state object or null if an error occurred.
|
|
48
|
+
*/
|
|
49
|
+
info(): Promise<object | null>;
|
|
50
|
+
/**
|
|
51
|
+
* Encrypts a string using AES-128-CTR.
|
|
52
|
+
* @param {string} str - The string to encrypt.
|
|
53
|
+
* @returns {Promise<string>} - The encrypted string in hex format.
|
|
54
|
+
*/
|
|
30
55
|
encrypt(str: string): Promise<string>;
|
|
56
|
+
/**
|
|
57
|
+
* Decrypts a buffer using AES-128-CTR.
|
|
58
|
+
* @param {Buffer} data - The data to decrypt.
|
|
59
|
+
* @returns {Promise<Buffer>} - The decrypted data.
|
|
60
|
+
*/
|
|
31
61
|
decrypt(data: Buffer): Promise<Buffer>;
|
|
62
|
+
/**
|
|
63
|
+
* Retrieves the IV from the device.
|
|
64
|
+
* @returns {Promise<Buffer>} - The IV buffer.
|
|
65
|
+
*/
|
|
32
66
|
getIv(): Promise<Buffer>;
|
|
67
|
+
/**
|
|
68
|
+
* Sends an encrypted command to the device.
|
|
69
|
+
* @param {string} key - The command key.
|
|
70
|
+
* @returns {Promise<Buffer>} - The response buffer.
|
|
71
|
+
*/
|
|
33
72
|
encryptedCommand(key: string): Promise<Buffer>;
|
|
34
|
-
|
|
73
|
+
/**
|
|
74
|
+
* Operates the lock with the given command.
|
|
75
|
+
* @param {string} key - The command key.
|
|
76
|
+
* @param {boolean} [encrypt] - Whether to encrypt the command.
|
|
77
|
+
* @returns {Promise<Buffer>} - The response buffer.
|
|
78
|
+
*/
|
|
79
|
+
operateLockPro(key: string, encrypt?: boolean): Promise<Buffer>;
|
|
35
80
|
}
|
|
36
81
|
//# sourceMappingURL=wosmartlockpro.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wosmartlockpro.d.ts","sourceRoot":"","sources":["../../src/device/wosmartlockpro.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"wosmartlockpro.d.ts","sourceRoot":"","sources":["../../src/device/wosmartlockpro.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,KAAK,KAAK,MAAM,mBAAmB,CAAA;AAE/C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAA;AACvD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,6BAA6B,CAAA;AAErE,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AAGpC,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAA;AAI9C;;;GAGG;AACH,qBAAa,cAAe,SAAQ,eAAe;IACjD,MAAM,CAAC,YAAY,EAAE,YAAY,CAAA;IAC1B,EAAE,EAAE,MAAM,GAAG,IAAI,CAAO;IACxB,MAAM,EAAE,MAAM,CAAK;IACn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