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

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 (578) hide show
  1. package/.github/ISSUE_TEMPLATE/e2e-verification.md +36 -0
  2. package/.github/copilot-instructions.md +39 -0
  3. package/.github/workflows/ci.yml +32 -0
  4. package/.github/workflows/manual-e2e.yml +115 -0
  5. package/.github/workflows/release.yml +0 -4
  6. package/CHANGELOG.md +35 -0
  7. package/E2E-VERIFICATION.md +121 -0
  8. package/MIGRATION.md +44 -0
  9. package/README.md +56 -3
  10. package/config.schema.json +170 -14787
  11. package/dist/device-types.d.ts +31 -0
  12. package/dist/device-types.d.ts.map +1 -0
  13. package/dist/device-types.js +216 -0
  14. package/dist/device-types.js.map +1 -0
  15. package/dist/deviceFactory.d.ts +13 -0
  16. package/dist/deviceFactory.d.ts.map +1 -0
  17. package/dist/deviceFactory.js +120 -0
  18. package/dist/deviceFactory.js.map +1 -0
  19. package/dist/devices/deviceBase.d.ts +50 -0
  20. package/dist/devices/deviceBase.d.ts.map +1 -0
  21. package/dist/devices/deviceBase.js +119 -0
  22. package/dist/devices/deviceBase.js.map +1 -0
  23. package/dist/devices/genericDevice.d.ts +298 -0
  24. package/dist/devices/genericDevice.d.ts.map +1 -0
  25. package/dist/devices/genericDevice.js +1067 -0
  26. package/dist/devices/genericDevice.js.map +1 -0
  27. package/dist/homebridge-ui/endpoints/config.d.ts +3 -0
  28. package/dist/homebridge-ui/endpoints/config.d.ts.map +1 -0
  29. package/dist/homebridge-ui/endpoints/config.js +104 -0
  30. package/dist/homebridge-ui/endpoints/config.js.map +1 -0
  31. package/dist/homebridge-ui/endpoints/credentials.d.ts +6 -0
  32. package/dist/homebridge-ui/endpoints/credentials.d.ts.map +1 -0
  33. package/dist/homebridge-ui/endpoints/credentials.js +65 -0
  34. package/dist/homebridge-ui/endpoints/credentials.js.map +1 -0
  35. package/dist/homebridge-ui/endpoints/devices.d.ts +6 -0
  36. package/dist/homebridge-ui/endpoints/devices.d.ts.map +1 -0
  37. package/dist/homebridge-ui/endpoints/devices.js +351 -0
  38. package/dist/homebridge-ui/endpoints/devices.js.map +1 -0
  39. package/dist/homebridge-ui/endpoints/discovery.d.ts +7 -0
  40. package/dist/homebridge-ui/endpoints/discovery.d.ts.map +1 -0
  41. package/dist/homebridge-ui/endpoints/discovery.js +171 -0
  42. package/dist/homebridge-ui/endpoints/discovery.js.map +1 -0
  43. package/dist/homebridge-ui/public/css/styles.css +254 -0
  44. package/dist/homebridge-ui/public/index.html +112 -247
  45. package/dist/homebridge-ui/public/js/api.d.ts +23 -0
  46. package/dist/homebridge-ui/public/js/api.d.ts.map +1 -0
  47. package/dist/homebridge-ui/public/js/api.js +188 -0
  48. package/dist/homebridge-ui/public/js/api.js.map +1 -0
  49. package/dist/homebridge-ui/public/js/api.ts +215 -0
  50. package/dist/homebridge-ui/public/js/app.d.ts +2 -0
  51. package/dist/homebridge-ui/public/js/app.d.ts.map +1 -0
  52. package/dist/homebridge-ui/public/js/app.js +1815 -0
  53. package/dist/homebridge-ui/public/js/app.js.map +7 -0
  54. package/dist/homebridge-ui/public/js/app.ts +22 -0
  55. package/dist/homebridge-ui/public/js/constants.d.ts +2 -0
  56. package/dist/homebridge-ui/public/js/constants.d.ts.map +1 -0
  57. package/dist/homebridge-ui/public/js/constants.js +2 -0
  58. package/dist/homebridge-ui/public/js/constants.js.map +1 -0
  59. package/dist/homebridge-ui/public/js/constants.ts +1 -0
  60. package/dist/homebridge-ui/public/js/credentials.d.ts +3 -0
  61. package/dist/homebridge-ui/public/js/credentials.d.ts.map +1 -0
  62. package/dist/homebridge-ui/public/js/credentials.js +96 -0
  63. package/dist/homebridge-ui/public/js/credentials.js.map +1 -0
  64. package/dist/homebridge-ui/public/js/credentials.ts +100 -0
  65. package/dist/homebridge-ui/public/js/devices-delete.d.ts +3 -0
  66. package/dist/homebridge-ui/public/js/devices-delete.d.ts.map +1 -0
  67. package/dist/homebridge-ui/public/js/devices-delete.js +206 -0
  68. package/dist/homebridge-ui/public/js/devices-delete.js.map +1 -0
  69. package/dist/homebridge-ui/public/js/devices-delete.ts +236 -0
  70. package/dist/homebridge-ui/public/js/devices.d.ts +9 -0
  71. package/dist/homebridge-ui/public/js/devices.d.ts.map +1 -0
  72. package/dist/homebridge-ui/public/js/devices.js +90 -0
  73. package/dist/homebridge-ui/public/js/devices.js.map +1 -0
  74. package/dist/homebridge-ui/public/js/devices.ts +98 -0
  75. package/dist/homebridge-ui/public/js/discovery.d.ts +3 -0
  76. package/dist/homebridge-ui/public/js/discovery.d.ts.map +1 -0
  77. package/dist/homebridge-ui/public/js/discovery.js +244 -0
  78. package/dist/homebridge-ui/public/js/discovery.js.map +1 -0
  79. package/dist/homebridge-ui/public/js/discovery.ts +290 -0
  80. package/dist/homebridge-ui/public/js/logger.d.ts +6 -0
  81. package/dist/homebridge-ui/public/js/logger.d.ts.map +1 -0
  82. package/dist/homebridge-ui/public/js/logger.js +12 -0
  83. package/dist/homebridge-ui/public/js/logger.js.map +1 -0
  84. package/dist/homebridge-ui/public/js/logger.ts +11 -0
  85. package/dist/homebridge-ui/public/js/modal.d.ts +5 -0
  86. package/dist/homebridge-ui/public/js/modal.d.ts.map +1 -0
  87. package/dist/homebridge-ui/public/js/modal.js +26 -0
  88. package/dist/homebridge-ui/public/js/modal.js.map +1 -0
  89. package/dist/homebridge-ui/public/js/modal.ts +28 -0
  90. package/dist/homebridge-ui/public/js/modals.d.ts +7 -0
  91. package/dist/homebridge-ui/public/js/modals.d.ts.map +1 -0
  92. package/dist/homebridge-ui/public/js/modals.js +323 -0
  93. package/dist/homebridge-ui/public/js/modals.js.map +1 -0
  94. package/dist/homebridge-ui/public/js/modals.ts +367 -0
  95. package/dist/homebridge-ui/public/js/render.d.ts +65 -0
  96. package/dist/homebridge-ui/public/js/render.d.ts.map +1 -0
  97. package/dist/homebridge-ui/public/js/render.js +499 -0
  98. package/dist/homebridge-ui/public/js/render.js.map +1 -0
  99. package/dist/homebridge-ui/public/js/render.ts +579 -0
  100. package/dist/homebridge-ui/public/js/toast.d.ts +6 -0
  101. package/dist/homebridge-ui/public/js/toast.d.ts.map +1 -0
  102. package/dist/homebridge-ui/public/js/toast.js +29 -0
  103. package/dist/homebridge-ui/public/js/toast.js.map +1 -0
  104. package/dist/homebridge-ui/public/js/toast.ts +37 -0
  105. package/dist/homebridge-ui/public/js/types.d.ts +23 -0
  106. package/dist/homebridge-ui/public/js/types.d.ts.map +1 -0
  107. package/dist/homebridge-ui/public/js/types.js +2 -0
  108. package/dist/homebridge-ui/public/js/types.js.map +1 -0
  109. package/dist/homebridge-ui/public/js/types.ts +26 -0
  110. package/dist/homebridge-ui/server.js +11 -41
  111. package/dist/homebridge-ui/server.js.map +1 -1
  112. package/dist/homebridge-ui/utils/config-parser.d.ts +35 -0
  113. package/dist/homebridge-ui/utils/config-parser.d.ts.map +1 -0
  114. package/dist/homebridge-ui/utils/config-parser.js +87 -0
  115. package/dist/homebridge-ui/utils/config-parser.js.map +1 -0
  116. package/dist/homebridge-ui/utils/device-migration.d.ts +35 -0
  117. package/dist/homebridge-ui/utils/device-migration.d.ts.map +1 -0
  118. package/dist/homebridge-ui/utils/device-migration.js +111 -0
  119. package/dist/homebridge-ui/utils/device-migration.js.map +1 -0
  120. package/dist/homebridge-ui/utils/logger.d.ts +7 -0
  121. package/dist/homebridge-ui/utils/logger.d.ts.map +1 -0
  122. package/dist/homebridge-ui/utils/logger.js +17 -0
  123. package/dist/homebridge-ui/utils/logger.js.map +1 -0
  124. package/dist/index.d.ts.map +1 -1
  125. package/dist/index.js +4 -65
  126. package/dist/index.js.map +1 -1
  127. package/dist/platform.d.ts +35 -0
  128. package/dist/platform.d.ts.map +1 -0
  129. package/dist/platform.js +1527 -0
  130. package/dist/platform.js.map +1 -0
  131. package/dist/settings.d.ts +10 -249
  132. package/dist/settings.d.ts.map +1 -1
  133. package/dist/settings.js +5 -30
  134. package/dist/settings.js.map +1 -1
  135. package/dist/switchbotClient.d.ts +32 -0
  136. package/dist/switchbotClient.d.ts.map +1 -0
  137. package/dist/switchbotClient.js +207 -0
  138. package/dist/switchbotClient.js.map +1 -0
  139. package/dist/utils.d.ts +39 -50
  140. package/dist/utils.d.ts.map +1 -1
  141. package/dist/utils.js +40 -688
  142. package/dist/utils.js.map +1 -1
  143. package/docs/assets/highlight.css +14 -0
  144. package/docs/assets/icons.js +1 -1
  145. package/docs/assets/icons.svg +1 -1
  146. package/docs/assets/main.js +2 -2
  147. package/docs/assets/style.css +3 -3
  148. package/docs/index.html +77 -13
  149. package/docs/variables/default.html +1 -1
  150. package/eslint.config.js +7 -8
  151. package/nodemon.json +2 -2
  152. package/package.json +35 -32
  153. package/scripts/build-ui.js +36 -0
  154. package/scripts/e2e/README.md +25 -0
  155. package/scripts/e2e/curtain-e2e.sh +70 -0
  156. package/scripts/e2e/fan-e2e.sh +75 -0
  157. package/scripts/e2e/light-advanced-e2e.sh +97 -0
  158. package/scripts/e2e/light-e2e.sh +75 -0
  159. package/scripts/e2e/list-accessories.sh +19 -0
  160. package/scripts/e2e/lock-e2e.sh +65 -0
  161. package/scripts/free-dev-ports.mjs +105 -0
  162. package/scripts/generate-matter-maps.js +60 -0
  163. package/scripts/run-e2e-local.sh +14 -0
  164. package/scripts/sync-device-types.mjs +28 -0
  165. package/src/device-types.ts +230 -0
  166. package/src/deviceFactory.ts +163 -0
  167. package/src/devices/deviceBase.ts +141 -0
  168. package/src/devices/genericDevice.ts +998 -0
  169. package/src/homebridge-ui/endpoints/config.ts +123 -0
  170. package/src/homebridge-ui/endpoints/credentials.ts +74 -0
  171. package/src/homebridge-ui/endpoints/devices.ts +383 -0
  172. package/src/homebridge-ui/endpoints/discovery.ts +191 -0
  173. package/src/homebridge-ui/public/css/styles.css +254 -0
  174. package/src/homebridge-ui/public/index.html +112 -247
  175. package/src/homebridge-ui/public/js/api.ts +215 -0
  176. package/src/homebridge-ui/public/js/app.ts +22 -0
  177. package/src/homebridge-ui/public/js/constants.ts +1 -0
  178. package/src/homebridge-ui/public/js/credentials.ts +100 -0
  179. package/src/homebridge-ui/public/js/devices-delete.ts +236 -0
  180. package/src/homebridge-ui/public/js/devices.ts +98 -0
  181. package/src/homebridge-ui/public/js/discovery.ts +290 -0
  182. package/src/homebridge-ui/public/js/logger.ts +11 -0
  183. package/src/homebridge-ui/public/js/modal.ts +28 -0
  184. package/src/homebridge-ui/public/js/modals.ts +367 -0
  185. package/src/homebridge-ui/public/js/render.ts +579 -0
  186. package/src/homebridge-ui/public/js/toast.ts +37 -0
  187. package/src/homebridge-ui/public/js/types.ts +26 -0
  188. package/src/homebridge-ui/server.ts +11 -43
  189. package/src/homebridge-ui/utils/config-parser.ts +108 -0
  190. package/src/homebridge-ui/utils/device-migration.ts +144 -0
  191. package/src/homebridge-ui/utils/logger.ts +17 -0
  192. package/src/index.ts +4 -66
  193. package/src/platform.ts +1539 -0
  194. package/src/settings.ts +12 -277
  195. package/src/switchbotClient.ts +216 -0
  196. package/src/utils.ts +46 -713
  197. package/switchbot-homebridge-switchbot-5.0.0.tgz +0 -0
  198. package/test/accessory-restore.spec.ts +73 -0
  199. package/test/device-mapping.spec.ts +37 -0
  200. package/test/deviceFactory.spec.ts +18 -0
  201. package/test/e2e/run-e2e.spec.ts +50 -0
  202. package/test/fan-swing.spec.ts +29 -0
  203. package/test/helpers/matter-harness.ts +53 -0
  204. package/test/lock-users.spec.ts +44 -0
  205. package/test/matter-childbridge.spec.ts +59 -0
  206. package/test/matter-descriptors.spec.ts +97 -0
  207. package/test/matter-device-state.spec.ts +101 -0
  208. package/test/matter-integration.spec.ts +111 -0
  209. package/test/platform.integration.spec.ts +55 -0
  210. package/test/switchbot-client-debounce.spec.ts +131 -0
  211. package/test/switchbot-client-openapi.spec.ts +56 -0
  212. package/test/switchbotClient.spec.ts +10 -0
  213. package/test/utils.spec.ts +36 -0
  214. package/todo/COMPLETED.md +229 -0
  215. package/todo/README.md +59 -0
  216. package/todo/TODO.md +176 -0
  217. package/todo/mockups/filtering-sorting.svg +112 -0
  218. package/todo/mockups/modal-switchbot-theme.svg +66 -0
  219. package/todo/mockups/signal-strength-visualization.svg +94 -0
  220. package/vitest.config.ts +7 -0
  221. package/coverage/base.css +0 -224
  222. package/coverage/block-navigation.js +0 -87
  223. package/coverage/clover.xml +0 -15847
  224. package/coverage/coverage-final.json +0 -42
  225. package/coverage/docs/assets/dmt/dmt-component-data.js.html +0 -85
  226. package/coverage/docs/assets/dmt/dmt-components.js.html +0 -286
  227. package/coverage/docs/assets/dmt/index.html +0 -131
  228. package/coverage/docs/assets/hierarchy.js.html +0 -85
  229. package/coverage/docs/assets/icons.js.html +0 -136
  230. package/coverage/docs/assets/index.html +0 -146
  231. package/coverage/docs/assets/main.js.html +0 -265
  232. package/coverage/favicon.png +0 -0
  233. package/coverage/index.html +0 -191
  234. package/coverage/prettify.css +0 -1
  235. package/coverage/prettify.js +0 -2
  236. package/coverage/sort-arrow-sprite.png +0 -0
  237. package/coverage/sorter.js +0 -196
  238. package/coverage/src/device/blindtilt.ts.html +0 -3238
  239. package/coverage/src/device/bot.ts.html +0 -2803
  240. package/coverage/src/device/ceilinglight.ts.html +0 -2338
  241. package/coverage/src/device/colorbulb.ts.html +0 -2824
  242. package/coverage/src/device/contact.ts.html +0 -1465
  243. package/coverage/src/device/curtain.ts.html +0 -2869
  244. package/coverage/src/device/device.ts.html +0 -2500
  245. package/coverage/src/device/fan.ts.html +0 -2242
  246. package/coverage/src/device/hub.ts.html +0 -1408
  247. package/coverage/src/device/humidifier.ts.html +0 -2116
  248. package/coverage/src/device/index.html +0 -416
  249. package/coverage/src/device/iosensor.ts.html +0 -1375
  250. package/coverage/src/device/lightstrip.ts.html +0 -2617
  251. package/coverage/src/device/lock.ts.html +0 -1963
  252. package/coverage/src/device/meter.ts.html +0 -1372
  253. package/coverage/src/device/meterplus.ts.html +0 -1384
  254. package/coverage/src/device/meterpro.ts.html +0 -1618
  255. package/coverage/src/device/motion.ts.html +0 -1264
  256. package/coverage/src/device/plug.ts.html +0 -1372
  257. package/coverage/src/device/relayswitch.ts.html +0 -2284
  258. package/coverage/src/device/robotvacuumcleaner.ts.html +0 -1810
  259. package/coverage/src/device/waterdetector.ts.html +0 -1294
  260. package/coverage/src/homebridge-ui/index.html +0 -116
  261. package/coverage/src/homebridge-ui/server.ts.html +0 -229
  262. package/coverage/src/index.html +0 -161
  263. package/coverage/src/index.ts.html +0 -124
  264. package/coverage/src/irdevice/airconditioner.ts.html +0 -1687
  265. package/coverage/src/irdevice/airpurifier.ts.html +0 -844
  266. package/coverage/src/irdevice/camera.ts.html +0 -475
  267. package/coverage/src/irdevice/fan.ts.html +0 -766
  268. package/coverage/src/irdevice/index.html +0 -251
  269. package/coverage/src/irdevice/irdevice.ts.html +0 -1117
  270. package/coverage/src/irdevice/light.ts.html +0 -826
  271. package/coverage/src/irdevice/other.ts.html +0 -2458
  272. package/coverage/src/irdevice/tv.ts.html +0 -1222
  273. package/coverage/src/irdevice/vacuumcleaner.ts.html +0 -466
  274. package/coverage/src/irdevice/waterheater.ts.html +0 -469
  275. package/coverage/src/platform.ts.html +0 -8776
  276. package/coverage/src/settings.ts.html +0 -934
  277. package/coverage/src/utils.ts.html +0 -2092
  278. package/dist/devices-hap/airpurifier.d.ts +0 -54
  279. package/dist/devices-hap/airpurifier.d.ts.map +0 -1
  280. package/dist/devices-hap/airpurifier.js +0 -527
  281. package/dist/devices-hap/airpurifier.js.map +0 -1
  282. package/dist/devices-hap/blindtilt.d.ts +0 -90
  283. package/dist/devices-hap/blindtilt.d.ts.map +0 -1
  284. package/dist/devices-hap/blindtilt.js +0 -974
  285. package/dist/devices-hap/blindtilt.js.map +0 -1
  286. package/dist/devices-hap/bot.d.ts +0 -102
  287. package/dist/devices-hap/bot.d.ts.map +0 -1
  288. package/dist/devices-hap/bot.js +0 -811
  289. package/dist/devices-hap/bot.js.map +0 -1
  290. package/dist/devices-hap/ceilinglight.d.ts +0 -85
  291. package/dist/devices-hap/ceilinglight.d.ts.map +0 -1
  292. package/dist/devices-hap/ceilinglight.js +0 -701
  293. package/dist/devices-hap/ceilinglight.js.map +0 -1
  294. package/dist/devices-hap/colorbulb.d.ts +0 -88
  295. package/dist/devices-hap/colorbulb.d.ts.map +0 -1
  296. package/dist/devices-hap/colorbulb.js +0 -881
  297. package/dist/devices-hap/colorbulb.js.map +0 -1
  298. package/dist/devices-hap/contact.d.ts +0 -44
  299. package/dist/devices-hap/contact.d.ts.map +0 -1
  300. package/dist/devices-hap/contact.js +0 -409
  301. package/dist/devices-hap/contact.js.map +0 -1
  302. package/dist/devices-hap/curtain.d.ts +0 -73
  303. package/dist/devices-hap/curtain.d.ts.map +0 -1
  304. package/dist/devices-hap/curtain.js +0 -869
  305. package/dist/devices-hap/curtain.js.map +0 -1
  306. package/dist/devices-hap/device.d.ts +0 -98
  307. package/dist/devices-hap/device.d.ts.map +0 -1
  308. package/dist/devices-hap/device.js +0 -749
  309. package/dist/devices-hap/device.js.map +0 -1
  310. package/dist/devices-hap/fan.d.ts +0 -69
  311. package/dist/devices-hap/fan.d.ts.map +0 -1
  312. package/dist/devices-hap/fan.js +0 -649
  313. package/dist/devices-hap/fan.js.map +0 -1
  314. package/dist/devices-hap/hub.d.ts +0 -37
  315. package/dist/devices-hap/hub.d.ts.map +0 -1
  316. package/dist/devices-hap/hub.js +0 -392
  317. package/dist/devices-hap/hub.js.map +0 -1
  318. package/dist/devices-hap/humidifier.d.ts +0 -68
  319. package/dist/devices-hap/humidifier.d.ts.map +0 -1
  320. package/dist/devices-hap/humidifier.js +0 -628
  321. package/dist/devices-hap/humidifier.js.map +0 -1
  322. package/dist/devices-hap/iosensor.d.ts +0 -42
  323. package/dist/devices-hap/iosensor.d.ts.map +0 -1
  324. package/dist/devices-hap/iosensor.js +0 -382
  325. package/dist/devices-hap/iosensor.js.map +0 -1
  326. package/dist/devices-hap/lightstrip.d.ts +0 -79
  327. package/dist/devices-hap/lightstrip.d.ts.map +0 -1
  328. package/dist/devices-hap/lightstrip.js +0 -797
  329. package/dist/devices-hap/lightstrip.js.map +0 -1
  330. package/dist/devices-hap/lock.d.ts +0 -53
  331. package/dist/devices-hap/lock.d.ts.map +0 -1
  332. package/dist/devices-hap/lock.js +0 -561
  333. package/dist/devices-hap/lock.js.map +0 -1
  334. package/dist/devices-hap/meter.d.ts +0 -37
  335. package/dist/devices-hap/meter.d.ts.map +0 -1
  336. package/dist/devices-hap/meter.js +0 -379
  337. package/dist/devices-hap/meter.js.map +0 -1
  338. package/dist/devices-hap/meterplus.d.ts +0 -42
  339. package/dist/devices-hap/meterplus.d.ts.map +0 -1
  340. package/dist/devices-hap/meterplus.js +0 -384
  341. package/dist/devices-hap/meterplus.js.map +0 -1
  342. package/dist/devices-hap/meterpro.d.ts +0 -43
  343. package/dist/devices-hap/meterpro.d.ts.map +0 -1
  344. package/dist/devices-hap/meterpro.js +0 -468
  345. package/dist/devices-hap/meterpro.js.map +0 -1
  346. package/dist/devices-hap/motion.d.ts +0 -42
  347. package/dist/devices-hap/motion.d.ts.map +0 -1
  348. package/dist/devices-hap/motion.js +0 -345
  349. package/dist/devices-hap/motion.js.map +0 -1
  350. package/dist/devices-hap/plug.d.ts +0 -49
  351. package/dist/devices-hap/plug.d.ts.map +0 -1
  352. package/dist/devices-hap/plug.js +0 -395
  353. package/dist/devices-hap/plug.js.map +0 -1
  354. package/dist/devices-hap/relayswitch.d.ts +0 -96
  355. package/dist/devices-hap/relayswitch.d.ts.map +0 -1
  356. package/dist/devices-hap/relayswitch.js +0 -642
  357. package/dist/devices-hap/relayswitch.js.map +0 -1
  358. package/dist/devices-hap/robotvacuumcleaner.d.ts +0 -54
  359. package/dist/devices-hap/robotvacuumcleaner.d.ts.map +0 -1
  360. package/dist/devices-hap/robotvacuumcleaner.js +0 -523
  361. package/dist/devices-hap/robotvacuumcleaner.js.map +0 -1
  362. package/dist/devices-hap/waterdetector.d.ts +0 -41
  363. package/dist/devices-hap/waterdetector.d.ts.map +0 -1
  364. package/dist/devices-hap/waterdetector.js +0 -356
  365. package/dist/devices-hap/waterdetector.js.map +0 -1
  366. package/dist/devices-matter/BaseMatterAccessory.d.ts +0 -63
  367. package/dist/devices-matter/BaseMatterAccessory.d.ts.map +0 -1
  368. package/dist/devices-matter/BaseMatterAccessory.js +0 -100
  369. package/dist/devices-matter/BaseMatterAccessory.js.map +0 -1
  370. package/dist/devices-matter/ColorLightAccessory.d.ts +0 -20
  371. package/dist/devices-matter/ColorLightAccessory.d.ts.map +0 -1
  372. package/dist/devices-matter/ColorLightAccessory.js +0 -95
  373. package/dist/devices-matter/ColorLightAccessory.js.map +0 -1
  374. package/dist/devices-matter/ColorTemperatureLightAccessory.d.ts +0 -18
  375. package/dist/devices-matter/ColorTemperatureLightAccessory.d.ts.map +0 -1
  376. package/dist/devices-matter/ColorTemperatureLightAccessory.js +0 -78
  377. package/dist/devices-matter/ColorTemperatureLightAccessory.js.map +0 -1
  378. package/dist/devices-matter/ContactSensorAccessory.d.ts +0 -12
  379. package/dist/devices-matter/ContactSensorAccessory.d.ts.map +0 -1
  380. package/dist/devices-matter/ContactSensorAccessory.js +0 -34
  381. package/dist/devices-matter/ContactSensorAccessory.js.map +0 -1
  382. package/dist/devices-matter/DimmableLightAccessory.d.ts +0 -58
  383. package/dist/devices-matter/DimmableLightAccessory.d.ts.map +0 -1
  384. package/dist/devices-matter/DimmableLightAccessory.js +0 -167
  385. package/dist/devices-matter/DimmableLightAccessory.js.map +0 -1
  386. package/dist/devices-matter/DoorLockAccessory.d.ts +0 -14
  387. package/dist/devices-matter/DoorLockAccessory.d.ts.map +0 -1
  388. package/dist/devices-matter/DoorLockAccessory.js +0 -50
  389. package/dist/devices-matter/DoorLockAccessory.js.map +0 -1
  390. package/dist/devices-matter/ExtendedColorLightAccessory.d.ts +0 -21
  391. package/dist/devices-matter/ExtendedColorLightAccessory.d.ts.map +0 -1
  392. package/dist/devices-matter/ExtendedColorLightAccessory.js +0 -107
  393. package/dist/devices-matter/ExtendedColorLightAccessory.js.map +0 -1
  394. package/dist/devices-matter/FanAccessory.d.ts +0 -16
  395. package/dist/devices-matter/FanAccessory.d.ts.map +0 -1
  396. package/dist/devices-matter/FanAccessory.js +0 -81
  397. package/dist/devices-matter/FanAccessory.js.map +0 -1
  398. package/dist/devices-matter/HumiditySensorAccessory.d.ts +0 -12
  399. package/dist/devices-matter/HumiditySensorAccessory.d.ts.map +0 -1
  400. package/dist/devices-matter/HumiditySensorAccessory.js +0 -34
  401. package/dist/devices-matter/HumiditySensorAccessory.js.map +0 -1
  402. package/dist/devices-matter/LeakSensorAccessory.d.ts +0 -12
  403. package/dist/devices-matter/LeakSensorAccessory.d.ts.map +0 -1
  404. package/dist/devices-matter/LeakSensorAccessory.js +0 -33
  405. package/dist/devices-matter/LeakSensorAccessory.js.map +0 -1
  406. package/dist/devices-matter/LightSensorAccessory.d.ts +0 -12
  407. package/dist/devices-matter/LightSensorAccessory.d.ts.map +0 -1
  408. package/dist/devices-matter/LightSensorAccessory.js +0 -34
  409. package/dist/devices-matter/LightSensorAccessory.js.map +0 -1
  410. package/dist/devices-matter/OccupancySensorAccessory.d.ts +0 -12
  411. package/dist/devices-matter/OccupancySensorAccessory.d.ts.map +0 -1
  412. package/dist/devices-matter/OccupancySensorAccessory.js +0 -39
  413. package/dist/devices-matter/OccupancySensorAccessory.js.map +0 -1
  414. package/dist/devices-matter/OnOffLightAccessory.d.ts +0 -38
  415. package/dist/devices-matter/OnOffLightAccessory.d.ts.map +0 -1
  416. package/dist/devices-matter/OnOffLightAccessory.js +0 -118
  417. package/dist/devices-matter/OnOffLightAccessory.js.map +0 -1
  418. package/dist/devices-matter/OnOffOutletAccessory.d.ts +0 -12
  419. package/dist/devices-matter/OnOffOutletAccessory.d.ts.map +0 -1
  420. package/dist/devices-matter/OnOffOutletAccessory.js +0 -40
  421. package/dist/devices-matter/OnOffOutletAccessory.js.map +0 -1
  422. package/dist/devices-matter/OnOffSwitchAccessory.d.ts +0 -14
  423. package/dist/devices-matter/OnOffSwitchAccessory.d.ts.map +0 -1
  424. package/dist/devices-matter/OnOffSwitchAccessory.js +0 -42
  425. package/dist/devices-matter/OnOffSwitchAccessory.js.map +0 -1
  426. package/dist/devices-matter/RoboticVacuumAccessory.d.ts +0 -68
  427. package/dist/devices-matter/RoboticVacuumAccessory.d.ts.map +0 -1
  428. package/dist/devices-matter/RoboticVacuumAccessory.js +0 -334
  429. package/dist/devices-matter/RoboticVacuumAccessory.js.map +0 -1
  430. package/dist/devices-matter/SmokeCOAlarmAccessory.d.ts +0 -11
  431. package/dist/devices-matter/SmokeCOAlarmAccessory.d.ts.map +0 -1
  432. package/dist/devices-matter/SmokeCOAlarmAccessory.js +0 -49
  433. package/dist/devices-matter/SmokeCOAlarmAccessory.js.map +0 -1
  434. package/dist/devices-matter/TemperatureSensorAccessory.d.ts +0 -12
  435. package/dist/devices-matter/TemperatureSensorAccessory.d.ts.map +0 -1
  436. package/dist/devices-matter/TemperatureSensorAccessory.js +0 -36
  437. package/dist/devices-matter/TemperatureSensorAccessory.js.map +0 -1
  438. package/dist/devices-matter/ThermostatAccessory.d.ts +0 -19
  439. package/dist/devices-matter/ThermostatAccessory.d.ts.map +0 -1
  440. package/dist/devices-matter/ThermostatAccessory.js +0 -95
  441. package/dist/devices-matter/ThermostatAccessory.js.map +0 -1
  442. package/dist/devices-matter/VenetianBlindAccessory.d.ts +0 -19
  443. package/dist/devices-matter/VenetianBlindAccessory.d.ts.map +0 -1
  444. package/dist/devices-matter/VenetianBlindAccessory.js +0 -99
  445. package/dist/devices-matter/VenetianBlindAccessory.js.map +0 -1
  446. package/dist/devices-matter/WindowBlindAccessory.d.ts +0 -17
  447. package/dist/devices-matter/WindowBlindAccessory.d.ts.map +0 -1
  448. package/dist/devices-matter/WindowBlindAccessory.js +0 -80
  449. package/dist/devices-matter/WindowBlindAccessory.js.map +0 -1
  450. package/dist/devices-matter/custom/PowerStripAccessory.d.ts +0 -97
  451. package/dist/devices-matter/custom/PowerStripAccessory.d.ts.map +0 -1
  452. package/dist/devices-matter/custom/PowerStripAccessory.js +0 -265
  453. package/dist/devices-matter/custom/PowerStripAccessory.js.map +0 -1
  454. package/dist/devices-matter/custom/index.d.ts +0 -8
  455. package/dist/devices-matter/custom/index.d.ts.map +0 -1
  456. package/dist/devices-matter/custom/index.js +0 -8
  457. package/dist/devices-matter/custom/index.js.map +0 -1
  458. package/dist/devices-matter/index.d.ts +0 -29
  459. package/dist/devices-matter/index.d.ts.map +0 -1
  460. package/dist/devices-matter/index.js +0 -28
  461. package/dist/devices-matter/index.js.map +0 -1
  462. package/dist/index.test.d.ts +0 -2
  463. package/dist/index.test.d.ts.map +0 -1
  464. package/dist/index.test.js +0 -19
  465. package/dist/index.test.js.map +0 -1
  466. package/dist/irdevice/airconditioner.d.ts +0 -61
  467. package/dist/irdevice/airconditioner.d.ts.map +0 -1
  468. package/dist/irdevice/airconditioner.js +0 -472
  469. package/dist/irdevice/airconditioner.js.map +0 -1
  470. package/dist/irdevice/airpurifier.d.ts +0 -50
  471. package/dist/irdevice/airpurifier.d.ts.map +0 -1
  472. package/dist/irdevice/airpurifier.js +0 -213
  473. package/dist/irdevice/airpurifier.js.map +0 -1
  474. package/dist/irdevice/camera.d.ts +0 -32
  475. package/dist/irdevice/camera.d.ts.map +0 -1
  476. package/dist/irdevice/camera.js +0 -107
  477. package/dist/irdevice/camera.js.map +0 -1
  478. package/dist/irdevice/fan.d.ts +0 -36
  479. package/dist/irdevice/fan.d.ts.map +0 -1
  480. package/dist/irdevice/fan.js +0 -200
  481. package/dist/irdevice/fan.js.map +0 -1
  482. package/dist/irdevice/irdevice.d.ts +0 -68
  483. package/dist/irdevice/irdevice.d.ts.map +0 -1
  484. package/dist/irdevice/irdevice.js +0 -298
  485. package/dist/irdevice/irdevice.js.map +0 -1
  486. package/dist/irdevice/light.d.ts +0 -36
  487. package/dist/irdevice/light.d.ts.map +0 -1
  488. package/dist/irdevice/light.js +0 -206
  489. package/dist/irdevice/light.js.map +0 -1
  490. package/dist/irdevice/other.d.ts +0 -57
  491. package/dist/irdevice/other.d.ts.map +0 -1
  492. package/dist/irdevice/other.js +0 -778
  493. package/dist/irdevice/other.js.map +0 -1
  494. package/dist/irdevice/tv.d.ts +0 -45
  495. package/dist/irdevice/tv.d.ts.map +0 -1
  496. package/dist/irdevice/tv.js +0 -327
  497. package/dist/irdevice/tv.js.map +0 -1
  498. package/dist/irdevice/vacuumcleaner.d.ts +0 -28
  499. package/dist/irdevice/vacuumcleaner.d.ts.map +0 -1
  500. package/dist/irdevice/vacuumcleaner.js +0 -104
  501. package/dist/irdevice/vacuumcleaner.js.map +0 -1
  502. package/dist/irdevice/waterheater.d.ts +0 -30
  503. package/dist/irdevice/waterheater.d.ts.map +0 -1
  504. package/dist/irdevice/waterheater.js +0 -105
  505. package/dist/irdevice/waterheater.js.map +0 -1
  506. package/dist/platform-hap.d.ts +0 -149
  507. package/dist/platform-hap.d.ts.map +0 -1
  508. package/dist/platform-hap.js +0 -2861
  509. package/dist/platform-hap.js.map +0 -1
  510. package/dist/platform-matter.d.ts +0 -120
  511. package/dist/platform-matter.d.ts.map +0 -1
  512. package/dist/platform-matter.js +0 -984
  513. package/dist/platform-matter.js.map +0 -1
  514. package/dist/verifyconfig.test.d.ts +0 -2
  515. package/dist/verifyconfig.test.d.ts.map +0 -1
  516. package/dist/verifyconfig.test.js +0 -167
  517. package/dist/verifyconfig.test.js.map +0 -1
  518. package/src/custom.d.ts +0 -7
  519. package/src/devices-hap/airpurifier.ts +0 -563
  520. package/src/devices-hap/blindtilt.ts +0 -1049
  521. package/src/devices-hap/bot.ts +0 -900
  522. package/src/devices-hap/ceilinglight.ts +0 -742
  523. package/src/devices-hap/colorbulb.ts +0 -904
  524. package/src/devices-hap/contact.ts +0 -457
  525. package/src/devices-hap/curtain.ts +0 -944
  526. package/src/devices-hap/device.ts +0 -811
  527. package/src/devices-hap/fan.ts +0 -711
  528. package/src/devices-hap/hub.ts +0 -439
  529. package/src/devices-hap/humidifier.ts +0 -669
  530. package/src/devices-hap/iosensor.ts +0 -427
  531. package/src/devices-hap/lightstrip.ts +0 -836
  532. package/src/devices-hap/lock.ts +0 -620
  533. package/src/devices-hap/meter.ts +0 -426
  534. package/src/devices-hap/meterplus.ts +0 -430
  535. package/src/devices-hap/meterpro.ts +0 -522
  536. package/src/devices-hap/motion.ts +0 -390
  537. package/src/devices-hap/plug.ts +0 -423
  538. package/src/devices-hap/relayswitch.ts +0 -727
  539. package/src/devices-hap/robotvacuumcleaner.ts +0 -568
  540. package/src/devices-hap/waterdetector.ts +0 -400
  541. package/src/devices-matter/BaseMatterAccessory.ts +0 -131
  542. package/src/devices-matter/ColorLightAccessory.ts +0 -110
  543. package/src/devices-matter/ColorTemperatureLightAccessory.ts +0 -92
  544. package/src/devices-matter/ContactSensorAccessory.ts +0 -41
  545. package/src/devices-matter/DimmableLightAccessory.ts +0 -192
  546. package/src/devices-matter/DoorLockAccessory.ts +0 -60
  547. package/src/devices-matter/ExtendedColorLightAccessory.ts +0 -123
  548. package/src/devices-matter/FanAccessory.ts +0 -95
  549. package/src/devices-matter/HumiditySensorAccessory.ts +0 -41
  550. package/src/devices-matter/LeakSensorAccessory.ts +0 -40
  551. package/src/devices-matter/LightSensorAccessory.ts +0 -41
  552. package/src/devices-matter/OccupancySensorAccessory.ts +0 -48
  553. package/src/devices-matter/OnOffLightAccessory.ts +0 -133
  554. package/src/devices-matter/OnOffOutletAccessory.ts +0 -46
  555. package/src/devices-matter/OnOffSwitchAccessory.ts +0 -51
  556. package/src/devices-matter/RoboticVacuumAccessory.ts +0 -407
  557. package/src/devices-matter/SmokeCOAlarmAccessory.ts +0 -59
  558. package/src/devices-matter/TemperatureSensorAccessory.ts +0 -43
  559. package/src/devices-matter/ThermostatAccessory.ts +0 -110
  560. package/src/devices-matter/VenetianBlindAccessory.ts +0 -115
  561. package/src/devices-matter/WindowBlindAccessory.ts +0 -92
  562. package/src/devices-matter/custom/PowerStripAccessory.ts +0 -309
  563. package/src/devices-matter/custom/index.ts +0 -8
  564. package/src/devices-matter/index.ts +0 -29
  565. package/src/index.test.ts +0 -24
  566. package/src/irdevice/airconditioner.ts +0 -533
  567. package/src/irdevice/airpurifier.ts +0 -252
  568. package/src/irdevice/camera.ts +0 -129
  569. package/src/irdevice/fan.ts +0 -226
  570. package/src/irdevice/irdevice.ts +0 -344
  571. package/src/irdevice/light.ts +0 -246
  572. package/src/irdevice/other.ts +0 -790
  573. package/src/irdevice/tv.ts +0 -378
  574. package/src/irdevice/vacuumcleaner.ts +0 -126
  575. package/src/irdevice/waterheater.ts +0 -127
  576. package/src/platform-hap.ts +0 -2997
  577. package/src/platform-matter.ts +0 -1110
  578. package/src/verifyconfig.test.ts +0 -197
@@ -0,0 +1,1527 @@
1
+ import { createDevice } from './deviceFactory.js';
2
+ import { PLATFORM_NAME, PLUGIN_NAME } from './settings.js';
3
+ import { SwitchBotClient } from './switchbotClient.js';
4
+ // Which device types should prefer Matter if available
5
+ // Based on HAP service mappings: device implementations use specific HomeKit services
6
+ // that map to corresponding Matter clusters when Matter is enabled
7
+ const DEVICE_MATTER_SUPPORTED = {
8
+ // Core devices
9
+ 'bot': true, // Switch → OnOff
10
+ 'curtain': true, // WindowCovering → WindowCovering
11
+ 'fan': true, // Fan → FanControl
12
+ 'light': true, // Lightbulb → OnOff + LevelControl
13
+ 'lightstrip': true, // Lightbulb (color) → OnOff + LevelControl + ColorControl
14
+ 'motion': true, // MotionSensor → OccupancySensing
15
+ 'contact': true, // ContactSensor → BooleanState
16
+ 'vacuum': true, // Switch → RobotVacuumCleaner
17
+ 'lock': true, // LockMechanism → DoorLock
18
+ 'humidifier': true, // Fan + Humidity → OnOff + FanControl + RelativeHumidityMeasurement
19
+ 'temperature': true, // TemperatureSensor → TemperatureMeasurement
20
+ // Switch devices
21
+ 'relay': true, // Switch → OnOff
22
+ 'relay switch 1': true, // Switch → OnOff
23
+ 'relay switch 1pm': true, // Switch → OnOff
24
+ 'plug': true, // Outlet → OnOff
25
+ 'plug mini (jp)': true, // Outlet → OnOff
26
+ 'plug mini (us)': true, // Outlet → OnOff
27
+ // Window covering variants
28
+ 'blindtilt': true, // WindowCovering → WindowCovering
29
+ 'blind tilt': true, // WindowCovering → WindowCovering
30
+ 'curtain3': true, // WindowCovering → WindowCovering
31
+ 'rollershade': true, // WindowCovering → WindowCovering
32
+ 'roller shade': true, // WindowCovering → WindowCovering
33
+ 'worollershade': true, // WindowCovering → WindowCovering
34
+ 'wo rollershade': true, // WindowCovering → WindowCovering
35
+ // Vacuum variants (normalized to 'vacuum' before lookup)
36
+ 'wosweeper': true, // VacuumDevice → RobotVacuumCleaner
37
+ 'wosweepermini': true, // VacuumDevice → RobotVacuumCleaner
38
+ 'wosweeperminipro': true, // VacuumDevice → RobotVacuumCleaner
39
+ 'k10+': true, // VacuumDevice → RobotVacuumCleaner
40
+ 'k10+ pro': true, // VacuumDevice → RobotVacuumCleaner
41
+ // Sensors
42
+ 'meter': true, // TemperatureSensor + HumiditySensor → TemperatureMeasurement + RelativeHumidityMeasurement
43
+ 'meterplus': true, // TemperatureSensor + HumiditySensor → TemperatureMeasurement + RelativeHumidityMeasurement
44
+ 'meter plus (jp)': true, // TemperatureSensor + HumiditySensor → TemperatureMeasurement + RelativeHumidityMeasurement
45
+ 'meterpro': true, // TemperatureSensor + HumiditySensor → TemperatureMeasurement + RelativeHumidityMeasurement
46
+ 'meterpro(co2)': true, // TemperatureSensor + HumiditySensor → TemperatureMeasurement + RelativeHumidityMeasurement
47
+ 'waterdetector': true, // LeakSensor → BooleanState
48
+ 'water detector': true, // LeakSensor → BooleanState
49
+ // Other devices
50
+ 'smart fan': true, // Fan → FanControl
51
+ 'strip light': true, // Lightbulb (color) → OnOff + LevelControl + ColorControl
52
+ 'hub 2': false, // Hub device - not exposed as accessory
53
+ 'walletfinder': false, // Button device - Matter support TBD
54
+ };
55
+ // Default Matter cluster configurations by device type
56
+ // Maps device types to their Matter cluster states (used when device doesn't provide clusters)
57
+ // Note: wosweeper/curtain/plug variants are normalized before cluster lookup (see loadDevices)
58
+ const DEVICE_MATTER_CLUSTERS = {
59
+ // Core devices - aligned with HAP service implementations
60
+ bot: { onOff: { onOff: false } }, // Switch → OnOff
61
+ vacuum: {
62
+ rvcRunMode: {
63
+ supportedModes: [
64
+ { label: 'Idle', mode: 0, modeTags: [{ value: 16384 }] },
65
+ { label: 'Cleaning', mode: 1, modeTags: [{ value: 16385 }] },
66
+ ],
67
+ currentMode: 0,
68
+ },
69
+ rvcCleanMode: {
70
+ supportedModes: [
71
+ { label: 'Vacuum', mode: 0, modeTags: [{ value: 16385 }] },
72
+ ],
73
+ currentMode: 0,
74
+ },
75
+ rvcOperationalState: {
76
+ operationalStateList: [
77
+ { operationalStateId: 0 }, // Stopped
78
+ { operationalStateId: 1 }, // Running
79
+ { operationalStateId: 2 }, // Paused
80
+ { operationalStateId: 3 }, // Error (required)
81
+ { operationalStateId: 64 }, // Seeking charger
82
+ { operationalStateId: 65 }, // Charging
83
+ { operationalStateId: 66 }, // Docked
84
+ ],
85
+ operationalState: 66,
86
+ },
87
+ }, // Switch in HAP, RobotVacuumCleaner in Matter
88
+ curtain: {
89
+ windowCovering: {
90
+ // Use a lift-only/non-tilt covering type to satisfy Matter conformance rules.
91
+ // Drapery (4) can fail validation in some stacks when TL (tilt) is not present.
92
+ type: 0, // Rollershade
93
+ },
94
+ }, // WindowCovering → WindowCovering (includes curtain3, rollershade variants via normalization)
95
+ blindtilt: {
96
+ windowCovering: {
97
+ type: 8, // TiltBlindLiftAndTilt - supports tilt feature
98
+ },
99
+ }, // WindowCovering with tilt → WindowCovering
100
+ fan: {
101
+ onOff: { onOff: false },
102
+ fanControl: {
103
+ fanMode: 0,
104
+ percentCurrent: 0,
105
+ percentSetting: 0,
106
+ speedCurrent: 0,
107
+ speedMax: 100,
108
+ },
109
+ }, // Fan → OnOff + FanControl
110
+ light: {
111
+ onOff: { onOff: false },
112
+ levelControl: {
113
+ currentLevel: 0,
114
+ minLevel: 0,
115
+ maxLevel: 254,
116
+ },
117
+ }, // Lightbulb → OnOff + LevelControl
118
+ lightstrip: {
119
+ onOff: { onOff: false },
120
+ levelControl: {
121
+ currentLevel: 0,
122
+ minLevel: 0,
123
+ maxLevel: 254,
124
+ },
125
+ colorControl: {
126
+ currentHue: 0,
127
+ currentSaturation: 0,
128
+ colorTemperatureMireds: 400,
129
+ colorMode: 0,
130
+ },
131
+ }, // Lightbulb with color → OnOff + LevelControl + ColorControl
132
+ lock: {
133
+ doorLock: {
134
+ lockState: 0,
135
+ lockType: 0,
136
+ actuatorEnabled: true,
137
+ operatingMode: 0,
138
+ },
139
+ }, // LockMechanism → DoorLock
140
+ motion: {
141
+ occupancySensing: {
142
+ occupancy: 0,
143
+ occupancySensorType: 0,
144
+ },
145
+ }, // MotionSensor → OccupancySensing
146
+ contact: {
147
+ booleanState: {
148
+ stateValue: false,
149
+ },
150
+ }, // ContactSensor → BooleanState
151
+ humidifier: {
152
+ onOff: { onOff: false },
153
+ fanControl: {
154
+ fanMode: 0,
155
+ percentCurrent: 0,
156
+ },
157
+ relativeHumidityMeasurement: {
158
+ measuredValue: 0,
159
+ minMeasuredValue: 0,
160
+ maxMeasuredValue: 100,
161
+ },
162
+ }, // HumidifierDehumidifier → OnOff + FanControl + RelativeHumidityMeasurement
163
+ temperature: {
164
+ temperatureMeasurement: {
165
+ measuredValue: 0,
166
+ minMeasuredValue: -27315,
167
+ maxMeasuredValue: 32767,
168
+ },
169
+ }, // TemperatureSensor → TemperatureMeasurement
170
+ // Switch/Outlet devices
171
+ relay: { onOff: { onOff: false } }, // Switch → OnOff
172
+ plug: {
173
+ onOff: { onOff: false },
174
+ electricalMeasurement: {
175
+ activePower: 0,
176
+ rmsCurrent: 0,
177
+ rmsVoltage: 0,
178
+ },
179
+ }, // Outlet → OnOff + ElectricalMeasurement (for PM models)
180
+ // Sensors
181
+ meter: {
182
+ temperatureMeasurement: {
183
+ measuredValue: 0,
184
+ minMeasuredValue: -27315,
185
+ maxMeasuredValue: 32767,
186
+ },
187
+ relativeHumidityMeasurement: {
188
+ measuredValue: 0,
189
+ minMeasuredValue: 0,
190
+ maxMeasuredValue: 100,
191
+ },
192
+ }, // TemperatureSensor + HumiditySensor → TemperatureMeasurement + RelativeHumidityMeasurement
193
+ waterdetector: {
194
+ booleanState: {
195
+ stateValue: false,
196
+ },
197
+ }, // LeakSensor → BooleanState
198
+ };
199
+ const DEVICE_MATTER_DEVICE_TYPE_KEYS = {
200
+ bot: 'OnOffSwitch',
201
+ vacuum: 'RoboticVacuumCleaner',
202
+ curtain: 'WindowCovering',
203
+ blindtilt: 'WindowCovering',
204
+ fan: 'Fan',
205
+ light: 'DimmableLight',
206
+ lightstrip: 'ExtendedColorLight',
207
+ lock: 'DoorLock',
208
+ motion: 'MotionSensor',
209
+ contact: 'ContactSensor',
210
+ humidifier: 'Fan',
211
+ temperature: 'TemperatureSensor',
212
+ relay: 'OnOffSwitch',
213
+ plug: 'OnOffOutlet',
214
+ meter: 'TemperatureSensor',
215
+ waterdetector: 'LeakSensor',
216
+ };
217
+ function normalizeTypeForMatter(typeValue) {
218
+ const raw = String(typeValue || '').trim().toLowerCase();
219
+ if (!raw) {
220
+ return 'unknown';
221
+ }
222
+ // Vacuum variants
223
+ if (['wosweeper', 'wosweepermini', 'wosweeperminipro', 'k10+', 'k10+ pro'].includes(raw)) {
224
+ return 'vacuum';
225
+ }
226
+ // Window covering variants
227
+ if (['blindtilt', 'blind tilt', 'curtain3', 'rollershade', 'roller shade', 'worollershade', 'wo rollershade'].includes(raw)) {
228
+ return 'curtain';
229
+ }
230
+ // Plug variants
231
+ if (['plug mini (jp)', 'plug mini (us)', 'plug mini (eu)'].includes(raw)) {
232
+ return 'plug';
233
+ }
234
+ // Meter variants
235
+ if (['meterplus', 'meter plus', 'meter plus (jp)', 'meterpro', 'meter pro', 'meterpro(co2)', 'meter pro (co2)'].includes(raw)) {
236
+ return 'meter';
237
+ }
238
+ // Relay switch variants
239
+ if (['relay switch 1', 'relay switch 1pm'].includes(raw)) {
240
+ return 'relay';
241
+ }
242
+ // Water detector variants
243
+ if (['water detector', 'waterdetector'].includes(raw)) {
244
+ return 'waterdetector';
245
+ }
246
+ // Fan variants
247
+ if (['smart fan', 'circulator fan', 'battery circulator fan', 'standing circulator fan'].includes(raw)) {
248
+ return 'fan';
249
+ }
250
+ // Light variants
251
+ if (['strip light', 'strip light 3', 'rgbic neon rope light', 'rgbic neon wire rope light', 'rgbicww floor lamp', 'rgbicww strip light'].includes(raw)) {
252
+ return 'lightstrip';
253
+ }
254
+ if (['color bulb', 'ceiling light', 'ceiling light pro', 'candle warmer lamp', 'floor lamp'].includes(raw)) {
255
+ return 'light';
256
+ }
257
+ // Sensor variants
258
+ if (raw === 'motion sensor') {
259
+ return 'motion';
260
+ }
261
+ if (['contact sensor', 'presence sensor'].includes(raw)) {
262
+ return 'contact';
263
+ }
264
+ // Lock variants
265
+ if (['smart lock', 'smart lock pro', 'smart lock ultra', 'lock lite', 'keypad', 'keypad touch', 'keypad vision', 'keypad vision pro', 'lock vision pro'].includes(raw)) {
266
+ return 'lock';
267
+ }
268
+ // Climate variant
269
+ if (raw === 'humidifier2') {
270
+ return 'humidifier';
271
+ }
272
+ return raw;
273
+ }
274
+ // Factory function to create Matter handlers with Homebridge logger integration
275
+ function createMatterHandlers(log, deviceId, type, client) {
276
+ const lowerType = type.toLowerCase();
277
+ switch (lowerType) {
278
+ case 'vacuum':
279
+ return {
280
+ rvcRunMode: {
281
+ changeToMode: async (request) => {
282
+ const modeNames = ['Idle', 'Cleaning', 'Mapping'];
283
+ const modeName = modeNames[request?.newMode] || `Unknown (${request?.newMode})`;
284
+ log.info(`[${deviceId}] RVC run mode change requested: ${modeName}`);
285
+ if (!client) {
286
+ log.warn(`[${deviceId}] No SwitchBot client available`);
287
+ return { success: false };
288
+ }
289
+ try {
290
+ // For K10+ family: use 'start' to begin cleaning (mode 1 = Cleaning)
291
+ // For older K10+: only supports start/stop/dock
292
+ // For newer K20+/S10/S20: supports startClean with more parameters
293
+ // Map Matter mode to SwitchBot command
294
+ const switchBotCommand = request?.newMode === 1 ? 'start' : 'stop';
295
+ const body = {
296
+ command: switchBotCommand,
297
+ parameter: 'default',
298
+ commandType: 'command',
299
+ };
300
+ log.debug(`[${deviceId}] Sending RVC mode change request:`, JSON.stringify(body));
301
+ const result = await client.setDeviceState(deviceId, body);
302
+ log.debug(`[${deviceId}] RVC mode change API response:`, JSON.stringify(result));
303
+ log.info(`[${deviceId}] RVC mode changed successfully to ${switchBotCommand}`);
304
+ return { success: true, result };
305
+ }
306
+ catch (e) {
307
+ log.error(`[${deviceId}] Failed to change RVC mode:`, e);
308
+ return { success: false, error: e };
309
+ }
310
+ },
311
+ },
312
+ rvcCleanMode: {
313
+ changeToMode: async (request) => {
314
+ const modeName = request?.newMode !== undefined ? `Mode ${request.newMode}` : 'Unknown';
315
+ log.info(`[${deviceId}] RVC clean mode change requested: ${modeName}`);
316
+ if (!client) {
317
+ log.warn(`[${deviceId}] No SwitchBot client available`);
318
+ return { success: false };
319
+ }
320
+ try {
321
+ // Clean mode (vacuum/mop/etc) not directly supported via Matter for K10+
322
+ // K20+ Pro and newer models support via startClean action parameter
323
+ log.info(`[${deviceId}] Clean mode change requires startClean command (not yet implemented for Matter)`);
324
+ return { success: true };
325
+ }
326
+ catch (e) {
327
+ log.error(`[${deviceId}] Failed to change RVC clean mode:`, e);
328
+ return { success: false, error: e };
329
+ }
330
+ },
331
+ },
332
+ rvcOperationalState: {
333
+ pause: async () => {
334
+ log.info(`[${deviceId}] RVC pause command received`);
335
+ if (!client) {
336
+ log.warn(`[${deviceId}] No SwitchBot client available`);
337
+ return { success: false };
338
+ }
339
+ try {
340
+ const body = {
341
+ command: 'stop',
342
+ parameter: 'default',
343
+ commandType: 'command',
344
+ };
345
+ log.debug(`[${deviceId}] Sending RVC pause request:`, JSON.stringify(body));
346
+ const result = await client.setDeviceState(deviceId, body);
347
+ log.debug(`[${deviceId}] RVC pause API response:`, JSON.stringify(result));
348
+ log.info(`[${deviceId}] RVC paused successfully`);
349
+ return { success: true, result };
350
+ }
351
+ catch (e) {
352
+ log.error(`[${deviceId}] Failed to pause RVC:`, e);
353
+ return { success: false, error: e };
354
+ }
355
+ },
356
+ resume: async () => {
357
+ log.info(`[${deviceId}] RVC resume command received`);
358
+ if (!client) {
359
+ log.warn(`[${deviceId}] No SwitchBot client available`);
360
+ return { success: false };
361
+ }
362
+ try {
363
+ const body = {
364
+ command: 'start',
365
+ parameter: 'default',
366
+ commandType: 'command',
367
+ };
368
+ log.debug(`[${deviceId}] Sending RVC resume request:`, JSON.stringify(body));
369
+ const result = await client.setDeviceState(deviceId, body);
370
+ log.debug(`[${deviceId}] RVC resume API response:`, JSON.stringify(result));
371
+ log.info(`[${deviceId}] RVC resumed successfully`);
372
+ return { success: true, result };
373
+ }
374
+ catch (e) {
375
+ log.error(`[${deviceId}] Failed to resume RVC:`, e);
376
+ return { success: false, error: e };
377
+ }
378
+ },
379
+ goHome: async () => {
380
+ log.info(`[${deviceId}] RVC goHome command received`);
381
+ if (!client) {
382
+ log.warn(`[${deviceId}] No SwitchBot client available`);
383
+ return { success: false };
384
+ }
385
+ try {
386
+ const body = {
387
+ command: 'dock',
388
+ parameter: 'default',
389
+ commandType: 'command',
390
+ };
391
+ log.debug(`[${deviceId}] Sending RVC goHome request:`, JSON.stringify(body));
392
+ const result = await client.setDeviceState(deviceId, body);
393
+ log.debug(`[${deviceId}] RVC goHome API response:`, JSON.stringify(result));
394
+ log.info(`[${deviceId}] RVC sent to dock successfully`);
395
+ return { success: true, result };
396
+ }
397
+ catch (e) {
398
+ log.error(`[${deviceId}] Failed to send goHome command:`, e);
399
+ return { success: false, error: e };
400
+ }
401
+ },
402
+ },
403
+ };
404
+ case 'bot':
405
+ return {
406
+ onOff: {
407
+ on: async () => {
408
+ log.info(`[${deviceId}] Bot ON command received`);
409
+ if (!client) {
410
+ log.warn(`[${deviceId}] No SwitchBot client available`);
411
+ return { success: false };
412
+ }
413
+ try {
414
+ const result = await client.setDeviceState(deviceId, {
415
+ command: 'turnOn',
416
+ parameter: 'default',
417
+ commandType: 'command',
418
+ });
419
+ log.info(`[${deviceId}] Bot turned on successfully`);
420
+ return { success: true, result };
421
+ }
422
+ catch (e) {
423
+ log.error(`[${deviceId}] Failed to turn on Bot:`, e);
424
+ return { success: false, error: e };
425
+ }
426
+ },
427
+ off: async () => {
428
+ log.info(`[${deviceId}] Bot OFF command received`);
429
+ if (!client) {
430
+ log.warn(`[${deviceId}] No SwitchBot client available`);
431
+ return { success: false };
432
+ }
433
+ try {
434
+ const result = await client.setDeviceState(deviceId, {
435
+ command: 'turnOff',
436
+ parameter: 'default',
437
+ commandType: 'command',
438
+ });
439
+ log.info(`[${deviceId}] Bot turned off successfully`);
440
+ return { success: true, result };
441
+ }
442
+ catch (e) {
443
+ log.error(`[${deviceId}] Failed to turn off Bot:`, e);
444
+ return { success: false, error: e };
445
+ }
446
+ },
447
+ },
448
+ };
449
+ case 'curtain':
450
+ case 'blindtilt':
451
+ return {
452
+ windowCovering: {
453
+ goToLiftPercentage: async (request) => {
454
+ const percentage = request?.liftPercent100thsValue;
455
+ log.info(`[${deviceId}] Curtain position change requested: ${percentage}`);
456
+ if (!client) {
457
+ log.warn(`[${deviceId}] No SwitchBot client available`);
458
+ return { success: false };
459
+ }
460
+ try {
461
+ // Convert Matter percentage (0-10000) to SwitchBot (0-100)
462
+ const position = Math.max(0, Math.min(100, Math.round((percentage || 0) / 100)));
463
+ const result = await client.setDeviceState(deviceId, {
464
+ command: 'setPosition',
465
+ parameter: String(position),
466
+ commandType: 'command',
467
+ });
468
+ log.info(`[${deviceId}] Curtain position set to ${position}% successfully`);
469
+ return { success: true, result };
470
+ }
471
+ catch (e) {
472
+ log.error(`[${deviceId}] Failed to set curtain position:`, e);
473
+ return { success: false, error: e };
474
+ }
475
+ },
476
+ upOrOpen: async () => {
477
+ log.info(`[${deviceId}] Curtain open command received`);
478
+ if (!client) {
479
+ log.warn(`[${deviceId}] No SwitchBot client available`);
480
+ return { success: false };
481
+ }
482
+ try {
483
+ const result = await client.setDeviceState(deviceId, {
484
+ command: 'open',
485
+ parameter: 'default',
486
+ commandType: 'command',
487
+ });
488
+ log.info(`[${deviceId}] Curtain opened successfully`);
489
+ return { success: true, result };
490
+ }
491
+ catch (e) {
492
+ log.error(`[${deviceId}] Failed to open curtain:`, e);
493
+ return { success: false, error: e };
494
+ }
495
+ },
496
+ downOrClose: async () => {
497
+ log.info(`[${deviceId}] Curtain close command received`);
498
+ if (!client) {
499
+ log.warn(`[${deviceId}] No SwitchBot client available`);
500
+ return { success: false };
501
+ }
502
+ try {
503
+ const result = await client.setDeviceState(deviceId, {
504
+ command: 'close',
505
+ parameter: 'default',
506
+ commandType: 'command',
507
+ });
508
+ log.info(`[${deviceId}] Curtain closed successfully`);
509
+ return { success: true, result };
510
+ }
511
+ catch (e) {
512
+ log.error(`[${deviceId}] Failed to close curtain:`, e);
513
+ return { success: false, error: e };
514
+ }
515
+ },
516
+ stopMotion: async () => {
517
+ log.info(`[${deviceId}] Curtain stop command received`);
518
+ if (!client) {
519
+ log.warn(`[${deviceId}] No SwitchBot client available`);
520
+ return { success: false };
521
+ }
522
+ try {
523
+ const result = await client.setDeviceState(deviceId, {
524
+ command: 'pause',
525
+ parameter: 'default',
526
+ commandType: 'command',
527
+ });
528
+ log.info(`[${deviceId}] Curtain motion stopped successfully`);
529
+ return { success: true, result };
530
+ }
531
+ catch (e) {
532
+ log.error(`[${deviceId}] Failed to stop curtain:`, e);
533
+ return { success: false, error: e };
534
+ }
535
+ },
536
+ },
537
+ };
538
+ case 'plug':
539
+ return {
540
+ onOff: {
541
+ on: async () => {
542
+ log.info(`[${deviceId}] Plug ON command received`);
543
+ if (!client) {
544
+ log.warn(`[${deviceId}] No SwitchBot client available`);
545
+ return { success: false };
546
+ }
547
+ try {
548
+ const result = await client.setDeviceState(deviceId, {
549
+ command: 'turnOn',
550
+ parameter: 'default',
551
+ commandType: 'command',
552
+ });
553
+ log.info(`[${deviceId}] Plug turned on successfully`);
554
+ return { success: true, result };
555
+ }
556
+ catch (e) {
557
+ log.error(`[${deviceId}] Failed to turn on plug:`, e);
558
+ return { success: false, error: e };
559
+ }
560
+ },
561
+ off: async () => {
562
+ log.info(`[${deviceId}] Plug OFF command received`);
563
+ if (!client) {
564
+ log.warn(`[${deviceId}] No SwitchBot client available`);
565
+ return { success: false };
566
+ }
567
+ try {
568
+ const result = await client.setDeviceState(deviceId, {
569
+ command: 'turnOff',
570
+ parameter: 'default',
571
+ commandType: 'command',
572
+ });
573
+ log.info(`[${deviceId}] Plug turned off successfully`);
574
+ return { success: true, result };
575
+ }
576
+ catch (e) {
577
+ log.error(`[${deviceId}] Failed to turn off plug:`, e);
578
+ return { success: false, error: e };
579
+ }
580
+ },
581
+ },
582
+ };
583
+ case 'lock':
584
+ return {
585
+ doorLock: {
586
+ setLockState: async (request) => {
587
+ const state = request?.lockState === 1 ? 'LOCKED' : 'UNLOCKED';
588
+ log.info(`[${deviceId}] Lock state change requested: ${state}`);
589
+ if (!client) {
590
+ log.warn(`[${deviceId}] No SwitchBot client available`);
591
+ return { success: false };
592
+ }
593
+ try {
594
+ const command = request?.lockState === 1 ? 'lock' : 'unlock';
595
+ const result = await client.setDeviceState(deviceId, {
596
+ command,
597
+ parameter: 'default',
598
+ commandType: 'command',
599
+ });
600
+ log.info(`[${deviceId}] Lock ${state} successfully`);
601
+ return { success: true, result };
602
+ }
603
+ catch (e) {
604
+ log.error(`[${deviceId}] Failed to change lock state:`, e);
605
+ return { success: false, error: e };
606
+ }
607
+ },
608
+ },
609
+ };
610
+ case 'fan':
611
+ return {
612
+ onOff: {
613
+ on: async () => {
614
+ log.info(`[${deviceId}] Fan ON command received`);
615
+ if (!client) {
616
+ log.warn(`[${deviceId}] No SwitchBot client available`);
617
+ return { success: false };
618
+ }
619
+ try {
620
+ const result = await client.setDeviceState(deviceId, {
621
+ command: 'turnOn',
622
+ parameter: 'default',
623
+ commandType: 'command',
624
+ });
625
+ log.info(`[${deviceId}] Fan turned on successfully`);
626
+ return { success: true, result };
627
+ }
628
+ catch (e) {
629
+ log.error(`[${deviceId}] Failed to turn on fan:`, e);
630
+ return { success: false, error: e };
631
+ }
632
+ },
633
+ off: async () => {
634
+ log.info(`[${deviceId}] Fan OFF command received`);
635
+ if (!client) {
636
+ log.warn(`[${deviceId}] No SwitchBot client available`);
637
+ return { success: false };
638
+ }
639
+ try {
640
+ const result = await client.setDeviceState(deviceId, {
641
+ command: 'turnOff',
642
+ parameter: 'default',
643
+ commandType: 'command',
644
+ });
645
+ log.info(`[${deviceId}] Fan turned off successfully`);
646
+ return { success: true, result };
647
+ }
648
+ catch (e) {
649
+ log.error(`[${deviceId}] Failed to turn off fan:`, e);
650
+ return { success: false, error: e };
651
+ }
652
+ },
653
+ },
654
+ fanControl: {
655
+ setFanSpeed: async (request) => {
656
+ const speed = request?.percentSetting || 0;
657
+ log.info(`[${deviceId}] Fan speed change requested: ${speed}%`);
658
+ if (!client) {
659
+ log.warn(`[${deviceId}] No SwitchBot client available`);
660
+ return { success: false };
661
+ }
662
+ try {
663
+ // Convert percentage to SwitchBot fan speed parameter
664
+ const speedParam = Math.max(1, Math.min(100, speed));
665
+ const result = await client.setDeviceState(deviceId, {
666
+ command: 'setFanSpeed',
667
+ parameter: String(speedParam),
668
+ commandType: 'command',
669
+ });
670
+ log.info(`[${deviceId}] Fan speed set to ${speedParam}% successfully`);
671
+ return { success: true, result };
672
+ }
673
+ catch (e) {
674
+ log.error(`[${deviceId}] Failed to set fan speed:`, e);
675
+ return { success: false, error: e };
676
+ }
677
+ },
678
+ },
679
+ };
680
+ case 'light':
681
+ return {
682
+ onOff: {
683
+ on: async () => {
684
+ log.info(`[${deviceId}] Light ON command received`);
685
+ if (!client) {
686
+ log.warn(`[${deviceId}] No SwitchBot client available`);
687
+ return { success: false };
688
+ }
689
+ try {
690
+ const result = await client.setDeviceState(deviceId, {
691
+ command: 'turnOn',
692
+ parameter: 'default',
693
+ commandType: 'command',
694
+ });
695
+ log.info(`[${deviceId}] Light turned on successfully`);
696
+ return { success: true, result };
697
+ }
698
+ catch (e) {
699
+ log.error(`[${deviceId}] Failed to turn on light:`, e);
700
+ return { success: false, error: e };
701
+ }
702
+ },
703
+ off: async () => {
704
+ log.info(`[${deviceId}] Light OFF command received`);
705
+ if (!client) {
706
+ log.warn(`[${deviceId}] No SwitchBot client available`);
707
+ return { success: false };
708
+ }
709
+ try {
710
+ const result = await client.setDeviceState(deviceId, {
711
+ command: 'turnOff',
712
+ parameter: 'default',
713
+ commandType: 'command',
714
+ });
715
+ log.info(`[${deviceId}] Light turned off successfully`);
716
+ return { success: true, result };
717
+ }
718
+ catch (e) {
719
+ log.error(`[${deviceId}] Failed to turn off light:`, e);
720
+ return { success: false, error: e };
721
+ }
722
+ },
723
+ },
724
+ levelControl: {
725
+ moveToLevel: async (request) => {
726
+ const level = request?.level || 0;
727
+ // Convert from 0-254 to 0-100
728
+ const brightness = Math.round((level / 254) * 100);
729
+ log.info(`[${deviceId}] Light brightness change requested: ${brightness}%`);
730
+ if (!client) {
731
+ log.warn(`[${deviceId}] No SwitchBot client available`);
732
+ return { success: false };
733
+ }
734
+ try {
735
+ const param = Math.max(0, Math.min(100, brightness));
736
+ const result = await client.setDeviceState(deviceId, {
737
+ command: 'setBrightness',
738
+ parameter: String(param),
739
+ commandType: 'command',
740
+ });
741
+ log.info(`[${deviceId}] Light brightness set to ${param}% successfully`);
742
+ return { success: true, result };
743
+ }
744
+ catch (e) {
745
+ log.error(`[${deviceId}] Failed to set light brightness:`, e);
746
+ return { success: false, error: e };
747
+ }
748
+ },
749
+ },
750
+ };
751
+ case 'lightstrip':
752
+ return {
753
+ onOff: {
754
+ on: async () => {
755
+ log.info(`[${deviceId}] Lightstrip ON command received`);
756
+ if (!client) {
757
+ log.warn(`[${deviceId}] No SwitchBot client available`);
758
+ return { success: false };
759
+ }
760
+ try {
761
+ const result = await client.setDeviceState(deviceId, {
762
+ command: 'turnOn',
763
+ parameter: 'default',
764
+ commandType: 'command',
765
+ });
766
+ log.info(`[${deviceId}] Lightstrip turned on successfully`);
767
+ return { success: true, result };
768
+ }
769
+ catch (e) {
770
+ log.error(`[${deviceId}] Failed to turn on lightstrip:`, e);
771
+ return { success: false, error: e };
772
+ }
773
+ },
774
+ off: async () => {
775
+ log.info(`[${deviceId}] Lightstrip OFF command received`);
776
+ if (!client) {
777
+ log.warn(`[${deviceId}] No SwitchBot client available`);
778
+ return { success: false };
779
+ }
780
+ try {
781
+ const result = await client.setDeviceState(deviceId, {
782
+ command: 'turnOff',
783
+ parameter: 'default',
784
+ commandType: 'command',
785
+ });
786
+ log.info(`[${deviceId}] Lightstrip turned off successfully`);
787
+ return { success: true, result };
788
+ }
789
+ catch (e) {
790
+ log.error(`[${deviceId}] Failed to turn off lightstrip:`, e);
791
+ return { success: false, error: e };
792
+ }
793
+ },
794
+ },
795
+ levelControl: {
796
+ moveToLevel: async (request) => {
797
+ const level = request?.level || 0;
798
+ // Convert from 0-254 to 0-100
799
+ const brightness = Math.round((level / 254) * 100);
800
+ log.info(`[${deviceId}] Lightstrip brightness change requested: ${brightness}%`);
801
+ if (!client) {
802
+ log.warn(`[${deviceId}] No SwitchBot client available`);
803
+ return { success: false };
804
+ }
805
+ try {
806
+ const param = Math.max(0, Math.min(100, brightness));
807
+ const result = await client.setDeviceState(deviceId, {
808
+ command: 'setBrightness',
809
+ parameter: String(param),
810
+ commandType: 'command',
811
+ });
812
+ log.info(`[${deviceId}] Lightstrip brightness set to ${param}% successfully`);
813
+ return { success: true, result };
814
+ }
815
+ catch (e) {
816
+ log.error(`[${deviceId}] Failed to set lightstrip brightness:`, e);
817
+ return { success: false, error: e };
818
+ }
819
+ },
820
+ },
821
+ colorControl: {
822
+ moveToHueAndSaturation: async (request) => {
823
+ const hue = request?.hue || 0;
824
+ const saturation = request?.saturation || 0;
825
+ log.info(`[${deviceId}] Lightstrip color change requested: hue=${hue}, sat=${saturation}`);
826
+ if (!client) {
827
+ log.warn(`[${deviceId}] No SwitchBot client available`);
828
+ return { success: false };
829
+ }
830
+ try {
831
+ // Convert hue (0-254) and saturation (0-254) to combined color parameter
832
+ // SwitchBot typically expects RGB or HSV format as parameter
833
+ const colorParam = `${Math.round(hue)},${Math.round(saturation)}`;
834
+ const result = await client.setDeviceState(deviceId, {
835
+ command: 'setColor',
836
+ parameter: colorParam,
837
+ commandType: 'command',
838
+ });
839
+ log.info(`[${deviceId}] Lightstrip color set successfully`);
840
+ return { success: true, result };
841
+ }
842
+ catch (e) {
843
+ log.error(`[${deviceId}] Failed to set lightstrip color:`, e);
844
+ return { success: false, error: e };
845
+ }
846
+ },
847
+ moveToColorTemperature: async (request) => {
848
+ const mireds = request?.colorTemperatureMireds || 400;
849
+ // Convert mireds (158-500 typical range) to Kelvin: K = 1000000 / mireds
850
+ const kelvin = Math.round(1000000 / mireds);
851
+ log.info(`[${deviceId}] Lightstrip color temperature change requested: ${mireds} mireds (${kelvin}K)`);
852
+ if (!client) {
853
+ log.warn(`[${deviceId}] No SwitchBot client available`);
854
+ return { success: false };
855
+ }
856
+ try {
857
+ // Map Kelvin to SwitchBot color temperature parameter (typically 0-100 or specific values)
858
+ // Normalize to 0-100 scale where 0=warm (2700K) and 100=cool (6500K)
859
+ const colorTempParam = Math.max(0, Math.min(100, Math.round(((kelvin - 2700) / 3800) * 100)));
860
+ const result = await client.setDeviceState(deviceId, {
861
+ command: 'setColorTemperature',
862
+ parameter: String(colorTempParam),
863
+ commandType: 'command',
864
+ });
865
+ log.info(`[${deviceId}] Lightstrip color temperature set to ${kelvin}K successfully`);
866
+ return { success: true, result };
867
+ }
868
+ catch (e) {
869
+ log.error(`[${deviceId}] Failed to set lightstrip color temperature:`, e);
870
+ return { success: false, error: e };
871
+ }
872
+ },
873
+ },
874
+ };
875
+ case 'humidifier':
876
+ return {
877
+ onOff: {
878
+ on: async () => {
879
+ log.info(`[${deviceId}] Humidifier ON command received`);
880
+ if (!client) {
881
+ log.warn(`[${deviceId}] No SwitchBot client available`);
882
+ return { success: false };
883
+ }
884
+ try {
885
+ const result = await client.setDeviceState(deviceId, {
886
+ command: 'turnOn',
887
+ parameter: 'default',
888
+ commandType: 'command',
889
+ });
890
+ log.info(`[${deviceId}] Humidifier turned on successfully`);
891
+ return { success: true, result };
892
+ }
893
+ catch (e) {
894
+ log.error(`[${deviceId}] Failed to turn on humidifier:`, e);
895
+ return { success: false, error: e };
896
+ }
897
+ },
898
+ off: async () => {
899
+ log.info(`[${deviceId}] Humidifier OFF command received`);
900
+ if (!client) {
901
+ log.warn(`[${deviceId}] No SwitchBot client available`);
902
+ return { success: false };
903
+ }
904
+ try {
905
+ const result = await client.setDeviceState(deviceId, {
906
+ command: 'turnOff',
907
+ parameter: 'default',
908
+ commandType: 'command',
909
+ });
910
+ log.info(`[${deviceId}] Humidifier turned off successfully`);
911
+ return { success: true, result };
912
+ }
913
+ catch (e) {
914
+ log.error(`[${deviceId}] Failed to turn off humidifier:`, e);
915
+ return { success: false, error: e };
916
+ }
917
+ },
918
+ },
919
+ fanControl: {
920
+ setFanSpeed: async (request) => {
921
+ const speed = request?.percentSetting || 0;
922
+ log.info(`[${deviceId}] Humidifier speed change requested: ${speed}%`);
923
+ if (!client) {
924
+ log.warn(`[${deviceId}] No SwitchBot client available`);
925
+ return { success: false };
926
+ }
927
+ try {
928
+ // Convert percentage to SwitchBot humidifier speed parameter
929
+ const speedParam = Math.max(1, Math.min(100, speed));
930
+ const result = await client.setDeviceState(deviceId, {
931
+ command: 'setFanSpeed',
932
+ parameter: String(speedParam),
933
+ commandType: 'command',
934
+ });
935
+ log.info(`[${deviceId}] Humidifier speed set to ${speedParam}% successfully`);
936
+ return { success: true, result };
937
+ }
938
+ catch (e) {
939
+ log.error(`[${deviceId}] Failed to set humidifier speed:`, e);
940
+ return { success: false, error: e };
941
+ }
942
+ },
943
+ },
944
+ };
945
+ case 'relay':
946
+ return {
947
+ onOff: {
948
+ on: async () => {
949
+ log.info(`[${deviceId}] Relay ON command received`);
950
+ if (!client) {
951
+ log.warn(`[${deviceId}] No SwitchBot client available`);
952
+ return { success: false };
953
+ }
954
+ try {
955
+ const result = await client.setDeviceState(deviceId, {
956
+ command: 'turnOn',
957
+ parameter: 'default',
958
+ commandType: 'command',
959
+ });
960
+ log.info(`[${deviceId}] Relay turned on successfully`);
961
+ return { success: true, result };
962
+ }
963
+ catch (e) {
964
+ log.error(`[${deviceId}] Failed to turn on relay:`, e);
965
+ return { success: false, error: e };
966
+ }
967
+ },
968
+ off: async () => {
969
+ log.info(`[${deviceId}] Relay OFF command received`);
970
+ if (!client) {
971
+ log.warn(`[${deviceId}] No SwitchBot client available`);
972
+ return { success: false };
973
+ }
974
+ try {
975
+ const result = await client.setDeviceState(deviceId, {
976
+ command: 'turnOff',
977
+ parameter: 'default',
978
+ commandType: 'command',
979
+ });
980
+ log.info(`[${deviceId}] Relay turned off successfully`);
981
+ return { success: true, result };
982
+ }
983
+ catch (e) {
984
+ log.error(`[${deviceId}] Failed to turn off relay:`, e);
985
+ return { success: false, error: e };
986
+ }
987
+ },
988
+ },
989
+ };
990
+ default:
991
+ return undefined;
992
+ }
993
+ }
994
+ function resolveMatterDeviceType(matterApi, type, createdDeviceType, clusters) {
995
+ if (createdDeviceType && typeof createdDeviceType === 'object' && typeof createdDeviceType.with === 'function') {
996
+ return createdDeviceType;
997
+ }
998
+ const lowerType = (typeof createdDeviceType === 'string' && createdDeviceType) ? createdDeviceType.toLowerCase() : (type || '').toLowerCase();
999
+ // Cluster-based upgrade for color lights if descriptor omitted device type.
1000
+ const hasColorControl = !!clusters?.colorControl;
1001
+ const inferredType = hasColorControl && lowerType === 'light'
1002
+ ? 'lightstrip'
1003
+ : lowerType;
1004
+ const mappedKey = DEVICE_MATTER_DEVICE_TYPE_KEYS[inferredType] || 'OnOffSwitch';
1005
+ return matterApi?.deviceTypes?.[mappedKey] || matterApi?.deviceTypes?.OnOffSwitch;
1006
+ }
1007
+ export class SwitchBotHAPPlatform {
1008
+ api;
1009
+ log;
1010
+ config;
1011
+ devices = [];
1012
+ // cached accessories restored by Homebridge
1013
+ accessories;
1014
+ // Track last loaded config to detect changes
1015
+ lastConfigHash = '';
1016
+ configReloadInterval = null;
1017
+ constructor(log, config, api) {
1018
+ this.log = log;
1019
+ this.config = config ?? {};
1020
+ this.api = api;
1021
+ this.accessories = new Map();
1022
+ this.log.info('SwitchBot HAP platform initialized');
1023
+ // Create/shared SwitchBot client and attach to config so child devices reuse it.
1024
+ try {
1025
+ const client = new SwitchBotClient(this.config);
1026
+ void client.init();
1027
+ this.config._client = client;
1028
+ }
1029
+ catch (e) {
1030
+ this.log.debug('Failed to create shared SwitchBot client', e);
1031
+ }
1032
+ // Create/shared SwitchBot client and attach to config so child devices reuse it.
1033
+ try {
1034
+ const client = new SwitchBotClient(this.config);
1035
+ void client.init();
1036
+ this.config._client = client;
1037
+ }
1038
+ catch (e) {
1039
+ this.log.debug('Failed to create shared SwitchBot client', e);
1040
+ }
1041
+ // Wait for Homebridge to finish launching to create/register accessories
1042
+ if (this.api && typeof this.api.on === 'function') {
1043
+ ;
1044
+ this.api.on('didFinishLaunching', () => {
1045
+ void this.loadDevices();
1046
+ // Start periodic config reload to pick up UI changes
1047
+ this.configReloadInterval = setInterval(() => {
1048
+ void this.checkAndReloadDevices();
1049
+ }, 10000); // Check every 10 seconds
1050
+ });
1051
+ }
1052
+ else {
1053
+ void this.loadDevices();
1054
+ // Start periodic config reload to pick up UI changes
1055
+ this.configReloadInterval = setInterval(() => {
1056
+ void this.checkAndReloadDevices();
1057
+ }, 10000); // Check every 10 seconds
1058
+ }
1059
+ }
1060
+ getConfigHash() {
1061
+ // Create a simple hash of current device config to detect changes
1062
+ const devices = this.config?.devices ?? [];
1063
+ return JSON.stringify(devices.map((d) => ({
1064
+ id: d.deviceId ?? d.id,
1065
+ type: d.configDeviceType ?? d.type,
1066
+ name: d.configDeviceName ?? d.name,
1067
+ })));
1068
+ }
1069
+ async checkAndReloadDevices() {
1070
+ const currentHash = this.getConfigHash();
1071
+ if (currentHash !== this.lastConfigHash) {
1072
+ this.log.info('[SwitchBot] Detected config changes, reloading devices...');
1073
+ // Clear existing devices
1074
+ this.devices = [];
1075
+ await this.loadDevices();
1076
+ }
1077
+ }
1078
+ async loadDevices() {
1079
+ const devices = this.config?.devices ?? [];
1080
+ for (const raw of devices) {
1081
+ // Normalize config keys from UI schema to internal shape
1082
+ const d = {
1083
+ id: raw.deviceId ?? raw.id,
1084
+ name: raw.configDeviceName ?? raw.name,
1085
+ type: raw.configDeviceType ?? raw.type ?? raw.deviceType ?? 'unknown',
1086
+ _raw: raw,
1087
+ };
1088
+ const type = normalizeTypeForMatter(d.type);
1089
+ const matterSupported = !!DEVICE_MATTER_SUPPORTED[(type || '').toLowerCase()];
1090
+ // Auto-detect Matter from Homebridge API, allow manual override via config
1091
+ const matterAvailable = !!(this.api?.isMatterAvailable?.() && this.api?.isMatterEnabled?.());
1092
+ const matterEnabled = matterAvailable || !!this.config.enableMatter;
1093
+ const useMatter = !!(matterEnabled && matterSupported && (!!this.config.preferMatter || matterAvailable));
1094
+ try {
1095
+ const created = await createDevice({ id: d.id, type, name: d.name }, this.config, useMatter);
1096
+ this.devices.push(created);
1097
+ // Prefer Matter: try registering to the Matter child bridge first.
1098
+ let matterRegistered = false;
1099
+ if (useMatter) {
1100
+ this.log.info(`Attempting Matter registration for ${d.id} (${type})`);
1101
+ // If Homebridge Matter APIs are available, register the accessory
1102
+ try {
1103
+ const matterApi = this.api?.matter;
1104
+ if (this.api?.isMatterAvailable?.() && this.api?.isMatterEnabled?.() && matterApi && typeof matterApi.registerPlatformAccessories === 'function') {
1105
+ const createdDesc = created.createAccessory?.(this.api) || { id: d.id, name: d.name || type };
1106
+ const uuid = matterApi.uuid.generate(`${d.id}`);
1107
+ const defaultClusters = DEVICE_MATTER_CLUSTERS[type.toLowerCase()] || { onOff: { onOff: false } };
1108
+ const clusters = createdDesc.clusters || defaultClusters;
1109
+ const deviceType = resolveMatterDeviceType(matterApi, type, createdDesc.deviceType, clusters);
1110
+ const accessory = {
1111
+ UUID: uuid,
1112
+ displayName: createdDesc.name || d.name || type,
1113
+ deviceType,
1114
+ manufacturer: createdDesc.manufacturer || 'SwitchBot',
1115
+ model: createdDesc.model || type,
1116
+ serialNumber: createdDesc.serialNumber || d.id,
1117
+ reachable: createdDesc.reachable !== false,
1118
+ firmwareRevision: createdDesc.firmwareRevision || '1.0.0',
1119
+ hardwareRevision: createdDesc.hardwareRevision || '',
1120
+ clusters,
1121
+ handlers: createdDesc.handlers || createMatterHandlers(this.log, d.id, type, this.config?._client) || undefined,
1122
+ context: { deviceId: d.id, type, _created: true },
1123
+ };
1124
+ try {
1125
+ await matterApi.registerPlatformAccessories(PLUGIN_NAME, PLATFORM_NAME, [accessory]);
1126
+ this.accessories.set(uuid, accessory);
1127
+ matterRegistered = true;
1128
+ this.log.info(`Registered Matter accessory ${d.id} (${type}) with uuid=${uuid}`);
1129
+ }
1130
+ catch (e) {
1131
+ this.log.warn('Failed to register Matter accessory with Homebridge matter API', e);
1132
+ }
1133
+ }
1134
+ else {
1135
+ this.log.info('Homebridge Matter API not available or not enabled; will fallback to HAP');
1136
+ }
1137
+ }
1138
+ catch (e) {
1139
+ this.log.warn('Matter registration attempt failed', e);
1140
+ }
1141
+ }
1142
+ // If Matter wasn't registered (either not supported, API missing, or registration failed), fall back to HAP registration.
1143
+ if (!matterRegistered && this.api && this.api.hap) {
1144
+ // Basic HAP accessory creation using homebridge API when available
1145
+ try {
1146
+ const hap = this.api.hap;
1147
+ const uuid = hap.uuid.generate(`${d.id}`);
1148
+ // Reuse cached accessory if available by uuid
1149
+ let accessory = this.accessories.get(uuid);
1150
+ // If not found by uuid, attempt to find by stored deviceId in accessory.context
1151
+ if (!accessory) {
1152
+ for (const [, a] of this.accessories.entries()) {
1153
+ try {
1154
+ if (a && a.context && a.context.deviceId === d.id) {
1155
+ accessory = a;
1156
+ break;
1157
+ }
1158
+ }
1159
+ catch (e) {
1160
+ // ignore
1161
+ }
1162
+ }
1163
+ }
1164
+ if (!accessory) {
1165
+ accessory = new this.api.platformAccessory(d.name || type, uuid);
1166
+ // Store device metadata on accessory.context for persistence across restarts
1167
+ try {
1168
+ accessory.context = accessory.context || {};
1169
+ accessory.context.deviceId = d.id;
1170
+ accessory.context.type = type;
1171
+ }
1172
+ catch (e) {
1173
+ // ignore context failures
1174
+ }
1175
+ // Register new accessory with Homebridge so it's cached
1176
+ try {
1177
+ ;
1178
+ this.api.registerPlatformAccessories(PLUGIN_NAME, PLATFORM_NAME, [accessory]);
1179
+ }
1180
+ catch (e) {
1181
+ // older API variations may require different registration; ignore if unavailable
1182
+ }
1183
+ this.accessories.set(uuid, accessory);
1184
+ }
1185
+ else {
1186
+ // ensure context includes deviceId (in case restored accessory lacked it)
1187
+ try {
1188
+ accessory.context = accessory.context || {};
1189
+ accessory.context.deviceId = accessory.context.deviceId || d.id;
1190
+ accessory.context.type = accessory.context.type || type;
1191
+ }
1192
+ catch (e) {
1193
+ // ignore
1194
+ }
1195
+ }
1196
+ // Add basic service descriptor from device
1197
+ const accDesc = created.createAccessory?.(this.api);
1198
+ if (accDesc && accDesc.services) {
1199
+ for (const s of accDesc.services) {
1200
+ const Service = hap.Service[s.type] || hap.Service[s.type];
1201
+ if (!Service) {
1202
+ continue;
1203
+ }
1204
+ const service = accessory.getService(Service) || accessory.addService(Service);
1205
+ for (const [charName, getterSetterRaw] of Object.entries(s.characteristics || {})) {
1206
+ const getterSetter = getterSetterRaw;
1207
+ const Characteristic = hap.Characteristic[charName];
1208
+ if (!Characteristic) {
1209
+ continue;
1210
+ }
1211
+ // Apply characteristic props if provided (min/max/step)
1212
+ if (getterSetter && getterSetter.props) {
1213
+ try {
1214
+ service.getCharacteristic(Characteristic).setProps(getterSetter.props);
1215
+ }
1216
+ catch (e) {
1217
+ // ignore setProps failures on older HAP implementations
1218
+ }
1219
+ }
1220
+ // Wire simple get/set handlers if provided
1221
+ if (getterSetter && typeof getterSetter.get === 'function') {
1222
+ service.getCharacteristic(Characteristic).onGet(getterSetter.get);
1223
+ }
1224
+ if (getterSetter && typeof getterSetter.set === 'function') {
1225
+ service.getCharacteristic(Characteristic).onSet(getterSetter.set);
1226
+ }
1227
+ }
1228
+ }
1229
+ }
1230
+ this.log.info(`Created/updated HAP accessory ${d.id} (${type})`);
1231
+ }
1232
+ catch (e) {
1233
+ this.log.warn('HAP accessory creation failed', e);
1234
+ }
1235
+ }
1236
+ else if (!matterRegistered) {
1237
+ this.log.info(`Created HAP descriptor for ${d.id} (${type}) (API not available to register)`);
1238
+ }
1239
+ }
1240
+ catch (e) {
1241
+ this.log.error(`Failed to create device ${d.id}:`, e);
1242
+ }
1243
+ }
1244
+ // Update hash after successfully loading devices
1245
+ this.lastConfigHash = this.getConfigHash();
1246
+ }
1247
+ // Example lifecycle method called by Homebridge
1248
+ async configureAccessory(accessory) {
1249
+ // Homebridge calls this for restored cached accessories — keep a reference.
1250
+ try {
1251
+ const uuid = accessory.UUID || accessory.UUID;
1252
+ this.accessories.set(uuid, accessory);
1253
+ this.log.info(`Restored cached accessory ${accessory.displayName || uuid}`);
1254
+ }
1255
+ catch (e) {
1256
+ this.log.warn('configureAccessory failed to restore accessory', e);
1257
+ }
1258
+ }
1259
+ // Called by Homebridge when a cached Matter accessory is restored
1260
+ configureMatterAccessory(accessory) {
1261
+ try {
1262
+ const uuid = accessory.uuid || accessory.UUID || accessory.uuid;
1263
+ this.accessories.set(uuid, accessory);
1264
+ this.log.info(`Restored cached Matter accessory ${accessory.displayName || uuid}`);
1265
+ }
1266
+ catch (e) {
1267
+ this.log.warn('configureMatterAccessory failed to restore accessory', e);
1268
+ }
1269
+ }
1270
+ }
1271
+ // Matter platform implementation (placeholder)
1272
+ export class SwitchBotMatterPlatform {
1273
+ api;
1274
+ log;
1275
+ config;
1276
+ devices = [];
1277
+ accessories;
1278
+ // Track last loaded config to detect changes
1279
+ lastConfigHash = '';
1280
+ configReloadInterval = null;
1281
+ constructor(log, config, api) {
1282
+ this.log = log;
1283
+ this.config = config ?? {};
1284
+ this.api = api;
1285
+ this.accessories = new Map();
1286
+ this.log.info('SwitchBot Matter platform initialized');
1287
+ if (this.api && typeof this.api.on === 'function') {
1288
+ ;
1289
+ this.api.on('didFinishLaunching', () => {
1290
+ ;
1291
+ (async () => {
1292
+ // After launch, perform discovery (if any) and register Matter accessories
1293
+ try {
1294
+ await this.loadDevices();
1295
+ if (this.api.isMatterAvailable?.() && this.api.isMatterEnabled?.() && this.api.matter && typeof this.api.matter.registerPlatformAccessories === 'function') {
1296
+ try {
1297
+ await this.registerMatterAccessories?.();
1298
+ }
1299
+ catch (e) {
1300
+ this.log.warn('registerMatterAccessories failed', e);
1301
+ }
1302
+ }
1303
+ }
1304
+ catch (e) {
1305
+ this.log.warn('Error during Matter platform startup', e);
1306
+ }
1307
+ })();
1308
+ // Start periodic config reload to pick up UI changes
1309
+ this.configReloadInterval = setInterval(() => {
1310
+ void this.checkAndReloadDevices();
1311
+ }, 10000); // Check every 10 seconds
1312
+ });
1313
+ }
1314
+ else {
1315
+ void this.loadDevices();
1316
+ // Start periodic config reload to pick up UI changes
1317
+ this.configReloadInterval = setInterval(() => {
1318
+ void this.checkAndReloadDevices();
1319
+ }, 10000); // Check every 10 seconds
1320
+ }
1321
+ // Create/shared SwitchBot client and attach to config so child devices reuse it.
1322
+ try {
1323
+ const client = new SwitchBotClient(this.config);
1324
+ void client.init();
1325
+ this.config._client = client;
1326
+ }
1327
+ catch (e) {
1328
+ this.log.debug('Failed to create shared SwitchBot client', e);
1329
+ }
1330
+ }
1331
+ async loadDevices() {
1332
+ const devices = this.config?.devices ?? [];
1333
+ for (const raw of devices) {
1334
+ // Normalize config keys produced by the UI schema
1335
+ const d = {
1336
+ id: raw.deviceId ?? raw.id,
1337
+ name: raw.configDeviceName ?? raw.name,
1338
+ type: raw.configDeviceType ?? raw.type ?? raw.deviceType ?? 'unknown',
1339
+ _raw: raw,
1340
+ };
1341
+ const type = normalizeTypeForMatter(d.type);
1342
+ const matterSupported = !!DEVICE_MATTER_SUPPORTED[(type || '').toLowerCase()];
1343
+ // Auto-detect Matter from Homebridge API, allow manual override via config
1344
+ const matterAvailable = this.api?.isMatterAvailable?.() && this.api?.isMatterEnabled?.();
1345
+ const matterEnabled = matterAvailable || !!this.config.enableMatter;
1346
+ const useMatter = matterEnabled && matterSupported;
1347
+ try {
1348
+ const created = await createDevice({ id: d.id, type, name: d.name }, this.config, useMatter);
1349
+ this.devices.push(created);
1350
+ if (useMatter) {
1351
+ this.log.info(`Prepared Matter accessory for ${d.id} (${type})${matterAvailable ? ' (auto-detected)' : ' (manually enabled)'}`);
1352
+ }
1353
+ else {
1354
+ if (!matterEnabled) {
1355
+ this.log.info(`Skipping Matter for ${d.id} (${type}) - Matter not available on this bridge`);
1356
+ }
1357
+ else if (!matterSupported) {
1358
+ this.log.info(`Skipping Matter for ${d.id} (${type}) - device type not supported`);
1359
+ }
1360
+ else {
1361
+ this.log.info(`Skipping Matter for ${d.id} (${type}) - not supported`);
1362
+ }
1363
+ }
1364
+ }
1365
+ catch (e) {
1366
+ this.log.error(`Failed to create Matter device ${d.id}:`, e);
1367
+ }
1368
+ }
1369
+ // Update hash after successfully loading devices
1370
+ this.lastConfigHash = this.getConfigHash();
1371
+ }
1372
+ getConfigHash() {
1373
+ // Create a simple hash of current device config to detect changes
1374
+ const devices = this.config?.devices ?? [];
1375
+ return JSON.stringify(devices.map((d) => ({
1376
+ id: d.deviceId ?? d.id,
1377
+ type: d.configDeviceType ?? d.type,
1378
+ name: d.configDeviceName ?? d.name,
1379
+ })));
1380
+ }
1381
+ async checkAndReloadDevices() {
1382
+ const currentHash = this.getConfigHash();
1383
+ if (currentHash !== this.lastConfigHash) {
1384
+ this.log.info('[SwitchBot] Detected config changes, reloading devices...');
1385
+ // Clear existing devices
1386
+ this.devices = [];
1387
+ await this.loadDevices();
1388
+ }
1389
+ }
1390
+ async configureAccessory(accessory) {
1391
+ try {
1392
+ const uuid = accessory.UUID || accessory.UUID;
1393
+ this.accessories.set(uuid, accessory);
1394
+ this.log.info(`Restored cached Matter accessory ${accessory.displayName || uuid}`);
1395
+ }
1396
+ catch (e) {
1397
+ this.log.warn('configureAccessory failed to restore Matter accessory', e);
1398
+ }
1399
+ }
1400
+ // Homebridge calls this when restoring cached Matter accessories
1401
+ configureMatterAccessory(accessory) {
1402
+ try {
1403
+ const uuid = accessory.uuid || accessory.UUID || accessory.uuid;
1404
+ this.accessories.set(uuid, accessory);
1405
+ this.log.info(`Restored cached Matter accessory ${accessory.displayName || uuid}`);
1406
+ }
1407
+ catch (e) {
1408
+ this.log.warn('configureMatterAccessory failed to restore Matter accessory', e);
1409
+ }
1410
+ }
1411
+ // Register serialized Matter accessories via Homebridge Matter API
1412
+ async registerMatterAccessories() {
1413
+ if (!this.api) {
1414
+ return;
1415
+ }
1416
+ const matterApi = this.api.matter;
1417
+ if (!matterApi || typeof matterApi.registerPlatformAccessories !== 'function') {
1418
+ this.log.info('Homebridge Matter API not available; skipping Matter accessory registration');
1419
+ return;
1420
+ }
1421
+ const devices = this.config?.devices ?? [];
1422
+ const accessoriesToRegister = [];
1423
+ // Auto-detect Matter from Homebridge API
1424
+ const matterAvailable = this.api?.isMatterAvailable?.() && this.api?.isMatterEnabled?.();
1425
+ const matterEnabled = matterAvailable || !!this.config.enableMatter;
1426
+ for (const raw of devices) {
1427
+ const d = {
1428
+ id: raw.deviceId ?? raw.id,
1429
+ name: raw.configDeviceName ?? raw.name,
1430
+ type: raw.configDeviceType ?? raw.type ?? raw.deviceType ?? 'unknown',
1431
+ };
1432
+ if (!d.id) {
1433
+ continue;
1434
+ }
1435
+ const type = normalizeTypeForMatter(d.type);
1436
+ const matterSupported = !!DEVICE_MATTER_SUPPORTED[(type || '').toLowerCase()];
1437
+ const useMatter = matterEnabled && matterSupported;
1438
+ if (!useMatter) {
1439
+ continue;
1440
+ }
1441
+ try {
1442
+ const created = await createDevice({ id: d.id, type, name: d.name }, this.config, true);
1443
+ const createdDesc = created.createAccessory?.(this.api) || { id: d.id, name: d.name || type };
1444
+ const uuid = matterApi.uuid.generate(`${d.id}`);
1445
+ // Try to find existing restored accessory by deviceId
1446
+ let existing;
1447
+ for (const [, a] of this.accessories.entries()) {
1448
+ try {
1449
+ if (a && a.context && a.context.deviceId === d.id) {
1450
+ existing = a;
1451
+ break;
1452
+ }
1453
+ }
1454
+ catch (e) {
1455
+ // ignore
1456
+ }
1457
+ }
1458
+ if (existing) {
1459
+ // Ensure context and displayName are up to date
1460
+ // Prioritize device-specific Matter clusters (e.g., RVC for vacuum) over generic HAP-derived clusters
1461
+ let clusters = DEVICE_MATTER_CLUSTERS[type.toLowerCase()];
1462
+ if (!clusters) {
1463
+ clusters = existing.clusters || createdDesc.clusters || { onOff: { onOff: false } };
1464
+ }
1465
+ const deviceType = resolveMatterDeviceType(matterApi, type, existing.deviceType || createdDesc.deviceType, clusters);
1466
+ existing.context = existing.context || {};
1467
+ existing.context.deviceId = existing.context.deviceId || d.id;
1468
+ existing.context.type = existing.context.type || type;
1469
+ existing.deviceType = deviceType;
1470
+ existing.manufacturer = existing.manufacturer || createdDesc.manufacturer || 'SwitchBot';
1471
+ existing.model = existing.model || createdDesc.model || type;
1472
+ existing.serialNumber = existing.serialNumber || createdDesc.serialNumber || d.id;
1473
+ existing.reachable = existing.reachable !== false;
1474
+ existing.firmwareRevision = existing.firmwareRevision || createdDesc.firmwareRevision || '1.0.0';
1475
+ existing.hardwareRevision = existing.hardwareRevision || createdDesc.hardwareRevision || '';
1476
+ existing.clusters = clusters;
1477
+ existing.handlers = createdDesc.handlers || createMatterHandlers(this.log, d.id, type, this.config?._client) || undefined;
1478
+ existing.displayName = createdDesc.name || d.name || type;
1479
+ existing.UUID = existing.UUID || existing.uuid || uuid;
1480
+ accessoriesToRegister.push(existing);
1481
+ this.accessories.set(existing.UUID || uuid, existing);
1482
+ }
1483
+ else {
1484
+ // Prioritize device-specific Matter clusters (e.g., RVC for vacuum) over generic HAP-derived clusters
1485
+ let clusters = DEVICE_MATTER_CLUSTERS[type.toLowerCase()];
1486
+ if (!clusters) {
1487
+ clusters = createdDesc.clusters || { onOff: { onOff: false } };
1488
+ }
1489
+ const deviceType = resolveMatterDeviceType(matterApi, type, createdDesc.deviceType, clusters);
1490
+ const serialized = {
1491
+ UUID: uuid,
1492
+ displayName: createdDesc.name || d.name || type,
1493
+ deviceType,
1494
+ manufacturer: createdDesc.manufacturer || 'SwitchBot',
1495
+ model: createdDesc.model || type,
1496
+ serialNumber: createdDesc.serialNumber || d.id,
1497
+ reachable: createdDesc.reachable !== false,
1498
+ firmwareRevision: createdDesc.firmwareRevision || '1.0.0',
1499
+ hardwareRevision: createdDesc.hardwareRevision || '',
1500
+ clusters,
1501
+ handlers: createdDesc.handlers || createMatterHandlers(this.log, d.id, type, this.config?._client) || undefined,
1502
+ context: { deviceId: d.id, type, created: true },
1503
+ };
1504
+ accessoriesToRegister.push(serialized);
1505
+ this.accessories.set(uuid, serialized);
1506
+ }
1507
+ }
1508
+ catch (e) {
1509
+ this.log.warn(`Failed to prepare Matter accessory for ${d.id} (${type})`, e);
1510
+ }
1511
+ }
1512
+ if (accessoriesToRegister.length > 0) {
1513
+ try {
1514
+ await matterApi.registerPlatformAccessories(PLUGIN_NAME, PLATFORM_NAME, accessoriesToRegister);
1515
+ this.log.info(`Registered ${accessoriesToRegister.length} Matter accessory(ies) with Homebridge`);
1516
+ }
1517
+ catch (e) {
1518
+ this.log.warn('Failed to register Matter accessories', e);
1519
+ }
1520
+ }
1521
+ else {
1522
+ this.log.info('No Matter accessories to register');
1523
+ }
1524
+ }
1525
+ }
1526
+ export default SwitchBotHAPPlatform;
1527
+ //# sourceMappingURL=platform.js.map