@switchbot/homebridge-switchbot 5.0.0-beta.70 → 5.0.0-beta.72

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 (534) hide show
  1. package/.github/ISSUE_TEMPLATE/e2e-verification.md +36 -0
  2. package/.github/workflows/ci.yml +61 -0
  3. package/.github/workflows/manual-e2e.yml +103 -0
  4. package/CHANGELOG.md +20 -0
  5. package/E2E-VERIFICATION.md +121 -0
  6. package/MIGRATION.md +44 -0
  7. package/README.md +11 -0
  8. package/config.schema.json +99 -1940
  9. package/dist/deviceFactory.d.ts +13 -0
  10. package/dist/deviceFactory.d.ts.map +1 -0
  11. package/dist/deviceFactory.js +81 -0
  12. package/dist/deviceFactory.js.map +1 -0
  13. package/dist/devices/deviceBase.d.ts +50 -0
  14. package/dist/devices/deviceBase.d.ts.map +1 -0
  15. package/dist/devices/deviceBase.js +119 -0
  16. package/dist/devices/deviceBase.js.map +1 -0
  17. package/dist/devices/genericDevice.d.ts +283 -0
  18. package/dist/devices/genericDevice.d.ts.map +1 -0
  19. package/dist/devices/genericDevice.js +1035 -0
  20. package/dist/devices/genericDevice.js.map +1 -0
  21. package/dist/homebridge-ui/public/index.html +72 -440
  22. package/dist/homebridge-ui/server.d.ts +3 -1
  23. package/dist/homebridge-ui/server.d.ts.map +1 -1
  24. package/dist/homebridge-ui/server.js +47 -10
  25. package/dist/homebridge-ui/server.js.map +1 -1
  26. package/dist/index.d.ts.map +1 -1
  27. package/dist/index.js +1 -3
  28. package/dist/index.js.map +1 -1
  29. package/dist/platform.d.ts +27 -0
  30. package/dist/platform.d.ts.map +1 -0
  31. package/dist/platform.js +404 -0
  32. package/dist/platform.js.map +1 -0
  33. package/dist/settings.d.ts +10 -317
  34. package/dist/settings.d.ts.map +1 -1
  35. package/dist/settings.js +5 -30
  36. package/dist/settings.js.map +1 -1
  37. package/dist/switchbotClient.d.ts +32 -0
  38. package/dist/switchbotClient.d.ts.map +1 -0
  39. package/dist/switchbotClient.js +259 -0
  40. package/dist/switchbotClient.js.map +1 -0
  41. package/dist/utils.d.ts +36 -248
  42. package/dist/utils.d.ts.map +1 -1
  43. package/dist/utils.js +38 -1367
  44. package/dist/utils.js.map +1 -1
  45. package/docs/assets/icons.js +1 -1
  46. package/docs/assets/icons.svg +1 -1
  47. package/docs/assets/style.css +3 -3
  48. package/docs/index.html +50 -15
  49. package/docs/variables/default.html +1 -1
  50. package/package.json +19 -18
  51. package/scripts/e2e/README.md +25 -0
  52. package/scripts/e2e/curtain-e2e.sh +70 -0
  53. package/scripts/e2e/fan-e2e.sh +75 -0
  54. package/scripts/e2e/light-advanced-e2e.sh +97 -0
  55. package/scripts/e2e/light-e2e.sh +75 -0
  56. package/scripts/e2e/list-accessories.sh +19 -0
  57. package/scripts/e2e/lock-e2e.sh +65 -0
  58. package/scripts/generate-matter-maps.js +60 -0
  59. package/scripts/run-e2e-local.sh +14 -0
  60. package/src/deviceFactory.ts +122 -0
  61. package/src/devices/deviceBase.ts +141 -0
  62. package/src/devices/genericDevice.ts +965 -0
  63. package/src/homebridge-ui/public/index.html +72 -440
  64. package/src/homebridge-ui/server.ts +52 -10
  65. package/src/index.ts +1 -3
  66. package/src/platform.ts +395 -0
  67. package/src/settings.ts +12 -352
  68. package/src/switchbotClient.ts +266 -0
  69. package/src/utils.ts +47 -1456
  70. package/test/accessory-restore.spec.ts +73 -0
  71. package/test/device-mapping.spec.ts +37 -0
  72. package/test/deviceFactory.spec.ts +18 -0
  73. package/test/e2e/run-e2e.spec.ts +50 -0
  74. package/test/fan-swing.spec.ts +29 -0
  75. package/test/helpers/matter-harness.ts +53 -0
  76. package/test/lock-users.spec.ts +44 -0
  77. package/test/matter-childbridge.spec.ts +55 -0
  78. package/test/matter-descriptors.spec.ts +97 -0
  79. package/test/matter-device-state.spec.ts +101 -0
  80. package/test/matter-integration.spec.ts +70 -0
  81. package/test/platform.integration.spec.ts +55 -0
  82. package/test/switchbot-client-debounce.spec.ts +131 -0
  83. package/test/switchbot-client-openapi.spec.ts +56 -0
  84. package/test/switchbotClient.spec.ts +10 -0
  85. package/test/utils.spec.ts +20 -0
  86. package/vitest.config.ts +7 -0
  87. package/coverage/base.css +0 -224
  88. package/coverage/block-navigation.js +0 -87
  89. package/coverage/clover.xml +0 -15847
  90. package/coverage/coverage-final.json +0 -42
  91. package/coverage/docs/assets/dmt/dmt-component-data.js.html +0 -85
  92. package/coverage/docs/assets/dmt/dmt-components.js.html +0 -286
  93. package/coverage/docs/assets/dmt/index.html +0 -131
  94. package/coverage/docs/assets/hierarchy.js.html +0 -85
  95. package/coverage/docs/assets/icons.js.html +0 -136
  96. package/coverage/docs/assets/index.html +0 -146
  97. package/coverage/docs/assets/main.js.html +0 -265
  98. package/coverage/favicon.png +0 -0
  99. package/coverage/index.html +0 -191
  100. package/coverage/prettify.css +0 -1
  101. package/coverage/prettify.js +0 -2
  102. package/coverage/sort-arrow-sprite.png +0 -0
  103. package/coverage/sorter.js +0 -196
  104. package/coverage/src/device/blindtilt.ts.html +0 -3238
  105. package/coverage/src/device/bot.ts.html +0 -2803
  106. package/coverage/src/device/ceilinglight.ts.html +0 -2338
  107. package/coverage/src/device/colorbulb.ts.html +0 -2824
  108. package/coverage/src/device/contact.ts.html +0 -1465
  109. package/coverage/src/device/curtain.ts.html +0 -2869
  110. package/coverage/src/device/device.ts.html +0 -2500
  111. package/coverage/src/device/fan.ts.html +0 -2242
  112. package/coverage/src/device/hub.ts.html +0 -1408
  113. package/coverage/src/device/humidifier.ts.html +0 -2116
  114. package/coverage/src/device/index.html +0 -416
  115. package/coverage/src/device/iosensor.ts.html +0 -1375
  116. package/coverage/src/device/lightstrip.ts.html +0 -2617
  117. package/coverage/src/device/lock.ts.html +0 -1963
  118. package/coverage/src/device/meter.ts.html +0 -1372
  119. package/coverage/src/device/meterplus.ts.html +0 -1384
  120. package/coverage/src/device/meterpro.ts.html +0 -1618
  121. package/coverage/src/device/motion.ts.html +0 -1264
  122. package/coverage/src/device/plug.ts.html +0 -1372
  123. package/coverage/src/device/relayswitch.ts.html +0 -2284
  124. package/coverage/src/device/robotvacuumcleaner.ts.html +0 -1810
  125. package/coverage/src/device/waterdetector.ts.html +0 -1294
  126. package/coverage/src/homebridge-ui/index.html +0 -116
  127. package/coverage/src/homebridge-ui/server.ts.html +0 -229
  128. package/coverage/src/index.html +0 -161
  129. package/coverage/src/index.ts.html +0 -124
  130. package/coverage/src/irdevice/airconditioner.ts.html +0 -1687
  131. package/coverage/src/irdevice/airpurifier.ts.html +0 -844
  132. package/coverage/src/irdevice/camera.ts.html +0 -475
  133. package/coverage/src/irdevice/fan.ts.html +0 -766
  134. package/coverage/src/irdevice/index.html +0 -251
  135. package/coverage/src/irdevice/irdevice.ts.html +0 -1117
  136. package/coverage/src/irdevice/light.ts.html +0 -826
  137. package/coverage/src/irdevice/other.ts.html +0 -2458
  138. package/coverage/src/irdevice/tv.ts.html +0 -1222
  139. package/coverage/src/irdevice/vacuumcleaner.ts.html +0 -466
  140. package/coverage/src/irdevice/waterheater.ts.html +0 -469
  141. package/coverage/src/platform.ts.html +0 -8776
  142. package/coverage/src/settings.ts.html +0 -934
  143. package/coverage/src/utils.ts.html +0 -2092
  144. package/dist/devices-hap/airpurifier.d.ts +0 -54
  145. package/dist/devices-hap/airpurifier.d.ts.map +0 -1
  146. package/dist/devices-hap/airpurifier.js +0 -533
  147. package/dist/devices-hap/airpurifier.js.map +0 -1
  148. package/dist/devices-hap/blindtilt.d.ts +0 -90
  149. package/dist/devices-hap/blindtilt.d.ts.map +0 -1
  150. package/dist/devices-hap/blindtilt.js +0 -974
  151. package/dist/devices-hap/blindtilt.js.map +0 -1
  152. package/dist/devices-hap/bot.d.ts +0 -102
  153. package/dist/devices-hap/bot.d.ts.map +0 -1
  154. package/dist/devices-hap/bot.js +0 -822
  155. package/dist/devices-hap/bot.js.map +0 -1
  156. package/dist/devices-hap/ceilinglight.d.ts +0 -85
  157. package/dist/devices-hap/ceilinglight.d.ts.map +0 -1
  158. package/dist/devices-hap/ceilinglight.js +0 -707
  159. package/dist/devices-hap/ceilinglight.js.map +0 -1
  160. package/dist/devices-hap/colorbulb.d.ts +0 -88
  161. package/dist/devices-hap/colorbulb.d.ts.map +0 -1
  162. package/dist/devices-hap/colorbulb.js +0 -921
  163. package/dist/devices-hap/colorbulb.js.map +0 -1
  164. package/dist/devices-hap/contact.d.ts +0 -44
  165. package/dist/devices-hap/contact.d.ts.map +0 -1
  166. package/dist/devices-hap/contact.js +0 -409
  167. package/dist/devices-hap/contact.js.map +0 -1
  168. package/dist/devices-hap/curtain.d.ts +0 -73
  169. package/dist/devices-hap/curtain.d.ts.map +0 -1
  170. package/dist/devices-hap/curtain.js +0 -869
  171. package/dist/devices-hap/curtain.js.map +0 -1
  172. package/dist/devices-hap/device.d.ts +0 -108
  173. package/dist/devices-hap/device.d.ts.map +0 -1
  174. package/dist/devices-hap/device.js +0 -821
  175. package/dist/devices-hap/device.js.map +0 -1
  176. package/dist/devices-hap/fan.d.ts +0 -69
  177. package/dist/devices-hap/fan.d.ts.map +0 -1
  178. package/dist/devices-hap/fan.js +0 -655
  179. package/dist/devices-hap/fan.js.map +0 -1
  180. package/dist/devices-hap/hub.d.ts +0 -37
  181. package/dist/devices-hap/hub.d.ts.map +0 -1
  182. package/dist/devices-hap/hub.js +0 -393
  183. package/dist/devices-hap/hub.js.map +0 -1
  184. package/dist/devices-hap/humidifier.d.ts +0 -73
  185. package/dist/devices-hap/humidifier.d.ts.map +0 -1
  186. package/dist/devices-hap/humidifier.js +0 -716
  187. package/dist/devices-hap/humidifier.js.map +0 -1
  188. package/dist/devices-hap/iosensor.d.ts +0 -42
  189. package/dist/devices-hap/iosensor.d.ts.map +0 -1
  190. package/dist/devices-hap/iosensor.js +0 -397
  191. package/dist/devices-hap/iosensor.js.map +0 -1
  192. package/dist/devices-hap/lightstrip.d.ts +0 -79
  193. package/dist/devices-hap/lightstrip.d.ts.map +0 -1
  194. package/dist/devices-hap/lightstrip.js +0 -827
  195. package/dist/devices-hap/lightstrip.js.map +0 -1
  196. package/dist/devices-hap/lock.d.ts +0 -53
  197. package/dist/devices-hap/lock.d.ts.map +0 -1
  198. package/dist/devices-hap/lock.js +0 -569
  199. package/dist/devices-hap/lock.js.map +0 -1
  200. package/dist/devices-hap/meter.d.ts +0 -37
  201. package/dist/devices-hap/meter.d.ts.map +0 -1
  202. package/dist/devices-hap/meter.js +0 -380
  203. package/dist/devices-hap/meter.js.map +0 -1
  204. package/dist/devices-hap/meterplus.d.ts +0 -42
  205. package/dist/devices-hap/meterplus.d.ts.map +0 -1
  206. package/dist/devices-hap/meterplus.js +0 -385
  207. package/dist/devices-hap/meterplus.js.map +0 -1
  208. package/dist/devices-hap/meterpro.d.ts +0 -43
  209. package/dist/devices-hap/meterpro.d.ts.map +0 -1
  210. package/dist/devices-hap/meterpro.js +0 -469
  211. package/dist/devices-hap/meterpro.js.map +0 -1
  212. package/dist/devices-hap/motion.d.ts +0 -42
  213. package/dist/devices-hap/motion.d.ts.map +0 -1
  214. package/dist/devices-hap/motion.js +0 -345
  215. package/dist/devices-hap/motion.js.map +0 -1
  216. package/dist/devices-hap/plug.d.ts +0 -49
  217. package/dist/devices-hap/plug.d.ts.map +0 -1
  218. package/dist/devices-hap/plug.js +0 -400
  219. package/dist/devices-hap/plug.js.map +0 -1
  220. package/dist/devices-hap/relayswitch.d.ts +0 -96
  221. package/dist/devices-hap/relayswitch.d.ts.map +0 -1
  222. package/dist/devices-hap/relayswitch.js +0 -642
  223. package/dist/devices-hap/relayswitch.js.map +0 -1
  224. package/dist/devices-hap/robotvacuumcleaner.d.ts +0 -54
  225. package/dist/devices-hap/robotvacuumcleaner.d.ts.map +0 -1
  226. package/dist/devices-hap/robotvacuumcleaner.js +0 -530
  227. package/dist/devices-hap/robotvacuumcleaner.js.map +0 -1
  228. package/dist/devices-hap/waterdetector.d.ts +0 -41
  229. package/dist/devices-hap/waterdetector.d.ts.map +0 -1
  230. package/dist/devices-hap/waterdetector.js +0 -356
  231. package/dist/devices-hap/waterdetector.js.map +0 -1
  232. package/dist/devices-matter/BaseMatterAccessory.d.ts +0 -90
  233. package/dist/devices-matter/BaseMatterAccessory.d.ts.map +0 -1
  234. package/dist/devices-matter/BaseMatterAccessory.js +0 -264
  235. package/dist/devices-matter/BaseMatterAccessory.js.map +0 -1
  236. package/dist/devices-matter/ColorLightAccessory.d.ts +0 -20
  237. package/dist/devices-matter/ColorLightAccessory.d.ts.map +0 -1
  238. package/dist/devices-matter/ColorLightAccessory.js +0 -95
  239. package/dist/devices-matter/ColorLightAccessory.js.map +0 -1
  240. package/dist/devices-matter/ColorTemperatureLightAccessory.d.ts +0 -18
  241. package/dist/devices-matter/ColorTemperatureLightAccessory.d.ts.map +0 -1
  242. package/dist/devices-matter/ColorTemperatureLightAccessory.js +0 -76
  243. package/dist/devices-matter/ColorTemperatureLightAccessory.js.map +0 -1
  244. package/dist/devices-matter/ContactSensorAccessory.d.ts +0 -12
  245. package/dist/devices-matter/ContactSensorAccessory.d.ts.map +0 -1
  246. package/dist/devices-matter/ContactSensorAccessory.js +0 -34
  247. package/dist/devices-matter/ContactSensorAccessory.js.map +0 -1
  248. package/dist/devices-matter/DimmableLightAccessory.d.ts +0 -58
  249. package/dist/devices-matter/DimmableLightAccessory.d.ts.map +0 -1
  250. package/dist/devices-matter/DimmableLightAccessory.js +0 -167
  251. package/dist/devices-matter/DimmableLightAccessory.js.map +0 -1
  252. package/dist/devices-matter/DoorLockAccessory.d.ts +0 -14
  253. package/dist/devices-matter/DoorLockAccessory.d.ts.map +0 -1
  254. package/dist/devices-matter/DoorLockAccessory.js +0 -50
  255. package/dist/devices-matter/DoorLockAccessory.js.map +0 -1
  256. package/dist/devices-matter/ExtendedColorLightAccessory.d.ts +0 -21
  257. package/dist/devices-matter/ExtendedColorLightAccessory.d.ts.map +0 -1
  258. package/dist/devices-matter/ExtendedColorLightAccessory.js +0 -106
  259. package/dist/devices-matter/ExtendedColorLightAccessory.js.map +0 -1
  260. package/dist/devices-matter/FanAccessory.d.ts +0 -16
  261. package/dist/devices-matter/FanAccessory.d.ts.map +0 -1
  262. package/dist/devices-matter/FanAccessory.js +0 -81
  263. package/dist/devices-matter/FanAccessory.js.map +0 -1
  264. package/dist/devices-matter/HumiditySensorAccessory.d.ts +0 -12
  265. package/dist/devices-matter/HumiditySensorAccessory.d.ts.map +0 -1
  266. package/dist/devices-matter/HumiditySensorAccessory.js +0 -34
  267. package/dist/devices-matter/HumiditySensorAccessory.js.map +0 -1
  268. package/dist/devices-matter/LeakSensorAccessory.d.ts +0 -12
  269. package/dist/devices-matter/LeakSensorAccessory.d.ts.map +0 -1
  270. package/dist/devices-matter/LeakSensorAccessory.js +0 -33
  271. package/dist/devices-matter/LeakSensorAccessory.js.map +0 -1
  272. package/dist/devices-matter/LightSensorAccessory.d.ts +0 -12
  273. package/dist/devices-matter/LightSensorAccessory.d.ts.map +0 -1
  274. package/dist/devices-matter/LightSensorAccessory.js +0 -34
  275. package/dist/devices-matter/LightSensorAccessory.js.map +0 -1
  276. package/dist/devices-matter/OccupancySensorAccessory.d.ts +0 -12
  277. package/dist/devices-matter/OccupancySensorAccessory.d.ts.map +0 -1
  278. package/dist/devices-matter/OccupancySensorAccessory.js +0 -39
  279. package/dist/devices-matter/OccupancySensorAccessory.js.map +0 -1
  280. package/dist/devices-matter/OnOffLightAccessory.d.ts +0 -38
  281. package/dist/devices-matter/OnOffLightAccessory.d.ts.map +0 -1
  282. package/dist/devices-matter/OnOffLightAccessory.js +0 -110
  283. package/dist/devices-matter/OnOffLightAccessory.js.map +0 -1
  284. package/dist/devices-matter/OnOffOutletAccessory.d.ts +0 -14
  285. package/dist/devices-matter/OnOffOutletAccessory.d.ts.map +0 -1
  286. package/dist/devices-matter/OnOffOutletAccessory.js +0 -43
  287. package/dist/devices-matter/OnOffOutletAccessory.js.map +0 -1
  288. package/dist/devices-matter/OnOffSwitchAccessory.d.ts +0 -14
  289. package/dist/devices-matter/OnOffSwitchAccessory.d.ts.map +0 -1
  290. package/dist/devices-matter/OnOffSwitchAccessory.js +0 -42
  291. package/dist/devices-matter/OnOffSwitchAccessory.js.map +0 -1
  292. package/dist/devices-matter/RoboticVacuumAccessory.d.ts +0 -61
  293. package/dist/devices-matter/RoboticVacuumAccessory.d.ts.map +0 -1
  294. package/dist/devices-matter/RoboticVacuumAccessory.js +0 -544
  295. package/dist/devices-matter/RoboticVacuumAccessory.js.map +0 -1
  296. package/dist/devices-matter/SmokeCOAlarmAccessory.d.ts +0 -11
  297. package/dist/devices-matter/SmokeCOAlarmAccessory.d.ts.map +0 -1
  298. package/dist/devices-matter/SmokeCOAlarmAccessory.js +0 -49
  299. package/dist/devices-matter/SmokeCOAlarmAccessory.js.map +0 -1
  300. package/dist/devices-matter/TemperatureSensorAccessory.d.ts +0 -12
  301. package/dist/devices-matter/TemperatureSensorAccessory.d.ts.map +0 -1
  302. package/dist/devices-matter/TemperatureSensorAccessory.js +0 -36
  303. package/dist/devices-matter/TemperatureSensorAccessory.js.map +0 -1
  304. package/dist/devices-matter/ThermostatAccessory.d.ts +0 -19
  305. package/dist/devices-matter/ThermostatAccessory.d.ts.map +0 -1
  306. package/dist/devices-matter/ThermostatAccessory.js +0 -95
  307. package/dist/devices-matter/ThermostatAccessory.js.map +0 -1
  308. package/dist/devices-matter/VenetianBlindAccessory.d.ts +0 -19
  309. package/dist/devices-matter/VenetianBlindAccessory.d.ts.map +0 -1
  310. package/dist/devices-matter/VenetianBlindAccessory.js +0 -99
  311. package/dist/devices-matter/VenetianBlindAccessory.js.map +0 -1
  312. package/dist/devices-matter/WindowBlindAccessory.d.ts +0 -17
  313. package/dist/devices-matter/WindowBlindAccessory.d.ts.map +0 -1
  314. package/dist/devices-matter/WindowBlindAccessory.js +0 -131
  315. package/dist/devices-matter/WindowBlindAccessory.js.map +0 -1
  316. package/dist/devices-matter/custom/PowerStripAccessory.d.ts +0 -97
  317. package/dist/devices-matter/custom/PowerStripAccessory.d.ts.map +0 -1
  318. package/dist/devices-matter/custom/PowerStripAccessory.js +0 -265
  319. package/dist/devices-matter/custom/PowerStripAccessory.js.map +0 -1
  320. package/dist/devices-matter/custom/index.d.ts +0 -8
  321. package/dist/devices-matter/custom/index.d.ts.map +0 -1
  322. package/dist/devices-matter/custom/index.js +0 -8
  323. package/dist/devices-matter/custom/index.js.map +0 -1
  324. package/dist/devices-matter/index.d.ts +0 -29
  325. package/dist/devices-matter/index.d.ts.map +0 -1
  326. package/dist/devices-matter/index.js +0 -28
  327. package/dist/devices-matter/index.js.map +0 -1
  328. package/dist/irdevice/airconditioner.d.ts +0 -61
  329. package/dist/irdevice/airconditioner.d.ts.map +0 -1
  330. package/dist/irdevice/airconditioner.js +0 -472
  331. package/dist/irdevice/airconditioner.js.map +0 -1
  332. package/dist/irdevice/airpurifier.d.ts +0 -50
  333. package/dist/irdevice/airpurifier.d.ts.map +0 -1
  334. package/dist/irdevice/airpurifier.js +0 -213
  335. package/dist/irdevice/airpurifier.js.map +0 -1
  336. package/dist/irdevice/camera.d.ts +0 -32
  337. package/dist/irdevice/camera.d.ts.map +0 -1
  338. package/dist/irdevice/camera.js +0 -107
  339. package/dist/irdevice/camera.js.map +0 -1
  340. package/dist/irdevice/fan.d.ts +0 -36
  341. package/dist/irdevice/fan.d.ts.map +0 -1
  342. package/dist/irdevice/fan.js +0 -200
  343. package/dist/irdevice/fan.js.map +0 -1
  344. package/dist/irdevice/irdevice.d.ts +0 -69
  345. package/dist/irdevice/irdevice.d.ts.map +0 -1
  346. package/dist/irdevice/irdevice.js +0 -339
  347. package/dist/irdevice/irdevice.js.map +0 -1
  348. package/dist/irdevice/light.d.ts +0 -36
  349. package/dist/irdevice/light.d.ts.map +0 -1
  350. package/dist/irdevice/light.js +0 -206
  351. package/dist/irdevice/light.js.map +0 -1
  352. package/dist/irdevice/other.d.ts +0 -57
  353. package/dist/irdevice/other.d.ts.map +0 -1
  354. package/dist/irdevice/other.js +0 -778
  355. package/dist/irdevice/other.js.map +0 -1
  356. package/dist/irdevice/tv.d.ts +0 -45
  357. package/dist/irdevice/tv.d.ts.map +0 -1
  358. package/dist/irdevice/tv.js +0 -327
  359. package/dist/irdevice/tv.js.map +0 -1
  360. package/dist/irdevice/vacuumcleaner.d.ts +0 -28
  361. package/dist/irdevice/vacuumcleaner.d.ts.map +0 -1
  362. package/dist/irdevice/vacuumcleaner.js +0 -104
  363. package/dist/irdevice/vacuumcleaner.js.map +0 -1
  364. package/dist/irdevice/waterheater.d.ts +0 -30
  365. package/dist/irdevice/waterheater.d.ts.map +0 -1
  366. package/dist/irdevice/waterheater.js +0 -105
  367. package/dist/irdevice/waterheater.js.map +0 -1
  368. package/dist/platform-hap.d.ts +0 -160
  369. package/dist/platform-hap.d.ts.map +0 -1
  370. package/dist/platform-hap.js +0 -3041
  371. package/dist/platform-hap.js.map +0 -1
  372. package/dist/platform-matter.d.ts +0 -188
  373. package/dist/platform-matter.d.ts.map +0 -1
  374. package/dist/platform-matter.js +0 -2545
  375. package/dist/platform-matter.js.map +0 -1
  376. package/dist/test/apiRequestTracker.test.d.ts +0 -2
  377. package/dist/test/apiRequestTracker.test.d.ts.map +0 -1
  378. package/dist/test/apiRequestTracker.test.js +0 -392
  379. package/dist/test/apiRequestTracker.test.js.map +0 -1
  380. package/dist/test/hap/device-webhook-context.test.d.ts +0 -2
  381. package/dist/test/hap/device-webhook-context.test.d.ts.map +0 -1
  382. package/dist/test/hap/device-webhook-context.test.js +0 -128
  383. package/dist/test/hap/device-webhook-context.test.js.map +0 -1
  384. package/dist/test/hap/platform-hap.logging.test.d.ts +0 -2
  385. package/dist/test/hap/platform-hap.logging.test.d.ts.map +0 -1
  386. package/dist/test/hap/platform-hap.logging.test.js +0 -33
  387. package/dist/test/hap/platform-hap.logging.test.js.map +0 -1
  388. package/dist/test/hap/platform-hap.test.d.ts +0 -2
  389. package/dist/test/hap/platform-hap.test.d.ts.map +0 -1
  390. package/dist/test/hap/platform-hap.test.js +0 -62
  391. package/dist/test/hap/platform-hap.test.js.map +0 -1
  392. package/dist/test/helpers/platform-fixtures.d.ts +0 -9
  393. package/dist/test/helpers/platform-fixtures.d.ts.map +0 -1
  394. package/dist/test/helpers/platform-fixtures.js +0 -30
  395. package/dist/test/helpers/platform-fixtures.js.map +0 -1
  396. package/dist/test/homebridge-ui/server.test.d.ts +0 -2
  397. package/dist/test/homebridge-ui/server.test.d.ts.map +0 -1
  398. package/dist/test/homebridge-ui/server.test.js +0 -445
  399. package/dist/test/homebridge-ui/server.test.js.map +0 -1
  400. package/dist/test/index.test.d.ts +0 -2
  401. package/dist/test/index.test.d.ts.map +0 -1
  402. package/dist/test/index.test.js +0 -19
  403. package/dist/test/index.test.js.map +0 -1
  404. package/dist/test/matter/devices-matter/baseMatterAccessory.test.d.ts +0 -2
  405. package/dist/test/matter/devices-matter/baseMatterAccessory.test.d.ts.map +0 -1
  406. package/dist/test/matter/devices-matter/baseMatterAccessory.test.js +0 -71
  407. package/dist/test/matter/devices-matter/baseMatterAccessory.test.js.map +0 -1
  408. package/dist/test/matter/platform-matter.additional.test.d.ts +0 -2
  409. package/dist/test/matter/platform-matter.additional.test.d.ts.map +0 -1
  410. package/dist/test/matter/platform-matter.additional.test.js +0 -35
  411. package/dist/test/matter/platform-matter.additional.test.js.map +0 -1
  412. package/dist/test/matter/platform-matter.bleparse.test.d.ts +0 -2
  413. package/dist/test/matter/platform-matter.bleparse.test.d.ts.map +0 -1
  414. package/dist/test/matter/platform-matter.bleparse.test.js +0 -43
  415. package/dist/test/matter/platform-matter.bleparse.test.js.map +0 -1
  416. package/dist/test/matter/platform-matter.cleanup.test.d.ts +0 -2
  417. package/dist/test/matter/platform-matter.cleanup.test.d.ts.map +0 -1
  418. package/dist/test/matter/platform-matter.cleanup.test.js +0 -70
  419. package/dist/test/matter/platform-matter.cleanup.test.js.map +0 -1
  420. package/dist/test/matter/platform-matter.keepstale.test.d.ts +0 -2
  421. package/dist/test/matter/platform-matter.keepstale.test.d.ts.map +0 -1
  422. package/dist/test/matter/platform-matter.keepstale.test.js +0 -27
  423. package/dist/test/matter/platform-matter.keepstale.test.js.map +0 -1
  424. package/dist/test/matter/platform-matter.logging.test.d.ts +0 -2
  425. package/dist/test/matter/platform-matter.logging.test.d.ts.map +0 -1
  426. package/dist/test/matter/platform-matter.logging.test.js +0 -29
  427. package/dist/test/matter/platform-matter.logging.test.js.map +0 -1
  428. package/dist/test/matter/platform-matter.mapping.test.d.ts +0 -2
  429. package/dist/test/matter/platform-matter.mapping.test.d.ts.map +0 -1
  430. package/dist/test/matter/platform-matter.mapping.test.js +0 -43
  431. package/dist/test/matter/platform-matter.mapping.test.js.map +0 -1
  432. package/dist/test/matter/platform-matter.openapi-mapping.test.d.ts +0 -2
  433. package/dist/test/matter/platform-matter.openapi-mapping.test.d.ts.map +0 -1
  434. package/dist/test/matter/platform-matter.openapi-mapping.test.js +0 -84
  435. package/dist/test/matter/platform-matter.openapi-mapping.test.js.map +0 -1
  436. package/dist/test/matter/platform-matter.test.d.ts +0 -2
  437. package/dist/test/matter/platform-matter.test.d.ts.map +0 -1
  438. package/dist/test/matter/platform-matter.test.js +0 -117
  439. package/dist/test/matter/platform-matter.test.js.map +0 -1
  440. package/dist/test/matter/platform-matter.unregister.test.d.ts +0 -2
  441. package/dist/test/matter/platform-matter.unregister.test.d.ts.map +0 -1
  442. package/dist/test/matter/platform-matter.unregister.test.js +0 -30
  443. package/dist/test/matter/platform-matter.unregister.test.js.map +0 -1
  444. package/dist/test/matter/platform-matter.webhook.test.d.ts +0 -2
  445. package/dist/test/matter/platform-matter.webhook.test.d.ts.map +0 -1
  446. package/dist/test/matter/platform-matter.webhook.test.js +0 -46
  447. package/dist/test/matter/platform-matter.webhook.test.js.map +0 -1
  448. package/dist/test/utils.test.d.ts +0 -2
  449. package/dist/test/utils.test.d.ts.map +0 -1
  450. package/dist/test/utils.test.js +0 -95
  451. package/dist/test/utils.test.js.map +0 -1
  452. package/dist/test/verifyconfig.test.d.ts +0 -2
  453. package/dist/test/verifyconfig.test.d.ts.map +0 -1
  454. package/dist/test/verifyconfig.test.js +0 -167
  455. package/dist/test/verifyconfig.test.js.map +0 -1
  456. package/src/custom.d.ts +0 -7
  457. package/src/devices-hap/airpurifier.ts +0 -568
  458. package/src/devices-hap/blindtilt.ts +0 -1049
  459. package/src/devices-hap/bot.ts +0 -910
  460. package/src/devices-hap/ceilinglight.ts +0 -747
  461. package/src/devices-hap/colorbulb.ts +0 -940
  462. package/src/devices-hap/contact.ts +0 -457
  463. package/src/devices-hap/curtain.ts +0 -944
  464. package/src/devices-hap/device.ts +0 -890
  465. package/src/devices-hap/fan.ts +0 -716
  466. package/src/devices-hap/hub.ts +0 -440
  467. package/src/devices-hap/humidifier.ts +0 -762
  468. package/src/devices-hap/iosensor.ts +0 -442
  469. package/src/devices-hap/lightstrip.ts +0 -863
  470. package/src/devices-hap/lock.ts +0 -627
  471. package/src/devices-hap/meter.ts +0 -427
  472. package/src/devices-hap/meterplus.ts +0 -431
  473. package/src/devices-hap/meterpro.ts +0 -523
  474. package/src/devices-hap/motion.ts +0 -390
  475. package/src/devices-hap/plug.ts +0 -427
  476. package/src/devices-hap/relayswitch.ts +0 -727
  477. package/src/devices-hap/robotvacuumcleaner.ts +0 -574
  478. package/src/devices-hap/waterdetector.ts +0 -400
  479. package/src/devices-matter/BaseMatterAccessory.ts +0 -302
  480. package/src/devices-matter/ColorLightAccessory.ts +0 -110
  481. package/src/devices-matter/ColorTemperatureLightAccessory.ts +0 -90
  482. package/src/devices-matter/ContactSensorAccessory.ts +0 -41
  483. package/src/devices-matter/DimmableLightAccessory.ts +0 -192
  484. package/src/devices-matter/DoorLockAccessory.ts +0 -60
  485. package/src/devices-matter/ExtendedColorLightAccessory.ts +0 -122
  486. package/src/devices-matter/FanAccessory.ts +0 -95
  487. package/src/devices-matter/HumiditySensorAccessory.ts +0 -41
  488. package/src/devices-matter/LeakSensorAccessory.ts +0 -40
  489. package/src/devices-matter/LightSensorAccessory.ts +0 -41
  490. package/src/devices-matter/OccupancySensorAccessory.ts +0 -48
  491. package/src/devices-matter/OnOffLightAccessory.ts +0 -125
  492. package/src/devices-matter/OnOffOutletAccessory.ts +0 -51
  493. package/src/devices-matter/OnOffSwitchAccessory.ts +0 -51
  494. package/src/devices-matter/RoboticVacuumAccessory.ts +0 -621
  495. package/src/devices-matter/SmokeCOAlarmAccessory.ts +0 -59
  496. package/src/devices-matter/TemperatureSensorAccessory.ts +0 -43
  497. package/src/devices-matter/ThermostatAccessory.ts +0 -110
  498. package/src/devices-matter/VenetianBlindAccessory.ts +0 -115
  499. package/src/devices-matter/WindowBlindAccessory.ts +0 -135
  500. package/src/devices-matter/custom/PowerStripAccessory.ts +0 -309
  501. package/src/devices-matter/custom/index.ts +0 -8
  502. package/src/devices-matter/index.ts +0 -29
  503. package/src/irdevice/airconditioner.ts +0 -533
  504. package/src/irdevice/airpurifier.ts +0 -252
  505. package/src/irdevice/camera.ts +0 -129
  506. package/src/irdevice/fan.ts +0 -226
  507. package/src/irdevice/irdevice.ts +0 -383
  508. package/src/irdevice/light.ts +0 -246
  509. package/src/irdevice/other.ts +0 -790
  510. package/src/irdevice/tv.ts +0 -378
  511. package/src/irdevice/vacuumcleaner.ts +0 -126
  512. package/src/irdevice/waterheater.ts +0 -127
  513. package/src/platform-hap.ts +0 -3193
  514. package/src/platform-matter.ts +0 -2703
  515. package/src/test/apiRequestTracker.test.ts +0 -417
  516. package/src/test/hap/device-webhook-context.test.ts +0 -136
  517. package/src/test/hap/platform-hap.logging.test.ts +0 -36
  518. package/src/test/hap/platform-hap.test.ts +0 -70
  519. package/src/test/helpers/platform-fixtures.ts +0 -33
  520. package/src/test/homebridge-ui/server.test.ts +0 -486
  521. package/src/test/index.test.ts +0 -24
  522. package/src/test/matter/devices-matter/baseMatterAccessory.test.ts +0 -88
  523. package/src/test/matter/platform-matter.additional.test.ts +0 -44
  524. package/src/test/matter/platform-matter.bleparse.test.ts +0 -47
  525. package/src/test/matter/platform-matter.cleanup.test.ts +0 -86
  526. package/src/test/matter/platform-matter.keepstale.test.ts +0 -37
  527. package/src/test/matter/platform-matter.logging.test.ts +0 -33
  528. package/src/test/matter/platform-matter.mapping.test.ts +0 -57
  529. package/src/test/matter/platform-matter.openapi-mapping.test.ts +0 -109
  530. package/src/test/matter/platform-matter.test.ts +0 -144
  531. package/src/test/matter/platform-matter.unregister.test.ts +0 -39
  532. package/src/test/matter/platform-matter.webhook.test.ts +0 -54
  533. package/src/test/utils.test.ts +0 -96
  534. package/src/test/verifyconfig.test.ts +0 -198
@@ -1,417 +0,0 @@
1
- import type { API, Logging } from 'homebridge'
2
-
3
- import { existsSync, mkdirSync, readdirSync, readFileSync, rmdirSync, unlinkSync } from 'node:fs'
4
- import { tmpdir } from 'node:os'
5
- import { join } from 'node:path'
6
-
7
- import { describe, expect, it, vi } from 'vitest'
8
-
9
- import { ApiRequestTracker } from '../utils.js'
10
-
11
- // Helper to create isolated test environment for each test
12
- function createTestEnvironment(pluginName = 'SwitchBotTest') {
13
- const testId = Math.random().toString(36).substring(7)
14
- const testDir = join(tmpdir(), `switchbot-test-${testId}`)
15
-
16
- // Create test directory
17
- if (!existsSync(testDir)) {
18
- mkdirSync(testDir, { recursive: true })
19
- }
20
-
21
- const testStatsFile = join(testDir, `${pluginName.toLowerCase()}-api-stats.json`)
22
-
23
- // Mock API with a unique storage path per test
24
- const mockApi = {
25
- user: {
26
- storagePath: () => testDir,
27
- },
28
- } as unknown as API
29
-
30
- // Mock logger
31
- const mockLog = {
32
- info: vi.fn(),
33
- warn: vi.fn(),
34
- error: vi.fn(),
35
- debug: vi.fn(),
36
- } as unknown as Logging
37
-
38
- return { mockApi, mockLog, testStatsFile, testDir }
39
- }
40
-
41
- // Cleanup helper
42
- function cleanup(testDir: string) {
43
- try {
44
- if (existsSync(testDir)) {
45
- const files = readdirSync(testDir)
46
- for (const file of files) {
47
- try {
48
- unlinkSync(join(testDir, file))
49
- } catch {
50
- // ignore
51
- }
52
- }
53
- rmdirSync(testDir)
54
- }
55
- } catch {
56
- // ignore
57
- }
58
- }
59
-
60
- describe('apiRequestTracker', () => {
61
- describe('initialization', () => {
62
- it('should create a new tracker with default limits', () => {
63
- const { mockApi, mockLog, testDir } = createTestEnvironment()
64
- try {
65
- const tracker = new ApiRequestTracker(mockApi, mockLog, 'SwitchBotTest')
66
- expect(tracker).toBeDefined()
67
- expect(tracker.getCount()).toBe(0)
68
- expect(tracker.getDate()).toBe(new Date().toISOString().split('T')[0])
69
- } finally {
70
- cleanup(testDir)
71
- }
72
- })
73
-
74
- it('should respect custom daily limit', () => {
75
- const { mockApi, mockLog, testDir } = createTestEnvironment()
76
- try {
77
- const tracker = new ApiRequestTracker(mockApi, mockLog, 'SwitchBotTest', {
78
- dailyLimit: 5000,
79
- reserveForCommands: 500,
80
- })
81
- expect(tracker).toBeDefined()
82
- } finally {
83
- cleanup(testDir)
84
- }
85
- })
86
-
87
- it('should load existing stats from file', () => {
88
- const { mockApi, mockLog, testDir } = createTestEnvironment()
89
- try {
90
- // Create a tracker, increment, and verify persistence
91
- const tracker1 = new ApiRequestTracker(mockApi, mockLog, 'SwitchBotTest')
92
- tracker1.track()
93
- tracker1.track()
94
- expect(tracker1.getCount()).toBe(2)
95
-
96
- // Create a new tracker instance and verify it loads the count
97
- const tracker2 = new ApiRequestTracker(mockApi, mockLog, 'SwitchBotTest')
98
- expect(tracker2.getCount()).toBe(2)
99
- } finally {
100
- cleanup(testDir)
101
- }
102
- })
103
- })
104
-
105
- describe('track() - legacy method', () => {
106
- it('should increment the counter', () => {
107
- const { mockApi, mockLog, testDir } = createTestEnvironment()
108
- try {
109
- const tracker = new ApiRequestTracker(mockApi, mockLog, 'SwitchBotTest')
110
- expect(tracker.getCount()).toBe(0)
111
- tracker.track()
112
- expect(tracker.getCount()).toBe(1)
113
- tracker.track()
114
- expect(tracker.getCount()).toBe(2)
115
- } finally {
116
- cleanup(testDir)
117
- }
118
- })
119
-
120
- it('should persist count to file', () => {
121
- const { mockApi, mockLog, testStatsFile, testDir } = createTestEnvironment()
122
- try {
123
- const tracker = new ApiRequestTracker(mockApi, mockLog, 'SwitchBotTest')
124
- tracker.track()
125
- tracker.track()
126
- tracker.track()
127
-
128
- // Read the stats file directly
129
- const statsContent = readFileSync(testStatsFile, 'utf8')
130
- const stats = JSON.parse(statsContent)
131
- expect(stats.count).toBe(3)
132
- expect(stats.date).toBe(new Date().toISOString().split('T')[0])
133
- } finally {
134
- cleanup(testDir)
135
- }
136
- })
137
- })
138
-
139
- describe('trySpend() - budget enforcement', () => {
140
- it('should allow commands when under soft cap', () => {
141
- const { mockApi, mockLog, testDir } = createTestEnvironment()
142
- try {
143
- const tracker = new ApiRequestTracker(mockApi, mockLog, 'SwitchBotTest', {
144
- dailyLimit: 100,
145
- reserveForCommands: 20,
146
- })
147
- // Use 50 requests (well under soft cap of 80)
148
- for (let i = 0; i < 50; i++) {
149
- expect(tracker.trySpend('command')).toBe(true)
150
- }
151
- expect(tracker.getCount()).toBe(50)
152
- } finally {
153
- cleanup(testDir)
154
- }
155
- })
156
-
157
- it('should allow polling when under soft cap', () => {
158
- const { mockApi, mockLog, testDir } = createTestEnvironment()
159
- try {
160
- const tracker = new ApiRequestTracker(mockApi, mockLog, 'SwitchBotTest', {
161
- dailyLimit: 100,
162
- reserveForCommands: 20,
163
- })
164
- // Use 50 requests
165
- for (let i = 0; i < 50; i++) {
166
- expect(tracker.trySpend('poll')).toBe(true)
167
- }
168
- expect(tracker.getCount()).toBe(50)
169
- } finally {
170
- cleanup(testDir)
171
- }
172
- })
173
-
174
- it('should block polling at soft cap when pausePollingAtReserve is true', () => {
175
- const { mockApi, mockLog, testDir } = createTestEnvironment()
176
- try {
177
- const tracker = new ApiRequestTracker(mockApi, mockLog, 'SwitchBotTest', {
178
- dailyLimit: 100,
179
- reserveForCommands: 20,
180
- pausePollingAtReserve: true, // Enable soft cap blocking
181
- })
182
- // Use up to soft cap (80 requests)
183
- for (let i = 0; i < 80; i++) {
184
- tracker.track()
185
- }
186
- expect(tracker.getCount()).toBe(80)
187
-
188
- // Polling should be blocked at soft cap
189
- expect(tracker.trySpend('poll')).toBe(false)
190
- expect(tracker.trySpend('discovery')).toBe(false)
191
-
192
- // Commands should still work
193
- expect(tracker.trySpend('command')).toBe(true)
194
- expect(tracker.getCount()).toBe(81)
195
- } finally {
196
- cleanup(testDir)
197
- }
198
- })
199
-
200
- it('should block all requests at hard cap', () => {
201
- const { mockApi, mockLog, testDir } = createTestEnvironment()
202
- try {
203
- const tracker = new ApiRequestTracker(mockApi, mockLog, 'SwitchBotTest', {
204
- dailyLimit: 100,
205
- reserveForCommands: 20,
206
- })
207
- // Use up to hard cap
208
- for (let i = 0; i < 100; i++) {
209
- tracker.track()
210
- }
211
- expect(tracker.getCount()).toBe(100)
212
-
213
- // All request types should be blocked
214
- expect(tracker.trySpend('poll')).toBe(false)
215
- expect(tracker.trySpend('discovery')).toBe(false)
216
- expect(tracker.trySpend('command')).toBe(false)
217
- expect(tracker.getCount()).toBe(100)
218
- } finally {
219
- cleanup(testDir)
220
- }
221
- })
222
-
223
- it('should support batch spending', () => {
224
- const { mockApi, mockLog, testDir } = createTestEnvironment()
225
- try {
226
- const tracker = new ApiRequestTracker(mockApi, mockLog, 'SwitchBotTest', {
227
- dailyLimit: 100,
228
- reserveForCommands: 20,
229
- })
230
- expect(tracker.trySpend('poll', 10)).toBe(true)
231
- expect(tracker.getCount()).toBe(10)
232
-
233
- expect(tracker.trySpend('command', 5)).toBe(true)
234
- expect(tracker.getCount()).toBe(15)
235
- } finally {
236
- cleanup(testDir)
237
- }
238
- })
239
- })
240
-
241
- describe('webhookOnlyOnReserve mode', () => {
242
- it('should continue polling beyond soft cap when pausePollingAtReserve is false', () => {
243
- const { mockApi, mockLog, testDir } = createTestEnvironment()
244
- try {
245
- const tracker = new ApiRequestTracker(mockApi, mockLog, 'SwitchBotTest', {
246
- dailyLimit: 100,
247
- reserveForCommands: 20,
248
- pausePollingAtReserve: false,
249
- })
250
- // Use 85 requests (past soft cap)
251
- for (let i = 0; i < 85; i++) {
252
- tracker.track()
253
- }
254
- expect(tracker.getCount()).toBe(85)
255
-
256
- // Polling should still work (not paused at reserve)
257
- expect(tracker.trySpend('poll')).toBe(true)
258
- expect(tracker.getCount()).toBe(86)
259
- } finally {
260
- cleanup(testDir)
261
- }
262
- })
263
-
264
- it('should stop polling at soft cap when pausePollingAtReserve is true', () => {
265
- const { mockApi, mockLog, testDir } = createTestEnvironment()
266
- try {
267
- const tracker = new ApiRequestTracker(mockApi, mockLog, 'SwitchBotTest', {
268
- dailyLimit: 100,
269
- reserveForCommands: 20,
270
- pausePollingAtReserve: true,
271
- })
272
- // Use up to soft cap
273
- for (let i = 0; i < 80; i++) {
274
- tracker.track()
275
- }
276
- expect(tracker.getCount()).toBe(80)
277
-
278
- // Polling should be blocked
279
- expect(tracker.trySpend('poll')).toBe(false)
280
- expect(tracker.getCount()).toBe(80)
281
-
282
- // Commands should still work
283
- expect(tracker.trySpend('command')).toBe(true)
284
- expect(tracker.getCount()).toBe(81)
285
- } finally {
286
- cleanup(testDir)
287
- }
288
- })
289
- })
290
-
291
- describe('warning logs', () => {
292
- it('should log warning when reaching soft cap with pausePollingAtReserve enabled', () => {
293
- const { mockApi, mockLog, testDir } = createTestEnvironment()
294
- try {
295
- const tracker = new ApiRequestTracker(mockApi, mockLog, 'SwitchBotTest', {
296
- dailyLimit: 100,
297
- reserveForCommands: 20,
298
- pausePollingAtReserve: true, // Enable soft cap warning
299
- })
300
- // Use up to soft cap
301
- for (let i = 0; i < 80; i++) {
302
- tracker.track()
303
- }
304
-
305
- // Trigger soft cap warning by attempting poll (will be blocked)
306
- tracker.trySpend('poll')
307
- expect(mockLog.warn).toHaveBeenCalledWith(
308
- expect.stringContaining('Near daily limit'),
309
- )
310
- } finally {
311
- cleanup(testDir)
312
- }
313
- })
314
-
315
- it('should log error when reaching hard cap', () => {
316
- const { mockApi, mockLog, testDir } = createTestEnvironment()
317
- try {
318
- const tracker = new ApiRequestTracker(mockApi, mockLog, 'SwitchBotTest', {
319
- dailyLimit: 100,
320
- reserveForCommands: 20,
321
- })
322
- // Use up to hard cap
323
- for (let i = 0; i < 100; i++) {
324
- tracker.track()
325
- }
326
-
327
- // Trigger hard cap error
328
- tracker.trySpend('command')
329
- expect(mockLog.error).toHaveBeenCalledWith(
330
- expect.stringContaining('Daily limit'),
331
- )
332
- } finally {
333
- cleanup(testDir)
334
- }
335
- })
336
- })
337
-
338
- describe('hourly logging', () => {
339
- it('should log immediately on startup', () => {
340
- const { mockApi, mockLog, testDir } = createTestEnvironment()
341
- try {
342
- const tracker = new ApiRequestTracker(mockApi, mockLog, 'SwitchBotTest')
343
- tracker.startHourlyLogging()
344
- tracker.stopHourlyLogging()
345
- expect(mockLog.info).toHaveBeenCalledWith(
346
- expect.stringContaining('[API Stats] Today'),
347
- )
348
- } finally {
349
- cleanup(testDir)
350
- }
351
- })
352
-
353
- it('should stop logging when stopHourlyLogging is called', () => {
354
- const { mockApi, mockLog, testDir } = createTestEnvironment()
355
- try {
356
- const tracker = new ApiRequestTracker(mockApi, mockLog, 'SwitchBotTest')
357
- tracker.startHourlyLogging()
358
- tracker.stopHourlyLogging()
359
- // Should not throw
360
- expect(true).toBe(true)
361
- } finally {
362
- cleanup(testDir)
363
- }
364
- })
365
- })
366
-
367
- describe('edge cases', () => {
368
- it('should handle zero daily limit', () => {
369
- const { mockApi, mockLog, testDir } = createTestEnvironment()
370
- try {
371
- const tracker = new ApiRequestTracker(mockApi, mockLog, 'SwitchBotTest', {
372
- dailyLimit: 0,
373
- reserveForCommands: 0,
374
- })
375
- // All requests should be blocked immediately
376
- expect(tracker.trySpend('poll')).toBe(false)
377
- expect(tracker.trySpend('command')).toBe(false)
378
- expect(tracker.getCount()).toBe(0)
379
- } finally {
380
- cleanup(testDir)
381
- }
382
- })
383
-
384
- it('should handle reserve larger than limit', () => {
385
- const { mockApi, mockLog, testDir } = createTestEnvironment()
386
- try {
387
- const tracker = new ApiRequestTracker(mockApi, mockLog, 'SwitchBotTest', {
388
- dailyLimit: 100,
389
- reserveForCommands: 150,
390
- pausePollingAtReserve: true, // Enable soft cap blocking
391
- })
392
- // Soft cap would be negative (100 - 150 = -50), clamped to 0
393
- // With pausePollingAtReserve=true, polling should be blocked immediately
394
- expect(tracker.trySpend('poll')).toBe(false)
395
- // Commands up to hard cap should work
396
- expect(tracker.trySpend('command')).toBe(true)
397
- } finally {
398
- cleanup(testDir)
399
- }
400
- })
401
-
402
- it('should handle negative values in config', () => {
403
- const { mockApi, mockLog, testDir } = createTestEnvironment()
404
- try {
405
- const tracker = new ApiRequestTracker(mockApi, mockLog, 'SwitchBotTest', {
406
- dailyLimit: -100,
407
- reserveForCommands: -50,
408
- })
409
- // Should be treated as 0
410
- expect(tracker.trySpend('poll')).toBe(false)
411
- expect(tracker.trySpend('command')).toBe(false)
412
- } finally {
413
- cleanup(testDir)
414
- }
415
- })
416
- })
417
- })
@@ -1,136 +0,0 @@
1
- /* eslint-disable import/first */
2
- import { describe, expect, it, vi } from 'vitest'
3
- // Mock modules used by HAP device base occasionally via platform
4
- vi.mock('fakegato-history', () => ({ default: () => ({}) }))
5
- vi.mock('homebridge-lib/EveHomeKitTypes', () => ({ EveHomeKitTypes: class { constructor() {} } }))
6
-
7
- import { deviceBase } from '../../devices-hap/device.js'
8
-
9
- // Minimal HAP stub to satisfy deviceBase constructor operations
10
- function makeHapStub() {
11
- class Service {
12
- private _chars: Record<string, any> = {}
13
- setCharacteristic(k: any, v: any) {
14
- this._chars[k] = v
15
- return this
16
- }
17
-
18
- getCharacteristic(k: any) {
19
- return {
20
- updateValue: (v: any) => {
21
- this._chars[k] = v
22
- return this
23
- },
24
- } as any
25
- }
26
- }
27
- const Characteristic: any = {
28
- Manufacturer: 'Manufacturer',
29
- AppMatchingIdentifier: 'AppMatchingIdentifier',
30
- Name: 'Name',
31
- ConfiguredName: 'ConfiguredName',
32
- Model: 'Model',
33
- ProductData: 'ProductData',
34
- SerialNumber: 'SerialNumber',
35
- HardwareRevision: 'HardwareRevision',
36
- SoftwareRevision: 'SoftwareRevision',
37
- FirmwareRevision: 'FirmwareRevision',
38
- On: 'On',
39
- }
40
- ;(Service as any).AccessoryInformation = class extends Service {}
41
- ;(Service as any).Outlet = class extends Service {}
42
- return { Service, Characteristic, Categories: { OUTLET: 7 } }
43
- }
44
-
45
- // Minimal PlatformAccessory stub
46
- function makeAccessoryStub(hap: any, name = 'Test Accessory') {
47
- const services: any[] = []
48
- return {
49
- displayName: name,
50
- category: 0,
51
- context: {},
52
- getService(cls: any) {
53
- // find existing or create
54
- const svc = services.find(s => s instanceof cls)
55
- if (svc) {
56
- return svc
57
- }
58
- const s = new cls()
59
- services.push(s)
60
- return s
61
- },
62
- addService(cls: any) {
63
- const s = new cls()
64
- services.push(s)
65
- return s
66
- },
67
- }
68
- }
69
-
70
- // Minimal SwitchBotHAPPlatform-like stub with required surface
71
- function makePlatformStub(options: any, hap: any) {
72
- const log = { info: vi.fn(), warn: vi.fn(), debug: vi.fn(), error: vi.fn(), success: vi.fn() }
73
- return {
74
- api: { hap },
75
- log,
76
- config: { options, credentials: {} },
77
- debugMode: false,
78
- // logging helpers used by deviceBase
79
- infoLog: () => {},
80
- successLog: () => {},
81
- debugSuccessLog: () => {},
82
- warnLog: () => {},
83
- debugWarnLog: () => {},
84
- errorLog: () => {},
85
- debugErrorLog: () => {},
86
- debugLog: () => {},
87
- loggingIsDebug: async () => false,
88
- enablingPlatformLogging: async () => true,
89
- connectBLE: vi.fn(),
90
- bleEventHandler: {},
91
- webhookEventHandler: {},
92
- }
93
- }
94
-
95
- // Create a tiny concrete subclass to instantiate deviceBase
96
- class TestHAPDevice extends deviceBase {
97
- // Override any methods that may be invoked by tests if needed
98
- }
99
-
100
- describe('hap device base webhook context', () => {
101
- it('sets accessory.context.webhook=true when global webhook is enabled and device.webhook is undefined', async () => {
102
- const hap = makeHapStub()
103
- const accessory: any = makeAccessoryStub(hap, 'Plug Device')
104
- const platform: any = makePlatformStub({ webhook: true, logging: 'debug' }, hap)
105
-
106
- const dev: any = {
107
- deviceId: 'DEV-HAP-1',
108
- deviceType: 'Plug',
109
- connectionType: 'OpenAPI',
110
- // webhook intentionally undefined
111
- }
112
-
113
- const d = new TestHAPDevice(platform, accessory, dev)
114
- // Assert context
115
- expect(accessory.context.webhook).toBe(true)
116
- // ensure no unused var warning
117
- expect(d).toBeDefined()
118
- })
119
-
120
- it('keeps accessory.context.webhook=false when device.webhook=false even if global is true', async () => {
121
- const hap = makeHapStub()
122
- const accessory: any = makeAccessoryStub(hap, 'Plug Device 2')
123
- const platform: any = makePlatformStub({ webhook: true, logging: 'debug' }, hap)
124
-
125
- const dev: any = {
126
- deviceId: 'DEV-HAP-2',
127
- deviceType: 'Plug',
128
- connectionType: 'OpenAPI',
129
- webhook: false,
130
- }
131
-
132
- const d = new TestHAPDevice(platform, accessory, dev)
133
- expect(accessory.context.webhook).toBe(false)
134
- expect(d).toBeDefined()
135
- })
136
- })
@@ -1,36 +0,0 @@
1
- /* eslint-disable import/first */
2
- import { describe, expect, it, vi } from 'vitest'
3
- // Mock modules used by the HAP platform constructor to avoid requiring a real Homebridge API
4
- vi.mock('fakegato-history', () => ({ default: () => ({}) }))
5
- vi.mock('homebridge-lib/EveHomeKitTypes', () => ({ EveHomeKitTypes: class { constructor() {} } }))
6
-
7
- import { SwitchBotHAPPlatform } from '../../platform-hap.js'
8
- import { makeLogStub } from '../helpers/platform-fixtures.js'
9
-
10
- /**
11
- * Verifies that HAP platform debug logger includes the accessory displayName
12
- * when loading an accessory from the cache.
13
- */
14
- describe('platform-hap logging', () => {
15
- it('prints accessory name when loading HAP cached accessory', async () => {
16
- const api: any = { on: vi.fn() }
17
- const log: any = makeLogStub()
18
-
19
- const platform = new SwitchBotHAPPlatform(log as any, {
20
- name: 'SwitchBot',
21
- credentials: {},
22
- options: { logging: 'debug' },
23
- devices: [],
24
- } as any, api)
25
-
26
- const accessory: any = { displayName: 'Test HAP Device' }
27
- await (platform as any).configureAccessory(accessory)
28
-
29
- // Allow async logger to flush
30
- await new Promise(resolve => setTimeout(resolve, 0))
31
-
32
- const calls = (log.info as any).mock.calls as Array<string[]>
33
- const hasLine = calls.some(args => String(args[0]).includes('Loading accessory from cache: Test HAP Device'))
34
- expect(hasLine).toBe(true)
35
- })
36
- })
@@ -1,70 +0,0 @@
1
- /* eslint-disable import/first */
2
- import { describe, expect, it, vi } from 'vitest'
3
- // Mock modules used by the HAP platform constructor to avoid requiring a real Homebridge API
4
- vi.mock('fakegato-history', () => ({ default: () => ({}) }))
5
- vi.mock('homebridge-lib/EveHomeKitTypes', () => ({ EveHomeKitTypes: class { constructor() {} } }))
6
-
7
- import { SwitchBotHAPPlatform } from '../../platform-hap.js'
8
- import { makeLogStub } from '../helpers/platform-fixtures.js'
9
-
10
- /**
11
- * High-level smoke tests for the HAP platform to ensure it initializes,
12
- * subscribes to lifecycle events, and handles cached accessories.
13
- */
14
- describe('platform-hap (smoke)', () => {
15
- it('initializes and subscribes to didFinishLaunching', async () => {
16
- const api: any = { on: vi.fn() }
17
- const log: any = makeLogStub()
18
-
19
- // Enable debug so debug* logs print via our shared logger
20
- // Construct the platform (smoke)
21
- new SwitchBotHAPPlatform(log as any, {
22
- name: 'SwitchBot',
23
- credentials: {},
24
- options: { logging: 'debug' },
25
- devices: [],
26
- } as any, api)
27
-
28
- // Should register didFinishLaunching handler
29
- expect(api.on).toHaveBeenCalled()
30
- const calledWithDL = (api.on as any).mock.calls.some((args: any[]) => args[0] === 'didFinishLaunching' && typeof args[1] === 'function')
31
- expect(calledWithDL).toBe(true)
32
-
33
- // Should log effective platform logging at startup
34
- const debugCalls = (log.debug as any).mock.calls as Array<string[]>
35
- const hasStartupLine = debugCalls.some(args => String(args[0]).includes('[SwitchBot HAP] effective platformLogging='))
36
- expect(hasStartupLine).toBe(true)
37
-
38
- // Missing credentials results in a debug error log
39
- // Allow async platform logger to flush
40
- await new Promise(resolve => setTimeout(resolve, 0))
41
- const errorCalls = (log.error as any).mock.calls as Array<string[]>
42
- const hasMissingCreds = errorCalls.some(args => String(args[0]).includes('Missing SwitchBot API credentials'))
43
- expect(hasMissingCreds).toBe(true)
44
- })
45
-
46
- it('adds cached accessories via configureAccessory', async () => {
47
- const api: any = { on: vi.fn() }
48
- const log: any = makeLogStub()
49
-
50
- const platform = new SwitchBotHAPPlatform(log as any, {
51
- name: 'SwitchBot',
52
- credentials: {},
53
- options: { logging: 'debug' },
54
- devices: [],
55
- } as any, api)
56
-
57
- const accessory: any = { displayName: 'Cached Device' }
58
- await (platform as any).configureAccessory(accessory)
59
-
60
- // Should be stored in platform.accessories
61
- expect(Array.isArray((platform as any).accessories)).toBe(true)
62
- expect((platform as any).accessories.length).toBe(1)
63
-
64
- // And should log the cache load message including device name
65
- await new Promise(resolve => setTimeout(resolve, 0))
66
- const infoCalls = (log.info as any).mock.calls as Array<string[]>
67
- const hasLine = infoCalls.some(args => String(args[0]).includes('Loading accessory from cache: Cached Device'))
68
- expect(hasLine).toBe(true)
69
- })
70
- })
@@ -1,33 +0,0 @@
1
- import { vi } from 'vitest'
2
-
3
- // Shared test helpers for platform-matter tests
4
- export function makeApiStub(matterProps: Record<string, any> = {}) {
5
- const handlers: Record<string, (...args: any[]) => any> = {}
6
-
7
- const api: any = {
8
- matter: {
9
- uuid: { generate: (s: string) => `uuid-${s}` },
10
- registerPlatformAccessories: matterProps.registerPlatformAccessories ?? vi.fn(),
11
- unregisterPlatformAccessories: matterProps.unregisterPlatformAccessories ?? vi.fn(),
12
- updateAccessoryState: matterProps.updateAccessoryState ?? vi.fn(),
13
- clusterNames: matterProps.clusterNames ?? {},
14
- deviceTypes: matterProps.deviceTypes ?? {},
15
- },
16
- isMatterAvailable: matterProps.isMatterAvailable ?? (() => true),
17
- isMatterEnabled: matterProps.isMatterEnabled ?? (() => true),
18
- on: (ev: string, fn: (...args: any[]) => any) => { handlers[ev] = fn },
19
- _handlers: handlers,
20
- }
21
-
22
- return api
23
- }
24
-
25
- export function makeLogStub() {
26
- return {
27
- info: vi.fn(),
28
- warn: vi.fn(),
29
- debug: vi.fn(),
30
- error: vi.fn(),
31
- success: vi.fn(),
32
- }
33
- }