node-switchbot 2.5.0-beta.3 → 2.5.0-beta.31

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (405) hide show
  1. package/.github/workflows/beta-release.yml +25 -2
  2. package/.github/workflows/release.yml +13 -0
  3. package/BLE.md +1109 -0
  4. package/CHANGELOG.md +14 -0
  5. package/OpenAPI.md +172 -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 +32 -21
  11. package/dist/advertising.d.ts.map +1 -1
  12. package/dist/advertising.js +72 -76
  13. package/dist/advertising.js.map +1 -1
  14. package/dist/device/woblindtilt.d.ts +21 -51
  15. package/dist/device/woblindtilt.d.ts.map +1 -1
  16. package/dist/device/woblindtilt.js +40 -103
  17. package/dist/device/woblindtilt.js.map +1 -1
  18. package/dist/device/wobulb.d.ts +42 -15
  19. package/dist/device/wobulb.d.ts.map +1 -1
  20. package/dist/device/wobulb.js +71 -131
  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 +94 -174
  25. package/dist/device/woceilinglight.js.map +1 -1
  26. package/dist/device/wocontact.d.ts +12 -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 +40 -1
  31. package/dist/device/wocurtain.d.ts.map +1 -1
  32. package/dist/device/wocurtain.js +68 -106
  33. package/dist/device/wocurtain.js.map +1 -1
  34. package/dist/device/wohand.d.ts +38 -2
  35. package/dist/device/wohand.d.ts.map +1 -1
  36. package/dist/device/wohand.js +54 -92
  37. package/dist/device/wohand.js.map +1 -1
  38. package/dist/device/wohub2.d.ts +12 -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 +38 -2
  43. package/dist/device/wohumi.d.ts.map +1 -1
  44. package/dist/device/wohumi.js +51 -86
  45. package/dist/device/wohumi.js.map +1 -1
  46. package/dist/device/woiosensorth.d.ts +13 -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 +44 -12
  51. package/dist/device/woplugmini.d.ts.map +1 -1
  52. package/dist/device/woplugmini.js +68 -80
  53. package/dist/device/woplugmini.js.map +1 -1
  54. package/dist/device/wopresence.d.ts +12 -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 +33 -50
  61. package/dist/device/wosensorth.js.map +1 -1
  62. package/dist/device/wosmartlock.d.ts +58 -13
  63. package/dist/device/wosmartlock.d.ts.map +1 -1
  64. package/dist/device/wosmartlock.js +108 -195
  65. package/dist/device/wosmartlock.js.map +1 -1
  66. package/dist/device/wosmartlockpro.d.ts +63 -18
  67. package/dist/device/wosmartlockpro.d.ts.map +1 -1
  68. package/dist/device/wosmartlockpro.js +116 -204
  69. package/dist/device/wosmartlockpro.js.map +1 -1
  70. package/dist/device/wostrip.d.ts +38 -18
  71. package/dist/device/wostrip.d.ts.map +1 -1
  72. package/dist/device/wostrip.js +79 -125
  73. package/dist/device/wostrip.js.map +1 -1
  74. package/dist/device.d.ts +85 -222
  75. package/dist/device.d.ts.map +1 -1
  76. package/dist/device.js +123 -407
  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 +79 -19
  83. package/dist/parameter-checker.d.ts.map +1 -1
  84. package/dist/parameter-checker.js +140 -335
  85. package/dist/parameter-checker.js.map +1 -1
  86. package/dist/settings.d.ts +46 -0
  87. package/dist/settings.d.ts.map +1 -1
  88. package/dist/settings.js +46 -2
  89. package/dist/settings.js.map +1 -1
  90. package/dist/{switchbot.d.ts → switchbot-ble.d.ts} +14 -8
  91. package/dist/switchbot-ble.d.ts.map +1 -0
  92. package/dist/switchbot-ble.js +428 -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 +96 -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.d.ts.map +1 -0
  127. package/dist/test/woblindtilt.test.js +2 -0
  128. package/dist/test/woblindtilt.test.js.map +1 -0
  129. package/dist/{device → test}/wobulb.test.d.ts.map +1 -1
  130. package/dist/test/wobulb.test.js +2 -0
  131. package/dist/test/wobulb.test.js.map +1 -0
  132. package/dist/test/woceilinglight.test.d.ts.map +1 -0
  133. package/dist/test/woceilinglight.test.js +2 -0
  134. package/dist/test/woceilinglight.test.js.map +1 -0
  135. package/dist/test/wocontact.test.d.ts.map +1 -0
  136. package/dist/test/wocontact.test.js +2 -0
  137. package/dist/test/wocontact.test.js.map +1 -0
  138. package/dist/test/wocurtain.test.d.ts.map +1 -0
  139. package/dist/test/wocurtain.test.js +2 -0
  140. package/dist/test/wocurtain.test.js.map +1 -0
  141. package/dist/{device → test}/wohand.test.d.ts.map +1 -1
  142. package/dist/test/wohand.test.js +2 -0
  143. package/dist/test/wohand.test.js.map +1 -0
  144. package/dist/test/wohub2.test.d.ts +2 -0
  145. package/dist/test/wohub2.test.d.ts.map +1 -0
  146. package/dist/test/wohub2.test.js +2 -0
  147. package/dist/test/wohub2.test.js.map +1 -0
  148. package/dist/{device → test}/wohumi.test.d.ts.map +1 -1
  149. package/dist/test/wohumi.test.js +2 -0
  150. package/dist/test/wohumi.test.js.map +1 -0
  151. package/dist/test/woiosensorth.test.d.ts.map +1 -0
  152. package/dist/test/woiosensorth.test.js +2 -0
  153. package/dist/test/woiosensorth.test.js.map +1 -0
  154. package/dist/test/woplugmini.test.d.ts.map +1 -0
  155. package/dist/test/woplugmini.test.js +2 -0
  156. package/dist/test/woplugmini.test.js.map +1 -0
  157. package/dist/test/wopresence.test.d.ts.map +1 -0
  158. package/dist/test/wopresence.test.js +2 -0
  159. package/dist/test/wopresence.test.js.map +1 -0
  160. package/dist/test/wosensorth.test.d.ts.map +1 -0
  161. package/dist/test/wosensorth.test.js +2 -0
  162. package/dist/test/wosensorth.test.js.map +1 -0
  163. package/dist/test/wosmartlock.test.d.ts.map +1 -0
  164. package/dist/test/wosmartlock.test.js +2 -0
  165. package/dist/test/wosmartlock.test.js.map +1 -0
  166. package/dist/test/wosmartlockpro.test.d.ts.map +1 -0
  167. package/dist/test/wosmartlockpro.test.js +2 -0
  168. package/dist/test/wosmartlockpro.test.js.map +1 -0
  169. package/dist/{device → test}/wostrip.test.d.ts.map +1 -1
  170. package/dist/test/wostrip.test.js +2 -0
  171. package/dist/test/wostrip.test.js.map +1 -0
  172. package/dist/types/bledevicestatus.d.ts +4 -12
  173. package/dist/types/bledevicestatus.d.ts.map +1 -1
  174. package/dist/types/devicelist.d.ts.map +1 -1
  175. package/dist/types/devicelist.js +0 -4
  176. package/dist/types/devicelist.js.map +1 -1
  177. package/dist/types/devicepush.d.ts +13 -0
  178. package/dist/types/devicepush.d.ts.map +1 -0
  179. package/dist/types/devicepush.js +2 -0
  180. package/dist/types/devicepush.js.map +1 -0
  181. package/dist/types/deviceresponse.d.ts +2 -3
  182. package/dist/types/deviceresponse.d.ts.map +1 -1
  183. package/dist/types/devicestatus.d.ts.map +1 -1
  184. package/dist/types/devicewebhookstatus.d.ts +32 -0
  185. package/dist/types/devicewebhookstatus.d.ts.map +1 -1
  186. package/dist/types/irdevicelist.d.ts.map +1 -1
  187. package/dist/types/types.d.ts +61 -120
  188. package/dist/types/types.d.ts.map +1 -1
  189. package/dist/types/types.js +10 -0
  190. package/dist/types/types.js.map +1 -1
  191. package/docs/assets/highlight.css +12 -47
  192. package/docs/assets/main.js +1 -1
  193. package/docs/assets/navigation.js +1 -1
  194. package/docs/assets/search.js +1 -1
  195. package/docs/classes/SwitchBotBLE.html +61 -0
  196. package/docs/classes/SwitchBotOpenAPI.html +47 -0
  197. package/docs/classes/SwitchbotDevice.html +28 -33
  198. package/docs/enums/LogLevel.html +6 -0
  199. package/docs/enums/SwitchBotBLEModel.html +2 -2
  200. package/docs/enums/SwitchBotBLEModelFriendlyName.html +2 -2
  201. package/docs/enums/SwitchBotBLEModelName.html +2 -2
  202. package/docs/enums/SwitchBotModel.html +2 -2
  203. package/docs/hierarchy.html +1 -0
  204. package/docs/index.html +16 -993
  205. package/docs/interfaces/Ad-1.html +5 -0
  206. package/docs/interfaces/AdvertisementData.html +3 -0
  207. package/docs/interfaces/Chars.html +4 -0
  208. package/docs/interfaces/ErrorObject.html +3 -0
  209. package/docs/interfaces/Params.html +6 -0
  210. package/docs/interfaces/ServiceData.html +2 -0
  211. package/docs/interfaces/SwitchBotBLEDevice.html +21 -0
  212. package/docs/interfaces/WebhookDetail.html +6 -0
  213. package/docs/interfaces/ad.html +5 -0
  214. package/docs/interfaces/body.html +3 -0
  215. package/docs/interfaces/bodyChange.html +4 -0
  216. package/docs/interfaces/deleteWebhookResponse.html +4 -0
  217. package/docs/interfaces/device.html +7 -0
  218. package/docs/interfaces/deviceList.html +2 -0
  219. package/docs/interfaces/deviceStatus.html +7 -0
  220. package/docs/interfaces/deviceStatusRequest.html +4 -0
  221. package/docs/interfaces/deviceWebhook.html +4 -0
  222. package/docs/interfaces/deviceWebhookContext.html +4 -0
  223. package/docs/interfaces/devices.html +4 -0
  224. package/docs/interfaces/infraredRemoteList.html +2 -0
  225. package/docs/interfaces/irdevice.html +5 -0
  226. package/docs/interfaces/pushResponse.html +4 -0
  227. package/docs/interfaces/queryWebhookResponse.html +4 -0
  228. package/docs/interfaces/setupWebhookResponse.html +4 -0
  229. package/docs/interfaces/switchbot.html +3 -0
  230. package/docs/interfaces/updateWebhookResponse.html +4 -0
  231. package/docs/interfaces/webhookRequest.html +4 -0
  232. package/docs/media/BLE.md +1109 -0
  233. package/docs/media/OpenAPI.md +172 -0
  234. package/docs/modules.html +136 -3
  235. package/docs/types/MacAddress.html +1 -0
  236. package/docs/types/batteryCirculatorFan.html +1 -0
  237. package/docs/types/batteryCirculatorFanServiceData.html +1 -0
  238. package/docs/types/batteryCirculatorFanStatus.html +1 -0
  239. package/docs/types/batteryCirculatorFanWebhookContext.html +1 -0
  240. package/docs/types/blindTilt.html +1 -0
  241. package/docs/types/blindTiltServiceData.html +1 -0
  242. package/docs/types/blindTiltStatus.html +1 -0
  243. package/docs/types/blindTiltWebhookContext.html +1 -0
  244. package/docs/types/bot.html +1 -0
  245. package/docs/types/botServiceData.html +1 -0
  246. package/docs/types/botStatus.html +1 -0
  247. package/docs/types/botWebhookContext.html +1 -0
  248. package/docs/types/ceilingLight.html +1 -0
  249. package/docs/types/ceilingLightPro.html +1 -0
  250. package/docs/types/ceilingLightProServiceData.html +1 -0
  251. package/docs/types/ceilingLightProStatus.html +1 -0
  252. package/docs/types/ceilingLightProWebhookContext.html +1 -0
  253. package/docs/types/ceilingLightServiceData.html +1 -0
  254. package/docs/types/ceilingLightStatus.html +1 -0
  255. package/docs/types/ceilingLightWebhookContext.html +1 -0
  256. package/docs/types/colorBulb.html +1 -0
  257. package/docs/types/colorBulbServiceData.html +1 -0
  258. package/docs/types/colorBulbStatus.html +1 -0
  259. package/docs/types/colorBulbWebhookContext.html +1 -0
  260. package/docs/types/contactSensor.html +1 -0
  261. package/docs/types/contactSensorServiceData.html +1 -0
  262. package/docs/types/contactSensorStatus.html +1 -0
  263. package/docs/types/contactSensorWebhookContext.html +1 -0
  264. package/docs/types/curtain.html +1 -0
  265. package/docs/types/curtain3.html +1 -0
  266. package/docs/types/curtain3ServiceData.html +1 -0
  267. package/docs/types/curtain3WebhookContext.html +1 -0
  268. package/docs/types/curtainServiceData.html +1 -0
  269. package/docs/types/curtainStatus.html +1 -0
  270. package/docs/types/curtainWebhookContext.html +1 -0
  271. package/docs/types/floorCleaningRobotS10.html +1 -0
  272. package/docs/types/floorCleaningRobotS10Status.html +1 -0
  273. package/docs/types/floorCleaningRobotS10WebhookContext.html +1 -0
  274. package/docs/types/hub2.html +1 -0
  275. package/docs/types/hub2ServiceData.html +1 -0
  276. package/docs/types/hub2Status.html +1 -0
  277. package/docs/types/hub2WebhookContext.html +1 -0
  278. package/docs/types/humidifier.html +1 -0
  279. package/docs/types/humidifierServiceData.html +1 -0
  280. package/docs/types/humidifierStatus.html +1 -0
  281. package/docs/types/humidifierWebhookContext.html +1 -0
  282. package/docs/types/indoorCam.html +1 -0
  283. package/docs/types/indoorCameraWebhookContext.html +1 -0
  284. package/docs/types/keypad.html +1 -0
  285. package/docs/types/keypadTouch.html +1 -0
  286. package/docs/types/keypadTouchWebhookContext.html +1 -0
  287. package/docs/types/keypadWebhookContext.html +1 -0
  288. package/docs/types/lock.html +1 -0
  289. package/docs/types/lockPro.html +1 -0
  290. package/docs/types/lockProServiceData.html +1 -0
  291. package/docs/types/lockProStatus.html +1 -0
  292. package/docs/types/lockProWebhookContext.html +1 -0
  293. package/docs/types/lockServiceData.html +1 -0
  294. package/docs/types/lockStatus.html +1 -0
  295. package/docs/types/lockWebhookContext.html +1 -0
  296. package/docs/types/meter.html +1 -0
  297. package/docs/types/meterPlus.html +1 -0
  298. package/docs/types/meterPlusServiceData.html +1 -0
  299. package/docs/types/meterPlusStatus.html +1 -0
  300. package/docs/types/meterPlusWebhookContext.html +1 -0
  301. package/docs/types/meterServiceData.html +1 -0
  302. package/docs/types/meterStatus.html +1 -0
  303. package/docs/types/meterWebhookContext.html +1 -0
  304. package/docs/types/motionSensor.html +1 -0
  305. package/docs/types/motionSensorServiceData.html +1 -0
  306. package/docs/types/motionSensorStatus.html +1 -0
  307. package/docs/types/motionSensorWebhookContext.html +1 -0
  308. package/docs/types/outdoorMeter.html +1 -0
  309. package/docs/types/outdoorMeterServiceData.html +1 -0
  310. package/docs/types/outdoorMeterStatus.html +1 -0
  311. package/docs/types/outdoorMeterWebhookContext.html +1 -0
  312. package/docs/types/panTiltCamWebhookContext.html +1 -0
  313. package/docs/types/pantiltCam.html +1 -0
  314. package/docs/types/pantiltCam2k.html +1 -0
  315. package/docs/types/plug.html +1 -0
  316. package/docs/types/plugMini.html +1 -0
  317. package/docs/types/plugMiniJPServiceData.html +1 -0
  318. package/docs/types/plugMiniJPWebhookContext.html +1 -0
  319. package/docs/types/plugMiniStatus.html +1 -0
  320. package/docs/types/plugMiniUSServiceData.html +1 -0
  321. package/docs/types/plugMiniUSWebhookContext.html +1 -0
  322. package/docs/types/plugStatus.html +1 -0
  323. package/docs/types/plugWebhookContext.html +1 -0
  324. package/docs/types/remote.html +1 -0
  325. package/docs/types/robotVacuumCleanerS1.html +1 -0
  326. package/docs/types/robotVacuumCleanerS1Plus.html +1 -0
  327. package/docs/types/robotVacuumCleanerS1PlusStatus.html +1 -0
  328. package/docs/types/robotVacuumCleanerS1PlusWebhookContext.html +1 -0
  329. package/docs/types/robotVacuumCleanerS1Status.html +1 -0
  330. package/docs/types/robotVacuumCleanerS1WebhookContext.html +1 -0
  331. package/docs/types/robotVacuumCleanerServiceData.html +1 -0
  332. package/docs/types/stripLight.html +1 -0
  333. package/docs/types/stripLightServiceData.html +1 -0
  334. package/docs/types/stripLightStatus.html +1 -0
  335. package/docs/types/stripLightWebhookContext.html +1 -0
  336. package/docs/types/waterLeakDetector.html +1 -0
  337. package/docs/types/waterLeakDetectorServiceData.html +1 -0
  338. package/docs/types/waterLeakDetectorStatus.html +1 -0
  339. package/docs/types/waterLeakDetectorWebhookContext.html +1 -0
  340. package/package.json +12 -10
  341. package/dist/device/woblindtilt.test.d.ts.map +0 -1
  342. package/dist/device/woblindtilt.test.js +0 -26
  343. package/dist/device/woblindtilt.test.js.map +0 -1
  344. package/dist/device/wobulb.test.js +0 -52
  345. package/dist/device/wobulb.test.js.map +0 -1
  346. package/dist/device/woceilinglight.test.d.ts.map +0 -1
  347. package/dist/device/woceilinglight.test.js +0 -63
  348. package/dist/device/woceilinglight.test.js.map +0 -1
  349. package/dist/device/wocontact.test.d.ts.map +0 -1
  350. package/dist/device/wocontact.test.js +0 -34
  351. package/dist/device/wocontact.test.js.map +0 -1
  352. package/dist/device/wocurtain.test.d.ts.map +0 -1
  353. package/dist/device/wocurtain.test.js +0 -33
  354. package/dist/device/wocurtain.test.js.map +0 -1
  355. package/dist/device/wohand.test.js +0 -62
  356. package/dist/device/wohand.test.js.map +0 -1
  357. package/dist/device/wohand2.test.d.ts +0 -2
  358. package/dist/device/wohand2.test.d.ts.map +0 -1
  359. package/dist/device/wohand2.test.js +0 -50
  360. package/dist/device/wohand2.test.js.map +0 -1
  361. package/dist/device/wohumi.test.js +0 -61
  362. package/dist/device/wohumi.test.js.map +0 -1
  363. package/dist/device/woiosensorth.test.d.ts.map +0 -1
  364. package/dist/device/woiosensorth.test.js +0 -39
  365. package/dist/device/woiosensorth.test.js.map +0 -1
  366. package/dist/device/woplugmini.test.d.ts.map +0 -1
  367. package/dist/device/woplugmini.test.js +0 -91
  368. package/dist/device/woplugmini.test.js.map +0 -1
  369. package/dist/device/wopresence.test.d.ts.map +0 -1
  370. package/dist/device/wopresence.test.js +0 -42
  371. package/dist/device/wopresence.test.js.map +0 -1
  372. package/dist/device/wosensorth.test.d.ts.map +0 -1
  373. package/dist/device/wosensorth.test.js +0 -59
  374. package/dist/device/wosensorth.test.js.map +0 -1
  375. package/dist/device/wosmartlock.test.d.ts.map +0 -1
  376. package/dist/device/wosmartlock.test.js +0 -84
  377. package/dist/device/wosmartlock.test.js.map +0 -1
  378. package/dist/device/wosmartlockpro.test.d.ts.map +0 -1
  379. package/dist/device/wosmartlockpro.test.js +0 -124
  380. package/dist/device/wosmartlockpro.test.js.map +0 -1
  381. package/dist/device/wostrip.test.js +0 -115
  382. package/dist/device/wostrip.test.js.map +0 -1
  383. package/dist/switchbot.d.ts.map +0 -1
  384. package/dist/switchbot.js +0 -259
  385. package/dist/switchbot.js.map +0 -1
  386. package/dist/types/pushbody.d.ts +0 -6
  387. package/dist/types/pushbody.d.ts.map +0 -1
  388. package/dist/types/pushbody.js +0 -2
  389. package/dist/types/pushbody.js.map +0 -1
  390. package/docs/classes/SwitchBot.html +0 -16
  391. package/docs/types/SwitchBotBLEDevice.html +0 -1
  392. /package/dist/{device → test}/woblindtilt.test.d.ts +0 -0
  393. /package/dist/{device → test}/wobulb.test.d.ts +0 -0
  394. /package/dist/{device → test}/woceilinglight.test.d.ts +0 -0
  395. /package/dist/{device → test}/wocontact.test.d.ts +0 -0
  396. /package/dist/{device → test}/wocurtain.test.d.ts +0 -0
  397. /package/dist/{device → test}/wohand.test.d.ts +0 -0
  398. /package/dist/{device → test}/wohumi.test.d.ts +0 -0
  399. /package/dist/{device → test}/woiosensorth.test.d.ts +0 -0
  400. /package/dist/{device → test}/woplugmini.test.d.ts +0 -0
  401. /package/dist/{device → test}/wopresence.test.d.ts +0 -0
  402. /package/dist/{device → test}/wosensorth.test.d.ts +0 -0
  403. /package/dist/{device → test}/wosmartlock.test.d.ts +0 -0
  404. /package/dist/{device → test}/wosmartlockpro.test.d.ts +0 -0
  405. /package/dist/{device → test}/wostrip.test.d.ts +0 -0
@@ -1,130 +1,102 @@
1
1
  import { Buffer } from 'node:buffer';
2
- /* Copyright(C) 2024, donavanbecker (https://github.com/donavanbecker). All rights reserved.
3
- *
4
- * woblindtilt.ts: Switchbot BLE API registration.
5
- */
6
2
  import { SwitchbotDevice } from '../device.js';
7
3
  import { SwitchBotBLEModel, SwitchBotBLEModelFriendlyName, SwitchBotBLEModelName } from '../types/types.js';
4
+ /**
5
+ * Class representing a WoBlindTilt device.
6
+ * @see https://github.com/OpenWonderLabs/SwitchBotAPI-BLE/blob/latest/devicetypes/curtain.md
7
+ */
8
8
  export class WoBlindTilt extends SwitchbotDevice {
9
9
  _reverse = false;
10
+ static switchBotBLE;
10
11
  /**
11
12
  * Parses the service data and manufacturer data for the WoBlindTilt device.
12
- *
13
13
  * @param {Buffer} serviceData - The service data buffer.
14
14
  * @param {Buffer} manufacturerData - The manufacturer data buffer.
15
- * @param {(message: string) => void} [onlog] - Optional logging function.
16
15
  * @param {boolean} [reverse] - Whether to reverse the tilt percentage.
17
- * @returns {object | null} The parsed data object or null if the data is invalid.
16
+ * @returns {Promise<object | null>} - The parsed data object or null if the data is invalid.
18
17
  */
19
- static async parseServiceData(serviceData, manufacturerData, onlog, reverse = false) {
20
- if (manufacturerData.length !== 5 && manufacturerData.length !== 6) {
21
- if (onlog && typeof onlog === 'function') {
22
- onlog(`[parseServiceDataForWoBlindTilt] Buffer length ${manufacturerData.length} !== 5 or 6!`);
23
- }
18
+ static async parseServiceData(serviceData, manufacturerData, reverse = false) {
19
+ if (![5, 6].includes(manufacturerData.length)) {
20
+ this.switchBotBLE.emitLog('error', `[parseServiceDataForWoBlindTilt] Buffer length ${manufacturerData.length} !== 5 or 6!`);
24
21
  return null;
25
22
  }
26
- // const byte1 = serviceData.readUInt8(1)
27
23
  const byte2 = serviceData.readUInt8(2);
28
24
  const byte6 = manufacturerData.subarray(6);
29
- const tilt = Math.max(Math.min(byte6.readUInt8(2) & 0b01111111, 100), 0); // current tilt % (100 - _tilt) if reverse else _tilt,
25
+ const tilt = Math.max(Math.min(byte6.readUInt8(2) & 0b01111111, 100), 0);
30
26
  const inMotion = !!(byte2 & 0b10000000);
31
- const lightLevel = (byte6.readUInt8(1) >> 4) & 0b00001111; // light sensor level (1-10)
32
- const calibration = !!(byte6.readUInt8(1) & 0b00000001); // Whether the calibration is completed
27
+ const lightLevel = (byte6.readUInt8(1) >> 4) & 0b00001111;
28
+ const calibration = !!(byte6.readUInt8(1) & 0b00000001);
33
29
  const sequenceNumber = byte6.readUInt8(0);
34
30
  const battery = serviceData.length > 2 ? byte2 & 0b01111111 : null;
35
- const data = {
31
+ return {
36
32
  model: SwitchBotBLEModel.BlindTilt,
37
33
  modelName: SwitchBotBLEModelName.BlindTilt,
38
34
  modelFriendlyName: SwitchBotBLEModelFriendlyName.BlindTilt,
39
35
  calibration,
40
36
  battery,
41
37
  inMotion,
42
- tilt: reverse ? (100 - tilt) : tilt,
38
+ tilt: reverse ? 100 - tilt : tilt,
43
39
  lightLevel,
44
40
  sequenceNumber,
45
41
  };
46
- return data;
47
42
  }
48
43
  /**
49
- * open
50
- *
51
44
  * Opens the blind tilt to the fully open position.
52
- *
53
- * @returns {Promise<void>} - A promise that resolves when the operation is complete. Nothing will be passed to the `resolve()`.
45
+ * @returns {Promise<void>}
54
46
  */
55
47
  async open() {
56
- return await this.operateBlindTilt([0x57, 0x0F, 0x45, 0x01, 0x05, 0xFF, 0x32]);
48
+ await this.operateBlindTilt([0x57, 0x0F, 0x45, 0x01, 0x05, 0xFF, 0x32]);
57
49
  }
58
50
  /**
59
- * closeUp
60
- *
61
51
  * Closes the blind tilt up to the nearest endpoint.
62
- *
63
- * @returns {Promise<void>} - A promise that resolves when the operation is complete. Nothing will be passed to the `resolve()`.
52
+ * @returns {Promise<void>}
64
53
  */
65
54
  async closeUp() {
66
- return await this.operateBlindTilt([0x57, 0x0F, 0x45, 0x01, 0x05, 0xFF, 0x64]);
55
+ await this.operateBlindTilt([0x57, 0x0F, 0x45, 0x01, 0x05, 0xFF, 0x64]);
67
56
  }
68
57
  /**
69
- * closeDown
70
- *
71
58
  * Closes the blind tilt down to the nearest endpoint.
72
- *
73
- * @returns {Promise<void>} - A promise that resolves when the operation is complete. Nothing will be passed to the `resolve()`.
59
+ * @returns {Promise<void>}
74
60
  */
75
61
  async closeDown() {
76
- return await this.operateBlindTilt([0x57, 0x0F, 0x45, 0x01, 0x05, 0xFF, 0x00]);
62
+ await this.operateBlindTilt([0x57, 0x0F, 0x45, 0x01, 0x05, 0xFF, 0x00]);
77
63
  }
78
64
  /**
79
- * close
80
- *
81
65
  * Closes the blind tilt to the nearest endpoint.
82
- *
83
- * @returns {Promise<void>} - A promise that resolves when the operation is complete. Nothing will be passed to the `resolve()`.
66
+ * @returns {Promise<void>}
84
67
  */
85
68
  async close() {
86
69
  const position = await this.getPosition();
87
70
  if (position > 50) {
88
- return await this.closeUp();
71
+ await this.closeUp();
89
72
  }
90
73
  else {
91
- return await this.closeDown();
74
+ await this.closeDown();
92
75
  }
93
76
  }
94
77
  /**
95
- * getPosition
96
- *
97
78
  * Retrieves the current position of the blind tilt.
98
- *
99
- * @returns {number} - The current position of the blind tilt (0-100).
79
+ * @returns {Promise<number>} - The current position of the blind tilt (0-100).
100
80
  */
101
81
  async getPosition() {
102
- // Retrieve the current tilt position using the _getAdvValue method
103
82
  const tiltPosition = await this._getAdvValue('tilt');
104
- // Ensure the tilt position is within the valid range (0-100)
105
83
  return Math.max(0, Math.min(tiltPosition, 100));
106
84
  }
107
85
  /**
108
- * _getAdvValue
109
- *
110
86
  * Retrieves the advertised value for a given key.
111
- *
112
87
  * @param {string} key - The key for the advertised value.
113
88
  * @returns {Promise<number>} - The advertised value.
89
+ * @private
114
90
  */
115
91
  async _getAdvValue(key) {
116
- // Mock implementation, replace with actual logic to retrieve the advertised value
117
92
  if (key === 'tilt') {
118
93
  return 50; // Example value
119
94
  }
120
95
  throw new Error(`Unknown key: ${key}`);
121
96
  }
122
97
  /**
123
- * getBasicInfo
124
- *
125
98
  * Retrieves the basic information of the blind tilt.
126
- *
127
- * @returns {Promise<object>} - A promise that resolves to an object containing the basic information of the blind tilt.
99
+ * @returns {Promise<object | null>} - A promise that resolves to an object containing the basic information of the blind tilt.
128
100
  */
129
101
  async getBasicInfo() {
130
102
  const data = await this.getBasicInfo();
@@ -168,73 +140,38 @@ export class WoBlindTilt extends SwitchbotDevice {
168
140
  }
169
141
  /**
170
142
  * Pauses the blind tilt operation.
171
- *
172
- * This method sends a command to pause the current operation of the blind tilt.
173
- *
174
- * @returns {Promise<void>} A promise that resolves when the operation is complete.
175
- * No value is passed to the `resolve()` function.
143
+ * @returns {Promise<void>}
176
144
  */
177
145
  async pause() {
178
146
  await this.operateBlindTilt([0x57, 0x0F, 0x45, 0x01, 0x00, 0xFF]);
179
147
  }
180
148
  /**
181
- * runToPos the blind tilt operation.
182
- *
183
- * This method sends a command to run the blind tilt to the specified position.
184
- *
149
+ * Runs the blind tilt to the specified position.
185
150
  * @param {number} percent - The target position percentage (0-100).
186
151
  * @param {number} mode - The running mode (0 or 1).
187
- * @returns {Promise<void>} - A promise that resolves when the operation is complete.
152
+ * @returns {Promise<void>}
188
153
  */
189
154
  async runToPos(percent, mode) {
190
- if (typeof percent !== 'number') {
191
- throw new TypeError(`The type of target position percentage is incorrect: ${typeof percent}`);
192
- }
193
- if (mode === null) {
194
- mode = 0xFF;
195
- }
196
- else {
197
- if (typeof mode !== 'number') {
198
- throw new TypeError(`The type of running mode is incorrect: ${typeof mode}`);
199
- }
200
- if (mode > 1) {
201
- mode = 0xFF;
202
- }
155
+ if (typeof percent !== 'number' || percent < 0 || percent > 100) {
156
+ throw new RangeError('Percent must be a number between 0 and 100');
203
157
  }
204
- if (percent > 100) {
205
- percent = 100;
206
- }
207
- else if (percent < 0) {
208
- percent = 0;
158
+ if (typeof mode !== 'number' || mode < 0 || mode > 1) {
159
+ throw new RangeError('Mode must be a number between 0 and 1');
209
160
  }
210
161
  await this.operateBlindTilt([0x57, 0x0F, 0x45, 0x01, 0x05, mode, percent]);
211
162
  }
212
163
  /**
213
164
  * Sends a command to operate the blind tilt and handles the response.
214
- *
215
- * This method constructs a buffer from the provided byte array and sends it as a command to the device.
216
- * It returns a promise that resolves if the device responds with a success code (0x01) and rejects if the device
217
- * returns an error or if the command fails.
218
- *
219
165
  * @param {number[]} bytes - The byte array representing the command to be sent to the device.
220
- * @returns {Promise<void>} A promise that resolves when the command is successfully executed or rejects with an
221
- * error if the command fails.
222
- *
223
- * @throws {Error} Throws an error if the device returns an error code or if the command fails.
166
+ * @returns {Promise<void>}
167
+ * @private
224
168
  */
225
169
  async operateBlindTilt(bytes) {
226
- const req_buf = Buffer.from(bytes);
227
- this.command(req_buf).then((res_buf) => {
228
- const code = res_buf.readUInt8(0);
229
- if (res_buf.length === 3 && code === 0x01) {
230
- // Success: No action needed
231
- }
232
- else {
233
- throw new Error(`The device returned an error: 0x${res_buf.toString('hex')}`);
234
- }
235
- }).catch((error) => {
236
- throw error;
237
- });
170
+ const reqBuf = Buffer.from(bytes);
171
+ const resBuf = await this.command(reqBuf);
172
+ if (resBuf.length !== 3 || resBuf.readUInt8(0) !== 0x01) {
173
+ throw new Error(`The device returned an error: 0x${resBuf.toString('hex')}`);
174
+ }
238
175
  }
239
176
  }
240
177
  //# sourceMappingURL=woblindtilt.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"woblindtilt.js","sourceRoot":"","sources":["../../src/device/woblindtilt.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AAEpC;;;GAGG;AACH,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAA;AAC9C,OAAO,EAAE,iBAAiB,EAAE,6BAA6B,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAA;AAE3G,MAAM,OAAO,WAAY,SAAQ,eAAe;IACtC,QAAQ,GAAY,KAAK,CAAA;IACjC;;;;;;;;OAQG;IACH,MAAM,CAAC,KAAK,CAAC,gBAAgB,CAC3B,WAAmB,EACnB,gBAAwB,EACxB,KAA8C,EAC9C,UAAmB,KAAK;QAExB,IAAI,gBAAgB,CAAC,MAAM,KAAK,CAAC,IAAI,gBAAgB,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YACnE,IAAI,KAAK,IAAI,OAAO,KAAK,KAAK,UAAU,EAAE,CAAC;gBACzC,KAAK,CAAC,kDAAkD,gBAAgB,CAAC,MAAM,cAAc,CAAC,CAAA;YAChG,CAAC;YACD,OAAO,IAAI,CAAA;QACb,CAAC;QAED,yCAAyC;QACzC,MAAM,KAAK,GAAG,WAAW,CAAC,SAAS,CAAC,CAAC,CAAC,CAAA;QACtC,MAAM,KAAK,GAAG,gBAAgB,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAA;QAE1C,MAAM,IAAI,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,CAAC,GAAG,UAAU,EAAE,GAAG,CAAC,EAAE,CAAC,CAAC,CAAA,CAAC,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G,EAAE,CAAC;YAChE,MAAM,IAAI,UAAU,CAAC,4CAA4C,CAAC,CAAA;QACpE,CAAC;QACD,IAAI,OAAO,IAAI,KAAK,QAAQ,IAAI,IAAI,GAAG,CAAC,IAAI,IAAI,GAAG,CAAC,EAAE,CAAC;YACrD,MAAM,IAAI,UAAU,CAAC,uCAAuC,CAAC,CAAA;QAC/D,CAAC;QACD,MAAM,IAAI,CAAC,gBAAgB,CAAC,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC,CAAA;IAC5E,CAAC;IAED;;;;;OAKG;IACK,KAAK,CAAC,gBAAgB,CAAC,KAAe;QAC5C,MAAM,MAAM,GAAG,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;QACjC,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,CAAA;QACzC,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC,IAAI,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC,KAAK,IAAI,EAAE,CAAC;YACxD,MAAM,IAAI,KAAK,CAAC,mCAAmC,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC,CAAA;QAC9E,CAAC;IACH,CAAC;CACF"}
@@ -1,41 +1,68 @@
1
+ import type { SwitchBotBLE } from '../switchbot-ble.js';
1
2
  import { Buffer } from 'node:buffer';
2
3
  import { SwitchbotDevice } from '../device.js';
3
4
  /**
5
+ * Class representing a WoBulb device.
4
6
  * @see https://github.com/OpenWonderLabs/SwitchBotAPI-BLE/blob/latest/devicetypes/colorbulb.md
5
7
  */
6
8
  export declare class WoBulb extends SwitchbotDevice {
7
- static parseServiceData(serviceData: Buffer, manufacturerData: Buffer, onlog: ((message: string) => void) | undefined): Promise<object | null>;
9
+ static switchBotBLE: SwitchBotBLE;
8
10
  /**
9
- * @returns resolves with a boolean that tells whether the plug in ON(true) or OFF(false)
11
+ * Parses the service data for WoBulb.
12
+ * @param {Buffer} serviceData - The service data buffer.
13
+ * @param {Buffer} manufacturerData - The manufacturer data buffer.
14
+ * @returns {Promise<object | null>} - Parsed service data or null if invalid.
10
15
  */
11
- readState(): Promise<void>;
16
+ static parseServiceData(serviceData: Buffer, manufacturerData: Buffer): Promise<object | null>;
12
17
  /**
18
+ * Reads the state of the bulb.
19
+ * @returns {Promise<boolean>} - Resolves with a boolean indicating whether the bulb is ON (true) or OFF (false).
20
+ */
21
+ readState(): Promise<boolean>;
22
+ /**
23
+ * Sets the state of the bulb.
24
+ * @param {number[]} reqByteArray - The request byte array.
25
+ * @returns {Promise<boolean>} - Resolves with a boolean indicating whether the operation was successful.
13
26
  * @private
14
27
  */
15
- setState(reqByteArray: number[]): Promise<void>;
28
+ setState(reqByteArray: number[]): Promise<boolean>;
16
29
  /**
17
- * @returns resolves with a boolean that tells whether the plug in ON(true) or OFF(false)
30
+ * Turns on the bulb.
31
+ * @returns {Promise<boolean>} - Resolves with a boolean indicating whether the bulb is ON (true).
18
32
  */
19
- turnOn(): Promise<void>;
33
+ turnOn(): Promise<boolean>;
20
34
  /**
21
- * @returns resolves with a boolean that tells whether the plug in ON(true) or OFF(false)
35
+ * Turns off the bulb.
36
+ * @returns {Promise<boolean>} - Resolves with a boolean indicating whether the bulb is OFF (false).
22
37
  */
23
- turnOff(): Promise<void>;
38
+ turnOff(): Promise<boolean>;
24
39
  /**
25
- * @returns resolves with brightness percent
40
+ * Sets the brightness of the bulb.
41
+ * @param {number} brightness - The brightness percentage (0-100).
42
+ * @returns {Promise<boolean>} - Resolves with a boolean indicating whether the operation was successful.
26
43
  */
27
- setBrightness(brightness: number): Promise<void>;
44
+ setBrightness(brightness: number): Promise<boolean>;
28
45
  /**
29
- * @returns resolves with color_temperature percent
46
+ * Sets the color temperature of the bulb.
47
+ * @param {number} color_temperature - The color temperature percentage (0-100).
48
+ * @returns {Promise<boolean>} - Resolves with a boolean indicating whether the operation was successful.
30
49
  */
31
- setColorTemperature(color_temperature: number): Promise<void>;
50
+ setColorTemperature(color_temperature: number): Promise<boolean>;
32
51
  /**
33
- * @returns resolves with brightness percent
52
+ * Sets the RGB color of the bulb.
53
+ * @param {number} brightness - The brightness percentage (0-100).
54
+ * @param {number} red - The red color value (0-255).
55
+ * @param {number} green - The green color value (0-255).
56
+ * @param {number} blue - The blue color value (0-255).
57
+ * @returns {Promise<boolean>} - Resolves with a boolean indicating whether the operation was successful.
34
58
  */
35
- setRGB(brightness: number, red: number, green: number, blue: number): Promise<void>;
59
+ setRGB(brightness: number, red: number, green: number, blue: number): Promise<boolean>;
36
60
  /**
61
+ * Sends a command to the bulb.
62
+ * @param {number[]} bytes - The command bytes.
63
+ * @returns {Promise<boolean>} - Resolves with a boolean indicating whether the operation was successful.
37
64
  * @private
38
65
  */
39
- operateBulb(bytes: number[]): Promise<void>;
66
+ private operateBulb;
40
67
  }
41
68
  //# sourceMappingURL=wobulb.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"wobulb.d.ts","sourceRoot":"","sources":["../../src/device/wobulb.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AAMpC,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAA;AAG9C;;GAEG;AACH,qBAAa,MAAO,SAAQ,eAAe;WAC5B,gBAAgB,CAC3B,WAAW,EAAE,MAAM,EACnB,gBAAgB,EAAE,MAAM,EACxB,KAAK,EAAE,CAAC,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC,GAAG,SAAS,GAC7C,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;IA0DzB;;OAEG;IACG,SAAS;IAIf;;OAEG;IACG,QAAQ,CAAC,YAAY,EAAE,MAAM,EAAE;IAKrC;;OAEG;IACG,MAAM;IAIZ;;OAEG;IACG,OAAO;IAIb;;OAEG;IACG,aAAa,CAAC,UAAU,EAAE,MAAM;IAYtC;;OAEG;IACG,mBAAmB,CAAC,iBA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AC;IAO5F;;;;;OAKG;YACW,WAAW;CAY1B"}
@@ -1,190 +1,130 @@
1
1
  import { Buffer } from 'node:buffer';
2
- /* Copyright(C) 2024, donavanbecker (https://github.com/donavanbecker). All rights reserved.
3
- *
4
- * wobulb.ts: Switchbot BLE API registration.
5
- */
6
2
  import { SwitchbotDevice } from '../device.js';
7
3
  import { SwitchBotBLEModel, SwitchBotBLEModelFriendlyName, SwitchBotBLEModelName } from '../types/types.js';
8
4
  /**
5
+ * Class representing a WoBulb device.
9
6
  * @see https://github.com/OpenWonderLabs/SwitchBotAPI-BLE/blob/latest/devicetypes/colorbulb.md
10
7
  */
11
8
  export class WoBulb extends SwitchbotDevice {
12
- static async parseServiceData(serviceData, manufacturerData, onlog) {
9
+ static switchBotBLE;
10
+ /**
11
+ * Parses the service data for WoBulb.
12
+ * @param {Buffer} serviceData - The service data buffer.
13
+ * @param {Buffer} manufacturerData - The manufacturer data buffer.
14
+ * @returns {Promise<object | null>} - Parsed service data or null if invalid.
15
+ */
16
+ static async parseServiceData(serviceData, manufacturerData) {
13
17
  if (serviceData.length !== 18) {
14
- if (onlog && typeof onlog === 'function') {
15
- onlog(`[parseServiceDataForWoBulb] Buffer length ${serviceData.length} !== 18!`);
16
- }
18
+ this.switchBotBLE.emitLog('error', `[parseServiceDataForWoBulb] Buffer length ${serviceData.length} !== 18!`);
17
19
  return null;
18
20
  }
19
21
  if (manufacturerData.length !== 13) {
20
- if (onlog && typeof onlog === 'function') {
21
- onlog(`[parseServiceDataForWoBulb] Buffer length ${manufacturerData.length} !== 13!`);
22
- }
22
+ this.switchBotBLE.emitLog('error', `[parseServiceDataForWoBulb] Buffer length ${manufacturerData.length} !== 13!`);
23
23
  return null;
24
24
  }
25
- const byte1 = manufacturerData.readUInt8(1); // power and light status
26
- // const byte2 = manufacturerData.readUInt8(2);//bulb brightness
27
- const byte3 = manufacturerData.readUInt8(3); // bulb R
28
- const byte4 = manufacturerData.readUInt8(4); // bulb G
29
- const byte5 = manufacturerData.readUInt8(5); // bulb B
30
- const byte6 = manufacturerData.readUInt8(6); // bulb temperature
31
- const byte7 = manufacturerData.readUInt8(7);
32
- const byte8 = manufacturerData.readUInt8(8);
33
- const byte9 = manufacturerData.readUInt8(9);
34
- const byte10 = manufacturerData.readUInt8(10); // bulb mode
35
- const power = byte1;
36
- const red = byte3;
37
- const green = byte4;
38
- const blue = byte5;
39
- const color_temperature = byte6;
40
- const state = !!(byte7 & 0b01111111);
41
- const brightness = byte7 & 0b01111111;
42
- const delay = byte8 & 0b10000000;
43
- const preset = byte8 & 0b00001000;
44
- const color_mode = byte8 & 0b00000111;
45
- const speed = byte9 & 0b01111111;
46
- const loop_index = byte10 & 0b11111110;
47
- const data = {
25
+ const [, byte1, , byte3, byte4, byte5, byte6, byte7, byte8, byte9, byte10,] = manufacturerData;
26
+ return {
48
27
  model: SwitchBotBLEModel.ColorBulb,
49
28
  modelName: SwitchBotBLEModelName.ColorBulb,
50
29
  modelFriendlyName: SwitchBotBLEModelFriendlyName.ColorBulb,
51
- color_temperature,
52
- power,
53
- state,
54
- red,
55
- green,
56
- blue,
57
- brightness,
58
- delay,
59
- preset,
60
- color_mode,
61
- speed,
62
- loop_index,
30
+ power: byte1,
31
+ red: byte3,
32
+ green: byte4,
33
+ blue: byte5,
34
+ color_temperature: byte6,
35
+ state: !!(byte7 & 0b01111111),
36
+ brightness: byte7 & 0b01111111,
37
+ delay: !!(byte8 & 0b10000000),
38
+ preset: !!(byte8 & 0b00001000),
39
+ color_mode: byte8 & 0b00000111,
40
+ speed: byte9 & 0b01111111,
41
+ loop_index: byte10 & 0b11111110,
63
42
  };
64
- return data;
65
43
  }
66
44
  /**
67
- * @returns resolves with a boolean that tells whether the plug in ON(true) or OFF(false)
45
+ * Reads the state of the bulb.
46
+ * @returns {Promise<boolean>} - Resolves with a boolean indicating whether the bulb is ON (true) or OFF (false).
68
47
  */
69
48
  async readState() {
70
- return await this.operateBulb([0x57, 0x0F, 0x48, 0x01]);
49
+ return this.operateBulb([0x57, 0x0F, 0x48, 0x01]);
71
50
  }
72
51
  /**
52
+ * Sets the state of the bulb.
53
+ * @param {number[]} reqByteArray - The request byte array.
54
+ * @returns {Promise<boolean>} - Resolves with a boolean indicating whether the operation was successful.
73
55
  * @private
74
56
  */
75
57
  async setState(reqByteArray) {
76
58
  const base = [0x57, 0x0F, 0x47, 0x01];
77
- return await this.operateBulb(base.concat(reqByteArray));
59
+ return this.operateBulb(base.concat(reqByteArray));
78
60
  }
79
61
  /**
80
- * @returns resolves with a boolean that tells whether the plug in ON(true) or OFF(false)
62
+ * Turns on the bulb.
63
+ * @returns {Promise<boolean>} - Resolves with a boolean indicating whether the bulb is ON (true).
81
64
  */
82
65
  async turnOn() {
83
- return await this.setState([0x01, 0x01]);
66
+ return this.setState([0x01, 0x01]);
84
67
  }
85
68
  /**
86
- * @returns resolves with a boolean that tells whether the plug in ON(true) or OFF(false)
69
+ * Turns off the bulb.
70
+ * @returns {Promise<boolean>} - Resolves with a boolean indicating whether the bulb is OFF (false).
87
71
  */
88
72
  async turnOff() {
89
- return await this.setState([0x01, 0x02]);
73
+ return this.setState([0x01, 0x02]);
90
74
  }
91
75
  /**
92
- * @returns resolves with brightness percent
76
+ * Sets the brightness of the bulb.
77
+ * @param {number} brightness - The brightness percentage (0-100).
78
+ * @returns {Promise<boolean>} - Resolves with a boolean indicating whether the operation was successful.
93
79
  */
94
80
  async setBrightness(brightness) {
95
- if (typeof brightness !== 'number') {
96
- throw new TypeError(`The type of target brightness percentage is incorrect: ${typeof brightness}`);
97
- }
98
- if (brightness > 100) {
99
- brightness = 100;
81
+ if (brightness < 0 || brightness > 100) {
82
+ throw new RangeError('Brightness must be between 0 and 100');
100
83
  }
101
- else if (brightness < 0) {
102
- brightness = 0;
103
- }
104
- return await this.setState([0x02, 0x14, brightness]);
84
+ return this.setState([0x02, 0x14, brightness]);
105
85
  }
106
86
  /**
107
- * @returns resolves with color_temperature percent
87
+ * Sets the color temperature of the bulb.
88
+ * @param {number} color_temperature - The color temperature percentage (0-100).
89
+ * @returns {Promise<boolean>} - Resolves with a boolean indicating whether the operation was successful.
108
90
  */
109
91
  async setColorTemperature(color_temperature) {
110
- if (typeof color_temperature !== 'number') {
111
- throw new TypeError(`The type of target color_temperature percentage is incorrect: ${typeof color_temperature}`);
112
- }
113
- else if (color_temperature > 100) {
114
- color_temperature = 100;
115
- }
116
- else if (color_temperature < 0) {
117
- color_temperature = 0;
92
+ if (color_temperature < 0 || color_temperature > 100) {
93
+ throw new RangeError('Color temperature must be between 0 and 100');
118
94
  }
119
- return await this.setState([0x02, 0x17, color_temperature]);
95
+ return this.setState([0x02, 0x17, color_temperature]);
120
96
  }
121
97
  /**
122
- * @returns resolves with brightness percent
98
+ * Sets the RGB color of the bulb.
99
+ * @param {number} brightness - The brightness percentage (0-100).
100
+ * @param {number} red - The red color value (0-255).
101
+ * @param {number} green - The green color value (0-255).
102
+ * @param {number} blue - The blue color value (0-255).
103
+ * @returns {Promise<boolean>} - Resolves with a boolean indicating whether the operation was successful.
123
104
  */
124
105
  async setRGB(brightness, red, green, blue) {
125
- if (typeof brightness !== 'number') {
126
- throw new TypeError(`The type of target brightness percentage is incorrect: ${typeof brightness}`);
127
- }
128
- if (typeof red !== 'number') {
129
- throw new TypeError(`The type of target red is incorrect: ${typeof red}`);
130
- }
131
- if (typeof green !== 'number') {
132
- throw new TypeError(`The type of target green is incorrect: ${typeof green}`);
106
+ if (brightness < 0 || brightness > 100 || red < 0 || red > 255 || green < 0 || green > 255 || blue < 0 || blue > 255) {
107
+ throw new RangeError('Invalid RGB or brightness values');
133
108
  }
134
- if (typeof blue !== 'number') {
135
- throw new TypeError(`The type of target blue is incorrect: ${typeof blue}`);
136
- }
137
- if (brightness > 100) {
138
- brightness = 100;
139
- }
140
- else if (brightness < 0) {
141
- brightness = 0;
142
- }
143
- if (red > 255) {
144
- red = 255;
145
- }
146
- else if (red < 0) {
147
- red = 0;
148
- }
149
- if (green > 255) {
150
- green = 255;
151
- }
152
- else if (green < 0) {
153
- green = 0;
154
- }
155
- if (blue > 255) {
156
- blue = 255;
157
- }
158
- else if (blue < 0) {
159
- blue = 0;
160
- }
161
- return await this.setState([0x02, 0x12, brightness, red, green, blue]);
109
+ return this.setState([0x02, 0x12, brightness, red, green, blue]);
162
110
  }
163
111
  /**
112
+ * Sends a command to the bulb.
113
+ * @param {number[]} bytes - The command bytes.
114
+ * @returns {Promise<boolean>} - Resolves with a boolean indicating whether the operation was successful.
164
115
  * @private
165
116
  */
166
117
  async operateBulb(bytes) {
167
- const req_buf = Buffer.from(bytes);
168
- await this.command(req_buf)
169
- .then((res_bytes) => {
170
- const res_buf = Buffer.from(res_bytes);
171
- if (res_buf.length === 2) {
172
- const code = res_buf.readUInt8(1);
173
- if (code === 0x00 || code === 0x80) {
174
- const is_on = code === 0x80;
175
- return is_on;
176
- }
177
- else {
178
- throw new Error(`The device returned an error: 0x${res_buf.toString('hex')}`);
179
- }
118
+ const reqBuf = Buffer.from(bytes);
119
+ const resBuf = await this.command(reqBuf);
120
+ if (resBuf.length === 2) {
121
+ const code = resBuf.readUInt8(1);
122
+ if (code === 0x00 || code === 0x80) {
123
+ return code === 0x80;
180
124
  }
181
- else {
182
- throw new Error(`Expecting a 2-byte response, got instead: 0x${res_buf.toString('hex')}`);
183
- }
184
- })
185
- .catch((error) => {
186
- throw error;
187
- });
125
+ throw new Error(`The device returned an error: 0x${resBuf.toString('hex')}`);
126
+ }
127
+ throw new Error(`Expecting a 2-byte response, got instead: 0x${resBuf.toString('hex')}`);
188
128
  }
189
129
  }
190
130
  //# sourceMappingURL=wobulb.js.map