node-switchbot 2.5.0-beta.9 → 3.0.1

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.
Files changed (341) hide show
  1. package/.github/workflows/beta-release.yml +25 -2
  2. package/.github/workflows/release.yml +13 -0
  3. package/BLE.md +1144 -0
  4. package/CHANGELOG.md +22 -0
  5. package/OpenAPI.md +185 -0
  6. package/README.md +20 -1189
  7. package/branding/Node_x_SwitchBot.svg +9 -0
  8. package/branding/icon.png +0 -0
  9. package/branding/switchbot.png +0 -0
  10. package/dist/advertising.d.ts +3 -3
  11. package/dist/advertising.d.ts.map +1 -1
  12. package/dist/advertising.js +26 -26
  13. package/dist/advertising.js.map +1 -1
  14. package/dist/device/woblindtilt.d.ts +19 -50
  15. package/dist/device/woblindtilt.d.ts.map +1 -1
  16. package/dist/device/woblindtilt.js +41 -100
  17. package/dist/device/woblindtilt.js.map +1 -1
  18. package/dist/device/wobulb.d.ts +41 -15
  19. package/dist/device/wobulb.d.ts.map +1 -1
  20. package/dist/device/wobulb.js +72 -128
  21. package/dist/device/wobulb.js.map +1 -1
  22. package/dist/device/woceilinglight.d.ts +47 -21
  23. package/dist/device/woceilinglight.d.ts.map +1 -1
  24. package/dist/device/woceilinglight.js +96 -171
  25. package/dist/device/woceilinglight.js.map +1 -1
  26. package/dist/device/wocontact.d.ts +11 -1
  27. package/dist/device/wocontact.d.ts.map +1 -1
  28. package/dist/device/wocontact.js +23 -22
  29. package/dist/device/wocontact.js.map +1 -1
  30. package/dist/device/wocurtain.d.ts +39 -1
  31. package/dist/device/wocurtain.d.ts.map +1 -1
  32. package/dist/device/wocurtain.js +69 -103
  33. package/dist/device/wocurtain.js.map +1 -1
  34. package/dist/device/wohand.d.ts +37 -2
  35. package/dist/device/wohand.d.ts.map +1 -1
  36. package/dist/device/wohand.js +55 -89
  37. package/dist/device/wohand.js.map +1 -1
  38. package/dist/device/wohub2.d.ts +11 -1
  39. package/dist/device/wohub2.d.ts.map +1 -1
  40. package/dist/device/wohub2.js +21 -29
  41. package/dist/device/wohub2.js.map +1 -1
  42. package/dist/device/wohumi.d.ts +37 -2
  43. package/dist/device/wohumi.d.ts.map +1 -1
  44. package/dist/device/wohumi.js +52 -83
  45. package/dist/device/wohumi.js.map +1 -1
  46. package/dist/device/woiosensorth.d.ts +12 -1
  47. package/dist/device/woiosensorth.d.ts.map +1 -1
  48. package/dist/device/woiosensorth.js +25 -29
  49. package/dist/device/woiosensorth.js.map +1 -1
  50. package/dist/device/woplugmini.d.ts +45 -12
  51. package/dist/device/woplugmini.d.ts.map +1 -1
  52. package/dist/device/woplugmini.js +71 -77
  53. package/dist/device/woplugmini.js.map +1 -1
  54. package/dist/device/wopresence.d.ts +11 -1
  55. package/dist/device/wopresence.d.ts.map +1 -1
  56. package/dist/device/wopresence.js +21 -27
  57. package/dist/device/wopresence.js.map +1 -1
  58. package/dist/device/wosensorth.d.ts +18 -2
  59. package/dist/device/wosensorth.d.ts.map +1 -1
  60. package/dist/device/wosensorth.js +34 -50
  61. package/dist/device/wosensorth.js.map +1 -1
  62. package/dist/device/wosmartlock.d.ts +63 -13
  63. package/dist/device/wosmartlock.d.ts.map +1 -1
  64. package/dist/device/wosmartlock.js +114 -195
  65. package/dist/device/wosmartlock.js.map +1 -1
  66. package/dist/device/wosmartlockpro.d.ts +16 -12
  67. package/dist/device/wosmartlockpro.d.ts.map +1 -1
  68. package/dist/device/wosmartlockpro.js +34 -29
  69. package/dist/device/wosmartlockpro.js.map +1 -1
  70. package/dist/device/wostrip.d.ts +4 -3
  71. package/dist/device/wostrip.d.ts.map +1 -1
  72. package/dist/device/wostrip.js +5 -4
  73. package/dist/device/wostrip.js.map +1 -1
  74. package/dist/device.d.ts +13 -5
  75. package/dist/device.d.ts.map +1 -1
  76. package/dist/device.js +13 -2
  77. package/dist/device.js.map +1 -1
  78. package/dist/index.d.ts +9 -1
  79. package/dist/index.d.ts.map +1 -1
  80. package/dist/index.js +9 -1
  81. package/dist/index.js.map +1 -1
  82. package/dist/parameter-checker.d.ts +10 -13
  83. package/dist/parameter-checker.d.ts.map +1 -1
  84. package/dist/parameter-checker.js +16 -1
  85. package/dist/parameter-checker.js.map +1 -1
  86. package/dist/settings.d.ts +47 -0
  87. package/dist/settings.d.ts.map +1 -1
  88. package/dist/settings.js +49 -0
  89. package/dist/settings.js.map +1 -1
  90. package/dist/{switchbot.d.ts → switchbot-ble.d.ts} +12 -9
  91. package/dist/switchbot-ble.d.ts.map +1 -0
  92. package/dist/switchbot-ble.js +426 -0
  93. package/dist/switchbot-ble.js.map +1 -0
  94. package/dist/switchbot-openapi.d.ts +131 -0
  95. package/dist/switchbot-openapi.d.ts.map +1 -0
  96. package/dist/switchbot-openapi.js +311 -0
  97. package/dist/switchbot-openapi.js.map +1 -0
  98. package/dist/test/advertising.test.d.ts +2 -0
  99. package/dist/test/advertising.test.d.ts.map +1 -0
  100. package/dist/test/advertising.test.js +99 -0
  101. package/dist/test/advertising.test.js.map +1 -0
  102. package/dist/test/device.test.d.ts +2 -0
  103. package/dist/test/device.test.d.ts.map +1 -0
  104. package/dist/test/device.test.js +38 -0
  105. package/dist/test/device.test.js.map +1 -0
  106. package/dist/test/index.test.d.ts +2 -0
  107. package/dist/test/index.test.d.ts.map +1 -0
  108. package/dist/test/index.test.js +35 -0
  109. package/dist/test/index.test.js.map +1 -0
  110. package/dist/test/parameter-checker.test.d.ts +2 -0
  111. package/dist/test/parameter-checker.test.d.ts.map +1 -0
  112. package/dist/test/parameter-checker.test.js +108 -0
  113. package/dist/test/parameter-checker.test.js.map +1 -0
  114. package/dist/test/settings.test.d.ts +2 -0
  115. package/dist/test/settings.test.d.ts.map +1 -0
  116. package/dist/test/settings.test.js +49 -0
  117. package/dist/test/settings.test.js.map +1 -0
  118. package/dist/test/switchbot-openapi.test.d.ts +2 -0
  119. package/dist/test/switchbot-openapi.test.d.ts.map +1 -0
  120. package/dist/test/switchbot-openapi.test.js +96 -0
  121. package/dist/test/switchbot-openapi.test.js.map +1 -0
  122. package/dist/test/switchbot.test.d.ts +2 -0
  123. package/dist/test/switchbot.test.d.ts.map +1 -0
  124. package/dist/test/switchbot.test.js +106 -0
  125. package/dist/test/switchbot.test.js.map +1 -0
  126. package/dist/test/woblindtilt.test.js +70 -20
  127. package/dist/test/woblindtilt.test.js.map +1 -1
  128. package/dist/test/wobulb.test.js +87 -44
  129. package/dist/test/wobulb.test.js.map +1 -1
  130. package/dist/test/woceilinglight.test.js +72 -54
  131. package/dist/test/woceilinglight.test.js.map +1 -1
  132. package/dist/test/wocontact.test.js +51 -20
  133. package/dist/test/wocontact.test.js.map +1 -1
  134. package/dist/test/wocurtain.test.js +65 -23
  135. package/dist/test/wocurtain.test.js.map +1 -1
  136. package/dist/test/wohand.test.js +34 -40
  137. package/dist/test/wohand.test.js.map +1 -1
  138. package/dist/test/wohub2.test.d.ts +2 -0
  139. package/dist/test/wohub2.test.d.ts.map +1 -0
  140. package/dist/test/wohub2.test.js +80 -0
  141. package/dist/test/wohub2.test.js.map +1 -0
  142. package/dist/test/wohumi.test.js +70 -49
  143. package/dist/test/wohumi.test.js.map +1 -1
  144. package/dist/test/woiosensorth.test.js +33 -32
  145. package/dist/test/woiosensorth.test.js.map +1 -1
  146. package/dist/test/woplugmini.test.js +80 -57
  147. package/dist/test/woplugmini.test.js.map +1 -1
  148. package/dist/test/wopresence.test.js +44 -18
  149. package/dist/test/wopresence.test.js.map +1 -1
  150. package/dist/test/wosensorth.test.js +44 -52
  151. package/dist/test/wosensorth.test.js.map +1 -1
  152. package/dist/test/wosmartlock.test.js +126 -59
  153. package/dist/test/wosmartlock.test.js.map +1 -1
  154. package/dist/test/wosmartlockpro.test.js +96 -69
  155. package/dist/test/wosmartlockpro.test.js.map +1 -1
  156. package/dist/test/wostrip.test.js +70 -83
  157. package/dist/test/wostrip.test.js.map +1 -1
  158. package/dist/types/bledevicestatus.d.ts +4 -12
  159. package/dist/types/bledevicestatus.d.ts.map +1 -1
  160. package/dist/types/devicelist.d.ts.map +1 -1
  161. package/dist/types/devicelist.js +0 -4
  162. package/dist/types/devicelist.js.map +1 -1
  163. package/dist/types/devicepush.d.ts +13 -0
  164. package/dist/types/devicepush.d.ts.map +1 -0
  165. package/dist/types/devicepush.js +2 -0
  166. package/dist/types/devicepush.js.map +1 -0
  167. package/dist/types/deviceresponse.d.ts +2 -3
  168. package/dist/types/deviceresponse.d.ts.map +1 -1
  169. package/dist/types/devicestatus.d.ts.map +1 -1
  170. package/dist/types/devicewebhookstatus.d.ts +32 -0
  171. package/dist/types/devicewebhookstatus.d.ts.map +1 -1
  172. package/dist/types/irdevicelist.d.ts.map +1 -1
  173. package/dist/types/types.d.ts +24 -1
  174. package/dist/types/types.d.ts.map +1 -1
  175. package/dist/types/types.js +14 -0
  176. package/dist/types/types.js.map +1 -1
  177. package/docs/assets/highlight.css +12 -47
  178. package/docs/assets/main.js +1 -1
  179. package/docs/assets/navigation.js +1 -1
  180. package/docs/assets/search.js +1 -1
  181. package/docs/classes/SwitchBotBLE.html +62 -0
  182. package/docs/classes/SwitchBotOpenAPI.html +47 -0
  183. package/docs/classes/SwitchbotDevice.html +32 -33
  184. package/docs/enums/LogLevel.html +10 -0
  185. package/docs/enums/SwitchBotBLEModel.html +2 -2
  186. package/docs/enums/SwitchBotBLEModelFriendlyName.html +2 -2
  187. package/docs/enums/SwitchBotBLEModelName.html +2 -2
  188. package/docs/enums/SwitchBotModel.html +2 -2
  189. package/docs/hierarchy.html +1 -0
  190. package/docs/index.html +16 -993
  191. package/docs/interfaces/Ad-1.html +5 -0
  192. package/docs/interfaces/AdvertisementData.html +3 -0
  193. package/docs/interfaces/Chars.html +4 -0
  194. package/docs/interfaces/ErrorObject.html +3 -0
  195. package/docs/interfaces/Params.html +6 -0
  196. package/docs/interfaces/Rule.html +9 -0
  197. package/docs/interfaces/ServiceData.html +2 -0
  198. package/docs/interfaces/SwitchBotBLEDevice.html +21 -0
  199. package/docs/interfaces/WebhookDetail.html +6 -0
  200. package/docs/interfaces/ad.html +5 -0
  201. package/docs/interfaces/body.html +3 -0
  202. package/docs/interfaces/bodyChange.html +4 -0
  203. package/docs/interfaces/deleteWebhookResponse.html +4 -0
  204. package/docs/interfaces/device.html +7 -0
  205. package/docs/interfaces/deviceList.html +2 -0
  206. package/docs/interfaces/deviceStatus.html +7 -0
  207. package/docs/interfaces/deviceStatusRequest.html +4 -0
  208. package/docs/interfaces/deviceWebhook.html +4 -0
  209. package/docs/interfaces/deviceWebhookContext.html +4 -0
  210. package/docs/interfaces/devices.html +4 -0
  211. package/docs/interfaces/infraredRemoteList.html +2 -0
  212. package/docs/interfaces/irdevice.html +5 -0
  213. package/docs/interfaces/pushResponse.html +4 -0
  214. package/docs/interfaces/queryWebhookResponse.html +4 -0
  215. package/docs/interfaces/setupWebhookResponse.html +4 -0
  216. package/docs/interfaces/switchbot.html +3 -0
  217. package/docs/interfaces/updateWebhookResponse.html +4 -0
  218. package/docs/interfaces/webhookRequest.html +4 -0
  219. package/docs/media/BLE.md +1144 -0
  220. package/docs/media/OpenAPI.md +185 -0
  221. package/docs/modules.html +137 -3
  222. package/docs/types/MacAddress.html +1 -0
  223. package/docs/types/batteryCirculatorFan.html +1 -0
  224. package/docs/types/batteryCirculatorFanServiceData.html +1 -0
  225. package/docs/types/batteryCirculatorFanStatus.html +1 -0
  226. package/docs/types/batteryCirculatorFanWebhookContext.html +1 -0
  227. package/docs/types/blindTilt.html +1 -0
  228. package/docs/types/blindTiltServiceData.html +1 -0
  229. package/docs/types/blindTiltStatus.html +1 -0
  230. package/docs/types/blindTiltWebhookContext.html +1 -0
  231. package/docs/types/bot.html +1 -0
  232. package/docs/types/botServiceData.html +1 -0
  233. package/docs/types/botStatus.html +1 -0
  234. package/docs/types/botWebhookContext.html +1 -0
  235. package/docs/types/ceilingLight.html +1 -0
  236. package/docs/types/ceilingLightPro.html +1 -0
  237. package/docs/types/ceilingLightProServiceData.html +1 -0
  238. package/docs/types/ceilingLightProStatus.html +1 -0
  239. package/docs/types/ceilingLightProWebhookContext.html +1 -0
  240. package/docs/types/ceilingLightServiceData.html +1 -0
  241. package/docs/types/ceilingLightStatus.html +1 -0
  242. package/docs/types/ceilingLightWebhookContext.html +1 -0
  243. package/docs/types/colorBulb.html +1 -0
  244. package/docs/types/colorBulbServiceData.html +1 -0
  245. package/docs/types/colorBulbStatus.html +1 -0
  246. package/docs/types/colorBulbWebhookContext.html +1 -0
  247. package/docs/types/contactSensor.html +1 -0
  248. package/docs/types/contactSensorServiceData.html +1 -0
  249. package/docs/types/contactSensorStatus.html +1 -0
  250. package/docs/types/contactSensorWebhookContext.html +1 -0
  251. package/docs/types/curtain.html +1 -0
  252. package/docs/types/curtain3.html +1 -0
  253. package/docs/types/curtain3ServiceData.html +1 -0
  254. package/docs/types/curtain3WebhookContext.html +1 -0
  255. package/docs/types/curtainServiceData.html +1 -0
  256. package/docs/types/curtainStatus.html +1 -0
  257. package/docs/types/curtainWebhookContext.html +1 -0
  258. package/docs/types/floorCleaningRobotS10.html +1 -0
  259. package/docs/types/floorCleaningRobotS10Status.html +1 -0
  260. package/docs/types/floorCleaningRobotS10WebhookContext.html +1 -0
  261. package/docs/types/hub2.html +1 -0
  262. package/docs/types/hub2ServiceData.html +1 -0
  263. package/docs/types/hub2Status.html +1 -0
  264. package/docs/types/hub2WebhookContext.html +1 -0
  265. package/docs/types/humidifier.html +1 -0
  266. package/docs/types/humidifierServiceData.html +1 -0
  267. package/docs/types/humidifierStatus.html +1 -0
  268. package/docs/types/humidifierWebhookContext.html +1 -0
  269. package/docs/types/indoorCam.html +1 -0
  270. package/docs/types/indoorCameraWebhookContext.html +1 -0
  271. package/docs/types/keypad.html +1 -0
  272. package/docs/types/keypadTouch.html +1 -0
  273. package/docs/types/keypadTouchWebhookContext.html +1 -0
  274. package/docs/types/keypadWebhookContext.html +1 -0
  275. package/docs/types/lock.html +1 -0
  276. package/docs/types/lockPro.html +1 -0
  277. package/docs/types/lockProServiceData.html +1 -0
  278. package/docs/types/lockProStatus.html +1 -0
  279. package/docs/types/lockProWebhookContext.html +1 -0
  280. package/docs/types/lockServiceData.html +1 -0
  281. package/docs/types/lockStatus.html +1 -0
  282. package/docs/types/lockWebhookContext.html +1 -0
  283. package/docs/types/meter.html +1 -0
  284. package/docs/types/meterPlus.html +1 -0
  285. package/docs/types/meterPlusServiceData.html +1 -0
  286. package/docs/types/meterPlusStatus.html +1 -0
  287. package/docs/types/meterPlusWebhookContext.html +1 -0
  288. package/docs/types/meterServiceData.html +1 -0
  289. package/docs/types/meterStatus.html +1 -0
  290. package/docs/types/meterWebhookContext.html +1 -0
  291. package/docs/types/motionSensor.html +1 -0
  292. package/docs/types/motionSensorServiceData.html +1 -0
  293. package/docs/types/motionSensorStatus.html +1 -0
  294. package/docs/types/motionSensorWebhookContext.html +1 -0
  295. package/docs/types/outdoorMeter.html +1 -0
  296. package/docs/types/outdoorMeterServiceData.html +1 -0
  297. package/docs/types/outdoorMeterStatus.html +1 -0
  298. package/docs/types/outdoorMeterWebhookContext.html +1 -0
  299. package/docs/types/panTiltCamWebhookContext.html +1 -0
  300. package/docs/types/pantiltCam.html +1 -0
  301. package/docs/types/pantiltCam2k.html +1 -0
  302. package/docs/types/plug.html +1 -0
  303. package/docs/types/plugMini.html +1 -0
  304. package/docs/types/plugMiniJPServiceData.html +1 -0
  305. package/docs/types/plugMiniJPWebhookContext.html +1 -0
  306. package/docs/types/plugMiniStatus.html +1 -0
  307. package/docs/types/plugMiniUSServiceData.html +1 -0
  308. package/docs/types/plugMiniUSWebhookContext.html +1 -0
  309. package/docs/types/plugStatus.html +1 -0
  310. package/docs/types/plugWebhookContext.html +1 -0
  311. package/docs/types/remote.html +1 -0
  312. package/docs/types/robotVacuumCleanerS1.html +1 -0
  313. package/docs/types/robotVacuumCleanerS1Plus.html +1 -0
  314. package/docs/types/robotVacuumCleanerS1PlusStatus.html +1 -0
  315. package/docs/types/robotVacuumCleanerS1PlusWebhookContext.html +1 -0
  316. package/docs/types/robotVacuumCleanerS1Status.html +1 -0
  317. package/docs/types/robotVacuumCleanerS1WebhookContext.html +1 -0
  318. package/docs/types/robotVacuumCleanerServiceData.html +1 -0
  319. package/docs/types/stripLight.html +1 -0
  320. package/docs/types/stripLightServiceData.html +1 -0
  321. package/docs/types/stripLightStatus.html +1 -0
  322. package/docs/types/stripLightWebhookContext.html +1 -0
  323. package/docs/types/waterLeakDetector.html +1 -0
  324. package/docs/types/waterLeakDetectorServiceData.html +1 -0
  325. package/docs/types/waterLeakDetectorStatus.html +1 -0
  326. package/docs/types/waterLeakDetectorWebhookContext.html +1 -0
  327. package/package.json +15 -13
  328. package/.github/npm-version-script.cjs +0 -81
  329. package/dist/switchbot.d.ts.map +0 -1
  330. package/dist/switchbot.js +0 -259
  331. package/dist/switchbot.js.map +0 -1
  332. package/dist/test/wohand2.test.d.ts +0 -2
  333. package/dist/test/wohand2.test.d.ts.map +0 -1
  334. package/dist/test/wohand2.test.js +0 -50
  335. package/dist/test/wohand2.test.js.map +0 -1
  336. package/dist/types/pushbody.d.ts +0 -6
  337. package/dist/types/pushbody.d.ts.map +0 -1
  338. package/dist/types/pushbody.js +0 -2
  339. package/dist/types/pushbody.js.map +0 -1
  340. package/docs/classes/SwitchBot.html +0 -16
  341. package/docs/types/SwitchBotBLEDevice.html +0 -1
package/BLE.md ADDED
@@ -0,0 +1,1144 @@
1
+ # SwitchBot BLE Documentation
2
+
3
+ The `SwitchBot` class allows you to interact with SwitchBot devices using the SwitchBot BLE. This documentation provides an overview of how to install, set up, and use the various methods available in the `SwitchBotBLE` class.
4
+
5
+ ## Table of Contents
6
+
7
+ - [BLE (Bluetooth Low Energy)](#ble-bluetooth-low-energy)
8
+ - [Supported OS](#supported-os)
9
+ - [Dependencies](#dependencies)
10
+ - [Importing and Setting Up](#importing-and-setting-up)
11
+ - [`SwitchBotBLE` Object](#switchbot-object)
12
+ - [`discover()` method](#discover-method)
13
+ - [`ondiscover` event handler](#ondiscover-event-handler)
14
+ - [`startScan()` method](#startscan-method)
15
+ - [`onadvertisement` event handler](#onadvertisement-event-handler)
16
+ - [`stopScan()` method](#stopscan-method)
17
+ - [`wait()` method](#wait-method)
18
+ - [`SwitchBotDevice` Object](#switchbotdevice-object)
19
+ - [Properties](#properties)
20
+ - [`getDeviceName()` method](#getdevicename-method)
21
+ - [`setDeviceName()` method](#setdevicename-method)
22
+ - [`connect()` method](#connect-method)
23
+ - [`disconnect()` method](#disconnect-method)
24
+ - [`onconnect` event handler](#onconnect-event-handler)
25
+ - [`ondisconnect` event handler](#ondisconnect-event-handler)
26
+ - [`WoHand` Object](#wohand-object)
27
+ - [`press()` method](#press-method)
28
+ - [`turnOn()` method](#turnon-method)
29
+ - [`turnOff()` method](#turnoff-method)
30
+ - [`down()` method](#down-method)
31
+ - [`up()` method](#up-method)
32
+ - [`WoCurtain` object](#wocurtain-object)
33
+ - [`open()` method](#open-method)
34
+ - [`close()` method](#close-method)
35
+ - [`pause()` method](#pause-method)
36
+ - [`runToPos()` method](#runtopos-method)
37
+ - [`WoPlugMini` object](#woplugmini-object)
38
+ - [`turnOn()` method](#turnon-method)
39
+ - [`turnOff()` method](#turnoff-method)
40
+ - [`toggle()` method](#toggle-method)
41
+ - [`WoSmartLock` object](#wosmartlock-object)
42
+ - [`lock()` method](#lock-method)
43
+ - [`unlock()` method](#unlock-method)
44
+ - [`unlock_no_unlatch()` method](#unlock_no_unlatch-method)
45
+ - [`info()` method](#info-method)
46
+ - [Advertisement data](#advertisement-data)
47
+ - [Bot (WoHand)](#bot-wohand)
48
+ - [Meter (WoSensorTH)](#meter-wosensorth)
49
+ - [Curtain (WoCurtain)](#curtain-wocurtain)
50
+ - [Contact (WoContact)](#contact-wocontact)
51
+ - [Motion (WoMotion)](#motion-womotion)
52
+ - [PlugMini (WoPlugMini)](#plugmini-woplugmini)
53
+ - [Supported Devices](#supported-devices)
54
+ - [Advertisement Data](#advertisement-data)
55
+ - [Control Device](#control-device)
56
+ - [Summary](#summary)
57
+
58
+ ## BLE (Bluetooth Low Energy)
59
+
60
+ ### Supported OS
61
+
62
+ 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 [@stoprocent/noble](https://github.com/stoprocent/noble#readme) is installed properly, this module might work well on such OSes.)
63
+
64
+ ### Dependencies
65
+
66
+ - [Node.js](https://nodejs.org/en/): ^20
67
+ - [@stoprocent/noble](https://github.com/stoprocent/noble)
68
+ - Included as a dependency so no need to install manually however if for some reason your OS requires addtional libaries, see `@stoprocent/noble` [prerequisites](https://github.com/stoprocent/noble?tab=readme-ov-file#prerequisites), you will then need to reinstall `node-switchbot` or the package that you have `node-swtichbot` as a dependency.
69
+
70
+ ### Importing and Setting Up
71
+
72
+ To use the `SwitchBotBLE` class in `node-switchbot`, you need to import it and create an instance.
73
+
74
+ ```typescript
75
+ import { SwitchBotBLE } from 'node-switchbot'
76
+
77
+ // Example usage
78
+ const switchBotBLE = new SwitchBotBLE()
79
+
80
+ try {
81
+ await switchBotBLE.startScan()
82
+ } catch (e: any) {
83
+ console.error(`Failed to start BLE scanning. Error:${e}`)
84
+ }
85
+ ```
86
+
87
+ ### `SwitchBotBLE` Object
88
+
89
+ The `SwitchBotBLE` constructor takes an argument optionally. It must be a hash object containing the properties as follows:
90
+
91
+ | Property | Type | Required | Description |
92
+ | :------- | :---- | :------- | :-------------------------------------------------------------------------------------- |
93
+ | `noble` | Noble | option | a Noble object of the [`@stoprocent/noble`](https://github.com/stoprocent/noble) module |
94
+
95
+ The node-switchbot module uses the [`@stoprocent/noble`](https://github.com/stoprocent/noble) module in order to interact with BLE devices. If you want to interact other BLE devices using the `@stoprocent/noble` module, you can create an `Noble` object by yourself, then pass it to this module. If you don't specify a `Noble` object to the `noble` property, this module automatically create a `Noble` object internally.
96
+
97
+ The sample code below shows how to pass a `Noble` object to the `Switchbot` constructor.
98
+
99
+ ```Typescript
100
+ // Create a Noble object
101
+ const noble = require('@stoprocent/noble');
102
+
103
+ const switchBotBLE = new SwitchBotBLE({ 'noble': Noble })
104
+ ```
105
+
106
+ In the code snippet above, the variable `switchbot` is an `SwitchBotBLE` object. The `SwitchBotBLE` object has a lot of methods as described in sections below.
107
+
108
+ #### `discover()` method
109
+
110
+ The `discover` method finds devices. This method returns a `Promise` object. This method takes an argument which is a hash object containing parameters as follows:
111
+
112
+ | Property | Type | Required | Description |
113
+ | :--------- | :------ | :------- | :--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
114
+ | `duration` | Integer | Optional | Duration for discovery process (msec). The default value is 5000 (msec). |
115
+ | `model` | String | Optional | `"H"`, `"T"` or `"c"`. If `"H"` is specified, this method will discover only Bots. If `"T"` is specified, this method will discover only Meters. If `"c"` is specified, this method will discover only Curtains. |
116
+ | `id` | String | Optional | 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. |
117
+ | `quick` | Boolean | Optional | If this value is `true`, this method finishes the discovery process when the first device is found, then calls the `resolve()` function without waiting the specified `duration`. The default value is `false`. |
118
+
119
+ In the code snippet below, no parameter is passed to the method:
120
+
121
+ ```Typescript
122
+ switchBotBLE.discover().then((device_list) => {
123
+ // Do something...
124
+ }).catch((error) => {
125
+ console.error(error);
126
+ });
127
+ ```
128
+
129
+ If no parameter is passed to the method as the code above, an `Array` object will be passed to the `resolve()` function in 5 seconds. The `Array` object contains [`SwitchbotDevice`](#SwitchbotDevice-object) objects representing the found devices. See the section "[`SwitchbotDevice`](#SwitchbotDevice-object) objects" for more details.
130
+
131
+ If you want a quick response, you can set the `quick` property to `true`.
132
+
133
+ ```Typescript
134
+ switchBotBLE.discover({
135
+ duration: 5000,
136
+ quick: true
137
+ }).then((device_list) => {
138
+ // Do something...
139
+ }).catch((error) => {
140
+ console.error(error);
141
+ });
142
+ ```
143
+
144
+ As the `quick` property is set to `true`, the `resolve()` function will be called immediately after a device is found regardless the value of the `duration` property.
145
+
146
+ #### `ondiscover` event handler
147
+
148
+ The `ondiscover` property on the [`Switchbot`](#Switchbot-object) object is an event handler called whenever a device is newly found in the discovery process. A [`SwitchbotDevice`](#SwitchbotDevice-object) object is passed to the callback function set to the `ondiscover` property.
149
+
150
+ ```Typescript
151
+ switchBotBLE.ondiscover = (device) => {
152
+ console.log(device.id + ' (' + device.modelName + ')');
153
+ };
154
+
155
+ switchBotBLE.discover().then(() => {
156
+ console.log('The discovery process was finished.');
157
+ }).catch((error) => {
158
+ console.error(error);
159
+ });
160
+ ```
161
+
162
+ The code snippet above will output the result as follows:
163
+
164
+ ```
165
+ cb4eb903c96d (WoSensorTH)
166
+ c12e453e2008 (WoHand)
167
+ The discovery process was finished.
168
+ ```
169
+
170
+ #### `startScan()` method
171
+
172
+ The `startScan()` method starts to scan advertising packets coming from devices. This method takes an argument which is a hash object containing the parameters as follows:
173
+
174
+ | Property | Type | Required | Description |
175
+ | :------- | :----- | :------- | :---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
176
+ | `model` | String | Optional | `"H"`, `"T"`, `"c"`, `"g"` or `"j"`. If `"H"` is specified, this method will discover only Bots. If `"T"` is specified, this method will discover only Meters. If `"c"` is specified, this method will discover only Curtains. If `"g"` or `"j"` is specified, this method will discover only (US/JP) Plug Minis. |
177
+ | `id` | String | Optional | 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. |
178
+
179
+ Whenever a packet is received, the callback function set to the [`onadvertisement`](#Switchbot-onadvertisement-event-handler) property of the [`Switchbot`](#Switchbot-object) object will be called. When a packet is received, a hash object representing the packet will be passed to the callback function.
180
+
181
+ ```Typescript
182
+ // Set a callback function called when a packet is received
183
+ switchBotBLE.onadvertisement = (ad) => {
184
+ console.log(ad);
185
+ };
186
+
187
+ // Start to scan advertising packets
188
+ switchBotBLE.startScan({
189
+ id: 'cb:4e:b9:03:c9:6d',
190
+ }).then(() => {
191
+ // Wait for 30 seconds
192
+ return switchBotBLE.wait(30000);
193
+ }).then(() => {
194
+ // Stop to scan
195
+ switchBotBLE.stopScan();
196
+ process.exit();
197
+ }).catch((error) => {
198
+ console.error(error);
199
+ });
200
+ ```
201
+
202
+ The code snippet above will output the result as follows:
203
+
204
+ ```
205
+ {
206
+ id: 'cb4eb903c96d',
207
+ address: 'cb:4e:b9:03:c9:6d',
208
+ rssi: -65,
209
+ serviceData: {
210
+ model: 'T',
211
+ modelName: 'WoSensorTH',
212
+ celsius: 25.8,
213
+ fahrenheit: 78.4,
214
+ fahrenheit_mode: false,
215
+ humidity: 43,
216
+ battery: 100
217
+ }
218
+ }
219
+ ...
220
+ ```
221
+
222
+ The `serviceData` property depends on the model of the device. See the section "[Advertisement data](#Advertisement-data)" for the details of the data format.
223
+
224
+ #### `onadvertisement` event handler
225
+
226
+ If a callback function is set to the `onadvertisement` 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 [`startScan()`](#startscan-method) method is called, to the moment when the [`stopScan()`](#Switchbot-stopScan-method) method is called).
227
+
228
+ ```typescript
229
+ switchBotBLE.onadvertisement = async (ad: any) => {
230
+ try {
231
+ this.bleEventHandler[ad.address]?.(ad.serviceData)
232
+ } catch (e: any) {
233
+ await this.errorLog(`Failed to handle BLE event. Error:${e}`)
234
+ }
235
+ }
236
+ ```
237
+
238
+ See the section "[`startScan()` method](#startscan-method)" for details.
239
+
240
+ #### `stopScan()` method
241
+
242
+ The `stopScan()` method stops to scan advertising packets coming from devices. This method returns nothing. Note that this method is _not_ asynchronous but synchronous unlike the other methods. See the section "[`startScan()` method](#startscan-method)" for details.
243
+
244
+ ```typescript
245
+ try {
246
+ switchBotBLE.stopScan()
247
+ console.log('Stopped BLE scanning to close listening.')
248
+ } catch (e: any) {
249
+ console.error(`Failed to stop BLE scanning, error:${e.message}`)
250
+ }
251
+ ```
252
+
253
+ #### `wait()` method
254
+
255
+ The `wait()` method waits for the specified milliseconds. This method takes an integer representing the duration (millisecond). This method returns a `Promise` object.
256
+
257
+ This method has nothing to do with Switchbot devices. It's just a utility method. See the section "[Quick Start](#Quick-Start)" for details of the usage of this method.
258
+
259
+ ```typescript
260
+ await switchBotBLE.wait(1000)
261
+ ```
262
+
263
+ ### `SwitchBotDevice` Object
264
+
265
+ The `SwitchbotDevice` object represents a Switchbot device (Bot, Meter, Curtain, Contact or Motion), which is created through the discovery process triggered by the [`switchBotBLE.discover()`](#discover-method) method.
266
+
267
+ Actually, the `SwitchbotDevice` object is a super class of the [`WoHand`](#SwitchbotDeviceWoHand-object) and `WoSensorTH` objects. The [`WoHand`](#SwitchbotDeviceWoHand-object) object represents a Bot, the `WoSensorTH` object represents a Meter.
268
+
269
+ You can use the properties and methods described in this section on Bot, Meter, Curtain, Contact and Motion. See the section "[`WoHand` object](#SwitchbotDeviceWoHand-object)" for the details of the functionalities available only on Bot. For now, `WoSensorTH` object has no additional functionality.
270
+
271
+ #### Properties
272
+
273
+ The `SwitchbotDevice` object supports the properties as follows:
274
+
275
+ | Property | Type | Description |
276
+ | :---------------- | :------- | :----------------------------------------------------------------------------------------------------------------------------------------------------------- |
277
+ | `id` | String | ID of the device. (e.g., `"cb4eb903c96d"`) |
278
+ | `address` | String | MAC address of the device. Basically it is as same as the value of the `id` except that this value includes `:` in the string. (e.g., `"cb:4e:b9:03:c9:6d"`) |
279
+ | `model` | String | This value is `"H"` "Bot (WoHand)", `"T"` "Meter (WoSensorTH)", `"c"` "Curtain (WoCurtain)", `"d"` "Contact (WoContact)" or `"s"` "Motion (WoMotion)". |
280
+ | `modelName` | String | This value is `"WoHand"`, `"WoSensorTH"`, `WoCurtain`, `WoContect` or `WoMotion`. |
281
+ | `connectionState` | String | This value indicates the BLE connection state. `"connecting"`, `"connected"`, `"disconnecting"`, or `"disconnected"`. |
282
+ | `onconnect` | Function | See the section "[`onconnect` event handler](#SwitchbotDevice-onconnect-event-handler)" for details. |
283
+ | `ondisconnect` | Function | See the section "[`ondisconnect` event handler](#SwitchbotDevice-ondisconnect-event-handler)" for details. |
284
+
285
+ #### `getDeviceName()` method
286
+
287
+ The `getDeviceName()` method fetches the device name saved in the device. This method returns a `Promise` object.
288
+
289
+ 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 [`connect()`](#SwitchbotDevice-connect-method) method in advance.
290
+
291
+ If the device name is fetched successfully, the device name will be passed to the `resolve()`.
292
+
293
+ ```Typescript
294
+ switchbot
295
+ .discover({ model: "H", quick: true })
296
+ .then((device_list) => {
297
+ return device_list[0].getDeviceName();
298
+ })
299
+ .then((name) => {
300
+ console.log(name);
301
+ process.exit();
302
+ })
303
+ .catch((error) => {
304
+ console.error(error);
305
+ process.exit();
306
+ });
307
+ ```
308
+
309
+ The code above will output the result as follows:
310
+
311
+ ```Typescript
312
+ WoHand;
313
+ ```
314
+
315
+ #### `setDeviceName()` method
316
+
317
+ The `setDeviceName()` method update the device name saved in the device with the name specified as the first argument. This method returns a `Promise` object. Nothing will be passed to the `resolve()` function.
318
+
319
+ 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 [`connect()`](#SwitchbotDevice-connect-method) method in advance.
320
+
321
+ 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.
322
+
323
+ ```Typescript
324
+ switchbot
325
+ .discover({ model: "H", quick: true })
326
+ .then((device_list) => {
327
+ return device_list[0].setDeviceName("Bot in kitchen");
328
+ })
329
+ .then(() => {
330
+ console.log("Done.");
331
+ process.exit();
332
+ })
333
+ .catch((error) => {
334
+ console.error(error);
335
+ process.exit();
336
+ });
337
+ ```
338
+
339
+ #### `connect()` method
340
+
341
+ The `connect()` method establishes a connection with the device (i.e., pairing). This method returns a `Promise` object. If the device has already been connected, this method does nothing and calls the `resolve()` function immediately.
342
+
343
+ Most of the methods implemented in the `SwitchbotDevice` 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.
344
+
345
+ The connection established using the `connect()` method is not disconnected automatically unless the [`disconnect()`](#SwitchbotDevice-disconnect-method) method is explicitly called.
346
+
347
+ The code snippet below establishes a connection with the Bot using the `connect()` method, then puts the Bot's arm down, then waits for 5 seconds, then puts the arm down, finally disconnects the device using the [`disconnect()`](#SwitchbotDevice-disconnect-method) method:
348
+
349
+ ```Typescript
350
+ let device = null;
351
+
352
+ switchbot
353
+ .discover({ model: "H", quick: true })
354
+ .then((device_list) => {
355
+ device = device_list[0];
356
+ if (!device) {
357
+ console.log("No device was found.");
358
+ process.exit();
359
+ }
360
+ console.log(device.modelName + " (" + device.address + ") was found.");
361
+ console.log("Connecting...");
362
+ return device.connect();
363
+ })
364
+ .then(() => {
365
+ console.log("Putting the arm down...");
366
+ return device.down();
367
+ })
368
+ .then(() => {
369
+ console.log("Waiting for 5 seconds...");
370
+ return switchBotBLE.wait(5000);
371
+ })
372
+ .then(() => {
373
+ console.log("Putting the arm up...");
374
+ return device.up();
375
+ })
376
+ .then(() => {
377
+ console.log("Disconnecting...");
378
+ return device.disconnect();
379
+ })
380
+ .then(() => {
381
+ console.log("Done.");
382
+ process.exit();
383
+ })
384
+ .catch((error) => {
385
+ console.error(error);
386
+ process.exit();
387
+ });
388
+ ```
389
+
390
+ The result will be as follows:
391
+
392
+ ```
393
+ WoHand (c1:2e:45:3e:20:08) was found.
394
+ Connecting...
395
+ Putting the arm down...
396
+ Waiting for 5 seconds...
397
+ Putting the arm up...
398
+ Disconnecting...
399
+ Done.
400
+ ```
401
+
402
+ #### `disconnect()` method
403
+
404
+ The `disconnect()` method disconnects the device. This method returns a `Promise` object. If the device has already been disconnected, this method does nothing and calls the `resolve()` function immediately.
405
+
406
+ See the [previous section](#SwitchbotDevice-connect-method) for more details.
407
+
408
+ #### `onconnect` event handler
409
+
410
+ The `onconnect` event handler will be called when the connection with the device is established. Nothing will be passed to the handler.
411
+
412
+ The code below calls the [`press()`](#SwitchbotDeviceWoHand-press-method) method, while callback functions are attached to the `onconnect` and `ondisconnect`.
413
+
414
+ ```Typescript
415
+ switchbot
416
+ .discover({ model: "H", quick: true })
417
+ .then((device_list) => {
418
+ const device = device_list[0];
419
+ if (!device) {
420
+ console.log("No device was found.");
421
+ process.exit();
422
+ }
423
+ console.log(device.modelName + " (" + device.address + ") was found.");
424
+
425
+ // Set event handers
426
+ device.onconnect = () => {
427
+ console.log("Connected.");
428
+ };
429
+ device.ondisconnect = () => {
430
+ console.log("Disconnected.");
431
+ };
432
+
433
+ console.log("Pressing the switch...");
434
+ return device.press();
435
+ })
436
+ .then(() => {
437
+ console.log("Done.");
438
+ process.exit();
439
+ })
440
+ .catch((error) => {
441
+ console.error(error);
442
+ process.exit();
443
+ });
444
+ ```
445
+
446
+ The code above will output the result as follows:
447
+
448
+ ```
449
+ WoHand (c1:2e:45:3e:20:08) was found.
450
+ Pressing the switch...
451
+ Connected.
452
+ Disconnected.
453
+ Done.
454
+ ```
455
+
456
+ Seeing the result, you would find the [`press()`](#SwitchbotDeviceWoHand-press-method) method automatically connects and disconnects the device.
457
+
458
+ #### `ondisconnect` event handler
459
+
460
+ The `ondisconnect` event handler will be called when the connection with the device is closed. Nothing will be passed to the handler. See the previous section "[`onconnect` event handler](#SwitchbotDevice-onconnect-event-handler)" for more details.
461
+
462
+ ### `WoHand` Object
463
+
464
+ The `WoHand` object represents a Bot, which is created through the discovery process triggered by the [`switchBotBLE.discover()`](#discover-method) method.
465
+
466
+ Actually, the `WoHand` is an object inherited from the [`SwitchbotDevice`](#SwitchbotDevice-object). You can use not only the method described in this section but also the properties and methods implemented in the [`SwitchbotDevice`](#SwitchbotDevice-object) object.
467
+
468
+ #### `press()` method
469
+
470
+ The `press()` method sends a press command to the Bot. This method returns a `Promise` object. Nothing will be passed to the `resove()`.
471
+
472
+ 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 [`connect()`](#SwitchbotDevice-connect-method) method in advance.
473
+
474
+ ```Typescript
475
+ switchbot
476
+ .discover({ model: "H", quick: true })
477
+ .then((device_list) => {
478
+ return device_list[0].press();
479
+ })
480
+ .then(() => {
481
+ console.log("Done.");
482
+ })
483
+ .catch((error) => {
484
+ console.error(error);
485
+ });
486
+ ```
487
+
488
+ When the Bot receives this command, the Bot's arm will be put down (stretched), then put up (retracted) in a few seconds.
489
+
490
+ #### `turnOn()` method
491
+
492
+ The `turnOn()` method sends a turn-on command to the Bot. This method returns a `Promise` object. Nothing will be passed to the `resove()`.
493
+
494
+ 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 [`connect()`](#SwitchbotDevice-connect-method) method in advance.
495
+
496
+ When the Bot receives this command, the Bot's arm will be put down (stretched) or put up (retracted) depending on the mode setting.
497
+
498
+ | Mode | Inverse the on/off direction | Physical position of the arm |
499
+ | :---------- | :--------------------------- | :------------------------------------ |
500
+ | Press mode | N/A | Down (stretched), then Up (retracted) |
501
+ | Switch mode | Disabled | Down (stretched) |
502
+ |   | Enabled | Up (retracted) |
503
+
504
+ ```Typescript
505
+ switchbot
506
+ .discover({ model: "H", quick: true })
507
+ .then((device_list) => {
508
+ return device_list[0].turnOn();
509
+ })
510
+ .then(() => {
511
+ console.log("Done.");
512
+ })
513
+ .catch((error) => {
514
+ console.error(error);
515
+ });
516
+ ```
517
+
518
+ #### `turnOff()` method
519
+
520
+ The `turnOff()` method sends a turn-off command to the Bot. This method returns a `Promise` object. Nothing will be passed to the `resove()`.
521
+
522
+ 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 [`connect()`](#SwitchbotDevice-connect-method) method in advance.
523
+
524
+ When the Bot receives this command, the Bot's arm will be put down (stretched) or put up (retracted) depending on the mode setting.
525
+
526
+ | Mode | Inverse the on/off direction | Physical position of the arm |
527
+ | :---------- | :--------------------------- | :------------------------------------ |
528
+ | Press mode | N/A | Down (stretched), then Up (retracted) |
529
+ | Switch mode | Disabled | Up (retracted) |
530
+ |   | Enabled | Down (stretched) |
531
+
532
+ ```Typescript
533
+ switchbot
534
+ .discover({ model: "H", quick: true })
535
+ .then((device_list) => {
536
+ return device_list[0].turnOff();
537
+ })
538
+ .then(() => {
539
+ console.log("Done.");
540
+ })
541
+ .catch((error) => {
542
+ console.error(error);
543
+ });
544
+ ```
545
+
546
+ #### `down()` method
547
+
548
+ The `down()` method sends a down command to the Bot. This method returns a `Promise` object. Nothing will be passed to the `resove()`.
549
+
550
+ 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 [`connect()`](#SwitchbotDevice-connect-method) method in advance.
551
+
552
+ When the Bot receives this command, the Bot's arm will be put down (stretched) regardless of the mode setting.
553
+
554
+ ```Typescript
555
+ switchbot
556
+ .discover({ model: "H", quick: true })
557
+ .then((device_list) => {
558
+ return device_list[0].down();
559
+ })
560
+ .then(() => {
561
+ console.log("Done.");
562
+ })
563
+ .catch((error) => {
564
+ console.error(error);
565
+ });
566
+ ```
567
+
568
+ #### `up()` method
569
+
570
+ The `up()` method sends an up command to the Bot. This method returns a `Promise` object. Nothing will be passed to the `resove()`.
571
+
572
+ 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 [`connect()`](#SwitchbotDevice-connect-method) method in advance.
573
+
574
+ When the Bot receives this command, the Bot's arm will be put up (retracted) regardless of the mode setting.
575
+
576
+ ```Typescript
577
+ switchbot
578
+ .discover({ model: "H", quick: true })
579
+ .then((device_list) => {
580
+ return device_list[0].up();
581
+ })
582
+ .then(() => {
583
+ console.log("Done.");
584
+ })
585
+ .catch((error) => {
586
+ console.error(error);
587
+ });
588
+ ```
589
+
590
+ ### `WoCurtain` Object
591
+
592
+ The `WoCurtain` object represents a Curtain, which is created through the discovery process triggered by the [`switchBotBLE.discover()`](#discover-method) method.
593
+
594
+ Actually, the `WoCurtain` is an object inherited from the [`SwitchbotDevice`](#SwitchbotDevice-object). You can use not only the method described in this section but also the properties and methods implemented in the [`SwitchbotDevice`](#SwitchbotDevice-object) object.
595
+
596
+ #### `open()` method
597
+
598
+ The `open()` method sends an open command to the Curtain. This method returns a `Promise` object. Nothing will be passed to the `resove()`.
599
+
600
+ 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 [`connect()`](#SwitchbotDevice-connect-method) method in advance.
601
+
602
+ When the Curtain receives this command, the Curtain will open the curtain (0% position). If not calibrated, the Curtain does not move.
603
+
604
+ The `open()` method receives an optional `mode` parameter. (See [`runToPos()`](#runtopos-method))
605
+
606
+ ```Typescript
607
+ switchbot
608
+ .discover({ model: "c", quick: true })
609
+ .then((device_list) => {
610
+ return device_list[0].open();
611
+ })
612
+ .then(() => {
613
+ console.log("Done.");
614
+ })
615
+ .catch((error) => {
616
+ console.error(error);
617
+ });
618
+ ```
619
+
620
+ #### `close()` method
621
+
622
+ The `close()` method sends a close command to the Curtain. This method returns a `Promise` object. Nothing will be passed to the `resove()`.
623
+
624
+ 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 [`connect()`](#SwitchbotDevice-connect-method) method in advance.
625
+
626
+ When the Curtain receives this command, the Curtain will close the curtain (100% position). If not calibrated, the Curtain does not move.
627
+
628
+ The `close()` method receives an optional `mode` parameter. (See [`runToPos()`](#runtopos-method))
629
+
630
+ ```Typescript
631
+ switchbot
632
+ .discover({ model: "c", quick: true })
633
+ .then((device_list) => {
634
+ return device_list[0].close();
635
+ })
636
+ .then(() => {
637
+ console.log("Done.");
638
+ })
639
+ .catch((error) => {
640
+ console.error(error);
641
+ });
642
+ ```
643
+
644
+ #### `pause()` method
645
+
646
+ The `pause()` method sends a pause command to the Curtain. This method returns a `Promise` object. Nothing will be passed to the `resove()`.
647
+
648
+ 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 [`connect()`](#SwitchbotDevice-connect-method) method in advance.
649
+
650
+ When the Curtain receives this command, the Curtain will pause.
651
+
652
+ ```Typescript
653
+ switchbot
654
+ .discover({ model: "c", quick: true })
655
+ .then((device_list) => {
656
+ return device_list[0].pause();
657
+ })
658
+ .then(() => {
659
+ console.log("Done.");
660
+ })
661
+ .catch((error) => {
662
+ console.error(error);
663
+ });
664
+ ```
665
+
666
+ #### `runToPos()` method
667
+
668
+ The `runToPos()` method sends a position command to the Curtain. This method returns a `Promise` object. Nothing will be passed to the `resove()`.
669
+
670
+ 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 [`connect()`](#SwitchbotDevice-connect-method) method in advance.
671
+
672
+ When the Curtain receives this command, the Curtain will run to the percentage position. If not calibrated, the Curtain does not move.
673
+
674
+ The `open()` method sends an open command to the Curtain. This method returns a `Promise` object. Nothing will be passed to the `resove()`.
675
+
676
+ 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 [`connect()`](#SwitchbotDevice-connect-method) method in advance.
677
+
678
+ When the Curtain receives this command, the Curtain will open the curtain (0% position). If not calibrated, the Curtain does not move.
679
+
680
+ | Property | Type | Required | Description |
681
+ | :-------- | :------ | :------- | :--------------------------------------------------------------------------------------------------------------------------------------------------- |
682
+ | `percent` | Integer | Required | The percentage of target position (`0-100`). (e.g., `50`) |
683
+ | `mode` | Integer | Optional | The running mode of Curtain. <br/>`0x00` - Performance mode.<br/> `0x01` - Silent mode. <br/>`0xff` - Default. Unspecified, from Curtain's settings. |
684
+
685
+ ```Typescript
686
+ switchbot
687
+ .discover({ model: "c", quick: true })
688
+ .then((device_list) => {
689
+ return device_list[0].runToPos(50);
690
+ })
691
+ .then(() => {
692
+ console.log("Done.");
693
+ })
694
+ .catch((error) => {
695
+ console.error(error);
696
+ });
697
+ ```
698
+
699
+ ### `WoPlugMini` Object
700
+
701
+ The `WoPlugMini ` object represents a PlugMini, which is created through the discovery process triggered by the [`switchBotBLE.discover()`](#discover-method) method.
702
+
703
+ Actually, the `WoPlugMini ` is an object inherited from the [`SwitchbotDevice`](#SwitchbotDevice-object). You can use not only the method described in this section but also the properties and methods implemented in the [`SwitchbotDevice`](#SwitchbotDevice-object) object.
704
+
705
+ #### `turnOn()` method
706
+
707
+ The `turnOn()` method sends a turn-on command to the PlugMini. This method returns a `Promise` object. A `boolean` value indicating whether the PlugMini is on (`true`), is passed to the `resolve()` method of the Promise.
708
+
709
+ 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 [`connect()`](#SwitchbotDevice-connect-method) method in advance.
710
+
711
+ #### `turnOff()` method
712
+
713
+ The `turnOff()` method sends a turn-off command to the PlugMini. This method returns a `Promise` object. A `boolean` value indicating whether the PlugMini is off (`false`), is passed to the `resolve()` method of the Promise.
714
+
715
+ 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 [`connect()`](#SwitchbotDevice-connect-method) method in advance.
716
+
717
+ #### `toggle()` method
718
+
719
+ The `toggle()` method sends a toggle command to the PlugMini, toggling between the on and off state. This method returns a `Promise` object. A `boolean` value indicating whether the PlugMini is on (`true`) or off (`false`), is passed to the `resolve()` method of the Promise.
720
+
721
+ 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 [`connect()`](#SwitchbotDevice-connect-method) method in advance.
722
+
723
+ ### `WoSmartLock` Object
724
+
725
+ The `WoSmartLock ` object represents a SmartLock, which is created through the discovery process triggered by the [`switchBotBLE.discover()`](#discover-method) method.
726
+
727
+ Actually, the `WoSmartLock ` is an object inherited from the [`SwitchbotDevice`](#SwitchbotDevice-object). You can use not only the method described in this section but also the properties and methods implemented in the [`SwitchbotDevice`](#SwitchbotDevice-object) object.
728
+
729
+ #### `setKey()` method
730
+
731
+ The `setKey()` method initialises the key information required for encrypted communication with the SmartLock
732
+
733
+ 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 [`pySwitchbot`](https://github.com/Danielhiversen/pySwitchbot/tree/master?tab=readme-ov-file#obtaining-locks-encryption-key) project for an example script.
734
+
735
+ | Property | Type | Description |
736
+ | :-------------- | :----- | :----------------------------------------------------------------------------------------------- |
737
+ | `keyId` | String | unique2 character ID for the key. (e.g., `"ff"`) returned from the SwitchBot api for your device |
738
+ | `encryptionKey` | String | the unique encryption key returned from the SwitchBot api for your device |
739
+
740
+ #### `lock()` method
741
+
742
+ The `lock()` method sends a lock command to the SmartLock. This method returns a `Promise` object. A `boolean` value indicating whether the SmartLock is locked (`true`), is passed to the `resolve()` method of the Promise.
743
+
744
+ 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 [`connect()`](#SwitchbotDevice-connect-method) method in advance.
745
+
746
+ #### `unlock()` method
747
+
748
+ The `unlock()` method sends an unlock command to the SmartLock. This method returns a `Promise` object. A `boolean` value indicating whether the SmartLock is locked (`false`), is passed to the `resolve()` method of the Promise.
749
+
750
+ 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 [`connect()`](#SwitchbotDevice-connect-method) method in advance.
751
+
752
+ #### `unlockNoUnlatch()` method
753
+
754
+ The `unlockNoUnlatch()` method sends a partial unlock command to the SmartLock, unlocking without the full unlatch.
755
+
756
+ 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 [`connect()`](#SwitchbotDevice-connect-method) method in advance.
757
+
758
+ #### `info()` method
759
+
760
+ The `info()` method retreieves state information from the SmartLock, This method returns a `Promise` object. An `object` value indicating with the state infor, is passed to the `resolve()` method of the Promise.
761
+
762
+ 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 [`connect()`](#SwitchbotDevice-connect-method) method in advance.
763
+
764
+ ### Advertisement Data
765
+
766
+ After the [`startScan()`](#startscan-method) method is invoked, the [`onadvertisement`](#Switchbot-onadvertisement-event-handler) event handler will be called whenever an advertising packet comes from the switchbot devices.
767
+
768
+ ```Typescript
769
+ // Load the node-switchbot and get a `Switchbot` constructor object
770
+ import { SwitchBotBLE } from 'node-switchbot';
771
+ // Create a `Switchbot` object
772
+ const switchBotBLE = new SwitchBotBLE();
773
+
774
+ (async () => {
775
+ // Start to monitor advertisement packets
776
+ await switchBotBLE.startScan();
777
+ // Set an event handler
778
+ switchBotBLE.onadvertisement = (ad) => {
779
+ console.log(JSON.stringify(ad, null, ' '));
780
+ };
781
+ // Wait 10 seconds
782
+ await switchBotBLE.wait(10000);
783
+ // Stop to monitor
784
+ switchBotBLE.stopScan();
785
+ process.exit();
786
+ })();
787
+ ```
788
+
789
+ An object containing the properties as follows will be passed to the event handler:
790
+
791
+ | Property | Type | Description |
792
+ | :------------ | :------ | :----------------------------------------------------------------------------------------------------------------------------------------------------------- |
793
+ | `id` | String | ID of the device. (e.g., `"cb4eb903c96d"`) |
794
+ | `address` | String | MAC address of the device. Basically it is as same as the value of the `id` except that this value includes `:` in the string. (e.g., `"cb:4e:b9:03:c9:6d"`) |
795
+ | `rssi` | Integer | RSSI. (e.g., `-62`) |
796
+ | `serviceData` | Object | An object including the device-specific data. |
797
+
798
+ The structures of the `serviceData` are described in the following sections.
799
+
800
+ #### Bot (WoHand)
801
+
802
+ Example of the advertisement data:
803
+
804
+ ```json
805
+ {
806
+ "id": "c12e453e2008",
807
+ "address": "c1:2e:45:3e:20:08",
808
+ "rssi": -61,
809
+ "serviceData": {
810
+ "model": "H",
811
+ "modelName": "WoHand",
812
+ "mode": true,
813
+ "state": false,
814
+ "battery": 100
815
+ }
816
+ }
817
+ ```
818
+
819
+ Structure of the `serviceData`:
820
+
821
+ | Property | Type | Description |
822
+ | :---------- | :------ | :------------------------------------------------------------------------------------------------------------------------------------------- |
823
+ | `model` | String | This value is always `"H"`, which means "Bot (WoHand)". |
824
+ | `modelName` | String | This value is always `"WoHand"`, which means "Bot". |
825
+ | `mode` | Boolean | This indicates the mode setting. When the mode is "Switch mode", this value is `true`. When the mode is "Press mode", this value is `false`. |
826
+ | `state` | Boolean | This value indicates whether the switch status is ON or OFF. |
827
+ | `battery` | Integer | (**experimental**) This value indicates the battery level (`%`). |
828
+
829
+ The `mode` 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.
830
+
831
+ If the `mode` is `false`, which means the "Press mode" is selected, the `state` is always `false`. If the `mode` is `true`, which means the "Switch mode" is selected, the `state` represents the logical state (ON or OFF). Note that it does _not_ mean the physical arm position. The physical arm position depends on the setting "Inverse the on/off direction" on the official smartphone app.
832
+
833
+ | "Inverse the on/off direction" | Value of the `state` | Logical state | Physical arm position |
834
+ | :----------------------------- | :------------------- | :------------ | :-------------------- |
835
+ | disabled | `true` | OFF | Up (retracted) |
836
+ | &nbsp; | `false` | ON | Down (stretched) |
837
+ | enabled | `true` | OFF | Down (stretched) |
838
+ | &nbsp; | `false` | ON | Up (retracted) |
839
+
840
+ The `battery` is _experimental_ for now. I'm not sure whether the value is correct or not. Never trust this value for now.
841
+
842
+ #### Meter (WoSensorTH)
843
+
844
+ Example of the advertisement data:
845
+
846
+ ```json
847
+ {
848
+ "id": "cb4eb903c96d",
849
+ "address": "cb:4e:b9:03:c9:6d",
850
+ "rssi": -70,
851
+ "serviceData": {
852
+ "model": "T",
853
+ "modelName": "WoSensorTH",
854
+ "temperature": {
855
+ "c": 25.2,
856
+ "f": 77.4
857
+ },
858
+ "fahrenheit": false,
859
+ "humidity": 43,
860
+ "battery": 100
861
+ }
862
+ }
863
+ ```
864
+
865
+ Structure of the `data`:
866
+
867
+ | Property | Type | Description |
868
+ | :--------------- | :------ | :----------------------------------------------------------------------------------------------------------- |
869
+ | `model` | String | This value is always `"T"`, which means "Meter (WoSensorTH)". |
870
+ | `modelName` | String | This value is always `"WoSensorTH"`, which means "Meter". |
871
+ | `temperature` | Object |
872
+ | &nbsp;&nbsp; `c` | Float | Temperature (degree Celsius/°C) |
873
+ | &nbsp;&nbsp; `f` | Float | Temperature (degree Fahrenheit/℉) |
874
+ | `fahrenheit` | Boolean | The flag whether the Meter shows Fahrenheit (`true`) or Celsius (`false`) for the temperature on the display |
875
+ | `humidity` | Integer | Humidity (`%`) |
876
+ | `battery` | Integer | (**experimental**) This value indicates the battery level (`%`). |
877
+
878
+ The `fahrenheit` indicates the setting on the device. Note that it does _not_ 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.
879
+
880
+ The `battery` is _experimental_ for now. I'm not sure whether the value is correct or not. Never trust this value for now.
881
+
882
+ #### Curtain (WoCurtain)
883
+
884
+ Example of the advertisement data:
885
+
886
+ ```json
887
+ {
888
+ "id": "ec58c5d00111",
889
+ "address": "ec:58:c5:d0:01:11",
890
+ "rssi": -39,
891
+ "serviceData": {
892
+ "model": "c",
893
+ "modelName": "WoCurtain",
894
+ "calibration": true,
895
+ "battery": 91,
896
+ "position": 1,
897
+ "lightLevel": 1
898
+ }
899
+ }
900
+ ```
901
+
902
+ Structure of the `serviceData`:
903
+
904
+ | Property | Type | Description |
905
+ | :------------ | :------ | :--------------------------------------------------------------------------------- |
906
+ | `model` | String | This value is `"c"`, which means "Curtain (WoCurtain)". |
907
+ | | | or `"{"`, which means "Curtain 3 (WoCurtain)". |
908
+ | `modelName` | String | This value is always `"WoCurtain"`, which means "Curtain". |
909
+ | `calibration` | Boolean | This value indicates the calibration status (`true` or `false`). |
910
+ | `battery` | Integer | This value indicates the battery level (`1-100`, `%`). |
911
+ | `position` | Integer | This value indicates the percentage of current position (`0-100`, 0 is open, `%`). |
912
+ | `lightLevel` | Integer | This value indicates the light level of the light source currently set (`1-10`). |
913
+
914
+ #### Contact (WoContact)
915
+
916
+ Example of the advertisement data:
917
+
918
+ ```json
919
+ {
920
+ "id": "f0cda125e3ec",
921
+ "address": "f0:cd:a1:25:e3:ec",
922
+ "rssi": -56,
923
+ "serviceData": {
924
+ "model": "d",
925
+ "modelName": "WoContact",
926
+ "movement": false,
927
+ "battery": 95,
928
+ "doorState": "close",
929
+ "lightLevel": "bright"
930
+ }
931
+ }
932
+ ```
933
+
934
+ Structure of the `serviceData`:
935
+
936
+ | Property | Type | Description |
937
+ | :----------- | :------ | :--------------------------------------------------------------------------- |
938
+ | `model` | String | This value is always `"c"`, which means "Contact (WoContact)". |
939
+ | `modelName` | String | This value is always `"WoContact"`, which means "Contact". |
940
+ | `movement` | Boolean | This value indicates the motion status (`true` or `false`). |
941
+ | `battery` | Integer | This value indicates the battery level (`1-100`, `%`). |
942
+ | `doorState` | String | This value indicates the door Status (`close`, `open`, `timeout no closed`). |
943
+ | `lightLevel` | String | This value indicates the light level (`dark`, `bright`). |
944
+
945
+ #### Motion (WoMotion)
946
+
947
+ Example of the advertisement data:
948
+
949
+ ```json
950
+ {
951
+ "id": "e7216fa344a9",
952
+ "address": "e7:21:6f:a3:44:a9",
953
+ "rssi": -53,
954
+ "serviceData": {
955
+ "model": "s",
956
+ "modelName": "WoMotion",
957
+ "movement": false,
958
+ "battery": 96,
959
+ "lightLevel": "bright"
960
+ }
961
+ }
962
+ ```
963
+
964
+ Structure of the `serviceData`:
965
+
966
+ | Property | Type | Description |
967
+ | :----------- | :------ | :----------------------------------------------------------- |
968
+ | `model` | String | This value is always `"s"`, which means "Motion (WoMotion)". |
969
+ | `modelName` | String | This value is always `"WoMotion"`, which means "Motion". |
970
+ | `movement` | Boolean | This value indicates the motion status (`true` or `false`). |
971
+ | `battery` | Integer | This value indicates the battery level (`1-100`, `%`). |
972
+ | `lightLevel` | String | This value indicates the light level (`dark`, `bright`). |
973
+
974
+ #### PlugMini (WoPlugMini)
975
+
976
+ Example of the advertisement data:
977
+
978
+ ```json
979
+ {
980
+ "id": "cd2409ea3e9441f87d4580e0380a62bf",
981
+ "address": "60:55:f9:35:f6:a6",
982
+ "rssi": -50,
983
+ "serviceData": {
984
+ "model": "j",
985
+ "modelName": "WoPlugMini",
986
+ "state": "off",
987
+ "delay": false,
988
+ "timer": false,
989
+ "syncUtcTime": true,
990
+ "wifiRssi": 48,
991
+ "overload": false,
992
+ "currentPower": 0
993
+ }
994
+ }
995
+ ```
996
+
997
+ Structure of the `serviceData`:
998
+
999
+ | Property | Type | Description |
1000
+ | :------------- | :------ | :--------------------------------------------------------------------------------- |
1001
+ | `model` | String | This value is always `"j"` or `"g"`, which means "PlugMini" (JP or US). |
1002
+ | `modelName` | String | This value is always `"WoPlugMini"`, which means "PlugMini". |
1003
+ | `state ` | Boolean | This value indicates whether the plug mini is turned on (`true`) or not (`false`). |
1004
+ | `delay` | Boolean | Indicates whether a delay is present. |
1005
+ | `timer` | Boolean | Indicates whether a timer is present. |
1006
+ | `syncUtcTime` | boolean | Indicates whether the UTC time has been synchronized. |
1007
+ | `overload` | boolean | Indicates whether the Plug Mini is overloaded, more than 15A current overload. |
1008
+ | `currentPower` | Float | Current power consumption in Watts. |
1009
+
1010
+ ---
1011
+
1012
+ #### SmartLock (WoSmartLock)
1013
+
1014
+ Example of the advertisement data:
1015
+
1016
+ ```json
1017
+ {
1018
+ "id": "d30864110b8c",
1019
+ "address": "d3:08:64:11:0b:8c",
1020
+ "rssi": -52,
1021
+ "serviceData": {
1022
+ "model": "o",
1023
+ "modelName": "WoSmartLock",
1024
+ "battery": 100,
1025
+ "calibration": true,
1026
+ "status": "LOCKED",
1027
+ "update_from_secondary_lock": false,
1028
+ "door_open": false,
1029
+ "double_lock_mode": false,
1030
+ "unclosed_alarm": false,
1031
+ "unlocked_alarm": false,
1032
+ "auto_lock_paused": false
1033
+ }
1034
+ }
1035
+ ```
1036
+
1037
+ Structure of the `serviceData`:
1038
+
1039
+ | Property | Type | Description |
1040
+ | :--------------------------- | :------ | :---------------------------------------------------------------------------------- |
1041
+ | `model` | String | This value is `"o"`, which means "Lock (WoSmartLock)". |
1042
+ | `modelName` | String | This value is always `"WoSmartLock"`, which means "Lock". |
1043
+ | `battery` | Integer | This value indicates the battery level (`1-100`, `%`). |
1044
+ | `calibration` | Boolean | This value indicates the calibration status (`true` or `false`). |
1045
+ | `status` | String | This value indicates the current locked state. Possible values: |
1046
+ | | | `"LOCKED"`, `"UNLOCKED"`, `"LOCKING"`, `"UNLOCKING"` |
1047
+ | | | `"LOCKING_STOP"`, `"UNLOCKING_STOP"` (stuck when locking or unlocking respectively) |
1048
+ | | | `"NOT_FULLY_LOCKED"` (eu model only), `"UNKNOWN"` (fallback: must be some error) |
1049
+ | `update_from_secondary_lock` | Boolean | ?? |
1050
+ | `door_open` | Boolean | door open status - whether the door is not detecting the sensor magnet |
1051
+ | `double_lock_mode` | Boolean | dual lock mode enabled status - two locks working simultaneously |
1052
+ | `unclosed_alarm` | Boolean | enabled status for door ajar alarm function |
1053
+ | `unlocked_alarm` | Boolean | whether the alarm function is enabled for door left unlocked |
1054
+ | `auto_lock_paused` | Boolean | auto lock mode paused |
1055
+ | `night_latch` | Boolean | night latch mode enabled (eu firmware only) |
1056
+
1057
+ ### Control Device
1058
+
1059
+ This sample discovers a Bot (WoHand), then put the Bot's arm down, finally put it up in 5 seconds.
1060
+
1061
+ ```Typescript
1062
+ // Load the node-switchbot and get a `Switchbot` constructor object
1063
+ import { SwitchBotBLE } from 'node-switchbot';
1064
+ // Create a `Switchbot` object
1065
+ const switchBotBLE = new SwitchBotBLE();
1066
+
1067
+ (async () => {
1068
+ // Find a Bot (WoHand)
1069
+ const bot_list = await switchBotBLE.discover({ model: "H", quick: true });
1070
+ if (bot_list.length === 0) {
1071
+ throw new Error("No device was found.");
1072
+ }
1073
+ // The `WoHand` object representing the found Bot.
1074
+ const device = bot_list[0];
1075
+ // Put the Bot's arm down (stretch the arm)
1076
+ await device.down();
1077
+ // Wait for 5 seconds
1078
+ await switchBotBLE.wait(5000);
1079
+ // Put the Bot's arm up (retract the arm)
1080
+ await device.up();
1081
+ process.exit();
1082
+ })();
1083
+ ```
1084
+
1085
+ In order to manipulate the arm of your Bot, you have to discover your Bot using the [`discover()`](#discover-method) method. The object `{ model: 'H' }` passed to the method means that only Bots will be discovered. That is, Meters will be ignored.
1086
+
1087
+ In this code, you can get a [`WoHand`](#SwitchbotDeviceWoHand-object) object representing the found Bot. Using the [`down()`](#SwitchbotDeviceWoHand-down-method) and [`up()`](#SwitchbotDeviceWoHand-up-method) methods of the object, you can move the arm. In addition to these methods, you can use the [`press()`](#SwitchbotDeviceWoHand-press-method), [`turnOn()`](#SwitchbotDeviceWoHand-turnOn-method), and [`turnOff()`](#SwitchbotDeviceWoHand-turnOff-method) methods as well.
1088
+
1089
+ ### Logging
1090
+
1091
+ To be able to receive logging that this module is pushing out you will need to subscribt to the events.
1092
+
1093
+ ```typescript
1094
+ this.switchBotBLE.on('log', (log) => {
1095
+ switch (log.level) {
1096
+ case LogLevel.SUCCESS:
1097
+ this.successLog(log.message)
1098
+ break
1099
+ case LogLevel.DEBUGSUCCESS:
1100
+ this.debugSuccessLog(log.message)
1101
+ break
1102
+ case LogLevel.WARN:
1103
+ this.warnLog(log.message)
1104
+ break
1105
+ case LogLevel.DEBUGWARN:
1106
+ this.debugWarnLog(log.message)
1107
+ break
1108
+ case LogLevel.ERROR:
1109
+ this.errorLog(log.message)
1110
+ break
1111
+ case LogLevel.DEBUGERROR:
1112
+ this.debugErrorLog(log.message)
1113
+ break
1114
+ case LogLevel.DEBUG:
1115
+ this.debugLog(log.message)
1116
+ break
1117
+ case LogLevel.INFO:
1118
+ default:
1119
+ this.infoLog(log.message)
1120
+ }
1121
+ })
1122
+ ```
1123
+
1124
+ ### Supported Devices
1125
+
1126
+ The following devices are supported.
1127
+
1128
+ | Device | BLE Support |
1129
+ | ------------------------- | ----------- |
1130
+ | SwitchBot Bot | Yes |
1131
+ | SwitchBot Curtain | Yes |
1132
+ | SwitchBot Meter | Yes |
1133
+ | SwitchBot Motion Sensor | Yes |
1134
+ | SwitchBot Contact Sensor | Yes |
1135
+ | SwitchBot Plug Mini | Yes |
1136
+ | SwitchBot Smart Lock | Yes |
1137
+ | SwitchBot Smart Lock Pro | Yes |
1138
+ | SwitchBot Humidifier | Yes |
1139
+ | SwitchBot Color Bulb | Yes |
1140
+ | SwitchBot LED Strip Light | Yes |
1141
+
1142
+ ### Summary
1143
+
1144
+ The `SwitchBotBLE` class provides a powerful way to interact with your SwitchBot devices through BLE. By following the examples provided, you can easily integrate SwitchBot device control and monitoring into your applications.