node-switchbot 3.6.5 → 4.0.0-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (548) hide show
  1. package/.github/npm-version-script-esm.js +97 -0
  2. package/CHANGELOG.md +586 -0
  3. package/PRODUCTION_READY.md +135 -0
  4. package/README.md +92 -0
  5. package/dist/api.d.ts +130 -0
  6. package/dist/api.d.ts.map +1 -0
  7. package/dist/api.js +286 -0
  8. package/dist/api.js.map +1 -0
  9. package/dist/ble.d.ts +116 -0
  10. package/dist/ble.d.ts.map +1 -0
  11. package/dist/ble.js +430 -0
  12. package/dist/ble.js.map +1 -0
  13. package/dist/devices/base.d.ts +146 -0
  14. package/dist/devices/base.d.ts.map +1 -0
  15. package/dist/devices/base.js +324 -0
  16. package/dist/devices/base.js.map +1 -0
  17. package/dist/devices/index.d.ts +30 -0
  18. package/dist/devices/index.d.ts.map +1 -0
  19. package/dist/devices/index.js +34 -0
  20. package/dist/devices/index.js.map +1 -0
  21. package/dist/devices/wo-air-purifier-table.d.ts +8 -0
  22. package/dist/devices/wo-air-purifier-table.d.ts.map +1 -0
  23. package/dist/devices/wo-air-purifier-table.js +12 -0
  24. package/dist/devices/wo-air-purifier-table.js.map +1 -0
  25. package/dist/devices/wo-air-purifier.d.ts +28 -0
  26. package/dist/devices/wo-air-purifier.d.ts.map +1 -0
  27. package/dist/devices/wo-air-purifier.js +105 -0
  28. package/dist/devices/wo-air-purifier.js.map +1 -0
  29. package/dist/devices/wo-blind-tilt.d.ts +36 -0
  30. package/dist/devices/wo-blind-tilt.d.ts.map +1 -0
  31. package/dist/devices/wo-blind-tilt.js +95 -0
  32. package/dist/devices/wo-blind-tilt.js.map +1 -0
  33. package/dist/devices/wo-bulb.d.ts +32 -0
  34. package/dist/devices/wo-bulb.d.ts.map +1 -0
  35. package/dist/devices/wo-bulb.js +109 -0
  36. package/dist/devices/wo-bulb.js.map +1 -0
  37. package/dist/devices/wo-ceiling-light.d.ts +8 -0
  38. package/dist/devices/wo-ceiling-light.d.ts.map +1 -0
  39. package/dist/devices/wo-ceiling-light.js +12 -0
  40. package/dist/devices/wo-ceiling-light.js.map +1 -0
  41. package/dist/devices/wo-contact.d.ts +12 -0
  42. package/dist/devices/wo-contact.d.ts.map +1 -0
  43. package/dist/devices/wo-contact.js +50 -0
  44. package/dist/devices/wo-contact.js.map +1 -0
  45. package/dist/devices/wo-curtain.d.ts +28 -0
  46. package/dist/devices/wo-curtain.d.ts.map +1 -0
  47. package/dist/devices/wo-curtain.js +82 -0
  48. package/dist/devices/wo-curtain.js.map +1 -0
  49. package/dist/devices/wo-hand.d.ts +24 -0
  50. package/dist/devices/wo-hand.d.ts.map +1 -0
  51. package/dist/devices/wo-hand.js +70 -0
  52. package/dist/devices/wo-hand.js.map +1 -0
  53. package/dist/devices/wo-hub2.d.ts +12 -0
  54. package/dist/devices/wo-hub2.d.ts.map +1 -0
  55. package/dist/devices/wo-hub2.js +48 -0
  56. package/dist/devices/wo-hub2.js.map +1 -0
  57. package/dist/devices/wo-hub3.d.ts +8 -0
  58. package/dist/devices/wo-hub3.d.ts.map +1 -0
  59. package/dist/devices/wo-hub3.js +12 -0
  60. package/dist/devices/wo-hub3.js.map +1 -0
  61. package/dist/devices/wo-humi.d.ts +28 -0
  62. package/dist/devices/wo-humi.d.ts.map +1 -0
  63. package/dist/devices/wo-humi.js +91 -0
  64. package/dist/devices/wo-humi.js.map +1 -0
  65. package/dist/devices/wo-humi2.d.ts +8 -0
  66. package/dist/devices/wo-humi2.d.ts.map +1 -0
  67. package/dist/devices/wo-humi2.js +12 -0
  68. package/dist/devices/wo-humi2.js.map +1 -0
  69. package/dist/devices/wo-io-sensor-th.d.ts +8 -0
  70. package/dist/devices/wo-io-sensor-th.d.ts.map +1 -0
  71. package/dist/devices/wo-io-sensor-th.js +12 -0
  72. package/dist/devices/wo-io-sensor-th.js.map +1 -0
  73. package/dist/devices/wo-keypad.d.ts +13 -0
  74. package/dist/devices/wo-keypad.d.ts.map +1 -0
  75. package/dist/devices/wo-keypad.js +46 -0
  76. package/dist/devices/wo-keypad.js.map +1 -0
  77. package/dist/devices/wo-leak.d.ts +12 -0
  78. package/dist/devices/wo-leak.d.ts.map +1 -0
  79. package/dist/devices/wo-leak.js +46 -0
  80. package/dist/devices/wo-leak.js.map +1 -0
  81. package/dist/devices/wo-lock-pro.d.ts +24 -0
  82. package/dist/devices/wo-lock-pro.d.ts.map +1 -0
  83. package/dist/devices/wo-lock-pro.js +72 -0
  84. package/dist/devices/wo-lock-pro.js.map +1 -0
  85. package/dist/devices/wo-lock.d.ts +20 -0
  86. package/dist/devices/wo-lock.d.ts.map +1 -0
  87. package/dist/devices/wo-lock.js +64 -0
  88. package/dist/devices/wo-lock.js.map +1 -0
  89. package/dist/devices/wo-plug-mini-jp.d.ts +8 -0
  90. package/dist/devices/wo-plug-mini-jp.d.ts.map +1 -0
  91. package/dist/devices/wo-plug-mini-jp.js +12 -0
  92. package/dist/devices/wo-plug-mini-jp.js.map +1 -0
  93. package/dist/devices/wo-plug-mini-us.d.ts +24 -0
  94. package/dist/devices/wo-plug-mini-us.d.ts.map +1 -0
  95. package/dist/devices/wo-plug-mini-us.js +70 -0
  96. package/dist/devices/wo-plug-mini-us.js.map +1 -0
  97. package/dist/devices/wo-presence.d.ts +12 -0
  98. package/dist/devices/wo-presence.d.ts.map +1 -0
  99. package/dist/devices/wo-presence.js +48 -0
  100. package/dist/devices/wo-presence.js.map +1 -0
  101. package/dist/devices/wo-relay-switch-1.d.ts +24 -0
  102. package/dist/devices/wo-relay-switch-1.d.ts.map +1 -0
  103. package/dist/devices/wo-relay-switch-1.js +70 -0
  104. package/dist/devices/wo-relay-switch-1.js.map +1 -0
  105. package/dist/devices/wo-relay-switch-1pm.d.ts +8 -0
  106. package/dist/devices/wo-relay-switch-1pm.d.ts.map +1 -0
  107. package/dist/devices/wo-relay-switch-1pm.js +12 -0
  108. package/dist/devices/wo-relay-switch-1pm.js.map +1 -0
  109. package/dist/devices/wo-remote.d.ts +13 -0
  110. package/dist/devices/wo-remote.d.ts.map +1 -0
  111. package/dist/devices/wo-remote.js +45 -0
  112. package/dist/devices/wo-remote.js.map +1 -0
  113. package/dist/devices/wo-sensor-th-plus.d.ts +8 -0
  114. package/dist/devices/wo-sensor-th-plus.d.ts.map +1 -0
  115. package/dist/devices/wo-sensor-th-plus.js +12 -0
  116. package/dist/devices/wo-sensor-th-plus.js.map +1 -0
  117. package/dist/devices/wo-sensor-th-pro-co2.d.ts +8 -0
  118. package/dist/devices/wo-sensor-th-pro-co2.d.ts.map +1 -0
  119. package/dist/devices/wo-sensor-th-pro-co2.js +12 -0
  120. package/dist/devices/wo-sensor-th-pro-co2.js.map +1 -0
  121. package/dist/devices/wo-sensor-th-pro.d.ts +8 -0
  122. package/dist/devices/wo-sensor-th-pro.d.ts.map +1 -0
  123. package/dist/devices/wo-sensor-th-pro.js +12 -0
  124. package/dist/devices/wo-sensor-th-pro.js.map +1 -0
  125. package/dist/devices/wo-sensor-th.d.ts +12 -0
  126. package/dist/devices/wo-sensor-th.d.ts.map +1 -0
  127. package/dist/devices/wo-sensor-th.js +49 -0
  128. package/dist/devices/wo-sensor-th.js.map +1 -0
  129. package/dist/devices/wo-strip.d.ts +8 -0
  130. package/dist/devices/wo-strip.d.ts.map +1 -0
  131. package/dist/devices/wo-strip.js +12 -0
  132. package/dist/devices/wo-strip.js.map +1 -0
  133. package/dist/errors.d.ts +63 -0
  134. package/dist/errors.d.ts.map +1 -0
  135. package/dist/errors.js +103 -0
  136. package/dist/errors.js.map +1 -0
  137. package/dist/index.d.ts +10 -6
  138. package/dist/index.d.ts.map +1 -1
  139. package/dist/index.js +9 -10
  140. package/dist/index.js.map +1 -1
  141. package/dist/settings.d.ts +126 -47
  142. package/dist/settings.d.ts.map +1 -1
  143. package/dist/settings.js +214 -64
  144. package/dist/settings.js.map +1 -1
  145. package/dist/switchbot.d.ts +80 -0
  146. package/dist/switchbot.d.ts.map +1 -0
  147. package/dist/switchbot.js +376 -0
  148. package/dist/switchbot.js.map +1 -0
  149. package/dist/types/api.d.ts +187 -0
  150. package/dist/types/api.d.ts.map +1 -0
  151. package/dist/types/api.js +6 -0
  152. package/dist/types/api.js.map +1 -0
  153. package/dist/types/ble.d.ts +246 -343
  154. package/dist/types/ble.d.ts.map +1 -1
  155. package/dist/types/ble.js +94 -1
  156. package/dist/types/ble.js.map +1 -1
  157. package/dist/types/device.d.ts +209 -0
  158. package/dist/types/device.d.ts.map +1 -0
  159. package/dist/types/device.js +6 -0
  160. package/dist/types/device.js.map +1 -0
  161. package/dist/types/index.d.ts +115 -0
  162. package/dist/types/index.d.ts.map +1 -0
  163. package/dist/types/index.js +19 -0
  164. package/dist/types/index.js.map +1 -0
  165. package/dist/utils/index.d.ts +97 -0
  166. package/dist/utils/index.d.ts.map +1 -0
  167. package/dist/utils/index.js +206 -0
  168. package/dist/utils/index.js.map +1 -0
  169. package/docs/assets/hierarchy.js +1 -1
  170. package/docs/assets/highlight.css +20 -6
  171. package/docs/assets/icons.js +1 -1
  172. package/docs/assets/icons.svg +1 -1
  173. package/docs/assets/main.js +2 -2
  174. package/docs/assets/navigation.js +1 -1
  175. package/docs/assets/search.js +1 -1
  176. package/docs/assets/style.css +3 -3
  177. package/docs/classes/APIError.html +6 -0
  178. package/docs/classes/APINotAvailableError.html +4 -0
  179. package/docs/classes/BLEConnection.html +17 -0
  180. package/docs/classes/BLENotAvailableError.html +4 -0
  181. package/docs/classes/BLEScanner.html +15 -0
  182. package/docs/classes/CommandFailedError.html +6 -0
  183. package/docs/classes/ConnectionTimeoutError.html +5 -0
  184. package/docs/classes/DeviceManager.html +25 -0
  185. package/docs/classes/DeviceNotFoundError.html +4 -0
  186. package/docs/classes/DiscoveryError.html +5 -0
  187. package/docs/classes/OpenAPIClient.html +66 -0
  188. package/docs/classes/SwitchBot.html +21 -0
  189. package/docs/classes/SwitchBotDevice.html +28 -0
  190. package/docs/classes/SwitchBotError.html +4 -0
  191. package/docs/classes/ValidationError.html +5 -0
  192. package/docs/classes/WoAirPurifier.html +32 -80
  193. package/docs/classes/WoAirPurifierTable.html +36 -83
  194. package/docs/classes/WoBlindTilt.html +34 -73
  195. package/docs/classes/WoBulb.html +33 -85
  196. package/docs/classes/WoCeilingLight.html +38 -107
  197. package/docs/classes/WoContact.html +27 -52
  198. package/docs/classes/WoCurtain.html +32 -69
  199. package/docs/classes/WoHand.html +30 -59
  200. package/docs/classes/WoHub2.html +27 -52
  201. package/docs/classes/WoHub3.html +28 -52
  202. package/docs/classes/WoHumi.html +33 -65
  203. package/docs/classes/WoHumi2.html +36 -67
  204. package/docs/classes/WoIOSensorTH.html +28 -53
  205. package/docs/classes/WoKeypad.html +28 -52
  206. package/docs/classes/WoLeak.html +27 -53
  207. package/docs/classes/WoPlugMiniJP.html +34 -78
  208. package/docs/classes/WoPlugMiniUS.html +30 -75
  209. package/docs/classes/WoPresence.html +27 -60
  210. package/docs/classes/WoRelaySwitch1.html +31 -55
  211. package/docs/classes/WoRelaySwitch1PM.html +34 -57
  212. package/docs/classes/WoRemote.html +28 -52
  213. package/docs/classes/WoSensorTH.html +27 -46
  214. package/docs/classes/WoSensorTHPlus.html +28 -46
  215. package/docs/classes/WoSensorTHPro.html +28 -46
  216. package/docs/classes/WoSensorTHProCO2.html +28 -46
  217. package/docs/classes/WoSmartLock.html +29 -111
  218. package/docs/classes/WoSmartLockPro.html +31 -111
  219. package/docs/classes/WoStrip.html +38 -94
  220. package/docs/enums/LogLevel.html +4 -7
  221. package/docs/enums/SwitchBotBLEModel.html +11 -5
  222. package/docs/enums/SwitchBotBLEModelName.html +13 -6
  223. package/docs/functions/updateBaseURL.html +3 -3
  224. package/docs/hierarchy.html +1 -1
  225. package/docs/index.html +40 -6
  226. package/docs/interfaces/APICommandRequest.html +5 -0
  227. package/docs/interfaces/APICommandResponse.html +5 -0
  228. package/docs/interfaces/APIDevice.html +18 -0
  229. package/docs/interfaces/APIDeviceStatus.html +36 -0
  230. package/docs/interfaces/APIErrorResponse.html +5 -0
  231. package/docs/interfaces/APIResponse.html +5 -0
  232. package/docs/interfaces/AirPurifierCommands.html +5 -0
  233. package/docs/interfaces/AirPurifierServiceData.html +14 -0
  234. package/docs/interfaces/AirPurifierStatus.html +17 -0
  235. package/docs/interfaces/BLEAdvertisement.html +6 -0
  236. package/docs/interfaces/BLEScanOptions.html +10 -0
  237. package/docs/interfaces/BLEServiceData.html +10 -0
  238. package/docs/interfaces/BlindTiltCommands.html +7 -0
  239. package/docs/interfaces/BlindTiltServiceData.html +14 -0
  240. package/docs/interfaces/BlindTiltStatus.html +15 -0
  241. package/docs/interfaces/BotCommands.html +4 -0
  242. package/docs/interfaces/BotServiceData.html +12 -0
  243. package/docs/interfaces/BotStatus.html +14 -0
  244. package/docs/interfaces/BulbCommands.html +6 -0
  245. package/docs/interfaces/BulbServiceData.html +19 -0
  246. package/docs/interfaces/BulbStatus.html +16 -0
  247. package/docs/interfaces/CeilingLightCommands.html +6 -0
  248. package/docs/interfaces/CeilingLightServiceData.html +19 -0
  249. package/docs/interfaces/CeilingLightStatus.html +16 -0
  250. package/docs/interfaces/CommandResult.html +12 -0
  251. package/docs/interfaces/ContactServiceData.html +13 -0
  252. package/docs/interfaces/ContactStatus.html +15 -0
  253. package/docs/interfaces/CurtainCommands.html +5 -0
  254. package/docs/interfaces/CurtainServiceData.html +14 -0
  255. package/docs/interfaces/CurtainStatus.html +17 -0
  256. package/docs/interfaces/DeviceInfo.html +26 -0
  257. package/docs/interfaces/DeviceListResponse.html +4 -0
  258. package/docs/interfaces/DeviceStatus.html +12 -0
  259. package/docs/interfaces/DiscoveryOptions.html +14 -0
  260. package/docs/interfaces/HubServiceData.html +14 -0
  261. package/docs/interfaces/HubStatus.html +15 -0
  262. package/docs/interfaces/HumidifierCommands.html +5 -0
  263. package/docs/interfaces/HumidifierServiceData.html +14 -0
  264. package/docs/interfaces/HumidifierStatus.html +18 -0
  265. package/docs/interfaces/KeypadStatus.html +13 -0
  266. package/docs/interfaces/LeakServiceData.html +11 -0
  267. package/docs/interfaces/LeakStatus.html +13 -0
  268. package/docs/interfaces/LockCommands.html +3 -0
  269. package/docs/interfaces/LockServiceData.html +15 -0
  270. package/docs/interfaces/LockStatus.html +15 -0
  271. package/docs/interfaces/MeterServiceData.html +13 -0
  272. package/docs/interfaces/MeterStatus.html +15 -0
  273. package/docs/interfaces/MotionServiceData.html +13 -0
  274. package/docs/interfaces/MotionStatus.html +14 -0
  275. package/docs/interfaces/PlugCommands.html +4 -0
  276. package/docs/interfaces/PlugServiceData.html +17 -0
  277. package/docs/interfaces/PlugStatus.html +16 -0
  278. package/docs/interfaces/PresenceServiceData.html +12 -0
  279. package/docs/interfaces/PresenceStatus.html +14 -0
  280. package/docs/interfaces/RelaySwitchCommands.html +4 -0
  281. package/docs/interfaces/RelaySwitchServiceData.html +14 -0
  282. package/docs/interfaces/RelaySwitchStatus.html +16 -0
  283. package/docs/interfaces/RemoteStatus.html +12 -0
  284. package/docs/interfaces/SceneListResponse.html +3 -0
  285. package/docs/interfaces/StripCommands.html +6 -0
  286. package/docs/interfaces/StripServiceData.html +19 -0
  287. package/docs/interfaces/StripStatus.html +16 -0
  288. package/docs/interfaces/SwitchBotConfig.html +18 -0
  289. package/docs/interfaces/WebhookConfig.html +4 -0
  290. package/docs/interfaces/WebhookDetails.html +7 -0
  291. package/docs/interfaces/WebhookQueryResponse.html +5 -0
  292. package/docs/interfaces/WebhookSetupResponse.html +5 -0
  293. package/docs/modules.html +1 -1
  294. package/docs/types/ConnectionType.html +2 -0
  295. package/docs/types/PhysicalDeviceType.html +2 -0
  296. package/docs/types/VirtualDeviceType.html +2 -0
  297. package/docs/variables/urls.html +1 -1
  298. package/package.json +11 -20
  299. package/.github/scripts/npm-version-script-esm-auto.js +0 -207
  300. package/dist/device.d.ts +0 -1577
  301. package/dist/device.d.ts.map +0 -1
  302. package/dist/device.js +0 -3493
  303. package/dist/device.js.map +0 -1
  304. package/dist/device.test.d.ts +0 -2
  305. package/dist/device.test.d.ts.map +0 -1
  306. package/dist/device.test.js +0 -255
  307. package/dist/device.test.js.map +0 -1
  308. package/dist/index.test.d.ts +0 -2
  309. package/dist/index.test.d.ts.map +0 -1
  310. package/dist/index.test.js +0 -14
  311. package/dist/index.test.js.map +0 -1
  312. package/dist/parameter-checker.d.ts +0 -91
  313. package/dist/parameter-checker.d.ts.map +0 -1
  314. package/dist/parameter-checker.js +0 -262
  315. package/dist/parameter-checker.js.map +0 -1
  316. package/dist/parameter-checker.test.d.ts +0 -2
  317. package/dist/parameter-checker.test.d.ts.map +0 -1
  318. package/dist/parameter-checker.test.js +0 -56
  319. package/dist/parameter-checker.test.js.map +0 -1
  320. package/dist/settings.test.d.ts +0 -2
  321. package/dist/settings.test.d.ts.map +0 -1
  322. package/dist/settings.test.js +0 -61
  323. package/dist/settings.test.js.map +0 -1
  324. package/dist/switchbot-ble.d.ts +0 -89
  325. package/dist/switchbot-ble.d.ts.map +0 -1
  326. package/dist/switchbot-ble.js +0 -319
  327. package/dist/switchbot-ble.js.map +0 -1
  328. package/dist/switchbot-ble.test.d.ts +0 -2
  329. package/dist/switchbot-ble.test.d.ts.map +0 -1
  330. package/dist/switchbot-ble.test.js +0 -32
  331. package/dist/switchbot-ble.test.js.map +0 -1
  332. package/dist/switchbot-openapi.d.ts +0 -139
  333. package/dist/switchbot-openapi.d.ts.map +0 -1
  334. package/dist/switchbot-openapi.js +0 -375
  335. package/dist/switchbot-openapi.js.map +0 -1
  336. package/dist/switchbot-openapi.test.d.ts +0 -2
  337. package/dist/switchbot-openapi.test.d.ts.map +0 -1
  338. package/dist/switchbot-openapi.test.js +0 -36
  339. package/dist/switchbot-openapi.test.js.map +0 -1
  340. package/dist/types/ble-guards.d.ts +0 -12
  341. package/dist/types/ble-guards.d.ts.map +0 -1
  342. package/dist/types/ble-guards.js +0 -10
  343. package/dist/types/ble-guards.js.map +0 -1
  344. package/dist/types/ble-guards.test.d.ts +0 -2
  345. package/dist/types/ble-guards.test.d.ts.map +0 -1
  346. package/dist/types/ble-guards.test.js +0 -62
  347. package/dist/types/ble-guards.test.js.map +0 -1
  348. package/dist/types/openapi.d.ts +0 -635
  349. package/dist/types/openapi.d.ts.map +0 -1
  350. package/dist/types/openapi.js +0 -3
  351. package/dist/types/openapi.js.map +0 -1
  352. package/docs/classes/Advertising.html +0 -21
  353. package/docs/classes/ErrorUtils.html +0 -25
  354. package/docs/classes/ParameterChecker.html +0 -69
  355. package/docs/classes/SwitchBotBLE.html +0 -39
  356. package/docs/classes/SwitchBotOpenAPI.html +0 -57
  357. package/docs/classes/SwitchbotDevice.html +0 -47
  358. package/docs/classes/ValidationUtils.html +0 -51
  359. package/docs/classes/WoSmartLockUltra.html +0 -113
  360. package/docs/enums/SwitchBotBLEModelFriendlyName.html +0 -39
  361. package/docs/enums/SwitchBotModel.html +0 -52
  362. package/docs/interfaces/AdvertisementData.html +0 -3
  363. package/docs/interfaces/Chars.html +0 -4
  364. package/docs/interfaces/ColorLightServiceDataBase.html +0 -17
  365. package/docs/interfaces/ErrorObject.html +0 -3
  366. package/docs/interfaces/LockBaseServiceData.html +0 -15
  367. package/docs/interfaces/NobleTypes.html +0 -3
  368. package/docs/interfaces/Params.html +0 -6
  369. package/docs/interfaces/PlugMiniServiceDataBase.html +0 -12
  370. package/docs/interfaces/Rule.html +0 -9
  371. package/docs/interfaces/ServiceData.html +0 -2
  372. package/docs/interfaces/SwitchBotBLEDevice.html +0 -27
  373. package/docs/interfaces/SwitchBotScanner.html +0 -6
  374. package/docs/interfaces/TemperatureServiceDataBase.html +0 -10
  375. package/docs/interfaces/WebhookDetail.html +0 -6
  376. package/docs/interfaces/ad.html +0 -5
  377. package/docs/interfaces/body.html +0 -3
  378. package/docs/interfaces/bodyChange.html +0 -4
  379. package/docs/interfaces/deleteWebhookResponse.html +0 -4
  380. package/docs/interfaces/device.html +0 -7
  381. package/docs/interfaces/deviceList.html +0 -2
  382. package/docs/interfaces/deviceStatus.html +0 -7
  383. package/docs/interfaces/deviceStatusRequest.html +0 -4
  384. package/docs/interfaces/deviceWebhook.html +0 -4
  385. package/docs/interfaces/deviceWebhookContext.html +0 -4
  386. package/docs/interfaces/devices.html +0 -4
  387. package/docs/interfaces/infraredRemoteList.html +0 -2
  388. package/docs/interfaces/irdevice.html +0 -5
  389. package/docs/interfaces/pushRequest.html +0 -5
  390. package/docs/interfaces/pushResponse.html +0 -5
  391. package/docs/interfaces/pushResponseBody.html +0 -3
  392. package/docs/interfaces/queryWebhookResponse.html +0 -4
  393. package/docs/interfaces/setupWebhookResponse.html +0 -4
  394. package/docs/interfaces/updateWebhookResponse.html +0 -4
  395. package/docs/interfaces/webhookRequest.html +0 -4
  396. package/docs/types/BLEDeviceServiceData.html +0 -1
  397. package/docs/types/IndoorCam.html +0 -1
  398. package/docs/types/MacAddress.html +0 -1
  399. package/docs/types/airPurifier.html +0 -1
  400. package/docs/types/airPurifierPM25WebhookContext.html +0 -1
  401. package/docs/types/airPurifierServiceData.html +0 -1
  402. package/docs/types/airPurifierStatus.html +0 -1
  403. package/docs/types/airPurifierTable.html +0 -1
  404. package/docs/types/airPurifierTablePM25WebhookContext.html +0 -1
  405. package/docs/types/airPurifierTableServiceData.html +0 -1
  406. package/docs/types/airPurifierTableStatus.html +0 -1
  407. package/docs/types/airPurifierTableVOC.html +0 -1
  408. package/docs/types/airPurifierTableVOCStatus.html +0 -1
  409. package/docs/types/airPurifierTableVOCWebhookContext.html +0 -1
  410. package/docs/types/airPurifierTableWebhookContext.html +0 -1
  411. package/docs/types/airPurifierVOC.html +0 -1
  412. package/docs/types/airPurifierVOCStatus.html +0 -1
  413. package/docs/types/airPurifierVOCWebhookContext.html +0 -1
  414. package/docs/types/airPurifierWebhookContext.html +0 -1
  415. package/docs/types/batteryCirculatorFan.html +0 -1
  416. package/docs/types/batteryCirculatorFanServiceData.html +0 -1
  417. package/docs/types/batteryCirculatorFanStatus.html +0 -1
  418. package/docs/types/batteryCirculatorFanWebhookContext.html +0 -1
  419. package/docs/types/blindTilt.html +0 -1
  420. package/docs/types/blindTiltServiceData.html +0 -1
  421. package/docs/types/blindTiltStatus.html +0 -1
  422. package/docs/types/blindTiltWebhookContext.html +0 -1
  423. package/docs/types/bot.html +0 -1
  424. package/docs/types/botServiceData.html +0 -1
  425. package/docs/types/botStatus.html +0 -1
  426. package/docs/types/botWebhookContext.html +0 -1
  427. package/docs/types/ceilingLight.html +0 -1
  428. package/docs/types/ceilingLightPro.html +0 -1
  429. package/docs/types/ceilingLightProServiceData.html +0 -1
  430. package/docs/types/ceilingLightProStatus.html +0 -1
  431. package/docs/types/ceilingLightProWebhookContext.html +0 -1
  432. package/docs/types/ceilingLightServiceData.html +0 -1
  433. package/docs/types/ceilingLightStatus.html +0 -1
  434. package/docs/types/ceilingLightWebhookContext.html +0 -1
  435. package/docs/types/circulatorFanStatus.html +0 -1
  436. package/docs/types/circulatorFanWebhookContext.html +0 -1
  437. package/docs/types/colorBulb.html +0 -1
  438. package/docs/types/colorBulbServiceData.html +0 -1
  439. package/docs/types/colorBulbStatus.html +0 -1
  440. package/docs/types/colorBulbWebhookContext.html +0 -1
  441. package/docs/types/commandType.html +0 -2
  442. package/docs/types/contactSensor.html +0 -1
  443. package/docs/types/contactSensorServiceData.html +0 -1
  444. package/docs/types/contactSensorStatus.html +0 -1
  445. package/docs/types/contactSensorWebhookContext.html +0 -1
  446. package/docs/types/curtain.html +0 -1
  447. package/docs/types/curtain3.html +0 -1
  448. package/docs/types/curtain3ServiceData.html +0 -1
  449. package/docs/types/curtain3WebhookContext.html +0 -1
  450. package/docs/types/curtainServiceData.html +0 -1
  451. package/docs/types/curtainStatus.html +0 -1
  452. package/docs/types/curtainWebhookContext.html +0 -1
  453. package/docs/types/floorCleaningRobotS10.html +0 -1
  454. package/docs/types/floorCleaningRobotS10Status.html +0 -1
  455. package/docs/types/floorCleaningRobotS10WebhookContext.html +0 -1
  456. package/docs/types/hub2.html +0 -1
  457. package/docs/types/hub2ServiceData.html +0 -1
  458. package/docs/types/hub2Status.html +0 -1
  459. package/docs/types/hub2WebhookContext.html +0 -1
  460. package/docs/types/hub3ServiceData.html +0 -1
  461. package/docs/types/humidifier.html +0 -1
  462. package/docs/types/humidifier2ServiceData.html +0 -1
  463. package/docs/types/humidifier2Status.html +0 -1
  464. package/docs/types/humidifier2WebhookContext.html +0 -1
  465. package/docs/types/humidifierServiceData.html +0 -1
  466. package/docs/types/humidifierStatus.html +0 -1
  467. package/docs/types/humidifierWebhookContext.html +0 -1
  468. package/docs/types/indoorCameraWebhookContext.html +0 -1
  469. package/docs/types/keypad.html +0 -1
  470. package/docs/types/keypadDetectorServiceData.html +0 -1
  471. package/docs/types/keypadTouch.html +0 -1
  472. package/docs/types/keypadTouchWebhookContext.html +0 -1
  473. package/docs/types/keypadWebhookContext.html +0 -1
  474. package/docs/types/lock.html +0 -1
  475. package/docs/types/lockPro.html +0 -1
  476. package/docs/types/lockProServiceData.html +0 -1
  477. package/docs/types/lockProStatus.html +0 -1
  478. package/docs/types/lockProWebhookContext.html +0 -1
  479. package/docs/types/lockServiceData.html +0 -1
  480. package/docs/types/lockStatus.html +0 -1
  481. package/docs/types/lockWebhookContext.html +0 -1
  482. package/docs/types/meter.html +0 -1
  483. package/docs/types/meterPlus.html +0 -1
  484. package/docs/types/meterPlusServiceData.html +0 -1
  485. package/docs/types/meterPlusStatus.html +0 -1
  486. package/docs/types/meterPlusWebhookContext.html +0 -1
  487. package/docs/types/meterPro.html +0 -1
  488. package/docs/types/meterProCO2ServiceData.html +0 -1
  489. package/docs/types/meterProCO2Status.html +0 -1
  490. package/docs/types/meterProCO2WebhookContext.html +0 -1
  491. package/docs/types/meterProServiceData.html +0 -1
  492. package/docs/types/meterProStatus.html +0 -1
  493. package/docs/types/meterProWebhookContext.html +0 -1
  494. package/docs/types/meterServiceData.html +0 -1
  495. package/docs/types/meterStatus.html +0 -1
  496. package/docs/types/meterWebhookContext.html +0 -1
  497. package/docs/types/motionSensor.html +0 -1
  498. package/docs/types/motionSensorServiceData.html +0 -1
  499. package/docs/types/motionSensorStatus.html +0 -1
  500. package/docs/types/motionSensorWebhookContext.html +0 -1
  501. package/docs/types/onadvertisement.html +0 -1
  502. package/docs/types/ondiscover.html +0 -1
  503. package/docs/types/outdoorMeter.html +0 -1
  504. package/docs/types/outdoorMeterServiceData.html +0 -1
  505. package/docs/types/outdoorMeterStatus.html +0 -1
  506. package/docs/types/outdoorMeterWebhookContext.html +0 -1
  507. package/docs/types/panTiltCamWebhookContext.html +0 -1
  508. package/docs/types/pantiltCam.html +0 -1
  509. package/docs/types/pantiltCam2k.html +0 -1
  510. package/docs/types/plug.html +0 -1
  511. package/docs/types/plugMini.html +0 -1
  512. package/docs/types/plugMiniJPServiceData.html +0 -1
  513. package/docs/types/plugMiniJPWebhookContext.html +0 -1
  514. package/docs/types/plugMiniStatus.html +0 -1
  515. package/docs/types/plugMiniUSServiceData.html +0 -1
  516. package/docs/types/plugMiniUSWebhookContext.html +0 -1
  517. package/docs/types/plugStatus.html +0 -1
  518. package/docs/types/plugWebhookContext.html +0 -1
  519. package/docs/types/presenceSensor.html +0 -1
  520. package/docs/types/presenceSensorServiceData.html +0 -1
  521. package/docs/types/presenceSensorStatus.html +0 -1
  522. package/docs/types/presenceSensorWebhookContext.html +0 -1
  523. package/docs/types/relaySwitch1Context.html +0 -1
  524. package/docs/types/relaySwitch1PMContext.html +0 -1
  525. package/docs/types/relaySwitch1PMServiceData.html +0 -1
  526. package/docs/types/relaySwitch1PMStatus.html +0 -1
  527. package/docs/types/relaySwitch1ServiceData.html +0 -1
  528. package/docs/types/relaySwitch1Status.html +0 -1
  529. package/docs/types/remote.html +0 -1
  530. package/docs/types/remoteServiceData.html +0 -1
  531. package/docs/types/robotVacuumCleanerS1.html +0 -1
  532. package/docs/types/robotVacuumCleanerS1Plus.html +0 -1
  533. package/docs/types/robotVacuumCleanerS1PlusStatus.html +0 -1
  534. package/docs/types/robotVacuumCleanerS1PlusWebhookContext.html +0 -1
  535. package/docs/types/robotVacuumCleanerS1Status.html +0 -1
  536. package/docs/types/robotVacuumCleanerS1WebhookContext.html +0 -1
  537. package/docs/types/robotVacuumCleanerServiceData.html +0 -1
  538. package/docs/types/stripLight.html +0 -1
  539. package/docs/types/stripLightServiceData.html +0 -1
  540. package/docs/types/stripLightStatus.html +0 -1
  541. package/docs/types/stripLightWebhookContext.html +0 -1
  542. package/docs/types/waterLeakDetector.html +0 -1
  543. package/docs/types/waterLeakDetectorServiceData.html +0 -1
  544. package/docs/types/waterLeakDetectorStatus.html +0 -1
  545. package/docs/types/waterLeakDetectorWebhookContext.html +0 -1
  546. package/docs/variables/parameterChecker.html +0 -1
  547. package/eslint.config.js +0 -48
  548. package/typedoc.json +0 -17
@@ -1,319 +0,0 @@
1
- import { EventEmitter } from 'node:events';
2
- import { Advertising, LogLevel, SwitchBotBLEModel, SwitchbotDevice, WoBlindTilt, WoBulb, WoCeilingLight, WoContact, WoCurtain, WoHand, WoHub2, WoHumi, WoHumi2, WoIOSensorTH, WoKeypad, WoLeak, WoPlugMiniJP, WoPlugMiniUS, WoPresence, WoRelaySwitch1, WoRelaySwitch1PM, WoRemote, WoSensorTH, WoSensorTHPlus, WoSensorTHPro, WoSensorTHProCO2, WoSmartLock, WoSmartLockPro, WoSmartLockUltra, WoStrip } from './device.js';
3
- import { parameterChecker } from './parameter-checker.js';
4
- import { DEFAULT_DISCOVERY_DURATION, PRIMARY_SERVICE_UUID_LIST } from './settings.js';
5
- /**
6
- * SwitchBotBLE class to interact with SwitchBot devices.
7
- */
8
- export class SwitchBotBLE extends EventEmitter {
9
- nobleInitialized;
10
- noble;
11
- ondiscover;
12
- onadvertisement;
13
- /**
14
- * Constructor
15
- *
16
- * @param {Params} [params] - Optional parameters
17
- */
18
- constructor(params) {
19
- super();
20
- this.nobleInitialized = this.initialize(params);
21
- }
22
- /**
23
- * Emits a log event with the specified log level and message.
24
- *
25
- * @param level - The severity level of the log (e.g., 'info', 'warn', 'error').
26
- * @param message - The log message to be emitted.
27
- */
28
- /**
29
- * Emits a log event with a defined LogLevel.
30
- */
31
- log(level, message) {
32
- // Emit log events asynchronously with level and message as separate args
33
- setTimeout(() => this.emit('log', { level, message }), 0);
34
- }
35
- /**
36
- * Initializes the noble object.
37
- *
38
- * @param {Params} [params] - Optional parameters
39
- * @returns {Promise<void>} - Resolves when initialization is complete
40
- */
41
- async initialize(params) {
42
- try {
43
- if (params && params.noble) {
44
- this.noble = params.noble;
45
- }
46
- else {
47
- this.noble = (await import('@stoprocent/noble')).default;
48
- }
49
- try {
50
- await this.noble.waitForPoweredOnAsync();
51
- this.log(LogLevel.DEBUG, 'Noble powered on');
52
- }
53
- catch (e) {
54
- this.log(LogLevel.ERROR, `Failed waiting for powered on: ${JSON.stringify(e.message ?? e)}`);
55
- }
56
- }
57
- catch (e) {
58
- this.log(LogLevel.ERROR, `Failed to import noble: ${JSON.stringify(e.message ?? e)}`);
59
- }
60
- }
61
- /**
62
- * Validates the parameters.
63
- *
64
- * @param {Params} params - The parameters to validate.
65
- * @param {Record<string, unknown>} schema - The schema to validate against.
66
- * @returns {Promise<void>} - Resolves if parameters are valid, otherwise throws an error.
67
- */
68
- async validate(params, schema) {
69
- const valid = parameterChecker.check(params, schema, false);
70
- if (!valid) {
71
- this.log(LogLevel.ERROR, `parameterChecker: ${JSON.stringify(parameterChecker.error.message)}`);
72
- throw new Error(parameterChecker.error.message);
73
- }
74
- }
75
- /**
76
- * Discovers Switchbot devices with enhanced error handling and logging.
77
- * @param params The discovery parameters.
78
- * @returns A Promise that resolves with an array of discovered Switchbot devices.
79
- */
80
- async discover(params = {}) {
81
- await this.initialize(params);
82
- await this.validate(params, {
83
- duration: { required: false, type: 'integer', min: 1, max: 60000 },
84
- model: { required: false, type: 'string', enum: Object.values(SwitchBotBLEModel) },
85
- id: { required: false, type: 'string', min: 12, max: 17 },
86
- quick: { required: false, type: 'boolean' },
87
- });
88
- if (!this.noble) {
89
- throw new Error('Noble BLE library failed to initialize properly');
90
- }
91
- const p = {
92
- duration: params.duration ?? DEFAULT_DISCOVERY_DURATION,
93
- model: params.model ?? '',
94
- id: params.id ?? '',
95
- quick: !!params.quick,
96
- };
97
- this.log(LogLevel.DEBUG, `Starting discovery with parameters: ${JSON.stringify(p)}`);
98
- const peripherals = {};
99
- let timer;
100
- let isDiscoveryActive = true;
101
- const finishDiscovery = async () => {
102
- if (!isDiscoveryActive) {
103
- return Object.values(peripherals);
104
- }
105
- isDiscoveryActive = false;
106
- if (timer) {
107
- clearTimeout(timer);
108
- }
109
- if (this.noble) {
110
- this.noble.removeAllListeners('discover');
111
- try {
112
- await this.noble.stopScanningAsync();
113
- this.log(LogLevel.DEBUG, 'Successfully stopped scanning for SwitchBot BLE devices');
114
- }
115
- catch (e) {
116
- this.log(LogLevel.ERROR, `Failed to stop scanning: ${JSON.stringify(e.message ?? e)}`);
117
- }
118
- }
119
- const devices = Object.values(peripherals);
120
- const deviceCount = devices.length;
121
- this.log(deviceCount > 0 ? LogLevel.INFO : LogLevel.WARN, `Discovery completed. Found ${deviceCount} device${deviceCount !== 1 ? 's' : ''}`);
122
- return devices;
123
- };
124
- return new Promise((resolve, reject) => {
125
- this.noble.on('discover', async (peripheral) => {
126
- try {
127
- const device = await this.createDevice(peripheral, p.id, p.model);
128
- if (!device) {
129
- return;
130
- }
131
- if (peripherals[device.id]) {
132
- this.log(LogLevel.DEBUG, `Device ${device.id} already discovered, skipping duplicate`);
133
- return;
134
- }
135
- peripherals[device.id] = device;
136
- this.log(LogLevel.DEBUG, `Discovered device: ${device.friendlyName} (${device.id}) at ${device.address}`);
137
- if (this.ondiscover) {
138
- try {
139
- await this.ondiscover(device);
140
- }
141
- catch (e) {
142
- this.log(LogLevel.ERROR, `Error in ondiscover callback: ${e.message ?? e}`);
143
- }
144
- }
145
- if (p.quick) {
146
- this.log(LogLevel.DEBUG, 'Quick discovery mode: stopping after first device found');
147
- resolve(await finishDiscovery());
148
- }
149
- }
150
- catch (e) {
151
- this.log(LogLevel.ERROR, `Error processing discovered device: ${e.message ?? e}`);
152
- }
153
- });
154
- // Start scanning with timeout handling
155
- this.noble.startScanningAsync(PRIMARY_SERVICE_UUID_LIST, false)
156
- .then(() => {
157
- this.log(LogLevel.DEBUG, `Started scanning for ${p.duration}ms`);
158
- timer = setTimeout(async () => {
159
- const result = await finishDiscovery();
160
- if (result.length === 0) {
161
- reject(new Error(`No SwitchBot devices found after ${p.duration}ms discovery timeout`));
162
- }
163
- else {
164
- resolve(result);
165
- }
166
- }, p.duration);
167
- })
168
- .catch((error) => {
169
- this.log(LogLevel.ERROR, `Failed to start scanning: ${error.message ?? error}`);
170
- reject(new Error(`Failed to start BLE scanning: ${error.message ?? error}`));
171
- });
172
- });
173
- }
174
- /**
175
- * Creates a device object based on the peripheral, id, and model.
176
- *
177
- * @param {NobleTypes['peripheral']} peripheral - The peripheral object.
178
- * @param {string} id - The device id.
179
- * @param {string} model - The device model.
180
- * @returns {Promise<SwitchbotDevice | null>} - The device object or null.
181
- */
182
- async createDevice(peripheral, id, model) {
183
- const ad = await Advertising.parse(peripheral, (level, message) => this.log(level, message));
184
- if (ad && await this.filterAd(ad, id, model) && this.noble) {
185
- switch (ad.serviceData.model) {
186
- case SwitchBotBLEModel.Bot: return new WoHand(peripheral, this.noble);
187
- case SwitchBotBLEModel.Curtain:
188
- case SwitchBotBLEModel.Curtain3: return new WoCurtain(peripheral, this.noble);
189
- case SwitchBotBLEModel.Humidifier: return new WoHumi(peripheral, this.noble);
190
- case SwitchBotBLEModel.Humidifier2: return new WoHumi2(peripheral, this.noble);
191
- case SwitchBotBLEModel.Meter: return new WoSensorTH(peripheral, this.noble);
192
- case SwitchBotBLEModel.MeterPlus: return new WoSensorTHPlus(peripheral, this.noble);
193
- case SwitchBotBLEModel.MeterPro: return new WoSensorTHPro(peripheral, this.noble);
194
- case SwitchBotBLEModel.MeterProCO2: return new WoSensorTHProCO2(peripheral, this.noble);
195
- case SwitchBotBLEModel.Hub2: return new WoHub2(peripheral, this.noble);
196
- case SwitchBotBLEModel.OutdoorMeter: return new WoIOSensorTH(peripheral, this.noble);
197
- case SwitchBotBLEModel.MotionSensor: return new WoPresence(peripheral, this.noble);
198
- case SwitchBotBLEModel.PresenceSensor: return new WoPresence(peripheral, this.noble);
199
- case SwitchBotBLEModel.ContactSensor: return new WoContact(peripheral, this.noble);
200
- case SwitchBotBLEModel.Remote: return new WoRemote(peripheral, this.noble);
201
- case SwitchBotBLEModel.ColorBulb: return new WoBulb(peripheral, this.noble);
202
- case SwitchBotBLEModel.CeilingLight:
203
- case SwitchBotBLEModel.CeilingLightPro: return new WoCeilingLight(peripheral, this.noble);
204
- case SwitchBotBLEModel.StripLight: return new WoStrip(peripheral, this.noble);
205
- case SwitchBotBLEModel.Leak: return new WoLeak(peripheral, this.noble);
206
- case SwitchBotBLEModel.PlugMiniUS: return new WoPlugMiniUS(peripheral, this.noble);
207
- case SwitchBotBLEModel.PlugMiniJP: return new WoPlugMiniJP(peripheral, this.noble);
208
- case SwitchBotBLEModel.Lock: return new WoSmartLock(peripheral, this.noble);
209
- case SwitchBotBLEModel.LockPro: return new WoSmartLockPro(peripheral, this.noble);
210
- case SwitchBotBLEModel.LockUltra: return new WoSmartLockUltra(peripheral, this.noble);
211
- case SwitchBotBLEModel.BlindTilt: return new WoBlindTilt(peripheral, this.noble);
212
- case SwitchBotBLEModel.Keypad: return new WoKeypad(peripheral, this.noble);
213
- case SwitchBotBLEModel.RelaySwitch1: return new WoRelaySwitch1(peripheral, this.noble);
214
- case SwitchBotBLEModel.RelaySwitch1PM: return new WoRelaySwitch1PM(peripheral, this.noble);
215
- default: return new SwitchbotDevice(peripheral, this.noble);
216
- }
217
- }
218
- return null;
219
- }
220
- /**
221
- * Filters advertising data based on id and model.
222
- *
223
- * @param {Ad} ad - The advertising data.
224
- * @param {string} id - The device id.
225
- * @param {string} model - The device model.
226
- * @returns {Promise<boolean>} - True if the advertising data matches the id and model, false otherwise.
227
- */
228
- async filterAd(ad, id, model) {
229
- if (!ad) {
230
- return false;
231
- }
232
- if (id && ad.address.toLowerCase().replace(/[^a-z0-9]/g, '') !== id.toLowerCase().replace(/:/g, '')) {
233
- return false;
234
- }
235
- if (model && ad.serviceData.model !== model) {
236
- return false;
237
- }
238
- return true;
239
- }
240
- /**
241
- * Starts scanning for SwitchBot devices.
242
- *
243
- * @param {Params} [params] - Optional parameters.
244
- * @returns {Promise<void>} - Resolves when scanning starts successfully.
245
- */
246
- async startScan(params = {}) {
247
- await this.nobleInitialized;
248
- await this.validate(params, {
249
- model: { required: false, type: 'string', enum: Object.values(SwitchBotBLEModel) },
250
- id: { required: false, type: 'string', min: 12, max: 17 },
251
- });
252
- if (!this.noble) {
253
- throw new Error('noble object failed to initialize');
254
- }
255
- const p = { model: params.model || '', id: params.id || '' };
256
- this.noble.removeAllListeners('discover');
257
- this.noble.on('discover', async (peripheral) => {
258
- try {
259
- const ad = await Advertising.parse(peripheral, (level, message) => this.log(level, message));
260
- this.log(LogLevel.DEBUG, `Advertisement: ${JSON.stringify(ad)}`);
261
- this.log(LogLevel.DEBUG, `Filter ID: ${p.id}`);
262
- this.log(LogLevel.DEBUG, `Filter Model: ${p.model}`);
263
- if (ad && await this.filterAd(ad, p.id, p.model)) {
264
- this.log(LogLevel.DEBUG, `Advertisement passed filter: ${JSON.stringify(ad)}`);
265
- if (this.onadvertisement) {
266
- try {
267
- await this.onadvertisement(ad);
268
- }
269
- catch (e) {
270
- this.log(LogLevel.ERROR, `Error in onadvertisement callback: ${e.message ?? e}`);
271
- }
272
- }
273
- }
274
- }
275
- catch (e) {
276
- this.log(LogLevel.ERROR, `Error parsing advertisement: ${e.message ?? e}`);
277
- }
278
- });
279
- try {
280
- await this.noble.startScanningAsync(PRIMARY_SERVICE_UUID_LIST, true);
281
- this.log(LogLevel.DEBUG, 'Started Scanning for SwitchBot BLE devices.');
282
- }
283
- catch (e) {
284
- this.log(LogLevel.ERROR, `startScanningAsync error: ${JSON.stringify(e.message ?? e)}`);
285
- }
286
- }
287
- /**
288
- * Stops scanning for SwitchBot devices.
289
- *
290
- * @returns {Promise<void>} - Resolves when scanning stops successfully.
291
- */
292
- async stopScan() {
293
- if (!this.noble) {
294
- return;
295
- }
296
- this.noble.removeAllListeners('discover');
297
- try {
298
- await this.noble.stopScanningAsync();
299
- this.log(LogLevel.DEBUG, 'Stopped Scanning for SwitchBot BLE devices.');
300
- }
301
- catch (e) {
302
- this.log(LogLevel.ERROR, `stopScanningAsync error: ${JSON.stringify(e.message ?? e)}`);
303
- }
304
- }
305
- /**
306
- * Waits for the specified time.
307
- *
308
- * @param {number} msec - The time to wait in milliseconds.
309
- * @returns {Promise<void>} - Resolves after the specified time.
310
- */
311
- async wait(msec) {
312
- if (typeof msec !== 'number' || msec < 0) {
313
- throw new Error('Invalid parameter: msec must be a non-negative integer.');
314
- }
315
- return new Promise(resolve => setTimeout(resolve, msec));
316
- }
317
- }
318
- export { LogLevel, SwitchbotDevice };
319
- //# sourceMappingURL=switchbot-ble.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"switchbot-ble.js","sourceRoot":"","sources":["../src/switchbot-ble.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAE1C,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,iBAAiB,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,EAAE,cAAc,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,EAAE,YAAY,EAAE,YAAY,EAAE,UAAU,EAAE,cAAc,EAAE,gBAAgB,EAAE,QAAQ,EAAE,UAAU,EAAE,cAAc,EAAE,aAAa,EAAE,gBAAgB,EAAE,WAAW,EAAE,cAAc,EAAE,gBAAgB,EAAE,OAAO,EAAE,MAAM,aAAa,CAAA;AAC5Z,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAA;AACzD,OAAO,EAAE,0BAA0B,EAAE,yBAAyB,EAAE,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C,QAAQ,CAAC,KAAK,EAAE,4BAA4B,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,OAAO,IAAI,CAAC,CAAC,EAAE,CAAC,CAAA;QACxF,CAAC;IACH,CAAC;IAED;;;;;OAKG;IACI,KAAK,CAAC,IAAI,CAAC,IAAY;QAC5B,IAAI,OAAO,IAAI,KAAK,QAAQ,IAAI,IAAI,GAAG,CAAC,EAAE,CAAC;YACzC,MAAM,IAAI,KAAK,CAAC,yDAAyD,CAAC,CAAA;QAC5E,CAAC;QAED,OAAO,IAAI,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC,CAAA;IAC1D,CAAC;CACF;AAED,OAAO,EAAE,QAAQ,EAAE,eAAe,EAAE,CAAA"}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=switchbot-ble.test.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"switchbot-ble.test.d.ts","sourceRoot":"","sources":["../src/switchbot-ble.test.ts"],"names":[],"mappings":""}
@@ -1,32 +0,0 @@
1
- import { describe, expect, it } from 'vitest';
2
- import { LogLevel, SwitchBotBLE } from './switchbot-ble';
3
- describe('switchBotBLE', () => {
4
- describe('constructor', () => {
5
- it('should create an instance without parameters', () => {
6
- const switchbot = new SwitchBotBLE();
7
- expect(switchbot).toBeInstanceOf(SwitchBotBLE);
8
- expect(switchbot.nobleInitialized).toBeInstanceOf(Promise);
9
- });
10
- it('should create an instance with parameters', () => {
11
- const params = { duration: 5000 };
12
- const switchbot = new SwitchBotBLE(params);
13
- expect(switchbot).toBeInstanceOf(SwitchBotBLE);
14
- expect(switchbot.nobleInitialized).toBeInstanceOf(Promise);
15
- });
16
- });
17
- it('should emit log events asynchronously', async () => {
18
- const sw = new SwitchBotBLE();
19
- // Listen for a single 'log' event
20
- const eventPromise = new Promise((resolve) => {
21
- sw.once('log', (event) => {
22
- resolve(event);
23
- });
24
- });
25
- sw.log(LogLevel.INFO, 'test message');
26
- const event = (await eventPromise);
27
- expect(event.level).toBe('info');
28
- expect(event.message).toBe('test message');
29
- expect(event.message).toBe('test message');
30
- });
31
- });
32
- //# sourceMappingURL=switchbot-ble.test.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"switchbot-ble.test.js","sourceRoot":"","sources":["../src/switchbot-ble.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAA;AAE7C,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAA;AAExD,QAAQ,CAAC,cAAc,EAAE,GAAG,EAAE;IAC5B,QAAQ,CAAC,aAAa,EAAE,GAAG,EAAE;QAC3B,EAAE,CAAC,8CAA8C,EAAE,GAAG,EAAE;YACtD,MAAM,SAAS,GAAG,IAAI,YAAY,EAAE,CAAA;YACpC,MAAM,CAAC,SAAS,CAAC,CAAC,cAAc,CAAC,YAAY,CAAC,CAAA;YAC9C,MAAM,CAAC,SAAS,CAAC,gBAAgB,CAAC,CAAC,cAAc,CAAC,OAAO,CAAC,CAAA;QAC5D,CAAC,CAAC,CAAA;QAEF,EAAE,CAAC,2CAA2C,EAAE,GAAG,EAAE;YACnD,MAAM,MAAM,GAAG,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAA;YACjC,MAAM,SAAS,GAAG,IAAI,YAAY,CAAC,MAAM,CAAC,CAAA;YAC1C,MAAM,CAAC,SAAS,CAAC,CAAC,cAAc,CAAC,YAAY,CAAC,CAAA;YAC9C,MAAM,CAAC,SAAS,CAAC,gBAAgB,CAAC,CAAC,cAAc,CAAC,OAAO,CAAC,CAAA;QAC5D,CAAC,CAAC,CAAA;IACJ,CAAC,CAAC,CAAA;IAEF,EAAE,CAAC,uCAAuC,EAAE,KAAK,IAAI,EAAE;QACrD,MAAM,EAAE,GAAG,IAAI,YAAY,EAAE,CAAA;QAC7B,kCAAkC;QAClC,MAAM,YAAY,GAAG,IAAI,OAAO,CAAqC,CAAC,OAAO,EAAE,EAAE;YAC/E,EAAE,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC,KAAK,EAAE,EAAE;gBACvB,OAAO,CAAC,KAAK,CAAC,CAAA;YAChB,CAAC,CAAC,CAAA;QACJ,CAAC,CAAC,CAAA;QACF,EAAE,CAAC,GAAG,CAAC,QAAQ,CAAC,IAAI,EAAE,cAAc,CAAC,CAAA;QACrC,MAAM,KAAK,GAAG,CAAC,MAAM,YAAY,CAAuC,CAAA;QACxE,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA;QAChC,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,cAAc,CAAC,CAAA;QAC1C,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,cAAc,CAAC,CAAA;IAC5C,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA"}
@@ -1,139 +0,0 @@
1
- import type { Server } from 'node:http';
2
- import type { commandType, devices, deviceStatus, deviceStatusRequest, pushResponseBody } from './types/openapi.js';
3
- import { EventEmitter } from 'node:events';
4
- /**
5
- * The `SwitchBotOpenAPI` class provides methods to interact with the SwitchBot OpenAPI.
6
- * It allows you to retrieve device information, control devices, and manage webhooks.
7
- *
8
- * @extends EventEmitter
9
- *
10
- * @example
11
- * ```typescript
12
- * const switchBotAPI = new SwitchBotOpenAPI('your-token', 'your-secret');
13
- *
14
- * // Get devices
15
- * switchBotAPI.getDevices().then(response => {
16
- * console.log(response);
17
- * }).catch(error => {
18
- * console.error(error);
19
- * });
20
- *
21
- * // Control a device
22
- * switchBotAPI.controlDevice('device-id', 'turnOn', 'default').then(response => {
23
- * console.log(response);
24
- * }).catch(error => {
25
- * console.error(error);
26
- * });
27
- *
28
- * // Setup webhook
29
- * switchBotAPI.setupWebhook('http://your-webhook-url').then(() => {
30
- * console.log('Webhook setup successfully');
31
- * }).catch(error => {
32
- * console.error(error);
33
- * });
34
- * ```
35
- *
36
- * @param {string} token - The API token used for authentication.
37
- * @param {string} secret - The secret key used for signing requests.
38
- */
39
- export declare class SwitchBotOpenAPI extends EventEmitter {
40
- private token;
41
- private secret;
42
- webhookEventListener?: Server | null;
43
- /**
44
- * Creates an instance of the SwitchBot OpenAPI client.
45
- *
46
- * @param token - The API token used for authentication.
47
- * @param secret - The secret key used for signing requests.
48
- */
49
- constructor(token: string, secret: string, hostname?: string);
50
- /**
51
- * Emits a log event with the specified log level and message.
52
- *
53
- * @param level - The severity level of the log (e.g., 'info', 'warn', 'error').
54
- * @param message - The log message to be emitted.
55
- */
56
- private emitLog;
57
- /**
58
- * Generates the headers required for authentication with the SwitchBot OpenAPI.
59
- *
60
- * @param configToken - The token used for authorization.
61
- * @param configSecret - The secret key used to sign the request.
62
- * @returns An object containing the necessary headers:
63
- * - `Authorization`: The authorization token.
64
- * - `sign`: The HMAC-SHA256 signature of the token, timestamp, and nonce.
65
- * - `nonce`: A unique identifier for the request.
66
- * - `t`: The current timestamp in milliseconds.
67
- * - `Content-Type`: The content type of the request, set to 'application/json'.
68
- */
69
- private generateHeaders;
70
- /**
71
- * Retrieves the list of devices from the SwitchBot OpenAPI.
72
- * @param token - (Optional) The token used for authentication. If not provided, the instance token will be used.
73
- * @param secret - (Optional) The secret used for authentication. If not provided, the instance secret will be used.
74
- * @returns {Promise<{ response: body, statusCode: number }>} A promise that resolves to an object containing the API response.
75
- * @throws {Error} Throws an error if the request to get devices fails.
76
- */
77
- getDevices(token?: string, secret?: string): Promise<{
78
- response: devices;
79
- statusCode: number;
80
- }>;
81
- /**
82
- * Controls a device by sending a command to the SwitchBot API.
83
- *
84
- * @param deviceId - The ID of the device to control.
85
- * @param command - The command to send to the device.
86
- * @param parameter - The parameter for the command.
87
- * @param commandType - The type of the command (default is 'command').
88
- * @param token - (Optional) The token used for authentication. If not provided, the instance token will be used.
89
- * @param secret - (Optional) The secret used for authentication. If not provided, the instance secret will be used.
90
- * @returns A promise that resolves to an object containing the response body and status code.
91
- * @throws An error if the device control fails.
92
- */
93
- controlDevice(deviceId: string, command: string, parameter: string, commandType?: commandType, token?: string, secret?: string): Promise<{
94
- response: pushResponseBody;
95
- statusCode: number;
96
- }>;
97
- /**
98
- * Retrieves the status of a specific device.
99
- *
100
- * @param deviceId - The unique identifier of the device.
101
- * @param token - (Optional) The token used for authentication. If not provided, the instance token will be used.
102
- * @param secret - (Optional) The secret used for authentication. If not provided, the instance secret will be used.
103
- * @returns A promise that resolves to an object containing the device status and the status code of the request.
104
- * @throws An error if the request fails.
105
- */
106
- getDeviceStatus(deviceId: string, token?: string, secret?: string): Promise<{
107
- response: deviceStatus;
108
- statusCode: deviceStatusRequest['statusCode'];
109
- }>;
110
- /**
111
- * Sets up a webhook listener and configures the webhook on the server.
112
- *
113
- * This method performs the following steps:
114
- * 1. Creates a local server to listen for incoming webhook events.
115
- * 2. Sends a request to set up the webhook with the provided URL.
116
- * 3. Sends a request to update the webhook configuration.
117
- * 4. Sends a request to query the current webhook URL.
118
- *
119
- * @param url - The URL to which the webhook events will be sent.
120
- * @param token - (Optional) The token used for authentication. If not provided, the instance token will be used.
121
- * @param secret - (Optional) The secret used for authentication. If not provided, the instance secret will be used.
122
- * @returns A promise that resolves when the webhook setup is complete.
123
- *
124
- * @throws Will log an error if any step in the webhook setup process fails.
125
- */
126
- setupWebhook(url: string, token?: string, secret?: string): Promise<void>;
127
- /**
128
- * Deletes a webhook by sending a request to the specified URL.
129
- *
130
- * @param url - The URL of the webhook to be deleted.
131
- * @param token - (Optional) The token used for authentication. If not provided, the instance token will be used.
132
- * @param secret - (Optional) The secret used for authentication. If not provided, the instance secret will be used.
133
- * @returns A promise that resolves when the webhook is successfully deleted.
134
- *
135
- * @throws Will log an error if the deletion fails.
136
- */
137
- deleteWebhook(url: string, token?: string, secret?: string): Promise<void>;
138
- }
139
- //# sourceMappingURL=switchbot-openapi.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,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