node-switchbot 2.5.0-beta.9 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/workflows/beta-release.yml +25 -2
- package/.github/workflows/release.yml +13 -0
- package/BLE.md +1144 -0
- package/CHANGELOG.md +14 -0
- package/OpenAPI.md +185 -0
- package/README.md +20 -1189
- package/branding/Node_x_SwitchBot.svg +9 -0
- package/branding/icon.png +0 -0
- package/branding/switchbot.png +0 -0
- package/dist/advertising.d.ts +3 -3
- package/dist/advertising.d.ts.map +1 -1
- package/dist/advertising.js +26 -26
- package/dist/advertising.js.map +1 -1
- package/dist/device/woblindtilt.d.ts +19 -50
- package/dist/device/woblindtilt.d.ts.map +1 -1
- package/dist/device/woblindtilt.js +41 -100
- package/dist/device/woblindtilt.js.map +1 -1
- package/dist/device/wobulb.d.ts +41 -15
- package/dist/device/wobulb.d.ts.map +1 -1
- package/dist/device/wobulb.js +72 -128
- package/dist/device/wobulb.js.map +1 -1
- package/dist/device/woceilinglight.d.ts +47 -21
- package/dist/device/woceilinglight.d.ts.map +1 -1
- package/dist/device/woceilinglight.js +96 -171
- package/dist/device/woceilinglight.js.map +1 -1
- package/dist/device/wocontact.d.ts +11 -1
- package/dist/device/wocontact.d.ts.map +1 -1
- package/dist/device/wocontact.js +23 -22
- package/dist/device/wocontact.js.map +1 -1
- package/dist/device/wocurtain.d.ts +39 -1
- package/dist/device/wocurtain.d.ts.map +1 -1
- package/dist/device/wocurtain.js +69 -103
- package/dist/device/wocurtain.js.map +1 -1
- package/dist/device/wohand.d.ts +37 -2
- package/dist/device/wohand.d.ts.map +1 -1
- package/dist/device/wohand.js +55 -89
- package/dist/device/wohand.js.map +1 -1
- package/dist/device/wohub2.d.ts +11 -1
- package/dist/device/wohub2.d.ts.map +1 -1
- package/dist/device/wohub2.js +21 -29
- package/dist/device/wohub2.js.map +1 -1
- package/dist/device/wohumi.d.ts +37 -2
- package/dist/device/wohumi.d.ts.map +1 -1
- package/dist/device/wohumi.js +52 -83
- package/dist/device/wohumi.js.map +1 -1
- package/dist/device/woiosensorth.d.ts +12 -1
- package/dist/device/woiosensorth.d.ts.map +1 -1
- package/dist/device/woiosensorth.js +25 -29
- package/dist/device/woiosensorth.js.map +1 -1
- package/dist/device/woplugmini.d.ts +45 -12
- package/dist/device/woplugmini.d.ts.map +1 -1
- package/dist/device/woplugmini.js +71 -77
- package/dist/device/woplugmini.js.map +1 -1
- package/dist/device/wopresence.d.ts +11 -1
- package/dist/device/wopresence.d.ts.map +1 -1
- package/dist/device/wopresence.js +21 -27
- package/dist/device/wopresence.js.map +1 -1
- package/dist/device/wosensorth.d.ts +18 -2
- package/dist/device/wosensorth.d.ts.map +1 -1
- package/dist/device/wosensorth.js +34 -50
- package/dist/device/wosensorth.js.map +1 -1
- package/dist/device/wosmartlock.d.ts +63 -13
- package/dist/device/wosmartlock.d.ts.map +1 -1
- package/dist/device/wosmartlock.js +114 -195
- package/dist/device/wosmartlock.js.map +1 -1
- package/dist/device/wosmartlockpro.d.ts +16 -12
- package/dist/device/wosmartlockpro.d.ts.map +1 -1
- package/dist/device/wosmartlockpro.js +34 -29
- package/dist/device/wosmartlockpro.js.map +1 -1
- package/dist/device/wostrip.d.ts +4 -3
- package/dist/device/wostrip.d.ts.map +1 -1
- package/dist/device/wostrip.js +5 -4
- package/dist/device/wostrip.js.map +1 -1
- package/dist/device.d.ts +13 -5
- package/dist/device.d.ts.map +1 -1
- package/dist/device.js +13 -2
- package/dist/device.js.map +1 -1
- package/dist/index.d.ts +9 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +9 -1
- package/dist/index.js.map +1 -1
- package/dist/parameter-checker.d.ts +10 -13
- package/dist/parameter-checker.d.ts.map +1 -1
- package/dist/parameter-checker.js +16 -1
- package/dist/parameter-checker.js.map +1 -1
- package/dist/settings.d.ts +41 -0
- package/dist/settings.d.ts.map +1 -1
- package/dist/settings.js +43 -0
- package/dist/settings.js.map +1 -1
- package/dist/{switchbot.d.ts → switchbot-ble.d.ts} +13 -8
- package/dist/switchbot-ble.d.ts.map +1 -0
- package/dist/switchbot-ble.js +427 -0
- package/dist/switchbot-ble.js.map +1 -0
- package/dist/switchbot-openapi.d.ts +131 -0
- package/dist/switchbot-openapi.d.ts.map +1 -0
- package/dist/switchbot-openapi.js +311 -0
- package/dist/switchbot-openapi.js.map +1 -0
- package/dist/test/advertising.test.d.ts +2 -0
- package/dist/test/advertising.test.d.ts.map +1 -0
- package/dist/test/advertising.test.js +99 -0
- package/dist/test/advertising.test.js.map +1 -0
- package/dist/test/device.test.d.ts +2 -0
- package/dist/test/device.test.d.ts.map +1 -0
- package/dist/test/device.test.js +38 -0
- package/dist/test/device.test.js.map +1 -0
- package/dist/test/index.test.d.ts +2 -0
- package/dist/test/index.test.d.ts.map +1 -0
- package/dist/test/index.test.js +35 -0
- package/dist/test/index.test.js.map +1 -0
- package/dist/test/parameter-checker.test.d.ts +2 -0
- package/dist/test/parameter-checker.test.d.ts.map +1 -0
- package/dist/test/parameter-checker.test.js +108 -0
- package/dist/test/parameter-checker.test.js.map +1 -0
- package/dist/test/settings.test.d.ts +2 -0
- package/dist/test/settings.test.d.ts.map +1 -0
- package/dist/test/settings.test.js +49 -0
- package/dist/test/settings.test.js.map +1 -0
- package/dist/test/switchbot-openapi.test.d.ts +2 -0
- package/dist/test/switchbot-openapi.test.d.ts.map +1 -0
- package/dist/test/switchbot-openapi.test.js +96 -0
- package/dist/test/switchbot-openapi.test.js.map +1 -0
- package/dist/test/switchbot.test.d.ts +2 -0
- package/dist/test/switchbot.test.d.ts.map +1 -0
- package/dist/test/switchbot.test.js +106 -0
- package/dist/test/switchbot.test.js.map +1 -0
- package/dist/test/woblindtilt.test.js +70 -20
- package/dist/test/woblindtilt.test.js.map +1 -1
- package/dist/test/wobulb.test.js +87 -44
- package/dist/test/wobulb.test.js.map +1 -1
- package/dist/test/woceilinglight.test.js +72 -54
- package/dist/test/woceilinglight.test.js.map +1 -1
- package/dist/test/wocontact.test.js +51 -20
- package/dist/test/wocontact.test.js.map +1 -1
- package/dist/test/wocurtain.test.js +65 -23
- package/dist/test/wocurtain.test.js.map +1 -1
- package/dist/test/wohand.test.js +34 -40
- package/dist/test/wohand.test.js.map +1 -1
- package/dist/test/wohub2.test.d.ts +2 -0
- package/dist/test/wohub2.test.d.ts.map +1 -0
- package/dist/test/wohub2.test.js +80 -0
- package/dist/test/wohub2.test.js.map +1 -0
- package/dist/test/wohumi.test.js +70 -49
- package/dist/test/wohumi.test.js.map +1 -1
- package/dist/test/woiosensorth.test.js +33 -32
- package/dist/test/woiosensorth.test.js.map +1 -1
- package/dist/test/woplugmini.test.js +80 -57
- package/dist/test/woplugmini.test.js.map +1 -1
- package/dist/test/wopresence.test.js +44 -18
- package/dist/test/wopresence.test.js.map +1 -1
- package/dist/test/wosensorth.test.js +44 -52
- package/dist/test/wosensorth.test.js.map +1 -1
- package/dist/test/wosmartlock.test.js +126 -59
- package/dist/test/wosmartlock.test.js.map +1 -1
- package/dist/test/wosmartlockpro.test.js +96 -69
- package/dist/test/wosmartlockpro.test.js.map +1 -1
- package/dist/test/wostrip.test.js +70 -83
- package/dist/test/wostrip.test.js.map +1 -1
- package/dist/types/bledevicestatus.d.ts +4 -12
- package/dist/types/bledevicestatus.d.ts.map +1 -1
- package/dist/types/devicelist.d.ts.map +1 -1
- package/dist/types/devicelist.js +0 -4
- package/dist/types/devicelist.js.map +1 -1
- package/dist/types/devicepush.d.ts +13 -0
- package/dist/types/devicepush.d.ts.map +1 -0
- package/dist/types/devicepush.js +2 -0
- package/dist/types/devicepush.js.map +1 -0
- package/dist/types/deviceresponse.d.ts +2 -3
- package/dist/types/deviceresponse.d.ts.map +1 -1
- package/dist/types/devicestatus.d.ts.map +1 -1
- package/dist/types/devicewebhookstatus.d.ts +32 -0
- package/dist/types/devicewebhookstatus.d.ts.map +1 -1
- package/dist/types/irdevicelist.d.ts.map +1 -1
- package/dist/types/types.d.ts +23 -0
- package/dist/types/types.d.ts.map +1 -1
- package/dist/types/types.js +14 -0
- package/dist/types/types.js.map +1 -1
- package/docs/assets/highlight.css +12 -47
- package/docs/assets/main.js +1 -1
- package/docs/assets/navigation.js +1 -1
- package/docs/assets/search.js +1 -1
- package/docs/classes/SwitchBotBLE.html +64 -0
- package/docs/classes/SwitchBotOpenAPI.html +47 -0
- package/docs/classes/SwitchbotDevice.html +32 -33
- package/docs/enums/LogLevel.html +10 -0
- package/docs/enums/SwitchBotBLEModel.html +2 -2
- package/docs/enums/SwitchBotBLEModelFriendlyName.html +2 -2
- package/docs/enums/SwitchBotBLEModelName.html +2 -2
- package/docs/enums/SwitchBotModel.html +2 -2
- package/docs/hierarchy.html +1 -0
- package/docs/index.html +16 -993
- package/docs/interfaces/Ad-1.html +5 -0
- package/docs/interfaces/AdvertisementData.html +3 -0
- package/docs/interfaces/Chars.html +4 -0
- package/docs/interfaces/ErrorObject.html +3 -0
- package/docs/interfaces/Params.html +6 -0
- package/docs/interfaces/ServiceData.html +2 -0
- package/docs/interfaces/SwitchBotBLEDevice.html +21 -0
- package/docs/interfaces/WebhookDetail.html +6 -0
- package/docs/interfaces/ad.html +5 -0
- package/docs/interfaces/body.html +3 -0
- package/docs/interfaces/bodyChange.html +4 -0
- package/docs/interfaces/deleteWebhookResponse.html +4 -0
- package/docs/interfaces/device.html +7 -0
- package/docs/interfaces/deviceList.html +2 -0
- package/docs/interfaces/deviceStatus.html +7 -0
- package/docs/interfaces/deviceStatusRequest.html +4 -0
- package/docs/interfaces/deviceWebhook.html +4 -0
- package/docs/interfaces/deviceWebhookContext.html +4 -0
- package/docs/interfaces/devices.html +4 -0
- package/docs/interfaces/infraredRemoteList.html +2 -0
- package/docs/interfaces/irdevice.html +5 -0
- package/docs/interfaces/pushResponse.html +4 -0
- package/docs/interfaces/queryWebhookResponse.html +4 -0
- package/docs/interfaces/setupWebhookResponse.html +4 -0
- package/docs/interfaces/switchbot.html +3 -0
- package/docs/interfaces/updateWebhookResponse.html +4 -0
- package/docs/interfaces/webhookRequest.html +4 -0
- package/docs/media/BLE.md +1109 -0
- package/docs/media/OpenAPI.md +185 -0
- package/docs/modules.html +136 -3
- package/docs/types/MacAddress.html +1 -0
- package/docs/types/batteryCirculatorFan.html +1 -0
- package/docs/types/batteryCirculatorFanServiceData.html +1 -0
- package/docs/types/batteryCirculatorFanStatus.html +1 -0
- package/docs/types/batteryCirculatorFanWebhookContext.html +1 -0
- package/docs/types/blindTilt.html +1 -0
- package/docs/types/blindTiltServiceData.html +1 -0
- package/docs/types/blindTiltStatus.html +1 -0
- package/docs/types/blindTiltWebhookContext.html +1 -0
- package/docs/types/bot.html +1 -0
- package/docs/types/botServiceData.html +1 -0
- package/docs/types/botStatus.html +1 -0
- package/docs/types/botWebhookContext.html +1 -0
- package/docs/types/ceilingLight.html +1 -0
- package/docs/types/ceilingLightPro.html +1 -0
- package/docs/types/ceilingLightProServiceData.html +1 -0
- package/docs/types/ceilingLightProStatus.html +1 -0
- package/docs/types/ceilingLightProWebhookContext.html +1 -0
- package/docs/types/ceilingLightServiceData.html +1 -0
- package/docs/types/ceilingLightStatus.html +1 -0
- package/docs/types/ceilingLightWebhookContext.html +1 -0
- package/docs/types/colorBulb.html +1 -0
- package/docs/types/colorBulbServiceData.html +1 -0
- package/docs/types/colorBulbStatus.html +1 -0
- package/docs/types/colorBulbWebhookContext.html +1 -0
- package/docs/types/contactSensor.html +1 -0
- package/docs/types/contactSensorServiceData.html +1 -0
- package/docs/types/contactSensorStatus.html +1 -0
- package/docs/types/contactSensorWebhookContext.html +1 -0
- package/docs/types/curtain.html +1 -0
- package/docs/types/curtain3.html +1 -0
- package/docs/types/curtain3ServiceData.html +1 -0
- package/docs/types/curtain3WebhookContext.html +1 -0
- package/docs/types/curtainServiceData.html +1 -0
- package/docs/types/curtainStatus.html +1 -0
- package/docs/types/curtainWebhookContext.html +1 -0
- package/docs/types/floorCleaningRobotS10.html +1 -0
- package/docs/types/floorCleaningRobotS10Status.html +1 -0
- package/docs/types/floorCleaningRobotS10WebhookContext.html +1 -0
- package/docs/types/hub2.html +1 -0
- package/docs/types/hub2ServiceData.html +1 -0
- package/docs/types/hub2Status.html +1 -0
- package/docs/types/hub2WebhookContext.html +1 -0
- package/docs/types/humidifier.html +1 -0
- package/docs/types/humidifierServiceData.html +1 -0
- package/docs/types/humidifierStatus.html +1 -0
- package/docs/types/humidifierWebhookContext.html +1 -0
- package/docs/types/indoorCam.html +1 -0
- package/docs/types/indoorCameraWebhookContext.html +1 -0
- package/docs/types/keypad.html +1 -0
- package/docs/types/keypadTouch.html +1 -0
- package/docs/types/keypadTouchWebhookContext.html +1 -0
- package/docs/types/keypadWebhookContext.html +1 -0
- package/docs/types/lock.html +1 -0
- package/docs/types/lockPro.html +1 -0
- package/docs/types/lockProServiceData.html +1 -0
- package/docs/types/lockProStatus.html +1 -0
- package/docs/types/lockProWebhookContext.html +1 -0
- package/docs/types/lockServiceData.html +1 -0
- package/docs/types/lockStatus.html +1 -0
- package/docs/types/lockWebhookContext.html +1 -0
- package/docs/types/meter.html +1 -0
- package/docs/types/meterPlus.html +1 -0
- package/docs/types/meterPlusServiceData.html +1 -0
- package/docs/types/meterPlusStatus.html +1 -0
- package/docs/types/meterPlusWebhookContext.html +1 -0
- package/docs/types/meterServiceData.html +1 -0
- package/docs/types/meterStatus.html +1 -0
- package/docs/types/meterWebhookContext.html +1 -0
- package/docs/types/motionSensor.html +1 -0
- package/docs/types/motionSensorServiceData.html +1 -0
- package/docs/types/motionSensorStatus.html +1 -0
- package/docs/types/motionSensorWebhookContext.html +1 -0
- package/docs/types/outdoorMeter.html +1 -0
- package/docs/types/outdoorMeterServiceData.html +1 -0
- package/docs/types/outdoorMeterStatus.html +1 -0
- package/docs/types/outdoorMeterWebhookContext.html +1 -0
- package/docs/types/panTiltCamWebhookContext.html +1 -0
- package/docs/types/pantiltCam.html +1 -0
- package/docs/types/pantiltCam2k.html +1 -0
- package/docs/types/plug.html +1 -0
- package/docs/types/plugMini.html +1 -0
- package/docs/types/plugMiniJPServiceData.html +1 -0
- package/docs/types/plugMiniJPWebhookContext.html +1 -0
- package/docs/types/plugMiniStatus.html +1 -0
- package/docs/types/plugMiniUSServiceData.html +1 -0
- package/docs/types/plugMiniUSWebhookContext.html +1 -0
- package/docs/types/plugStatus.html +1 -0
- package/docs/types/plugWebhookContext.html +1 -0
- package/docs/types/remote.html +1 -0
- package/docs/types/robotVacuumCleanerS1.html +1 -0
- package/docs/types/robotVacuumCleanerS1Plus.html +1 -0
- package/docs/types/robotVacuumCleanerS1PlusStatus.html +1 -0
- package/docs/types/robotVacuumCleanerS1PlusWebhookContext.html +1 -0
- package/docs/types/robotVacuumCleanerS1Status.html +1 -0
- package/docs/types/robotVacuumCleanerS1WebhookContext.html +1 -0
- package/docs/types/robotVacuumCleanerServiceData.html +1 -0
- package/docs/types/stripLight.html +1 -0
- package/docs/types/stripLightServiceData.html +1 -0
- package/docs/types/stripLightStatus.html +1 -0
- package/docs/types/stripLightWebhookContext.html +1 -0
- package/docs/types/waterLeakDetector.html +1 -0
- package/docs/types/waterLeakDetectorServiceData.html +1 -0
- package/docs/types/waterLeakDetectorStatus.html +1 -0
- package/docs/types/waterLeakDetectorWebhookContext.html +1 -0
- package/package.json +13 -11
- package/.github/npm-version-script.cjs +0 -81
- package/dist/switchbot.d.ts.map +0 -1
- package/dist/switchbot.js +0 -259
- package/dist/switchbot.js.map +0 -1
- package/dist/test/wohand2.test.d.ts +0 -2
- package/dist/test/wohand2.test.d.ts.map +0 -1
- package/dist/test/wohand2.test.js +0 -50
- package/dist/test/wohand2.test.js.map +0 -1
- package/dist/types/pushbody.d.ts +0 -6
- package/dist/types/pushbody.d.ts.map +0 -1
- package/dist/types/pushbody.js +0 -2
- package/dist/types/pushbody.js.map +0 -1
- package/docs/classes/SwitchBot.html +0 -16
- package/docs/types/SwitchBotBLEDevice.html +0 -1
package/docs/index.html
CHANGED
|
@@ -1,998 +1,21 @@
|
|
|
1
|
-
<!DOCTYPE html><html class="default" lang="en"><head><meta charset="utf-8"/><meta http-equiv="x-ua-compatible" content="IE=edge"/><title>node-switchbot</title><meta name="description" content="Documentation for node-switchbot"/><meta name="viewport" content="width=device-width, initial-scale=1"/><link rel="stylesheet" href="assets/style.css"/><link rel="stylesheet" href="assets/highlight.css"/><script defer src="assets/main.js"></script><script async src="assets/icons.js" id="tsd-icons-script"></script><script async src="assets/search.js" id="tsd-search-script"></script><script async src="assets/navigation.js" id="tsd-nav-script"></script></head><body><script>document.documentElement.dataset.theme = localStorage.getItem("tsd-theme") || "os";document.body.style.display="none";setTimeout(() => app?app.showPage():document.body.style.removeProperty("display"),500)</script><header class="tsd-page-toolbar"><div class="tsd-toolbar-contents container"><div class="table-cell" id="tsd-search" data-base="."><div class="field"><label for="tsd-search-field" class="tsd-widget tsd-toolbar-icon search no-caption"><svg width="16" height="16" viewBox="0 0 16 16" fill="none"><use href="assets/icons.svg#icon-search"></use></svg></label><input type="text" id="tsd-search-field" aria-label="Search"/></div><div class="field"><div id="tsd-toolbar-links"></div></div><ul class="results"><li class="state loading">Preparing search index...</li><li class="state failure">The search index is not available</li></ul><a href="index.html" class="title">node-switchbot</a></div><div class="table-cell" id="tsd-widgets"><a href="#" class="tsd-widget tsd-toolbar-icon menu no-caption" data-toggle="menu" aria-label="Menu"><svg width="16" height="16" viewBox="0 0 16 16" fill="none"><use href="assets/icons.svg#icon-menu"></use></svg></a></div></div></header><div class="container container-main"><div class="col-content"><div class="tsd-page-title"><h2>node-switchbot</h2></div><div class="tsd-panel tsd-typography"><
|
|
2
|
-
<
|
|
3
|
-
<a href="https://www.npmjs.com/package/node-switchbot"
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
and <a href="https://www.switch-bot.com/products/contact-sensor">SwitchBot Contact Sensor</a></p>
|
|
10
|
-
<p>This module is unofficial. It was developed by reference to <a href="https://github.com/OpenWonderLabs/python-host">the official python code</a>.
|
|
11
|
-
But some functionalities of this module were developed through trial and error. So some information obtained from this module might be wrong.</p>
|
|
1
|
+
<!DOCTYPE html><html class="default" lang="en"><head><meta charset="utf-8"/><meta http-equiv="x-ua-compatible" content="IE=edge"/><title>node-switchbot</title><meta name="description" content="Documentation for node-switchbot"/><meta name="viewport" content="width=device-width, initial-scale=1"/><link rel="stylesheet" href="assets/style.css"/><link rel="stylesheet" href="assets/highlight.css"/><script defer src="assets/main.js"></script><script async src="assets/icons.js" id="tsd-icons-script"></script><script async src="assets/search.js" id="tsd-search-script"></script><script async src="assets/navigation.js" id="tsd-nav-script"></script></head><body><script>document.documentElement.dataset.theme = localStorage.getItem("tsd-theme") || "os";document.body.style.display="none";setTimeout(() => app?app.showPage():document.body.style.removeProperty("display"),500)</script><header class="tsd-page-toolbar"><div class="tsd-toolbar-contents container"><div class="table-cell" id="tsd-search" data-base="."><div class="field"><label for="tsd-search-field" class="tsd-widget tsd-toolbar-icon search no-caption"><svg width="16" height="16" viewBox="0 0 16 16" fill="none"><use href="assets/icons.svg#icon-search"></use></svg></label><input type="text" id="tsd-search-field" aria-label="Search"/></div><div class="field"><div id="tsd-toolbar-links"></div></div><ul class="results"><li class="state loading">Preparing search index...</li><li class="state failure">The search index is not available</li></ul><a href="index.html" class="title">node-switchbot</a></div><div class="table-cell" id="tsd-widgets"><a href="#" class="tsd-widget tsd-toolbar-icon menu no-caption" data-toggle="menu" aria-label="Menu"><svg width="16" height="16" viewBox="0 0 16 16" fill="none"><use href="assets/icons.svg#icon-menu"></use></svg></a></div></div></header><div class="container container-main"><div class="col-content"><div class="tsd-page-title"><h2>node-switchbot</h2></div><div class="tsd-panel tsd-typography"><div align="center">
|
|
2
|
+
<p><img src="https://raw.githubusercontent.com/OpenWonderLabs/node-switchbot/latest/branding/Node_x_SwitchBot.svg?sanitize=true" alt="node-switchbot"></p>
|
|
3
|
+
<a id="md:node-switchbot" class="tsd-anchor"></a><h1 class="tsd-anchor-link">Node-SwitchBot<a href="#md:node-switchbot" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24"><use href="assets/icons.svg#icon-anchor"></use></svg></a></h1><p><a href="https://www.npmjs.com/package/node-switchbot" target="_blank" class="external"><img src="https://badgen.net/npm/v/node-switchbot" alt="npm version"></a>
|
|
4
|
+
<a href="https://www.npmjs.com/package/node-switchbot" target="_blank" class="external"><img src="https://badgen.net/npm/dt/node-switchbot" alt="npm downloads"></a></p>
|
|
5
|
+
</div>
|
|
6
|
+
<p>The <code>node-switchbot</code> is a Node.js module that allows you to interact with various SwitchBot devices. You can control your <a href="https://www.switch-bot.com/bot" target="_blank" class="external">SwitchBot (Bot)'s</a> arm, operate your <a href="https://www.switch-bot.com/products/switchbot-curtain" target="_blank" class="external">SwitchBot Curtain</a>, and manage your <a href="https://www.switch-bot.com/products/switchbot-lock" target="_blank" class="external">SwitchBot Lock</a>. Additionally, you can monitor temperature and humidity using the <a href="https://www.switch-bot.com/meter" target="_blank" class="external">SwitchBot Thermometer & Hygrometer (Meter)</a>, and check the status of the <a href="https://www.switch-bot.com/products/motion-sensor" target="_blank" class="external">SwitchBot Motion Sensor</a> and <a href="https://www.switch-bot.com/products/contact-sensor" target="_blank" class="external">SwitchBot Contact Sensor</a>.</p>
|
|
7
|
+
<p>This module now supports both Bluetooth Low Energy (BLE) and the SwitchBot OpenAPI, providing more flexibility and options for interacting with your devices.</p>
|
|
8
|
+
<p>Please note that most of this module was developed by referencing the official <a href="https://github.com/OpenWonderLabs/SwitchBotAPI-BLE" target="_blank" class="external">BLE API</a> and <a href="https://github.com/OpenWonderLabs/SwitchBotAPI" target="_blank" class="external">OpenAPI</a> documentation. However, some functionalities were developed through trial and error, so there might be inaccuracies in the information obtained from this module.</p>
|
|
12
9
|
<hr>
|
|
13
|
-
<a id="md:
|
|
14
|
-
<
|
|
15
|
-
<ul>
|
|
16
|
-
<li><a href="#md:table-of-contents">Table of Contents</a></li>
|
|
17
|
-
<li><a href="#md:supported-os">Supported OS</a></li>
|
|
18
|
-
<li><a href="#md:dependencies">Dependencies</a></li>
|
|
19
|
-
<li><a href="#md:installation">Installation</a></li>
|
|
20
|
-
<li><a href="#md:quick-start">Quick Start</a>
|
|
21
|
-
<ul>
|
|
22
|
-
<li><a href="#md:monitoring-advertising-packets">Monitoring Advertising packets</a></li>
|
|
23
|
-
<li><a href="#md:moving-the-arm-of-the-bot">Moving the arm of the Bot</a></li>
|
|
24
|
-
</ul>
|
|
25
|
-
</li>
|
|
26
|
-
<li><a href="#md:switchbot-object"><code>Switchbot</code> object</a>
|
|
27
|
-
<ul>
|
|
28
|
-
<li><a href="#md:discover-method"><code>discover()</code> method</a></li>
|
|
29
|
-
<li><a href="#md:ondiscover-event-handler"><code>ondiscover</code> event handler</a></li>
|
|
30
|
-
<li><a href="#md:startscan-method"><code>startScan()</code> method</a></li>
|
|
31
|
-
<li><a href="#md:stopscan-method"><code>stopScan()</code> method</a></li>
|
|
32
|
-
<li><a href="#md:onadvertisement-event-handler"><code>onadvertisement</code> event handler</a></li>
|
|
33
|
-
<li><a href="#md:wait-method"><code>wait()</code> method</a></li>
|
|
34
|
-
</ul>
|
|
35
|
-
</li>
|
|
36
|
-
<li><a href="#md:switchbotdevice-object"><code>SwitchbotDevice</code> object</a>
|
|
37
|
-
<ul>
|
|
38
|
-
<li><a href="#md:properties">Properties</a></li>
|
|
39
|
-
<li><a href="#md:getdevicename-method"><code>getDeviceName()</code> method</a></li>
|
|
40
|
-
<li><a href="#md:setdevicename-method"><code>setDeviceName()</code> method</a></li>
|
|
41
|
-
<li><a href="#md:connect-method"><code>connect()</code> method</a></li>
|
|
42
|
-
<li><a href="#md:disconnect-method"><code>disconnect()</code> method</a></li>
|
|
43
|
-
<li><a href="#md:onconnect-event-handler"><code>onconnect</code> event handler</a></li>
|
|
44
|
-
<li><a href="#md:ondisconnect-event-handler"><code>ondisconnect</code> event handler</a></li>
|
|
45
|
-
</ul>
|
|
46
|
-
</li>
|
|
47
|
-
<li><a href="#md:wohand-object"><code>WoHand</code> object</a>
|
|
48
|
-
<ul>
|
|
49
|
-
<li><a href="#md:press-method"><code>press()</code> method</a></li>
|
|
50
|
-
<li><a href="#md:turnon-method"><code>turnOn()</code> method</a></li>
|
|
51
|
-
<li><a href="#md:turnoff-method"><code>turnOff()</code> method</a></li>
|
|
52
|
-
<li><a href="#md:down-method"><code>down()</code> method</a></li>
|
|
53
|
-
<li><a href="#md:up-method"><code>up()</code> method</a></li>
|
|
54
|
-
</ul>
|
|
55
|
-
</li>
|
|
56
|
-
<li><a href="#md:wocurtain-object"><code>WoCurtain</code> object</a>
|
|
57
|
-
<ul>
|
|
58
|
-
<li><a href="#md:open-method"><code>open()</code> method</a></li>
|
|
59
|
-
<li><a href="#md:close-method"><code>close()</code> method</a></li>
|
|
60
|
-
<li><a href="#md:pause-method"><code>pause()</code> method</a></li>
|
|
61
|
-
<li><a href="#md:runtopos-method"><code>runToPos()</code> method</a></li>
|
|
62
|
-
</ul>
|
|
63
|
-
</li>
|
|
64
|
-
<li><a href="#md:woplugmini-object"><code>WoPlugMini</code> object</a>
|
|
65
|
-
<ul>
|
|
66
|
-
<li><a href="#md:turnon-method"><code>turnOn()</code> method</a></li>
|
|
67
|
-
<li><a href="#md:turnoff-method"><code>turnOff()</code> method</a></li>
|
|
68
|
-
<li><a href="#md:toggle-method"><code>toggle()</code> method</a></li>
|
|
69
|
-
</ul>
|
|
70
|
-
</li>
|
|
71
|
-
<li><a href="#md:wosmartlock-object"><code>WoSmartLock</code> object</a>
|
|
72
|
-
<ul>
|
|
73
|
-
<li><a href="#md:lock-method"><code>lock()</code> method</a></li>
|
|
74
|
-
<li><a href="#md:unlock-method"><code>unlock()</code> method</a></li>
|
|
75
|
-
<li><a href="#md:unlock_no_unlatch-method"><code>unlock_no_unlatch()</code> method</a></li>
|
|
76
|
-
<li><a href="#md:info-method"><code>info()</code> method</a></li>
|
|
77
|
-
</ul>
|
|
78
|
-
</li>
|
|
79
|
-
<li><a href="#md:advertisement-data">Advertisement data</a>
|
|
80
|
-
<ul>
|
|
81
|
-
<li><a href="#md:bot-wohand">Bot (WoHand)</a></li>
|
|
82
|
-
<li><a href="#md:meter-wosensorth">Meter (WoSensorTH)</a></li>
|
|
83
|
-
<li><a href="#md:curtain-wocurtain">Curtain (WoCurtain)</a></li>
|
|
84
|
-
<li><a href="#md:contact-wocontact">Contact (WoContact)</a></li>
|
|
85
|
-
<li><a href="#md:motion-womotion">Motion (WoMotion)</a></li>
|
|
86
|
-
<li><a href="#md:plugmini-woplugmini">PlugMini (WoPlugMini)</a></li>
|
|
87
|
-
</ul>
|
|
88
|
-
</li>
|
|
89
|
-
<li><a href="#md:release-note">Release Note</a></li>
|
|
90
|
-
<li><a href="#md:references">References</a></li>
|
|
91
|
-
<li><a href="#md:license">License</a></li>
|
|
92
|
-
</ul>
|
|
93
|
-
</li>
|
|
94
|
-
</ul>
|
|
95
|
-
<a id="md:supported-os" class="tsd-anchor"></a><h2 class="tsd-anchor-link">Supported OS<a href="#md:supported-os" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24"><use href="assets/icons.svg#icon-anchor"></use></svg></a></h2><p>The node-switchbot supports only Linux-based OSes, such as Raspbian, Ubuntu, and so on. This module does not support Windows and macOS for now. (If <a href="https://github.com/abandonware/noble">@abandonware/noble</a> is installed properly, this module might work well on such OSes.)</p>
|
|
96
|
-
<a id="md:dependencies" class="tsd-anchor"></a><h2 class="tsd-anchor-link">Dependencies<a href="#md:dependencies" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24"><use href="assets/icons.svg#icon-anchor"></use></svg></a></h2><ul>
|
|
97
|
-
<li><a href="https://nodejs.org/en/">Node.js</a> 10 +</li>
|
|
98
|
-
<li><a href="https://github.com/abandonware/noble">@abandonware/noble</a></li>
|
|
99
|
-
</ul>
|
|
100
|
-
<p>See the document of the <a href="https://github.com/abandonware/noble">@abandonware/noble</a> for details on installing the <a href="https://github.com/abandonware/noble">@abandonware/noble</a>.</p>
|
|
101
|
-
<p>Note that the noble must be run as root on most of Linux environments. See the document of the <a href="https://github.com/abandonware/noble">@abandonware/noble</a> for details.</p>
|
|
102
|
-
<a id="md:installation" class="tsd-anchor"></a><h2 class="tsd-anchor-link">Installation<a href="#md:installation" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24"><use href="assets/icons.svg#icon-anchor"></use></svg></a></h2><p>Before installing the <a href="https://github.com/abandonware/noble">@abandonware/noble</a>, some linux libraries related Bluetooth as follows if the OS is Ubuntu/Debian/Raspbian.</p>
|
|
103
|
-
<pre><code><span class="hl-0">$</span><span class="hl-1"> </span><span class="hl-0">sudo</span><span class="hl-1"> </span><span class="hl-0">apt</span><span class="hl-1">-</span><span class="hl-0">get</span><span class="hl-1"> </span><span class="hl-0">install</span><span class="hl-1"> </span><span class="hl-0">bluetooth</span><span class="hl-1"> </span><span class="hl-0">bluez</span><span class="hl-1"> </span><span class="hl-0">libbluetooth</span><span class="hl-1">-</span><span class="hl-0">dev</span><span class="hl-1"> </span><span class="hl-0">libudev</span><span class="hl-1">-</span><span class="hl-0">dev</span>
|
|
104
|
-
</code><button>Copy</button></pre>
|
|
105
|
-
|
|
106
|
-
<p>If you use other OS, follow the instructions described in the document of the <a href="https://github.com/abandonware/noble">@abandonware/noble</a>.</p>
|
|
107
|
-
<p>After installing the libraries above, install the <a href="https://github.com/abandonware/noble">@abandonware/noble</a> and the node-switchbot (this module) as follows:</p>
|
|
108
|
-
<pre><code><span class="hl-0">$</span><span class="hl-1"> </span><span class="hl-0">cd</span><span class="hl-1"> ~</span><br/><span class="hl-0">$</span><span class="hl-1"> </span><span class="hl-0">npm</span><span class="hl-1"> </span><span class="hl-0">install</span><span class="hl-1"> @</span><span class="hl-0">abandonware</span><span class="hl-1">/</span><span class="hl-0">noble</span><br/><span class="hl-0">$</span><span class="hl-1"> </span><span class="hl-0">npm</span><span class="hl-1"> </span><span class="hl-0">install</span><span class="hl-1"> </span><span class="hl-0">node</span><span class="hl-1">-</span><span class="hl-0">switchbot</span>
|
|
109
|
-
</code><button>Copy</button></pre>
|
|
110
|
-
|
|
111
|
-
<hr>
|
|
112
|
-
<a id="md:quick-start" class="tsd-anchor"></a><h2 class="tsd-anchor-link">Quick Start<a href="#md:quick-start" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24"><use href="assets/icons.svg#icon-anchor"></use></svg></a></h2><a id="md:monitoring-advertising-packets" class="tsd-anchor"></a><h3 class="tsd-anchor-link">Monitoring Advertising packets<a href="#md:monitoring-advertising-packets" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24"><use href="assets/icons.svg#icon-anchor"></use></svg></a></h3><p>Monitoring the advertising packets, you can find your devices and know the latest state of each device. The packet contains the settings of the device, the arm position of the Bot, the temperature and humidity of the Meter, and so on.</p>
|
|
113
|
-
<pre><code class="Typescript"><span class="hl-2">// Load the node-switchbot and get a `Switchbot` constructor object</span><br/><span class="hl-3">import</span><span class="hl-1"> { </span><span class="hl-0">SwitchBot</span><span class="hl-1"> } </span><span class="hl-3">from</span><span class="hl-1"> </span><span class="hl-4">'node-switchbot'</span><span class="hl-1">;</span><br/><span class="hl-2">// Create a `Switchbot` object</span><br/><span class="hl-5">const</span><span class="hl-1"> </span><span class="hl-6">switchbot</span><span class="hl-1"> = </span><span class="hl-5">new</span><span class="hl-1"> </span><span class="hl-7">SwitchBot</span><span class="hl-1">();</span><br/><br/><span class="hl-1">(</span><span class="hl-5">async</span><span class="hl-1"> () </span><span class="hl-5">=></span><span class="hl-1"> {</span><br/><span class="hl-1"> </span><span class="hl-2">// Start to monitor advertisement packets</span><br/><span class="hl-1"> </span><span class="hl-3">await</span><span class="hl-1"> </span><span class="hl-0">switchbot</span><span class="hl-1">.</span><span class="hl-7">startScan</span><span class="hl-1">();</span><br/><span class="hl-1"> </span><span class="hl-2">// Set an event handler</span><br/><span class="hl-1"> </span><span class="hl-0">switchbot</span><span class="hl-1">.</span><span class="hl-7">onadvertisement</span><span class="hl-1"> = (</span><span class="hl-0">ad</span><span class="hl-1">) </span><span class="hl-5">=></span><span class="hl-1"> {</span><br/><span class="hl-1"> </span><span class="hl-0">console</span><span class="hl-1">.</span><span class="hl-7">log</span><span class="hl-1">(</span><span class="hl-6">JSON</span><span class="hl-1">.</span><span class="hl-7">stringify</span><span class="hl-1">(</span><span class="hl-0">ad</span><span class="hl-1">, </span><span class="hl-5">null</span><span class="hl-1">, </span><span class="hl-4">' '</span><span class="hl-1">));</span><br/><span class="hl-1"> };</span><br/><span class="hl-1"> </span><span class="hl-2">// Wait 10 seconds</span><br/><span class="hl-1"> </span><span class="hl-3">await</span><span class="hl-1"> </span><span class="hl-0">switchbot</span><span class="hl-1">.</span><span class="hl-7">wait</span><span class="hl-1">(</span><span class="hl-8">10000</span><span class="hl-1">);</span><br/><span class="hl-1"> </span><span class="hl-2">// Stop to monitor</span><br/><span class="hl-1"> </span><span class="hl-0">switchbot</span><span class="hl-1">.</span><span class="hl-7">stopScan</span><span class="hl-1">();</span><br/><span class="hl-1"> </span><span class="hl-0">process</span><span class="hl-1">.</span><span class="hl-7">exit</span><span class="hl-1">();</span><br/><span class="hl-1">})();</span>
|
|
114
|
-
</code><button type="button">Copy</button></pre>
|
|
115
|
-
|
|
116
|
-
<p>The <a href="#md:startscan-method"><code>startScan()</code></a> methods starts to monitor advertisement packets. In order to receive the packets, you have to assign a callback function to the <a href="#md:Switchbot-onadvertisement-event-handler"><code>onadvertisement</code></a>.</p>
|
|
117
|
-
<p>The <a href="#md:Switchbot-wait-method"><code>wait()</code></a> method is just a utility method, which wait for the specified milliseconds.</p>
|
|
118
|
-
<p>The <a href="#md:startscan-method"><code>startScan()</code></a> and <a href="#md:Switchbot-wait-method"><code>wait()</code></a> methods are asynchronous, they return a <code>Promise</code> object. You can write code in promise style as well. What the code below does is as same as what the code above does:</p>
|
|
119
|
-
<pre><code class="Typescript"><span class="hl-2">// Load the node-switchbot and get a `Switchbot` constructor object</span><br/><span class="hl-5">const</span><span class="hl-1"> </span><span class="hl-6">Switchbot</span><span class="hl-1"> = </span><span class="hl-7">require</span><span class="hl-1">(</span><span class="hl-4">"node-switchbot"</span><span class="hl-1">);</span><br/><span class="hl-2">// Create a `Switchbot` object</span><br/><span class="hl-5">const</span><span class="hl-1"> </span><span class="hl-6">switchbot</span><span class="hl-1"> = </span><span class="hl-5">new</span><span class="hl-1"> </span><span class="hl-7">Switchbot</span><span class="hl-1">();</span><br/><br/><span class="hl-2">// Start to monitor advertisement packets</span><br/><span class="hl-0">switchbot</span><br/><span class="hl-1"> .</span><span class="hl-7">startScan</span><span class="hl-1">()</span><br/><span class="hl-1"> .</span><span class="hl-7">then</span><span class="hl-1">(() </span><span class="hl-5">=></span><span class="hl-1"> {</span><br/><span class="hl-1"> </span><span class="hl-2">// Set an event handler</span><br/><span class="hl-1"> </span><span class="hl-0">switchbot</span><span class="hl-1">.</span><span class="hl-7">onadvertisement</span><span class="hl-1"> = (</span><span class="hl-0">ad</span><span class="hl-1">) </span><span class="hl-5">=></span><span class="hl-1"> {</span><br/><span class="hl-1"> </span><span class="hl-0">console</span><span class="hl-1">.</span><span class="hl-7">log</span><span class="hl-1">(</span><span class="hl-6">JSON</span><span class="hl-1">.</span><span class="hl-7">stringify</span><span class="hl-1">(</span><span class="hl-0">ad</span><span class="hl-1">, </span><span class="hl-5">null</span><span class="hl-1">, </span><span class="hl-4">" "</span><span class="hl-1">));</span><br/><span class="hl-1"> };</span><br/><span class="hl-1"> </span><span class="hl-2">// Wait 10 seconds</span><br/><span class="hl-1"> </span><span class="hl-3">return</span><span class="hl-1"> </span><span class="hl-0">switchbot</span><span class="hl-1">.</span><span class="hl-7">wait</span><span class="hl-1">(</span><span class="hl-8">10000</span><span class="hl-1">);</span><br/><span class="hl-1"> })</span><br/><span class="hl-1"> .</span><span class="hl-7">then</span><span class="hl-1">(() </span><span class="hl-5">=></span><span class="hl-1"> {</span><br/><span class="hl-1"> </span><span class="hl-2">// Stop to monitor</span><br/><span class="hl-1"> </span><span class="hl-0">switchbot</span><span class="hl-1">.</span><span class="hl-7">stopScan</span><span class="hl-1">();</span><br/><span class="hl-1"> </span><span class="hl-0">process</span><span class="hl-1">.</span><span class="hl-7">exit</span><span class="hl-1">();</span><br/><span class="hl-1"> });</span>
|
|
120
|
-
</code><button type="button">Copy</button></pre>
|
|
121
|
-
|
|
122
|
-
<p>The sample codes above will output the result as follows:</p>
|
|
123
|
-
<pre><code class="json"><span class="hl-1">{</span><br/><span class="hl-1"> </span><span class="hl-9">"id"</span><span class="hl-1">: </span><span class="hl-4">"c12e453e2008"</span><span class="hl-1">,</span><br/><span class="hl-1"> </span><span class="hl-9">"address"</span><span class="hl-1">: </span><span class="hl-4">"c1:2e:45:3e:20:08"</span><span class="hl-1">,</span><br/><span class="hl-1"> </span><span class="hl-9">"rssi"</span><span class="hl-1">: </span><span class="hl-8">-61</span><span class="hl-1">,</span><br/><span class="hl-1"> </span><span class="hl-9">"serviceData"</span><span class="hl-1">: {</span><br/><span class="hl-1"> </span><span class="hl-9">"model"</span><span class="hl-1">: </span><span class="hl-4">"H"</span><span class="hl-1">,</span><br/><span class="hl-1"> </span><span class="hl-9">"modelName"</span><span class="hl-1">: </span><span class="hl-4">"WoHand"</span><span class="hl-1">,</span><br/><span class="hl-1"> </span><span class="hl-9">"mode"</span><span class="hl-1">: </span><span class="hl-5">true</span><span class="hl-1">,</span><br/><span class="hl-1"> </span><span class="hl-9">"state"</span><span class="hl-1">: </span><span class="hl-5">false</span><span class="hl-1">,</span><br/><span class="hl-1"> </span><span class="hl-9">"battery"</span><span class="hl-1">: </span><span class="hl-8">100</span><br/><span class="hl-1"> }</span><br/><span class="hl-1">}</span><br/><span class="hl-1">{</span><br/><span class="hl-1"> </span><span class="hl-9">"id"</span><span class="hl-1">: </span><span class="hl-4">"cb4eb903c96d"</span><span class="hl-1">,</span><br/><span class="hl-1"> </span><span class="hl-9">"address"</span><span class="hl-1">: </span><span class="hl-4">"cb:4e:b9:03:c9:6d"</span><span class="hl-1">,</span><br/><span class="hl-1"> </span><span class="hl-9">"rssi"</span><span class="hl-1">: </span><span class="hl-8">-70</span><span class="hl-1">,</span><br/><span class="hl-1"> </span><span class="hl-9">"serviceData"</span><span class="hl-1">: {</span><br/><span class="hl-1"> </span><span class="hl-9">"model"</span><span class="hl-1">: </span><span class="hl-4">"T"</span><span class="hl-1">,</span><br/><span class="hl-1"> </span><span class="hl-9">"modelName"</span><span class="hl-1">: </span><span class="hl-4">"WoSensorTH"</span><span class="hl-1">,</span><br/><span class="hl-1"> </span><span class="hl-9">"temperature"</span><span class="hl-1">: {</span><br/><span class="hl-1"> </span><span class="hl-9">"c"</span><span class="hl-1">: </span><span class="hl-8">25.2</span><span class="hl-1">,</span><br/><span class="hl-1"> </span><span class="hl-9">"f"</span><span class="hl-1">: </span><span class="hl-8">77.4</span><br/><span class="hl-1"> },</span><br/><span class="hl-1"> </span><span class="hl-9">"fahrenheit"</span><span class="hl-1">: </span><span class="hl-5">false</span><span class="hl-1">,</span><br/><span class="hl-1"> </span><span class="hl-9">"humidity"</span><span class="hl-1">: </span><span class="hl-8">43</span><span class="hl-1">,</span><br/><span class="hl-1"> </span><span class="hl-9">"battery"</span><span class="hl-1">: </span><span class="hl-8">100</span><br/><span class="hl-1"> }</span><br/><span class="hl-1">}</span><br/><span class="hl-1">{</span><br/><span class="hl-1"> </span><span class="hl-9">"id"</span><span class="hl-1">: </span><span class="hl-4">"ec58c5d00111"</span><span class="hl-1">,</span><br/><span class="hl-1"> </span><span class="hl-9">"address"</span><span class="hl-1">: </span><span class="hl-4">"ec:58:c5:d0:01:11"</span><span class="hl-1">,</span><br/><span class="hl-1"> </span><span class="hl-9">"rssi"</span><span class="hl-1">: </span><span class="hl-8">-39</span><span class="hl-1">,</span><br/><span class="hl-1"> </span><span class="hl-9">"serviceData"</span><span class="hl-1">: {</span><br/><span class="hl-1"> </span><span class="hl-9">"model"</span><span class="hl-1">: </span><span class="hl-4">"c"</span><span class="hl-1">,</span><br/><span class="hl-1"> </span><span class="hl-9">"modelName"</span><span class="hl-1">: </span><span class="hl-4">"WoCurtain"</span><span class="hl-1">,</span><br/><span class="hl-1"> </span><span class="hl-9">"calibration"</span><span class="hl-1">: </span><span class="hl-5">true</span><span class="hl-1">,</span><br/><span class="hl-1"> </span><span class="hl-9">"battery"</span><span class="hl-1">: </span><span class="hl-8">91</span><span class="hl-1">,</span><br/><span class="hl-1"> </span><span class="hl-9">"position"</span><span class="hl-1">: </span><span class="hl-8">1</span><span class="hl-1">,</span><br/><span class="hl-1"> </span><span class="hl-9">"lightLevel"</span><span class="hl-1">: </span><span class="hl-8">1</span><br/><span class="hl-1"> }</span><br/><span class="hl-1">}</span>
|
|
124
|
-
</code><button type="button">Copy</button></pre>
|
|
125
|
-
|
|
126
|
-
<p>See the section "<a href="#md:Advertisement-data">Advertisement data</a>" for the details of the advertising packets.</p>
|
|
127
|
-
<a id="md:moving-the-arm-of-the-bot" class="tsd-anchor"></a><h3 class="tsd-anchor-link">Moving the arm of the Bot<a href="#md:moving-the-arm-of-the-bot" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24"><use href="assets/icons.svg#icon-anchor"></use></svg></a></h3><p>This sample discovers a Bot (WoHand), then put the Bot's arm down, finally put it up in 5 seconds.</p>
|
|
128
|
-
<pre><code class="Typescript"><span class="hl-2">// Load the node-switchbot and get a `Switchbot` constructor object</span><br/><span class="hl-3">import</span><span class="hl-1"> { </span><span class="hl-0">SwitchBot</span><span class="hl-1"> } </span><span class="hl-3">from</span><span class="hl-1"> </span><span class="hl-4">'node-switchbot'</span><span class="hl-1">;</span><br/><span class="hl-2">// Create a `Switchbot` object</span><br/><span class="hl-5">const</span><span class="hl-1"> </span><span class="hl-6">switchbot</span><span class="hl-1"> = </span><span class="hl-5">new</span><span class="hl-1"> </span><span class="hl-7">SwitchBot</span><span class="hl-1">();</span><br/><br/><span class="hl-1">(</span><span class="hl-5">async</span><span class="hl-1"> () </span><span class="hl-5">=></span><span class="hl-1"> {</span><br/><span class="hl-1"> </span><span class="hl-2">// Find a Bot (WoHand)</span><br/><span class="hl-1"> </span><span class="hl-5">const</span><span class="hl-1"> </span><span class="hl-6">bot_list</span><span class="hl-1"> = </span><span class="hl-3">await</span><span class="hl-1"> </span><span class="hl-0">switchbot</span><span class="hl-1">.</span><span class="hl-7">discover</span><span class="hl-1">({ </span><span class="hl-0">model:</span><span class="hl-1"> </span><span class="hl-4">"H"</span><span class="hl-1">, </span><span class="hl-0">quick:</span><span class="hl-1"> </span><span class="hl-5">true</span><span class="hl-1"> });</span><br/><span class="hl-1"> </span><span class="hl-3">if</span><span class="hl-1"> (</span><span class="hl-0">bot_list</span><span class="hl-1">.</span><span class="hl-0">length</span><span class="hl-1"> === </span><span class="hl-8">0</span><span class="hl-1">) {</span><br/><span class="hl-1"> </span><span class="hl-3">throw</span><span class="hl-1"> </span><span class="hl-5">new</span><span class="hl-1"> </span><span class="hl-7">Error</span><span class="hl-1">(</span><span class="hl-4">"No device was found."</span><span class="hl-1">);</span><br/><span class="hl-1"> }</span><br/><span class="hl-1"> </span><span class="hl-2">// The `WoHand` object representing the found Bot.</span><br/><span class="hl-1"> </span><span class="hl-5">const</span><span class="hl-1"> </span><span class="hl-6">device</span><span class="hl-1"> = </span><span class="hl-0">bot_list</span><span class="hl-1">[</span><span class="hl-8">0</span><span class="hl-1">];</span><br/><span class="hl-1"> </span><span class="hl-2">// Put the Bot's arm down (stretch the arm)</span><br/><span class="hl-1"> </span><span class="hl-3">await</span><span class="hl-1"> </span><span class="hl-0">device</span><span class="hl-1">.</span><span class="hl-7">down</span><span class="hl-1">();</span><br/><span class="hl-1"> </span><span class="hl-2">// Wait for 5 seconds</span><br/><span class="hl-1"> </span><span class="hl-3">await</span><span class="hl-1"> </span><span class="hl-0">switchbot</span><span class="hl-1">.</span><span class="hl-7">wait</span><span class="hl-1">(</span><span class="hl-8">5000</span><span class="hl-1">);</span><br/><span class="hl-1"> </span><span class="hl-2">// Put the Bot's arm up (retract the arm)</span><br/><span class="hl-1"> </span><span class="hl-3">await</span><span class="hl-1"> </span><span class="hl-0">device</span><span class="hl-1">.</span><span class="hl-7">up</span><span class="hl-1">();</span><br/><span class="hl-1"> </span><span class="hl-0">process</span><span class="hl-1">.</span><span class="hl-7">exit</span><span class="hl-1">();</span><br/><span class="hl-1">})();</span>
|
|
129
|
-
</code><button type="button">Copy</button></pre>
|
|
130
|
-
|
|
131
|
-
<p>In order to manipulate the arm of your Bot, you have to discover your Bot using the <a href="#md:Switchbot-discover-method"><code>discover()</code></a> method. The object <code>{ model: 'H' }</code> passed to the method means that only Bots will be discovered. That is, Meters will be ignored.</p>
|
|
132
|
-
<p>In this code, you can get a <a href="#md:SwitchbotDeviceWoHand-object"><code>WoHand</code></a> object representing the found Bot. Using the <a href="#md:SwitchbotDeviceWoHand-down-method"><code>down()</code></a> and <a href="#md:SwitchbotDeviceWoHand-up-method"><code>up()</code></a> methods of the object, you can move the arm. In addition to these methods, you can use the <a href="#md:SwitchbotDeviceWoHand-press-method"><code>press()</code></a>, <a href="#md:SwitchbotDeviceWoHand-turnOn-method"><code>turnOn()</code></a>, and <a href="#md:SwitchbotDeviceWoHand-turnOff-method"><code>turnOff()</code></a> methods as well.</p>
|
|
133
|
-
<hr>
|
|
134
|
-
<a id="md:switchbot-object" class="tsd-anchor"></a><h2 class="tsd-anchor-link"><code>Switchbot</code> object<a href="#md:switchbot-object" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24"><use href="assets/icons.svg#icon-anchor"></use></svg></a></h2><p>In order to use the node-switchbot, you have to load the node-switchbot module as follows:</p>
|
|
135
|
-
<pre><code class="Typescript"><span class="hl-3">import</span><span class="hl-1"> { </span><span class="hl-0">SwitchBot</span><span class="hl-1"> } </span><span class="hl-3">from</span><span class="hl-1"> </span><span class="hl-4">'node-switchbot'</span><span class="hl-1">;</span>
|
|
136
|
-
</code><button type="button">Copy</button></pre>
|
|
137
|
-
|
|
138
|
-
<p>You can get an <code>SwitchBot</code> constructor from the code above. Then you have to create a <code>SwitchBot</code> object from the <code>SwitchBot</code> constructor as follows:</p>
|
|
139
|
-
<pre><code class="typescript"><span class="hl-5">const</span><span class="hl-1"> </span><span class="hl-6">switchbot</span><span class="hl-1"> = </span><span class="hl-5">new</span><span class="hl-1"> </span><span class="hl-7">SwitchBot</span><span class="hl-1">();</span>
|
|
140
|
-
</code><button type="button">Copy</button></pre>
|
|
141
|
-
|
|
142
|
-
<p>The <code>SwitchBot</code> constructor takes an argument optionally. It must be a hash object containing the properties as follows:</p>
|
|
143
|
-
<table>
|
|
144
|
-
<thead>
|
|
145
|
-
<tr>
|
|
146
|
-
<th style="text-align:left">Property</th>
|
|
147
|
-
<th style="text-align:left">Type</th>
|
|
148
|
-
<th style="text-align:left">Required</th>
|
|
149
|
-
<th style="text-align:left">Description</th>
|
|
150
|
-
</tr>
|
|
151
|
-
</thead>
|
|
152
|
-
<tbody>
|
|
153
|
-
<tr>
|
|
154
|
-
<td style="text-align:left"><code>noble</code></td>
|
|
155
|
-
<td style="text-align:left">Noble</td>
|
|
156
|
-
<td style="text-align:left">option</td>
|
|
157
|
-
<td style="text-align:left">a Noble object of the <a href="https://github.com/abandonware/noble"><code>@abandonware/noble</code></a> module</td>
|
|
158
|
-
</tr>
|
|
159
|
-
</tbody>
|
|
160
|
-
</table>
|
|
161
|
-
<p>The node-switchbot module uses the <a href="https://github.com/abandonware/noble"><code>@abandonware/noble</code></a> module in order to interact with BLE devices. If you want to interact other BLE devices using the <code>@abandonware/noble</code> module, you can create an <code>Noble</code> object by yourself, then pass it to this module. If you don't specify a <code>Noble</code> object to the <code>noble</code> property, this module automatically create a <code>Noble</code> object internally.</p>
|
|
162
|
-
<p>The sample code below shows how to pass a <code>Noble</code> object to the <code>Switchbot</code> constructor.</p>
|
|
163
|
-
<pre><code class="Typescript"><span class="hl-2">// Create a Noble object</span><br/><span class="hl-5">const</span><span class="hl-1"> </span><span class="hl-6">noble</span><span class="hl-1"> = </span><span class="hl-7">require</span><span class="hl-1">(</span><span class="hl-4">'@abandonware/noble'</span><span class="hl-1">);</span><br/><br/><span class="hl-2">// Create a Switchbot object</span><br/><span class="hl-3">import</span><span class="hl-1"> { </span><span class="hl-0">SwitchBot</span><span class="hl-1"> } </span><span class="hl-3">from</span><span class="hl-1"> </span><span class="hl-4">'node-switchbot'</span><span class="hl-1">;</span><br/><span class="hl-5">const</span><span class="hl-1"> </span><span class="hl-6">switchbot</span><span class="hl-1"> = </span><span class="hl-5">new</span><span class="hl-1"> </span><span class="hl-7">SwitchBot</span><span class="hl-1">({ </span><span class="hl-4">'noble'</span><span class="hl-0">:</span><span class="hl-1"> </span><span class="hl-0">noble</span><span class="hl-1"> })</span>
|
|
164
|
-
</code><button type="button">Copy</button></pre>
|
|
165
|
-
|
|
166
|
-
<p>In the code snippet above, the variable <code>switchbot</code> is an <code>SwitchBot</code> object. The <code>SwitchBot</code> object has a lot of methods as described in sections below.</p>
|
|
167
|
-
<a id="md:discover-method" class="tsd-anchor"></a><h3 class="tsd-anchor-link"><code>discover()</code> method<a href="#md:discover-method" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24"><use href="assets/icons.svg#icon-anchor"></use></svg></a></h3><p>The <code>discover</code> method finds devices. This method returns a <code>Promise</code> object. This method takes an argument which is a hash object containing parameters as follows:</p>
|
|
168
|
-
<table>
|
|
169
|
-
<thead>
|
|
170
|
-
<tr>
|
|
171
|
-
<th style="text-align:left">Property</th>
|
|
172
|
-
<th style="text-align:left">Type</th>
|
|
173
|
-
<th style="text-align:left">Required</th>
|
|
174
|
-
<th style="text-align:left">Description</th>
|
|
175
|
-
</tr>
|
|
176
|
-
</thead>
|
|
177
|
-
<tbody>
|
|
178
|
-
<tr>
|
|
179
|
-
<td style="text-align:left"><code>duration</code></td>
|
|
180
|
-
<td style="text-align:left">Integer</td>
|
|
181
|
-
<td style="text-align:left">Optional</td>
|
|
182
|
-
<td style="text-align:left">Duration for discovery process (msec). The default value is 5000 (msec).</td>
|
|
183
|
-
</tr>
|
|
184
|
-
<tr>
|
|
185
|
-
<td style="text-align:left"><code>model</code></td>
|
|
186
|
-
<td style="text-align:left">String</td>
|
|
187
|
-
<td style="text-align:left">Optional</td>
|
|
188
|
-
<td style="text-align:left"><code>"H"</code>, <code>"T"</code> or <code>"c"</code>. If <code>"H"</code> is specified, this method will discover only Bots. If <code>"T"</code> is specified, this method will discover only Meters. If <code>"c"</code> is specified, this method will discover only Curtains.</td>
|
|
189
|
-
</tr>
|
|
190
|
-
<tr>
|
|
191
|
-
<td style="text-align:left"><code>id</code></td>
|
|
192
|
-
<td style="text-align:left">String</td>
|
|
193
|
-
<td style="text-align:left">Optional</td>
|
|
194
|
-
<td style="text-align:left">If this value is set, this method will discover only a device whose ID is as same as this value. The ID is identical to the MAC address. This parameter is case-insensitive, and colons are ignored.</td>
|
|
195
|
-
</tr>
|
|
196
|
-
<tr>
|
|
197
|
-
<td style="text-align:left"><code>quick</code></td>
|
|
198
|
-
<td style="text-align:left">Boolean</td>
|
|
199
|
-
<td style="text-align:left">Optional</td>
|
|
200
|
-
<td style="text-align:left">If this value is <code>true</code>, this method finishes the discovery process when the first device is found, then calls the <code>resolve()</code> function without waiting the specified <code>duration</code>. The default value is <code>false</code>.</td>
|
|
201
|
-
</tr>
|
|
202
|
-
</tbody>
|
|
203
|
-
</table>
|
|
204
|
-
<p>In the code snippet below, no parameter is passed to the method:</p>
|
|
205
|
-
<pre><code class="Typescript"><span class="hl-0">switchbot</span><span class="hl-1">.</span><span class="hl-7">discover</span><span class="hl-1">().</span><span class="hl-7">then</span><span class="hl-1">((</span><span class="hl-0">device_list</span><span class="hl-1">) </span><span class="hl-5">=></span><span class="hl-1"> {</span><br/><span class="hl-1"> </span><span class="hl-2">// Do something...</span><br/><span class="hl-1">}).</span><span class="hl-7">catch</span><span class="hl-1">((</span><span class="hl-0">error</span><span class="hl-1">) </span><span class="hl-5">=></span><span class="hl-1"> {</span><br/><span class="hl-1"> </span><span class="hl-0">console</span><span class="hl-1">.</span><span class="hl-7">error</span><span class="hl-1">(</span><span class="hl-0">error</span><span class="hl-1">);</span><br/><span class="hl-1">});</span>
|
|
206
|
-
</code><button type="button">Copy</button></pre>
|
|
207
|
-
|
|
208
|
-
<p>If no parameter is passed to the method as the code above, an <code>Array</code> object will be passed to the <code>resolve()</code> function in 5 seconds. The <code>Array</code> object contains <a href="#md:SwitchbotDevice-object"><code>SwitchbotDevice</code></a> objects representing the found devices. See the section "<a href="#md:SwitchbotDevice-object"><code>SwitchbotDevice</code></a> objects" for more details.</p>
|
|
209
|
-
<p>If you want a quick response, you can set the <code>quick</code> property to <code>true</code>.</p>
|
|
210
|
-
<pre><code class="Typescript"><span class="hl-0">switchbot</span><span class="hl-1">.</span><span class="hl-7">discover</span><span class="hl-1">({</span><br/><span class="hl-1"> </span><span class="hl-0">duration:</span><span class="hl-1"> </span><span class="hl-8">5000</span><span class="hl-1">,</span><br/><span class="hl-1"> </span><span class="hl-0">quick:</span><span class="hl-1"> </span><span class="hl-5">true</span><br/><span class="hl-1">}).</span><span class="hl-7">then</span><span class="hl-1">((</span><span class="hl-0">device_list</span><span class="hl-1">) </span><span class="hl-5">=></span><span class="hl-1"> {</span><br/><span class="hl-1"> </span><span class="hl-2">// Do something...</span><br/><span class="hl-1">}).</span><span class="hl-7">catch</span><span class="hl-1">((</span><span class="hl-0">error</span><span class="hl-1">) </span><span class="hl-5">=></span><span class="hl-1"> {</span><br/><span class="hl-1"> </span><span class="hl-0">console</span><span class="hl-1">.</span><span class="hl-7">error</span><span class="hl-1">(</span><span class="hl-0">error</span><span class="hl-1">);</span><br/><span class="hl-1">});</span>
|
|
211
|
-
</code><button type="button">Copy</button></pre>
|
|
212
|
-
|
|
213
|
-
<p>As the <code>quick</code> property is set to <code>true</code>, the <code>resolve()</code> function will be called immediately after a device is found regardless the value of the <code>duration</code> property.</p>
|
|
214
|
-
<a id="md:ondiscover-event-handler" class="tsd-anchor"></a><h3 class="tsd-anchor-link"><code>ondiscover</code> event handler<a href="#md:ondiscover-event-handler" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24"><use href="assets/icons.svg#icon-anchor"></use></svg></a></h3><p>The <code>ondiscover</code> property on the <a href="#md:Switchbot-object"><code>Switchbot</code></a> object is an event handler called whenever a device is newly found in the discovery process. A <a href="#md:SwitchbotDevice-object"><code>SwitchbotDevice</code></a> object is passed to the callback function set to the <code>ondiscover</code> property.</p>
|
|
215
|
-
<pre><code class="Typescript"><span class="hl-0">switchbot</span><span class="hl-1">.</span><span class="hl-7">ondiscover</span><span class="hl-1"> = (</span><span class="hl-0">device</span><span class="hl-1">) </span><span class="hl-5">=></span><span class="hl-1"> {</span><br/><span class="hl-1"> </span><span class="hl-0">console</span><span class="hl-1">.</span><span class="hl-7">log</span><span class="hl-1">(</span><span class="hl-0">device</span><span class="hl-1">.</span><span class="hl-0">id</span><span class="hl-1"> + </span><span class="hl-4">' ('</span><span class="hl-1"> + </span><span class="hl-0">device</span><span class="hl-1">.</span><span class="hl-0">modelName</span><span class="hl-1"> + </span><span class="hl-4">')'</span><span class="hl-1">);</span><br/><span class="hl-1">};</span><br/><br/><span class="hl-0">switchbot</span><span class="hl-1">.</span><span class="hl-7">discover</span><span class="hl-1">().</span><span class="hl-7">then</span><span class="hl-1">(() </span><span class="hl-5">=></span><span class="hl-1"> {</span><br/><span class="hl-1"> </span><span class="hl-0">console</span><span class="hl-1">.</span><span class="hl-7">log</span><span class="hl-1">(</span><span class="hl-4">'The discovery process was finished.'</span><span class="hl-1">);</span><br/><span class="hl-1">}).</span><span class="hl-7">catch</span><span class="hl-1">((</span><span class="hl-0">error</span><span class="hl-1">) </span><span class="hl-5">=></span><span class="hl-1"> {</span><br/><span class="hl-1"> </span><span class="hl-0">console</span><span class="hl-1">.</span><span class="hl-7">error</span><span class="hl-1">(</span><span class="hl-0">error</span><span class="hl-1">);</span><br/><span class="hl-1">});</span>
|
|
216
|
-
</code><button type="button">Copy</button></pre>
|
|
217
|
-
|
|
218
|
-
<p>The code snippet above will output the result as follows:</p>
|
|
219
|
-
<pre><code><span class="hl-7">cb4eb903c96d</span><span class="hl-1"> (</span><span class="hl-0">WoSensorTH</span><span class="hl-1">)</span><br/><span class="hl-7">c12e453e2008</span><span class="hl-1"> (</span><span class="hl-0">WoHand</span><span class="hl-1">)</span><br/><span class="hl-0">The</span><span class="hl-1"> </span><span class="hl-0">discovery</span><span class="hl-1"> </span><span class="hl-0">process</span><span class="hl-1"> </span><span class="hl-0">was</span><span class="hl-1"> </span><span class="hl-0">finished</span><span class="hl-1">.</span>
|
|
220
|
-
</code><button>Copy</button></pre>
|
|
221
|
-
|
|
222
|
-
<a id="md:startscan-method" class="tsd-anchor"></a><h3 class="tsd-anchor-link"><code>startScan()</code> method<a href="#md:startscan-method" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24"><use href="assets/icons.svg#icon-anchor"></use></svg></a></h3><p>The <code>startScan()</code> method starts to scan advertising packets coming from devices. This method takes an argument which is a hash object containing the parameters as follows:</p>
|
|
223
|
-
<table>
|
|
224
|
-
<thead>
|
|
225
|
-
<tr>
|
|
226
|
-
<th style="text-align:left">Property</th>
|
|
227
|
-
<th style="text-align:left">Type</th>
|
|
228
|
-
<th style="text-align:left">Required</th>
|
|
229
|
-
<th style="text-align:left">Description</th>
|
|
230
|
-
</tr>
|
|
231
|
-
</thead>
|
|
232
|
-
<tbody>
|
|
233
|
-
<tr>
|
|
234
|
-
<td style="text-align:left"><code>model</code></td>
|
|
235
|
-
<td style="text-align:left">String</td>
|
|
236
|
-
<td style="text-align:left">Optional</td>
|
|
237
|
-
<td style="text-align:left"><code>"H"</code>, <code>"T"</code>, <code>"c"</code>, <code>"g"</code> or <code>"j"</code>. If <code>"H"</code> is specified, this method will discover only Bots. If <code>"T"</code> is specified, this method will discover only Meters. If <code>"c"</code> is specified, this method will discover only Curtains. If <code>"g"</code> or <code>"j"</code> is specified, this method will discover only (US/JP) Plug Minis.</td>
|
|
238
|
-
</tr>
|
|
239
|
-
<tr>
|
|
240
|
-
<td style="text-align:left"><code>id</code></td>
|
|
241
|
-
<td style="text-align:left">String</td>
|
|
242
|
-
<td style="text-align:left">Optional</td>
|
|
243
|
-
<td style="text-align:left">If this value is set, this method will discover only a device whose ID is as same as this value. The ID is identical to the MAC address. This value is case-insensitive, and colons are ignored.</td>
|
|
244
|
-
</tr>
|
|
245
|
-
</tbody>
|
|
246
|
-
</table>
|
|
247
|
-
<p>Whenever a packet is received, the callback function set to the <a href="#md:Switchbot-onadvertisement-event-handler"><code>onadvertisement</code></a> property of the <a href="#md:Switchbot-object"><code>Switchbot</code></a> object will be called. When a packet is received, a hash object representing the packet will be passed to the callback function.</p>
|
|
248
|
-
<pre><code class="Typescript"><span class="hl-2">// Set a callback function called when a packet is received</span><br/><span class="hl-0">switchbot</span><span class="hl-1">.</span><span class="hl-7">onadvertisement</span><span class="hl-1"> = (</span><span class="hl-0">ad</span><span class="hl-1">) </span><span class="hl-5">=></span><span class="hl-1"> {</span><br/><span class="hl-1"> </span><span class="hl-0">console</span><span class="hl-1">.</span><span class="hl-7">log</span><span class="hl-1">(</span><span class="hl-0">ad</span><span class="hl-1">);</span><br/><span class="hl-1">};</span><br/><br/><span class="hl-2">// Start to scan advertising packets</span><br/><span class="hl-0">switchbot</span><span class="hl-1">.</span><span class="hl-7">startScan</span><span class="hl-1">({</span><br/><span class="hl-1"> </span><span class="hl-0">id:</span><span class="hl-1"> </span><span class="hl-4">'cb:4e:b9:03:c9:6d'</span><span class="hl-1">,</span><br/><span class="hl-1">}).</span><span class="hl-7">then</span><span class="hl-1">(() </span><span class="hl-5">=></span><span class="hl-1"> {</span><br/><span class="hl-1"> </span><span class="hl-2">// Wait for 30 seconds</span><br/><span class="hl-1"> </span><span class="hl-3">return</span><span class="hl-1"> </span><span class="hl-0">switchbot</span><span class="hl-1">.</span><span class="hl-7">wait</span><span class="hl-1">(</span><span class="hl-8">30000</span><span class="hl-1">);</span><br/><span class="hl-1">}).</span><span class="hl-7">then</span><span class="hl-1">(() </span><span class="hl-5">=></span><span class="hl-1"> {</span><br/><span class="hl-1"> </span><span class="hl-2">// Stop to scan</span><br/><span class="hl-1"> </span><span class="hl-0">switchbot</span><span class="hl-1">.</span><span class="hl-7">stopScan</span><span class="hl-1">();</span><br/><span class="hl-1"> </span><span class="hl-0">process</span><span class="hl-1">.</span><span class="hl-7">exit</span><span class="hl-1">();</span><br/><span class="hl-1">}).</span><span class="hl-7">catch</span><span class="hl-1">((</span><span class="hl-0">error</span><span class="hl-1">) </span><span class="hl-5">=></span><span class="hl-1"> {</span><br/><span class="hl-1"> </span><span class="hl-0">console</span><span class="hl-1">.</span><span class="hl-7">error</span><span class="hl-1">(</span><span class="hl-0">error</span><span class="hl-1">);</span><br/><span class="hl-1">});</span>
|
|
249
|
-
</code><button type="button">Copy</button></pre>
|
|
250
|
-
|
|
251
|
-
<p>The code snippet above will output the result as follows:</p>
|
|
252
|
-
<pre><code><span class="hl-1">{</span><br/><span class="hl-1"> </span><span class="hl-10">id</span><span class="hl-1">: </span><span class="hl-4">'cb4eb903c96d'</span><span class="hl-1">,</span><br/><span class="hl-1"> </span><span class="hl-10">address</span><span class="hl-1">: </span><span class="hl-4">'cb:4e:b9:03:c9:6d'</span><span class="hl-1">,</span><br/><span class="hl-1"> </span><span class="hl-10">rssi</span><span class="hl-1">: -</span><span class="hl-8">65</span><span class="hl-1">,</span><br/><span class="hl-1"> </span><span class="hl-10">serviceData</span><span class="hl-1">: {</span><br/><span class="hl-1"> </span><span class="hl-10">model</span><span class="hl-1">: </span><span class="hl-4">'T'</span><span class="hl-1">,</span><br/><span class="hl-1"> </span><span class="hl-10">modelName</span><span class="hl-1">: </span><span class="hl-4">'WoSensorTH'</span><span class="hl-1">,</span><br/><span class="hl-1"> </span><span class="hl-10">temperature</span><span class="hl-1">: { </span><span class="hl-10">c</span><span class="hl-1">: </span><span class="hl-8">25.8</span><span class="hl-1">, </span><span class="hl-10">f</span><span class="hl-1">: </span><span class="hl-8">78.4</span><span class="hl-1"> },</span><br/><span class="hl-1"> </span><span class="hl-10">fahrenheit</span><span class="hl-1">: </span><span class="hl-5">false</span><span class="hl-1">,</span><br/><span class="hl-1"> </span><span class="hl-10">humidity</span><span class="hl-1">: </span><span class="hl-8">43</span><span class="hl-1">,</span><br/><span class="hl-1"> </span><span class="hl-10">battery</span><span class="hl-1">: </span><span class="hl-8">100</span><br/><span class="hl-1"> }</span><br/><span class="hl-1">}</span><br/><span class="hl-1">...</span>
|
|
253
|
-
</code><button>Copy</button></pre>
|
|
254
|
-
|
|
255
|
-
<p>The <code>serviceData</code> property depends on the model of the device. See the section "<a href="#md:Advertisement-data">Advertisement data</a>" for the details of the data format.</p>
|
|
256
|
-
<a id="md:stopscan-method" class="tsd-anchor"></a><h3 class="tsd-anchor-link"><code>stopScan()</code> method<a href="#md:stopscan-method" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24"><use href="assets/icons.svg#icon-anchor"></use></svg></a></h3><p>The <code>stopScan()</code> method stops to scan advertising packets coming from devices. This method returns nothing. Note that this method is <em>not</em> asynchronous but synchronous unlike the other methods. See the section "<a href="#md:startscan-method"><code>startScan()</code> method</a>" for details.</p>
|
|
257
|
-
<a id="md:onadvertisement-event-handler" class="tsd-anchor"></a><h3 class="tsd-anchor-link"><code>onadvertisement</code> event handler<a href="#md:onadvertisement-event-handler" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24"><use href="assets/icons.svg#icon-anchor"></use></svg></a></h3><p>If a callback function is set to the <code>onadvertisement</code> property, the callback function will be called whenever an advertising packet is received from a device during the scan is active (from the moment when the <a href="#md:startscan-method"><code>startScan()</code></a> method is called, to the moment when the <a href="#md:Switchbot-stopScan-method"><code>stopScan()</code></a> method is called).</p>
|
|
258
|
-
<p>See the section "<a href="#md:startscan-method"><code>startScan()</code> method</a>" for details.</p>
|
|
259
|
-
<a id="md:wait-method" class="tsd-anchor"></a><h3 class="tsd-anchor-link"><code>wait()</code> method<a href="#md:wait-method" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24"><use href="assets/icons.svg#icon-anchor"></use></svg></a></h3><p>The <code>wait()</code> method waits for the specified milliseconds. This method takes an integer representing the duration (millisecond). This method returns a <code>Promise</code> object.</p>
|
|
260
|
-
<p>This method has nothing to do with Switchbot devices. It's just a utility method. See the section "<a href="#md:Quick-Start">Quick Start</a>" for details of the usage of this method.</p>
|
|
261
|
-
<hr>
|
|
262
|
-
<a id="md:switchbotdevice-object" class="tsd-anchor"></a><h2 class="tsd-anchor-link"><code>SwitchbotDevice</code> object<a href="#md:switchbotdevice-object" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24"><use href="assets/icons.svg#icon-anchor"></use></svg></a></h2><p>The <code>SwitchbotDevice</code> object represents a Switchbot device (Bot, Meter, Curtain, Contact or Motion), which is created through the discovery process triggered by the <a href="#md:Switchbot-discover-method"><code>Switchbot.discover()</code></a> method.</p>
|
|
263
|
-
<p>Actually, the <code>SwitchbotDevice</code> object is a super class of the <a href="#md:SwitchbotDeviceWoHand-object"><code>WoHand</code></a> and <code>WoSensorTH</code> objects. The <a href="#md:SwitchbotDeviceWoHand-object"><code>WoHand</code></a> object represents a Bot, the <code>WoSensorTH</code> object represents a Meter.</p>
|
|
264
|
-
<p>You can use the properties and methods described in this section on Bot, Meter, Curtain, Contact and Motion. See the section "<a href="#md:SwitchbotDeviceWoHand-object"><code>WoHand</code> object</a>" for the details of the functionalities available only on Bot. For now, <code>WoSensorTH</code> object has no additional functionality.</p>
|
|
265
|
-
<a id="md:properties" class="tsd-anchor"></a><h3 class="tsd-anchor-link">Properties<a href="#md:properties" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24"><use href="assets/icons.svg#icon-anchor"></use></svg></a></h3><p>The <code>SwitchbotDevice</code> object supports the properties as follows:</p>
|
|
266
|
-
<table>
|
|
267
|
-
<thead>
|
|
268
|
-
<tr>
|
|
269
|
-
<th style="text-align:left">Property</th>
|
|
270
|
-
<th style="text-align:left">Type</th>
|
|
271
|
-
<th style="text-align:left">Description</th>
|
|
272
|
-
</tr>
|
|
273
|
-
</thead>
|
|
274
|
-
<tbody>
|
|
275
|
-
<tr>
|
|
276
|
-
<td style="text-align:left"><code>id</code></td>
|
|
277
|
-
<td style="text-align:left">String</td>
|
|
278
|
-
<td style="text-align:left">ID of the device. (e.g., <code>"cb4eb903c96d"</code>)</td>
|
|
279
|
-
</tr>
|
|
280
|
-
<tr>
|
|
281
|
-
<td style="text-align:left"><code>address</code></td>
|
|
282
|
-
<td style="text-align:left">String</td>
|
|
283
|
-
<td style="text-align:left">MAC address of the device. Basically it is as same as the value of the <code>id</code> except that this value includes <code>:</code> in the string. (e.g., <code>"cb:4e:b9:03:c9:6d"</code>)</td>
|
|
284
|
-
</tr>
|
|
285
|
-
<tr>
|
|
286
|
-
<td style="text-align:left"><code>model</code></td>
|
|
287
|
-
<td style="text-align:left">String</td>
|
|
288
|
-
<td style="text-align:left">This value is <code>"H"</code> "Bot (WoHand)", <code>"T"</code> "Meter (WoSensorTH)", <code>"c"</code> "Curtain (WoCurtain)", <code>"d"</code> "Contact (WoContact)" or <code>"s"</code> "Motion (WoMotion)".</td>
|
|
289
|
-
</tr>
|
|
290
|
-
<tr>
|
|
291
|
-
<td style="text-align:left"><code>modelName</code></td>
|
|
292
|
-
<td style="text-align:left">String</td>
|
|
293
|
-
<td style="text-align:left">This value is <code>"WoHand"</code>, <code>"WoSensorTH"</code>, <code>WoCurtain</code>, <code>WoContect</code> or <code>WoMotion</code>.</td>
|
|
294
|
-
</tr>
|
|
295
|
-
<tr>
|
|
296
|
-
<td style="text-align:left"><code>connectionState</code></td>
|
|
297
|
-
<td style="text-align:left">String</td>
|
|
298
|
-
<td style="text-align:left">This value indicates the BLE connection state. <code>"connecting"</code>, <code>"connected"</code>, <code>"disconnecting"</code>, or <code>"disconnected"</code>.</td>
|
|
299
|
-
</tr>
|
|
300
|
-
<tr>
|
|
301
|
-
<td style="text-align:left"><code>onconnect</code></td>
|
|
302
|
-
<td style="text-align:left">Function</td>
|
|
303
|
-
<td style="text-align:left">See the section "<a href="#md:SwitchbotDevice-onconnect-event-handler"><code>onconnect</code> event handler</a>" for details.</td>
|
|
304
|
-
</tr>
|
|
305
|
-
<tr>
|
|
306
|
-
<td style="text-align:left"><code>ondisconnect</code></td>
|
|
307
|
-
<td style="text-align:left">Function</td>
|
|
308
|
-
<td style="text-align:left">See the section "<a href="#md:SwitchbotDevice-ondisconnect-event-handler"><code>ondisconnect</code> event handler</a>" for details.</td>
|
|
309
|
-
</tr>
|
|
310
|
-
</tbody>
|
|
311
|
-
</table>
|
|
312
|
-
<a id="md:getdevicename-method" class="tsd-anchor"></a><h3 class="tsd-anchor-link"><code>getDeviceName()</code> method<a href="#md:getdevicename-method" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24"><use href="assets/icons.svg#icon-anchor"></use></svg></a></h3><p>The <code>getDeviceName()</code> method fetches the device name saved in the device. This method returns a <code>Promise</code> object.</p>
|
|
313
|
-
<p>If no connection is established with the device, this method automatically establishes a connection with the device, then finally closes the connection. You don't have to call the <a href="#md:SwitchbotDevice-connect-method"><code>connect()</code></a> method in advance.</p>
|
|
314
|
-
<p>If the device name is fetched successfully, the device name will be passed to the <code>resolve()</code>.</p>
|
|
315
|
-
<pre><code class="Typescript"><span class="hl-0">switchbot</span><br/><span class="hl-1"> .</span><span class="hl-7">discover</span><span class="hl-1">({ </span><span class="hl-0">model:</span><span class="hl-1"> </span><span class="hl-4">"H"</span><span class="hl-1">, </span><span class="hl-0">quick:</span><span class="hl-1"> </span><span class="hl-5">true</span><span class="hl-1"> })</span><br/><span class="hl-1"> .</span><span class="hl-7">then</span><span class="hl-1">((</span><span class="hl-0">device_list</span><span class="hl-1">) </span><span class="hl-5">=></span><span class="hl-1"> {</span><br/><span class="hl-1"> </span><span class="hl-3">return</span><span class="hl-1"> </span><span class="hl-0">device_list</span><span class="hl-1">[</span><span class="hl-8">0</span><span class="hl-1">].</span><span class="hl-7">getDeviceName</span><span class="hl-1">();</span><br/><span class="hl-1"> })</span><br/><span class="hl-1"> .</span><span class="hl-7">then</span><span class="hl-1">((</span><span class="hl-0">name</span><span class="hl-1">) </span><span class="hl-5">=></span><span class="hl-1"> {</span><br/><span class="hl-1"> </span><span class="hl-0">console</span><span class="hl-1">.</span><span class="hl-7">log</span><span class="hl-1">(</span><span class="hl-0">name</span><span class="hl-1">);</span><br/><span class="hl-1"> </span><span class="hl-0">process</span><span class="hl-1">.</span><span class="hl-7">exit</span><span class="hl-1">();</span><br/><span class="hl-1"> })</span><br/><span class="hl-1"> .</span><span class="hl-7">catch</span><span class="hl-1">((</span><span class="hl-0">error</span><span class="hl-1">) </span><span class="hl-5">=></span><span class="hl-1"> {</span><br/><span class="hl-1"> </span><span class="hl-0">console</span><span class="hl-1">.</span><span class="hl-7">error</span><span class="hl-1">(</span><span class="hl-0">error</span><span class="hl-1">);</span><br/><span class="hl-1"> </span><span class="hl-0">process</span><span class="hl-1">.</span><span class="hl-7">exit</span><span class="hl-1">();</span><br/><span class="hl-1"> });</span>
|
|
316
|
-
</code><button type="button">Copy</button></pre>
|
|
317
|
-
|
|
318
|
-
<p>The code above will output the result as follows:</p>
|
|
319
|
-
<pre><code class="Typescript"><span class="hl-0">WoHand</span><span class="hl-1">;</span>
|
|
320
|
-
</code><button type="button">Copy</button></pre>
|
|
321
|
-
|
|
322
|
-
<a id="md:setdevicename-method" class="tsd-anchor"></a><h3 class="tsd-anchor-link"><code>setDeviceName()</code> method<a href="#md:setdevicename-method" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24"><use href="assets/icons.svg#icon-anchor"></use></svg></a></h3><p>The <code>setDeviceName()</code> method update the device name saved in the device with the name specified as the first argument. This method returns a <code>Promise</code> object. Nothing will be passed to the <code>resolve()</code> function.</p>
|
|
323
|
-
<p>If no connection is established with the device, this method automatically establishes a connection with the device, then finally closes the connection. You don't have to call the <a href="#md:SwitchbotDevice-connect-method"><code>connect()</code></a> method in advance.</p>
|
|
324
|
-
<p>The character set of the device name saved in the device is UTF-8. The byte length of the name must be less than or equal to 20 bytes. If the name consists of only ASCII characters, up to 20 characters would be allowed. But if the name consists of multibyte characters, the upper limit of characters would be fewer than half. For example, Japanese characters could be saved at most 6 characters because most of Japanese characters consume 3 byte per each character.</p>
|
|
325
|
-
<pre><code class="Typescript"><span class="hl-0">switchbot</span><br/><span class="hl-1"> .</span><span class="hl-7">discover</span><span class="hl-1">({ </span><span class="hl-0">model:</span><span class="hl-1"> </span><span class="hl-4">"H"</span><span class="hl-1">, </span><span class="hl-0">quick:</span><span class="hl-1"> </span><span class="hl-5">true</span><span class="hl-1"> })</span><br/><span class="hl-1"> .</span><span class="hl-7">then</span><span class="hl-1">((</span><span class="hl-0">device_list</span><span class="hl-1">) </span><span class="hl-5">=></span><span class="hl-1"> {</span><br/><span class="hl-1"> </span><span class="hl-3">return</span><span class="hl-1"> </span><span class="hl-0">device_list</span><span class="hl-1">[</span><span class="hl-8">0</span><span class="hl-1">].</span><span class="hl-7">setDeviceName</span><span class="hl-1">(</span><span class="hl-4">"Bot in kitchen"</span><span class="hl-1">);</span><br/><span class="hl-1"> })</span><br/><span class="hl-1"> .</span><span class="hl-7">then</span><span class="hl-1">(() </span><span class="hl-5">=></span><span class="hl-1"> {</span><br/><span class="hl-1"> </span><span class="hl-0">console</span><span class="hl-1">.</span><span class="hl-7">log</span><span class="hl-1">(</span><span class="hl-4">"Done."</span><span class="hl-1">);</span><br/><span class="hl-1"> </span><span class="hl-0">process</span><span class="hl-1">.</span><span class="hl-7">exit</span><span class="hl-1">();</span><br/><span class="hl-1"> })</span><br/><span class="hl-1"> .</span><span class="hl-7">catch</span><span class="hl-1">((</span><span class="hl-0">error</span><span class="hl-1">) </span><span class="hl-5">=></span><span class="hl-1"> {</span><br/><span class="hl-1"> </span><span class="hl-0">console</span><span class="hl-1">.</span><span class="hl-7">error</span><span class="hl-1">(</span><span class="hl-0">error</span><span class="hl-1">);</span><br/><span class="hl-1"> </span><span class="hl-0">process</span><span class="hl-1">.</span><span class="hl-7">exit</span><span class="hl-1">();</span><br/><span class="hl-1"> });</span>
|
|
326
|
-
</code><button type="button">Copy</button></pre>
|
|
327
|
-
|
|
328
|
-
<a id="md:connect-method" class="tsd-anchor"></a><h3 class="tsd-anchor-link"><code>connect()</code> method<a href="#md:connect-method" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24"><use href="assets/icons.svg#icon-anchor"></use></svg></a></h3><p>The <code>connect()</code> method establishes a connection with the device (i.e., pairing). This method returns a <code>Promise</code> object. If the device has already been connected, this method does nothing and calls the <code>resolve()</code> function immediately.</p>
|
|
329
|
-
<p>Most of the methods implemented in the <code>SwitchbotDevice</code> object automatically connect and disconnect the device. But this mechanism would be absolutely inefficient if you want to manipulate the device repeatedly in the short time.</p>
|
|
330
|
-
<p>The connection established using the <code>connect()</code> method is not disconnected automatically unless the <a href="#md:SwitchbotDevice-disconnect-method"><code>disconnect()</code></a> method is explicitly called.</p>
|
|
331
|
-
<p>The code snippet below establishes a connection with the Bot using the <code>connect()</code> method, then puts the Bot's arm down, then waits for 5 seconds, then puts the arm down, finally disconnects the device using the <a href="#md:SwitchbotDevice-disconnect-method"><code>disconnect()</code></a> method:</p>
|
|
332
|
-
<pre><code class="Typescript"><span class="hl-5">let</span><span class="hl-1"> </span><span class="hl-0">device</span><span class="hl-1"> = </span><span class="hl-5">null</span><span class="hl-1">;</span><br/><br/><span class="hl-0">switchbot</span><br/><span class="hl-1"> .</span><span class="hl-7">discover</span><span class="hl-1">({ </span><span class="hl-0">model:</span><span class="hl-1"> </span><span class="hl-4">"H"</span><span class="hl-1">, </span><span class="hl-0">quick:</span><span class="hl-1"> </span><span class="hl-5">true</span><span class="hl-1"> })</span><br/><span class="hl-1"> .</span><span class="hl-7">then</span><span class="hl-1">((</span><span class="hl-0">device_list</span><span class="hl-1">) </span><span class="hl-5">=></span><span class="hl-1"> {</span><br/><span class="hl-1"> </span><span class="hl-0">device</span><span class="hl-1"> = </span><span class="hl-0">device_list</span><span class="hl-1">[</span><span class="hl-8">0</span><span class="hl-1">];</span><br/><span class="hl-1"> </span><span class="hl-3">if</span><span class="hl-1"> (!</span><span class="hl-0">device</span><span class="hl-1">) {</span><br/><span class="hl-1"> </span><span class="hl-0">console</span><span class="hl-1">.</span><span class="hl-7">log</span><span class="hl-1">(</span><span class="hl-4">"No device was found."</span><span class="hl-1">);</span><br/><span class="hl-1"> </span><span class="hl-0">process</span><span class="hl-1">.</span><span class="hl-7">exit</span><span class="hl-1">();</span><br/><span class="hl-1"> }</span><br/><span class="hl-1"> </span><span class="hl-0">console</span><span class="hl-1">.</span><span class="hl-7">log</span><span class="hl-1">(</span><span class="hl-0">device</span><span class="hl-1">.</span><span class="hl-0">modelName</span><span class="hl-1"> + </span><span class="hl-4">" ("</span><span class="hl-1"> + </span><span class="hl-0">device</span><span class="hl-1">.</span><span class="hl-0">address</span><span class="hl-1"> + </span><span class="hl-4">") was found."</span><span class="hl-1">);</span><br/><span class="hl-1"> </span><span class="hl-0">console</span><span class="hl-1">.</span><span class="hl-7">log</span><span class="hl-1">(</span><span class="hl-4">"Connecting..."</span><span class="hl-1">);</span><br/><span class="hl-1"> </span><span class="hl-3">return</span><span class="hl-1"> </span><span class="hl-0">device</span><span class="hl-1">.</span><span class="hl-7">connect</span><span class="hl-1">();</span><br/><span class="hl-1"> })</span><br/><span class="hl-1"> .</span><span class="hl-7">then</span><span class="hl-1">(() </span><span class="hl-5">=></span><span class="hl-1"> {</span><br/><span class="hl-1"> </span><span class="hl-0">console</span><span class="hl-1">.</span><span class="hl-7">log</span><span class="hl-1">(</span><span class="hl-4">"Putting the arm down..."</span><span class="hl-1">);</span><br/><span class="hl-1"> </span><span class="hl-3">return</span><span class="hl-1"> </span><span class="hl-0">device</span><span class="hl-1">.</span><span class="hl-7">down</span><span class="hl-1">();</span><br/><span class="hl-1"> })</span><br/><span class="hl-1"> .</span><span class="hl-7">then</span><span class="hl-1">(() </span><span class="hl-5">=></span><span class="hl-1"> {</span><br/><span class="hl-1"> </span><span class="hl-0">console</span><span class="hl-1">.</span><span class="hl-7">log</span><span class="hl-1">(</span><span class="hl-4">"Waiting for 5 seconds..."</span><span class="hl-1">);</span><br/><span class="hl-1"> </span><span class="hl-3">return</span><span class="hl-1"> </span><span class="hl-0">switchbot</span><span class="hl-1">.</span><span class="hl-7">wait</span><span class="hl-1">(</span><span class="hl-8">5000</span><span class="hl-1">);</span><br/><span class="hl-1"> })</span><br/><span class="hl-1"> .</span><span class="hl-7">then</span><span class="hl-1">(() </span><span class="hl-5">=></span><span class="hl-1"> {</span><br/><span class="hl-1"> </span><span class="hl-0">console</span><span class="hl-1">.</span><span class="hl-7">log</span><span class="hl-1">(</span><span class="hl-4">"Putting the arm up..."</span><span class="hl-1">);</span><br/><span class="hl-1"> </span><span class="hl-3">return</span><span class="hl-1"> </span><span class="hl-0">device</span><span class="hl-1">.</span><span class="hl-7">up</span><span class="hl-1">();</span><br/><span class="hl-1"> })</span><br/><span class="hl-1"> .</span><span class="hl-7">then</span><span class="hl-1">(() </span><span class="hl-5">=></span><span class="hl-1"> {</span><br/><span class="hl-1"> </span><span class="hl-0">console</span><span class="hl-1">.</span><span class="hl-7">log</span><span class="hl-1">(</span><span class="hl-4">"Disconnecting..."</span><span class="hl-1">);</span><br/><span class="hl-1"> </span><span class="hl-3">return</span><span class="hl-1"> </span><span class="hl-0">device</span><span class="hl-1">.</span><span class="hl-7">disconnect</span><span class="hl-1">();</span><br/><span class="hl-1"> })</span><br/><span class="hl-1"> .</span><span class="hl-7">then</span><span class="hl-1">(() </span><span class="hl-5">=></span><span class="hl-1"> {</span><br/><span class="hl-1"> </span><span class="hl-0">console</span><span class="hl-1">.</span><span class="hl-7">log</span><span class="hl-1">(</span><span class="hl-4">"Done."</span><span class="hl-1">);</span><br/><span class="hl-1"> </span><span class="hl-0">process</span><span class="hl-1">.</span><span class="hl-7">exit</span><span class="hl-1">();</span><br/><span class="hl-1"> })</span><br/><span class="hl-1"> .</span><span class="hl-7">catch</span><span class="hl-1">((</span><span class="hl-0">error</span><span class="hl-1">) </span><span class="hl-5">=></span><span class="hl-1"> {</span><br/><span class="hl-1"> </span><span class="hl-0">console</span><span class="hl-1">.</span><span class="hl-7">error</span><span class="hl-1">(</span><span class="hl-0">error</span><span class="hl-1">);</span><br/><span class="hl-1"> </span><span class="hl-0">process</span><span class="hl-1">.</span><span class="hl-7">exit</span><span class="hl-1">();</span><br/><span class="hl-1"> });</span>
|
|
333
|
-
</code><button type="button">Copy</button></pre>
|
|
334
|
-
|
|
335
|
-
<p>The result will be as follows:</p>
|
|
336
|
-
<pre><code><span class="hl-7">WoHand</span><span class="hl-1"> (</span><span class="hl-0">c1</span><span class="hl-1">:2</span><span class="hl-0">e</span><span class="hl-1">:</span><span class="hl-8">45</span><span class="hl-1">:3</span><span class="hl-0">e</span><span class="hl-1">:</span><span class="hl-8">20</span><span class="hl-1">:</span><span class="hl-8">08</span><span class="hl-1">) </span><span class="hl-0">was</span><span class="hl-1"> </span><span class="hl-0">found</span><span class="hl-1">.</span><br/><span class="hl-0">Connecting</span><span class="hl-1">...</span><br/><span class="hl-0">Putting</span><span class="hl-1"> </span><span class="hl-0">the</span><span class="hl-1"> </span><span class="hl-0">arm</span><span class="hl-1"> </span><span class="hl-0">down</span><span class="hl-1">...</span><br/><span class="hl-0">Waiting</span><span class="hl-1"> </span><span class="hl-0">for</span><span class="hl-1"> </span><span class="hl-8">5</span><span class="hl-1"> </span><span class="hl-0">seconds</span><span class="hl-1">...</span><br/><span class="hl-0">Putting</span><span class="hl-1"> </span><span class="hl-0">the</span><span class="hl-1"> </span><span class="hl-0">arm</span><span class="hl-1"> </span><span class="hl-0">up</span><span class="hl-1">...</span><br/><span class="hl-0">Disconnecting</span><span class="hl-1">...</span><br/><span class="hl-0">Done</span><span class="hl-1">.</span>
|
|
337
|
-
</code><button>Copy</button></pre>
|
|
338
|
-
|
|
339
|
-
<a id="md:disconnect-method" class="tsd-anchor"></a><h3 class="tsd-anchor-link"><code>disconnect()</code> method<a href="#md:disconnect-method" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24"><use href="assets/icons.svg#icon-anchor"></use></svg></a></h3><p>The <code>disconnect()</code> method disconnects the device. This method returns a <code>Promise</code> object. If the device has already been disconnected, this method does nothing and calls the <code>resolve()</code> function immediately.</p>
|
|
340
|
-
<p>See the <a href="#md:SwitchbotDevice-connect-method">previous section</a> for more details.</p>
|
|
341
|
-
<a id="md:onconnect-event-handler" class="tsd-anchor"></a><h3 class="tsd-anchor-link"><code>onconnect</code> event handler<a href="#md:onconnect-event-handler" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24"><use href="assets/icons.svg#icon-anchor"></use></svg></a></h3><p>The <code>onconnect</code> event handler will be called when the connection with the device is established. Nothing will be passed to the handler.</p>
|
|
342
|
-
<p>The code below calls the <a href="#md:SwitchbotDeviceWoHand-press-method"><code>press()</code></a> method, while callback functions are attached to the <code>onconnect</code> and <code>ondisconnect</code>.</p>
|
|
343
|
-
<pre><code class="Typescript"><span class="hl-0">switchbot</span><br/><span class="hl-1"> .</span><span class="hl-7">discover</span><span class="hl-1">({ </span><span class="hl-0">model:</span><span class="hl-1"> </span><span class="hl-4">"H"</span><span class="hl-1">, </span><span class="hl-0">quick:</span><span class="hl-1"> </span><span class="hl-5">true</span><span class="hl-1"> })</span><br/><span class="hl-1"> .</span><span class="hl-7">then</span><span class="hl-1">((</span><span class="hl-0">device_list</span><span class="hl-1">) </span><span class="hl-5">=></span><span class="hl-1"> {</span><br/><span class="hl-1"> </span><span class="hl-5">const</span><span class="hl-1"> </span><span class="hl-6">device</span><span class="hl-1"> = </span><span class="hl-0">device_list</span><span class="hl-1">[</span><span class="hl-8">0</span><span class="hl-1">];</span><br/><span class="hl-1"> </span><span class="hl-3">if</span><span class="hl-1"> (!</span><span class="hl-0">device</span><span class="hl-1">) {</span><br/><span class="hl-1"> </span><span class="hl-0">console</span><span class="hl-1">.</span><span class="hl-7">log</span><span class="hl-1">(</span><span class="hl-4">"No device was found."</span><span class="hl-1">);</span><br/><span class="hl-1"> </span><span class="hl-0">process</span><span class="hl-1">.</span><span class="hl-7">exit</span><span class="hl-1">();</span><br/><span class="hl-1"> }</span><br/><span class="hl-1"> </span><span class="hl-0">console</span><span class="hl-1">.</span><span class="hl-7">log</span><span class="hl-1">(</span><span class="hl-0">device</span><span class="hl-1">.</span><span class="hl-0">modelName</span><span class="hl-1"> + </span><span class="hl-4">" ("</span><span class="hl-1"> + </span><span class="hl-0">device</span><span class="hl-1">.</span><span class="hl-0">address</span><span class="hl-1"> + </span><span class="hl-4">") was found."</span><span class="hl-1">);</span><br/><br/><span class="hl-1"> </span><span class="hl-2">// Set event handers</span><br/><span class="hl-1"> </span><span class="hl-0">device</span><span class="hl-1">.</span><span class="hl-7">onconnect</span><span class="hl-1"> = () </span><span class="hl-5">=></span><span class="hl-1"> {</span><br/><span class="hl-1"> </span><span class="hl-0">console</span><span class="hl-1">.</span><span class="hl-7">log</span><span class="hl-1">(</span><span class="hl-4">"Connected."</span><span class="hl-1">);</span><br/><span class="hl-1"> };</span><br/><span class="hl-1"> </span><span class="hl-0">device</span><span class="hl-1">.</span><span class="hl-7">ondisconnect</span><span class="hl-1"> = () </span><span class="hl-5">=></span><span class="hl-1"> {</span><br/><span class="hl-1"> </span><span class="hl-0">console</span><span class="hl-1">.</span><span class="hl-7">log</span><span class="hl-1">(</span><span class="hl-4">"Disconnected."</span><span class="hl-1">);</span><br/><span class="hl-1"> };</span><br/><br/><span class="hl-1"> </span><span class="hl-0">console</span><span class="hl-1">.</span><span class="hl-7">log</span><span class="hl-1">(</span><span class="hl-4">"Pressing the switch..."</span><span class="hl-1">);</span><br/><span class="hl-1"> </span><span class="hl-3">return</span><span class="hl-1"> </span><span class="hl-0">device</span><span class="hl-1">.</span><span class="hl-7">press</span><span class="hl-1">();</span><br/><span class="hl-1"> })</span><br/><span class="hl-1"> .</span><span class="hl-7">then</span><span class="hl-1">(() </span><span class="hl-5">=></span><span class="hl-1"> {</span><br/><span class="hl-1"> </span><span class="hl-0">console</span><span class="hl-1">.</span><span class="hl-7">log</span><span class="hl-1">(</span><span class="hl-4">"Done."</span><span class="hl-1">);</span><br/><span class="hl-1"> </span><span class="hl-0">process</span><span class="hl-1">.</span><span class="hl-7">exit</span><span class="hl-1">();</span><br/><span class="hl-1"> })</span><br/><span class="hl-1"> .</span><span class="hl-7">catch</span><span class="hl-1">((</span><span class="hl-0">error</span><span class="hl-1">) </span><span class="hl-5">=></span><span class="hl-1"> {</span><br/><span class="hl-1"> </span><span class="hl-0">console</span><span class="hl-1">.</span><span class="hl-7">error</span><span class="hl-1">(</span><span class="hl-0">error</span><span class="hl-1">);</span><br/><span class="hl-1"> </span><span class="hl-0">process</span><span class="hl-1">.</span><span class="hl-7">exit</span><span class="hl-1">();</span><br/><span class="hl-1"> });</span>
|
|
344
|
-
</code><button type="button">Copy</button></pre>
|
|
345
|
-
|
|
346
|
-
<p>The code above will output the result as follows:</p>
|
|
347
|
-
<pre><code><span class="hl-7">WoHand</span><span class="hl-1"> (</span><span class="hl-0">c1</span><span class="hl-1">:2</span><span class="hl-0">e</span><span class="hl-1">:</span><span class="hl-8">45</span><span class="hl-1">:3</span><span class="hl-0">e</span><span class="hl-1">:</span><span class="hl-8">20</span><span class="hl-1">:</span><span class="hl-8">08</span><span class="hl-1">) </span><span class="hl-0">was</span><span class="hl-1"> </span><span class="hl-0">found</span><span class="hl-1">.</span><br/><span class="hl-0">Pressing</span><span class="hl-1"> </span><span class="hl-0">the</span><span class="hl-1"> </span><span class="hl-3">switch</span><span class="hl-1">...</span><br/><span class="hl-0">Connected</span><span class="hl-1">.</span><br/><span class="hl-0">Disconnected</span><span class="hl-1">.</span><br/><span class="hl-0">Done</span><span class="hl-1">.</span>
|
|
348
|
-
</code><button>Copy</button></pre>
|
|
349
|
-
|
|
350
|
-
<p>Seeing the result, you would find the <a href="#md:SwitchbotDeviceWoHand-press-method"><code>press()</code></a> method automatically connects and disconnects the device.</p>
|
|
351
|
-
<a id="md:ondisconnect-event-handler" class="tsd-anchor"></a><h3 class="tsd-anchor-link"><code>ondisconnect</code> event handler<a href="#md:ondisconnect-event-handler" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24"><use href="assets/icons.svg#icon-anchor"></use></svg></a></h3><p>The <code>ondisconnect</code> event handler will be called when the connection with the device is closed. Nothing will be passed to the handler. See the previous section "<a href="#md:SwitchbotDevice-onconnect-event-handler"><code>onconnect</code> event handler</a>" for more details.</p>
|
|
352
|
-
<hr>
|
|
353
|
-
<a id="md:wohand-object" class="tsd-anchor"></a><h2 class="tsd-anchor-link"><code>WoHand</code> object<a href="#md:wohand-object" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24"><use href="assets/icons.svg#icon-anchor"></use></svg></a></h2><p>The <code>WoHand</code> object represents a Bot, which is created through the discovery process triggered by the <a href="#md:Switchbot-discover-method"><code>Switchbot.discover()</code></a> method.</p>
|
|
354
|
-
<p>Actually, the <code>WoHand</code> is an object inherited from the <a href="#md:SwitchbotDevice-object"><code>SwitchbotDevice</code></a>. You can use not only the method described in this section but also the properties and methods implemented in the <a href="#md:SwitchbotDevice-object"><code>SwitchbotDevice</code></a> object.</p>
|
|
355
|
-
<a id="md:press-method" class="tsd-anchor"></a><h3 class="tsd-anchor-link"><code>press()</code> method<a href="#md:press-method" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24"><use href="assets/icons.svg#icon-anchor"></use></svg></a></h3><p>The <code>press()</code> method sends a press command to the Bot. This method returns a <code>Promise</code> object. Nothing will be passed to the <code>resove()</code>.</p>
|
|
356
|
-
<p>If no connection is established with the device, this method automatically establishes a connection with the device, then finally closes the connection. You don't have to call the <a href="#md:SwitchbotDevice-connect-method"><code>connect()</code></a> method in advance.</p>
|
|
357
|
-
<pre><code class="Typescript"><span class="hl-0">switchbot</span><br/><span class="hl-1"> .</span><span class="hl-7">discover</span><span class="hl-1">({ </span><span class="hl-0">model:</span><span class="hl-1"> </span><span class="hl-4">"H"</span><span class="hl-1">, </span><span class="hl-0">quick:</span><span class="hl-1"> </span><span class="hl-5">true</span><span class="hl-1"> })</span><br/><span class="hl-1"> .</span><span class="hl-7">then</span><span class="hl-1">((</span><span class="hl-0">device_list</span><span class="hl-1">) </span><span class="hl-5">=></span><span class="hl-1"> {</span><br/><span class="hl-1"> </span><span class="hl-3">return</span><span class="hl-1"> </span><span class="hl-0">device_list</span><span class="hl-1">[</span><span class="hl-8">0</span><span class="hl-1">].</span><span class="hl-7">press</span><span class="hl-1">();</span><br/><span class="hl-1"> })</span><br/><span class="hl-1"> .</span><span class="hl-7">then</span><span class="hl-1">(() </span><span class="hl-5">=></span><span class="hl-1"> {</span><br/><span class="hl-1"> </span><span class="hl-0">console</span><span class="hl-1">.</span><span class="hl-7">log</span><span class="hl-1">(</span><span class="hl-4">"Done."</span><span class="hl-1">);</span><br/><span class="hl-1"> })</span><br/><span class="hl-1"> .</span><span class="hl-7">catch</span><span class="hl-1">((</span><span class="hl-0">error</span><span class="hl-1">) </span><span class="hl-5">=></span><span class="hl-1"> {</span><br/><span class="hl-1"> </span><span class="hl-0">console</span><span class="hl-1">.</span><span class="hl-7">error</span><span class="hl-1">(</span><span class="hl-0">error</span><span class="hl-1">);</span><br/><span class="hl-1"> });</span>
|
|
358
|
-
</code><button type="button">Copy</button></pre>
|
|
359
|
-
|
|
360
|
-
<p>When the Bot receives this command, the Bot's arm will be put down (stretched), then put up (retracted) in a few seconds.</p>
|
|
361
|
-
<a id="md:turnon-method" class="tsd-anchor"></a><h3 class="tsd-anchor-link"><code>turnOn()</code> method<a href="#md:turnon-method" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24"><use href="assets/icons.svg#icon-anchor"></use></svg></a></h3><p>The <code>turnOn()</code> method sends a turn-on command to the Bot. This method returns a <code>Promise</code> object. Nothing will be passed to the <code>resove()</code>.</p>
|
|
362
|
-
<p>If no connection is established with the device, this method automatically establishes a connection with the device, then finally closes the connection. You don't have to call the <a href="#md:SwitchbotDevice-connect-method"><code>connect()</code></a> method in advance.</p>
|
|
363
|
-
<p>When the Bot receives this command, the Bot's arm will be put down (stretched) or put up (retracted) depending on the mode setting.</p>
|
|
364
|
-
<table>
|
|
365
|
-
<thead>
|
|
366
|
-
<tr>
|
|
367
|
-
<th style="text-align:left">Mode</th>
|
|
368
|
-
<th style="text-align:left">Inverse the on/off direction</th>
|
|
369
|
-
<th style="text-align:left">Physical position of the arm</th>
|
|
370
|
-
</tr>
|
|
371
|
-
</thead>
|
|
372
|
-
<tbody>
|
|
373
|
-
<tr>
|
|
374
|
-
<td style="text-align:left">Press mode</td>
|
|
375
|
-
<td style="text-align:left">N/A</td>
|
|
376
|
-
<td style="text-align:left">Down (stretched), then Up (retracted)</td>
|
|
377
|
-
</tr>
|
|
378
|
-
<tr>
|
|
379
|
-
<td style="text-align:left">Switch mode</td>
|
|
380
|
-
<td style="text-align:left">Disabled</td>
|
|
381
|
-
<td style="text-align:left">Down (stretched)</td>
|
|
382
|
-
</tr>
|
|
383
|
-
<tr>
|
|
384
|
-
<td style="text-align:left"> </td>
|
|
385
|
-
<td style="text-align:left">Enabled</td>
|
|
386
|
-
<td style="text-align:left">Up (retracted)</td>
|
|
387
|
-
</tr>
|
|
388
|
-
</tbody>
|
|
389
|
-
</table>
|
|
390
|
-
<pre><code class="Typescript"><span class="hl-0">switchbot</span><br/><span class="hl-1"> .</span><span class="hl-7">discover</span><span class="hl-1">({ </span><span class="hl-0">model:</span><span class="hl-1"> </span><span class="hl-4">"H"</span><span class="hl-1">, </span><span class="hl-0">quick:</span><span class="hl-1"> </span><span class="hl-5">true</span><span class="hl-1"> })</span><br/><span class="hl-1"> .</span><span class="hl-7">then</span><span class="hl-1">((</span><span class="hl-0">device_list</span><span class="hl-1">) </span><span class="hl-5">=></span><span class="hl-1"> {</span><br/><span class="hl-1"> </span><span class="hl-3">return</span><span class="hl-1"> </span><span class="hl-0">device_list</span><span class="hl-1">[</span><span class="hl-8">0</span><span class="hl-1">].</span><span class="hl-7">turnOn</span><span class="hl-1">();</span><br/><span class="hl-1"> })</span><br/><span class="hl-1"> .</span><span class="hl-7">then</span><span class="hl-1">(() </span><span class="hl-5">=></span><span class="hl-1"> {</span><br/><span class="hl-1"> </span><span class="hl-0">console</span><span class="hl-1">.</span><span class="hl-7">log</span><span class="hl-1">(</span><span class="hl-4">"Done."</span><span class="hl-1">);</span><br/><span class="hl-1"> })</span><br/><span class="hl-1"> .</span><span class="hl-7">catch</span><span class="hl-1">((</span><span class="hl-0">error</span><span class="hl-1">) </span><span class="hl-5">=></span><span class="hl-1"> {</span><br/><span class="hl-1"> </span><span class="hl-0">console</span><span class="hl-1">.</span><span class="hl-7">error</span><span class="hl-1">(</span><span class="hl-0">error</span><span class="hl-1">);</span><br/><span class="hl-1"> });</span>
|
|
391
|
-
</code><button type="button">Copy</button></pre>
|
|
392
|
-
|
|
393
|
-
<a id="md:turnoff-method" class="tsd-anchor"></a><h3 class="tsd-anchor-link"><code>turnOff()</code> method<a href="#md:turnoff-method" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24"><use href="assets/icons.svg#icon-anchor"></use></svg></a></h3><p>The <code>turnOff()</code> method sends a turn-off command to the Bot. This method returns a <code>Promise</code> object. Nothing will be passed to the <code>resove()</code>.</p>
|
|
394
|
-
<p>If no connection is established with the device, this method automatically establishes a connection with the device, then finally closes the connection. You don't have to call the <a href="#md:SwitchbotDevice-connect-method"><code>connect()</code></a> method in advance.</p>
|
|
395
|
-
<p>When the Bot receives this command, the Bot's arm will be put down (stretched) or put up (retracted) depending on the mode setting.</p>
|
|
396
|
-
<table>
|
|
397
|
-
<thead>
|
|
398
|
-
<tr>
|
|
399
|
-
<th style="text-align:left">Mode</th>
|
|
400
|
-
<th style="text-align:left">Inverse the on/off direction</th>
|
|
401
|
-
<th style="text-align:left">Physical position of the arm</th>
|
|
402
|
-
</tr>
|
|
403
|
-
</thead>
|
|
404
|
-
<tbody>
|
|
405
|
-
<tr>
|
|
406
|
-
<td style="text-align:left">Press mode</td>
|
|
407
|
-
<td style="text-align:left">N/A</td>
|
|
408
|
-
<td style="text-align:left">Down (stretched), then Up (retracted)</td>
|
|
409
|
-
</tr>
|
|
410
|
-
<tr>
|
|
411
|
-
<td style="text-align:left">Switch mode</td>
|
|
412
|
-
<td style="text-align:left">Disabled</td>
|
|
413
|
-
<td style="text-align:left">Up (retracted)</td>
|
|
414
|
-
</tr>
|
|
415
|
-
<tr>
|
|
416
|
-
<td style="text-align:left"> </td>
|
|
417
|
-
<td style="text-align:left">Enabled</td>
|
|
418
|
-
<td style="text-align:left">Down (stretched)</td>
|
|
419
|
-
</tr>
|
|
420
|
-
</tbody>
|
|
421
|
-
</table>
|
|
422
|
-
<pre><code class="Typescript"><span class="hl-0">switchbot</span><br/><span class="hl-1"> .</span><span class="hl-7">discover</span><span class="hl-1">({ </span><span class="hl-0">model:</span><span class="hl-1"> </span><span class="hl-4">"H"</span><span class="hl-1">, </span><span class="hl-0">quick:</span><span class="hl-1"> </span><span class="hl-5">true</span><span class="hl-1"> })</span><br/><span class="hl-1"> .</span><span class="hl-7">then</span><span class="hl-1">((</span><span class="hl-0">device_list</span><span class="hl-1">) </span><span class="hl-5">=></span><span class="hl-1"> {</span><br/><span class="hl-1"> </span><span class="hl-3">return</span><span class="hl-1"> </span><span class="hl-0">device_list</span><span class="hl-1">[</span><span class="hl-8">0</span><span class="hl-1">].</span><span class="hl-7">turnOff</span><span class="hl-1">();</span><br/><span class="hl-1"> })</span><br/><span class="hl-1"> .</span><span class="hl-7">then</span><span class="hl-1">(() </span><span class="hl-5">=></span><span class="hl-1"> {</span><br/><span class="hl-1"> </span><span class="hl-0">console</span><span class="hl-1">.</span><span class="hl-7">log</span><span class="hl-1">(</span><span class="hl-4">"Done."</span><span class="hl-1">);</span><br/><span class="hl-1"> })</span><br/><span class="hl-1"> .</span><span class="hl-7">catch</span><span class="hl-1">((</span><span class="hl-0">error</span><span class="hl-1">) </span><span class="hl-5">=></span><span class="hl-1"> {</span><br/><span class="hl-1"> </span><span class="hl-0">console</span><span class="hl-1">.</span><span class="hl-7">error</span><span class="hl-1">(</span><span class="hl-0">error</span><span class="hl-1">);</span><br/><span class="hl-1"> });</span>
|
|
423
|
-
</code><button type="button">Copy</button></pre>
|
|
424
|
-
|
|
425
|
-
<a id="md:down-method" class="tsd-anchor"></a><h3 class="tsd-anchor-link"><code>down()</code> method<a href="#md:down-method" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24"><use href="assets/icons.svg#icon-anchor"></use></svg></a></h3><p>The <code>down()</code> method sends a down command to the Bot. This method returns a <code>Promise</code> object. Nothing will be passed to the <code>resove()</code>.</p>
|
|
426
|
-
<p>If no connection is established with the device, this method automatically establishes a connection with the device, then finally closes the connection. You don't have to call the <a href="#md:SwitchbotDevice-connect-method"><code>connect()</code></a> method in advance.</p>
|
|
427
|
-
<p>When the Bot receives this command, the Bot's arm will be put down (stretched) regardless of the mode setting.</p>
|
|
428
|
-
<pre><code class="Typescript"><span class="hl-0">switchbot</span><br/><span class="hl-1"> .</span><span class="hl-7">discover</span><span class="hl-1">({ </span><span class="hl-0">model:</span><span class="hl-1"> </span><span class="hl-4">"H"</span><span class="hl-1">, </span><span class="hl-0">quick:</span><span class="hl-1"> </span><span class="hl-5">true</span><span class="hl-1"> })</span><br/><span class="hl-1"> .</span><span class="hl-7">then</span><span class="hl-1">((</span><span class="hl-0">device_list</span><span class="hl-1">) </span><span class="hl-5">=></span><span class="hl-1"> {</span><br/><span class="hl-1"> </span><span class="hl-3">return</span><span class="hl-1"> </span><span class="hl-0">device_list</span><span class="hl-1">[</span><span class="hl-8">0</span><span class="hl-1">].</span><span class="hl-7">down</span><span class="hl-1">();</span><br/><span class="hl-1"> })</span><br/><span class="hl-1"> .</span><span class="hl-7">then</span><span class="hl-1">(() </span><span class="hl-5">=></span><span class="hl-1"> {</span><br/><span class="hl-1"> </span><span class="hl-0">console</span><span class="hl-1">.</span><span class="hl-7">log</span><span class="hl-1">(</span><span class="hl-4">"Done."</span><span class="hl-1">);</span><br/><span class="hl-1"> })</span><br/><span class="hl-1"> .</span><span class="hl-7">catch</span><span class="hl-1">((</span><span class="hl-0">error</span><span class="hl-1">) </span><span class="hl-5">=></span><span class="hl-1"> {</span><br/><span class="hl-1"> </span><span class="hl-0">console</span><span class="hl-1">.</span><span class="hl-7">error</span><span class="hl-1">(</span><span class="hl-0">error</span><span class="hl-1">);</span><br/><span class="hl-1"> });</span>
|
|
429
|
-
</code><button type="button">Copy</button></pre>
|
|
430
|
-
|
|
431
|
-
<a id="md:up-method" class="tsd-anchor"></a><h3 class="tsd-anchor-link"><code>up()</code> method<a href="#md:up-method" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24"><use href="assets/icons.svg#icon-anchor"></use></svg></a></h3><p>The <code>up()</code> method sends an up command to the Bot. This method returns a <code>Promise</code> object. Nothing will be passed to the <code>resove()</code>.</p>
|
|
432
|
-
<p>If no connection is established with the device, this method automatically establishes a connection with the device, then finally closes the connection. You don't have to call the <a href="#md:SwitchbotDevice-connect-method"><code>connect()</code></a> method in advance.</p>
|
|
433
|
-
<p>When the Bot receives this command, the Bot's arm will be put up (retracted) regardless of the mode setting.</p>
|
|
434
|
-
<pre><code class="Typescript"><span class="hl-0">switchbot</span><br/><span class="hl-1"> .</span><span class="hl-7">discover</span><span class="hl-1">({ </span><span class="hl-0">model:</span><span class="hl-1"> </span><span class="hl-4">"H"</span><span class="hl-1">, </span><span class="hl-0">quick:</span><span class="hl-1"> </span><span class="hl-5">true</span><span class="hl-1"> })</span><br/><span class="hl-1"> .</span><span class="hl-7">then</span><span class="hl-1">((</span><span class="hl-0">device_list</span><span class="hl-1">) </span><span class="hl-5">=></span><span class="hl-1"> {</span><br/><span class="hl-1"> </span><span class="hl-3">return</span><span class="hl-1"> </span><span class="hl-0">device_list</span><span class="hl-1">[</span><span class="hl-8">0</span><span class="hl-1">].</span><span class="hl-7">up</span><span class="hl-1">();</span><br/><span class="hl-1"> })</span><br/><span class="hl-1"> .</span><span class="hl-7">then</span><span class="hl-1">(() </span><span class="hl-5">=></span><span class="hl-1"> {</span><br/><span class="hl-1"> </span><span class="hl-0">console</span><span class="hl-1">.</span><span class="hl-7">log</span><span class="hl-1">(</span><span class="hl-4">"Done."</span><span class="hl-1">);</span><br/><span class="hl-1"> })</span><br/><span class="hl-1"> .</span><span class="hl-7">catch</span><span class="hl-1">((</span><span class="hl-0">error</span><span class="hl-1">) </span><span class="hl-5">=></span><span class="hl-1"> {</span><br/><span class="hl-1"> </span><span class="hl-0">console</span><span class="hl-1">.</span><span class="hl-7">error</span><span class="hl-1">(</span><span class="hl-0">error</span><span class="hl-1">);</span><br/><span class="hl-1"> });</span>
|
|
435
|
-
</code><button type="button">Copy</button></pre>
|
|
436
|
-
|
|
437
|
-
<hr>
|
|
438
|
-
<a id="md:wocurtain-object" class="tsd-anchor"></a><h2 class="tsd-anchor-link"><code>WoCurtain</code> object<a href="#md:wocurtain-object" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24"><use href="assets/icons.svg#icon-anchor"></use></svg></a></h2><p>The <code>WoCurtain</code> object represents a Curtain, which is created through the discovery process triggered by the <a href="#md:Switchbot-discover-method"><code>Switchbot.discover()</code></a> method.</p>
|
|
439
|
-
<p>Actually, the <code>WoCurtain</code> is an object inherited from the <a href="#md:SwitchbotDevice-object"><code>SwitchbotDevice</code></a>. You can use not only the method described in this section but also the properties and methods implemented in the <a href="#md:SwitchbotDevice-object"><code>SwitchbotDevice</code></a> object.</p>
|
|
440
|
-
<a id="md:open-method" class="tsd-anchor"></a><h3 class="tsd-anchor-link"><code>open()</code> method<a href="#md:open-method" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24"><use href="assets/icons.svg#icon-anchor"></use></svg></a></h3><p>The <code>open()</code> method sends an open command to the Curtain. This method returns a <code>Promise</code> object. Nothing will be passed to the <code>resove()</code>.</p>
|
|
441
|
-
<p>If no connection is established with the device, this method automatically establishes a connection with the device, then finally closes the connection. You don't have to call the <a href="#md:SwitchbotDevice-connect-method"><code>connect()</code></a> method in advance.</p>
|
|
442
|
-
<p>When the Curtain receives this command, the Curtain will open the curtain (0% position). If not calibrated, the Curtain does not move.</p>
|
|
443
|
-
<p>The <code>open()</code> method receives an optional <code>mode</code> parameter. (See <a href="#md:runtopos-method"><code>runToPos()</code></a>)</p>
|
|
444
|
-
<pre><code class="Typescript"><span class="hl-0">switchbot</span><br/><span class="hl-1"> .</span><span class="hl-7">discover</span><span class="hl-1">({ </span><span class="hl-0">model:</span><span class="hl-1"> </span><span class="hl-4">"c"</span><span class="hl-1">, </span><span class="hl-0">quick:</span><span class="hl-1"> </span><span class="hl-5">true</span><span class="hl-1"> })</span><br/><span class="hl-1"> .</span><span class="hl-7">then</span><span class="hl-1">((</span><span class="hl-0">device_list</span><span class="hl-1">) </span><span class="hl-5">=></span><span class="hl-1"> {</span><br/><span class="hl-1"> </span><span class="hl-3">return</span><span class="hl-1"> </span><span class="hl-0">device_list</span><span class="hl-1">[</span><span class="hl-8">0</span><span class="hl-1">].</span><span class="hl-7">open</span><span class="hl-1">();</span><br/><span class="hl-1"> })</span><br/><span class="hl-1"> .</span><span class="hl-7">then</span><span class="hl-1">(() </span><span class="hl-5">=></span><span class="hl-1"> {</span><br/><span class="hl-1"> </span><span class="hl-0">console</span><span class="hl-1">.</span><span class="hl-7">log</span><span class="hl-1">(</span><span class="hl-4">"Done."</span><span class="hl-1">);</span><br/><span class="hl-1"> })</span><br/><span class="hl-1"> .</span><span class="hl-7">catch</span><span class="hl-1">((</span><span class="hl-0">error</span><span class="hl-1">) </span><span class="hl-5">=></span><span class="hl-1"> {</span><br/><span class="hl-1"> </span><span class="hl-0">console</span><span class="hl-1">.</span><span class="hl-7">error</span><span class="hl-1">(</span><span class="hl-0">error</span><span class="hl-1">);</span><br/><span class="hl-1"> });</span>
|
|
445
|
-
</code><button type="button">Copy</button></pre>
|
|
446
|
-
|
|
447
|
-
<a id="md:close-method" class="tsd-anchor"></a><h3 class="tsd-anchor-link"><code>close()</code> method<a href="#md:close-method" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24"><use href="assets/icons.svg#icon-anchor"></use></svg></a></h3><p>The <code>close()</code> method sends a close command to the Curtain. This method returns a <code>Promise</code> object. Nothing will be passed to the <code>resove()</code>.</p>
|
|
448
|
-
<p>If no connection is established with the device, this method automatically establishes a connection with the device, then finally closes the connection. You don't have to call the <a href="#md:SwitchbotDevice-connect-method"><code>connect()</code></a> method in advance.</p>
|
|
449
|
-
<p>When the Curtain receives this command, the Curtain will close the curtain (100% position). If not calibrated, the Curtain does not move.</p>
|
|
450
|
-
<p>The <code>close()</code> method receives an optional <code>mode</code> parameter. (See <a href="#md:runtopos-method"><code>runToPos()</code></a>)</p>
|
|
451
|
-
<pre><code class="Typescript"><span class="hl-0">switchbot</span><br/><span class="hl-1"> .</span><span class="hl-7">discover</span><span class="hl-1">({ </span><span class="hl-0">model:</span><span class="hl-1"> </span><span class="hl-4">"c"</span><span class="hl-1">, </span><span class="hl-0">quick:</span><span class="hl-1"> </span><span class="hl-5">true</span><span class="hl-1"> })</span><br/><span class="hl-1"> .</span><span class="hl-7">then</span><span class="hl-1">((</span><span class="hl-0">device_list</span><span class="hl-1">) </span><span class="hl-5">=></span><span class="hl-1"> {</span><br/><span class="hl-1"> </span><span class="hl-3">return</span><span class="hl-1"> </span><span class="hl-0">device_list</span><span class="hl-1">[</span><span class="hl-8">0</span><span class="hl-1">].</span><span class="hl-7">close</span><span class="hl-1">();</span><br/><span class="hl-1"> })</span><br/><span class="hl-1"> .</span><span class="hl-7">then</span><span class="hl-1">(() </span><span class="hl-5">=></span><span class="hl-1"> {</span><br/><span class="hl-1"> </span><span class="hl-0">console</span><span class="hl-1">.</span><span class="hl-7">log</span><span class="hl-1">(</span><span class="hl-4">"Done."</span><span class="hl-1">);</span><br/><span class="hl-1"> })</span><br/><span class="hl-1"> .</span><span class="hl-7">catch</span><span class="hl-1">((</span><span class="hl-0">error</span><span class="hl-1">) </span><span class="hl-5">=></span><span class="hl-1"> {</span><br/><span class="hl-1"> </span><span class="hl-0">console</span><span class="hl-1">.</span><span class="hl-7">error</span><span class="hl-1">(</span><span class="hl-0">error</span><span class="hl-1">);</span><br/><span class="hl-1"> });</span>
|
|
452
|
-
</code><button type="button">Copy</button></pre>
|
|
453
|
-
|
|
454
|
-
<a id="md:pause-method" class="tsd-anchor"></a><h3 class="tsd-anchor-link"><code>pause()</code> method<a href="#md:pause-method" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24"><use href="assets/icons.svg#icon-anchor"></use></svg></a></h3><p>The <code>pause()</code> method sends a pause command to the Curtain. This method returns a <code>Promise</code> object. Nothing will be passed to the <code>resove()</code>.</p>
|
|
455
|
-
<p>If no connection is established with the device, this method automatically establishes a connection with the device, then finally closes the connection. You don't have to call the <a href="#md:SwitchbotDevice-connect-method"><code>connect()</code></a> method in advance.</p>
|
|
456
|
-
<p>When the Curtain receives this command, the Curtain will pause.</p>
|
|
457
|
-
<pre><code class="Typescript"><span class="hl-0">switchbot</span><br/><span class="hl-1"> .</span><span class="hl-7">discover</span><span class="hl-1">({ </span><span class="hl-0">model:</span><span class="hl-1"> </span><span class="hl-4">"c"</span><span class="hl-1">, </span><span class="hl-0">quick:</span><span class="hl-1"> </span><span class="hl-5">true</span><span class="hl-1"> })</span><br/><span class="hl-1"> .</span><span class="hl-7">then</span><span class="hl-1">((</span><span class="hl-0">device_list</span><span class="hl-1">) </span><span class="hl-5">=></span><span class="hl-1"> {</span><br/><span class="hl-1"> </span><span class="hl-3">return</span><span class="hl-1"> </span><span class="hl-0">device_list</span><span class="hl-1">[</span><span class="hl-8">0</span><span class="hl-1">].</span><span class="hl-7">pause</span><span class="hl-1">();</span><br/><span class="hl-1"> })</span><br/><span class="hl-1"> .</span><span class="hl-7">then</span><span class="hl-1">(() </span><span class="hl-5">=></span><span class="hl-1"> {</span><br/><span class="hl-1"> </span><span class="hl-0">console</span><span class="hl-1">.</span><span class="hl-7">log</span><span class="hl-1">(</span><span class="hl-4">"Done."</span><span class="hl-1">);</span><br/><span class="hl-1"> })</span><br/><span class="hl-1"> .</span><span class="hl-7">catch</span><span class="hl-1">((</span><span class="hl-0">error</span><span class="hl-1">) </span><span class="hl-5">=></span><span class="hl-1"> {</span><br/><span class="hl-1"> </span><span class="hl-0">console</span><span class="hl-1">.</span><span class="hl-7">error</span><span class="hl-1">(</span><span class="hl-0">error</span><span class="hl-1">);</span><br/><span class="hl-1"> });</span>
|
|
458
|
-
</code><button type="button">Copy</button></pre>
|
|
459
|
-
|
|
460
|
-
<a id="md:runtopos-method" class="tsd-anchor"></a><h3 class="tsd-anchor-link"><code>runToPos()</code> method<a href="#md:runtopos-method" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24"><use href="assets/icons.svg#icon-anchor"></use></svg></a></h3><p>The <code>runToPos()</code> method sends a position command to the Curtain. This method returns a <code>Promise</code> object. Nothing will be passed to the <code>resove()</code>.</p>
|
|
461
|
-
<p>If no connection is established with the device, this method automatically establishes a connection with the device, then finally closes the connection. You don't have to call the <a href="#md:SwitchbotDevice-connect-method"><code>connect()</code></a> method in advance.</p>
|
|
462
|
-
<p>When the Curtain receives this command, the Curtain will run to the percentage position. If not calibrated, the Curtain does not move.</p>
|
|
463
|
-
<p>The <code>open()</code> method sends an open command to the Curtain. This method returns a <code>Promise</code> object. Nothing will be passed to the <code>resove()</code>.</p>
|
|
464
|
-
<p>If no connection is established with the device, this method automatically establishes a connection with the device, then finally closes the connection. You don't have to call the <a href="#md:SwitchbotDevice-connect-method"><code>connect()</code></a> method in advance.</p>
|
|
465
|
-
<p>When the Curtain receives this command, the Curtain will open the curtain (0% position). If not calibrated, the Curtain does not move.</p>
|
|
466
|
-
<table>
|
|
467
|
-
<thead>
|
|
468
|
-
<tr>
|
|
469
|
-
<th style="text-align:left">Property</th>
|
|
470
|
-
<th style="text-align:left">Type</th>
|
|
471
|
-
<th style="text-align:left">Required</th>
|
|
472
|
-
<th style="text-align:left">Description</th>
|
|
473
|
-
</tr>
|
|
474
|
-
</thead>
|
|
475
|
-
<tbody>
|
|
476
|
-
<tr>
|
|
477
|
-
<td style="text-align:left"><code>percent</code></td>
|
|
478
|
-
<td style="text-align:left">Integer</td>
|
|
479
|
-
<td style="text-align:left">Required</td>
|
|
480
|
-
<td style="text-align:left">The percentage of target position (<code>0-100</code>). (e.g., <code>50</code>)</td>
|
|
481
|
-
</tr>
|
|
482
|
-
<tr>
|
|
483
|
-
<td style="text-align:left"><code>mode</code></td>
|
|
484
|
-
<td style="text-align:left">Integer</td>
|
|
485
|
-
<td style="text-align:left">Optional</td>
|
|
486
|
-
<td style="text-align:left">The running mode of Curtain. <br/><code>0x00</code> - Performance mode.<br/> <code>0x01</code> - Silent mode. <br/><code>0xff</code> - Default. Unspecified, from Curtain's settings.</td>
|
|
487
|
-
</tr>
|
|
488
|
-
</tbody>
|
|
489
|
-
</table>
|
|
490
|
-
<pre><code class="Typescript"><span class="hl-0">switchbot</span><br/><span class="hl-1"> .</span><span class="hl-7">discover</span><span class="hl-1">({ </span><span class="hl-0">model:</span><span class="hl-1"> </span><span class="hl-4">"c"</span><span class="hl-1">, </span><span class="hl-0">quick:</span><span class="hl-1"> </span><span class="hl-5">true</span><span class="hl-1"> })</span><br/><span class="hl-1"> .</span><span class="hl-7">then</span><span class="hl-1">((</span><span class="hl-0">device_list</span><span class="hl-1">) </span><span class="hl-5">=></span><span class="hl-1"> {</span><br/><span class="hl-1"> </span><span class="hl-3">return</span><span class="hl-1"> </span><span class="hl-0">device_list</span><span class="hl-1">[</span><span class="hl-8">0</span><span class="hl-1">].</span><span class="hl-7">runToPos</span><span class="hl-1">(</span><span class="hl-8">50</span><span class="hl-1">);</span><br/><span class="hl-1"> })</span><br/><span class="hl-1"> .</span><span class="hl-7">then</span><span class="hl-1">(() </span><span class="hl-5">=></span><span class="hl-1"> {</span><br/><span class="hl-1"> </span><span class="hl-0">console</span><span class="hl-1">.</span><span class="hl-7">log</span><span class="hl-1">(</span><span class="hl-4">"Done."</span><span class="hl-1">);</span><br/><span class="hl-1"> })</span><br/><span class="hl-1"> .</span><span class="hl-7">catch</span><span class="hl-1">((</span><span class="hl-0">error</span><span class="hl-1">) </span><span class="hl-5">=></span><span class="hl-1"> {</span><br/><span class="hl-1"> </span><span class="hl-0">console</span><span class="hl-1">.</span><span class="hl-7">error</span><span class="hl-1">(</span><span class="hl-0">error</span><span class="hl-1">);</span><br/><span class="hl-1"> });</span>
|
|
491
|
-
</code><button type="button">Copy</button></pre>
|
|
492
|
-
|
|
493
|
-
<hr>
|
|
494
|
-
<a id="md:woplugmini-object" class="tsd-anchor"></a><h2 class="tsd-anchor-link"><code>WoPlugMini</code> object<a href="#md:woplugmini-object" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24"><use href="assets/icons.svg#icon-anchor"></use></svg></a></h2><p>The <code>WoPlugMini </code> object represents a PlugMini, which is created through the discovery process triggered by the <a href="#md:Switchbot-discover-method"><code>Switchbot.discover()</code></a> method.</p>
|
|
495
|
-
<p>Actually, the <code>WoPlugMini </code> is an object inherited from the <a href="#md:SwitchbotDevice-object"><code>SwitchbotDevice</code></a>. You can use not only the method described in this section but also the properties and methods implemented in the <a href="#md:SwitchbotDevice-object"><code>SwitchbotDevice</code></a> object.</p>
|
|
496
|
-
<a id="md:turnon-method-1" class="tsd-anchor"></a><h3 class="tsd-anchor-link"><code>turnOn()</code> method<a href="#md:turnon-method-1" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24"><use href="assets/icons.svg#icon-anchor"></use></svg></a></h3><p>The <code>turnOn()</code> method sends a turn-on command to the PlugMini. This method returns a <code>Promise</code> object. A <code>boolean</code> value indicating whether the PlugMini is on (<code>true</code>), is passed to the <code>resolve()</code> method of the Promise.</p>
|
|
497
|
-
<p>If no connection is established with the device, this method automatically establishes a connection with the device, then finally closes the connection. You don't have to call the <a href="#md:SwitchbotDevice-connect-method"><code>connect()</code></a> method in advance.</p>
|
|
498
|
-
<a id="md:turnoff-method-1" class="tsd-anchor"></a><h3 class="tsd-anchor-link"><code>turnOff()</code> method<a href="#md:turnoff-method-1" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24"><use href="assets/icons.svg#icon-anchor"></use></svg></a></h3><p>The <code>turnOff()</code> method sends a turn-off command to the PlugMini. This method returns a <code>Promise</code> object. A <code>boolean</code> value indicating whether the PlugMini is off (<code>false</code>), is passed to the <code>resolve()</code> method of the Promise.</p>
|
|
499
|
-
<p>If no connection is established with the device, this method automatically establishes a connection with the device, then finally closes the connection. You don't have to call the <a href="#md:SwitchbotDevice-connect-method"><code>connect()</code></a> method in advance.</p>
|
|
500
|
-
<a id="md:toggle-method" class="tsd-anchor"></a><h3 class="tsd-anchor-link"><code>toggle()</code> method<a href="#md:toggle-method" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24"><use href="assets/icons.svg#icon-anchor"></use></svg></a></h3><p>The <code>toggle()</code> method sends a toggle command to the PlugMini, toggling between the on and off state. This method returns a <code>Promise</code> object. A <code>boolean</code> value indicating whether the PlugMini is on (<code>true</code>) or off (<code>false</code>), is passed to the <code>resolve()</code> method of the Promise.</p>
|
|
501
|
-
<p>If no connection is established with the device, this method automatically establishes a connection with the device, then finally closes the connection. You don't have to call the <a href="#md:SwitchbotDevice-connect-method"><code>connect()</code></a> method in advance.</p>
|
|
502
|
-
<hr>
|
|
503
|
-
<hr>
|
|
504
|
-
<a id="md:wosmartlock-object" class="tsd-anchor"></a><h2 class="tsd-anchor-link"><code>WoSmartLock</code> object<a href="#md:wosmartlock-object" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24"><use href="assets/icons.svg#icon-anchor"></use></svg></a></h2><p>The <code>WoSmartLock </code> object represents a SmartLock, which is created through the discovery process triggered by the <a href="#md:Switchbot-discover-method"><code>Switchbot.discover()</code></a> method.</p>
|
|
505
|
-
<p>Actually, the <code>WoSmartLock </code> is an object inherited from the <a href="#md:SwitchbotDevice-object"><code>SwitchbotDevice</code></a>. You can use not only the method described in this section but also the properties and methods implemented in the <a href="#md:SwitchbotDevice-object"><code>SwitchbotDevice</code></a> object.</p>
|
|
506
|
-
<a id="md:setkey-method" class="tsd-anchor"></a><h3 class="tsd-anchor-link"><code>setKey()</code> method<a href="#md:setkey-method" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24"><use href="assets/icons.svg#icon-anchor"></use></svg></a></h3><p>The <code>setKey()</code> method initialises the key information required for encrypted communication with the SmartLock</p>
|
|
507
|
-
<p>This must be set before any control commands are sent to the device. To obtain the key information you will need to use an external tool - see <a href="https://github.com/Danielhiversen/pySwitchbot/tree/master?tab=readme-ov-file#obtaining-locks-encryption-key"><code>pySwitchbot</code></a> project for an example script.</p>
|
|
508
|
-
<table>
|
|
509
|
-
<thead>
|
|
510
|
-
<tr>
|
|
511
|
-
<th style="text-align:left">Property</th>
|
|
512
|
-
<th style="text-align:left">Type</th>
|
|
513
|
-
<th style="text-align:left">Description</th>
|
|
514
|
-
</tr>
|
|
515
|
-
</thead>
|
|
516
|
-
<tbody>
|
|
517
|
-
<tr>
|
|
518
|
-
<td style="text-align:left"><code>keyId</code></td>
|
|
519
|
-
<td style="text-align:left">String</td>
|
|
520
|
-
<td style="text-align:left">unique2 character ID for the key. (e.g., <code>"ff"</code>) returned from the SwitchBot api for your device</td>
|
|
521
|
-
</tr>
|
|
522
|
-
<tr>
|
|
523
|
-
<td style="text-align:left"><code>encryptionKey</code></td>
|
|
524
|
-
<td style="text-align:left">String</td>
|
|
525
|
-
<td style="text-align:left">the unique encryption key returned from the SwitchBot api for your device</td>
|
|
526
|
-
</tr>
|
|
527
|
-
</tbody>
|
|
528
|
-
</table>
|
|
529
|
-
<a id="md:lock-method" class="tsd-anchor"></a><h3 class="tsd-anchor-link"><code>lock()</code> method<a href="#md:lock-method" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24"><use href="assets/icons.svg#icon-anchor"></use></svg></a></h3><p>The <code>lock()</code> method sends a lock command to the SmartLock. This method returns a <code>Promise</code> object. A <code>boolean</code> value indicating whether the SmartLock is locked (<code>true</code>), is passed to the <code>resolve()</code> method of the Promise.</p>
|
|
530
|
-
<p>If no connection is established with the device, this method automatically establishes a connection with the device, then finally closes the connection. You don't have to call the <a href="#md:SwitchbotDevice-connect-method"><code>connect()</code></a> method in advance.</p>
|
|
531
|
-
<a id="md:unlock-method" class="tsd-anchor"></a><h3 class="tsd-anchor-link"><code>unlock()</code> method<a href="#md:unlock-method" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24"><use href="assets/icons.svg#icon-anchor"></use></svg></a></h3><p>The <code>unlock()</code> method sends an unlock command to the SmartLock. This method returns a <code>Promise</code> object. A <code>boolean</code> value indicating whether the SmartLock is locked (<code>false</code>), is passed to the <code>resolve()</code> method of the Promise.</p>
|
|
532
|
-
<p>If no connection is established with the device, this method automatically establishes a connection with the device, then finally closes the connection. You don't have to call the <a href="#md:SwitchbotDevice-connect-method"><code>connect()</code></a> method in advance.</p>
|
|
533
|
-
<a id="md:unlocknounlatch-method" class="tsd-anchor"></a><h3 class="tsd-anchor-link"><code>unlockNoUnlatch()</code> method<a href="#md:unlocknounlatch-method" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24"><use href="assets/icons.svg#icon-anchor"></use></svg></a></h3><p>The <code>unlockNoUnlatch()</code> method sends a partial unlock command to the SmartLock, unlocking without the full unlatch.</p>
|
|
534
|
-
<p>If no connection is established with the device, this method automatically establishes a connection with the device, then finally closes the connection. You don't have to call the <a href="#md:SwitchbotDevice-connect-method"><code>connect()</code></a> method in advance.</p>
|
|
535
|
-
<a id="md:info-method" class="tsd-anchor"></a><h3 class="tsd-anchor-link"><code>info()</code> method<a href="#md:info-method" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24"><use href="assets/icons.svg#icon-anchor"></use></svg></a></h3><p>The <code>info()</code> method retreieves state information from the SmartLock, This method returns a <code>Promise</code> object. An <code>object</code> value indicating with the state infor, is passed to the <code>resolve()</code> method of the Promise.</p>
|
|
536
|
-
<p>If no connection is established with the device, this method automatically establishes a connection with the device, then finally closes the connection. You don't have to call the <a href="#md:SwitchbotDevice-connect-method"><code>connect()</code></a> method in advance.</p>
|
|
537
|
-
<a id="md:advertisement-data" class="tsd-anchor"></a><h2 class="tsd-anchor-link">Advertisement data<a href="#md:advertisement-data" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24"><use href="assets/icons.svg#icon-anchor"></use></svg></a></h2><p>After the <a href="#md:startscan-method"><code>startScan()</code></a> method is invoked, the <a href="#md:Switchbot-onadvertisement-event-handler"><code>onadvertisement</code></a> event handler will be called whenever an advertising packet comes from the switchbot devices. An object containing the properties as follows will be passed to the event handler:</p>
|
|
538
|
-
<table>
|
|
539
|
-
<thead>
|
|
540
|
-
<tr>
|
|
541
|
-
<th style="text-align:left">Property</th>
|
|
542
|
-
<th style="text-align:left">Type</th>
|
|
543
|
-
<th style="text-align:left">Description</th>
|
|
544
|
-
</tr>
|
|
545
|
-
</thead>
|
|
546
|
-
<tbody>
|
|
547
|
-
<tr>
|
|
548
|
-
<td style="text-align:left"><code>id</code></td>
|
|
549
|
-
<td style="text-align:left">String</td>
|
|
550
|
-
<td style="text-align:left">ID of the device. (e.g., <code>"cb4eb903c96d"</code>)</td>
|
|
551
|
-
</tr>
|
|
552
|
-
<tr>
|
|
553
|
-
<td style="text-align:left"><code>address</code></td>
|
|
554
|
-
<td style="text-align:left">String</td>
|
|
555
|
-
<td style="text-align:left">MAC address of the device. Basically it is as same as the value of the <code>id</code> except that this value includes <code>:</code> in the string. (e.g., <code>"cb:4e:b9:03:c9:6d"</code>)</td>
|
|
556
|
-
</tr>
|
|
557
|
-
<tr>
|
|
558
|
-
<td style="text-align:left"><code>rssi</code></td>
|
|
559
|
-
<td style="text-align:left">Integer</td>
|
|
560
|
-
<td style="text-align:left">RSSI. (e.g., <code>-62</code>)</td>
|
|
561
|
-
</tr>
|
|
562
|
-
<tr>
|
|
563
|
-
<td style="text-align:left"><code>serviceData</code></td>
|
|
564
|
-
<td style="text-align:left">Object</td>
|
|
565
|
-
<td style="text-align:left">An object including the device-specific data.</td>
|
|
566
|
-
</tr>
|
|
567
|
-
</tbody>
|
|
568
|
-
</table>
|
|
569
|
-
<p>The structures of the <code>serviceData</code> are described in the following sections.</p>
|
|
570
|
-
<a id="md:bot-wohand" class="tsd-anchor"></a><h3 class="tsd-anchor-link">Bot (WoHand)<a href="#md:bot-wohand" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24"><use href="assets/icons.svg#icon-anchor"></use></svg></a></h3><p>Example of the advertisement data:</p>
|
|
571
|
-
<pre><code class="json"><span class="hl-1">{</span><br/><span class="hl-1"> </span><span class="hl-9">"id"</span><span class="hl-1">: </span><span class="hl-4">"c12e453e2008"</span><span class="hl-1">,</span><br/><span class="hl-1"> </span><span class="hl-9">"address"</span><span class="hl-1">: </span><span class="hl-4">"c1:2e:45:3e:20:08"</span><span class="hl-1">,</span><br/><span class="hl-1"> </span><span class="hl-9">"rssi"</span><span class="hl-1">: </span><span class="hl-8">-61</span><span class="hl-1">,</span><br/><span class="hl-1"> </span><span class="hl-9">"serviceData"</span><span class="hl-1">: {</span><br/><span class="hl-1"> </span><span class="hl-9">"model"</span><span class="hl-1">: </span><span class="hl-4">"H"</span><span class="hl-1">,</span><br/><span class="hl-1"> </span><span class="hl-9">"modelName"</span><span class="hl-1">: </span><span class="hl-4">"WoHand"</span><span class="hl-1">,</span><br/><span class="hl-1"> </span><span class="hl-9">"mode"</span><span class="hl-1">: </span><span class="hl-5">true</span><span class="hl-1">,</span><br/><span class="hl-1"> </span><span class="hl-9">"state"</span><span class="hl-1">: </span><span class="hl-5">false</span><span class="hl-1">,</span><br/><span class="hl-1"> </span><span class="hl-9">"battery"</span><span class="hl-1">: </span><span class="hl-8">100</span><br/><span class="hl-1"> }</span><br/><span class="hl-1">}</span>
|
|
572
|
-
</code><button type="button">Copy</button></pre>
|
|
573
|
-
|
|
574
|
-
<p>Structure of the <code>serviceData</code>:</p>
|
|
575
|
-
<table>
|
|
576
|
-
<thead>
|
|
577
|
-
<tr>
|
|
578
|
-
<th style="text-align:left">Property</th>
|
|
579
|
-
<th style="text-align:left">Type</th>
|
|
580
|
-
<th style="text-align:left">Description</th>
|
|
581
|
-
</tr>
|
|
582
|
-
</thead>
|
|
583
|
-
<tbody>
|
|
584
|
-
<tr>
|
|
585
|
-
<td style="text-align:left"><code>model</code></td>
|
|
586
|
-
<td style="text-align:left">String</td>
|
|
587
|
-
<td style="text-align:left">This value is always <code>"H"</code>, which means "Bot (WoHand)".</td>
|
|
588
|
-
</tr>
|
|
589
|
-
<tr>
|
|
590
|
-
<td style="text-align:left"><code>modelName</code></td>
|
|
591
|
-
<td style="text-align:left">String</td>
|
|
592
|
-
<td style="text-align:left">This value is always <code>"WoHand"</code>, which means "Bot".</td>
|
|
593
|
-
</tr>
|
|
594
|
-
<tr>
|
|
595
|
-
<td style="text-align:left"><code>mode</code></td>
|
|
596
|
-
<td style="text-align:left">Boolean</td>
|
|
597
|
-
<td style="text-align:left">This indicates the mode setting. When the mode is "Switch mode", this value is <code>true</code>. When the mode is "Press mode", this value is <code>false</code>.</td>
|
|
598
|
-
</tr>
|
|
599
|
-
<tr>
|
|
600
|
-
<td style="text-align:left"><code>state</code></td>
|
|
601
|
-
<td style="text-align:left">Boolean</td>
|
|
602
|
-
<td style="text-align:left">This value indicates whether the switch status is ON or OFF.</td>
|
|
603
|
-
</tr>
|
|
604
|
-
<tr>
|
|
605
|
-
<td style="text-align:left"><code>battery</code></td>
|
|
606
|
-
<td style="text-align:left">Integer</td>
|
|
607
|
-
<td style="text-align:left">(<strong>experimental</strong>) This value indicates the battery level (<code>%</code>).</td>
|
|
608
|
-
</tr>
|
|
609
|
-
</tbody>
|
|
610
|
-
</table>
|
|
611
|
-
<p>The <code>mode</code> can be changed only using the official smartphone app. The node-switchbot does not support changing the mode because the BLE protocol is non-public.</p>
|
|
612
|
-
<p>If the <code>mode</code> is <code>false</code>, which means the "Press mode" is selected, the <code>state</code> is always <code>false</code>. If the <code>mode</code> is <code>true</code>, which means the "Switch mode" is selected, the <code>state</code> represents the logical state (ON or OFF). Note that it does <em>not</em> mean the physical arm position. The physical arm position depends on the setting "Inverse the on/off direction" on the official smartphone app.</p>
|
|
613
|
-
<table>
|
|
614
|
-
<thead>
|
|
615
|
-
<tr>
|
|
616
|
-
<th style="text-align:left">"Inverse the on/off direction"</th>
|
|
617
|
-
<th style="text-align:left">Value of the <code>state</code></th>
|
|
618
|
-
<th style="text-align:left">Logical state</th>
|
|
619
|
-
<th style="text-align:left">Physical arm position</th>
|
|
620
|
-
</tr>
|
|
621
|
-
</thead>
|
|
622
|
-
<tbody>
|
|
623
|
-
<tr>
|
|
624
|
-
<td style="text-align:left">disabled</td>
|
|
625
|
-
<td style="text-align:left"><code>true</code></td>
|
|
626
|
-
<td style="text-align:left">OFF</td>
|
|
627
|
-
<td style="text-align:left">Up (retracted)</td>
|
|
628
|
-
</tr>
|
|
629
|
-
<tr>
|
|
630
|
-
<td style="text-align:left"> </td>
|
|
631
|
-
<td style="text-align:left"><code>false</code></td>
|
|
632
|
-
<td style="text-align:left">ON</td>
|
|
633
|
-
<td style="text-align:left">Down (stretched)</td>
|
|
634
|
-
</tr>
|
|
635
|
-
<tr>
|
|
636
|
-
<td style="text-align:left">enabled</td>
|
|
637
|
-
<td style="text-align:left"><code>true</code></td>
|
|
638
|
-
<td style="text-align:left">OFF</td>
|
|
639
|
-
<td style="text-align:left">Down (stretched)</td>
|
|
640
|
-
</tr>
|
|
641
|
-
<tr>
|
|
642
|
-
<td style="text-align:left"> </td>
|
|
643
|
-
<td style="text-align:left"><code>false</code></td>
|
|
644
|
-
<td style="text-align:left">ON</td>
|
|
645
|
-
<td style="text-align:left">Up (retracted)</td>
|
|
646
|
-
</tr>
|
|
647
|
-
</tbody>
|
|
648
|
-
</table>
|
|
649
|
-
<p>The <code>battery</code> is <em>experimental</em> for now. I'm not sure whether the value is correct or not. Never trust this value for now.</p>
|
|
650
|
-
<a id="md:meter-wosensorth" class="tsd-anchor"></a><h3 class="tsd-anchor-link">Meter (WoSensorTH)<a href="#md:meter-wosensorth" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24"><use href="assets/icons.svg#icon-anchor"></use></svg></a></h3><p>Example of the advertisement data:</p>
|
|
651
|
-
<pre><code class="json"><span class="hl-1">{</span><br/><span class="hl-1"> </span><span class="hl-9">"id"</span><span class="hl-1">: </span><span class="hl-4">"cb4eb903c96d"</span><span class="hl-1">,</span><br/><span class="hl-1"> </span><span class="hl-9">"address"</span><span class="hl-1">: </span><span class="hl-4">"cb:4e:b9:03:c9:6d"</span><span class="hl-1">,</span><br/><span class="hl-1"> </span><span class="hl-9">"rssi"</span><span class="hl-1">: </span><span class="hl-8">-70</span><span class="hl-1">,</span><br/><span class="hl-1"> </span><span class="hl-9">"serviceData"</span><span class="hl-1">: {</span><br/><span class="hl-1"> </span><span class="hl-9">"model"</span><span class="hl-1">: </span><span class="hl-4">"T"</span><span class="hl-1">,</span><br/><span class="hl-1"> </span><span class="hl-9">"modelName"</span><span class="hl-1">: </span><span class="hl-4">"WoSensorTH"</span><span class="hl-1">,</span><br/><span class="hl-1"> </span><span class="hl-9">"temperature"</span><span class="hl-1">: {</span><br/><span class="hl-1"> </span><span class="hl-9">"c"</span><span class="hl-1">: </span><span class="hl-8">25.2</span><span class="hl-1">,</span><br/><span class="hl-1"> </span><span class="hl-9">"f"</span><span class="hl-1">: </span><span class="hl-8">77.4</span><br/><span class="hl-1"> },</span><br/><span class="hl-1"> </span><span class="hl-9">"fahrenheit"</span><span class="hl-1">: </span><span class="hl-5">false</span><span class="hl-1">,</span><br/><span class="hl-1"> </span><span class="hl-9">"humidity"</span><span class="hl-1">: </span><span class="hl-8">43</span><span class="hl-1">,</span><br/><span class="hl-1"> </span><span class="hl-9">"battery"</span><span class="hl-1">: </span><span class="hl-8">100</span><br/><span class="hl-1"> }</span><br/><span class="hl-1">}</span>
|
|
652
|
-
</code><button type="button">Copy</button></pre>
|
|
653
|
-
|
|
654
|
-
<p>Structure of the <code>data</code>:</p>
|
|
655
|
-
<table>
|
|
656
|
-
<thead>
|
|
657
|
-
<tr>
|
|
658
|
-
<th style="text-align:left">Property</th>
|
|
659
|
-
<th style="text-align:left">Type</th>
|
|
660
|
-
<th style="text-align:left">Description</th>
|
|
661
|
-
</tr>
|
|
662
|
-
</thead>
|
|
663
|
-
<tbody>
|
|
664
|
-
<tr>
|
|
665
|
-
<td style="text-align:left"><code>model</code></td>
|
|
666
|
-
<td style="text-align:left">String</td>
|
|
667
|
-
<td style="text-align:left">This value is always <code>"T"</code>, which means "Meter (WoSensorTH)".</td>
|
|
668
|
-
</tr>
|
|
669
|
-
<tr>
|
|
670
|
-
<td style="text-align:left"><code>modelName</code></td>
|
|
671
|
-
<td style="text-align:left">String</td>
|
|
672
|
-
<td style="text-align:left">This value is always <code>"WoSensorTH"</code>, which means "Meter".</td>
|
|
673
|
-
</tr>
|
|
674
|
-
<tr>
|
|
675
|
-
<td style="text-align:left"><code>temperature</code></td>
|
|
676
|
-
<td style="text-align:left">Object</td>
|
|
677
|
-
<td style="text-align:left"></td>
|
|
678
|
-
</tr>
|
|
679
|
-
<tr>
|
|
680
|
-
<td style="text-align:left"> <code>c</code></td>
|
|
681
|
-
<td style="text-align:left">Float</td>
|
|
682
|
-
<td style="text-align:left">Temperature (degree Celsius/°C)</td>
|
|
683
|
-
</tr>
|
|
684
|
-
<tr>
|
|
685
|
-
<td style="text-align:left"> <code>f</code></td>
|
|
686
|
-
<td style="text-align:left">Float</td>
|
|
687
|
-
<td style="text-align:left">Temperature (degree Fahrenheit/℉)</td>
|
|
688
|
-
</tr>
|
|
689
|
-
<tr>
|
|
690
|
-
<td style="text-align:left"><code>fahrenheit</code></td>
|
|
691
|
-
<td style="text-align:left">Boolean</td>
|
|
692
|
-
<td style="text-align:left">The flag whether the Meter shows Fahrenheit (<code>true</code>) or Celsius (<code>false</code>) for the temperature on the display</td>
|
|
693
|
-
</tr>
|
|
694
|
-
<tr>
|
|
695
|
-
<td style="text-align:left"><code>humidity</code></td>
|
|
696
|
-
<td style="text-align:left">Integer</td>
|
|
697
|
-
<td style="text-align:left">Humidity (<code>%</code>)</td>
|
|
698
|
-
</tr>
|
|
699
|
-
<tr>
|
|
700
|
-
<td style="text-align:left"><code>battery</code></td>
|
|
701
|
-
<td style="text-align:left">Integer</td>
|
|
702
|
-
<td style="text-align:left">(<strong>experimental</strong>) This value indicates the battery level (<code>%</code>).</td>
|
|
703
|
-
</tr>
|
|
704
|
-
</tbody>
|
|
705
|
-
</table>
|
|
706
|
-
<p>The <code>fahrenheit</code> indicates the setting on the device. Note that it does <em>not</em> indicate the setting on the official smartphone app. The setting of the temperature unit on the device and the setting on the app are independent.</p>
|
|
707
|
-
<p>The <code>battery</code> is <em>experimental</em> for now. I'm not sure whether the value is correct or not. Never trust this value for now.</p>
|
|
708
|
-
<a id="md:curtain-wocurtain" class="tsd-anchor"></a><h3 class="tsd-anchor-link">Curtain (WoCurtain)<a href="#md:curtain-wocurtain" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24"><use href="assets/icons.svg#icon-anchor"></use></svg></a></h3><p>Example of the advertisement data:</p>
|
|
709
|
-
<pre><code class="json"><span class="hl-1">{</span><br/><span class="hl-1"> </span><span class="hl-9">"id"</span><span class="hl-1">: </span><span class="hl-4">"ec58c5d00111"</span><span class="hl-1">,</span><br/><span class="hl-1"> </span><span class="hl-9">"address"</span><span class="hl-1">: </span><span class="hl-4">"ec:58:c5:d0:01:11"</span><span class="hl-1">,</span><br/><span class="hl-1"> </span><span class="hl-9">"rssi"</span><span class="hl-1">: </span><span class="hl-8">-39</span><span class="hl-1">,</span><br/><span class="hl-1"> </span><span class="hl-9">"serviceData"</span><span class="hl-1">: {</span><br/><span class="hl-1"> </span><span class="hl-9">"model"</span><span class="hl-1">: </span><span class="hl-4">"c"</span><span class="hl-1">,</span><br/><span class="hl-1"> </span><span class="hl-9">"modelName"</span><span class="hl-1">: </span><span class="hl-4">"WoCurtain"</span><span class="hl-1">,</span><br/><span class="hl-1"> </span><span class="hl-9">"calibration"</span><span class="hl-1">: </span><span class="hl-5">true</span><span class="hl-1">,</span><br/><span class="hl-1"> </span><span class="hl-9">"battery"</span><span class="hl-1">: </span><span class="hl-8">91</span><span class="hl-1">,</span><br/><span class="hl-1"> </span><span class="hl-9">"position"</span><span class="hl-1">: </span><span class="hl-8">1</span><span class="hl-1">,</span><br/><span class="hl-1"> </span><span class="hl-9">"lightLevel"</span><span class="hl-1">: </span><span class="hl-8">1</span><br/><span class="hl-1"> }</span><br/><span class="hl-1">}</span>
|
|
710
|
-
</code><button type="button">Copy</button></pre>
|
|
711
|
-
|
|
712
|
-
<p>Structure of the <code>serviceData</code>:</p>
|
|
713
|
-
<table>
|
|
714
|
-
<thead>
|
|
715
|
-
<tr>
|
|
716
|
-
<th style="text-align:left">Property</th>
|
|
717
|
-
<th style="text-align:left">Type</th>
|
|
718
|
-
<th style="text-align:left">Description</th>
|
|
719
|
-
</tr>
|
|
720
|
-
</thead>
|
|
721
|
-
<tbody>
|
|
722
|
-
<tr>
|
|
723
|
-
<td style="text-align:left"><code>model</code></td>
|
|
724
|
-
<td style="text-align:left">String</td>
|
|
725
|
-
<td style="text-align:left">This value is <code>"c"</code>, which means "Curtain (WoCurtain)".</td>
|
|
726
|
-
</tr>
|
|
727
|
-
<tr>
|
|
728
|
-
<td style="text-align:left"></td>
|
|
729
|
-
<td style="text-align:left"></td>
|
|
730
|
-
<td style="text-align:left">or <code>"{"</code>, which means "Curtain 3 (WoCurtain)".</td>
|
|
731
|
-
</tr>
|
|
732
|
-
<tr>
|
|
733
|
-
<td style="text-align:left"><code>modelName</code></td>
|
|
734
|
-
<td style="text-align:left">String</td>
|
|
735
|
-
<td style="text-align:left">This value is always <code>"WoCurtain"</code>, which means "Curtain".</td>
|
|
736
|
-
</tr>
|
|
737
|
-
<tr>
|
|
738
|
-
<td style="text-align:left"><code>calibration</code></td>
|
|
739
|
-
<td style="text-align:left">Boolean</td>
|
|
740
|
-
<td style="text-align:left">This value indicates the calibration status (<code>true</code> or <code>false</code>).</td>
|
|
741
|
-
</tr>
|
|
742
|
-
<tr>
|
|
743
|
-
<td style="text-align:left"><code>battery</code></td>
|
|
744
|
-
<td style="text-align:left">Integer</td>
|
|
745
|
-
<td style="text-align:left">This value indicates the battery level (<code>1-100</code>, <code>%</code>).</td>
|
|
746
|
-
</tr>
|
|
747
|
-
<tr>
|
|
748
|
-
<td style="text-align:left"><code>position</code></td>
|
|
749
|
-
<td style="text-align:left">Integer</td>
|
|
750
|
-
<td style="text-align:left">This value indicates the percentage of current position (<code>0-100</code>, 0 is open, <code>%</code>).</td>
|
|
751
|
-
</tr>
|
|
752
|
-
<tr>
|
|
753
|
-
<td style="text-align:left"><code>lightLevel</code></td>
|
|
754
|
-
<td style="text-align:left">Integer</td>
|
|
755
|
-
<td style="text-align:left">This value indicates the light level of the light source currently set (<code>1-10</code>).</td>
|
|
756
|
-
</tr>
|
|
757
|
-
</tbody>
|
|
758
|
-
</table>
|
|
759
|
-
<a id="md:contact-wocontact" class="tsd-anchor"></a><h3 class="tsd-anchor-link">Contact (WoContact)<a href="#md:contact-wocontact" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24"><use href="assets/icons.svg#icon-anchor"></use></svg></a></h3><p>Example of the advertisement data:</p>
|
|
760
|
-
<pre><code class="json"><span class="hl-1">{</span><br/><span class="hl-1"> </span><span class="hl-9">"id"</span><span class="hl-1">: </span><span class="hl-4">"f0cda125e3ec"</span><span class="hl-1">,</span><br/><span class="hl-1"> </span><span class="hl-9">"address"</span><span class="hl-1">: </span><span class="hl-4">"f0:cd:a1:25:e3:ec"</span><span class="hl-1">,</span><br/><span class="hl-1"> </span><span class="hl-9">"rssi"</span><span class="hl-1">: </span><span class="hl-8">-56</span><span class="hl-1">,</span><br/><span class="hl-1"> </span><span class="hl-9">"serviceData"</span><span class="hl-1">: {</span><br/><span class="hl-1"> </span><span class="hl-9">"model"</span><span class="hl-1">: </span><span class="hl-4">"d"</span><span class="hl-1">,</span><br/><span class="hl-1"> </span><span class="hl-9">"modelName"</span><span class="hl-1">: </span><span class="hl-4">"WoContact"</span><span class="hl-1">,</span><br/><span class="hl-1"> </span><span class="hl-9">"movement"</span><span class="hl-1">: </span><span class="hl-5">false</span><span class="hl-1">,</span><br/><span class="hl-1"> </span><span class="hl-9">"battery"</span><span class="hl-1">: </span><span class="hl-8">95</span><span class="hl-1">,</span><br/><span class="hl-1"> </span><span class="hl-9">"doorState"</span><span class="hl-1">: </span><span class="hl-4">"close"</span><span class="hl-1">,</span><br/><span class="hl-1"> </span><span class="hl-9">"lightLevel"</span><span class="hl-1">: </span><span class="hl-4">"bright"</span><br/><span class="hl-1"> }</span><br/><span class="hl-1">}</span>
|
|
761
|
-
</code><button type="button">Copy</button></pre>
|
|
762
|
-
|
|
763
|
-
<p>Structure of the <code>serviceData</code>:</p>
|
|
764
|
-
<table>
|
|
765
|
-
<thead>
|
|
766
|
-
<tr>
|
|
767
|
-
<th style="text-align:left">Property</th>
|
|
768
|
-
<th style="text-align:left">Type</th>
|
|
769
|
-
<th style="text-align:left">Description</th>
|
|
770
|
-
</tr>
|
|
771
|
-
</thead>
|
|
772
|
-
<tbody>
|
|
773
|
-
<tr>
|
|
774
|
-
<td style="text-align:left"><code>model</code></td>
|
|
775
|
-
<td style="text-align:left">String</td>
|
|
776
|
-
<td style="text-align:left">This value is always <code>"c"</code>, which means "Contact (WoContact)".</td>
|
|
777
|
-
</tr>
|
|
778
|
-
<tr>
|
|
779
|
-
<td style="text-align:left"><code>modelName</code></td>
|
|
780
|
-
<td style="text-align:left">String</td>
|
|
781
|
-
<td style="text-align:left">This value is always <code>"WoContact"</code>, which means "Contact".</td>
|
|
782
|
-
</tr>
|
|
783
|
-
<tr>
|
|
784
|
-
<td style="text-align:left"><code>movement</code></td>
|
|
785
|
-
<td style="text-align:left">Boolean</td>
|
|
786
|
-
<td style="text-align:left">This value indicates the motion status (<code>true</code> or <code>false</code>).</td>
|
|
787
|
-
</tr>
|
|
788
|
-
<tr>
|
|
789
|
-
<td style="text-align:left"><code>battery</code></td>
|
|
790
|
-
<td style="text-align:left">Integer</td>
|
|
791
|
-
<td style="text-align:left">This value indicates the battery level (<code>1-100</code>, <code>%</code>).</td>
|
|
792
|
-
</tr>
|
|
793
|
-
<tr>
|
|
794
|
-
<td style="text-align:left"><code>doorState</code></td>
|
|
795
|
-
<td style="text-align:left">String</td>
|
|
796
|
-
<td style="text-align:left">This value indicates the door Status (<code>close</code>, <code>open</code>, <code>timeout no closed</code>).</td>
|
|
797
|
-
</tr>
|
|
798
|
-
<tr>
|
|
799
|
-
<td style="text-align:left"><code>lightLevel</code></td>
|
|
800
|
-
<td style="text-align:left">String</td>
|
|
801
|
-
<td style="text-align:left">This value indicates the light level (<code>dark</code>, <code>bright</code>).</td>
|
|
802
|
-
</tr>
|
|
803
|
-
</tbody>
|
|
804
|
-
</table>
|
|
805
|
-
<a id="md:motion-womotion" class="tsd-anchor"></a><h3 class="tsd-anchor-link">Motion (WoMotion)<a href="#md:motion-womotion" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24"><use href="assets/icons.svg#icon-anchor"></use></svg></a></h3><p>Example of the advertisement data:</p>
|
|
806
|
-
<pre><code class="json"><span class="hl-1">{</span><br/><span class="hl-1"> </span><span class="hl-9">"id"</span><span class="hl-1">: </span><span class="hl-4">"e7216fa344a9"</span><span class="hl-1">,</span><br/><span class="hl-1"> </span><span class="hl-9">"address"</span><span class="hl-1">: </span><span class="hl-4">"e7:21:6f:a3:44:a9"</span><span class="hl-1">,</span><br/><span class="hl-1"> </span><span class="hl-9">"rssi"</span><span class="hl-1">: </span><span class="hl-8">-53</span><span class="hl-1">,</span><br/><span class="hl-1"> </span><span class="hl-9">"serviceData"</span><span class="hl-1">: {</span><br/><span class="hl-1"> </span><span class="hl-9">"model"</span><span class="hl-1">: </span><span class="hl-4">"s"</span><span class="hl-1">,</span><br/><span class="hl-1"> </span><span class="hl-9">"modelName"</span><span class="hl-1">: </span><span class="hl-4">"WoMotion"</span><span class="hl-1">,</span><br/><span class="hl-1"> </span><span class="hl-9">"movement"</span><span class="hl-1">: </span><span class="hl-5">false</span><span class="hl-1">,</span><br/><span class="hl-1"> </span><span class="hl-9">"battery"</span><span class="hl-1">: </span><span class="hl-8">96</span><span class="hl-1">,</span><br/><span class="hl-1"> </span><span class="hl-9">"lightLevel"</span><span class="hl-1">: </span><span class="hl-4">"bright"</span><br/><span class="hl-1"> }</span><br/><span class="hl-1">}</span>
|
|
807
|
-
</code><button type="button">Copy</button></pre>
|
|
808
|
-
|
|
809
|
-
<p>Structure of the <code>serviceData</code>:</p>
|
|
810
|
-
<table>
|
|
811
|
-
<thead>
|
|
812
|
-
<tr>
|
|
813
|
-
<th style="text-align:left">Property</th>
|
|
814
|
-
<th style="text-align:left">Type</th>
|
|
815
|
-
<th style="text-align:left">Description</th>
|
|
816
|
-
</tr>
|
|
817
|
-
</thead>
|
|
818
|
-
<tbody>
|
|
819
|
-
<tr>
|
|
820
|
-
<td style="text-align:left"><code>model</code></td>
|
|
821
|
-
<td style="text-align:left">String</td>
|
|
822
|
-
<td style="text-align:left">This value is always <code>"s"</code>, which means "Motion (WoMotion)".</td>
|
|
823
|
-
</tr>
|
|
824
|
-
<tr>
|
|
825
|
-
<td style="text-align:left"><code>modelName</code></td>
|
|
826
|
-
<td style="text-align:left">String</td>
|
|
827
|
-
<td style="text-align:left">This value is always <code>"WoMotion"</code>, which means "Motion".</td>
|
|
828
|
-
</tr>
|
|
829
|
-
<tr>
|
|
830
|
-
<td style="text-align:left"><code>movement</code></td>
|
|
831
|
-
<td style="text-align:left">Boolean</td>
|
|
832
|
-
<td style="text-align:left">This value indicates the motion status (<code>true</code> or <code>false</code>).</td>
|
|
833
|
-
</tr>
|
|
834
|
-
<tr>
|
|
835
|
-
<td style="text-align:left"><code>battery</code></td>
|
|
836
|
-
<td style="text-align:left">Integer</td>
|
|
837
|
-
<td style="text-align:left">This value indicates the battery level (<code>1-100</code>, <code>%</code>).</td>
|
|
838
|
-
</tr>
|
|
839
|
-
<tr>
|
|
840
|
-
<td style="text-align:left"><code>lightLevel</code></td>
|
|
841
|
-
<td style="text-align:left">String</td>
|
|
842
|
-
<td style="text-align:left">This value indicates the light level (<code>dark</code>, <code>bright</code>).</td>
|
|
843
|
-
</tr>
|
|
844
|
-
</tbody>
|
|
845
|
-
</table>
|
|
846
|
-
<a id="md:plugmini-woplugmini" class="tsd-anchor"></a><h3 class="tsd-anchor-link">PlugMini (WoPlugMini)<a href="#md:plugmini-woplugmini" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24"><use href="assets/icons.svg#icon-anchor"></use></svg></a></h3><p>Example of the advertisement data:</p>
|
|
847
|
-
<pre><code class="json"><span class="hl-1">{</span><br/><span class="hl-1"> </span><span class="hl-9">"id"</span><span class="hl-1">: </span><span class="hl-4">"cd2409ea3e9441f87d4580e0380a62bf"</span><span class="hl-1">,</span><br/><span class="hl-1"> </span><span class="hl-9">"address"</span><span class="hl-1">: </span><span class="hl-4">"60:55:f9:35:f6:a6"</span><span class="hl-1">,</span><br/><span class="hl-1"> </span><span class="hl-9">"rssi"</span><span class="hl-1">: </span><span class="hl-8">-50</span><span class="hl-1">,</span><br/><span class="hl-1"> </span><span class="hl-9">"serviceData"</span><span class="hl-1">: {</span><br/><span class="hl-1"> </span><span class="hl-9">"model"</span><span class="hl-1">: </span><span class="hl-4">"j"</span><span class="hl-1">,</span><br/><span class="hl-1"> </span><span class="hl-9">"modelName"</span><span class="hl-1">: </span><span class="hl-4">"WoPlugMini"</span><span class="hl-1">,</span><br/><span class="hl-1"> </span><span class="hl-9">"state"</span><span class="hl-1">: </span><span class="hl-4">"off"</span><span class="hl-1">,</span><br/><span class="hl-1"> </span><span class="hl-9">"delay"</span><span class="hl-1">: </span><span class="hl-5">false</span><span class="hl-1">,</span><br/><span class="hl-1"> </span><span class="hl-9">"timer"</span><span class="hl-1">: </span><span class="hl-5">false</span><span class="hl-1">,</span><br/><span class="hl-1"> </span><span class="hl-9">"syncUtcTime"</span><span class="hl-1">: </span><span class="hl-5">true</span><span class="hl-1">,</span><br/><span class="hl-1"> </span><span class="hl-9">"wifiRssi"</span><span class="hl-1">: </span><span class="hl-8">48</span><span class="hl-1">,</span><br/><span class="hl-1"> </span><span class="hl-9">"overload"</span><span class="hl-1">: </span><span class="hl-5">false</span><span class="hl-1">,</span><br/><span class="hl-1"> </span><span class="hl-9">"currentPower"</span><span class="hl-1">: </span><span class="hl-8">0</span><br/><span class="hl-1"> }</span><br/><span class="hl-1">}</span>
|
|
848
|
-
</code><button type="button">Copy</button></pre>
|
|
849
|
-
|
|
850
|
-
<p>Structure of the <code>serviceData</code>:</p>
|
|
851
|
-
<table>
|
|
852
|
-
<thead>
|
|
853
|
-
<tr>
|
|
854
|
-
<th style="text-align:left">Property</th>
|
|
855
|
-
<th style="text-align:left">Type</th>
|
|
856
|
-
<th style="text-align:left">Description</th>
|
|
857
|
-
</tr>
|
|
858
|
-
</thead>
|
|
859
|
-
<tbody>
|
|
860
|
-
<tr>
|
|
861
|
-
<td style="text-align:left"><code>model</code></td>
|
|
862
|
-
<td style="text-align:left">String</td>
|
|
863
|
-
<td style="text-align:left">This value is always <code>"j"</code> or <code>"g"</code>, which means "PlugMini" (JP or US).</td>
|
|
864
|
-
</tr>
|
|
865
|
-
<tr>
|
|
866
|
-
<td style="text-align:left"><code>modelName</code></td>
|
|
867
|
-
<td style="text-align:left">String</td>
|
|
868
|
-
<td style="text-align:left">This value is always <code>"WoPlugMini"</code>, which means "PlugMini".</td>
|
|
869
|
-
</tr>
|
|
870
|
-
<tr>
|
|
871
|
-
<td style="text-align:left"><code>state </code></td>
|
|
872
|
-
<td style="text-align:left">Boolean</td>
|
|
873
|
-
<td style="text-align:left">This value indicates whether the plug mini is turned on (<code>true</code>) or not (<code>false</code>).</td>
|
|
874
|
-
</tr>
|
|
875
|
-
<tr>
|
|
876
|
-
<td style="text-align:left"><code>delay</code></td>
|
|
877
|
-
<td style="text-align:left">Boolean</td>
|
|
878
|
-
<td style="text-align:left">Indicates whether a delay is present.</td>
|
|
879
|
-
</tr>
|
|
880
|
-
<tr>
|
|
881
|
-
<td style="text-align:left"><code>timer</code></td>
|
|
882
|
-
<td style="text-align:left">Boolean</td>
|
|
883
|
-
<td style="text-align:left">Indicates whether a timer is present.</td>
|
|
884
|
-
</tr>
|
|
885
|
-
<tr>
|
|
886
|
-
<td style="text-align:left"><code>syncUtcTime</code></td>
|
|
887
|
-
<td style="text-align:left">boolean</td>
|
|
888
|
-
<td style="text-align:left">Indicates whether the UTC time has been synchronized.</td>
|
|
889
|
-
</tr>
|
|
890
|
-
<tr>
|
|
891
|
-
<td style="text-align:left"><code>overload</code></td>
|
|
892
|
-
<td style="text-align:left">boolean</td>
|
|
893
|
-
<td style="text-align:left">Indicates whether the Plug Mini is overloaded, more than 15A current overload.</td>
|
|
894
|
-
</tr>
|
|
895
|
-
<tr>
|
|
896
|
-
<td style="text-align:left"><code>currentPower</code></td>
|
|
897
|
-
<td style="text-align:left">Float</td>
|
|
898
|
-
<td style="text-align:left">Current power consumption in Watts.</td>
|
|
899
|
-
</tr>
|
|
900
|
-
</tbody>
|
|
901
|
-
</table>
|
|
902
|
-
<hr>
|
|
903
|
-
<a id="md:smartlock-wosmartlock" class="tsd-anchor"></a><h3 class="tsd-anchor-link">SmartLock (WoSmartLock)<a href="#md:smartlock-wosmartlock" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24"><use href="assets/icons.svg#icon-anchor"></use></svg></a></h3><p>Example of the advertisement data:</p>
|
|
904
|
-
<pre><code class="json"><span class="hl-1">{</span><br/><span class="hl-1"> </span><span class="hl-9">"id: 'd30864110b8c',</span><br/><span class="hl-9"> "</span><span class="hl-11">address</span><span class="hl-9">": 'd3:08:64:11:0b:8c',</span><br/><span class="hl-9"> "</span><span class="hl-11">rssi</span><span class="hl-9">": -52,</span><br/><span class="hl-9"> "</span><span class="hl-11">serviceData</span><span class="hl-9">": {</span><br/><span class="hl-9"> "</span><span class="hl-11">model</span><span class="hl-9">": "</span><span class="hl-11">o</span><span class="hl-9">",</span><br/><span class="hl-9"> "</span><span class="hl-11">modelName</span><span class="hl-9">": "</span><span class="hl-11">WoSmartLock</span><span class="hl-9">",</span><br/><span class="hl-9"> "</span><span class="hl-11">battery</span><span class="hl-9">": 100,</span><br/><span class="hl-9"> "</span><span class="hl-11">calibration</span><span class="hl-9">": true,</span><br/><span class="hl-9"> "</span><span class="hl-11">status</span><span class="hl-9">": "</span><span class="hl-11">LOCKED</span><span class="hl-9">",</span><br/><span class="hl-9"> "</span><span class="hl-11">update_from_secondary_lock</span><span class="hl-9">": false,</span><br/><span class="hl-9"> "</span><span class="hl-11">door_open</span><span class="hl-9">": false,</span><br/><span class="hl-9"> "</span><span class="hl-11">double_lock_mode</span><span class="hl-9">": false,</span><br/><span class="hl-9"> "</span><span class="hl-11">unclosed_alarm</span><span class="hl-9">": false,</span><br/><span class="hl-9"> "</span><span class="hl-11">unlocked_alarm</span><span class="hl-9">": false,</span><br/><span class="hl-9"> "</span><span class="hl-11">auto_lock_paused</span><span class="hl-9">": false</span><br/><span class="hl-9"> }</span><br/><span class="hl-9">}</span><br/>
|
|
10
|
+
<a id="md:installation" class="tsd-anchor"></a><h2 class="tsd-anchor-link"><a href="https://npmjs.org/node-switchbot" target="_blank" class="external">Installation</a><a href="#md:installation" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24"><use href="assets/icons.svg#icon-anchor"></use></svg></a></h2><p>To install the <code>node-switchbot</code> module within your project, use the following command:</p>
|
|
11
|
+
<pre><code class="sh"><span class="hl-0">$</span><span class="hl-1"> </span><span class="hl-2">npm</span><span class="hl-1"> </span><span class="hl-2">install</span><span class="hl-1"> </span><span class="hl-3">--save</span><span class="hl-1"> </span><span class="hl-2">node-switchbot</span>
|
|
905
12
|
</code><button type="button">Copy</button></pre>
|
|
906
13
|
|
|
907
|
-
<p>
|
|
908
|
-
<
|
|
909
|
-
<thead>
|
|
910
|
-
<tr>
|
|
911
|
-
<th style="text-align:left">Property</th>
|
|
912
|
-
<th style="text-align:left">Type</th>
|
|
913
|
-
<th style="text-align:left">Description</th>
|
|
914
|
-
</tr>
|
|
915
|
-
</thead>
|
|
916
|
-
<tbody>
|
|
917
|
-
<tr>
|
|
918
|
-
<td style="text-align:left"><code>model</code></td>
|
|
919
|
-
<td style="text-align:left">String</td>
|
|
920
|
-
<td style="text-align:left">This value is <code>"o"</code>, which means "Lock (WoSmartLock)".</td>
|
|
921
|
-
</tr>
|
|
922
|
-
<tr>
|
|
923
|
-
<td style="text-align:left"><code>modelName</code></td>
|
|
924
|
-
<td style="text-align:left">String</td>
|
|
925
|
-
<td style="text-align:left">This value is always <code>"WoSmartLock"</code>, which means "Lock".</td>
|
|
926
|
-
</tr>
|
|
927
|
-
<tr>
|
|
928
|
-
<td style="text-align:left"><code>battery</code></td>
|
|
929
|
-
<td style="text-align:left">Integer</td>
|
|
930
|
-
<td style="text-align:left">This value indicates the battery level (<code>1-100</code>, <code>%</code>).</td>
|
|
931
|
-
</tr>
|
|
932
|
-
<tr>
|
|
933
|
-
<td style="text-align:left"><code>calibration</code></td>
|
|
934
|
-
<td style="text-align:left">Boolean</td>
|
|
935
|
-
<td style="text-align:left">This value indicates the calibration status (<code>true</code> or <code>false</code>).</td>
|
|
936
|
-
</tr>
|
|
937
|
-
<tr>
|
|
938
|
-
<td style="text-align:left"><code>status</code></td>
|
|
939
|
-
<td style="text-align:left">String</td>
|
|
940
|
-
<td style="text-align:left">This value indicates the current locked state. Possible values:</td>
|
|
941
|
-
</tr>
|
|
942
|
-
<tr>
|
|
943
|
-
<td style="text-align:left"></td>
|
|
944
|
-
<td style="text-align:left"></td>
|
|
945
|
-
<td style="text-align:left"><code>"LOCKED"</code>, <code>"UNLOCKED"</code>, <code>"LOCKING"</code>, <code>"UNLOCKING"</code></td>
|
|
946
|
-
</tr>
|
|
947
|
-
<tr>
|
|
948
|
-
<td style="text-align:left"></td>
|
|
949
|
-
<td style="text-align:left"></td>
|
|
950
|
-
<td style="text-align:left"><code>"LOCKING_STOP"</code>, <code>"UNLOCKING_STOP"</code> (stuck when locking or unlocking respectively)</td>
|
|
951
|
-
</tr>
|
|
952
|
-
<tr>
|
|
953
|
-
<td style="text-align:left"></td>
|
|
954
|
-
<td style="text-align:left"></td>
|
|
955
|
-
<td style="text-align:left"><code>"NOT_FULLY_LOCKED"</code> (eu model only), <code>"UNKNOWN"</code> (fallback: must be some error)</td>
|
|
956
|
-
</tr>
|
|
957
|
-
<tr>
|
|
958
|
-
<td style="text-align:left"><code>update_from_secondary_lock</code></td>
|
|
959
|
-
<td style="text-align:left">Boolean</td>
|
|
960
|
-
<td style="text-align:left">??</td>
|
|
961
|
-
</tr>
|
|
962
|
-
<tr>
|
|
963
|
-
<td style="text-align:left"><code>door_open</code></td>
|
|
964
|
-
<td style="text-align:left">Boolean</td>
|
|
965
|
-
<td style="text-align:left">door open status - whether the door is not detecting the sensor magnet</td>
|
|
966
|
-
</tr>
|
|
967
|
-
<tr>
|
|
968
|
-
<td style="text-align:left"><code>double_lock_mode</code></td>
|
|
969
|
-
<td style="text-align:left">Boolean</td>
|
|
970
|
-
<td style="text-align:left">dual lock mode enabled status - two locks working simultaneously</td>
|
|
971
|
-
</tr>
|
|
972
|
-
<tr>
|
|
973
|
-
<td style="text-align:left"><code>unclosed_alarm</code></td>
|
|
974
|
-
<td style="text-align:left">Boolean</td>
|
|
975
|
-
<td style="text-align:left">enabled status for door ajar alarm function</td>
|
|
976
|
-
</tr>
|
|
977
|
-
<tr>
|
|
978
|
-
<td style="text-align:left"><code>unlocked_alarm</code></td>
|
|
979
|
-
<td style="text-align:left">Boolean</td>
|
|
980
|
-
<td style="text-align:left">whether the alarm function is enabled for door left unlocked</td>
|
|
981
|
-
</tr>
|
|
982
|
-
<tr>
|
|
983
|
-
<td style="text-align:left"><code>auto_lock_paused</code></td>
|
|
984
|
-
<td style="text-align:left">Boolean</td>
|
|
985
|
-
<td style="text-align:left">auto lock mode paused</td>
|
|
986
|
-
</tr>
|
|
987
|
-
<tr>
|
|
988
|
-
<td style="text-align:left"><code>night_latch</code></td>
|
|
989
|
-
<td style="text-align:left">Boolean</td>
|
|
990
|
-
<td style="text-align:left">night latch mode enabled (eu firmware only)</td>
|
|
991
|
-
</tr>
|
|
992
|
-
</tbody>
|
|
993
|
-
</table>
|
|
14
|
+
<a id="md:ble-bluetooth-low-energy" class="tsd-anchor"></a><h2 class="tsd-anchor-link"><a href="media/BLE.md">BLE (Bluetooth Low Energy)</a><a href="#md:ble-bluetooth-low-energy" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24"><use href="assets/icons.svg#icon-anchor"></use></svg></a></h2><p>To see a breakdown of how to use the BLE functionality of this project, visit the <a href="media/BLE.md">BLE (Bluetooth Low Energy)</a> documentation.</p>
|
|
15
|
+
<a id="md:openapi" class="tsd-anchor"></a><h2 class="tsd-anchor-link"><a href="media/OpenAPI.md">OpenAPI</a><a href="#md:openapi" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24"><use href="assets/icons.svg#icon-anchor"></use></svg></a></h2><p>To see a breakdown of how to use the OpenAPI functionality of this project, visit the <a href="media/OpenAPI.md">OpenAPI</a> documentation.</p>
|
|
994
16
|
<a id="md:references" class="tsd-anchor"></a><h2 class="tsd-anchor-link">References<a href="#md:references" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24"><use href="assets/icons.svg#icon-anchor"></use></svg></a></h2><ul>
|
|
995
|
-
<li><a href="https://www.switch-bot.com/">
|
|
996
|
-
<li><a href="https://
|
|
17
|
+
<li><a href="https://www.switch-bot.com/" target="_blank" class="external">SwitchBot (Official website)</a></li>
|
|
18
|
+
<li><a href="https://www.facebook.com/SwitchBotRobot/" target="_blank" class="external">Facebook @SwitchBotRobot</a></li>
|
|
19
|
+
<li><a href="https://twitter.com/switchbot" target="_blank" class="external">Twitter @SwitchBot</a></li>
|
|
997
20
|
</ul>
|
|
998
|
-
</div></div><div class="col-sidebar"><div class="page-menu"><div class="tsd-navigation settings"><details class="tsd-accordion"><summary class="tsd-accordion-summary"><h3><svg width="20" height="20" viewBox="0 0 24 24" fill="none"><use href="assets/icons.svg#icon-chevronDown"></use></svg>Settings</h3></summary><div class="tsd-accordion-details"><div class="tsd-filter-visibility"><span class="settings-label">Member Visibility</span><ul id="tsd-filter-options"><li class="tsd-filter-item"><label class="tsd-filter-input"><input type="checkbox" id="tsd-filter-inherited" name="inherited" checked/><svg width="32" height="32" viewBox="0 0 32 32" aria-hidden="true"><rect class="tsd-checkbox-background" width="30" height="30" x="1" y="1" rx="6" fill="none"></rect><path class="tsd-checkbox-checkmark" d="M8.35422 16.8214L13.2143 21.75L24.6458 10.25" stroke="none" stroke-width="3.5" stroke-linejoin="round" fill="none"></path></svg><span>Inherited</span></label></li></ul></div><div class="tsd-theme-toggle"><label class="settings-label" for="tsd-theme">Theme</label><select id="tsd-theme"><option value="os">OS</option><option value="light">Light</option><option value="dark">Dark</option></select></div></div></details></div><details open class="tsd-accordion tsd-page-navigation"><summary class="tsd-accordion-summary"><h3><svg width="20" height="20" viewBox="0 0 24 24" fill="none"><use href="assets/icons.svg#icon-chevronDown"></use></svg>On This Page</h3></summary><div class="tsd-accordion-details"><a href="#md:node-switchbot"><span>Node-<wbr/>Switch<wbr/>Bot</span></a><ul><li><a href="#md:
|
|
21
|
+
</div></div><div class="col-sidebar"><div class="page-menu"><div class="tsd-navigation settings"><details class="tsd-accordion"><summary class="tsd-accordion-summary"><h3><svg width="20" height="20" viewBox="0 0 24 24" fill="none"><use href="assets/icons.svg#icon-chevronDown"></use></svg>Settings</h3></summary><div class="tsd-accordion-details"><div class="tsd-filter-visibility"><span class="settings-label">Member Visibility</span><ul id="tsd-filter-options"><li class="tsd-filter-item"><label class="tsd-filter-input"><input type="checkbox" id="tsd-filter-inherited" name="inherited" checked/><svg width="32" height="32" viewBox="0 0 32 32" aria-hidden="true"><rect class="tsd-checkbox-background" width="30" height="30" x="1" y="1" rx="6" fill="none"></rect><path class="tsd-checkbox-checkmark" d="M8.35422 16.8214L13.2143 21.75L24.6458 10.25" stroke="none" stroke-width="3.5" stroke-linejoin="round" fill="none"></path></svg><span>Inherited</span></label></li></ul></div><div class="tsd-theme-toggle"><label class="settings-label" for="tsd-theme">Theme</label><select id="tsd-theme"><option value="os">OS</option><option value="light">Light</option><option value="dark">Dark</option></select></div></div></details></div><details open class="tsd-accordion tsd-page-navigation"><summary class="tsd-accordion-summary"><h3><svg width="20" height="20" viewBox="0 0 24 24" fill="none"><use href="assets/icons.svg#icon-chevronDown"></use></svg>On This Page</h3></summary><div class="tsd-accordion-details"><a href="#md:node-switchbot"><span>Node-<wbr/>Switch<wbr/>Bot</span></a><ul><li><a href="#md:installation"><span>Installation</span></a></li><li><a href="#md:ble-bluetooth-low-energy"><span>BLE (<wbr/>Bluetooth <wbr/>Low <wbr/>Energy)</span></a></li><li><a href="#md:openapi"><span>OpenAPI</span></a></li><li><a href="#md:references"><span>References</span></a></li></ul></div></details></div><div class="site-menu"><nav class="tsd-navigation"><a href="modules.html" class="current"><svg class="tsd-kind-icon" viewBox="0 0 24 24"><use href="assets/icons.svg#icon-1"></use></svg><span>node-switchbot</span></a><ul class="tsd-small-nested-navigation" id="tsd-nav-container" data-base="."><li>Loading...</li></ul></nav></div></div></div><footer></footer><div class="overlay"></div></body></html>
|