node-switchbot 3.6.6 → 4.0.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (551) hide show
  1. package/.github/npm-version-script-esm.js +97 -0
  2. package/CHANGELOG.md +322 -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 +87 -0
  146. package/dist/switchbot.d.ts.map +1 -0
  147. package/dist/switchbot.js +422 -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 -348
  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 +22 -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 -6
  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 +12 -21
  299. package/.github/scripts/npm-version-script-esm-auto.js +0 -207
  300. package/dist/device.d.ts +0 -1626
  301. package/dist/device.d.ts.map +0 -1
  302. package/dist/device.js +0 -3602
  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 -336
  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 -320
  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 -638
  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/WoPlugMiniEU.html +0 -84
  360. package/docs/classes/WoSmartLockUltra.html +0 -113
  361. package/docs/enums/SwitchBotBLEModelFriendlyName.html +0 -39
  362. package/docs/enums/SwitchBotModel.html +0 -53
  363. package/docs/interfaces/AdvertisementData.html +0 -3
  364. package/docs/interfaces/Chars.html +0 -4
  365. package/docs/interfaces/ColorLightServiceDataBase.html +0 -17
  366. package/docs/interfaces/ErrorObject.html +0 -3
  367. package/docs/interfaces/LockBaseServiceData.html +0 -15
  368. package/docs/interfaces/NobleTypes.html +0 -3
  369. package/docs/interfaces/Params.html +0 -6
  370. package/docs/interfaces/PlugMiniServiceDataBase.html +0 -12
  371. package/docs/interfaces/Rule.html +0 -9
  372. package/docs/interfaces/ServiceData.html +0 -2
  373. package/docs/interfaces/SwitchBotBLEDevice.html +0 -28
  374. package/docs/interfaces/SwitchBotScanner.html +0 -6
  375. package/docs/interfaces/TemperatureServiceDataBase.html +0 -10
  376. package/docs/interfaces/WebhookDetail.html +0 -6
  377. package/docs/interfaces/ad.html +0 -5
  378. package/docs/interfaces/body.html +0 -3
  379. package/docs/interfaces/bodyChange.html +0 -4
  380. package/docs/interfaces/deleteWebhookResponse.html +0 -4
  381. package/docs/interfaces/device.html +0 -7
  382. package/docs/interfaces/deviceList.html +0 -2
  383. package/docs/interfaces/deviceStatus.html +0 -7
  384. package/docs/interfaces/deviceStatusRequest.html +0 -4
  385. package/docs/interfaces/deviceWebhook.html +0 -4
  386. package/docs/interfaces/deviceWebhookContext.html +0 -4
  387. package/docs/interfaces/devices.html +0 -4
  388. package/docs/interfaces/infraredRemoteList.html +0 -2
  389. package/docs/interfaces/irdevice.html +0 -5
  390. package/docs/interfaces/pushRequest.html +0 -5
  391. package/docs/interfaces/pushResponse.html +0 -5
  392. package/docs/interfaces/pushResponseBody.html +0 -3
  393. package/docs/interfaces/queryWebhookResponse.html +0 -4
  394. package/docs/interfaces/setupWebhookResponse.html +0 -4
  395. package/docs/interfaces/updateWebhookResponse.html +0 -4
  396. package/docs/interfaces/webhookRequest.html +0 -4
  397. package/docs/types/BLEDeviceServiceData.html +0 -1
  398. package/docs/types/IndoorCam.html +0 -1
  399. package/docs/types/MacAddress.html +0 -1
  400. package/docs/types/airPurifier.html +0 -1
  401. package/docs/types/airPurifierPM25WebhookContext.html +0 -1
  402. package/docs/types/airPurifierServiceData.html +0 -1
  403. package/docs/types/airPurifierStatus.html +0 -1
  404. package/docs/types/airPurifierTable.html +0 -1
  405. package/docs/types/airPurifierTablePM25WebhookContext.html +0 -1
  406. package/docs/types/airPurifierTableServiceData.html +0 -1
  407. package/docs/types/airPurifierTableStatus.html +0 -1
  408. package/docs/types/airPurifierTableVOC.html +0 -1
  409. package/docs/types/airPurifierTableVOCStatus.html +0 -1
  410. package/docs/types/airPurifierTableVOCWebhookContext.html +0 -1
  411. package/docs/types/airPurifierTableWebhookContext.html +0 -1
  412. package/docs/types/airPurifierVOC.html +0 -1
  413. package/docs/types/airPurifierVOCStatus.html +0 -1
  414. package/docs/types/airPurifierVOCWebhookContext.html +0 -1
  415. package/docs/types/airPurifierWebhookContext.html +0 -1
  416. package/docs/types/batteryCirculatorFan.html +0 -1
  417. package/docs/types/batteryCirculatorFanServiceData.html +0 -1
  418. package/docs/types/batteryCirculatorFanStatus.html +0 -1
  419. package/docs/types/batteryCirculatorFanWebhookContext.html +0 -1
  420. package/docs/types/blindTilt.html +0 -1
  421. package/docs/types/blindTiltServiceData.html +0 -1
  422. package/docs/types/blindTiltStatus.html +0 -1
  423. package/docs/types/blindTiltWebhookContext.html +0 -1
  424. package/docs/types/bot.html +0 -1
  425. package/docs/types/botServiceData.html +0 -1
  426. package/docs/types/botStatus.html +0 -1
  427. package/docs/types/botWebhookContext.html +0 -1
  428. package/docs/types/ceilingLight.html +0 -1
  429. package/docs/types/ceilingLightPro.html +0 -1
  430. package/docs/types/ceilingLightProServiceData.html +0 -1
  431. package/docs/types/ceilingLightProStatus.html +0 -1
  432. package/docs/types/ceilingLightProWebhookContext.html +0 -1
  433. package/docs/types/ceilingLightServiceData.html +0 -1
  434. package/docs/types/ceilingLightStatus.html +0 -1
  435. package/docs/types/ceilingLightWebhookContext.html +0 -1
  436. package/docs/types/circulatorFanStatus.html +0 -1
  437. package/docs/types/circulatorFanWebhookContext.html +0 -1
  438. package/docs/types/colorBulb.html +0 -1
  439. package/docs/types/colorBulbServiceData.html +0 -1
  440. package/docs/types/colorBulbStatus.html +0 -1
  441. package/docs/types/colorBulbWebhookContext.html +0 -1
  442. package/docs/types/commandType.html +0 -2
  443. package/docs/types/contactSensor.html +0 -1
  444. package/docs/types/contactSensorServiceData.html +0 -1
  445. package/docs/types/contactSensorStatus.html +0 -1
  446. package/docs/types/contactSensorWebhookContext.html +0 -1
  447. package/docs/types/curtain.html +0 -1
  448. package/docs/types/curtain3.html +0 -1
  449. package/docs/types/curtain3ServiceData.html +0 -1
  450. package/docs/types/curtain3WebhookContext.html +0 -1
  451. package/docs/types/curtainServiceData.html +0 -1
  452. package/docs/types/curtainStatus.html +0 -1
  453. package/docs/types/curtainWebhookContext.html +0 -1
  454. package/docs/types/floorCleaningRobotS10.html +0 -1
  455. package/docs/types/floorCleaningRobotS10Status.html +0 -1
  456. package/docs/types/floorCleaningRobotS10WebhookContext.html +0 -1
  457. package/docs/types/hub2.html +0 -1
  458. package/docs/types/hub2ServiceData.html +0 -1
  459. package/docs/types/hub2Status.html +0 -1
  460. package/docs/types/hub2WebhookContext.html +0 -1
  461. package/docs/types/hub3ServiceData.html +0 -1
  462. package/docs/types/humidifier.html +0 -1
  463. package/docs/types/humidifier2ServiceData.html +0 -1
  464. package/docs/types/humidifier2Status.html +0 -1
  465. package/docs/types/humidifier2WebhookContext.html +0 -1
  466. package/docs/types/humidifierServiceData.html +0 -1
  467. package/docs/types/humidifierStatus.html +0 -1
  468. package/docs/types/humidifierWebhookContext.html +0 -1
  469. package/docs/types/indoorCameraWebhookContext.html +0 -1
  470. package/docs/types/keypad.html +0 -1
  471. package/docs/types/keypadDetectorServiceData.html +0 -1
  472. package/docs/types/keypadTouch.html +0 -1
  473. package/docs/types/keypadTouchWebhookContext.html +0 -1
  474. package/docs/types/keypadWebhookContext.html +0 -1
  475. package/docs/types/lock.html +0 -1
  476. package/docs/types/lockPro.html +0 -1
  477. package/docs/types/lockProServiceData.html +0 -1
  478. package/docs/types/lockProStatus.html +0 -1
  479. package/docs/types/lockProWebhookContext.html +0 -1
  480. package/docs/types/lockServiceData.html +0 -1
  481. package/docs/types/lockStatus.html +0 -1
  482. package/docs/types/lockWebhookContext.html +0 -1
  483. package/docs/types/meter.html +0 -1
  484. package/docs/types/meterPlus.html +0 -1
  485. package/docs/types/meterPlusServiceData.html +0 -1
  486. package/docs/types/meterPlusStatus.html +0 -1
  487. package/docs/types/meterPlusWebhookContext.html +0 -1
  488. package/docs/types/meterPro.html +0 -1
  489. package/docs/types/meterProCO2ServiceData.html +0 -1
  490. package/docs/types/meterProCO2Status.html +0 -1
  491. package/docs/types/meterProCO2WebhookContext.html +0 -1
  492. package/docs/types/meterProServiceData.html +0 -1
  493. package/docs/types/meterProStatus.html +0 -1
  494. package/docs/types/meterProWebhookContext.html +0 -1
  495. package/docs/types/meterServiceData.html +0 -1
  496. package/docs/types/meterStatus.html +0 -1
  497. package/docs/types/meterWebhookContext.html +0 -1
  498. package/docs/types/motionSensor.html +0 -1
  499. package/docs/types/motionSensorServiceData.html +0 -1
  500. package/docs/types/motionSensorStatus.html +0 -1
  501. package/docs/types/motionSensorWebhookContext.html +0 -1
  502. package/docs/types/onadvertisement.html +0 -1
  503. package/docs/types/ondiscover.html +0 -1
  504. package/docs/types/outdoorMeter.html +0 -1
  505. package/docs/types/outdoorMeterServiceData.html +0 -1
  506. package/docs/types/outdoorMeterStatus.html +0 -1
  507. package/docs/types/outdoorMeterWebhookContext.html +0 -1
  508. package/docs/types/panTiltCamWebhookContext.html +0 -1
  509. package/docs/types/pantiltCam.html +0 -1
  510. package/docs/types/pantiltCam2k.html +0 -1
  511. package/docs/types/plug.html +0 -1
  512. package/docs/types/plugMini.html +0 -1
  513. package/docs/types/plugMiniEUServiceData.html +0 -1
  514. package/docs/types/plugMiniEUWebhookContext.html +0 -1
  515. package/docs/types/plugMiniJPServiceData.html +0 -1
  516. package/docs/types/plugMiniJPWebhookContext.html +0 -1
  517. package/docs/types/plugMiniStatus.html +0 -1
  518. package/docs/types/plugMiniUSServiceData.html +0 -1
  519. package/docs/types/plugMiniUSWebhookContext.html +0 -1
  520. package/docs/types/plugStatus.html +0 -1
  521. package/docs/types/plugWebhookContext.html +0 -1
  522. package/docs/types/presenceSensor.html +0 -1
  523. package/docs/types/presenceSensorServiceData.html +0 -1
  524. package/docs/types/presenceSensorStatus.html +0 -1
  525. package/docs/types/presenceSensorWebhookContext.html +0 -1
  526. package/docs/types/relaySwitch1Context.html +0 -1
  527. package/docs/types/relaySwitch1PMContext.html +0 -1
  528. package/docs/types/relaySwitch1PMServiceData.html +0 -1
  529. package/docs/types/relaySwitch1PMStatus.html +0 -1
  530. package/docs/types/relaySwitch1ServiceData.html +0 -1
  531. package/docs/types/relaySwitch1Status.html +0 -1
  532. package/docs/types/remote.html +0 -1
  533. package/docs/types/remoteServiceData.html +0 -1
  534. package/docs/types/robotVacuumCleanerS1.html +0 -1
  535. package/docs/types/robotVacuumCleanerS1Plus.html +0 -1
  536. package/docs/types/robotVacuumCleanerS1PlusStatus.html +0 -1
  537. package/docs/types/robotVacuumCleanerS1PlusWebhookContext.html +0 -1
  538. package/docs/types/robotVacuumCleanerS1Status.html +0 -1
  539. package/docs/types/robotVacuumCleanerS1WebhookContext.html +0 -1
  540. package/docs/types/robotVacuumCleanerServiceData.html +0 -1
  541. package/docs/types/stripLight.html +0 -1
  542. package/docs/types/stripLightServiceData.html +0 -1
  543. package/docs/types/stripLightStatus.html +0 -1
  544. package/docs/types/stripLightWebhookContext.html +0 -1
  545. package/docs/types/waterLeakDetector.html +0 -1
  546. package/docs/types/waterLeakDetectorServiceData.html +0 -1
  547. package/docs/types/waterLeakDetectorStatus.html +0 -1
  548. package/docs/types/waterLeakDetectorWebhookContext.html +0 -1
  549. package/docs/variables/parameterChecker.html +0 -1
  550. package/eslint.config.js +0 -48
  551. package/typedoc.json +0 -17
package/dist/ble.js ADDED
@@ -0,0 +1,430 @@
1
+ /* Copyright(C) 2024-2026, donavanbecker (https://github.com/donavanbecker). All rights reserved.
2
+ *
3
+ * ble.ts: SwitchBot v4.0.0 - BLE Discovery and Communication
4
+ */
5
+ import { EventEmitter } from 'node:events';
6
+ import { BLENotAvailableError, DeviceNotFoundError } from './errors.js';
7
+ import { BLE_COMMAND_TIMEOUT, BLE_CONNECT_TIMEOUT, BLE_NOTIFY_CHARACTERISTIC_UUID, BLE_SCAN_TIMEOUT, BLE_SERVICE_UUID, BLE_WRITE_CHARACTERISTIC_UUID, DEVICE_MODEL_MAP } from './settings.js';
8
+ import { Logger, normalizeMAC, withTimeout } from './utils/index.js';
9
+ /**
10
+ * BLE Scanner for discovering SwitchBot devices
11
+ */
12
+ export class BLEScanner extends EventEmitter {
13
+ noble;
14
+ logger;
15
+ scanning = false;
16
+ discoveredDevices = new Map();
17
+ noblePromise = null;
18
+ constructor(options = {}) {
19
+ super();
20
+ this.logger = new Logger('BLEScanner', options.logLevel);
21
+ this.noble = options.noble;
22
+ if (!this.noble) {
23
+ this.initializeNoble().catch((error) => {
24
+ this.logger.error('Failed to initialize Noble', error);
25
+ });
26
+ }
27
+ else {
28
+ this.setupNobleHandlers();
29
+ }
30
+ }
31
+ /**
32
+ * Initialize Noble lazily
33
+ */
34
+ async initializeNoble() {
35
+ if (this.noble || this.noblePromise) {
36
+ return;
37
+ }
38
+ if (!this.noblePromise) {
39
+ this.noblePromise = (async () => {
40
+ try {
41
+ const module = await import('@stoprocent/noble');
42
+ return module.default;
43
+ }
44
+ catch (error) {
45
+ throw new BLENotAvailableError('BLE not supported on this platform or @stoprocent/noble not installed');
46
+ }
47
+ })();
48
+ }
49
+ try {
50
+ this.noble = await this.noblePromise;
51
+ this.setupNobleHandlers();
52
+ }
53
+ catch (error) {
54
+ throw new BLENotAvailableError('BLE not supported on this platform or @stoprocent/noble not installed');
55
+ }
56
+ }
57
+ /**
58
+ * Ensure Noble is loaded before operations
59
+ */
60
+ async ensureNoble() {
61
+ if (!this.noble) {
62
+ await this.initializeNoble();
63
+ }
64
+ }
65
+ /**
66
+ * Setup Noble event handlers
67
+ */
68
+ setupNobleHandlers() {
69
+ this.noble.on('stateChange', (state) => {
70
+ this.logger.debug('Noble state changed:', state);
71
+ this.emit('state-change', state);
72
+ if (state === 'poweredOn') {
73
+ this.emit('ready');
74
+ }
75
+ });
76
+ this.noble.on('discover', (peripheral) => {
77
+ this.handleDiscovery(peripheral);
78
+ });
79
+ this.noble.on('scanStart', () => {
80
+ this.scanning = true;
81
+ this.logger.info('BLE scan started');
82
+ this.emit('scan-start');
83
+ });
84
+ this.noble.on('scanStop', () => {
85
+ this.scanning = false;
86
+ this.logger.info('BLE scan stopped');
87
+ this.emit('scan-stop');
88
+ });
89
+ }
90
+ /**
91
+ * Handle device discovery
92
+ */
93
+ handleDiscovery(peripheral) {
94
+ try {
95
+ const { advertisement, address, rssi } = peripheral;
96
+ // Check if this is a SwitchBot device
97
+ if (!advertisement.serviceData || advertisement.serviceData.length === 0) {
98
+ return;
99
+ }
100
+ for (const serviceDataItem of advertisement.serviceData) {
101
+ // SwitchBot service UUID
102
+ if (serviceDataItem.uuid !== 'fd3d' && serviceDataItem.uuid !== '0000fd3d-0000-1000-8000-00805f9b34fb') {
103
+ continue;
104
+ }
105
+ const serviceData = this.parseServiceData(serviceDataItem.data);
106
+ if (!serviceData) {
107
+ continue;
108
+ }
109
+ const mac = normalizeMAC(address);
110
+ const advertisement = {
111
+ id: peripheral.id,
112
+ address: mac,
113
+ rssi,
114
+ serviceData,
115
+ };
116
+ this.discoveredDevices.set(mac, advertisement);
117
+ this.emit('discover', advertisement);
118
+ this.logger.debug(`Discovered ${serviceData.modelName} at ${mac}`);
119
+ }
120
+ }
121
+ catch (error) {
122
+ this.logger.error('Error handling discovery', error);
123
+ }
124
+ }
125
+ /**
126
+ * Parse service data from BLE advertisement
127
+ */
128
+ parseServiceData(data) {
129
+ if (!data || data.length < 1) {
130
+ return null;
131
+ }
132
+ try {
133
+ const model = String.fromCharCode(data[0] & 0x7F);
134
+ const modelName = DEVICE_MODEL_MAP[model];
135
+ if (!modelName) {
136
+ this.logger.debug(`Unknown device model: ${model} (0x${data[0].toString(16)})`);
137
+ return null;
138
+ }
139
+ // Basic service data structure
140
+ const serviceData = {
141
+ model,
142
+ modelName,
143
+ rawData: data,
144
+ };
145
+ // Parse battery if available (common across most devices)
146
+ if (data.length > 2) {
147
+ serviceData.battery = data[2] & 0x7F;
148
+ }
149
+ return serviceData;
150
+ }
151
+ catch (error) {
152
+ this.logger.error('Error parsing service data', error);
153
+ return null;
154
+ }
155
+ }
156
+ /**
157
+ * Start scanning for devices
158
+ */
159
+ async startScan(options = {}) {
160
+ await this.ensureNoble();
161
+ const { duration = BLE_SCAN_TIMEOUT, active = true } = options;
162
+ this.logger.info('Starting BLE scan', { duration, active });
163
+ if (this.noble.state !== 'poweredOn') {
164
+ await new Promise((resolve, reject) => {
165
+ const timeout = setTimeout(() => {
166
+ reject(new Error('BLE adapter not ready'));
167
+ }, 5000);
168
+ this.once('ready', () => {
169
+ clearTimeout(timeout);
170
+ resolve();
171
+ });
172
+ });
173
+ }
174
+ // Clear previous discoveries if starting fresh
175
+ this.discoveredDevices.clear();
176
+ // Start scanning
177
+ this.noble.startScanning([], active);
178
+ // Auto-stop after duration
179
+ if (duration > 0) {
180
+ setTimeout(() => {
181
+ if (this.scanning) {
182
+ this.stopScan();
183
+ }
184
+ }, duration);
185
+ }
186
+ }
187
+ /**
188
+ * Stop scanning
189
+ */
190
+ stopScan() {
191
+ if (this.scanning) {
192
+ this.noble.stopScanning();
193
+ }
194
+ }
195
+ /**
196
+ * Get all discovered devices
197
+ */
198
+ getDiscoveredDevices() {
199
+ return Array.from(this.discoveredDevices.values());
200
+ }
201
+ /**
202
+ * Get discovered device by MAC
203
+ */
204
+ getDevice(mac) {
205
+ return this.discoveredDevices.get(normalizeMAC(mac));
206
+ }
207
+ /**
208
+ * Check if currently scanning
209
+ */
210
+ isScanning() {
211
+ return this.scanning;
212
+ }
213
+ /**
214
+ * Wait for specific device
215
+ */
216
+ async waitForDevice(mac, timeoutMs = BLE_SCAN_TIMEOUT) {
217
+ const normalizedMac = normalizeMAC(mac);
218
+ // Check if already discovered
219
+ const existing = this.discoveredDevices.get(normalizedMac);
220
+ if (existing) {
221
+ return existing;
222
+ }
223
+ // Wait for discovery
224
+ return withTimeout(new Promise((resolve) => {
225
+ const handler = (advertisement) => {
226
+ if (normalizeMAC(advertisement.address) === normalizedMac) {
227
+ this.off('discover', handler);
228
+ resolve(advertisement);
229
+ }
230
+ };
231
+ this.on('discover', handler);
232
+ }), timeoutMs, `Device ${mac} not found within ${timeoutMs}ms`);
233
+ }
234
+ }
235
+ /**
236
+ * BLE Connection for communicating with SwitchBot devices
237
+ */
238
+ export class BLEConnection {
239
+ noble;
240
+ logger;
241
+ connections = new Map(); // Map of MAC -> Peripheral
242
+ characteristics = new Map();
243
+ noblePromise = null;
244
+ constructor(options = {}) {
245
+ this.logger = new Logger('BLEConnection', options.logLevel);
246
+ this.noble = options.noble;
247
+ if (!this.noble) {
248
+ this.initializeNoble().catch((error) => {
249
+ this.logger.error('Failed to initialize Noble', error);
250
+ });
251
+ }
252
+ }
253
+ /**
254
+ * Initialize Noble lazily
255
+ */
256
+ async initializeNoble() {
257
+ if (this.noble || this.noblePromise) {
258
+ return;
259
+ }
260
+ if (!this.noblePromise) {
261
+ this.noblePromise = (async () => {
262
+ try {
263
+ const module = await import('@stoprocent/noble');
264
+ return module.default;
265
+ }
266
+ catch (error) {
267
+ throw new BLENotAvailableError('BLE not supported on this platform or @stoprocent/noble not installed');
268
+ }
269
+ })();
270
+ }
271
+ try {
272
+ this.noble = await this.noblePromise;
273
+ }
274
+ catch (error) {
275
+ throw new BLENotAvailableError('BLE not supported on this platform or @stoprocent/noble not installed');
276
+ }
277
+ }
278
+ /**
279
+ * Ensure Noble is loaded before operations
280
+ */
281
+ async ensureNoble() {
282
+ if (!this.noble) {
283
+ await this.initializeNoble();
284
+ }
285
+ }
286
+ /**
287
+ * Connect to a device
288
+ */
289
+ async connect(mac) {
290
+ await this.ensureNoble();
291
+ const normalizedMac = normalizeMAC(mac);
292
+ // Already connected?
293
+ if (this.connections.has(normalizedMac)) {
294
+ this.logger.debug(`Already connected to ${mac}`);
295
+ return;
296
+ }
297
+ this.logger.info(`Connecting to ${mac}`);
298
+ // Find peripheral
299
+ const peripherals = await this.noble.peripherals || [];
300
+ const peripheral = peripherals.find((p) => normalizeMAC(p.address) === normalizedMac);
301
+ if (!peripheral) {
302
+ throw new DeviceNotFoundError(mac);
303
+ }
304
+ // Connect
305
+ await withTimeout(new Promise((resolve, reject) => {
306
+ peripheral.connect((error) => {
307
+ if (error) {
308
+ reject(error);
309
+ }
310
+ else {
311
+ resolve();
312
+ }
313
+ });
314
+ }), BLE_CONNECT_TIMEOUT, `Connection to ${mac} timed out`);
315
+ this.connections.set(normalizedMac, peripheral);
316
+ this.logger.info(`Connected to ${mac}`);
317
+ // Discover characteristics
318
+ await this.discoverCharacteristics(normalizedMac, peripheral);
319
+ }
320
+ /**
321
+ * Discover service characteristics
322
+ */
323
+ async discoverCharacteristics(mac, peripheral) {
324
+ const { characteristics } = await withTimeout(new Promise((resolve, reject) => {
325
+ peripheral.discoverSomeServicesAndCharacteristics([BLE_SERVICE_UUID], [BLE_WRITE_CHARACTERISTIC_UUID, BLE_NOTIFY_CHARACTERISTIC_UUID], (error, services, chars) => {
326
+ if (error) {
327
+ reject(error);
328
+ }
329
+ else {
330
+ resolve({ services, characteristics: chars });
331
+ }
332
+ });
333
+ }), BLE_CONNECT_TIMEOUT, 'Characteristic discovery timed out');
334
+ const writeChar = characteristics.find((c) => c.uuid === BLE_WRITE_CHARACTERISTIC_UUID.replace(/-/g, ''));
335
+ const notifyChar = characteristics.find((c) => c.uuid === BLE_NOTIFY_CHARACTERISTIC_UUID.replace(/-/g, ''));
336
+ if (!writeChar || !notifyChar) {
337
+ throw new Error('Required characteristics not found');
338
+ }
339
+ this.characteristics.set(mac, { write: writeChar, notify: notifyChar });
340
+ this.logger.debug(`Characteristics discovered for ${mac}`);
341
+ }
342
+ /**
343
+ * Disconnect from a device
344
+ */
345
+ async disconnect(mac) {
346
+ const normalizedMac = normalizeMAC(mac);
347
+ const peripheral = this.connections.get(normalizedMac);
348
+ if (!peripheral) {
349
+ return;
350
+ }
351
+ await new Promise((resolve) => {
352
+ peripheral.disconnect(() => {
353
+ this.connections.delete(normalizedMac);
354
+ this.characteristics.delete(normalizedMac);
355
+ this.logger.info(`Disconnected from ${mac}`);
356
+ resolve();
357
+ });
358
+ });
359
+ }
360
+ /**
361
+ * Write data to device
362
+ */
363
+ async write(mac, data) {
364
+ const normalizedMac = normalizeMAC(mac);
365
+ // Ensure connected
366
+ if (!this.connections.has(normalizedMac)) {
367
+ await this.connect(mac);
368
+ }
369
+ const chars = this.characteristics.get(normalizedMac);
370
+ if (!chars) {
371
+ throw new Error(`Characteristics not available for ${mac}`);
372
+ }
373
+ this.logger.debug(`Writing to ${mac}:`, data.toString('hex'));
374
+ await withTimeout(new Promise((resolve, reject) => {
375
+ chars.write.write(data, false, (error) => {
376
+ if (error) {
377
+ reject(error);
378
+ }
379
+ else {
380
+ resolve();
381
+ }
382
+ });
383
+ }), BLE_COMMAND_TIMEOUT, 'Write operation timed out');
384
+ }
385
+ /**
386
+ * Read data from device
387
+ */
388
+ async read(mac) {
389
+ const normalizedMac = normalizeMAC(mac);
390
+ // Ensure connected
391
+ if (!this.connections.has(normalizedMac)) {
392
+ await this.connect(mac);
393
+ }
394
+ const chars = this.characteristics.get(normalizedMac);
395
+ if (!chars) {
396
+ throw new Error(`Characteristics not available for ${mac}`);
397
+ }
398
+ this.logger.debug(`Reading from ${mac}`);
399
+ return withTimeout(new Promise((resolve, reject) => {
400
+ chars.notify.read((error, data) => {
401
+ if (error) {
402
+ reject(error);
403
+ }
404
+ else {
405
+ resolve(data);
406
+ }
407
+ });
408
+ }), BLE_COMMAND_TIMEOUT, 'Read operation timed out');
409
+ }
410
+ /**
411
+ * Check if connected to device
412
+ */
413
+ isConnected(mac) {
414
+ return this.connections.has(normalizeMAC(mac));
415
+ }
416
+ /**
417
+ * Disconnect all devices
418
+ */
419
+ async disconnectAll() {
420
+ const macs = Array.from(this.connections.keys());
421
+ await Promise.all(macs.map(mac => this.disconnect(mac)));
422
+ }
423
+ /**
424
+ * Get connected device count
425
+ */
426
+ getConnectionCount() {
427
+ return this.connections.size;
428
+ }
429
+ }
430
+ //# sourceMappingURL=ble.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ble.js","sourceRoot":"","sources":["../src/ble.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAMH,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAE1C,OAAO,EAAE,oBAAoB,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAA;AACvE,OAAO,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,8BAA8B,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,6BAA6B,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAA;AAC7L,OAAO,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,CAAA;gBACf,CAAC;qBAAM,CAAC;oBACN,OAAO,CAAC,IAAI,CAAC,CAAA;gBACf,CAAC;YACH,CAAC,CAAC,CAAA;QACJ,CAAC,CAAC,EACF,mBAAmB,EACnB,0BAA0B,CAC3B,CAAA;IACH,CAAC;IAED;;OAEG;IACH,WAAW,CAAC,GAAW;QACrB,OAAO,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,YAAY,CAAC,GAAG,CAAC,CAAC,CAAA;IAChD,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,aAAa;QACjB,MAAM,IAAI,GAAG,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,IAAI,EAAE,CAAC,CAAA;QAChD,MAAM,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,CAAA;IAC1D,CAAC;IAED;;OAEG;IACH,kBAAkB;QAChB,OAAO,IAAI,CAAC,WAAW,CAAC,IAAI,CAAA;IAC9B,CAAC;CACF"}
@@ -0,0 +1,146 @@
1
+ import type { OpenAPIClient } from '../api.js';
2
+ import type { BLEConnection } from '../ble.js';
3
+ import type { CommandResult, ConnectionType, DeviceInfo, DeviceStatus } from '../types/index.js';
4
+ import { Buffer } from 'node:buffer';
5
+ import { EventEmitter } from 'node:events';
6
+ import { Logger } from '../utils/index.js';
7
+ /**
8
+ * Base class for all SwitchBot devices
9
+ * Provides hybrid BLE/API functionality with automatic fallback
10
+ */
11
+ export declare abstract class SwitchBotDevice extends EventEmitter {
12
+ protected info: DeviceInfo;
13
+ protected logger: Logger;
14
+ protected bleConnection?: BLEConnection;
15
+ protected apiClient?: OpenAPIClient;
16
+ protected enableFallback: boolean;
17
+ protected preferredConnection: ConnectionType;
18
+ constructor(info: DeviceInfo, options?: {
19
+ bleConnection?: BLEConnection;
20
+ apiClient?: OpenAPIClient;
21
+ enableFallback?: boolean;
22
+ preferredConnection?: ConnectionType;
23
+ logLevel?: number;
24
+ });
25
+ /**
26
+ * Get device information
27
+ */
28
+ getInfo(): DeviceInfo;
29
+ /**
30
+ * Get device ID
31
+ */
32
+ getId(): string;
33
+ /**
34
+ * Get device name
35
+ */
36
+ getName(): string;
37
+ /**
38
+ * Get device type
39
+ */
40
+ getDeviceType(): string;
41
+ /**
42
+ * Get MAC address (if available)
43
+ */
44
+ getMAC(): string | undefined;
45
+ /**
46
+ * Get active connection type
47
+ */
48
+ getActiveConnection(): ConnectionType | undefined;
49
+ /**
50
+ * Check if BLE is available for this device
51
+ */
52
+ hasBLE(): boolean;
53
+ /**
54
+ * Check if API is available for this device
55
+ */
56
+ hasAPI(): boolean;
57
+ /**
58
+ * Get device status (abstract - implemented by subclasses)
59
+ */
60
+ abstract getStatus(): Promise<DeviceStatus>;
61
+ /**
62
+ * Send a command via BLE
63
+ */
64
+ protected sendBLECommand(command: readonly number[] | number[] | Buffer): Promise<CommandResult>;
65
+ /**
66
+ * Send a command via OpenAPI
67
+ */
68
+ protected sendAPICommand(command: string, parameter?: any): Promise<CommandResult>;
69
+ /**
70
+ * Send a command with automatic BLE/API fallback
71
+ */
72
+ protected sendCommand(bleCommand: readonly number[] | number[] | Buffer, apiCommand: string, apiParameter?: any): Promise<CommandResult>;
73
+ /**
74
+ * Get device status via BLE
75
+ */
76
+ protected getBLEStatus(): Promise<any>;
77
+ /**
78
+ * Get device status via OpenAPI
79
+ */
80
+ protected getAPIStatus(): Promise<any>;
81
+ /**
82
+ * Update device information
83
+ */
84
+ updateInfo(newInfo: Partial<DeviceInfo>): void;
85
+ /**
86
+ * Set preferred connection type
87
+ */
88
+ setPreferredConnection(type: ConnectionType): void;
89
+ /**
90
+ * Enable or disable fallback
91
+ */
92
+ setFallbackEnabled(enabled: boolean): void;
93
+ }
94
+ /**
95
+ * Device Manager for managing multiple devices
96
+ */
97
+ export declare class DeviceManager extends EventEmitter {
98
+ private devices;
99
+ private logger;
100
+ constructor(logLevel?: number);
101
+ /**
102
+ * Add a device to the manager
103
+ */
104
+ add(device: SwitchBotDevice): void;
105
+ /**
106
+ * Remove a device from the manager
107
+ */
108
+ remove(deviceId: string): boolean;
109
+ /**
110
+ * Get a device by ID
111
+ */
112
+ get(deviceId: string): SwitchBotDevice | undefined;
113
+ /**
114
+ * Get all devices
115
+ */
116
+ list(): SwitchBotDevice[];
117
+ /**
118
+ * Get devices filtered by type
119
+ */
120
+ getByType(deviceType: string): SwitchBotDevice[];
121
+ /**
122
+ * Get device by MAC address
123
+ */
124
+ getByMAC(mac: string): SwitchBotDevice | undefined;
125
+ /**
126
+ * Check if device exists
127
+ */
128
+ has(deviceId: string): boolean;
129
+ /**
130
+ * Get device count
131
+ */
132
+ count(): number;
133
+ /**
134
+ * Clear all devices
135
+ */
136
+ clear(): void;
137
+ /**
138
+ * Get all device IDs
139
+ */
140
+ getIds(): string[];
141
+ /**
142
+ * Get devices as an object keyed by ID
143
+ */
144
+ toObject(): Record<string, SwitchBotDevice>;
145
+ }
146
+ //# sourceMappingURL=base.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"base.d.ts","sourceRoot":"","sources":["../../src/devices/base.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,WAAW,CAAA;AAC9C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,WAAW,CAAA;AAC9C,OAAO,KAAK,EAAE,aAAa,EAAE,cAAc,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAEhG,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AACpC,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAG1C,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAA;AAE1C;;;GAGG;AACH,8BAAsB,eAAgB,SAAQ,YAAY;IAQtD,SAAS,CAAC,IAAI,EAAE,UAAU;IAP5B,SAAS,CAAC,MAAM,EAAE,MAAM,CAAA;IACxB,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