@switchbot/homebridge-switchbot 5.0.0-beta.11 → 5.0.0-beta.110

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 (577) hide show
  1. package/.github/ISSUE_TEMPLATE/e2e-verification.md +36 -0
  2. package/.github/workflows/ci.yml +32 -0
  3. package/.github/workflows/manual-e2e.yml +115 -0
  4. package/.github/workflows/release.yml +0 -4
  5. package/CHANGELOG.md +35 -0
  6. package/E2E-VERIFICATION.md +121 -0
  7. package/MIGRATION.md +44 -0
  8. package/README.md +56 -3
  9. package/config.schema.json +170 -14787
  10. package/dist/device-types.d.ts +31 -0
  11. package/dist/device-types.d.ts.map +1 -0
  12. package/dist/device-types.js +216 -0
  13. package/dist/device-types.js.map +1 -0
  14. package/dist/deviceFactory.d.ts +13 -0
  15. package/dist/deviceFactory.d.ts.map +1 -0
  16. package/dist/deviceFactory.js +120 -0
  17. package/dist/deviceFactory.js.map +1 -0
  18. package/dist/devices/deviceBase.d.ts +50 -0
  19. package/dist/devices/deviceBase.d.ts.map +1 -0
  20. package/dist/devices/deviceBase.js +119 -0
  21. package/dist/devices/deviceBase.js.map +1 -0
  22. package/dist/devices/genericDevice.d.ts +298 -0
  23. package/dist/devices/genericDevice.d.ts.map +1 -0
  24. package/dist/devices/genericDevice.js +1067 -0
  25. package/dist/devices/genericDevice.js.map +1 -0
  26. package/dist/homebridge-ui/endpoints/config.d.ts +3 -0
  27. package/dist/homebridge-ui/endpoints/config.d.ts.map +1 -0
  28. package/dist/homebridge-ui/endpoints/config.js +104 -0
  29. package/dist/homebridge-ui/endpoints/config.js.map +1 -0
  30. package/dist/homebridge-ui/endpoints/credentials.d.ts +6 -0
  31. package/dist/homebridge-ui/endpoints/credentials.d.ts.map +1 -0
  32. package/dist/homebridge-ui/endpoints/credentials.js +65 -0
  33. package/dist/homebridge-ui/endpoints/credentials.js.map +1 -0
  34. package/dist/homebridge-ui/endpoints/devices.d.ts +6 -0
  35. package/dist/homebridge-ui/endpoints/devices.d.ts.map +1 -0
  36. package/dist/homebridge-ui/endpoints/devices.js +342 -0
  37. package/dist/homebridge-ui/endpoints/devices.js.map +1 -0
  38. package/dist/homebridge-ui/endpoints/discovery.d.ts +7 -0
  39. package/dist/homebridge-ui/endpoints/discovery.d.ts.map +1 -0
  40. package/dist/homebridge-ui/endpoints/discovery.js +171 -0
  41. package/dist/homebridge-ui/endpoints/discovery.js.map +1 -0
  42. package/dist/homebridge-ui/public/css/styles.css +254 -0
  43. package/dist/homebridge-ui/public/index.html +112 -247
  44. package/dist/homebridge-ui/public/js/api.d.ts +19 -0
  45. package/dist/homebridge-ui/public/js/api.d.ts.map +1 -0
  46. package/dist/homebridge-ui/public/js/api.js +178 -0
  47. package/dist/homebridge-ui/public/js/api.js.map +1 -0
  48. package/dist/homebridge-ui/public/js/api.ts +205 -0
  49. package/dist/homebridge-ui/public/js/app.d.ts +2 -0
  50. package/dist/homebridge-ui/public/js/app.d.ts.map +1 -0
  51. package/dist/homebridge-ui/public/js/app.js +1581 -0
  52. package/dist/homebridge-ui/public/js/app.js.map +7 -0
  53. package/dist/homebridge-ui/public/js/app.ts +22 -0
  54. package/dist/homebridge-ui/public/js/constants.d.ts +2 -0
  55. package/dist/homebridge-ui/public/js/constants.d.ts.map +1 -0
  56. package/dist/homebridge-ui/public/js/constants.js +2 -0
  57. package/dist/homebridge-ui/public/js/constants.js.map +1 -0
  58. package/dist/homebridge-ui/public/js/constants.ts +1 -0
  59. package/dist/homebridge-ui/public/js/credentials.d.ts +3 -0
  60. package/dist/homebridge-ui/public/js/credentials.d.ts.map +1 -0
  61. package/dist/homebridge-ui/public/js/credentials.js +96 -0
  62. package/dist/homebridge-ui/public/js/credentials.js.map +1 -0
  63. package/dist/homebridge-ui/public/js/credentials.ts +100 -0
  64. package/dist/homebridge-ui/public/js/devices-delete.d.ts +3 -0
  65. package/dist/homebridge-ui/public/js/devices-delete.d.ts.map +1 -0
  66. package/dist/homebridge-ui/public/js/devices-delete.js +206 -0
  67. package/dist/homebridge-ui/public/js/devices-delete.js.map +1 -0
  68. package/dist/homebridge-ui/public/js/devices-delete.ts +236 -0
  69. package/dist/homebridge-ui/public/js/devices.d.ts +9 -0
  70. package/dist/homebridge-ui/public/js/devices.d.ts.map +1 -0
  71. package/dist/homebridge-ui/public/js/devices.js +81 -0
  72. package/dist/homebridge-ui/public/js/devices.js.map +1 -0
  73. package/dist/homebridge-ui/public/js/devices.ts +88 -0
  74. package/dist/homebridge-ui/public/js/discovery.d.ts +3 -0
  75. package/dist/homebridge-ui/public/js/discovery.d.ts.map +1 -0
  76. package/dist/homebridge-ui/public/js/discovery.js +233 -0
  77. package/dist/homebridge-ui/public/js/discovery.js.map +1 -0
  78. package/dist/homebridge-ui/public/js/discovery.ts +277 -0
  79. package/dist/homebridge-ui/public/js/logger.d.ts +6 -0
  80. package/dist/homebridge-ui/public/js/logger.d.ts.map +1 -0
  81. package/dist/homebridge-ui/public/js/logger.js +12 -0
  82. package/dist/homebridge-ui/public/js/logger.js.map +1 -0
  83. package/dist/homebridge-ui/public/js/logger.ts +11 -0
  84. package/dist/homebridge-ui/public/js/modal.d.ts +5 -0
  85. package/dist/homebridge-ui/public/js/modal.d.ts.map +1 -0
  86. package/dist/homebridge-ui/public/js/modal.js +26 -0
  87. package/dist/homebridge-ui/public/js/modal.js.map +1 -0
  88. package/dist/homebridge-ui/public/js/modal.ts +28 -0
  89. package/dist/homebridge-ui/public/js/modals.d.ts +2 -0
  90. package/dist/homebridge-ui/public/js/modals.d.ts.map +1 -0
  91. package/dist/homebridge-ui/public/js/modals.js +177 -0
  92. package/dist/homebridge-ui/public/js/modals.js.map +1 -0
  93. package/dist/homebridge-ui/public/js/modals.ts +200 -0
  94. package/dist/homebridge-ui/public/js/render.d.ts +63 -0
  95. package/dist/homebridge-ui/public/js/render.d.ts.map +1 -0
  96. package/dist/homebridge-ui/public/js/render.js +439 -0
  97. package/dist/homebridge-ui/public/js/render.js.map +1 -0
  98. package/dist/homebridge-ui/public/js/render.ts +510 -0
  99. package/dist/homebridge-ui/public/js/toast.d.ts +6 -0
  100. package/dist/homebridge-ui/public/js/toast.d.ts.map +1 -0
  101. package/dist/homebridge-ui/public/js/toast.js +29 -0
  102. package/dist/homebridge-ui/public/js/toast.js.map +1 -0
  103. package/dist/homebridge-ui/public/js/toast.ts +37 -0
  104. package/dist/homebridge-ui/public/js/types.d.ts +23 -0
  105. package/dist/homebridge-ui/public/js/types.d.ts.map +1 -0
  106. package/dist/homebridge-ui/public/js/types.js +2 -0
  107. package/dist/homebridge-ui/public/js/types.js.map +1 -0
  108. package/dist/homebridge-ui/public/js/types.ts +26 -0
  109. package/dist/homebridge-ui/server.js +11 -41
  110. package/dist/homebridge-ui/server.js.map +1 -1
  111. package/dist/homebridge-ui/utils/config-parser.d.ts +35 -0
  112. package/dist/homebridge-ui/utils/config-parser.d.ts.map +1 -0
  113. package/dist/homebridge-ui/utils/config-parser.js +87 -0
  114. package/dist/homebridge-ui/utils/config-parser.js.map +1 -0
  115. package/dist/homebridge-ui/utils/device-migration.d.ts +35 -0
  116. package/dist/homebridge-ui/utils/device-migration.d.ts.map +1 -0
  117. package/dist/homebridge-ui/utils/device-migration.js +111 -0
  118. package/dist/homebridge-ui/utils/device-migration.js.map +1 -0
  119. package/dist/homebridge-ui/utils/logger.d.ts +7 -0
  120. package/dist/homebridge-ui/utils/logger.d.ts.map +1 -0
  121. package/dist/homebridge-ui/utils/logger.js +17 -0
  122. package/dist/homebridge-ui/utils/logger.js.map +1 -0
  123. package/dist/index.d.ts.map +1 -1
  124. package/dist/index.js +4 -65
  125. package/dist/index.js.map +1 -1
  126. package/dist/platform.d.ts +35 -0
  127. package/dist/platform.d.ts.map +1 -0
  128. package/dist/platform.js +1567 -0
  129. package/dist/platform.js.map +1 -0
  130. package/dist/settings.d.ts +10 -249
  131. package/dist/settings.d.ts.map +1 -1
  132. package/dist/settings.js +5 -30
  133. package/dist/settings.js.map +1 -1
  134. package/dist/switchbotClient.d.ts +32 -0
  135. package/dist/switchbotClient.d.ts.map +1 -0
  136. package/dist/switchbotClient.js +207 -0
  137. package/dist/switchbotClient.js.map +1 -0
  138. package/dist/utils.d.ts +39 -50
  139. package/dist/utils.d.ts.map +1 -1
  140. package/dist/utils.js +39 -688
  141. package/dist/utils.js.map +1 -1
  142. package/docs/assets/highlight.css +14 -0
  143. package/docs/assets/icons.js +1 -1
  144. package/docs/assets/icons.svg +1 -1
  145. package/docs/assets/main.js +2 -2
  146. package/docs/assets/style.css +3 -3
  147. package/docs/index.html +77 -13
  148. package/docs/variables/default.html +1 -1
  149. package/eslint.config.js +7 -8
  150. package/nodemon.json +2 -2
  151. package/package.json +35 -32
  152. package/scripts/build-ui.js +36 -0
  153. package/scripts/e2e/README.md +25 -0
  154. package/scripts/e2e/curtain-e2e.sh +70 -0
  155. package/scripts/e2e/fan-e2e.sh +75 -0
  156. package/scripts/e2e/light-advanced-e2e.sh +97 -0
  157. package/scripts/e2e/light-e2e.sh +75 -0
  158. package/scripts/e2e/list-accessories.sh +19 -0
  159. package/scripts/e2e/lock-e2e.sh +65 -0
  160. package/scripts/free-dev-ports.mjs +105 -0
  161. package/scripts/generate-matter-maps.js +60 -0
  162. package/scripts/run-e2e-local.sh +14 -0
  163. package/scripts/sync-device-types.mjs +28 -0
  164. package/src/device-types.ts +230 -0
  165. package/src/deviceFactory.ts +163 -0
  166. package/src/devices/deviceBase.ts +141 -0
  167. package/src/devices/genericDevice.ts +998 -0
  168. package/src/homebridge-ui/endpoints/config.ts +123 -0
  169. package/src/homebridge-ui/endpoints/credentials.ts +74 -0
  170. package/src/homebridge-ui/endpoints/devices.ts +380 -0
  171. package/src/homebridge-ui/endpoints/discovery.ts +191 -0
  172. package/src/homebridge-ui/public/css/styles.css +254 -0
  173. package/src/homebridge-ui/public/index.html +112 -247
  174. package/src/homebridge-ui/public/js/api.ts +205 -0
  175. package/src/homebridge-ui/public/js/app.ts +22 -0
  176. package/src/homebridge-ui/public/js/constants.ts +1 -0
  177. package/src/homebridge-ui/public/js/credentials.ts +100 -0
  178. package/src/homebridge-ui/public/js/devices-delete.ts +236 -0
  179. package/src/homebridge-ui/public/js/devices.ts +88 -0
  180. package/src/homebridge-ui/public/js/discovery.ts +277 -0
  181. package/src/homebridge-ui/public/js/logger.ts +11 -0
  182. package/src/homebridge-ui/public/js/modal.ts +28 -0
  183. package/src/homebridge-ui/public/js/modals.ts +200 -0
  184. package/src/homebridge-ui/public/js/render.ts +510 -0
  185. package/src/homebridge-ui/public/js/toast.ts +37 -0
  186. package/src/homebridge-ui/public/js/types.ts +26 -0
  187. package/src/homebridge-ui/server.ts +11 -43
  188. package/src/homebridge-ui/utils/config-parser.ts +108 -0
  189. package/src/homebridge-ui/utils/device-migration.ts +144 -0
  190. package/src/homebridge-ui/utils/logger.ts +17 -0
  191. package/src/index.ts +4 -66
  192. package/src/platform.ts +1566 -0
  193. package/src/settings.ts +12 -277
  194. package/src/switchbotClient.ts +216 -0
  195. package/src/utils.ts +45 -713
  196. package/switchbot-homebridge-switchbot-5.0.0.tgz +0 -0
  197. package/test/accessory-restore.spec.ts +73 -0
  198. package/test/device-mapping.spec.ts +37 -0
  199. package/test/deviceFactory.spec.ts +18 -0
  200. package/test/e2e/run-e2e.spec.ts +50 -0
  201. package/test/fan-swing.spec.ts +29 -0
  202. package/test/helpers/matter-harness.ts +53 -0
  203. package/test/lock-users.spec.ts +44 -0
  204. package/test/matter-childbridge.spec.ts +55 -0
  205. package/test/matter-descriptors.spec.ts +97 -0
  206. package/test/matter-device-state.spec.ts +101 -0
  207. package/test/matter-integration.spec.ts +70 -0
  208. package/test/platform.integration.spec.ts +55 -0
  209. package/test/switchbot-client-debounce.spec.ts +131 -0
  210. package/test/switchbot-client-openapi.spec.ts +56 -0
  211. package/test/switchbotClient.spec.ts +10 -0
  212. package/test/utils.spec.ts +20 -0
  213. package/todo/COMPLETED.md +189 -0
  214. package/todo/README.md +59 -0
  215. package/todo/TODO.md +205 -0
  216. package/todo/mockups/filtering-sorting.svg +112 -0
  217. package/todo/mockups/modal-switchbot-theme.svg +66 -0
  218. package/todo/mockups/signal-strength-visualization.svg +94 -0
  219. package/vitest.config.ts +7 -0
  220. package/coverage/base.css +0 -224
  221. package/coverage/block-navigation.js +0 -87
  222. package/coverage/clover.xml +0 -15847
  223. package/coverage/coverage-final.json +0 -42
  224. package/coverage/docs/assets/dmt/dmt-component-data.js.html +0 -85
  225. package/coverage/docs/assets/dmt/dmt-components.js.html +0 -286
  226. package/coverage/docs/assets/dmt/index.html +0 -131
  227. package/coverage/docs/assets/hierarchy.js.html +0 -85
  228. package/coverage/docs/assets/icons.js.html +0 -136
  229. package/coverage/docs/assets/index.html +0 -146
  230. package/coverage/docs/assets/main.js.html +0 -265
  231. package/coverage/favicon.png +0 -0
  232. package/coverage/index.html +0 -191
  233. package/coverage/prettify.css +0 -1
  234. package/coverage/prettify.js +0 -2
  235. package/coverage/sort-arrow-sprite.png +0 -0
  236. package/coverage/sorter.js +0 -196
  237. package/coverage/src/device/blindtilt.ts.html +0 -3238
  238. package/coverage/src/device/bot.ts.html +0 -2803
  239. package/coverage/src/device/ceilinglight.ts.html +0 -2338
  240. package/coverage/src/device/colorbulb.ts.html +0 -2824
  241. package/coverage/src/device/contact.ts.html +0 -1465
  242. package/coverage/src/device/curtain.ts.html +0 -2869
  243. package/coverage/src/device/device.ts.html +0 -2500
  244. package/coverage/src/device/fan.ts.html +0 -2242
  245. package/coverage/src/device/hub.ts.html +0 -1408
  246. package/coverage/src/device/humidifier.ts.html +0 -2116
  247. package/coverage/src/device/index.html +0 -416
  248. package/coverage/src/device/iosensor.ts.html +0 -1375
  249. package/coverage/src/device/lightstrip.ts.html +0 -2617
  250. package/coverage/src/device/lock.ts.html +0 -1963
  251. package/coverage/src/device/meter.ts.html +0 -1372
  252. package/coverage/src/device/meterplus.ts.html +0 -1384
  253. package/coverage/src/device/meterpro.ts.html +0 -1618
  254. package/coverage/src/device/motion.ts.html +0 -1264
  255. package/coverage/src/device/plug.ts.html +0 -1372
  256. package/coverage/src/device/relayswitch.ts.html +0 -2284
  257. package/coverage/src/device/robotvacuumcleaner.ts.html +0 -1810
  258. package/coverage/src/device/waterdetector.ts.html +0 -1294
  259. package/coverage/src/homebridge-ui/index.html +0 -116
  260. package/coverage/src/homebridge-ui/server.ts.html +0 -229
  261. package/coverage/src/index.html +0 -161
  262. package/coverage/src/index.ts.html +0 -124
  263. package/coverage/src/irdevice/airconditioner.ts.html +0 -1687
  264. package/coverage/src/irdevice/airpurifier.ts.html +0 -844
  265. package/coverage/src/irdevice/camera.ts.html +0 -475
  266. package/coverage/src/irdevice/fan.ts.html +0 -766
  267. package/coverage/src/irdevice/index.html +0 -251
  268. package/coverage/src/irdevice/irdevice.ts.html +0 -1117
  269. package/coverage/src/irdevice/light.ts.html +0 -826
  270. package/coverage/src/irdevice/other.ts.html +0 -2458
  271. package/coverage/src/irdevice/tv.ts.html +0 -1222
  272. package/coverage/src/irdevice/vacuumcleaner.ts.html +0 -466
  273. package/coverage/src/irdevice/waterheater.ts.html +0 -469
  274. package/coverage/src/platform.ts.html +0 -8776
  275. package/coverage/src/settings.ts.html +0 -934
  276. package/coverage/src/utils.ts.html +0 -2092
  277. package/dist/devices-hap/airpurifier.d.ts +0 -54
  278. package/dist/devices-hap/airpurifier.d.ts.map +0 -1
  279. package/dist/devices-hap/airpurifier.js +0 -527
  280. package/dist/devices-hap/airpurifier.js.map +0 -1
  281. package/dist/devices-hap/blindtilt.d.ts +0 -90
  282. package/dist/devices-hap/blindtilt.d.ts.map +0 -1
  283. package/dist/devices-hap/blindtilt.js +0 -974
  284. package/dist/devices-hap/blindtilt.js.map +0 -1
  285. package/dist/devices-hap/bot.d.ts +0 -102
  286. package/dist/devices-hap/bot.d.ts.map +0 -1
  287. package/dist/devices-hap/bot.js +0 -811
  288. package/dist/devices-hap/bot.js.map +0 -1
  289. package/dist/devices-hap/ceilinglight.d.ts +0 -85
  290. package/dist/devices-hap/ceilinglight.d.ts.map +0 -1
  291. package/dist/devices-hap/ceilinglight.js +0 -701
  292. package/dist/devices-hap/ceilinglight.js.map +0 -1
  293. package/dist/devices-hap/colorbulb.d.ts +0 -88
  294. package/dist/devices-hap/colorbulb.d.ts.map +0 -1
  295. package/dist/devices-hap/colorbulb.js +0 -881
  296. package/dist/devices-hap/colorbulb.js.map +0 -1
  297. package/dist/devices-hap/contact.d.ts +0 -44
  298. package/dist/devices-hap/contact.d.ts.map +0 -1
  299. package/dist/devices-hap/contact.js +0 -409
  300. package/dist/devices-hap/contact.js.map +0 -1
  301. package/dist/devices-hap/curtain.d.ts +0 -73
  302. package/dist/devices-hap/curtain.d.ts.map +0 -1
  303. package/dist/devices-hap/curtain.js +0 -869
  304. package/dist/devices-hap/curtain.js.map +0 -1
  305. package/dist/devices-hap/device.d.ts +0 -98
  306. package/dist/devices-hap/device.d.ts.map +0 -1
  307. package/dist/devices-hap/device.js +0 -749
  308. package/dist/devices-hap/device.js.map +0 -1
  309. package/dist/devices-hap/fan.d.ts +0 -69
  310. package/dist/devices-hap/fan.d.ts.map +0 -1
  311. package/dist/devices-hap/fan.js +0 -649
  312. package/dist/devices-hap/fan.js.map +0 -1
  313. package/dist/devices-hap/hub.d.ts +0 -37
  314. package/dist/devices-hap/hub.d.ts.map +0 -1
  315. package/dist/devices-hap/hub.js +0 -392
  316. package/dist/devices-hap/hub.js.map +0 -1
  317. package/dist/devices-hap/humidifier.d.ts +0 -68
  318. package/dist/devices-hap/humidifier.d.ts.map +0 -1
  319. package/dist/devices-hap/humidifier.js +0 -628
  320. package/dist/devices-hap/humidifier.js.map +0 -1
  321. package/dist/devices-hap/iosensor.d.ts +0 -42
  322. package/dist/devices-hap/iosensor.d.ts.map +0 -1
  323. package/dist/devices-hap/iosensor.js +0 -382
  324. package/dist/devices-hap/iosensor.js.map +0 -1
  325. package/dist/devices-hap/lightstrip.d.ts +0 -79
  326. package/dist/devices-hap/lightstrip.d.ts.map +0 -1
  327. package/dist/devices-hap/lightstrip.js +0 -797
  328. package/dist/devices-hap/lightstrip.js.map +0 -1
  329. package/dist/devices-hap/lock.d.ts +0 -53
  330. package/dist/devices-hap/lock.d.ts.map +0 -1
  331. package/dist/devices-hap/lock.js +0 -561
  332. package/dist/devices-hap/lock.js.map +0 -1
  333. package/dist/devices-hap/meter.d.ts +0 -37
  334. package/dist/devices-hap/meter.d.ts.map +0 -1
  335. package/dist/devices-hap/meter.js +0 -379
  336. package/dist/devices-hap/meter.js.map +0 -1
  337. package/dist/devices-hap/meterplus.d.ts +0 -42
  338. package/dist/devices-hap/meterplus.d.ts.map +0 -1
  339. package/dist/devices-hap/meterplus.js +0 -384
  340. package/dist/devices-hap/meterplus.js.map +0 -1
  341. package/dist/devices-hap/meterpro.d.ts +0 -43
  342. package/dist/devices-hap/meterpro.d.ts.map +0 -1
  343. package/dist/devices-hap/meterpro.js +0 -468
  344. package/dist/devices-hap/meterpro.js.map +0 -1
  345. package/dist/devices-hap/motion.d.ts +0 -42
  346. package/dist/devices-hap/motion.d.ts.map +0 -1
  347. package/dist/devices-hap/motion.js +0 -345
  348. package/dist/devices-hap/motion.js.map +0 -1
  349. package/dist/devices-hap/plug.d.ts +0 -49
  350. package/dist/devices-hap/plug.d.ts.map +0 -1
  351. package/dist/devices-hap/plug.js +0 -395
  352. package/dist/devices-hap/plug.js.map +0 -1
  353. package/dist/devices-hap/relayswitch.d.ts +0 -96
  354. package/dist/devices-hap/relayswitch.d.ts.map +0 -1
  355. package/dist/devices-hap/relayswitch.js +0 -642
  356. package/dist/devices-hap/relayswitch.js.map +0 -1
  357. package/dist/devices-hap/robotvacuumcleaner.d.ts +0 -54
  358. package/dist/devices-hap/robotvacuumcleaner.d.ts.map +0 -1
  359. package/dist/devices-hap/robotvacuumcleaner.js +0 -523
  360. package/dist/devices-hap/robotvacuumcleaner.js.map +0 -1
  361. package/dist/devices-hap/waterdetector.d.ts +0 -41
  362. package/dist/devices-hap/waterdetector.d.ts.map +0 -1
  363. package/dist/devices-hap/waterdetector.js +0 -356
  364. package/dist/devices-hap/waterdetector.js.map +0 -1
  365. package/dist/devices-matter/BaseMatterAccessory.d.ts +0 -63
  366. package/dist/devices-matter/BaseMatterAccessory.d.ts.map +0 -1
  367. package/dist/devices-matter/BaseMatterAccessory.js +0 -100
  368. package/dist/devices-matter/BaseMatterAccessory.js.map +0 -1
  369. package/dist/devices-matter/ColorLightAccessory.d.ts +0 -20
  370. package/dist/devices-matter/ColorLightAccessory.d.ts.map +0 -1
  371. package/dist/devices-matter/ColorLightAccessory.js +0 -95
  372. package/dist/devices-matter/ColorLightAccessory.js.map +0 -1
  373. package/dist/devices-matter/ColorTemperatureLightAccessory.d.ts +0 -18
  374. package/dist/devices-matter/ColorTemperatureLightAccessory.d.ts.map +0 -1
  375. package/dist/devices-matter/ColorTemperatureLightAccessory.js +0 -78
  376. package/dist/devices-matter/ColorTemperatureLightAccessory.js.map +0 -1
  377. package/dist/devices-matter/ContactSensorAccessory.d.ts +0 -12
  378. package/dist/devices-matter/ContactSensorAccessory.d.ts.map +0 -1
  379. package/dist/devices-matter/ContactSensorAccessory.js +0 -34
  380. package/dist/devices-matter/ContactSensorAccessory.js.map +0 -1
  381. package/dist/devices-matter/DimmableLightAccessory.d.ts +0 -58
  382. package/dist/devices-matter/DimmableLightAccessory.d.ts.map +0 -1
  383. package/dist/devices-matter/DimmableLightAccessory.js +0 -167
  384. package/dist/devices-matter/DimmableLightAccessory.js.map +0 -1
  385. package/dist/devices-matter/DoorLockAccessory.d.ts +0 -14
  386. package/dist/devices-matter/DoorLockAccessory.d.ts.map +0 -1
  387. package/dist/devices-matter/DoorLockAccessory.js +0 -50
  388. package/dist/devices-matter/DoorLockAccessory.js.map +0 -1
  389. package/dist/devices-matter/ExtendedColorLightAccessory.d.ts +0 -21
  390. package/dist/devices-matter/ExtendedColorLightAccessory.d.ts.map +0 -1
  391. package/dist/devices-matter/ExtendedColorLightAccessory.js +0 -107
  392. package/dist/devices-matter/ExtendedColorLightAccessory.js.map +0 -1
  393. package/dist/devices-matter/FanAccessory.d.ts +0 -16
  394. package/dist/devices-matter/FanAccessory.d.ts.map +0 -1
  395. package/dist/devices-matter/FanAccessory.js +0 -81
  396. package/dist/devices-matter/FanAccessory.js.map +0 -1
  397. package/dist/devices-matter/HumiditySensorAccessory.d.ts +0 -12
  398. package/dist/devices-matter/HumiditySensorAccessory.d.ts.map +0 -1
  399. package/dist/devices-matter/HumiditySensorAccessory.js +0 -34
  400. package/dist/devices-matter/HumiditySensorAccessory.js.map +0 -1
  401. package/dist/devices-matter/LeakSensorAccessory.d.ts +0 -12
  402. package/dist/devices-matter/LeakSensorAccessory.d.ts.map +0 -1
  403. package/dist/devices-matter/LeakSensorAccessory.js +0 -33
  404. package/dist/devices-matter/LeakSensorAccessory.js.map +0 -1
  405. package/dist/devices-matter/LightSensorAccessory.d.ts +0 -12
  406. package/dist/devices-matter/LightSensorAccessory.d.ts.map +0 -1
  407. package/dist/devices-matter/LightSensorAccessory.js +0 -34
  408. package/dist/devices-matter/LightSensorAccessory.js.map +0 -1
  409. package/dist/devices-matter/OccupancySensorAccessory.d.ts +0 -12
  410. package/dist/devices-matter/OccupancySensorAccessory.d.ts.map +0 -1
  411. package/dist/devices-matter/OccupancySensorAccessory.js +0 -39
  412. package/dist/devices-matter/OccupancySensorAccessory.js.map +0 -1
  413. package/dist/devices-matter/OnOffLightAccessory.d.ts +0 -38
  414. package/dist/devices-matter/OnOffLightAccessory.d.ts.map +0 -1
  415. package/dist/devices-matter/OnOffLightAccessory.js +0 -118
  416. package/dist/devices-matter/OnOffLightAccessory.js.map +0 -1
  417. package/dist/devices-matter/OnOffOutletAccessory.d.ts +0 -12
  418. package/dist/devices-matter/OnOffOutletAccessory.d.ts.map +0 -1
  419. package/dist/devices-matter/OnOffOutletAccessory.js +0 -40
  420. package/dist/devices-matter/OnOffOutletAccessory.js.map +0 -1
  421. package/dist/devices-matter/OnOffSwitchAccessory.d.ts +0 -14
  422. package/dist/devices-matter/OnOffSwitchAccessory.d.ts.map +0 -1
  423. package/dist/devices-matter/OnOffSwitchAccessory.js +0 -42
  424. package/dist/devices-matter/OnOffSwitchAccessory.js.map +0 -1
  425. package/dist/devices-matter/RoboticVacuumAccessory.d.ts +0 -68
  426. package/dist/devices-matter/RoboticVacuumAccessory.d.ts.map +0 -1
  427. package/dist/devices-matter/RoboticVacuumAccessory.js +0 -334
  428. package/dist/devices-matter/RoboticVacuumAccessory.js.map +0 -1
  429. package/dist/devices-matter/SmokeCOAlarmAccessory.d.ts +0 -11
  430. package/dist/devices-matter/SmokeCOAlarmAccessory.d.ts.map +0 -1
  431. package/dist/devices-matter/SmokeCOAlarmAccessory.js +0 -49
  432. package/dist/devices-matter/SmokeCOAlarmAccessory.js.map +0 -1
  433. package/dist/devices-matter/TemperatureSensorAccessory.d.ts +0 -12
  434. package/dist/devices-matter/TemperatureSensorAccessory.d.ts.map +0 -1
  435. package/dist/devices-matter/TemperatureSensorAccessory.js +0 -36
  436. package/dist/devices-matter/TemperatureSensorAccessory.js.map +0 -1
  437. package/dist/devices-matter/ThermostatAccessory.d.ts +0 -19
  438. package/dist/devices-matter/ThermostatAccessory.d.ts.map +0 -1
  439. package/dist/devices-matter/ThermostatAccessory.js +0 -95
  440. package/dist/devices-matter/ThermostatAccessory.js.map +0 -1
  441. package/dist/devices-matter/VenetianBlindAccessory.d.ts +0 -19
  442. package/dist/devices-matter/VenetianBlindAccessory.d.ts.map +0 -1
  443. package/dist/devices-matter/VenetianBlindAccessory.js +0 -99
  444. package/dist/devices-matter/VenetianBlindAccessory.js.map +0 -1
  445. package/dist/devices-matter/WindowBlindAccessory.d.ts +0 -17
  446. package/dist/devices-matter/WindowBlindAccessory.d.ts.map +0 -1
  447. package/dist/devices-matter/WindowBlindAccessory.js +0 -80
  448. package/dist/devices-matter/WindowBlindAccessory.js.map +0 -1
  449. package/dist/devices-matter/custom/PowerStripAccessory.d.ts +0 -97
  450. package/dist/devices-matter/custom/PowerStripAccessory.d.ts.map +0 -1
  451. package/dist/devices-matter/custom/PowerStripAccessory.js +0 -265
  452. package/dist/devices-matter/custom/PowerStripAccessory.js.map +0 -1
  453. package/dist/devices-matter/custom/index.d.ts +0 -8
  454. package/dist/devices-matter/custom/index.d.ts.map +0 -1
  455. package/dist/devices-matter/custom/index.js +0 -8
  456. package/dist/devices-matter/custom/index.js.map +0 -1
  457. package/dist/devices-matter/index.d.ts +0 -29
  458. package/dist/devices-matter/index.d.ts.map +0 -1
  459. package/dist/devices-matter/index.js +0 -28
  460. package/dist/devices-matter/index.js.map +0 -1
  461. package/dist/index.test.d.ts +0 -2
  462. package/dist/index.test.d.ts.map +0 -1
  463. package/dist/index.test.js +0 -19
  464. package/dist/index.test.js.map +0 -1
  465. package/dist/irdevice/airconditioner.d.ts +0 -61
  466. package/dist/irdevice/airconditioner.d.ts.map +0 -1
  467. package/dist/irdevice/airconditioner.js +0 -472
  468. package/dist/irdevice/airconditioner.js.map +0 -1
  469. package/dist/irdevice/airpurifier.d.ts +0 -50
  470. package/dist/irdevice/airpurifier.d.ts.map +0 -1
  471. package/dist/irdevice/airpurifier.js +0 -213
  472. package/dist/irdevice/airpurifier.js.map +0 -1
  473. package/dist/irdevice/camera.d.ts +0 -32
  474. package/dist/irdevice/camera.d.ts.map +0 -1
  475. package/dist/irdevice/camera.js +0 -107
  476. package/dist/irdevice/camera.js.map +0 -1
  477. package/dist/irdevice/fan.d.ts +0 -36
  478. package/dist/irdevice/fan.d.ts.map +0 -1
  479. package/dist/irdevice/fan.js +0 -200
  480. package/dist/irdevice/fan.js.map +0 -1
  481. package/dist/irdevice/irdevice.d.ts +0 -68
  482. package/dist/irdevice/irdevice.d.ts.map +0 -1
  483. package/dist/irdevice/irdevice.js +0 -298
  484. package/dist/irdevice/irdevice.js.map +0 -1
  485. package/dist/irdevice/light.d.ts +0 -36
  486. package/dist/irdevice/light.d.ts.map +0 -1
  487. package/dist/irdevice/light.js +0 -206
  488. package/dist/irdevice/light.js.map +0 -1
  489. package/dist/irdevice/other.d.ts +0 -57
  490. package/dist/irdevice/other.d.ts.map +0 -1
  491. package/dist/irdevice/other.js +0 -778
  492. package/dist/irdevice/other.js.map +0 -1
  493. package/dist/irdevice/tv.d.ts +0 -45
  494. package/dist/irdevice/tv.d.ts.map +0 -1
  495. package/dist/irdevice/tv.js +0 -327
  496. package/dist/irdevice/tv.js.map +0 -1
  497. package/dist/irdevice/vacuumcleaner.d.ts +0 -28
  498. package/dist/irdevice/vacuumcleaner.d.ts.map +0 -1
  499. package/dist/irdevice/vacuumcleaner.js +0 -104
  500. package/dist/irdevice/vacuumcleaner.js.map +0 -1
  501. package/dist/irdevice/waterheater.d.ts +0 -30
  502. package/dist/irdevice/waterheater.d.ts.map +0 -1
  503. package/dist/irdevice/waterheater.js +0 -105
  504. package/dist/irdevice/waterheater.js.map +0 -1
  505. package/dist/platform-hap.d.ts +0 -149
  506. package/dist/platform-hap.d.ts.map +0 -1
  507. package/dist/platform-hap.js +0 -2861
  508. package/dist/platform-hap.js.map +0 -1
  509. package/dist/platform-matter.d.ts +0 -120
  510. package/dist/platform-matter.d.ts.map +0 -1
  511. package/dist/platform-matter.js +0 -984
  512. package/dist/platform-matter.js.map +0 -1
  513. package/dist/verifyconfig.test.d.ts +0 -2
  514. package/dist/verifyconfig.test.d.ts.map +0 -1
  515. package/dist/verifyconfig.test.js +0 -167
  516. package/dist/verifyconfig.test.js.map +0 -1
  517. package/src/custom.d.ts +0 -7
  518. package/src/devices-hap/airpurifier.ts +0 -563
  519. package/src/devices-hap/blindtilt.ts +0 -1049
  520. package/src/devices-hap/bot.ts +0 -900
  521. package/src/devices-hap/ceilinglight.ts +0 -742
  522. package/src/devices-hap/colorbulb.ts +0 -904
  523. package/src/devices-hap/contact.ts +0 -457
  524. package/src/devices-hap/curtain.ts +0 -944
  525. package/src/devices-hap/device.ts +0 -811
  526. package/src/devices-hap/fan.ts +0 -711
  527. package/src/devices-hap/hub.ts +0 -439
  528. package/src/devices-hap/humidifier.ts +0 -669
  529. package/src/devices-hap/iosensor.ts +0 -427
  530. package/src/devices-hap/lightstrip.ts +0 -836
  531. package/src/devices-hap/lock.ts +0 -620
  532. package/src/devices-hap/meter.ts +0 -426
  533. package/src/devices-hap/meterplus.ts +0 -430
  534. package/src/devices-hap/meterpro.ts +0 -522
  535. package/src/devices-hap/motion.ts +0 -390
  536. package/src/devices-hap/plug.ts +0 -423
  537. package/src/devices-hap/relayswitch.ts +0 -727
  538. package/src/devices-hap/robotvacuumcleaner.ts +0 -568
  539. package/src/devices-hap/waterdetector.ts +0 -400
  540. package/src/devices-matter/BaseMatterAccessory.ts +0 -131
  541. package/src/devices-matter/ColorLightAccessory.ts +0 -110
  542. package/src/devices-matter/ColorTemperatureLightAccessory.ts +0 -92
  543. package/src/devices-matter/ContactSensorAccessory.ts +0 -41
  544. package/src/devices-matter/DimmableLightAccessory.ts +0 -192
  545. package/src/devices-matter/DoorLockAccessory.ts +0 -60
  546. package/src/devices-matter/ExtendedColorLightAccessory.ts +0 -123
  547. package/src/devices-matter/FanAccessory.ts +0 -95
  548. package/src/devices-matter/HumiditySensorAccessory.ts +0 -41
  549. package/src/devices-matter/LeakSensorAccessory.ts +0 -40
  550. package/src/devices-matter/LightSensorAccessory.ts +0 -41
  551. package/src/devices-matter/OccupancySensorAccessory.ts +0 -48
  552. package/src/devices-matter/OnOffLightAccessory.ts +0 -133
  553. package/src/devices-matter/OnOffOutletAccessory.ts +0 -46
  554. package/src/devices-matter/OnOffSwitchAccessory.ts +0 -51
  555. package/src/devices-matter/RoboticVacuumAccessory.ts +0 -407
  556. package/src/devices-matter/SmokeCOAlarmAccessory.ts +0 -59
  557. package/src/devices-matter/TemperatureSensorAccessory.ts +0 -43
  558. package/src/devices-matter/ThermostatAccessory.ts +0 -110
  559. package/src/devices-matter/VenetianBlindAccessory.ts +0 -115
  560. package/src/devices-matter/WindowBlindAccessory.ts +0 -92
  561. package/src/devices-matter/custom/PowerStripAccessory.ts +0 -309
  562. package/src/devices-matter/custom/index.ts +0 -8
  563. package/src/devices-matter/index.ts +0 -29
  564. package/src/index.test.ts +0 -24
  565. package/src/irdevice/airconditioner.ts +0 -533
  566. package/src/irdevice/airpurifier.ts +0 -252
  567. package/src/irdevice/camera.ts +0 -129
  568. package/src/irdevice/fan.ts +0 -226
  569. package/src/irdevice/irdevice.ts +0 -344
  570. package/src/irdevice/light.ts +0 -246
  571. package/src/irdevice/other.ts +0 -790
  572. package/src/irdevice/tv.ts +0 -378
  573. package/src/irdevice/vacuumcleaner.ts +0 -126
  574. package/src/irdevice/waterheater.ts +0 -127
  575. package/src/platform-hap.ts +0 -2997
  576. package/src/platform-matter.ts +0 -1110
  577. package/src/verifyconfig.test.ts +0 -197
@@ -0,0 +1,1581 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropNames = Object.getOwnPropertyNames;
3
+ var __esm = (fn, res) => function __init() {
4
+ return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
5
+ };
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+
11
+ // src/homebridge-ui/public/js/types.ts
12
+ var init_types = __esm({
13
+ "src/homebridge-ui/public/js/types.ts"() {
14
+ "use strict";
15
+ }
16
+ });
17
+
18
+ // src/homebridge-ui/public/js/logger.ts
19
+ var uiLog;
20
+ var init_logger = __esm({
21
+ "src/homebridge-ui/public/js/logger.ts"() {
22
+ "use strict";
23
+ uiLog = {
24
+ info: (message, ...parameters) => {
25
+ console.warn("[SwitchBot UI]", message, ...parameters);
26
+ },
27
+ warn: (message, ...parameters) => {
28
+ console.warn("[SwitchBot UI]", message, ...parameters);
29
+ },
30
+ error: (message, ...parameters) => {
31
+ console.error("[SwitchBot UI]", message, ...parameters);
32
+ }
33
+ };
34
+ }
35
+ });
36
+
37
+ // src/homebridge-ui/public/js/api.ts
38
+ var api_exports = {};
39
+ __export(api_exports, {
40
+ addDevice: () => addDevice,
41
+ addDevicesInBulk: () => addDevicesInBulk,
42
+ deleteAllDevices: () => deleteAllDevices,
43
+ deleteDevice: () => deleteDevice,
44
+ discoverDevices: () => discoverDevices,
45
+ fetchCredentialStatus: () => fetchCredentialStatus,
46
+ fetchDevices: () => fetchDevices,
47
+ saveCredentials: () => saveCredentials,
48
+ syncParentPluginConfigFromDisk: () => syncParentPluginConfigFromDisk,
49
+ updateDevice: () => updateDevice
50
+ });
51
+ function isSwitchBotPlatformConfig(block) {
52
+ const platformName = String(block?.platform || block?.name || "").toLowerCase();
53
+ return platformName === "switchbot" || platformName === "@switchbot/homebridge-switchbot" || platformName.includes("switchbot");
54
+ }
55
+ async function syncParentPluginConfigFromDisk(autoSave = false) {
56
+ try {
57
+ if (typeof homebridge.getPluginConfig !== "function" || typeof homebridge.updatePluginConfig !== "function") {
58
+ uiLog.warn("Parent config sync API not available");
59
+ return false;
60
+ }
61
+ const diskResp = await homebridge.request("/platform-config", {});
62
+ if (!diskResp || diskResp.success === false || !diskResp.data) {
63
+ uiLog.warn("Failed to fetch fresh platform config from disk");
64
+ return false;
65
+ }
66
+ const pluginConfigBlocks = await homebridge.getPluginConfig();
67
+ if (!Array.isArray(pluginConfigBlocks) || !pluginConfigBlocks.length) {
68
+ uiLog.warn("No plugin config blocks returned from Homebridge");
69
+ return false;
70
+ }
71
+ const index = pluginConfigBlocks.findIndex((block) => isSwitchBotPlatformConfig(block));
72
+ if (index < 0) {
73
+ uiLog.warn("SwitchBot platform block not found in Homebridge plugin config");
74
+ return false;
75
+ }
76
+ pluginConfigBlocks[index] = diskResp.data;
77
+ await homebridge.updatePluginConfig(pluginConfigBlocks);
78
+ if (autoSave && typeof homebridge.savePluginConfig === "function") {
79
+ uiLog.info("Auto-saving config to disk...");
80
+ await homebridge.savePluginConfig();
81
+ uiLog.info("Config saved successfully");
82
+ }
83
+ return true;
84
+ } catch (e) {
85
+ uiLog.warn("Failed to sync parent plugin config cache:", e);
86
+ return false;
87
+ }
88
+ }
89
+ async function fetchCredentialStatus() {
90
+ try {
91
+ const resp = await homebridge.request("/credentials", {});
92
+ uiLog.info("Load credentials response:", resp);
93
+ if (!resp || resp.success === false) {
94
+ uiLog.error("Failed to load credentials:", resp);
95
+ return null;
96
+ }
97
+ return resp.data || {};
98
+ } catch (e) {
99
+ uiLog.error("Error loading credentials:", e);
100
+ return null;
101
+ }
102
+ }
103
+ async function saveCredentials(token, secret) {
104
+ try {
105
+ uiLog.info("Saving credentials...");
106
+ const resp = await homebridge.request("/credentials", { token, secret });
107
+ uiLog.info("Save response:", resp);
108
+ if (!resp || resp.success === false) {
109
+ throw new Error(resp?.message || "Save failed");
110
+ }
111
+ return resp.data || resp;
112
+ } catch (e) {
113
+ throw e;
114
+ }
115
+ }
116
+ async function fetchDevices() {
117
+ try {
118
+ const resp = await homebridge.request("/devices", {});
119
+ if (!resp || resp.success === false) {
120
+ throw new Error(resp?.data?.message || "request failed");
121
+ }
122
+ return resp.data || [];
123
+ } catch (e) {
124
+ uiLog.error("Error fetching devices:", e);
125
+ return [];
126
+ }
127
+ }
128
+ async function discoverDevices() {
129
+ try {
130
+ const resp = await homebridge.request("/discover", {});
131
+ uiLog.info("Discover response:", resp);
132
+ if (!resp || resp.success === false) {
133
+ throw new Error(resp?.data?.message || "Discovery failed");
134
+ }
135
+ return resp.data || [];
136
+ } catch (e) {
137
+ throw e;
138
+ }
139
+ }
140
+ async function addDevice(deviceId, name, type) {
141
+ try {
142
+ uiLog.info("Adding device to config:", { deviceId, name, type });
143
+ const resp = await homebridge.request("/add-device", { deviceId, name, type });
144
+ uiLog.info("Add device response:", resp);
145
+ if (!resp || resp.success === false) {
146
+ throw new Error(resp?.data?.message || "Failed to add device");
147
+ }
148
+ return resp.data || resp;
149
+ } catch (e) {
150
+ throw e;
151
+ }
152
+ }
153
+ async function addDevicesInBulk(devices) {
154
+ try {
155
+ const resp = await homebridge.request("/add-devices", { devices });
156
+ uiLog.info("Bulk add response:", resp);
157
+ if (!resp || resp.success === false) {
158
+ throw new Error(resp?.data?.message || "Bulk add failed");
159
+ }
160
+ return resp.data || resp;
161
+ } catch (e) {
162
+ throw e;
163
+ }
164
+ }
165
+ async function updateDevice(deviceId, configDeviceName, configDeviceType) {
166
+ try {
167
+ const params = { deviceId };
168
+ if (configDeviceName) {
169
+ params.configDeviceName = configDeviceName;
170
+ }
171
+ if (configDeviceType) {
172
+ params.configDeviceType = configDeviceType;
173
+ }
174
+ uiLog.info("[Update Device] Sending update request with params:", params);
175
+ const resp = await homebridge.request("/update-device", params);
176
+ uiLog.info("[Update Device] Update response:", resp);
177
+ if (!resp || resp.success === false) {
178
+ throw new Error(resp?.data?.message || "Failed to update device");
179
+ }
180
+ return resp.data || resp;
181
+ } catch (e) {
182
+ throw e;
183
+ }
184
+ }
185
+ async function deleteDevice(deviceId) {
186
+ try {
187
+ uiLog.info("Sending delete request for deviceId:", deviceId);
188
+ const resp = await homebridge.request("/delete-device", { deviceId });
189
+ uiLog.info("Delete response:", resp);
190
+ if (!resp || resp.success === false) {
191
+ throw new Error(resp?.data?.message || "Failed to delete device");
192
+ }
193
+ return resp.data || resp;
194
+ } catch (e) {
195
+ throw e;
196
+ }
197
+ }
198
+ async function deleteAllDevices() {
199
+ try {
200
+ uiLog.info("Sending delete all devices request");
201
+ const resp = await homebridge.request("/delete-all-devices", {});
202
+ uiLog.info("Delete all response:", resp);
203
+ if (!resp || resp.success === false) {
204
+ throw new Error(resp?.data?.message || "Failed to delete all devices");
205
+ }
206
+ return resp.data || resp;
207
+ } catch (e) {
208
+ throw e;
209
+ }
210
+ }
211
+ var init_api = __esm({
212
+ "src/homebridge-ui/public/js/api.ts"() {
213
+ "use strict";
214
+ init_types();
215
+ init_logger();
216
+ }
217
+ });
218
+
219
+ // src/homebridge-ui/public/js/modal.ts
220
+ function callUiMethod(name) {
221
+ try {
222
+ const value = homebridge?.[name];
223
+ if (typeof value === "function") {
224
+ const fn = value;
225
+ fn();
226
+ }
227
+ } catch (e) {
228
+ uiLog.warn(`Homebridge UI method ${String(name)} failed:`, e);
229
+ }
230
+ }
231
+ function showBusyUi() {
232
+ callUiMethod("disableSaveButton");
233
+ callUiMethod("showSpinner");
234
+ }
235
+ function hideBusyUi() {
236
+ callUiMethod("hideSpinner");
237
+ callUiMethod("enableSaveButton");
238
+ }
239
+ var init_modal = __esm({
240
+ "src/homebridge-ui/public/js/modal.ts"() {
241
+ "use strict";
242
+ init_types();
243
+ init_logger();
244
+ }
245
+ });
246
+
247
+ // src/homebridge-ui/public/js/toast.ts
248
+ function showToast(method, message, title = "SwitchBot") {
249
+ try {
250
+ const toast = homebridge?.toast;
251
+ const fn = toast?.[method];
252
+ if (typeof fn === "function") {
253
+ fn(message, title);
254
+ return;
255
+ }
256
+ uiLog.info(`[Toast:${method}] ${title} - ${message}`);
257
+ } catch (e) {
258
+ uiLog.warn(`Toast ${method} failed:`, e);
259
+ }
260
+ }
261
+ function toastSuccess(message, title) {
262
+ showToast("success", message, title);
263
+ }
264
+ function toastError(message, title) {
265
+ showToast("error", message, title);
266
+ }
267
+ function toastWarning(message, title) {
268
+ showToast("warning", message, title);
269
+ }
270
+ function toastInfo(message, title) {
271
+ showToast("info", message, title);
272
+ }
273
+ var init_toast = __esm({
274
+ "src/homebridge-ui/public/js/toast.ts"() {
275
+ "use strict";
276
+ init_types();
277
+ init_logger();
278
+ }
279
+ });
280
+
281
+ // src/homebridge-ui/public/js/discovery.ts
282
+ var discovery_exports = {};
283
+ __export(discovery_exports, {
284
+ addDeviceToConfig: () => addDeviceToConfig,
285
+ discoverDevices: () => discoverDevices2
286
+ });
287
+ async function discoverDevices2() {
288
+ const btn = document.getElementById("discoverBtn");
289
+ const status = document.getElementById("discoverStatus");
290
+ const list = document.getElementById("discoveredList");
291
+ const autoAddAll = document.getElementById("autoAddAllCheckbox")?.checked;
292
+ if (!btn || !status || !list) {
293
+ return;
294
+ }
295
+ try {
296
+ showBusyUi();
297
+ btn.disabled = true;
298
+ btn.textContent = "\u{1F50D} Discovering...";
299
+ status.textContent = "Searching SwitchBot account...";
300
+ status.classList.remove("error");
301
+ const devicesRaw = await discoverDevices();
302
+ uiLog.info("Discover response:", devicesRaw);
303
+ const devices = devicesRaw.filter((d, index, arr) => !!d?.id && arr.findIndex((x) => x?.id === d.id) === index);
304
+ if (!devices.length) {
305
+ status.textContent = "No devices found in your SwitchBot account";
306
+ toastInfo("No devices found in your SwitchBot account");
307
+ list.style.display = "none";
308
+ return;
309
+ }
310
+ if (autoAddAll) {
311
+ status.textContent = `Auto-adding ${devices.length} device(s)...`;
312
+ try {
313
+ const bulkResult = await addDevicesInBulk(
314
+ devices.map((d) => ({
315
+ deviceId: d.id,
316
+ name: d.name,
317
+ type: d.type,
318
+ rssi: d.rssi,
319
+ address: d.address,
320
+ model: d.model
321
+ }))
322
+ );
323
+ uiLog.info("Bulk add response:", bulkResult);
324
+ if (!bulkResult || bulkResult.success === false) {
325
+ throw new Error(bulkResult?.data?.message || "Bulk add failed");
326
+ }
327
+ const addedCount = bulkResult?.addedCount ?? bulkResult?.data?.addedCount ?? 0;
328
+ const skippedCount = bulkResult?.skippedCount ?? bulkResult?.data?.skippedCount ?? 0;
329
+ status.textContent = `\u2713 Added ${addedCount} device(s)${skippedCount > 0 ? ` (${skippedCount} skipped)` : ""}`;
330
+ if (addedCount > 0) {
331
+ toastSuccess(`Added ${addedCount} device(s)${skippedCount > 0 ? ` (${skippedCount} skipped)` : ""}`);
332
+ } else if (skippedCount > 0) {
333
+ toastWarning(`No new devices were added (${skippedCount} skipped)`);
334
+ }
335
+ status.classList.remove("error");
336
+ list.style.display = "none";
337
+ if (devices.length > 0) {
338
+ const synced = await syncParentPluginConfigFromDisk(true);
339
+ status.textContent += synced ? " - Config saved automatically." : " - Warning: config may not persist until you close/reopen settings.";
340
+ if (synced) {
341
+ toastSuccess("Configuration synced and saved automatically");
342
+ } else {
343
+ toastWarning("Configuration sync failed; close and reopen settings before Save");
344
+ }
345
+ }
346
+ } catch (e) {
347
+ uiLog.error("Bulk add error:", e);
348
+ status.textContent = `\u2717 Error: ${e instanceof Error ? e.message : "Failed to add devices"}`;
349
+ status.classList.add("error");
350
+ toastError(e instanceof Error ? e.message : "Failed to add devices");
351
+ }
352
+ await loadConfiguredDevices();
353
+ return;
354
+ }
355
+ status.textContent = `Found ${devices.length} device(s)`;
356
+ const controlsDiv = document.createElement("div");
357
+ controlsDiv.style.cssText = "margin-bottom: 12px; display: flex; gap: 12px; flex-wrap: wrap; align-items: center;";
358
+ const preferences = getDiscoveryPreferences();
359
+ const filterLabel = document.createElement("label");
360
+ filterLabel.style.fontSize = "12px";
361
+ filterLabel.style.fontWeight = "500";
362
+ filterLabel.textContent = "Filter:";
363
+ const filterGroup = document.createElement("div");
364
+ filterGroup.style.display = "flex";
365
+ filterGroup.style.gap = "4px";
366
+ const filterOptions = [
367
+ { label: "All", value: "all" },
368
+ { label: "BLE", value: "ble" },
369
+ { label: "API", value: "api" },
370
+ { label: "Both", value: "both" },
371
+ { label: "IR", value: "ir" }
372
+ ];
373
+ for (const option of filterOptions) {
374
+ const btn2 = document.createElement("button");
375
+ btn2.textContent = option.label;
376
+ btn2.style.padding = "4px 8px";
377
+ btn2.style.fontSize = "11px";
378
+ btn2.style.borderRadius = "3px";
379
+ btn2.style.cursor = "pointer";
380
+ btn2.style.border = preferences.connectionType === option.value ? "2px solid #007AFF" : "1px solid #ccc";
381
+ btn2.style.backgroundColor = preferences.connectionType === option.value ? "#f0f7ff" : "#fff";
382
+ btn2.onclick = () => {
383
+ preferences.connectionType = option.value;
384
+ setDiscoveryPreferences(preferences);
385
+ updateDiscoveryView(devices, preferences);
386
+ for (const b of Array.from(filterGroup.querySelectorAll("button"))) {
387
+ ;
388
+ b.style.border = "1px solid #ccc";
389
+ b.style.backgroundColor = "#fff";
390
+ }
391
+ btn2.style.border = "2px solid #007AFF";
392
+ btn2.style.backgroundColor = "#f0f7ff";
393
+ };
394
+ filterGroup.appendChild(btn2);
395
+ }
396
+ const sortLabel = document.createElement("label");
397
+ sortLabel.style.fontSize = "12px";
398
+ sortLabel.style.fontWeight = "500";
399
+ sortLabel.style.marginLeft = "8px";
400
+ sortLabel.textContent = "Sort:";
401
+ const sortSelect = document.createElement("select");
402
+ sortSelect.style.fontSize = "11px";
403
+ sortSelect.style.padding = "4px 8px";
404
+ sortSelect.style.borderRadius = "3px";
405
+ sortSelect.value = preferences.sortBy;
406
+ const sortOptions = [
407
+ { label: "Name", value: "name" },
408
+ { label: "Signal Strength", value: "signal" },
409
+ { label: "Type", value: "type" },
410
+ { label: "Connection", value: "connection" }
411
+ ];
412
+ for (const opt of sortOptions) {
413
+ const option = document.createElement("option");
414
+ option.value = opt.value;
415
+ option.textContent = opt.label;
416
+ sortSelect.appendChild(option);
417
+ }
418
+ sortSelect.onchange = () => {
419
+ preferences.sortBy = sortSelect.value;
420
+ setDiscoveryPreferences(preferences);
421
+ updateDiscoveryView(devices, preferences);
422
+ };
423
+ const searchInput = document.createElement("input");
424
+ searchInput.type = "text";
425
+ searchInput.placeholder = "Search by name, ID, or type...";
426
+ searchInput.style.fontSize = "11px";
427
+ searchInput.style.padding = "4px 8px";
428
+ searchInput.style.borderRadius = "3px";
429
+ searchInput.style.border = "1px solid #ccc";
430
+ searchInput.style.flex = "1";
431
+ searchInput.style.minWidth = "200px";
432
+ searchInput.style.maxWidth = "300px";
433
+ searchInput.value = preferences.searchQuery;
434
+ let searchTimeout;
435
+ searchInput.oninput = () => {
436
+ clearTimeout(searchTimeout);
437
+ searchTimeout = setTimeout(() => {
438
+ preferences.searchQuery = searchInput.value;
439
+ setDiscoveryPreferences(preferences);
440
+ updateDiscoveryView(devices, preferences);
441
+ }, 300);
442
+ };
443
+ controlsDiv.appendChild(filterLabel);
444
+ controlsDiv.appendChild(filterGroup);
445
+ controlsDiv.appendChild(sortLabel);
446
+ controlsDiv.appendChild(sortSelect);
447
+ controlsDiv.appendChild(searchInput);
448
+ list.innerHTML = "";
449
+ list.appendChild(controlsDiv);
450
+ list.style.display = "block";
451
+ await updateDiscoveryView(devices, preferences);
452
+ } catch (e) {
453
+ uiLog.error("Discovery error:", e);
454
+ status.textContent = `Error: ${e instanceof Error ? e.message : "Discovery failed"}`;
455
+ status.classList.add("error");
456
+ toastError(e instanceof Error ? e.message : "Discovery failed");
457
+ list.style.display = "none";
458
+ } finally {
459
+ hideBusyUi();
460
+ btn.disabled = false;
461
+ btn.textContent = "\u{1F50D} Discover Devices";
462
+ }
463
+ }
464
+ async function updateDiscoveryView(allDevices, preferences) {
465
+ const filtered = filterDevices(allDevices, preferences.connectionType, preferences.searchQuery);
466
+ const sorted = sortDevices(filtered, preferences.sortBy);
467
+ const ul = await renderDiscoveredDevices(sorted);
468
+ document.getElementById("discoveredDevices")?.replaceWith(ul);
469
+ ul.id = "discoveredDevices";
470
+ const status = document.getElementById("discoverStatus");
471
+ if (status) {
472
+ const totalCount = allDevices.length;
473
+ const filteredCount = sorted.length;
474
+ status.textContent = filteredCount === totalCount ? `Found ${totalCount} device(s)` : `Showing ${filteredCount} of ${totalCount} device(s)`;
475
+ }
476
+ }
477
+ async function addDeviceToConfig(device) {
478
+ const { addDeviceToConfig: addDevice2 } = await Promise.resolve().then(() => (init_devices(), devices_exports));
479
+ await addDevice2(device);
480
+ }
481
+ var init_discovery = __esm({
482
+ "src/homebridge-ui/public/js/discovery.ts"() {
483
+ "use strict";
484
+ init_api();
485
+ init_devices();
486
+ init_logger();
487
+ init_modal();
488
+ init_render();
489
+ init_toast();
490
+ }
491
+ });
492
+
493
+ // src/device-types.ts
494
+ var DEVICE_TYPES;
495
+ var init_device_types = __esm({
496
+ "src/device-types.ts"() {
497
+ "use strict";
498
+ DEVICE_TYPES = {
499
+ "Window Coverings": ["Blind Tilt", "Curtain", "Curtain3", "Roller Shade"],
500
+ "Locks & Access": [
501
+ "Keypad",
502
+ "Keypad Touch",
503
+ "Keypad Vision",
504
+ "Keypad Vision Pro",
505
+ "Lock Vision Pro",
506
+ "Lock Lite",
507
+ "Smart Lock",
508
+ "Smart Lock Pro",
509
+ "Smart Lock Ultra",
510
+ "Video Doorbell"
511
+ ],
512
+ "Sensors": ["Contact Sensor", "Motion Sensor", "Presence Sensor", "Water Detector"],
513
+ "Lighting": [
514
+ "Candle Warmer Lamp",
515
+ "Ceiling Light",
516
+ "Ceiling Light Pro",
517
+ "Color Bulb",
518
+ "Floor Lamp",
519
+ "RGBIC Neon Rope Light",
520
+ "RGBIC Neon Wire Rope Light",
521
+ "RGBICWW Floor Lamp",
522
+ "RGBICWW Strip Light",
523
+ "Strip Light",
524
+ "Strip Light 3"
525
+ ],
526
+ "Climate Control": [
527
+ "Air Purifier PM2.5",
528
+ "Air Purifier Table PM2.5",
529
+ "Air Purifier VOC",
530
+ "Air Purifier Table VOC",
531
+ "Battery Circulator Fan",
532
+ "Circulator Fan",
533
+ "Humidifier",
534
+ "Humidifier2",
535
+ "Meter",
536
+ "MeterPlus",
537
+ "Meter Plus",
538
+ "MeterPro",
539
+ "Meter Pro",
540
+ "MeterPro(CO2)",
541
+ "Meter Pro (CO2)",
542
+ "Smart Radiator Thermostat",
543
+ "Standing Circulator Fan",
544
+ "WoIOSensor"
545
+ ],
546
+ "Plugs & Switches": [
547
+ "Garage Door Opener",
548
+ "Plug",
549
+ "Plug Mini (EU)",
550
+ "Plug Mini (JP)",
551
+ "Plug Mini (US)",
552
+ "Relay Switch 1",
553
+ "Relay Switch 1PM",
554
+ "Relay Switch 2PM"
555
+ ],
556
+ "Robot Vacuums": [
557
+ "K10+",
558
+ "K10+ Pro",
559
+ "Robot Vacuum Cleaner K10+ Pro Combo",
560
+ "Robot Vacuum Cleaner K11+",
561
+ "Robot Vacuum Cleaner K20 Plus Pro",
562
+ "Robot Vacuum Cleaner S1",
563
+ "Robot Vacuum Cleaner S1 Plus",
564
+ "Robot Vacuum Cleaner S10",
565
+ "Robot Vacuum Cleaner S20"
566
+ ],
567
+ "Hubs": ["AI Hub", "Hub", "Hub 2", "Hub 3", "Hub Mini", "Hub Plus"],
568
+ "Cameras": [
569
+ "Indoor Cam",
570
+ "Pan/Tilt Cam",
571
+ "Pan/Tilt Cam 2K",
572
+ "Pan/Tilt Cam Plus 2K",
573
+ "Pan/Tilt Cam Plus 3K"
574
+ ],
575
+ "IR Devices": [
576
+ "Air Conditioner",
577
+ "Air Purifier",
578
+ "Camera",
579
+ "DVD",
580
+ "Fan",
581
+ "Light",
582
+ "Others",
583
+ "Projector",
584
+ "Set Top Box",
585
+ "Speaker",
586
+ "Streamer",
587
+ "TV",
588
+ "Vacuum Cleaner",
589
+ "Water Heater"
590
+ ],
591
+ "Other Devices": ["AI Art Frame", "Bot", "Home Climate Panel", "Remote", "remote with screen"]
592
+ };
593
+ }
594
+ });
595
+
596
+ // src/homebridge-ui/public/js/constants.ts
597
+ var init_constants = __esm({
598
+ "src/homebridge-ui/public/js/constants.ts"() {
599
+ "use strict";
600
+ init_device_types();
601
+ }
602
+ });
603
+
604
+ // src/homebridge-ui/public/js/modals.ts
605
+ var modals_exports = {};
606
+ __export(modals_exports, {
607
+ editDevice: () => editDevice
608
+ });
609
+ async function editDevice(device) {
610
+ const div = document.createElement("div");
611
+ div.style.position = "fixed";
612
+ div.style.top = "0";
613
+ div.style.left = "0";
614
+ div.style.width = "100%";
615
+ div.style.height = "100%";
616
+ div.style.background = "rgba(0,0,0,0.7)";
617
+ div.style.display = "flex";
618
+ div.style.alignItems = "center";
619
+ div.style.justifyContent = "center";
620
+ div.style.zIndex = "9999";
621
+ const modal = document.createElement("div");
622
+ modal.style.background = getComputedStyle(document.body).backgroundColor;
623
+ modal.style.color = getComputedStyle(document.body).color;
624
+ modal.style.padding = "0";
625
+ modal.style.borderRadius = "10px";
626
+ modal.style.minWidth = "440px";
627
+ modal.style.maxWidth = "90vw";
628
+ modal.style.boxShadow = "0 8px 32px rgba(0,0,0,0.35)";
629
+ modal.style.overflow = "hidden";
630
+ modal.style.borderTop = "3px solid var(--switchbot-red, #ef4444)";
631
+ const title = document.createElement("h3");
632
+ title.textContent = "Edit Device";
633
+ title.style.marginTop = "0";
634
+ title.style.marginBottom = "16px";
635
+ title.style.padding = "20px 20px 0";
636
+ title.style.fontSize = "18px";
637
+ title.style.fontWeight = "600";
638
+ title.style.color = "var(--switchbot-red, #ef4444)";
639
+ title.style.letterSpacing = "-0.02em";
640
+ const contentDiv = document.createElement("div");
641
+ contentDiv.style.padding = "0 20px 20px";
642
+ const nameLabel = document.createElement("label");
643
+ nameLabel.textContent = "Device Name";
644
+ nameLabel.style.display = "block";
645
+ nameLabel.style.marginBottom = "6px";
646
+ nameLabel.style.fontWeight = "500";
647
+ nameLabel.style.fontSize = "12px";
648
+ nameLabel.style.color = "#6b7280";
649
+ const nameInput = document.createElement("input");
650
+ nameInput.type = "text";
651
+ nameInput.value = device.name || device.id;
652
+ nameInput.style.width = "100%";
653
+ nameInput.style.marginBottom = "12px";
654
+ nameInput.style.padding = "8px 10px";
655
+ nameInput.style.borderRadius = "6px";
656
+ nameInput.style.fontSize = "14px";
657
+ nameInput.style.boxSizing = "border-box";
658
+ nameInput.style.transition = "border-color 0.2s ease";
659
+ const apiTypeLabel = document.createElement("label");
660
+ apiTypeLabel.textContent = "Device Type (API - Read Only)";
661
+ apiTypeLabel.style.display = "block";
662
+ apiTypeLabel.style.marginBottom = "6px";
663
+ apiTypeLabel.style.fontWeight = "500";
664
+ apiTypeLabel.style.fontSize = "12px";
665
+ apiTypeLabel.style.color = "#6b7280";
666
+ const apiTypeInput = document.createElement("input");
667
+ apiTypeInput.type = "text";
668
+ apiTypeInput.value = device.deviceType || device.type || "Unknown";
669
+ apiTypeInput.readOnly = true;
670
+ apiTypeInput.style.width = "100%";
671
+ apiTypeInput.style.marginBottom = "12px";
672
+ apiTypeInput.style.padding = "8px 10px";
673
+ apiTypeInput.style.borderRadius = "6px";
674
+ apiTypeInput.style.fontSize = "13px";
675
+ apiTypeInput.style.opacity = "0.6";
676
+ apiTypeInput.style.cursor = "not-allowed";
677
+ apiTypeInput.style.boxSizing = "border-box";
678
+ apiTypeInput.style.backgroundColor = "#f9fafb";
679
+ const typeLabel = document.createElement("label");
680
+ typeLabel.textContent = "Config Device Type (Override)";
681
+ typeLabel.style.display = "block";
682
+ typeLabel.style.marginBottom = "6px";
683
+ typeLabel.style.fontWeight = "500";
684
+ typeLabel.style.fontSize = "12px";
685
+ typeLabel.style.color = "#6b7280";
686
+ const typeSelect = document.createElement("select");
687
+ typeSelect.style.width = "100%";
688
+ typeSelect.style.padding = "8px 10px";
689
+ typeSelect.style.marginBottom = "12px";
690
+ typeSelect.style.borderRadius = "6px";
691
+ typeSelect.style.fontSize = "14px";
692
+ typeSelect.style.background = getComputedStyle(nameInput).background;
693
+ typeSelect.style.color = getComputedStyle(nameInput).color;
694
+ typeSelect.style.border = getComputedStyle(nameInput).border;
695
+ typeSelect.style.boxSizing = "border-box";
696
+ typeSelect.style.cursor = "pointer";
697
+ typeSelect.style.transition = "border-color 0.2s ease";
698
+ Object.keys(DEVICE_TYPES).forEach((categoryName) => {
699
+ const optgroup = document.createElement("optgroup");
700
+ optgroup.label = categoryName;
701
+ DEVICE_TYPES[categoryName].forEach((deviceType) => {
702
+ const opt = document.createElement("option");
703
+ opt.value = deviceType;
704
+ opt.text = deviceType;
705
+ const currentType = device.configDeviceType || device.deviceType || device.type || "";
706
+ opt.selected = currentType === deviceType;
707
+ optgroup.appendChild(opt);
708
+ });
709
+ typeSelect.appendChild(optgroup);
710
+ });
711
+ const errorMessage = document.createElement("div");
712
+ errorMessage.style.color = "var(--switchbot-red, #ef4444)";
713
+ errorMessage.style.marginBottom = "12px";
714
+ errorMessage.style.fontSize = "12px";
715
+ errorMessage.style.display = "none";
716
+ errorMessage.style.padding = "8px 10px";
717
+ errorMessage.style.background = "var(--switchbot-red-light, #fee2e2)";
718
+ errorMessage.style.borderRadius = "6px";
719
+ errorMessage.style.fontWeight = "500";
720
+ const buttons = document.createElement("div");
721
+ buttons.style.display = "flex";
722
+ buttons.style.gap = "10px";
723
+ buttons.style.justifyContent = "flex-end";
724
+ buttons.style.marginTop = "18px";
725
+ buttons.style.paddingTop = "18px";
726
+ buttons.style.borderTop = "1px solid rgba(0, 0, 0, 0.08)";
727
+ const cancelBtn = document.createElement("button");
728
+ cancelBtn.textContent = "Cancel";
729
+ cancelBtn.className = "secondary";
730
+ cancelBtn.style.background = "#6b7280";
731
+ cancelBtn.style.padding = "8px 16px";
732
+ cancelBtn.style.fontSize = "13px";
733
+ cancelBtn.onclick = () => div.remove();
734
+ const saveBtn = document.createElement("button");
735
+ saveBtn.textContent = "Save";
736
+ saveBtn.style.background = "var(--switchbot-red, #ef4444)";
737
+ saveBtn.style.padding = "8px 20px";
738
+ saveBtn.style.fontSize = "13px";
739
+ saveBtn.onclick = async () => {
740
+ try {
741
+ const { updateDevice: updateDevice2, syncParentPluginConfigFromDisk: syncParentPluginConfigFromDisk2, fetchDevices: fetchDevices3 } = await Promise.resolve().then(() => (init_api(), api_exports));
742
+ const { renderDeviceList: renderDeviceList2 } = await Promise.resolve().then(() => (init_render(), render_exports));
743
+ const params = {
744
+ deviceId: device.id,
745
+ configDeviceName: nameInput.value || void 0,
746
+ configDeviceType: typeSelect.value
747
+ };
748
+ await updateDevice2(params.deviceId, params.configDeviceName, params.configDeviceType);
749
+ await syncParentPluginConfigFromDisk2();
750
+ uiLog.info("[Edit Device] Refreshing device list after update");
751
+ const list = await fetchDevices3();
752
+ renderDeviceList2(list);
753
+ div.remove();
754
+ } catch (e) {
755
+ uiLog.error("Update error:", e);
756
+ errorMessage.textContent = `Error: ${e instanceof Error ? e.message : "Failed to update device"}`;
757
+ errorMessage.style.display = "block";
758
+ }
759
+ };
760
+ buttons.appendChild(cancelBtn);
761
+ buttons.appendChild(saveBtn);
762
+ contentDiv.appendChild(nameLabel);
763
+ contentDiv.appendChild(nameInput);
764
+ contentDiv.appendChild(apiTypeLabel);
765
+ contentDiv.appendChild(apiTypeInput);
766
+ contentDiv.appendChild(typeLabel);
767
+ contentDiv.appendChild(typeSelect);
768
+ contentDiv.appendChild(errorMessage);
769
+ contentDiv.appendChild(buttons);
770
+ modal.appendChild(title);
771
+ modal.appendChild(contentDiv);
772
+ div.appendChild(modal);
773
+ document.body.appendChild(div);
774
+ nameInput.focus();
775
+ }
776
+ var init_modals = __esm({
777
+ "src/homebridge-ui/public/js/modals.ts"() {
778
+ "use strict";
779
+ init_constants();
780
+ init_logger();
781
+ }
782
+ });
783
+
784
+ // src/homebridge-ui/public/js/devices-delete.ts
785
+ var devices_delete_exports = {};
786
+ __export(devices_delete_exports, {
787
+ deleteAllDevicesFromConfig: () => deleteAllDevicesFromConfig,
788
+ deleteDeviceFromConfig: () => deleteDeviceFromConfig
789
+ });
790
+ async function confirmDeleteDialog(deviceNameOrId) {
791
+ return new Promise((resolve) => {
792
+ const overlay = document.createElement("div");
793
+ overlay.style.position = "fixed";
794
+ overlay.style.top = "0";
795
+ overlay.style.left = "0";
796
+ overlay.style.width = "100%";
797
+ overlay.style.height = "100%";
798
+ overlay.style.background = "rgba(0,0,0,0.6)";
799
+ overlay.style.display = "flex";
800
+ overlay.style.alignItems = "center";
801
+ overlay.style.justifyContent = "center";
802
+ overlay.style.zIndex = "10000";
803
+ const modal = document.createElement("div");
804
+ modal.style.background = getComputedStyle(document.body).backgroundColor;
805
+ modal.style.color = getComputedStyle(document.body).color;
806
+ modal.style.padding = "20px";
807
+ modal.style.borderRadius = "10px";
808
+ modal.style.minWidth = "340px";
809
+ modal.style.maxWidth = "90vw";
810
+ modal.style.boxShadow = "0 12px 40px rgba(0,0,0,0.35)";
811
+ const title = document.createElement("h3");
812
+ title.textContent = "Delete Device";
813
+ title.style.margin = "0 0 10px 0";
814
+ const message = document.createElement("p");
815
+ message.textContent = `Remove "${deviceNameOrId}" from configuration?`;
816
+ message.style.margin = "0 0 16px 0";
817
+ const actions = document.createElement("div");
818
+ actions.style.display = "flex";
819
+ actions.style.justifyContent = "flex-end";
820
+ actions.style.gap = "8px";
821
+ const cancelBtn = document.createElement("button");
822
+ cancelBtn.textContent = "Cancel";
823
+ cancelBtn.style.background = "#6b7280";
824
+ const deleteBtn = document.createElement("button");
825
+ deleteBtn.textContent = "Delete";
826
+ deleteBtn.style.background = "#ef4444";
827
+ const cleanup = (result) => {
828
+ overlay.remove();
829
+ resolve(result);
830
+ };
831
+ cancelBtn.onclick = () => cleanup(false);
832
+ deleteBtn.onclick = () => cleanup(true);
833
+ overlay.addEventListener("click", (event) => {
834
+ if (event.target === overlay) {
835
+ cleanup(false);
836
+ }
837
+ });
838
+ actions.appendChild(cancelBtn);
839
+ actions.appendChild(deleteBtn);
840
+ modal.appendChild(title);
841
+ modal.appendChild(message);
842
+ modal.appendChild(actions);
843
+ overlay.appendChild(modal);
844
+ document.body.appendChild(overlay);
845
+ });
846
+ }
847
+ async function deleteDeviceFromConfig(deviceId, deviceName) {
848
+ uiLog.info("Delete button clicked for device:", deviceId, deviceName);
849
+ const confirmed = await confirmDeleteDialog(deviceName || deviceId);
850
+ if (!confirmed) {
851
+ uiLog.info("Delete cancelled by user");
852
+ return;
853
+ }
854
+ try {
855
+ showBusyUi();
856
+ uiLog.info("Sending delete request for deviceId:", deviceId);
857
+ const resp = await deleteDevice(deviceId);
858
+ uiLog.info("Delete response:", resp);
859
+ if (!resp || resp.success === false) {
860
+ throw new Error(resp?.data?.message || "Failed to delete device");
861
+ }
862
+ uiLog.info("Syncing parent config from disk...");
863
+ const synced = await syncParentPluginConfigFromDisk(true);
864
+ if (!synced) {
865
+ toastWarning("Device deleted, but configuration sync failed");
866
+ }
867
+ uiLog.info("Refreshing device list...");
868
+ const list = await fetchDevices();
869
+ uiLog.info("Rendering devices:", list.length);
870
+ renderDeviceList(list);
871
+ uiLog.info("\u2713 Device deleted successfully");
872
+ toastSuccess(`Device "${deviceName || deviceId}" deleted successfully`);
873
+ } catch (e) {
874
+ uiLog.error("Delete error:", e);
875
+ toastError(e instanceof Error ? e.message : "Failed to delete device");
876
+ } finally {
877
+ hideBusyUi();
878
+ }
879
+ }
880
+ async function confirmDeleteAllDialog(deviceCount) {
881
+ return new Promise((resolve) => {
882
+ const overlay = document.createElement("div");
883
+ overlay.style.position = "fixed";
884
+ overlay.style.top = "0";
885
+ overlay.style.left = "0";
886
+ overlay.style.width = "100%";
887
+ overlay.style.height = "100%";
888
+ overlay.style.background = "rgba(0,0,0,0.7)";
889
+ overlay.style.display = "flex";
890
+ overlay.style.alignItems = "center";
891
+ overlay.style.justifyContent = "center";
892
+ overlay.style.zIndex = "10000";
893
+ const modal = document.createElement("div");
894
+ modal.style.background = getComputedStyle(document.body).backgroundColor;
895
+ modal.style.color = getComputedStyle(document.body).color;
896
+ modal.style.padding = "20px";
897
+ modal.style.borderRadius = "10px";
898
+ modal.style.minWidth = "380px";
899
+ modal.style.maxWidth = "90vw";
900
+ modal.style.boxShadow = "0 12px 40px rgba(0,0,0,0.35)";
901
+ modal.style.borderTop = "3px solid #ef4444";
902
+ const title = document.createElement("h3");
903
+ title.textContent = "\u26A0\uFE0F Remove All Devices";
904
+ title.style.margin = "0 0 12px 0";
905
+ title.style.color = "#ef4444";
906
+ const message = document.createElement("p");
907
+ message.innerHTML = `Are you sure you want to remove <strong>all ${deviceCount} device(s)</strong> from your configuration?<br><br>This action cannot be undone.`;
908
+ message.style.margin = "0 0 18px 0";
909
+ message.style.lineHeight = "1.5";
910
+ const actions = document.createElement("div");
911
+ actions.style.display = "flex";
912
+ actions.style.justifyContent = "flex-end";
913
+ actions.style.gap = "10px";
914
+ const cancelBtn = document.createElement("button");
915
+ cancelBtn.textContent = "Cancel";
916
+ cancelBtn.style.background = "#6b7280";
917
+ cancelBtn.style.padding = "8px 16px";
918
+ cancelBtn.style.fontSize = "13px";
919
+ cancelBtn.className = "secondary";
920
+ const deleteBtn = document.createElement("button");
921
+ deleteBtn.textContent = "Remove All";
922
+ deleteBtn.style.background = "#ef4444";
923
+ deleteBtn.style.padding = "8px 20px";
924
+ deleteBtn.style.fontSize = "13px";
925
+ const cleanup = (result) => {
926
+ overlay.remove();
927
+ resolve(result);
928
+ };
929
+ cancelBtn.onclick = () => cleanup(false);
930
+ deleteBtn.onclick = () => cleanup(true);
931
+ overlay.addEventListener("click", (event) => {
932
+ if (event.target === overlay) {
933
+ cleanup(false);
934
+ }
935
+ });
936
+ actions.appendChild(cancelBtn);
937
+ actions.appendChild(deleteBtn);
938
+ modal.appendChild(title);
939
+ modal.appendChild(message);
940
+ modal.appendChild(actions);
941
+ overlay.appendChild(modal);
942
+ document.body.appendChild(overlay);
943
+ });
944
+ }
945
+ async function deleteAllDevicesFromConfig() {
946
+ uiLog.info("Remove All Devices button clicked");
947
+ try {
948
+ const list = await fetchDevices();
949
+ if (!list || list.length === 0) {
950
+ toastWarning("No devices to remove");
951
+ return;
952
+ }
953
+ const confirmed = await confirmDeleteAllDialog(list.length);
954
+ if (!confirmed) {
955
+ uiLog.info("Remove all cancelled by user");
956
+ return;
957
+ }
958
+ showBusyUi();
959
+ uiLog.info("Sending delete all devices request");
960
+ const resp = await deleteAllDevices();
961
+ uiLog.info("Delete all response:", resp);
962
+ if (!resp || resp.success === false) {
963
+ throw new Error(resp?.data?.message || "Failed to delete all devices");
964
+ }
965
+ uiLog.info("Syncing parent config from disk...");
966
+ const synced = await syncParentPluginConfigFromDisk(true);
967
+ if (!synced) {
968
+ toastWarning("Devices deleted, but configuration sync failed");
969
+ }
970
+ uiLog.info("Refreshing device list...");
971
+ const updatedList = await fetchDevices();
972
+ uiLog.info("Rendering devices:", updatedList.length);
973
+ renderDeviceList(updatedList);
974
+ const deletedCount = resp?.deletedCount || list.length;
975
+ uiLog.info(`\u2713 Removed ${deletedCount} device(s) successfully`);
976
+ toastSuccess(`Removed ${deletedCount} device(s) successfully`);
977
+ } catch (e) {
978
+ uiLog.error("Delete all error:", e);
979
+ toastError(e instanceof Error ? e.message : "Failed to delete all devices");
980
+ } finally {
981
+ hideBusyUi();
982
+ }
983
+ }
984
+ var init_devices_delete = __esm({
985
+ "src/homebridge-ui/public/js/devices-delete.ts"() {
986
+ "use strict";
987
+ init_api();
988
+ init_logger();
989
+ init_modal();
990
+ init_render();
991
+ init_toast();
992
+ }
993
+ });
994
+
995
+ // src/homebridge-ui/public/js/render.ts
996
+ var render_exports = {};
997
+ __export(render_exports, {
998
+ filterDevices: () => filterDevices,
999
+ getDiscoveryPreferences: () => getDiscoveryPreferences,
1000
+ getRssiSignalQuality: () => getRssiSignalQuality,
1001
+ renderBadge: () => renderBadge,
1002
+ renderConnectionBadge: () => renderConnectionBadge,
1003
+ renderDeviceList: () => renderDeviceList,
1004
+ renderDiscoveredDevices: () => renderDiscoveredDevices,
1005
+ renderIRBadge: () => renderIRBadge,
1006
+ renderSignalBars: () => renderSignalBars,
1007
+ renderSignalQualityBadge: () => renderSignalQualityBadge,
1008
+ setDiscoveryPreferences: () => setDiscoveryPreferences,
1009
+ sortDevices: () => sortDevices
1010
+ });
1011
+ function getRssiSignalQuality(rssi) {
1012
+ if (!rssi || rssi === 0) {
1013
+ return {
1014
+ level: "unknown",
1015
+ color: "#999",
1016
+ bgColor: "#f5f5f5",
1017
+ description: "Signal strength unknown",
1018
+ bars: 0
1019
+ };
1020
+ }
1021
+ const dbm = Math.floor(rssi);
1022
+ if (dbm > -60) {
1023
+ return {
1024
+ level: "excellent",
1025
+ color: "#34a853",
1026
+ bgColor: "#e8f5e9",
1027
+ description: `Excellent (${dbm} dBm)`,
1028
+ bars: 4
1029
+ };
1030
+ } else if (dbm > -75) {
1031
+ return {
1032
+ level: "good",
1033
+ color: "#fbbc04",
1034
+ bgColor: "#fffde7",
1035
+ description: `Good (${dbm} dBm)`,
1036
+ bars: 3
1037
+ };
1038
+ } else if (dbm > -85) {
1039
+ return {
1040
+ level: "fair",
1041
+ color: "#ff9800",
1042
+ bgColor: "#fff3e0",
1043
+ description: `Fair (${dbm} dBm)`,
1044
+ bars: 2
1045
+ };
1046
+ } else {
1047
+ return {
1048
+ level: "poor",
1049
+ color: "#ea4335",
1050
+ bgColor: "#ffebee",
1051
+ description: `Poor (${dbm} dBm) - unreliable`,
1052
+ bars: 1
1053
+ };
1054
+ }
1055
+ }
1056
+ function renderSignalBars(rssi) {
1057
+ const quality = getRssiSignalQuality(rssi);
1058
+ const container = document.createElement("span");
1059
+ container.style.display = "inline-flex";
1060
+ container.style.gap = "2px";
1061
+ container.style.alignItems = "center";
1062
+ container.style.marginLeft = "8px";
1063
+ container.style.fontSize = "12px";
1064
+ for (let i = 1; i <= 4; i++) {
1065
+ const bar = document.createElement("span");
1066
+ bar.style.height = `${i * 3}px`;
1067
+ bar.style.width = "3px";
1068
+ bar.style.borderRadius = "1px";
1069
+ bar.style.border = `1px solid ${quality.color}`;
1070
+ if (i <= quality.bars) {
1071
+ bar.style.backgroundColor = quality.color;
1072
+ } else {
1073
+ bar.style.backgroundColor = "transparent";
1074
+ }
1075
+ container.appendChild(bar);
1076
+ }
1077
+ container.title = quality.description;
1078
+ return container;
1079
+ }
1080
+ function renderSignalQualityBadge(rssi) {
1081
+ const quality = getRssiSignalQuality(rssi);
1082
+ const badge = document.createElement("span");
1083
+ badge.textContent = quality.level.charAt(0).toUpperCase() + quality.level.slice(1);
1084
+ badge.style.cssText = `
1085
+ background: ${quality.color};
1086
+ color: white;
1087
+ padding: 2px 6px;
1088
+ border-radius: 3px;
1089
+ font-size: 10px;
1090
+ font-weight: 600;
1091
+ margin-left: 8px;
1092
+ `;
1093
+ badge.title = quality.description;
1094
+ return badge;
1095
+ }
1096
+ function renderBadge(text, style) {
1097
+ const badge = document.createElement("span");
1098
+ badge.textContent = text;
1099
+ badge.style.cssText = style;
1100
+ return badge;
1101
+ }
1102
+ function renderConnectionBadge(connectionType) {
1103
+ if (!connectionType) {
1104
+ return null;
1105
+ }
1106
+ const badge = renderBadge(connectionType, "");
1107
+ if (connectionType === "BLE") {
1108
+ badge.style.cssText = "background: #4285f4; color: white; padding: 2px 6px; border-radius: 3px; font-size: 10px; font-weight: 600; margin-left: 8px;";
1109
+ } else if (connectionType === "Both") {
1110
+ badge.style.cssText = "background: #34a853; color: white; padding: 2px 6px; border-radius: 3px; font-size: 10px; font-weight: 600; margin-left: 8px;";
1111
+ } else {
1112
+ badge.style.cssText = "background: #9e9e9e; color: white; padding: 2px 6px; border-radius: 3px; font-size: 10px; font-weight: 600; margin-left: 8px;";
1113
+ }
1114
+ return badge;
1115
+ }
1116
+ function renderIRBadge() {
1117
+ return renderBadge(
1118
+ "IR",
1119
+ "background: #ff6b35; color: white; padding: 2px 6px; border-radius: 3px; font-size: 10px; font-weight: 600; margin-left: 8px;"
1120
+ );
1121
+ }
1122
+ async function renderDiscoveredDevices(devices) {
1123
+ const ul = document.createElement("ul");
1124
+ ul.style.maxHeight = "400px";
1125
+ ul.style.overflowY = "auto";
1126
+ ul.style.marginTop = "12px";
1127
+ ul.style.padding = "0";
1128
+ ul.style.listStyle = "none";
1129
+ const { addDeviceToConfig: addDeviceToConfig3 } = await Promise.resolve().then(() => (init_discovery(), discovery_exports));
1130
+ for (const d of devices) {
1131
+ const li = document.createElement("li");
1132
+ li.className = "device-item";
1133
+ li.style.display = "flex";
1134
+ li.style.alignItems = "center";
1135
+ li.style.justifyContent = "space-between";
1136
+ li.style.padding = "10px 12px";
1137
+ li.style.marginBottom = "6px";
1138
+ li.style.borderRadius = "6px";
1139
+ li.style.transition = "all 0.2s ease";
1140
+ const info = document.createElement("div");
1141
+ info.style.flex = "1";
1142
+ const nameContainer = document.createElement("div");
1143
+ nameContainer.style.display = "flex";
1144
+ nameContainer.style.alignItems = "center";
1145
+ nameContainer.style.marginBottom = "4px";
1146
+ nameContainer.style.flexWrap = "wrap";
1147
+ nameContainer.style.gap = "6px";
1148
+ const name = document.createElement("div");
1149
+ name.style.fontWeight = "500";
1150
+ name.style.fontSize = "14px";
1151
+ name.textContent = d.name || d.id;
1152
+ nameContainer.appendChild(name);
1153
+ if (d.connectionType) {
1154
+ const badge = renderConnectionBadge(d.connectionType);
1155
+ if (badge) {
1156
+ nameContainer.appendChild(badge);
1157
+ }
1158
+ }
1159
+ if (d.isIR) {
1160
+ nameContainer.appendChild(renderIRBadge());
1161
+ }
1162
+ if (d.rssi !== void 0 && d.rssi !== null && d.rssi !== 0) {
1163
+ nameContainer.appendChild(renderSignalBars(d.rssi));
1164
+ nameContainer.appendChild(renderSignalQualityBadge(d.rssi));
1165
+ }
1166
+ const details = document.createElement("div");
1167
+ details.style.fontSize = "11px";
1168
+ details.style.opacity = "0.7";
1169
+ details.style.marginTop = "4px";
1170
+ details.style.fontFamily = "monospace";
1171
+ let detailsText = `ID: ${d.id} | Type: ${d.type} | Model: ${d.model || "N/A"}`;
1172
+ if (d.hubDeviceId) {
1173
+ detailsText += ` | Hub: ${d.hubDeviceId}`;
1174
+ }
1175
+ if (d.address) {
1176
+ detailsText += ` | MAC: ${d.address}`;
1177
+ }
1178
+ details.textContent = detailsText;
1179
+ info.appendChild(nameContainer);
1180
+ info.appendChild(details);
1181
+ const addBtn = document.createElement("button");
1182
+ addBtn.textContent = "+ Add";
1183
+ addBtn.style.marginLeft = "8px";
1184
+ addBtn.style.padding = "6px 14px";
1185
+ addBtn.style.fontSize = "12px";
1186
+ addBtn.style.whiteSpace = "nowrap";
1187
+ addBtn.style.flexShrink = "0";
1188
+ addBtn.onclick = async () => {
1189
+ await addDeviceToConfig3(d);
1190
+ };
1191
+ li.appendChild(info);
1192
+ li.appendChild(addBtn);
1193
+ ul.appendChild(li);
1194
+ }
1195
+ return ul;
1196
+ }
1197
+ function filterDevices(devices, connectionType = "all", searchQuery = "") {
1198
+ let filtered = [...devices];
1199
+ if (connectionType !== "all") {
1200
+ filtered = filtered.filter((d) => {
1201
+ if (connectionType === "ir") {
1202
+ return d.isIR === true;
1203
+ }
1204
+ if (connectionType === "ble") {
1205
+ return d.connectionType === "BLE" || d.connectionType?.includes("BLE");
1206
+ }
1207
+ if (connectionType === "api") {
1208
+ return d.connectionType === "OpenAPI" || d.connectionType === "API" || d.connectionType?.includes("API");
1209
+ }
1210
+ if (connectionType === "both") {
1211
+ return d.connectionType === "Both" || d.connectionType?.includes("Both");
1212
+ }
1213
+ return true;
1214
+ });
1215
+ }
1216
+ if (searchQuery.trim()) {
1217
+ const query = searchQuery.toLowerCase();
1218
+ filtered = filtered.filter((d) => {
1219
+ const name = (d.name || "").toLowerCase();
1220
+ const id = (d.id || "").toLowerCase();
1221
+ const type = (d.type || "").toLowerCase();
1222
+ const model = (d.model || "").toLowerCase();
1223
+ return name.includes(query) || id.includes(query) || type.includes(query) || model.includes(query);
1224
+ });
1225
+ }
1226
+ return filtered;
1227
+ }
1228
+ function sortDevices(devices, sortBy = "name") {
1229
+ const sorted = [...devices];
1230
+ switch (sortBy) {
1231
+ case "signal": {
1232
+ sorted.sort((a, b) => {
1233
+ const aRssi = a.rssi || 0;
1234
+ const bRssi = b.rssi || 0;
1235
+ return bRssi - aRssi;
1236
+ });
1237
+ break;
1238
+ }
1239
+ case "type": {
1240
+ sorted.sort((a, b) => {
1241
+ const aType = (a.type || "").localeCompare(b.type || "");
1242
+ return aType;
1243
+ });
1244
+ break;
1245
+ }
1246
+ case "connection": {
1247
+ const connectionOrder = {
1248
+ "Both": 0,
1249
+ "BLE": 1,
1250
+ "OpenAPI": 2,
1251
+ "API": 2,
1252
+ "Unknown": 3
1253
+ };
1254
+ sorted.sort((a, b) => {
1255
+ const aOrder = connectionOrder[a.connectionType || "Unknown"] ?? 3;
1256
+ const bOrder = connectionOrder[b.connectionType || "Unknown"] ?? 3;
1257
+ return aOrder - bOrder;
1258
+ });
1259
+ break;
1260
+ }
1261
+ case "name":
1262
+ default: {
1263
+ sorted.sort((a, b) => (a.name || a.id || "").localeCompare(b.name || b.id || ""));
1264
+ break;
1265
+ }
1266
+ }
1267
+ return sorted;
1268
+ }
1269
+ function getDiscoveryPreferences() {
1270
+ try {
1271
+ const stored = localStorage.getItem("discoveryPreferences");
1272
+ if (stored) {
1273
+ return JSON.parse(stored);
1274
+ }
1275
+ } catch (_e) {
1276
+ }
1277
+ return {
1278
+ connectionType: "all",
1279
+ sortBy: "name",
1280
+ searchQuery: ""
1281
+ };
1282
+ }
1283
+ function setDiscoveryPreferences(preferences) {
1284
+ try {
1285
+ localStorage.setItem("discoveryPreferences", JSON.stringify(preferences));
1286
+ } catch (_e) {
1287
+ }
1288
+ }
1289
+ function renderDeviceList(list) {
1290
+ const ul = document.getElementById("devices");
1291
+ const status = document.getElementById("status");
1292
+ const removeAllContainer = document.getElementById("removeAllContainer");
1293
+ if (!ul || !status) {
1294
+ return;
1295
+ }
1296
+ if (!list.length) {
1297
+ status.textContent = "No devices found in config.";
1298
+ ul.innerHTML = "";
1299
+ if (removeAllContainer) {
1300
+ removeAllContainer.style.display = "none";
1301
+ }
1302
+ return;
1303
+ }
1304
+ status.textContent = `Found ${list.length} device(s)`;
1305
+ ul.innerHTML = "";
1306
+ if (removeAllContainer) {
1307
+ removeAllContainer.style.display = "block";
1308
+ }
1309
+ for (const d of list) {
1310
+ const li = document.createElement("li");
1311
+ li.className = "device-item";
1312
+ const info = document.createElement("div");
1313
+ info.style.flex = "1";
1314
+ const nameContainer = document.createElement("div");
1315
+ nameContainer.style.display = "flex";
1316
+ nameContainer.style.alignItems = "center";
1317
+ nameContainer.style.flexWrap = "wrap";
1318
+ nameContainer.style.gap = "6px";
1319
+ const name = document.createElement("div");
1320
+ name.style.fontWeight = "500";
1321
+ name.textContent = d.name || d.id;
1322
+ const code = document.createElement("code");
1323
+ code.textContent = d.id;
1324
+ code.style.fontSize = "12px";
1325
+ code.style.opacity = "0.75";
1326
+ code.style.marginLeft = "8px";
1327
+ nameContainer.appendChild(name);
1328
+ nameContainer.appendChild(code);
1329
+ if (d.rssi !== void 0 && d.rssi !== null && d.rssi !== 0) {
1330
+ nameContainer.appendChild(renderSignalBars(d.rssi));
1331
+ nameContainer.appendChild(renderSignalQualityBadge(d.rssi));
1332
+ }
1333
+ const meta = document.createElement("div");
1334
+ meta.style.opacity = "0.75";
1335
+ meta.style.marginTop = "4px";
1336
+ meta.style.fontSize = "12px";
1337
+ const typeText = d.type ? `type: ${d.type}` : "";
1338
+ const connText = d.connectionPreference ? `conn: ${d.connectionPreference}` : "";
1339
+ const roomText = d.room ? `room: ${d.room}` : "";
1340
+ meta.textContent = [typeText, connText, roomText].filter(Boolean).join(" | ");
1341
+ info.appendChild(nameContainer);
1342
+ info.appendChild(meta);
1343
+ const buttons = document.createElement("div");
1344
+ buttons.style.display = "flex";
1345
+ buttons.style.gap = "8px";
1346
+ const editBtn = document.createElement("button");
1347
+ editBtn.textContent = "\u270F\uFE0F Edit";
1348
+ editBtn.style.padding = "6px 12px";
1349
+ editBtn.style.fontSize = "12px";
1350
+ editBtn.onclick = async () => {
1351
+ const { editDevice: editDevice2 } = await Promise.resolve().then(() => (init_modals(), modals_exports));
1352
+ await editDevice2(d);
1353
+ };
1354
+ const copyBtn = document.createElement("button");
1355
+ copyBtn.textContent = "Copy ID";
1356
+ copyBtn.style.padding = "6px 12px";
1357
+ copyBtn.style.fontSize = "12px";
1358
+ copyBtn.addEventListener("click", async () => {
1359
+ try {
1360
+ await navigator.clipboard.writeText(d.id);
1361
+ copyBtn.textContent = "Copied";
1362
+ copyBtn.classList.add("success");
1363
+ setTimeout(() => {
1364
+ copyBtn.textContent = "Copy ID";
1365
+ copyBtn.classList.remove("success");
1366
+ }, 1200);
1367
+ } catch (e) {
1368
+ alert("Failed to copy");
1369
+ }
1370
+ });
1371
+ const deleteBtn = document.createElement("button");
1372
+ deleteBtn.textContent = "\u{1F5D1}\uFE0F Delete";
1373
+ deleteBtn.style.padding = "6px 12px";
1374
+ deleteBtn.style.fontSize = "12px";
1375
+ deleteBtn.style.background = "#ef4444";
1376
+ deleteBtn.onclick = async () => {
1377
+ const { deleteDeviceFromConfig: deleteDeviceFromConfig2 } = await Promise.resolve().then(() => (init_devices_delete(), devices_delete_exports));
1378
+ await deleteDeviceFromConfig2(d.id, d.name || d.id);
1379
+ };
1380
+ buttons.appendChild(editBtn);
1381
+ buttons.appendChild(copyBtn);
1382
+ buttons.appendChild(deleteBtn);
1383
+ li.appendChild(info);
1384
+ li.appendChild(buttons);
1385
+ ul.appendChild(li);
1386
+ }
1387
+ }
1388
+ var init_render = __esm({
1389
+ "src/homebridge-ui/public/js/render.ts"() {
1390
+ "use strict";
1391
+ }
1392
+ });
1393
+
1394
+ // src/homebridge-ui/public/js/devices.ts
1395
+ var devices_exports = {};
1396
+ __export(devices_exports, {
1397
+ addDeviceToConfig: () => addDeviceToConfig2,
1398
+ initRemoveAllButton: () => initRemoveAllButton,
1399
+ loadConfiguredDevices: () => loadConfiguredDevices
1400
+ });
1401
+ async function addDeviceToConfig2(device, options = {}) {
1402
+ const { refresh = true, showStatus = true } = options;
1403
+ try {
1404
+ showBusyUi();
1405
+ uiLog.info("Adding device to config:", device);
1406
+ const resp = await addDevice(device.id, device.name, device.type);
1407
+ uiLog.info("Add device response:", resp);
1408
+ if (!resp || resp.success === false) {
1409
+ throw new Error(resp?.data?.message || "Failed to add device");
1410
+ }
1411
+ const alreadyExists = !!resp?.alreadyExists;
1412
+ const message = resp?.message || (alreadyExists ? `Device "${device.name}" already in config` : `Device "${device.name}" added successfully!`);
1413
+ if (alreadyExists) {
1414
+ toastInfo(message);
1415
+ } else {
1416
+ toastSuccess(message);
1417
+ }
1418
+ if (showStatus) {
1419
+ const status = document.getElementById("discoverStatus");
1420
+ if (status) {
1421
+ status.textContent = (alreadyExists ? "\u2022 " : "\u2713 ") + message;
1422
+ status.classList.remove("error");
1423
+ status.classList.add("success-msg");
1424
+ if (!alreadyExists) {
1425
+ const synced = await syncParentPluginConfigFromDisk(true);
1426
+ status.textContent += synced ? " - Config saved automatically." : " - Warning: config may not persist until you close/reopen settings.";
1427
+ if (synced) {
1428
+ toastSuccess("Configuration synced and saved automatically");
1429
+ } else {
1430
+ toastWarning("Configuration sync failed; close and reopen settings before Save");
1431
+ }
1432
+ }
1433
+ }
1434
+ }
1435
+ if (refresh) {
1436
+ await loadConfiguredDevices();
1437
+ }
1438
+ return { added: !alreadyExists };
1439
+ } catch (e) {
1440
+ uiLog.error("Add device error:", e);
1441
+ const status = document.getElementById("discoverStatus");
1442
+ if (status) {
1443
+ status.textContent = `\u2717 Error: ${e instanceof Error ? e.message : "Failed to add device"}`;
1444
+ status.classList.add("error");
1445
+ }
1446
+ toastError(e instanceof Error ? e.message : "Failed to add device");
1447
+ return { added: false };
1448
+ } finally {
1449
+ hideBusyUi();
1450
+ }
1451
+ }
1452
+ async function initRemoveAllButton() {
1453
+ const removeAllBtn = document.getElementById("removeAllBtn");
1454
+ if (!removeAllBtn) {
1455
+ return;
1456
+ }
1457
+ removeAllBtn.addEventListener("click", async () => {
1458
+ const { deleteAllDevicesFromConfig: deleteAllDevicesFromConfig2 } = await Promise.resolve().then(() => (init_devices_delete(), devices_delete_exports));
1459
+ await deleteAllDevicesFromConfig2();
1460
+ });
1461
+ }
1462
+ async function loadConfiguredDevices() {
1463
+ const list = await fetchDevices();
1464
+ renderDeviceList(list);
1465
+ }
1466
+ var init_devices = __esm({
1467
+ "src/homebridge-ui/public/js/devices.ts"() {
1468
+ "use strict";
1469
+ init_api();
1470
+ init_logger();
1471
+ init_modal();
1472
+ init_render();
1473
+ init_toast();
1474
+ }
1475
+ });
1476
+
1477
+ // src/homebridge-ui/public/js/credentials.ts
1478
+ init_api();
1479
+ init_logger();
1480
+ init_modal();
1481
+ init_toast();
1482
+ async function loadCredentialStatus() {
1483
+ try {
1484
+ const creds = await fetchCredentialStatus();
1485
+ if (!creds) {
1486
+ uiLog.error("Failed to load credentials");
1487
+ return;
1488
+ }
1489
+ const tokenStatus = document.getElementById("tokenStatus");
1490
+ const secretStatus = document.getElementById("secretStatus");
1491
+ if (!tokenStatus || !secretStatus) {
1492
+ return;
1493
+ }
1494
+ if (creds.hasToken) {
1495
+ tokenStatus.textContent = `\u2713 Configured (${creds.tokenLength} characters)`;
1496
+ tokenStatus.classList.add("ok");
1497
+ } else {
1498
+ tokenStatus.textContent = "Not configured";
1499
+ tokenStatus.classList.remove("ok");
1500
+ }
1501
+ if (creds.hasSecret) {
1502
+ secretStatus.textContent = `\u2713 Configured (${creds.secretLength} characters)`;
1503
+ secretStatus.classList.add("ok");
1504
+ } else {
1505
+ secretStatus.textContent = "Not configured";
1506
+ secretStatus.classList.remove("ok");
1507
+ }
1508
+ } catch (e) {
1509
+ uiLog.error("Error loading credentials:", e);
1510
+ }
1511
+ }
1512
+ async function saveCredentials2() {
1513
+ const token = document.getElementById("token")?.value;
1514
+ const secret = document.getElementById("secret")?.value;
1515
+ const saveStatus = document.getElementById("saveStatus");
1516
+ const saveBtn = document.getElementById("saveBtn");
1517
+ if (!saveStatus || !saveBtn) {
1518
+ return;
1519
+ }
1520
+ if (!token || !secret) {
1521
+ saveStatus.textContent = "Please enter both token and secret";
1522
+ saveStatus.classList.add("error");
1523
+ toastWarning("Please enter both token and secret");
1524
+ return;
1525
+ }
1526
+ try {
1527
+ showBusyUi();
1528
+ saveBtn.disabled = true;
1529
+ saveBtn.textContent = "Saving...";
1530
+ uiLog.info("Saving credentials...");
1531
+ const result = await saveCredentials(token, secret);
1532
+ uiLog.info("Save response:", result);
1533
+ const message = result?.message || "Credentials saved successfully";
1534
+ saveStatus.textContent = `\u2713 ${message}`;
1535
+ saveStatus.classList.remove("error");
1536
+ saveStatus.classList.add("success-msg");
1537
+ toastSuccess(message);
1538
+ const synced = await syncParentPluginConfigFromDisk(true);
1539
+ if (synced) {
1540
+ saveStatus.textContent += " - Config saved automatically.";
1541
+ toastSuccess("Configuration synced and saved automatically");
1542
+ } else {
1543
+ toastWarning("Credentials saved, but configuration sync failed");
1544
+ }
1545
+ ;
1546
+ document.getElementById("token").value = "";
1547
+ document.getElementById("secret").value = "";
1548
+ setTimeout(() => loadCredentialStatus(), 500);
1549
+ setTimeout(() => {
1550
+ saveStatus.textContent = "";
1551
+ saveStatus.classList.remove("success-msg");
1552
+ }, 3e3);
1553
+ } catch (e) {
1554
+ uiLog.error("Save error:", e);
1555
+ saveStatus.textContent = `Error: ${e instanceof Error ? e.message : "Failed to save"}`;
1556
+ saveStatus.classList.add("error");
1557
+ toastError(e instanceof Error ? e.message : "Failed to save credentials");
1558
+ } finally {
1559
+ hideBusyUi();
1560
+ saveBtn.disabled = false;
1561
+ saveBtn.textContent = "Save Credentials";
1562
+ }
1563
+ }
1564
+
1565
+ // src/homebridge-ui/public/js/app.ts
1566
+ init_devices();
1567
+ init_discovery();
1568
+ window.loadCredentialStatus = loadCredentialStatus;
1569
+ window.saveCredentials = saveCredentials2;
1570
+ window.discoverDevices = discoverDevices2;
1571
+ async function init() {
1572
+ await loadCredentialStatus();
1573
+ const list = await loadConfiguredDevices();
1574
+ await initRemoveAllButton();
1575
+ }
1576
+ if (document.readyState === "loading") {
1577
+ document.addEventListener("DOMContentLoaded", init);
1578
+ } else {
1579
+ init();
1580
+ }
1581
+ //# sourceMappingURL=app.js.map