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

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