node-switchbot 3.6.6 → 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 (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 +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 -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 +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 -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 +11 -20
  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
@@ -1,375 +0,0 @@
1
- import crypto, { randomUUID } from 'node:crypto';
2
- import { EventEmitter } from 'node:events';
3
- import { createServer } from 'node:http';
4
- import { request } from 'undici';
5
- import { updateBaseURL, urls } from './settings.js';
6
- /**
7
- * Custom error class for API errors.
8
- */
9
- class APIError extends Error {
10
- statusCode;
11
- constructor(message, statusCode) {
12
- super(message);
13
- this.statusCode = statusCode;
14
- this.name = 'APIError';
15
- }
16
- }
17
- /**
18
- * The `SwitchBotOpenAPI` class provides methods to interact with the SwitchBot OpenAPI.
19
- * It allows you to retrieve device information, control devices, and manage webhooks.
20
- *
21
- * @extends EventEmitter
22
- *
23
- * @example
24
- * ```typescript
25
- * const switchBotAPI = new SwitchBotOpenAPI('your-token', 'your-secret');
26
- *
27
- * // Get devices
28
- * switchBotAPI.getDevices().then(response => {
29
- * console.log(response);
30
- * }).catch(error => {
31
- * console.error(error);
32
- * });
33
- *
34
- * // Control a device
35
- * switchBotAPI.controlDevice('device-id', 'turnOn', 'default').then(response => {
36
- * console.log(response);
37
- * }).catch(error => {
38
- * console.error(error);
39
- * });
40
- *
41
- * // Setup webhook
42
- * switchBotAPI.setupWebhook('http://your-webhook-url').then(() => {
43
- * console.log('Webhook setup successfully');
44
- * }).catch(error => {
45
- * console.error(error);
46
- * });
47
- * ```
48
- *
49
- * @param {string} token - The API token used for authentication.
50
- * @param {string} secret - The secret key used for signing requests.
51
- */
52
- export class SwitchBotOpenAPI extends EventEmitter {
53
- token;
54
- secret;
55
- webhookEventListener = null;
56
- /**
57
- * Creates an instance of the SwitchBot OpenAPI client.
58
- *
59
- * @param token - The API token used for authentication.
60
- * @param secret - The secret key used for signing requests.
61
- */
62
- constructor(token, secret, hostname) {
63
- super();
64
- this.token = token;
65
- this.secret = secret;
66
- // Log instance creation and token (secret is hidden)
67
- this.emitLog('info', 'SwitchBotOpenAPI instance created');
68
- this.emitLog('debug', `Token: ${token}`);
69
- // Update baseURL if custom hostname provided
70
- if (hostname) {
71
- updateBaseURL(hostname);
72
- }
73
- }
74
- /**
75
- * Emits a log event with the specified log level and message.
76
- *
77
- * @param level - The severity level of the log (e.g., 'info', 'warn', 'error').
78
- * @param message - The log message to be emitted.
79
- */
80
- async emitLog(level, message) {
81
- this.emit('log', { level, message });
82
- }
83
- /**
84
- * Generates the headers required for authentication with the SwitchBot OpenAPI.
85
- *
86
- * @param configToken - The token used for authorization.
87
- * @param configSecret - The secret key used to sign the request.
88
- * @returns An object containing the necessary headers:
89
- * - `Authorization`: The authorization token.
90
- * - `sign`: The HMAC-SHA256 signature of the token, timestamp, and nonce.
91
- * - `nonce`: A unique identifier for the request.
92
- * - `t`: The current timestamp in milliseconds.
93
- * - `Content-Type`: The content type of the request, set to 'application/json'.
94
- */
95
- generateHeaders = (configToken, configSecret) => {
96
- const t = Date.now().toString();
97
- const nonce = randomUUID();
98
- const data = configToken + t + nonce;
99
- const sign = crypto
100
- .createHmac('sha256', configSecret)
101
- .update(data)
102
- .digest('base64');
103
- return {
104
- 'Authorization': configToken,
105
- 'sign': sign,
106
- 'nonce': nonce,
107
- 't': t,
108
- 'Content-Type': 'application/json',
109
- };
110
- };
111
- /**
112
- * Retrieves the list of devices from the SwitchBot OpenAPI.
113
- * @param token - (Optional) The token used for authentication. If not provided, the instance token will be used.
114
- * @param secret - (Optional) The secret used for authentication. If not provided, the instance secret will be used.
115
- * @returns {Promise<{ response: body, statusCode: number }>} A promise that resolves to an object containing the API response.
116
- * @throws {Error} Throws an error if the request to get devices fails.
117
- */
118
- async getDevices(token, secret) {
119
- const url = urls.devicesURL;
120
- try {
121
- const configToken = token || this.token;
122
- const configSecret = secret || this.secret;
123
- const { body, statusCode } = await request(url, { headers: this.generateHeaders(configToken, configSecret) });
124
- const response = await body.json();
125
- this.emitLog('debug', `Got devices: ${JSON.stringify(response)}`);
126
- this.emitLog('debug', `statusCode: ${statusCode}`);
127
- return { response, statusCode };
128
- }
129
- catch (e) {
130
- this.emitLog('error', `Failed to get devices: ${e.message ?? e}`);
131
- throw new APIError(`Failed to get devices: ${e.message ?? e}`, e.statusCode);
132
- }
133
- }
134
- /**
135
- * Controls a device by sending a command to the SwitchBot API.
136
- *
137
- * @param deviceId - The ID of the device to control.
138
- * @param command - The command to send to the device.
139
- * @param parameter - The parameter for the command.
140
- * @param commandType - The type of the command (default is 'command').
141
- * @param token - (Optional) The token used for authentication. If not provided, the instance token will be used.
142
- * @param secret - (Optional) The secret used for authentication. If not provided, the instance secret will be used.
143
- * @returns A promise that resolves to an object containing the response body and status code.
144
- * @throws An error if the device control fails.
145
- */
146
- async controlDevice(deviceId, command, parameter, commandType = 'command', token, secret) {
147
- try {
148
- const configToken = token || this.token;
149
- const configSecret = secret || this.secret;
150
- // Build request payload
151
- const payload = { command, parameter, commandType };
152
- const { body, statusCode } = await request(`${urls.devicesURL}/${deviceId}/commands`, {
153
- method: 'POST',
154
- headers: this.generateHeaders(configToken, configSecret),
155
- body: JSON.stringify(payload),
156
- });
157
- const response = (await body.json());
158
- this.emitLog('debug', `Controlled device: ${deviceId} with command: ${command} and parameter: ${parameter}`);
159
- this.emitLog('debug', `statusCode: ${statusCode}`);
160
- return { response, statusCode };
161
- }
162
- catch (e) {
163
- this.emitLog('error', `Failed to control device: ${e.message ?? e}`);
164
- throw new APIError(`Failed to control device: ${e.message ?? e}`, e.statusCode);
165
- }
166
- }
167
- /**
168
- * Retrieves the status of a specific device.
169
- *
170
- * @param deviceId - The unique identifier of the device.
171
- * @param token - (Optional) The token used for authentication. If not provided, the instance token will be used.
172
- * @param secret - (Optional) The secret used for authentication. If not provided, the instance secret will be used.
173
- * @returns A promise that resolves to an object containing the device status and the status code of the request.
174
- * @throws An error if the request fails.
175
- */
176
- async getDeviceStatus(deviceId, token, secret) {
177
- try {
178
- const configToken = token || this.token;
179
- const configSecret = secret || this.secret;
180
- const { body, statusCode } = await request(`${urls.devicesURL}/${deviceId}/status`, { headers: this.generateHeaders(configToken, configSecret) });
181
- const { body: response } = await body.json();
182
- this.emitLog('debug', `Got device status: ${deviceId}`);
183
- this.emitLog('debug', `statusCode: ${statusCode}`);
184
- return { response, statusCode };
185
- }
186
- catch (error) {
187
- this.emitLog('error', `Failed to get device status: ${error.message}`);
188
- throw new APIError(`Failed to get device status: ${error.message}`, error.statusCode);
189
- }
190
- }
191
- /**
192
- * Sets up a webhook listener and configures the webhook on the server.
193
- *
194
- * This method performs the following steps:
195
- * 1. Creates a local server to listen for incoming webhook events.
196
- * 2. Sends a request to set up the webhook with the provided URL.
197
- * 3. Sends a request to update the webhook configuration.
198
- * 4. Sends a request to query the current webhook URL.
199
- *
200
- * @param url - The URL to which the webhook events will be sent.
201
- * @param token - (Optional) The token used for authentication. If not provided, the instance token will be used.
202
- * @param secret - (Optional) The secret used for authentication. If not provided, the instance secret will be used.
203
- * @returns A promise that resolves when the webhook setup is complete.
204
- *
205
- * @throws Will log an error if any step in the webhook setup process fails.
206
- */
207
- async setupWebhook(url, token, secret) {
208
- try {
209
- // Close existing listener if any to avoid port conflicts
210
- if (this.webhookEventListener) {
211
- this.webhookEventListener.close();
212
- this.webhookEventListener = null;
213
- }
214
- const xurl = new URL(url);
215
- const port = Number(xurl.port);
216
- const path = xurl.pathname;
217
- this.webhookEventListener = createServer(async (request, response) => {
218
- try {
219
- if (request.url === path && request.method === 'POST') {
220
- request.on('data', async (data) => {
221
- try {
222
- const body = JSON.parse(data);
223
- await this.emitLog('debug', `Received Webhook: ${JSON.stringify(body)}`);
224
- this.emit('webhookEvent', body);
225
- }
226
- catch (e) {
227
- await this.emitLog('error', `Failed to handle webhook event data, Error: ${e.message ?? e}`);
228
- }
229
- });
230
- response.writeHead(200, { 'Content-Type': 'text/plain' });
231
- response.end('OK');
232
- }
233
- else {
234
- await this.emitLog('error', `Invalid request received. URL:${request.url}, Method:${request.method}`);
235
- response.writeHead(403, { 'Content-Type': 'text/plain' });
236
- response.end(`NG`);
237
- }
238
- }
239
- catch (e) {
240
- await this.emitLog('error', `Failed to handle webhook event, Error: ${e.message ?? e}`);
241
- }
242
- }).listen(port || 80);
243
- }
244
- catch (e) {
245
- await this.emitLog('error', `Failed to create webhook listener, Error: ${e.message ?? e}`);
246
- throw new APIError(`Failed to create webhook listener: ${e.message ?? e}`, e.statusCode);
247
- }
248
- try {
249
- const configToken = token || this.token;
250
- const configSecret = secret || this.secret;
251
- const requestOptions = {
252
- method: 'POST',
253
- headers: this.generateHeaders(configToken, configSecret),
254
- body: JSON.stringify({
255
- action: 'setupWebhook',
256
- url,
257
- deviceList: 'ALL',
258
- }),
259
- timeout: 20000, // Increase timeout to 20 seconds
260
- };
261
- const { body, statusCode } = await requestWithRetry(urls.setupWebhook, requestOptions);
262
- const response = await body.json();
263
- await this.emitLog('debug', `setupWebhook: url:${url}, body:${JSON.stringify(response)}, statusCode:${statusCode}`);
264
- if (statusCode !== 200 || response?.statusCode !== 100) {
265
- await this.emitLog('error', `Failed to configure webhook. Existing webhook well be overridden. HTTP:${statusCode} API:${response?.statusCode} message:${response?.message}`);
266
- }
267
- }
268
- catch (e) {
269
- await this.emitLog('error', `Failed to configure webhook, Error: ${e.message ?? e}`);
270
- throw new APIError(`Failed to configure webhook: ${e.message ?? e}`, e.statusCode);
271
- }
272
- try {
273
- const configToken = token || this.token;
274
- const configSecret = secret || this.secret;
275
- const { body, statusCode } = await request(urls.updateWebhook, {
276
- method: 'POST',
277
- headers: this.generateHeaders(configToken, configSecret),
278
- body: JSON.stringify({
279
- action: 'updateWebhook',
280
- config: {
281
- url,
282
- enable: true,
283
- },
284
- }),
285
- });
286
- const response = await body.json();
287
- await this.emitLog('debug', `updateWebhook: url:${url}, body:${JSON.stringify(response)}, statusCode:${statusCode}`);
288
- if (statusCode !== 200 || response?.statusCode !== 100) {
289
- await this.emitLog('error', `Failed to update webhook. HTTP:${statusCode} API:${response?.statusCode} message:${response?.message}`);
290
- }
291
- }
292
- catch (e) {
293
- await this.emitLog('error', `Failed to update webhook, Error: ${e.message ?? e}`);
294
- throw new APIError(`Failed to update webhook: ${e.message ?? e}`, e.statusCode);
295
- }
296
- try {
297
- const configToken = token || this.token;
298
- const configSecret = secret || this.secret;
299
- const { body, statusCode } = await request(urls.queryWebhook, {
300
- method: 'POST',
301
- headers: this.generateHeaders(configToken, configSecret),
302
- body: JSON.stringify({
303
- action: 'queryUrl',
304
- }),
305
- });
306
- const response = await body.json();
307
- await this.emitLog('debug', `queryWebhook: body:${JSON.stringify(response)}, statusCode:${statusCode}`);
308
- if (statusCode !== 200 || response?.statusCode !== 100) {
309
- await this.emitLog('error', `Failed to query webhook. HTTP:${statusCode} API:${response?.statusCode} message:${response?.message}`);
310
- }
311
- else {
312
- await this.emitLog('info', `Listening webhook on ${response?.body?.urls[0]}`);
313
- }
314
- }
315
- catch (e) {
316
- await this.emitLog('error', `Failed to query webhook, Error: ${e.message ?? e}`);
317
- throw new APIError(`Failed to query webhook: ${e.message ?? e}`, e.statusCode);
318
- }
319
- }
320
- /**
321
- * Deletes a webhook by sending a request to the specified URL.
322
- *
323
- * @param url - The URL of the webhook to be deleted.
324
- * @param token - (Optional) The token used for authentication. If not provided, the instance token will be used.
325
- * @param secret - (Optional) The secret used for authentication. If not provided, the instance secret will be used.
326
- * @returns A promise that resolves when the webhook is successfully deleted.
327
- *
328
- * @throws Will log an error if the deletion fails.
329
- */
330
- async deleteWebhook(url, token, secret) {
331
- try {
332
- const configToken = token || this.token;
333
- const configSecret = secret || this.secret;
334
- const { body, statusCode } = await request(urls.deleteWebhook, {
335
- method: 'POST',
336
- headers: this.generateHeaders(configToken, configSecret),
337
- body: JSON.stringify({
338
- action: 'deleteWebhook',
339
- url,
340
- }),
341
- });
342
- const response = await body.json();
343
- await this.emitLog('debug', `deleteWebhook: url:${url}, body:${JSON.stringify(response)}, statusCode:${statusCode}`);
344
- if (statusCode !== 200 || response?.statusCode !== 100) {
345
- await this.emitLog('error', `Failed to delete webhook. HTTP:${statusCode} API:${response?.statusCode} message:${response?.message}`);
346
- }
347
- else {
348
- await this.emitLog('info', 'Unregistered webhook to close listening.');
349
- // Close listener server
350
- if (this.webhookEventListener) {
351
- this.webhookEventListener.close();
352
- this.webhookEventListener = null;
353
- }
354
- }
355
- }
356
- catch (e) {
357
- await this.emitLog('error', `Failed to delete webhook, Error: ${e.message ?? e}`);
358
- throw new APIError(`Failed to delete webhook: ${e.message ?? e}`, e.statusCode);
359
- }
360
- }
361
- }
362
- async function requestWithRetry(url, options, retries = 3) {
363
- for (let attempt = 1; attempt <= retries; attempt++) {
364
- try {
365
- return await request(url, options);
366
- }
367
- catch (error) {
368
- if (attempt === retries) {
369
- throw error;
370
- }
371
- await new Promise(resolve => setTimeout(resolve, 1000 * attempt)); // Exponential backoff
372
- }
373
- }
374
- }
375
- //# sourceMappingURL=switchbot-openapi.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"switchbot-openapi.js","sourceRoot":"","sources":["../src/switchbot-openapi.ts"],"names":[],"mappings":"AAQA,OAAO,MAAM,EAAE,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AAChD,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAC1C,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAA;AAExC,O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OAAO,EAAE,CAAC;gBACxB,MAAM,KAAK,CAAA;YACb,CAAC;YACD,MAAM,IAAI,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,IAAI,GAAG,OAAO,CAAC,CAAC,CAAA,CAAC,sBAAsB;QAC1F,CAAC;IACH,CAAC;AACH,CAAC"}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=switchbot-openapi.test.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"switchbot-openapi.test.d.ts","sourceRoot":"","sources":["../src/switchbot-openapi.test.ts"],"names":[],"mappings":""}
@@ -1,36 +0,0 @@
1
- /* eslint-disable import/order */
2
- /* eslint-disable */
3
- import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
4
- // Mock undici.request in ESM via module mock
5
- vi.mock('undici', async () => {
6
- const actual = await vi.importActual('undici');
7
- return { ...actual, request: vi.fn() };
8
- });
9
- import * as undici from 'undici';
10
- // Alias the mocked request function
11
- const requestMock = undici.request;
12
- import { SwitchBotOpenAPI } from './switchbot-openapi';
13
- describe('switchBotOpenAPI', () => {
14
- beforeEach(() => {
15
- // Reset module-level undici.request mock
16
- requestMock.mockReset();
17
- });
18
- afterEach(() => {
19
- vi.resetAllMocks();
20
- });
21
- it('controlDevice should send correct request and parse response', async () => {
22
- const fakeBody = { json: vi.fn().mockResolvedValue({ commandId: 'abc123' }) };
23
- const statusCode = 200;
24
- requestMock.mockResolvedValue({ body: fakeBody, statusCode });
25
- const api = new SwitchBotOpenAPI('my-token', 'my-secret');
26
- const result = await api.controlDevice('dev123', 'turnOn', 'default');
27
- expect(requestMock).toHaveBeenCalledWith(expect.stringContaining('/dev123/commands'), expect.objectContaining({
28
- method: 'POST',
29
- headers: expect.any(Object),
30
- body: JSON.stringify({ command: 'turnOn', parameter: 'default', commandType: 'command' }),
31
- }));
32
- expect(result.response).toEqual({ commandId: 'abc123' });
33
- expect(result.statusCode).toBe(statusCode);
34
- });
35
- });
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AAE,CAAC,CAAA;QAE7D,MAAM,GAAG,GAAG,IAAI,gBAAgB,CAAC,UAAU,EAAE,WAAW,CAAC,CAAA;QACzD,MAAM,MAAM,GAAG,MAAM,GAAG,CAAC,aAAa,CAAC,QAAQ,EAAE,QAAQ,EAAE,SAAS,CAAC,CAAA;QAErE,MAAM,CAAC,WAAW,CAAC,CAAC,oBAAoB,CACtC,MAAM,CAAC,gBAAgB,CAAC,kBAAkB,CAAC,EAC3C,MAAM,CAAC,gBAAgB,CAAC;YACtB,MAAM,EAAE,MAAM;YACd,OAAO,EAAE,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC;YAC3B,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,EAAE,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,SAAS,EAAE,WAAW,EAAE,SAAS,EAAE,CAAC;SAC1F,CAAC,CACH,CAAA;QACD,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,OAAO,CAAC,EAAE,SAAS,EAAE,QAAQ,EAAE,CAAC,CAAA;QACxD,MAAM,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,CAAA;IAC5C,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA"}
@@ -1,12 +0,0 @@
1
- import type { SwitchBotBLEModel } from '../device';
2
- import type { BLEDeviceServiceData } from './ble.js';
3
- /**
4
- * Generic type guard for BLE device service data by model.
5
- * @param data The BLE service data object.
6
- * @param model The SwitchBotBLEModel enum to check against.
7
- * @returns True if data.model matches, and narrows to the specific service data type.
8
- */
9
- export declare function isServiceDataOfModel<M extends SwitchBotBLEModel>(data: BLEDeviceServiceData, model: M): data is Extract<BLEDeviceServiceData, {
10
- model: M;
11
- }>;
12
- //# sourceMappingURL=ble-guards.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ble-guards.d.ts","sourceRoot":"","sources":["../../src/types/ble-guards.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAA;AAClD,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,UAAU,CAAA;AAEpD;;;;;GAKG;AACH,wBAAgB,oBAAoB,CAAC,CAAC,SAAS,iBAAiB,EAC9D,IAAI,EAAE,oBAAoB,EAC1B,KAAK,EAAE,CAAC,GACP,IAAI,IAAI,OAAO,CAAC,oBAAoB,EAAE;IAAE,KAAK,EAAE,CAAC,CAAA;CAAE,CAAC,CAErD"}
@@ -1,10 +0,0 @@
1
- /**
2
- * Generic type guard for BLE device service data by model.
3
- * @param data The BLE service data object.
4
- * @param model The SwitchBotBLEModel enum to check against.
5
- * @returns True if data.model matches, and narrows to the specific service data type.
6
- */
7
- export function isServiceDataOfModel(data, model) {
8
- return data.model === model;
9
- }
10
- //# sourceMappingURL=ble-guards.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ble-guards.js","sourceRoot":"","sources":["../../src/types/ble-guards.ts"],"names":[],"mappings":"AAGA;;;;;GAKG;AACH,MAAM,UAAU,oBAAoB,CAClC,IAA0B,EAC1B,KAAQ;IAER,OAAO,IAAI,CAAC,KAAK,KAAK,KAAK,CAAA;AAC7B,CAAC"}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=ble-guards.test.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ble-guards.test.d.ts","sourceRoot":"","sources":["../../src/types/ble-guards.test.ts"],"names":[],"mappings":""}
@@ -1,62 +0,0 @@
1
- import { describe, expect, it } from 'vitest';
2
- import { SwitchBotBLEModel, SwitchBotBLEModelFriendlyName, SwitchBotBLEModelName } from '../device';
3
- import { isServiceDataOfModel } from './ble-guards';
4
- describe('ble service data guards', () => {
5
- it('identifies colorBulbServiceData correctly', () => {
6
- const sample = {
7
- model: SwitchBotBLEModel.ColorBulb,
8
- modelName: SwitchBotBLEModelName.ColorBulb,
9
- modelFriendlyName: SwitchBotBLEModelFriendlyName.ColorBulb,
10
- color_temperature: 3000,
11
- power: true,
12
- state: false,
13
- red: 255,
14
- green: 200,
15
- blue: 150,
16
- brightness: 50,
17
- delay: 0,
18
- preset: 1,
19
- color_mode: 0,
20
- speed: 10,
21
- loop_index: 0,
22
- };
23
- expect(isServiceDataOfModel(sample, SwitchBotBLEModel.ColorBulb)).toBe(true);
24
- expect(isServiceDataOfModel(sample, SwitchBotBLEModel.CeilingLight)).toBe(false);
25
- });
26
- it('identifies ceilingLightServiceData correctly', () => {
27
- const sample = {
28
- model: SwitchBotBLEModel.CeilingLight,
29
- modelName: SwitchBotBLEModelName.CeilingLight,
30
- modelFriendlyName: SwitchBotBLEModelFriendlyName.CeilingLight,
31
- color_temperature: 3500,
32
- power: false,
33
- state: true,
34
- red: 100,
35
- green: 150,
36
- blue: 200,
37
- brightness: 75,
38
- delay: 5,
39
- preset: 2,
40
- color_mode: 1,
41
- speed: 5,
42
- loop_index: 1,
43
- };
44
- expect(isServiceDataOfModel(sample, SwitchBotBLEModel.CeilingLight)).toBe(true);
45
- expect(isServiceDataOfModel(sample, SwitchBotBLEModel.Meter)).toBe(false);
46
- });
47
- it('identifies meterServiceData correctly', () => {
48
- const sample = {
49
- model: SwitchBotBLEModel.Meter,
50
- modelName: SwitchBotBLEModelName.Meter,
51
- modelFriendlyName: SwitchBotBLEModelFriendlyName.Meter,
52
- celsius: 22.5,
53
- fahrenheit: 72.5,
54
- fahrenheit_mode: false,
55
- humidity: 45,
56
- battery: 90,
57
- };
58
- expect(isServiceDataOfModel(sample, SwitchBotBLEModel.Meter)).toBe(true);
59
- expect(isServiceDataOfModel(sample, SwitchBotBLEModel.ColorBulb)).toBe(false);
60
- });
61
- });
62
- //# sourceMappingURL=ble-guards.test.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ble-guards.test.js","sourceRoot":"","sources":["../../src/types/ble-guards.test.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAA;AAE7C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