@switchbot/homebridge-switchbot 5.0.0-beta.8 → 5.0.0-beta.80

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 (447) hide show
  1. package/.github/ISSUE_TEMPLATE/e2e-verification.md +36 -0
  2. package/.github/workflows/ci.yml +61 -0
  3. package/.github/workflows/manual-e2e.yml +103 -0
  4. package/CHANGELOG.md +35 -0
  5. package/E2E-VERIFICATION.md +121 -0
  6. package/MIGRATION.md +44 -0
  7. package/README.md +56 -3
  8. package/config.schema.json +83 -14807
  9. package/dist/deviceFactory.d.ts +13 -0
  10. package/dist/deviceFactory.d.ts.map +1 -0
  11. package/dist/deviceFactory.js +81 -0
  12. package/dist/deviceFactory.js.map +1 -0
  13. package/dist/devices/deviceBase.d.ts +50 -0
  14. package/dist/devices/deviceBase.d.ts.map +1 -0
  15. package/dist/devices/deviceBase.js +119 -0
  16. package/dist/devices/deviceBase.js.map +1 -0
  17. package/dist/devices/genericDevice.d.ts +283 -0
  18. package/dist/devices/genericDevice.d.ts.map +1 -0
  19. package/dist/devices/genericDevice.js +1035 -0
  20. package/dist/devices/genericDevice.js.map +1 -0
  21. package/dist/homebridge-ui/public/index.html +425 -243
  22. package/dist/homebridge-ui/server.d.ts +3 -1
  23. package/dist/homebridge-ui/server.d.ts.map +1 -1
  24. package/dist/homebridge-ui/server.js +276 -35
  25. package/dist/homebridge-ui/server.js.map +1 -1
  26. package/dist/index.d.ts.map +1 -1
  27. package/dist/index.js +4 -11
  28. package/dist/index.js.map +1 -1
  29. package/dist/platform.d.ts +27 -0
  30. package/dist/platform.d.ts.map +1 -0
  31. package/dist/platform.js +404 -0
  32. package/dist/platform.js.map +1 -0
  33. package/dist/settings.d.ts +10 -249
  34. package/dist/settings.d.ts.map +1 -1
  35. package/dist/settings.js +5 -30
  36. package/dist/settings.js.map +1 -1
  37. package/dist/switchbotClient.d.ts +32 -0
  38. package/dist/switchbotClient.d.ts.map +1 -0
  39. package/dist/switchbotClient.js +194 -0
  40. package/dist/switchbotClient.js.map +1 -0
  41. package/dist/utils.d.ts +39 -50
  42. package/dist/utils.d.ts.map +1 -1
  43. package/dist/utils.js +39 -688
  44. package/dist/utils.js.map +1 -1
  45. package/docs/assets/highlight.css +14 -0
  46. package/docs/assets/icons.js +1 -1
  47. package/docs/assets/icons.svg +1 -1
  48. package/docs/assets/main.js +2 -2
  49. package/docs/assets/style.css +3 -3
  50. package/docs/index.html +77 -13
  51. package/docs/variables/default.html +1 -1
  52. package/eslint.config.js +2 -8
  53. package/package.json +21 -28
  54. package/scripts/e2e/README.md +25 -0
  55. package/scripts/e2e/curtain-e2e.sh +70 -0
  56. package/scripts/e2e/fan-e2e.sh +75 -0
  57. package/scripts/e2e/light-advanced-e2e.sh +97 -0
  58. package/scripts/e2e/light-e2e.sh +75 -0
  59. package/scripts/e2e/list-accessories.sh +19 -0
  60. package/scripts/e2e/lock-e2e.sh +65 -0
  61. package/scripts/generate-matter-maps.js +60 -0
  62. package/scripts/run-e2e-local.sh +14 -0
  63. package/src/deviceFactory.ts +122 -0
  64. package/src/devices/deviceBase.ts +141 -0
  65. package/src/devices/genericDevice.ts +965 -0
  66. package/src/homebridge-ui/public/index.html +425 -243
  67. package/src/homebridge-ui/server.ts +329 -40
  68. package/src/index.ts +4 -12
  69. package/src/platform.ts +395 -0
  70. package/src/settings.ts +12 -277
  71. package/src/switchbotClient.ts +203 -0
  72. package/src/utils.ts +45 -713
  73. package/test/accessory-restore.spec.ts +73 -0
  74. package/test/device-mapping.spec.ts +37 -0
  75. package/test/deviceFactory.spec.ts +18 -0
  76. package/test/e2e/run-e2e.spec.ts +50 -0
  77. package/test/fan-swing.spec.ts +29 -0
  78. package/test/helpers/matter-harness.ts +53 -0
  79. package/test/lock-users.spec.ts +44 -0
  80. package/test/matter-childbridge.spec.ts +55 -0
  81. package/test/matter-descriptors.spec.ts +97 -0
  82. package/test/matter-device-state.spec.ts +101 -0
  83. package/test/matter-integration.spec.ts +70 -0
  84. package/test/platform.integration.spec.ts +55 -0
  85. package/test/switchbot-client-debounce.spec.ts +131 -0
  86. package/test/switchbot-client-openapi.spec.ts +56 -0
  87. package/test/switchbotClient.spec.ts +10 -0
  88. package/test/utils.spec.ts +20 -0
  89. package/vitest.config.ts +7 -0
  90. package/coverage/base.css +0 -224
  91. package/coverage/block-navigation.js +0 -87
  92. package/coverage/clover.xml +0 -15847
  93. package/coverage/coverage-final.json +0 -42
  94. package/coverage/docs/assets/dmt/dmt-component-data.js.html +0 -85
  95. package/coverage/docs/assets/dmt/dmt-components.js.html +0 -286
  96. package/coverage/docs/assets/dmt/index.html +0 -131
  97. package/coverage/docs/assets/hierarchy.js.html +0 -85
  98. package/coverage/docs/assets/icons.js.html +0 -136
  99. package/coverage/docs/assets/index.html +0 -146
  100. package/coverage/docs/assets/main.js.html +0 -265
  101. package/coverage/favicon.png +0 -0
  102. package/coverage/index.html +0 -191
  103. package/coverage/prettify.css +0 -1
  104. package/coverage/prettify.js +0 -2
  105. package/coverage/sort-arrow-sprite.png +0 -0
  106. package/coverage/sorter.js +0 -196
  107. package/coverage/src/device/blindtilt.ts.html +0 -3238
  108. package/coverage/src/device/bot.ts.html +0 -2803
  109. package/coverage/src/device/ceilinglight.ts.html +0 -2338
  110. package/coverage/src/device/colorbulb.ts.html +0 -2824
  111. package/coverage/src/device/contact.ts.html +0 -1465
  112. package/coverage/src/device/curtain.ts.html +0 -2869
  113. package/coverage/src/device/device.ts.html +0 -2500
  114. package/coverage/src/device/fan.ts.html +0 -2242
  115. package/coverage/src/device/hub.ts.html +0 -1408
  116. package/coverage/src/device/humidifier.ts.html +0 -2116
  117. package/coverage/src/device/index.html +0 -416
  118. package/coverage/src/device/iosensor.ts.html +0 -1375
  119. package/coverage/src/device/lightstrip.ts.html +0 -2617
  120. package/coverage/src/device/lock.ts.html +0 -1963
  121. package/coverage/src/device/meter.ts.html +0 -1372
  122. package/coverage/src/device/meterplus.ts.html +0 -1384
  123. package/coverage/src/device/meterpro.ts.html +0 -1618
  124. package/coverage/src/device/motion.ts.html +0 -1264
  125. package/coverage/src/device/plug.ts.html +0 -1372
  126. package/coverage/src/device/relayswitch.ts.html +0 -2284
  127. package/coverage/src/device/robotvacuumcleaner.ts.html +0 -1810
  128. package/coverage/src/device/waterdetector.ts.html +0 -1294
  129. package/coverage/src/homebridge-ui/index.html +0 -116
  130. package/coverage/src/homebridge-ui/server.ts.html +0 -229
  131. package/coverage/src/index.html +0 -161
  132. package/coverage/src/index.ts.html +0 -124
  133. package/coverage/src/irdevice/airconditioner.ts.html +0 -1687
  134. package/coverage/src/irdevice/airpurifier.ts.html +0 -844
  135. package/coverage/src/irdevice/camera.ts.html +0 -475
  136. package/coverage/src/irdevice/fan.ts.html +0 -766
  137. package/coverage/src/irdevice/index.html +0 -251
  138. package/coverage/src/irdevice/irdevice.ts.html +0 -1117
  139. package/coverage/src/irdevice/light.ts.html +0 -826
  140. package/coverage/src/irdevice/other.ts.html +0 -2458
  141. package/coverage/src/irdevice/tv.ts.html +0 -1222
  142. package/coverage/src/irdevice/vacuumcleaner.ts.html +0 -466
  143. package/coverage/src/irdevice/waterheater.ts.html +0 -469
  144. package/coverage/src/platform.ts.html +0 -8776
  145. package/coverage/src/settings.ts.html +0 -934
  146. package/coverage/src/utils.ts.html +0 -2092
  147. package/dist/devices-hap/airpurifier.d.ts +0 -54
  148. package/dist/devices-hap/airpurifier.d.ts.map +0 -1
  149. package/dist/devices-hap/airpurifier.js +0 -527
  150. package/dist/devices-hap/airpurifier.js.map +0 -1
  151. package/dist/devices-hap/blindtilt.d.ts +0 -90
  152. package/dist/devices-hap/blindtilt.d.ts.map +0 -1
  153. package/dist/devices-hap/blindtilt.js +0 -974
  154. package/dist/devices-hap/blindtilt.js.map +0 -1
  155. package/dist/devices-hap/bot.d.ts +0 -102
  156. package/dist/devices-hap/bot.d.ts.map +0 -1
  157. package/dist/devices-hap/bot.js +0 -811
  158. package/dist/devices-hap/bot.js.map +0 -1
  159. package/dist/devices-hap/ceilinglight.d.ts +0 -85
  160. package/dist/devices-hap/ceilinglight.d.ts.map +0 -1
  161. package/dist/devices-hap/ceilinglight.js +0 -701
  162. package/dist/devices-hap/ceilinglight.js.map +0 -1
  163. package/dist/devices-hap/colorbulb.d.ts +0 -88
  164. package/dist/devices-hap/colorbulb.d.ts.map +0 -1
  165. package/dist/devices-hap/colorbulb.js +0 -881
  166. package/dist/devices-hap/colorbulb.js.map +0 -1
  167. package/dist/devices-hap/contact.d.ts +0 -44
  168. package/dist/devices-hap/contact.d.ts.map +0 -1
  169. package/dist/devices-hap/contact.js +0 -409
  170. package/dist/devices-hap/contact.js.map +0 -1
  171. package/dist/devices-hap/curtain.d.ts +0 -73
  172. package/dist/devices-hap/curtain.d.ts.map +0 -1
  173. package/dist/devices-hap/curtain.js +0 -869
  174. package/dist/devices-hap/curtain.js.map +0 -1
  175. package/dist/devices-hap/device.d.ts +0 -98
  176. package/dist/devices-hap/device.d.ts.map +0 -1
  177. package/dist/devices-hap/device.js +0 -749
  178. package/dist/devices-hap/device.js.map +0 -1
  179. package/dist/devices-hap/fan.d.ts +0 -69
  180. package/dist/devices-hap/fan.d.ts.map +0 -1
  181. package/dist/devices-hap/fan.js +0 -649
  182. package/dist/devices-hap/fan.js.map +0 -1
  183. package/dist/devices-hap/hub.d.ts +0 -37
  184. package/dist/devices-hap/hub.d.ts.map +0 -1
  185. package/dist/devices-hap/hub.js +0 -392
  186. package/dist/devices-hap/hub.js.map +0 -1
  187. package/dist/devices-hap/humidifier.d.ts +0 -68
  188. package/dist/devices-hap/humidifier.d.ts.map +0 -1
  189. package/dist/devices-hap/humidifier.js +0 -628
  190. package/dist/devices-hap/humidifier.js.map +0 -1
  191. package/dist/devices-hap/iosensor.d.ts +0 -42
  192. package/dist/devices-hap/iosensor.d.ts.map +0 -1
  193. package/dist/devices-hap/iosensor.js +0 -382
  194. package/dist/devices-hap/iosensor.js.map +0 -1
  195. package/dist/devices-hap/lightstrip.d.ts +0 -79
  196. package/dist/devices-hap/lightstrip.d.ts.map +0 -1
  197. package/dist/devices-hap/lightstrip.js +0 -797
  198. package/dist/devices-hap/lightstrip.js.map +0 -1
  199. package/dist/devices-hap/lock.d.ts +0 -53
  200. package/dist/devices-hap/lock.d.ts.map +0 -1
  201. package/dist/devices-hap/lock.js +0 -561
  202. package/dist/devices-hap/lock.js.map +0 -1
  203. package/dist/devices-hap/meter.d.ts +0 -37
  204. package/dist/devices-hap/meter.d.ts.map +0 -1
  205. package/dist/devices-hap/meter.js +0 -379
  206. package/dist/devices-hap/meter.js.map +0 -1
  207. package/dist/devices-hap/meterplus.d.ts +0 -42
  208. package/dist/devices-hap/meterplus.d.ts.map +0 -1
  209. package/dist/devices-hap/meterplus.js +0 -384
  210. package/dist/devices-hap/meterplus.js.map +0 -1
  211. package/dist/devices-hap/meterpro.d.ts +0 -43
  212. package/dist/devices-hap/meterpro.d.ts.map +0 -1
  213. package/dist/devices-hap/meterpro.js +0 -468
  214. package/dist/devices-hap/meterpro.js.map +0 -1
  215. package/dist/devices-hap/motion.d.ts +0 -42
  216. package/dist/devices-hap/motion.d.ts.map +0 -1
  217. package/dist/devices-hap/motion.js +0 -345
  218. package/dist/devices-hap/motion.js.map +0 -1
  219. package/dist/devices-hap/plug.d.ts +0 -49
  220. package/dist/devices-hap/plug.d.ts.map +0 -1
  221. package/dist/devices-hap/plug.js +0 -395
  222. package/dist/devices-hap/plug.js.map +0 -1
  223. package/dist/devices-hap/relayswitch.d.ts +0 -96
  224. package/dist/devices-hap/relayswitch.d.ts.map +0 -1
  225. package/dist/devices-hap/relayswitch.js +0 -642
  226. package/dist/devices-hap/relayswitch.js.map +0 -1
  227. package/dist/devices-hap/robotvacuumcleaner.d.ts +0 -54
  228. package/dist/devices-hap/robotvacuumcleaner.d.ts.map +0 -1
  229. package/dist/devices-hap/robotvacuumcleaner.js +0 -523
  230. package/dist/devices-hap/robotvacuumcleaner.js.map +0 -1
  231. package/dist/devices-hap/waterdetector.d.ts +0 -41
  232. package/dist/devices-hap/waterdetector.d.ts.map +0 -1
  233. package/dist/devices-hap/waterdetector.js +0 -356
  234. package/dist/devices-hap/waterdetector.js.map +0 -1
  235. package/dist/devices-matter/BaseMatterAccessory.d.ts +0 -63
  236. package/dist/devices-matter/BaseMatterAccessory.d.ts.map +0 -1
  237. package/dist/devices-matter/BaseMatterAccessory.js +0 -100
  238. package/dist/devices-matter/BaseMatterAccessory.js.map +0 -1
  239. package/dist/devices-matter/ColorLightAccessory.d.ts +0 -20
  240. package/dist/devices-matter/ColorLightAccessory.d.ts.map +0 -1
  241. package/dist/devices-matter/ColorLightAccessory.js +0 -95
  242. package/dist/devices-matter/ColorLightAccessory.js.map +0 -1
  243. package/dist/devices-matter/ColorTemperatureLightAccessory.d.ts +0 -18
  244. package/dist/devices-matter/ColorTemperatureLightAccessory.d.ts.map +0 -1
  245. package/dist/devices-matter/ColorTemperatureLightAccessory.js +0 -78
  246. package/dist/devices-matter/ColorTemperatureLightAccessory.js.map +0 -1
  247. package/dist/devices-matter/ContactSensorAccessory.d.ts +0 -12
  248. package/dist/devices-matter/ContactSensorAccessory.d.ts.map +0 -1
  249. package/dist/devices-matter/ContactSensorAccessory.js +0 -34
  250. package/dist/devices-matter/ContactSensorAccessory.js.map +0 -1
  251. package/dist/devices-matter/DimmableLightAccessory.d.ts +0 -58
  252. package/dist/devices-matter/DimmableLightAccessory.d.ts.map +0 -1
  253. package/dist/devices-matter/DimmableLightAccessory.js +0 -167
  254. package/dist/devices-matter/DimmableLightAccessory.js.map +0 -1
  255. package/dist/devices-matter/DoorLockAccessory.d.ts +0 -14
  256. package/dist/devices-matter/DoorLockAccessory.d.ts.map +0 -1
  257. package/dist/devices-matter/DoorLockAccessory.js +0 -50
  258. package/dist/devices-matter/DoorLockAccessory.js.map +0 -1
  259. package/dist/devices-matter/ExtendedColorLightAccessory.d.ts +0 -21
  260. package/dist/devices-matter/ExtendedColorLightAccessory.d.ts.map +0 -1
  261. package/dist/devices-matter/ExtendedColorLightAccessory.js +0 -107
  262. package/dist/devices-matter/ExtendedColorLightAccessory.js.map +0 -1
  263. package/dist/devices-matter/FanAccessory.d.ts +0 -16
  264. package/dist/devices-matter/FanAccessory.d.ts.map +0 -1
  265. package/dist/devices-matter/FanAccessory.js +0 -81
  266. package/dist/devices-matter/FanAccessory.js.map +0 -1
  267. package/dist/devices-matter/HumiditySensorAccessory.d.ts +0 -12
  268. package/dist/devices-matter/HumiditySensorAccessory.d.ts.map +0 -1
  269. package/dist/devices-matter/HumiditySensorAccessory.js +0 -34
  270. package/dist/devices-matter/HumiditySensorAccessory.js.map +0 -1
  271. package/dist/devices-matter/LeakSensorAccessory.d.ts +0 -12
  272. package/dist/devices-matter/LeakSensorAccessory.d.ts.map +0 -1
  273. package/dist/devices-matter/LeakSensorAccessory.js +0 -33
  274. package/dist/devices-matter/LeakSensorAccessory.js.map +0 -1
  275. package/dist/devices-matter/LightSensorAccessory.d.ts +0 -12
  276. package/dist/devices-matter/LightSensorAccessory.d.ts.map +0 -1
  277. package/dist/devices-matter/LightSensorAccessory.js +0 -34
  278. package/dist/devices-matter/LightSensorAccessory.js.map +0 -1
  279. package/dist/devices-matter/OccupancySensorAccessory.d.ts +0 -12
  280. package/dist/devices-matter/OccupancySensorAccessory.d.ts.map +0 -1
  281. package/dist/devices-matter/OccupancySensorAccessory.js +0 -39
  282. package/dist/devices-matter/OccupancySensorAccessory.js.map +0 -1
  283. package/dist/devices-matter/OnOffLightAccessory.d.ts +0 -38
  284. package/dist/devices-matter/OnOffLightAccessory.d.ts.map +0 -1
  285. package/dist/devices-matter/OnOffLightAccessory.js +0 -118
  286. package/dist/devices-matter/OnOffLightAccessory.js.map +0 -1
  287. package/dist/devices-matter/OnOffOutletAccessory.d.ts +0 -12
  288. package/dist/devices-matter/OnOffOutletAccessory.d.ts.map +0 -1
  289. package/dist/devices-matter/OnOffOutletAccessory.js +0 -40
  290. package/dist/devices-matter/OnOffOutletAccessory.js.map +0 -1
  291. package/dist/devices-matter/OnOffSwitchAccessory.d.ts +0 -14
  292. package/dist/devices-matter/OnOffSwitchAccessory.d.ts.map +0 -1
  293. package/dist/devices-matter/OnOffSwitchAccessory.js +0 -42
  294. package/dist/devices-matter/OnOffSwitchAccessory.js.map +0 -1
  295. package/dist/devices-matter/RoboticVacuumAccessory.d.ts +0 -68
  296. package/dist/devices-matter/RoboticVacuumAccessory.d.ts.map +0 -1
  297. package/dist/devices-matter/RoboticVacuumAccessory.js +0 -334
  298. package/dist/devices-matter/RoboticVacuumAccessory.js.map +0 -1
  299. package/dist/devices-matter/SmokeCOAlarmAccessory.d.ts +0 -11
  300. package/dist/devices-matter/SmokeCOAlarmAccessory.d.ts.map +0 -1
  301. package/dist/devices-matter/SmokeCOAlarmAccessory.js +0 -49
  302. package/dist/devices-matter/SmokeCOAlarmAccessory.js.map +0 -1
  303. package/dist/devices-matter/TemperatureSensorAccessory.d.ts +0 -12
  304. package/dist/devices-matter/TemperatureSensorAccessory.d.ts.map +0 -1
  305. package/dist/devices-matter/TemperatureSensorAccessory.js +0 -36
  306. package/dist/devices-matter/TemperatureSensorAccessory.js.map +0 -1
  307. package/dist/devices-matter/ThermostatAccessory.d.ts +0 -19
  308. package/dist/devices-matter/ThermostatAccessory.d.ts.map +0 -1
  309. package/dist/devices-matter/ThermostatAccessory.js +0 -95
  310. package/dist/devices-matter/ThermostatAccessory.js.map +0 -1
  311. package/dist/devices-matter/VenetianBlindAccessory.d.ts +0 -19
  312. package/dist/devices-matter/VenetianBlindAccessory.d.ts.map +0 -1
  313. package/dist/devices-matter/VenetianBlindAccessory.js +0 -99
  314. package/dist/devices-matter/VenetianBlindAccessory.js.map +0 -1
  315. package/dist/devices-matter/WindowBlindAccessory.d.ts +0 -17
  316. package/dist/devices-matter/WindowBlindAccessory.d.ts.map +0 -1
  317. package/dist/devices-matter/WindowBlindAccessory.js +0 -80
  318. package/dist/devices-matter/WindowBlindAccessory.js.map +0 -1
  319. package/dist/devices-matter/custom/PowerStripAccessory.d.ts +0 -97
  320. package/dist/devices-matter/custom/PowerStripAccessory.d.ts.map +0 -1
  321. package/dist/devices-matter/custom/PowerStripAccessory.js +0 -265
  322. package/dist/devices-matter/custom/PowerStripAccessory.js.map +0 -1
  323. package/dist/devices-matter/custom/index.d.ts +0 -8
  324. package/dist/devices-matter/custom/index.d.ts.map +0 -1
  325. package/dist/devices-matter/custom/index.js +0 -8
  326. package/dist/devices-matter/custom/index.js.map +0 -1
  327. package/dist/devices-matter/index.d.ts +0 -29
  328. package/dist/devices-matter/index.d.ts.map +0 -1
  329. package/dist/devices-matter/index.js +0 -28
  330. package/dist/devices-matter/index.js.map +0 -1
  331. package/dist/index.test.d.ts +0 -2
  332. package/dist/index.test.d.ts.map +0 -1
  333. package/dist/index.test.js +0 -14
  334. package/dist/index.test.js.map +0 -1
  335. package/dist/irdevice/airconditioner.d.ts +0 -61
  336. package/dist/irdevice/airconditioner.d.ts.map +0 -1
  337. package/dist/irdevice/airconditioner.js +0 -472
  338. package/dist/irdevice/airconditioner.js.map +0 -1
  339. package/dist/irdevice/airpurifier.d.ts +0 -50
  340. package/dist/irdevice/airpurifier.d.ts.map +0 -1
  341. package/dist/irdevice/airpurifier.js +0 -213
  342. package/dist/irdevice/airpurifier.js.map +0 -1
  343. package/dist/irdevice/camera.d.ts +0 -32
  344. package/dist/irdevice/camera.d.ts.map +0 -1
  345. package/dist/irdevice/camera.js +0 -107
  346. package/dist/irdevice/camera.js.map +0 -1
  347. package/dist/irdevice/fan.d.ts +0 -36
  348. package/dist/irdevice/fan.d.ts.map +0 -1
  349. package/dist/irdevice/fan.js +0 -200
  350. package/dist/irdevice/fan.js.map +0 -1
  351. package/dist/irdevice/irdevice.d.ts +0 -68
  352. package/dist/irdevice/irdevice.d.ts.map +0 -1
  353. package/dist/irdevice/irdevice.js +0 -298
  354. package/dist/irdevice/irdevice.js.map +0 -1
  355. package/dist/irdevice/light.d.ts +0 -36
  356. package/dist/irdevice/light.d.ts.map +0 -1
  357. package/dist/irdevice/light.js +0 -206
  358. package/dist/irdevice/light.js.map +0 -1
  359. package/dist/irdevice/other.d.ts +0 -57
  360. package/dist/irdevice/other.d.ts.map +0 -1
  361. package/dist/irdevice/other.js +0 -778
  362. package/dist/irdevice/other.js.map +0 -1
  363. package/dist/irdevice/tv.d.ts +0 -45
  364. package/dist/irdevice/tv.d.ts.map +0 -1
  365. package/dist/irdevice/tv.js +0 -327
  366. package/dist/irdevice/tv.js.map +0 -1
  367. package/dist/irdevice/vacuumcleaner.d.ts +0 -28
  368. package/dist/irdevice/vacuumcleaner.d.ts.map +0 -1
  369. package/dist/irdevice/vacuumcleaner.js +0 -104
  370. package/dist/irdevice/vacuumcleaner.js.map +0 -1
  371. package/dist/irdevice/waterheater.d.ts +0 -30
  372. package/dist/irdevice/waterheater.d.ts.map +0 -1
  373. package/dist/irdevice/waterheater.js +0 -105
  374. package/dist/irdevice/waterheater.js.map +0 -1
  375. package/dist/platform-hap.d.ts +0 -149
  376. package/dist/platform-hap.d.ts.map +0 -1
  377. package/dist/platform-hap.js +0 -2861
  378. package/dist/platform-hap.js.map +0 -1
  379. package/dist/platform-matter.d.ts +0 -120
  380. package/dist/platform-matter.d.ts.map +0 -1
  381. package/dist/platform-matter.js +0 -966
  382. package/dist/platform-matter.js.map +0 -1
  383. package/dist/verifyconfig.test.d.ts +0 -2
  384. package/dist/verifyconfig.test.d.ts.map +0 -1
  385. package/dist/verifyconfig.test.js +0 -167
  386. package/dist/verifyconfig.test.js.map +0 -1
  387. package/src/custom.d.ts +0 -7
  388. package/src/devices-hap/airpurifier.ts +0 -563
  389. package/src/devices-hap/blindtilt.ts +0 -1049
  390. package/src/devices-hap/bot.ts +0 -900
  391. package/src/devices-hap/ceilinglight.ts +0 -742
  392. package/src/devices-hap/colorbulb.ts +0 -904
  393. package/src/devices-hap/contact.ts +0 -457
  394. package/src/devices-hap/curtain.ts +0 -944
  395. package/src/devices-hap/device.ts +0 -811
  396. package/src/devices-hap/fan.ts +0 -711
  397. package/src/devices-hap/hub.ts +0 -439
  398. package/src/devices-hap/humidifier.ts +0 -669
  399. package/src/devices-hap/iosensor.ts +0 -427
  400. package/src/devices-hap/lightstrip.ts +0 -836
  401. package/src/devices-hap/lock.ts +0 -620
  402. package/src/devices-hap/meter.ts +0 -426
  403. package/src/devices-hap/meterplus.ts +0 -430
  404. package/src/devices-hap/meterpro.ts +0 -522
  405. package/src/devices-hap/motion.ts +0 -390
  406. package/src/devices-hap/plug.ts +0 -423
  407. package/src/devices-hap/relayswitch.ts +0 -727
  408. package/src/devices-hap/robotvacuumcleaner.ts +0 -568
  409. package/src/devices-hap/waterdetector.ts +0 -400
  410. package/src/devices-matter/BaseMatterAccessory.ts +0 -131
  411. package/src/devices-matter/ColorLightAccessory.ts +0 -110
  412. package/src/devices-matter/ColorTemperatureLightAccessory.ts +0 -92
  413. package/src/devices-matter/ContactSensorAccessory.ts +0 -41
  414. package/src/devices-matter/DimmableLightAccessory.ts +0 -192
  415. package/src/devices-matter/DoorLockAccessory.ts +0 -60
  416. package/src/devices-matter/ExtendedColorLightAccessory.ts +0 -123
  417. package/src/devices-matter/FanAccessory.ts +0 -95
  418. package/src/devices-matter/HumiditySensorAccessory.ts +0 -41
  419. package/src/devices-matter/LeakSensorAccessory.ts +0 -40
  420. package/src/devices-matter/LightSensorAccessory.ts +0 -41
  421. package/src/devices-matter/OccupancySensorAccessory.ts +0 -48
  422. package/src/devices-matter/OnOffLightAccessory.ts +0 -133
  423. package/src/devices-matter/OnOffOutletAccessory.ts +0 -46
  424. package/src/devices-matter/OnOffSwitchAccessory.ts +0 -51
  425. package/src/devices-matter/RoboticVacuumAccessory.ts +0 -407
  426. package/src/devices-matter/SmokeCOAlarmAccessory.ts +0 -59
  427. package/src/devices-matter/TemperatureSensorAccessory.ts +0 -43
  428. package/src/devices-matter/ThermostatAccessory.ts +0 -110
  429. package/src/devices-matter/VenetianBlindAccessory.ts +0 -115
  430. package/src/devices-matter/WindowBlindAccessory.ts +0 -92
  431. package/src/devices-matter/custom/PowerStripAccessory.ts +0 -309
  432. package/src/devices-matter/custom/index.ts +0 -8
  433. package/src/devices-matter/index.ts +0 -29
  434. package/src/index.test.ts +0 -19
  435. package/src/irdevice/airconditioner.ts +0 -533
  436. package/src/irdevice/airpurifier.ts +0 -252
  437. package/src/irdevice/camera.ts +0 -129
  438. package/src/irdevice/fan.ts +0 -226
  439. package/src/irdevice/irdevice.ts +0 -344
  440. package/src/irdevice/light.ts +0 -246
  441. package/src/irdevice/other.ts +0 -790
  442. package/src/irdevice/tv.ts +0 -378
  443. package/src/irdevice/vacuumcleaner.ts +0 -126
  444. package/src/irdevice/waterheater.ts +0 -127
  445. package/src/platform-hap.ts +0 -2997
  446. package/src/platform-matter.ts +0 -1092
  447. package/src/verifyconfig.test.ts +0 -197
@@ -1,249 +1,431 @@
1
- <p class="text-center">
2
- <img
3
- src="https://raw.githubusercontent.com/OpenWonderLabs/homebridge-switchbot/latest/branding/Homebridge_x_SwitchBot.svg"
4
- alt="homebridge-switchbot logo" style="width: 50%" />
5
- </p>
6
- <div id="pageIntro" style="display: none">
7
- <p class="lead text-center">Thank you for installing <strong>homebridge-switchbot</strong></p>
8
- <p class="lead text-center">Before continuing:</p>
9
- <ol>
10
- <li class="mb-3">
11
- Download the SwitchBot App from either the
12
- <a href="https://apps.apple.com/us/app/switchbot/id1087374760" target="_blank" rel="noreferrer noopener">App
13
- Store</a> or the
14
- <a href="https://play.google.com/store/apps/details?id=com.theswitchbot.switchbot&hl=en_US&gl=US" target="_blank"
15
- rel="noreferrer noopener">Play Store</a>.
16
- </li>
17
- <li class="mb-3">Select <strong>Profile</strong>.</li>
18
- <li class="mb-3">Select <strong>Preferences</strong>.</li>
19
- <li class="mb-3">Tap the <strong>App version</strong> 10 times, this will enable Developer Options.</li>
20
- <li class="mb-3">Select <strong>Developer Options</strong>.</li>
21
- <li class="mb-3">Copy your token by hitting <strong>Copy to Clipboard</strong>.</li>
22
- <li class="mb-3">Paste the Token into the Token parameter on the next page.</li>
23
- </ol>
24
- <div class="text-center">
25
- <button type="button" class="btn btn-primary" id="introLink">Continue &rarr;</button>
26
- </div>
27
- </div>
28
- <div id="menuWrapper" class="btn-group w-100 mb-0" role="group" aria-label="UI Menu" style="display: none">
29
- <button type="button" class="btn btn-primary" id="menuSettings">Settings</button>
30
- <button type="button" class="btn btn-primary" id="menuDevices">Devices</button>
31
- <button type="button" class="btn btn-primary mr-0" id="menuHome">Support</button>
32
- </div>
33
- <div id="disabledBanner" class="alert alert-secondary mb-0 mt-3" role="alert" style="display: none">
34
- Plugin is currently disabled
35
- <button id="disabledEnable" type="button" class="btn btn-link p-0 m-0 float-right">Enable</button>
36
- </div>
37
- <div id="pageDevices" class="mt-4" style="display: none">
38
- <div id="deviceInfo">
39
- <form>
1
+ <!doctype html>
2
+ <html>
3
+ <head>
4
+ <meta charset="utf-8" />
5
+ <meta name="viewport" content="width=device-width,initial-scale=1" />
6
+ <title>SwitchBot Plugin UI</title>
7
+ <style>
8
+ body { font-family: system-ui, -apple-system, Arial; padding: 16px; background:#1a1a1a; color:#fff }
9
+ h1 { font-size: 24px; margin-top:0 }
10
+ h2 { font-size: 16px; margin-top: 24px; margin-bottom: 12px; border-bottom:1px solid #444; padding-bottom:8px }
11
+ ul { padding-left: 0; list-style: none }
12
+ li { margin: 8px 0; display:flex; gap:8px; align-items:center }
13
+ button { padding: 8px 16px; background:#6366f1; color:#fff; border:none; border-radius:4px; cursor:pointer }
14
+ button:hover { background:#4f46e5 }
15
+ button.success { background:#10b981 }
16
+ code { background:#333; padding:4px 6px; border-radius:4px; color:#fff }
17
+ .form-group { margin-bottom:16px }
18
+ label { display:block; margin-bottom:6px; font-weight:500 }
19
+ input { width:100%; max-width:400px; padding:8px; background:#2a2a2a; border:1px solid #444; border-radius:4px; color:#fff; font-family:monospace }
20
+ input:focus { outline:none; border-color:#6366f1 }
21
+ .status { font-size:14px; color:#888; margin-top:4px }
22
+ .status.ok { color:#10b981 }
23
+ .error { color:#ef4444 }
24
+ .success-msg { color:#10b981; margin-top:8px }
25
+ .card { background:#2a2a2a; padding:16px; border-radius:8px; margin-bottom:16px }
26
+ </style>
27
+ </head>
28
+ <body>
29
+ <h1>🤖 SwitchBot Configuration</h1>
30
+
31
+ <div class="card">
32
+ <h2>API Credentials</h2>
33
+ <p>Configure your SwitchBot API token and secret to enable device discovery and control.</p>
34
+
40
35
  <div class="form-group">
41
- <select class="form-control" id="deviceSelect"></select>
36
+ <label for="token">API Token:</label>
37
+ <input type="password" id="token" placeholder="Enter your SwitchBot API token" />
38
+ <div class="status" id="tokenStatus"></div>
42
39
  </div>
43
- </form>
44
- <table class="table w-100" id="deviceTable" style="display: none">
45
- <thead>
46
- <tr class="table-active">
47
- <th scope="col" style="width: 40%">Device Name</th>
48
- <th scope="col" style="width: 60%" id="displayName"></th>
49
- </tr>
50
- </thead>
51
- <tbody>
52
- <tr>
53
- <th scope="row">Device ID</th>
54
- <td id="deviceId"></td>
55
- </tr>
56
- <tr>
57
- <th scope="row">Model</th>
58
- <td id="model"></td>
59
- </tr>
60
- <tr>
61
- <th scope="row">Firmware Version</th>
62
- <td id="version"></td>
63
- </tr>
64
- <tr>
65
- <th scope="row">Device Type</th>
66
- <td id="deviceType"></td>
67
- </tr>
68
- <tr>
69
- <th scope="row">Connection Type</th>
70
- <td id="connectionType"></td>
71
- </tr>
72
- </tbody>
73
- </table>
74
- <p class="text-center">External accessories will not be displayed here.</p>
75
- </div>
76
- </div>
77
- <div id="pageSupport" class="mt-4" style="display: none">
78
- <p class="text-center lead">Thank you for using <strong>homebridge-switchbot</strong></p>
79
- <p class="text-center">The links below will take you to our GitHub wiki</p>
80
- <h5>Setup</h5>
81
- <ul>
82
- <li>
83
- <a href="https://github.com/OpenWonderLabs/homebridge-switchbot/wiki" target="_blank">Wiki Home</a>
84
- </li>
85
- <li>
86
- <a href="https://github.com/OpenWonderLabs/homebridge-switchbot/wiki/Configuration"
87
- target="_blank">Configuration</a>
88
- </li>
89
- <li>
90
- <a href="https://github.com/OpenWonderLabs/homebridge-switchbot/wiki/Beta-Version" target="_blank">Beta
91
- Version</a>
92
- </li>
93
- <li>
94
- <a href="https://github.com/OpenWonderLabs/homebridge-switchbot/wiki/Node-Version" target="_blank">Node
95
- Version</a>
96
- </li>
97
- <li>
98
- <a href="https://github.com/OpenWonderLabs/homebridge-switchbot/wiki/Uninstallation"
99
- target="_blank">Uninstallation</a>
100
- </li>
101
- </ul>
102
- <h5>Features</h5>
103
- <ul>
104
- <li>
105
- <a href="https://github.com/OpenWonderLabs/homebridge-switchbot/wiki/Supported-Devices" target="_blank">Supported
106
- Devices</a>
107
- </li>
108
- </ul>
109
- <h5>Help/About</h5>
110
- <ul>
111
- <li>
112
- <a href="https://github.com/OpenWonderLabs/homebridge-switchbot/issues/new/choose" target="_blank">Support
113
- Request</a>
114
- </li>
115
- <li>
116
- <a href="https://github.com/OpenWonderLabs/homebridge-switchbot/blob/latest/CHANGELOG.md"
117
- target="_blank">Changelog</a>
118
- </li>
119
- </ul>
120
- </div>
121
- <script>
122
- (async () => {
123
- try {
124
- const currentConfig = await homebridge.getPluginConfig();
125
- showIntro = () => {
126
- const introLink = document.getElementById('introLink');
127
- introLink.addEventListener('click', () => {
128
- homebridge.showSpinner();
129
- document.getElementById('pageIntro').style.display = 'none';
130
- document.getElementById('menuWrapper').style.display = 'inline-flex';
131
- showSettings();
132
- homebridge.hideSpinner();
133
- });
134
- document.getElementById('pageIntro').style.display = 'block';
135
- };
136
- showDevices = async () => {
137
- homebridge.showSpinner();
138
- homebridge.hideSchemaForm();
139
- document.getElementById('menuHome').classList.remove('btn-elegant');
140
- document.getElementById('menuHome').classList.add('btn-primary');
141
- document.getElementById('menuDevices').classList.add('btn-elegant');
142
- document.getElementById('menuDevices').classList.remove('btn-primary');
143
- document.getElementById('menuSettings').classList.remove('btn-elegant');
144
- document.getElementById('menuSettings').classList.add('btn-primary');
145
- document.getElementById('pageSupport').style.display = 'none';
146
- document.getElementById('pageDevices').style.display = 'block';
147
- const cachedAccessories =
148
- typeof homebridge.getCachedAccessories === 'function'
149
- ? await homebridge.getCachedAccessories()
150
- : await homebridge.request('/getCachedAccessories');
151
- if (cachedAccessories.length > 0) {
152
- cachedAccessories.sort((a, b) => {
153
- return a.displayName.toLowerCase() > b.displayName.toLowerCase() ? 1 : b.displayName.toLowerCase() > a.displayName.toLowerCase() ? -1 : 0;
154
- });
40
+
41
+ <div class="form-group">
42
+ <label for="secret">API Secret:</label>
43
+ <input type="password" id="secret" placeholder="Enter your SwitchBot API secret" />
44
+ <div class="status" id="secretStatus"></div>
45
+ </div>
46
+
47
+ <button id="saveBtn" onclick="saveCredentials()">Save Credentials</button>
48
+ <div id="saveStatus"></div>
49
+ </div>
50
+
51
+ <div class="card">
52
+ <h2>Discover Devices</h2>
53
+ <p>Click "Discover" to find all devices available in your SwitchBot account and add them to your configuration.</p>
54
+ <button id="discoverBtn" onclick="discoverDevices()" style="margin-bottom: 16px">🔍 Discover Devices</button>
55
+ <div id="discoverStatus" style="margin-bottom: 16px"></div>
56
+ <div id="discoveredList" style="display: none">
57
+ <h3 style="margin-top: 0">Available Devices</h3>
58
+ <ul id="discoveredDevices" style="max-height: 300px; overflow-y: auto"></ul>
59
+ </div>
60
+ </div>
61
+
62
+ <div class="card">
63
+ <h2>Configured Devices</h2>
64
+ <p>This page lists devices found in your Homebridge config for the SwitchBot platform. Use the copy button to insert device IDs into the plugin configuration. Connection preference (BLE/OpenAPI) is shown when available.</p>
65
+ <div id="status">Loading…</div>
66
+ <ul id="devices"></ul>
67
+ </div>
68
+
69
+ <script>
70
+ async function loadCredentialStatus() {
71
+ try {
72
+ const resp = await homebridge.request('/credentials', {})
73
+ console.log('Load credentials response:', resp)
74
+
75
+ if (!resp || resp.success === false) {
76
+ console.error('Failed to load credentials:', resp)
77
+ return
78
+ }
79
+
80
+ const creds = resp.data || {}
81
+ const tokenStatus = document.getElementById('tokenStatus')
82
+ const secretStatus = document.getElementById('secretStatus')
83
+
84
+ if (creds.hasToken) {
85
+ tokenStatus.textContent = `✓ Configured (${creds.tokenLength} characters)`
86
+ tokenStatus.classList.add('ok')
87
+ } else {
88
+ tokenStatus.textContent = 'Not configured'
89
+ tokenStatus.classList.remove('ok')
90
+ }
91
+
92
+ if (creds.hasSecret) {
93
+ secretStatus.textContent = `✓ Configured (${creds.secretLength} characters)`
94
+ secretStatus.classList.add('ok')
95
+ } else {
96
+ secretStatus.textContent = 'Not configured'
97
+ secretStatus.classList.remove('ok')
98
+ }
99
+ } catch (e) {
100
+ console.error('Error loading credentials:', e)
101
+ }
102
+ }
103
+
104
+ async function saveCredentials() {
105
+ const token = document.getElementById('token').value
106
+ const secret = document.getElementById('secret').value
107
+ const saveStatus = document.getElementById('saveStatus')
108
+ const saveBtn = document.getElementById('saveBtn')
109
+
110
+ if (!token || !secret) {
111
+ saveStatus.textContent = 'Please enter both token and secret'
112
+ saveStatus.classList.add('error')
113
+ return
114
+ }
115
+
116
+ try {
117
+ saveBtn.disabled = true
118
+ saveBtn.textContent = 'Saving...'
119
+
120
+ console.log('Saving credentials...')
121
+ const resp = await homebridge.request('/credentials', { token, secret })
122
+ console.log('Save response:', resp)
123
+
124
+ if (!resp || resp.success === false) {
125
+ throw new Error(resp?.message || 'Save failed')
126
+ }
127
+
128
+ const result = resp.data || resp
129
+ saveStatus.textContent = '✓ ' + (result.message || 'Credentials saved successfully')
130
+ saveStatus.classList.remove('error')
131
+ saveStatus.classList.add('success-msg')
132
+
133
+ // Clear inputs after successful save
134
+ document.getElementById('token').value = ''
135
+ document.getElementById('secret').value = ''
136
+
137
+ // Reload status to verify save
138
+ setTimeout(() => loadCredentialStatus(), 500)
139
+
140
+ // Clear status message
141
+ setTimeout(() => {
142
+ saveStatus.textContent = ''
143
+ saveStatus.classList.remove('success-msg')
144
+ }, 3000)
145
+ } catch (e) {
146
+ console.error('Save error:', e)
147
+ saveStatus.textContent = 'Error: ' + (e?.message || 'Failed to save')
148
+ saveStatus.classList.add('error')
149
+ } finally {
150
+ saveBtn.disabled = false
151
+ saveBtn.textContent = 'Save Credentials'
152
+ }
153
+ }
154
+
155
+ async function fetchDevices() {
156
+ try {
157
+ const resp = await homebridge.request('/devices', {})
158
+ if (!resp || resp.success === false) throw new Error(resp?.data?.message || 'request failed')
159
+ return resp.data || []
160
+ } catch (e) {
161
+ console.error(e)
162
+ return []
163
+ }
164
+ }
165
+
166
+ async function discoverDevices() {
167
+ const btn = document.getElementById('discoverBtn')
168
+ const status = document.getElementById('discoverStatus')
169
+ const list = document.getElementById('discoveredList')
170
+ const ul = document.getElementById('discoveredDevices')
171
+
172
+ try {
173
+ btn.disabled = true
174
+ btn.textContent = '🔍 Discovering...'
175
+ status.textContent = 'Searching SwitchBot account...'
176
+ status.classList.remove('error')
177
+
178
+ const resp = await homebridge.request('/discover', {})
179
+ console.log('Discover response:', resp)
180
+
181
+ if (!resp || resp.success === false) {
182
+ throw new Error(resp?.data?.message || 'Discovery failed')
183
+ }
184
+
185
+ const devices = resp.data || []
186
+
187
+ if (!devices.length) {
188
+ status.textContent = 'No devices found in your SwitchBot account'
189
+ list.style.display = 'none'
190
+ return
191
+ }
192
+
193
+ status.textContent = `Found ${devices.length} device(s)`
194
+ ul.innerHTML = ''
195
+
196
+ for (const d of devices) {
197
+ const li = document.createElement('li')
198
+ li.style.display = 'flex'
199
+ li.style.gap = '8px'
200
+ li.style.alignItems = 'center'
201
+ li.style.justifyContent = 'space-between'
202
+ li.style.padding = '8px'
203
+ li.style.background = '#333'
204
+ li.style.borderRadius = '4px'
205
+ li.style.marginBottom = '8px'
206
+
207
+ const info = document.createElement('div')
208
+ info.style.flex = '1'
209
+ const name = document.createElement('div')
210
+ name.style.fontWeight = '500'
211
+ name.textContent = d.name || d.id
212
+ const details = document.createElement('div')
213
+ details.style.fontSize = '12px'
214
+ details.style.opacity = '0.75'
215
+ details.textContent = `ID: ${d.id} | Type: ${d.type} | Model: ${d.model || 'N/A'}`
216
+ info.appendChild(name)
217
+ info.appendChild(details)
218
+
219
+ const addBtn = document.createElement('button')
220
+ addBtn.textContent = '+ Add'
221
+ addBtn.style.marginLeft = '8px'
222
+ addBtn.onclick = async () => {
223
+ await addDeviceToConfig(d)
224
+ }
225
+
226
+ li.appendChild(info)
227
+ li.appendChild(addBtn)
228
+ ul.appendChild(li)
229
+ }
230
+
231
+ list.style.display = 'block'
232
+ } catch (e) {
233
+ console.error('Discovery error:', e)
234
+ status.textContent = 'Error: ' + (e?.message || 'Discovery failed')
235
+ status.classList.add('error')
236
+ list.style.display = 'none'
237
+ } finally {
238
+ btn.disabled = false
239
+ btn.textContent = '🔍 Discover Devices'
155
240
  }
156
- const deviceSelect = document.getElementById('deviceSelect');
157
- deviceSelect.innerHTML = '';
158
- cachedAccessories.forEach((a) => {
159
- const option = document.createElement('option');
160
- option.text = a.displayName;
161
- option.value = a.UUID;
162
- deviceSelect.add(option);
163
- });
164
- showDeviceInfo = async (UUID) => {
165
- homebridge.showSpinner();
166
- const thisAcc = cachedAccessories.find((x) => x.UUID === UUID);
167
- const context = thisAcc.context;
168
- document.getElementById('displayName').innerHTML = thisAcc.displayName;
169
- document.getElementById('deviceId').innerHTML = context.deviceId;
170
- document.getElementById('model').innerHTML = context.model;
171
- document.getElementById('version').innerHTML = context.version;
172
- document.getElementById('deviceType').innerHTML = context.deviceType;
173
- document.getElementById('connectionType').innerHTML = context.connectionType;
174
- document.getElementById('refreshRate').innerHTML = context.refreshRate;
175
- document.getElementById('updateRate').innerHTML = context.updateRate;
176
- document.getElementById('pushRate').innerHTML = context.pushRate;
177
- document.getElementById('deviceTable').style.display = 'inline-table';
178
- homebridge.hideSpinner();
179
- };
180
- deviceSelect.addEventListener('change', (event) => showDeviceInfo(event.target.value));
181
- if (cachedAccessories.length > 0) {
182
- showDeviceInfo(cachedAccessories[0].UUID);
183
- } else {
184
- const option = document.createElement('option');
185
- option.text = 'No Devices';
186
- deviceSelect.add(option);
187
- deviceSelect.disabled = true;
241
+ }
242
+
243
+ async function addDeviceToConfig(device) {
244
+ try {
245
+ console.log('Adding device to config:', device)
246
+
247
+ const resp = await homebridge.request('/add-device', {
248
+ deviceId: device.id,
249
+ name: device.name,
250
+ type: device.type,
251
+ })
252
+
253
+ console.log('Add device response:', resp)
254
+
255
+ if (!resp || resp.success === false) {
256
+ throw new Error(resp?.data?.message || 'Failed to add device')
257
+ }
258
+
259
+ // Show success message
260
+ const message = resp.data?.message || `Device "${device.name}" added successfully!`
261
+ const status = document.getElementById('discoverStatus')
262
+ status.textContent = '' + message
263
+ status.classList.remove('error')
264
+ status.classList.add('success-msg')
265
+
266
+ // Refresh lists after 1 second
267
+ setTimeout(async () => {
268
+ await loadConfiguredDevices()
269
+ await discoverDevices()
270
+ }, 1000)
271
+ } catch (e) {
272
+ console.error('Add device error:', e)
273
+ const status = document.getElementById('discoverStatus')
274
+ status.textContent = '✗ Error: ' + (e?.message || 'Failed to add device')
275
+ status.classList.add('error')
276
+ }
277
+ }
278
+
279
+ async function loadConfiguredDevices() {
280
+ const list = await fetchDevices()
281
+ render(list)
282
+ }
283
+
284
+ async function deleteDevice(deviceId, deviceName) {
285
+ if (!confirm(`Are you sure you want to remove "${deviceName || deviceId}"?`)) {
286
+ return
287
+ }
288
+
289
+ try {
290
+ const resp = await homebridge.request('/delete-device', { deviceId })
291
+
292
+ if (!resp || resp.success === false) {
293
+ throw new Error(resp?.data?.message || 'Failed to delete device')
294
+ }
295
+
296
+ // Refresh device list
297
+ const list = await fetchDevices()
298
+ render(list)
299
+ } catch (e) {
300
+ console.error('Delete error:', e)
301
+ alert('Error: ' + (e?.message || 'Failed to delete device'))
302
+ }
303
+ }
304
+
305
+ async function editDevice(device) {
306
+ const newName = prompt('Device Name:', device.name || device.id)
307
+ if (newName === null) return // User cancelled
308
+
309
+ try {
310
+ const resp = await homebridge.request('/update-device', {
311
+ deviceId: device.id,
312
+ configDeviceName: newName || undefined,
313
+ })
314
+
315
+ if (!resp || resp.success === false) {
316
+ throw new Error(resp?.data?.message || 'Failed to update device')
317
+ }
318
+
319
+ // Refresh device list
320
+ const list = await fetchDevices()
321
+ render(list)
322
+ } catch (e) {
323
+ console.error('Update error:', e)
324
+ alert('Error: ' + (e?.message || 'Failed to update device'))
325
+ }
326
+ }
327
+
328
+ function render(list) {
329
+ const ul = document.getElementById('devices')
330
+ const status = document.getElementById('status')
331
+ if (!list.length) {
332
+ status.textContent = 'No devices found in config.'
333
+ ul.innerHTML = ''
334
+ return
188
335
  }
189
- homebridge.hideSpinner();
190
- };
191
- showSupport = () => {
192
- homebridge.showSpinner();
193
- homebridge.hideSchemaForm();
194
- document.getElementById('menuHome').classList.add('btn-elegant');
195
- document.getElementById('menuHome').classList.remove('btn-primary');
196
- document.getElementById('menuDevices').classList.remove('btn-elegant');
197
- document.getElementById('menuDevices').classList.add('btn-primary');
198
- document.getElementById('menuSettings').classList.remove('btn-elegant');
199
- document.getElementById('menuSettings').classList.add('btn-primary');
200
- document.getElementById('pageSupport').style.display = 'block';
201
- document.getElementById('pageDevices').style.display = 'none';
202
- homebridge.hideSpinner();
203
- };
204
- showSettings = () => {
205
- homebridge.showSpinner();
206
- document.getElementById('menuHome').classList.remove('btn-elegant');
207
- document.getElementById('menuHome').classList.add('btn-primary');
208
- document.getElementById('menuDevices').classList.remove('btn-elegant');
209
- document.getElementById('menuDevices').classList.add('btn-primary');
210
- document.getElementById('menuSettings').classList.add('btn-elegant');
211
- document.getElementById('menuSettings').classList.remove('btn-primary');
212
- document.getElementById('pageSupport').style.display = 'none';
213
- document.getElementById('pageDevices').style.display = 'none';
214
- homebridge.showSchemaForm();
215
- homebridge.hideSpinner();
216
- };
217
- showDisabledBanner = () => {
218
- document.getElementById('disabledBanner').style.display = 'block';
219
- };
220
- enablePlugin = async () => {
221
- homebridge.showSpinner();
222
- document.getElementById('disabledBanner').style.display = 'none';
223
- currentConfig[0].disablePlugin = false;
224
- await homebridge.updatePluginConfig(currentConfig);
225
- await homebridge.savePluginConfig();
226
- homebridge.hideSpinner();
227
- };
228
- menuHome.addEventListener('click', () => showSupport());
229
- menuDevices.addEventListener('click', () => showDevices());
230
- menuSettings.addEventListener('click', () => showSettings());
231
- disabledEnable.addEventListener('click', () => enablePlugin());
232
- if (currentConfig.length) {
233
- document.getElementById('menuWrapper').style.display = 'inline-flex';
234
- showSettings();
235
- if (currentConfig[0].disablePlugin) {
236
- showDisabledBanner();
336
+ status.textContent = `Found ${list.length} device(s)`
337
+ ul.innerHTML = ''
338
+ for (const d of list) {
339
+ const li = document.createElement('li')
340
+ li.style.display = 'flex'
341
+ li.style.gap = '8px'
342
+ li.style.alignItems = 'center'
343
+ li.style.justifyContent = 'space-between'
344
+ li.style.padding = '8px'
345
+ li.style.background = '#333'
346
+ li.style.borderRadius = '4px'
347
+ li.style.marginBottom = '8px'
348
+
349
+ const info = document.createElement('div')
350
+ info.style.flex = '1'
351
+
352
+ const name = document.createElement('div')
353
+ name.style.fontWeight = '500'
354
+ name.textContent = d.name || d.id
355
+
356
+ const code = document.createElement('code')
357
+ code.textContent = d.id
358
+ code.style.fontSize = '12px'
359
+ code.style.opacity = '0.75'
360
+ code.style.marginLeft = '8px'
361
+
362
+ const meta = document.createElement('div')
363
+ meta.style.opacity = '0.75'
364
+ meta.style.marginTop = '4px'
365
+ meta.style.fontSize = '12px'
366
+ const typeText = d.type ? `type: ${d.type}` : ''
367
+ const connText = d.connectionPreference ? `conn: ${d.connectionPreference}` : ''
368
+ const roomText = d.room ? `room: ${d.room}` : ''
369
+ meta.textContent = [typeText, connText, roomText].filter(Boolean).join(' | ')
370
+
371
+ info.appendChild(name)
372
+ info.appendChild(code)
373
+ info.appendChild(meta)
374
+
375
+ const buttons = document.createElement('div')
376
+ buttons.style.display = 'flex'
377
+ buttons.style.gap = '8px'
378
+
379
+ const editBtn = document.createElement('button')
380
+ editBtn.textContent = '✏️ Edit'
381
+ editBtn.style.padding = '6px 12px'
382
+ editBtn.style.fontSize = '12px'
383
+ editBtn.onclick = async () => {
384
+ await editDevice(d)
385
+ }
386
+
387
+ const copyBtn = document.createElement('button')
388
+ copyBtn.textContent = 'Copy ID'
389
+ copyBtn.style.padding = '6px 12px'
390
+ copyBtn.style.fontSize = '12px'
391
+ copyBtn.addEventListener('click', async () => {
392
+ try {
393
+ await navigator.clipboard.writeText(d.id)
394
+ copyBtn.textContent = 'Copied'
395
+ copyBtn.classList.add('success')
396
+ setTimeout(() => {
397
+ copyBtn.textContent = 'Copy ID'
398
+ copyBtn.classList.remove('success')
399
+ }, 1200)
400
+ } catch (e) {
401
+ alert('Failed to copy')
402
+ }
403
+ })
404
+
405
+ const deleteBtn = document.createElement('button')
406
+ deleteBtn.textContent = '🗑️ Delete'
407
+ deleteBtn.style.padding = '6px 12px'
408
+ deleteBtn.style.fontSize = '12px'
409
+ deleteBtn.style.background = '#ef4444'
410
+ deleteBtn.onclick = async () => {
411
+ await deleteDevice(d.id, d.name || d.id)
412
+ }
413
+
414
+ buttons.appendChild(editBtn)
415
+ buttons.appendChild(copyBtn)
416
+ buttons.appendChild(deleteBtn)
417
+
418
+ li.appendChild(info)
419
+ li.appendChild(buttons)
420
+ ul.appendChild(li)
237
421
  }
238
- } else {
239
- currentConfig.push({ name: 'SwitchBot' });
240
- await homebridge.updatePluginConfig(currentConfig);
241
- showIntro();
242
422
  }
243
- } catch (err) {
244
- homebridge.toast.error(err.message, 'Error');
245
- } finally {
246
- homebridge.hideSpinner();
247
- }
248
- })();
249
- </script>
423
+
424
+ (async () => {
425
+ await loadCredentialStatus()
426
+ const list = await fetchDevices()
427
+ render(list)
428
+ })()
429
+ </script>
430
+ </body>
431
+ </html>