@switchbot/homebridge-switchbot 5.0.0-beta.12 → 5.0.0-beta.121

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 (588) 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 +54 -0
  9. package/README.md +99 -3
  10. package/TODO.md +263 -0
  11. package/config.schema.json +187 -14787
  12. package/dist/device-types.d.ts +31 -0
  13. package/dist/device-types.d.ts.map +1 -0
  14. package/dist/device-types.js +246 -0
  15. package/dist/device-types.js.map +1 -0
  16. package/dist/deviceFactory.d.ts +13 -0
  17. package/dist/deviceFactory.d.ts.map +1 -0
  18. package/dist/deviceFactory.js +146 -0
  19. package/dist/deviceFactory.js.map +1 -0
  20. package/dist/devices/deviceBase.d.ts +50 -0
  21. package/dist/devices/deviceBase.d.ts.map +1 -0
  22. package/dist/devices/deviceBase.js +119 -0
  23. package/dist/devices/deviceBase.js.map +1 -0
  24. package/dist/devices/genericDevice.d.ts +276 -0
  25. package/dist/devices/genericDevice.d.ts.map +1 -0
  26. package/dist/devices/genericDevice.js +1320 -0
  27. package/dist/devices/genericDevice.js.map +1 -0
  28. package/dist/errors.d.ts +5 -0
  29. package/dist/errors.d.ts.map +1 -0
  30. package/dist/errors.js +51 -0
  31. package/dist/errors.js.map +1 -0
  32. package/dist/homebridge-ui/endpoints/config.d.ts +3 -0
  33. package/dist/homebridge-ui/endpoints/config.d.ts.map +1 -0
  34. package/dist/homebridge-ui/endpoints/config.js +107 -0
  35. package/dist/homebridge-ui/endpoints/config.js.map +1 -0
  36. package/dist/homebridge-ui/endpoints/credentials.d.ts +6 -0
  37. package/dist/homebridge-ui/endpoints/credentials.d.ts.map +1 -0
  38. package/dist/homebridge-ui/endpoints/credentials.js +65 -0
  39. package/dist/homebridge-ui/endpoints/credentials.js.map +1 -0
  40. package/dist/homebridge-ui/endpoints/devices.d.ts +6 -0
  41. package/dist/homebridge-ui/endpoints/devices.d.ts.map +1 -0
  42. package/dist/homebridge-ui/endpoints/devices.js +430 -0
  43. package/dist/homebridge-ui/endpoints/devices.js.map +1 -0
  44. package/dist/homebridge-ui/endpoints/discovery.d.ts +7 -0
  45. package/dist/homebridge-ui/endpoints/discovery.d.ts.map +1 -0
  46. package/dist/homebridge-ui/endpoints/discovery.js +203 -0
  47. package/dist/homebridge-ui/endpoints/discovery.js.map +1 -0
  48. package/dist/homebridge-ui/public/css/styles.css +447 -0
  49. package/dist/homebridge-ui/public/index.html +144 -248
  50. package/dist/homebridge-ui/public/js/api.d.ts +59 -0
  51. package/dist/homebridge-ui/public/js/api.d.ts.map +1 -0
  52. package/dist/homebridge-ui/public/js/api.js +219 -0
  53. package/dist/homebridge-ui/public/js/api.js.map +1 -0
  54. package/dist/homebridge-ui/public/js/api.ts +272 -0
  55. package/dist/homebridge-ui/public/js/app.d.ts +2 -0
  56. package/dist/homebridge-ui/public/js/app.d.ts.map +1 -0
  57. package/dist/homebridge-ui/public/js/app.js +3475 -0
  58. package/dist/homebridge-ui/public/js/app.js.map +7 -0
  59. package/dist/homebridge-ui/public/js/app.ts +23 -0
  60. package/dist/homebridge-ui/public/js/constants.d.ts +2 -0
  61. package/dist/homebridge-ui/public/js/constants.d.ts.map +1 -0
  62. package/dist/homebridge-ui/public/js/constants.js +2 -0
  63. package/dist/homebridge-ui/public/js/constants.js.map +1 -0
  64. package/dist/homebridge-ui/public/js/constants.ts +1 -0
  65. package/dist/homebridge-ui/public/js/credentials.d.ts +3 -0
  66. package/dist/homebridge-ui/public/js/credentials.d.ts.map +1 -0
  67. package/dist/homebridge-ui/public/js/credentials.js +96 -0
  68. package/dist/homebridge-ui/public/js/credentials.js.map +1 -0
  69. package/dist/homebridge-ui/public/js/credentials.ts +100 -0
  70. package/dist/homebridge-ui/public/js/devices-delete.d.ts +3 -0
  71. package/dist/homebridge-ui/public/js/devices-delete.d.ts.map +1 -0
  72. package/dist/homebridge-ui/public/js/devices-delete.js +206 -0
  73. package/dist/homebridge-ui/public/js/devices-delete.js.map +1 -0
  74. package/dist/homebridge-ui/public/js/devices-delete.ts +236 -0
  75. package/dist/homebridge-ui/public/js/devices.d.ts +9 -0
  76. package/dist/homebridge-ui/public/js/devices.d.ts.map +1 -0
  77. package/dist/homebridge-ui/public/js/devices.js +93 -0
  78. package/dist/homebridge-ui/public/js/devices.js.map +1 -0
  79. package/dist/homebridge-ui/public/js/devices.ts +111 -0
  80. package/dist/homebridge-ui/public/js/discovery.d.ts +4 -0
  81. package/dist/homebridge-ui/public/js/discovery.d.ts.map +1 -0
  82. package/dist/homebridge-ui/public/js/discovery.js +1364 -0
  83. package/dist/homebridge-ui/public/js/discovery.js.map +1 -0
  84. package/dist/homebridge-ui/public/js/discovery.ts +1492 -0
  85. package/dist/homebridge-ui/public/js/logger.d.ts +6 -0
  86. package/dist/homebridge-ui/public/js/logger.d.ts.map +1 -0
  87. package/dist/homebridge-ui/public/js/logger.js +12 -0
  88. package/dist/homebridge-ui/public/js/logger.js.map +1 -0
  89. package/dist/homebridge-ui/public/js/logger.ts +11 -0
  90. package/dist/homebridge-ui/public/js/modal.d.ts +5 -0
  91. package/dist/homebridge-ui/public/js/modal.d.ts.map +1 -0
  92. package/dist/homebridge-ui/public/js/modal.js +26 -0
  93. package/dist/homebridge-ui/public/js/modal.js.map +1 -0
  94. package/dist/homebridge-ui/public/js/modal.ts +28 -0
  95. package/dist/homebridge-ui/public/js/modals.d.ts +7 -0
  96. package/dist/homebridge-ui/public/js/modals.d.ts.map +1 -0
  97. package/dist/homebridge-ui/public/js/modals.js +365 -0
  98. package/dist/homebridge-ui/public/js/modals.js.map +1 -0
  99. package/dist/homebridge-ui/public/js/modals.ts +416 -0
  100. package/dist/homebridge-ui/public/js/render.d.ts +68 -0
  101. package/dist/homebridge-ui/public/js/render.d.ts.map +1 -0
  102. package/dist/homebridge-ui/public/js/render.js +914 -0
  103. package/dist/homebridge-ui/public/js/render.js.map +1 -0
  104. package/dist/homebridge-ui/public/js/render.ts +1026 -0
  105. package/dist/homebridge-ui/public/js/toast.d.ts +6 -0
  106. package/dist/homebridge-ui/public/js/toast.d.ts.map +1 -0
  107. package/dist/homebridge-ui/public/js/toast.js +29 -0
  108. package/dist/homebridge-ui/public/js/toast.js.map +1 -0
  109. package/dist/homebridge-ui/public/js/toast.ts +37 -0
  110. package/dist/homebridge-ui/public/js/types.d.ts +23 -0
  111. package/dist/homebridge-ui/public/js/types.d.ts.map +1 -0
  112. package/dist/homebridge-ui/public/js/types.js +2 -0
  113. package/dist/homebridge-ui/public/js/types.js.map +1 -0
  114. package/dist/homebridge-ui/public/js/types.ts +26 -0
  115. package/dist/homebridge-ui/server.js +11 -41
  116. package/dist/homebridge-ui/server.js.map +1 -1
  117. package/dist/homebridge-ui/utils/config-parser.d.ts +35 -0
  118. package/dist/homebridge-ui/utils/config-parser.d.ts.map +1 -0
  119. package/dist/homebridge-ui/utils/config-parser.js +87 -0
  120. package/dist/homebridge-ui/utils/config-parser.js.map +1 -0
  121. package/dist/homebridge-ui/utils/device-migration.d.ts +35 -0
  122. package/dist/homebridge-ui/utils/device-migration.d.ts.map +1 -0
  123. package/dist/homebridge-ui/utils/device-migration.js +111 -0
  124. package/dist/homebridge-ui/utils/device-migration.js.map +1 -0
  125. package/dist/homebridge-ui/utils/logger.d.ts +7 -0
  126. package/dist/homebridge-ui/utils/logger.d.ts.map +1 -0
  127. package/dist/homebridge-ui/utils/logger.js +17 -0
  128. package/dist/homebridge-ui/utils/logger.js.map +1 -0
  129. package/dist/index.d.ts.map +1 -1
  130. package/dist/index.js +1 -3
  131. package/dist/index.js.map +1 -1
  132. package/dist/platform.d.ts +39 -0
  133. package/dist/platform.d.ts.map +1 -0
  134. package/dist/platform.js +1553 -0
  135. package/dist/platform.js.map +1 -0
  136. package/dist/settings.d.ts +10 -249
  137. package/dist/settings.d.ts.map +1 -1
  138. package/dist/settings.js +5 -30
  139. package/dist/settings.js.map +1 -1
  140. package/dist/switchbotClient.d.ts +32 -0
  141. package/dist/switchbotClient.d.ts.map +1 -0
  142. package/dist/switchbotClient.js +253 -0
  143. package/dist/switchbotClient.js.map +1 -0
  144. package/dist/utils.d.ts +36 -82
  145. package/dist/utils.d.ts.map +1 -1
  146. package/dist/utils.js +40 -786
  147. package/dist/utils.js.map +1 -1
  148. package/docs/assets/highlight.css +21 -0
  149. package/docs/assets/icons.js +1 -1
  150. package/docs/assets/icons.svg +1 -1
  151. package/docs/assets/main.js +2 -2
  152. package/docs/assets/style.css +3 -3
  153. package/docs/index.html +103 -13
  154. package/docs/variables/default.html +1 -1
  155. package/eslint.config.js +7 -8
  156. package/nodemon.json +2 -2
  157. package/package.json +36 -32
  158. package/scripts/build-ui.js +36 -0
  159. package/scripts/e2e/README.md +25 -0
  160. package/scripts/e2e/curtain-e2e.sh +70 -0
  161. package/scripts/e2e/fan-e2e.sh +75 -0
  162. package/scripts/e2e/light-advanced-e2e.sh +97 -0
  163. package/scripts/e2e/light-e2e.sh +75 -0
  164. package/scripts/e2e/list-accessories.sh +19 -0
  165. package/scripts/e2e/lock-e2e.sh +65 -0
  166. package/scripts/free-dev-ports.mjs +105 -0
  167. package/scripts/generate-matter-maps.js +60 -0
  168. package/scripts/run-e2e-local.sh +14 -0
  169. package/scripts/sync-device-types.mjs +28 -0
  170. package/src/device-types.ts +261 -0
  171. package/src/deviceFactory.ts +190 -0
  172. package/src/devices/deviceBase.ts +141 -0
  173. package/src/devices/genericDevice.ts +1258 -0
  174. package/src/errors.ts +43 -0
  175. package/src/homebridge-ui/endpoints/config.ts +126 -0
  176. package/src/homebridge-ui/endpoints/credentials.ts +74 -0
  177. package/src/homebridge-ui/endpoints/devices.ts +464 -0
  178. package/src/homebridge-ui/endpoints/discovery.ts +225 -0
  179. package/src/homebridge-ui/public/css/styles.css +447 -0
  180. package/src/homebridge-ui/public/index.html +144 -248
  181. package/src/homebridge-ui/public/js/api.ts +272 -0
  182. package/src/homebridge-ui/public/js/app.ts +23 -0
  183. package/src/homebridge-ui/public/js/constants.ts +1 -0
  184. package/src/homebridge-ui/public/js/credentials.ts +100 -0
  185. package/src/homebridge-ui/public/js/devices-delete.ts +236 -0
  186. package/src/homebridge-ui/public/js/devices.ts +111 -0
  187. package/src/homebridge-ui/public/js/discovery.ts +1492 -0
  188. package/src/homebridge-ui/public/js/logger.ts +11 -0
  189. package/src/homebridge-ui/public/js/modal.ts +28 -0
  190. package/src/homebridge-ui/public/js/modals.ts +416 -0
  191. package/src/homebridge-ui/public/js/render.ts +1026 -0
  192. package/src/homebridge-ui/public/js/toast.ts +37 -0
  193. package/src/homebridge-ui/public/js/types.ts +26 -0
  194. package/src/homebridge-ui/server.ts +11 -43
  195. package/src/homebridge-ui/utils/config-parser.ts +108 -0
  196. package/src/homebridge-ui/utils/device-migration.ts +144 -0
  197. package/src/homebridge-ui/utils/logger.ts +17 -0
  198. package/src/index.ts +1 -3
  199. package/src/platform.ts +1568 -0
  200. package/src/settings.ts +12 -277
  201. package/src/switchbotClient.ts +251 -0
  202. package/src/utils.ts +48 -812
  203. package/test/accessory-restore.spec.ts +73 -0
  204. package/test/device-mapping.spec.ts +37 -0
  205. package/test/deviceFactory.spec.ts +18 -0
  206. package/test/e2e/run-e2e.spec.ts +52 -0
  207. package/test/fan-swing.spec.ts +29 -0
  208. package/test/helpers/matter-harness.ts +53 -0
  209. package/test/lock-users.spec.ts +44 -0
  210. package/test/matter-childbridge.spec.ts +59 -0
  211. package/test/matter-descriptors.spec.ts +97 -0
  212. package/test/matter-device-state.spec.ts +101 -0
  213. package/test/matter-integration.spec.ts +136 -0
  214. package/test/platform.integration.spec.ts +55 -0
  215. package/test/switchbot-client-debounce.spec.ts +131 -0
  216. package/test/switchbot-client-openapi.spec.ts +56 -0
  217. package/test/switchbotClient.spec.ts +10 -0
  218. package/test/utils.spec.ts +36 -0
  219. package/todo/COMPLETED.md +542 -0
  220. package/todo/README.md +59 -0
  221. package/todo/TODO.md +190 -0
  222. package/todo/mockups/filtering-sorting.svg +112 -0
  223. package/todo/mockups/modal-switchbot-theme.svg +66 -0
  224. package/todo/mockups/signal-strength-visualization.svg +94 -0
  225. package/vitest.config.ts +7 -0
  226. package/coverage/base.css +0 -224
  227. package/coverage/block-navigation.js +0 -87
  228. package/coverage/clover.xml +0 -15847
  229. package/coverage/coverage-final.json +0 -42
  230. package/coverage/docs/assets/dmt/dmt-component-data.js.html +0 -85
  231. package/coverage/docs/assets/dmt/dmt-components.js.html +0 -286
  232. package/coverage/docs/assets/dmt/index.html +0 -131
  233. package/coverage/docs/assets/hierarchy.js.html +0 -85
  234. package/coverage/docs/assets/icons.js.html +0 -136
  235. package/coverage/docs/assets/index.html +0 -146
  236. package/coverage/docs/assets/main.js.html +0 -265
  237. package/coverage/favicon.png +0 -0
  238. package/coverage/index.html +0 -191
  239. package/coverage/prettify.css +0 -1
  240. package/coverage/prettify.js +0 -2
  241. package/coverage/sort-arrow-sprite.png +0 -0
  242. package/coverage/sorter.js +0 -196
  243. package/coverage/src/device/blindtilt.ts.html +0 -3238
  244. package/coverage/src/device/bot.ts.html +0 -2803
  245. package/coverage/src/device/ceilinglight.ts.html +0 -2338
  246. package/coverage/src/device/colorbulb.ts.html +0 -2824
  247. package/coverage/src/device/contact.ts.html +0 -1465
  248. package/coverage/src/device/curtain.ts.html +0 -2869
  249. package/coverage/src/device/device.ts.html +0 -2500
  250. package/coverage/src/device/fan.ts.html +0 -2242
  251. package/coverage/src/device/hub.ts.html +0 -1408
  252. package/coverage/src/device/humidifier.ts.html +0 -2116
  253. package/coverage/src/device/index.html +0 -416
  254. package/coverage/src/device/iosensor.ts.html +0 -1375
  255. package/coverage/src/device/lightstrip.ts.html +0 -2617
  256. package/coverage/src/device/lock.ts.html +0 -1963
  257. package/coverage/src/device/meter.ts.html +0 -1372
  258. package/coverage/src/device/meterplus.ts.html +0 -1384
  259. package/coverage/src/device/meterpro.ts.html +0 -1618
  260. package/coverage/src/device/motion.ts.html +0 -1264
  261. package/coverage/src/device/plug.ts.html +0 -1372
  262. package/coverage/src/device/relayswitch.ts.html +0 -2284
  263. package/coverage/src/device/robotvacuumcleaner.ts.html +0 -1810
  264. package/coverage/src/device/waterdetector.ts.html +0 -1294
  265. package/coverage/src/homebridge-ui/index.html +0 -116
  266. package/coverage/src/homebridge-ui/server.ts.html +0 -229
  267. package/coverage/src/index.html +0 -161
  268. package/coverage/src/index.ts.html +0 -124
  269. package/coverage/src/irdevice/airconditioner.ts.html +0 -1687
  270. package/coverage/src/irdevice/airpurifier.ts.html +0 -844
  271. package/coverage/src/irdevice/camera.ts.html +0 -475
  272. package/coverage/src/irdevice/fan.ts.html +0 -766
  273. package/coverage/src/irdevice/index.html +0 -251
  274. package/coverage/src/irdevice/irdevice.ts.html +0 -1117
  275. package/coverage/src/irdevice/light.ts.html +0 -826
  276. package/coverage/src/irdevice/other.ts.html +0 -2458
  277. package/coverage/src/irdevice/tv.ts.html +0 -1222
  278. package/coverage/src/irdevice/vacuumcleaner.ts.html +0 -466
  279. package/coverage/src/irdevice/waterheater.ts.html +0 -469
  280. package/coverage/src/platform.ts.html +0 -8776
  281. package/coverage/src/settings.ts.html +0 -934
  282. package/coverage/src/utils.ts.html +0 -2092
  283. package/dist/devices-hap/airpurifier.d.ts +0 -54
  284. package/dist/devices-hap/airpurifier.d.ts.map +0 -1
  285. package/dist/devices-hap/airpurifier.js +0 -527
  286. package/dist/devices-hap/airpurifier.js.map +0 -1
  287. package/dist/devices-hap/blindtilt.d.ts +0 -90
  288. package/dist/devices-hap/blindtilt.d.ts.map +0 -1
  289. package/dist/devices-hap/blindtilt.js +0 -974
  290. package/dist/devices-hap/blindtilt.js.map +0 -1
  291. package/dist/devices-hap/bot.d.ts +0 -102
  292. package/dist/devices-hap/bot.d.ts.map +0 -1
  293. package/dist/devices-hap/bot.js +0 -811
  294. package/dist/devices-hap/bot.js.map +0 -1
  295. package/dist/devices-hap/ceilinglight.d.ts +0 -85
  296. package/dist/devices-hap/ceilinglight.d.ts.map +0 -1
  297. package/dist/devices-hap/ceilinglight.js +0 -701
  298. package/dist/devices-hap/ceilinglight.js.map +0 -1
  299. package/dist/devices-hap/colorbulb.d.ts +0 -88
  300. package/dist/devices-hap/colorbulb.d.ts.map +0 -1
  301. package/dist/devices-hap/colorbulb.js +0 -881
  302. package/dist/devices-hap/colorbulb.js.map +0 -1
  303. package/dist/devices-hap/contact.d.ts +0 -44
  304. package/dist/devices-hap/contact.d.ts.map +0 -1
  305. package/dist/devices-hap/contact.js +0 -409
  306. package/dist/devices-hap/contact.js.map +0 -1
  307. package/dist/devices-hap/curtain.d.ts +0 -73
  308. package/dist/devices-hap/curtain.d.ts.map +0 -1
  309. package/dist/devices-hap/curtain.js +0 -869
  310. package/dist/devices-hap/curtain.js.map +0 -1
  311. package/dist/devices-hap/device.d.ts +0 -98
  312. package/dist/devices-hap/device.d.ts.map +0 -1
  313. package/dist/devices-hap/device.js +0 -749
  314. package/dist/devices-hap/device.js.map +0 -1
  315. package/dist/devices-hap/fan.d.ts +0 -69
  316. package/dist/devices-hap/fan.d.ts.map +0 -1
  317. package/dist/devices-hap/fan.js +0 -649
  318. package/dist/devices-hap/fan.js.map +0 -1
  319. package/dist/devices-hap/hub.d.ts +0 -37
  320. package/dist/devices-hap/hub.d.ts.map +0 -1
  321. package/dist/devices-hap/hub.js +0 -392
  322. package/dist/devices-hap/hub.js.map +0 -1
  323. package/dist/devices-hap/humidifier.d.ts +0 -68
  324. package/dist/devices-hap/humidifier.d.ts.map +0 -1
  325. package/dist/devices-hap/humidifier.js +0 -628
  326. package/dist/devices-hap/humidifier.js.map +0 -1
  327. package/dist/devices-hap/iosensor.d.ts +0 -42
  328. package/dist/devices-hap/iosensor.d.ts.map +0 -1
  329. package/dist/devices-hap/iosensor.js +0 -382
  330. package/dist/devices-hap/iosensor.js.map +0 -1
  331. package/dist/devices-hap/lightstrip.d.ts +0 -79
  332. package/dist/devices-hap/lightstrip.d.ts.map +0 -1
  333. package/dist/devices-hap/lightstrip.js +0 -797
  334. package/dist/devices-hap/lightstrip.js.map +0 -1
  335. package/dist/devices-hap/lock.d.ts +0 -53
  336. package/dist/devices-hap/lock.d.ts.map +0 -1
  337. package/dist/devices-hap/lock.js +0 -561
  338. package/dist/devices-hap/lock.js.map +0 -1
  339. package/dist/devices-hap/meter.d.ts +0 -37
  340. package/dist/devices-hap/meter.d.ts.map +0 -1
  341. package/dist/devices-hap/meter.js +0 -379
  342. package/dist/devices-hap/meter.js.map +0 -1
  343. package/dist/devices-hap/meterplus.d.ts +0 -42
  344. package/dist/devices-hap/meterplus.d.ts.map +0 -1
  345. package/dist/devices-hap/meterplus.js +0 -384
  346. package/dist/devices-hap/meterplus.js.map +0 -1
  347. package/dist/devices-hap/meterpro.d.ts +0 -43
  348. package/dist/devices-hap/meterpro.d.ts.map +0 -1
  349. package/dist/devices-hap/meterpro.js +0 -468
  350. package/dist/devices-hap/meterpro.js.map +0 -1
  351. package/dist/devices-hap/motion.d.ts +0 -42
  352. package/dist/devices-hap/motion.d.ts.map +0 -1
  353. package/dist/devices-hap/motion.js +0 -345
  354. package/dist/devices-hap/motion.js.map +0 -1
  355. package/dist/devices-hap/plug.d.ts +0 -49
  356. package/dist/devices-hap/plug.d.ts.map +0 -1
  357. package/dist/devices-hap/plug.js +0 -395
  358. package/dist/devices-hap/plug.js.map +0 -1
  359. package/dist/devices-hap/relayswitch.d.ts +0 -96
  360. package/dist/devices-hap/relayswitch.d.ts.map +0 -1
  361. package/dist/devices-hap/relayswitch.js +0 -642
  362. package/dist/devices-hap/relayswitch.js.map +0 -1
  363. package/dist/devices-hap/robotvacuumcleaner.d.ts +0 -54
  364. package/dist/devices-hap/robotvacuumcleaner.d.ts.map +0 -1
  365. package/dist/devices-hap/robotvacuumcleaner.js +0 -523
  366. package/dist/devices-hap/robotvacuumcleaner.js.map +0 -1
  367. package/dist/devices-hap/waterdetector.d.ts +0 -41
  368. package/dist/devices-hap/waterdetector.d.ts.map +0 -1
  369. package/dist/devices-hap/waterdetector.js +0 -356
  370. package/dist/devices-hap/waterdetector.js.map +0 -1
  371. package/dist/devices-matter/BaseMatterAccessory.d.ts +0 -63
  372. package/dist/devices-matter/BaseMatterAccessory.d.ts.map +0 -1
  373. package/dist/devices-matter/BaseMatterAccessory.js +0 -100
  374. package/dist/devices-matter/BaseMatterAccessory.js.map +0 -1
  375. package/dist/devices-matter/ColorLightAccessory.d.ts +0 -20
  376. package/dist/devices-matter/ColorLightAccessory.d.ts.map +0 -1
  377. package/dist/devices-matter/ColorLightAccessory.js +0 -95
  378. package/dist/devices-matter/ColorLightAccessory.js.map +0 -1
  379. package/dist/devices-matter/ColorTemperatureLightAccessory.d.ts +0 -18
  380. package/dist/devices-matter/ColorTemperatureLightAccessory.d.ts.map +0 -1
  381. package/dist/devices-matter/ColorTemperatureLightAccessory.js +0 -78
  382. package/dist/devices-matter/ColorTemperatureLightAccessory.js.map +0 -1
  383. package/dist/devices-matter/ContactSensorAccessory.d.ts +0 -12
  384. package/dist/devices-matter/ContactSensorAccessory.d.ts.map +0 -1
  385. package/dist/devices-matter/ContactSensorAccessory.js +0 -34
  386. package/dist/devices-matter/ContactSensorAccessory.js.map +0 -1
  387. package/dist/devices-matter/DimmableLightAccessory.d.ts +0 -58
  388. package/dist/devices-matter/DimmableLightAccessory.d.ts.map +0 -1
  389. package/dist/devices-matter/DimmableLightAccessory.js +0 -167
  390. package/dist/devices-matter/DimmableLightAccessory.js.map +0 -1
  391. package/dist/devices-matter/DoorLockAccessory.d.ts +0 -14
  392. package/dist/devices-matter/DoorLockAccessory.d.ts.map +0 -1
  393. package/dist/devices-matter/DoorLockAccessory.js +0 -50
  394. package/dist/devices-matter/DoorLockAccessory.js.map +0 -1
  395. package/dist/devices-matter/ExtendedColorLightAccessory.d.ts +0 -21
  396. package/dist/devices-matter/ExtendedColorLightAccessory.d.ts.map +0 -1
  397. package/dist/devices-matter/ExtendedColorLightAccessory.js +0 -107
  398. package/dist/devices-matter/ExtendedColorLightAccessory.js.map +0 -1
  399. package/dist/devices-matter/FanAccessory.d.ts +0 -16
  400. package/dist/devices-matter/FanAccessory.d.ts.map +0 -1
  401. package/dist/devices-matter/FanAccessory.js +0 -81
  402. package/dist/devices-matter/FanAccessory.js.map +0 -1
  403. package/dist/devices-matter/HumiditySensorAccessory.d.ts +0 -12
  404. package/dist/devices-matter/HumiditySensorAccessory.d.ts.map +0 -1
  405. package/dist/devices-matter/HumiditySensorAccessory.js +0 -34
  406. package/dist/devices-matter/HumiditySensorAccessory.js.map +0 -1
  407. package/dist/devices-matter/LeakSensorAccessory.d.ts +0 -12
  408. package/dist/devices-matter/LeakSensorAccessory.d.ts.map +0 -1
  409. package/dist/devices-matter/LeakSensorAccessory.js +0 -33
  410. package/dist/devices-matter/LeakSensorAccessory.js.map +0 -1
  411. package/dist/devices-matter/LightSensorAccessory.d.ts +0 -12
  412. package/dist/devices-matter/LightSensorAccessory.d.ts.map +0 -1
  413. package/dist/devices-matter/LightSensorAccessory.js +0 -34
  414. package/dist/devices-matter/LightSensorAccessory.js.map +0 -1
  415. package/dist/devices-matter/OccupancySensorAccessory.d.ts +0 -12
  416. package/dist/devices-matter/OccupancySensorAccessory.d.ts.map +0 -1
  417. package/dist/devices-matter/OccupancySensorAccessory.js +0 -39
  418. package/dist/devices-matter/OccupancySensorAccessory.js.map +0 -1
  419. package/dist/devices-matter/OnOffLightAccessory.d.ts +0 -38
  420. package/dist/devices-matter/OnOffLightAccessory.d.ts.map +0 -1
  421. package/dist/devices-matter/OnOffLightAccessory.js +0 -118
  422. package/dist/devices-matter/OnOffLightAccessory.js.map +0 -1
  423. package/dist/devices-matter/OnOffOutletAccessory.d.ts +0 -12
  424. package/dist/devices-matter/OnOffOutletAccessory.d.ts.map +0 -1
  425. package/dist/devices-matter/OnOffOutletAccessory.js +0 -40
  426. package/dist/devices-matter/OnOffOutletAccessory.js.map +0 -1
  427. package/dist/devices-matter/OnOffSwitchAccessory.d.ts +0 -14
  428. package/dist/devices-matter/OnOffSwitchAccessory.d.ts.map +0 -1
  429. package/dist/devices-matter/OnOffSwitchAccessory.js +0 -42
  430. package/dist/devices-matter/OnOffSwitchAccessory.js.map +0 -1
  431. package/dist/devices-matter/RoboticVacuumAccessory.d.ts +0 -68
  432. package/dist/devices-matter/RoboticVacuumAccessory.d.ts.map +0 -1
  433. package/dist/devices-matter/RoboticVacuumAccessory.js +0 -334
  434. package/dist/devices-matter/RoboticVacuumAccessory.js.map +0 -1
  435. package/dist/devices-matter/SmokeCOAlarmAccessory.d.ts +0 -11
  436. package/dist/devices-matter/SmokeCOAlarmAccessory.d.ts.map +0 -1
  437. package/dist/devices-matter/SmokeCOAlarmAccessory.js +0 -49
  438. package/dist/devices-matter/SmokeCOAlarmAccessory.js.map +0 -1
  439. package/dist/devices-matter/TemperatureSensorAccessory.d.ts +0 -12
  440. package/dist/devices-matter/TemperatureSensorAccessory.d.ts.map +0 -1
  441. package/dist/devices-matter/TemperatureSensorAccessory.js +0 -36
  442. package/dist/devices-matter/TemperatureSensorAccessory.js.map +0 -1
  443. package/dist/devices-matter/ThermostatAccessory.d.ts +0 -19
  444. package/dist/devices-matter/ThermostatAccessory.d.ts.map +0 -1
  445. package/dist/devices-matter/ThermostatAccessory.js +0 -95
  446. package/dist/devices-matter/ThermostatAccessory.js.map +0 -1
  447. package/dist/devices-matter/VenetianBlindAccessory.d.ts +0 -19
  448. package/dist/devices-matter/VenetianBlindAccessory.d.ts.map +0 -1
  449. package/dist/devices-matter/VenetianBlindAccessory.js +0 -99
  450. package/dist/devices-matter/VenetianBlindAccessory.js.map +0 -1
  451. package/dist/devices-matter/WindowBlindAccessory.d.ts +0 -17
  452. package/dist/devices-matter/WindowBlindAccessory.d.ts.map +0 -1
  453. package/dist/devices-matter/WindowBlindAccessory.js +0 -80
  454. package/dist/devices-matter/WindowBlindAccessory.js.map +0 -1
  455. package/dist/devices-matter/custom/PowerStripAccessory.d.ts +0 -97
  456. package/dist/devices-matter/custom/PowerStripAccessory.d.ts.map +0 -1
  457. package/dist/devices-matter/custom/PowerStripAccessory.js +0 -265
  458. package/dist/devices-matter/custom/PowerStripAccessory.js.map +0 -1
  459. package/dist/devices-matter/custom/index.d.ts +0 -8
  460. package/dist/devices-matter/custom/index.d.ts.map +0 -1
  461. package/dist/devices-matter/custom/index.js +0 -8
  462. package/dist/devices-matter/custom/index.js.map +0 -1
  463. package/dist/devices-matter/index.d.ts +0 -29
  464. package/dist/devices-matter/index.d.ts.map +0 -1
  465. package/dist/devices-matter/index.js +0 -28
  466. package/dist/devices-matter/index.js.map +0 -1
  467. package/dist/index.test.d.ts +0 -2
  468. package/dist/index.test.d.ts.map +0 -1
  469. package/dist/index.test.js +0 -19
  470. package/dist/index.test.js.map +0 -1
  471. package/dist/irdevice/airconditioner.d.ts +0 -61
  472. package/dist/irdevice/airconditioner.d.ts.map +0 -1
  473. package/dist/irdevice/airconditioner.js +0 -472
  474. package/dist/irdevice/airconditioner.js.map +0 -1
  475. package/dist/irdevice/airpurifier.d.ts +0 -50
  476. package/dist/irdevice/airpurifier.d.ts.map +0 -1
  477. package/dist/irdevice/airpurifier.js +0 -213
  478. package/dist/irdevice/airpurifier.js.map +0 -1
  479. package/dist/irdevice/camera.d.ts +0 -32
  480. package/dist/irdevice/camera.d.ts.map +0 -1
  481. package/dist/irdevice/camera.js +0 -107
  482. package/dist/irdevice/camera.js.map +0 -1
  483. package/dist/irdevice/fan.d.ts +0 -36
  484. package/dist/irdevice/fan.d.ts.map +0 -1
  485. package/dist/irdevice/fan.js +0 -200
  486. package/dist/irdevice/fan.js.map +0 -1
  487. package/dist/irdevice/irdevice.d.ts +0 -68
  488. package/dist/irdevice/irdevice.d.ts.map +0 -1
  489. package/dist/irdevice/irdevice.js +0 -298
  490. package/dist/irdevice/irdevice.js.map +0 -1
  491. package/dist/irdevice/light.d.ts +0 -36
  492. package/dist/irdevice/light.d.ts.map +0 -1
  493. package/dist/irdevice/light.js +0 -206
  494. package/dist/irdevice/light.js.map +0 -1
  495. package/dist/irdevice/other.d.ts +0 -57
  496. package/dist/irdevice/other.d.ts.map +0 -1
  497. package/dist/irdevice/other.js +0 -778
  498. package/dist/irdevice/other.js.map +0 -1
  499. package/dist/irdevice/tv.d.ts +0 -45
  500. package/dist/irdevice/tv.d.ts.map +0 -1
  501. package/dist/irdevice/tv.js +0 -327
  502. package/dist/irdevice/tv.js.map +0 -1
  503. package/dist/irdevice/vacuumcleaner.d.ts +0 -28
  504. package/dist/irdevice/vacuumcleaner.d.ts.map +0 -1
  505. package/dist/irdevice/vacuumcleaner.js +0 -104
  506. package/dist/irdevice/vacuumcleaner.js.map +0 -1
  507. package/dist/irdevice/waterheater.d.ts +0 -30
  508. package/dist/irdevice/waterheater.d.ts.map +0 -1
  509. package/dist/irdevice/waterheater.js +0 -105
  510. package/dist/irdevice/waterheater.js.map +0 -1
  511. package/dist/platform-hap.d.ts +0 -149
  512. package/dist/platform-hap.d.ts.map +0 -1
  513. package/dist/platform-hap.js +0 -2861
  514. package/dist/platform-hap.js.map +0 -1
  515. package/dist/platform-matter.d.ts +0 -120
  516. package/dist/platform-matter.d.ts.map +0 -1
  517. package/dist/platform-matter.js +0 -984
  518. package/dist/platform-matter.js.map +0 -1
  519. package/dist/utils.test.d.ts +0 -2
  520. package/dist/utils.test.d.ts.map +0 -1
  521. package/dist/utils.test.js +0 -95
  522. package/dist/utils.test.js.map +0 -1
  523. package/dist/verifyconfig.test.d.ts +0 -2
  524. package/dist/verifyconfig.test.d.ts.map +0 -1
  525. package/dist/verifyconfig.test.js +0 -167
  526. package/dist/verifyconfig.test.js.map +0 -1
  527. package/src/custom.d.ts +0 -7
  528. package/src/devices-hap/airpurifier.ts +0 -563
  529. package/src/devices-hap/blindtilt.ts +0 -1049
  530. package/src/devices-hap/bot.ts +0 -900
  531. package/src/devices-hap/ceilinglight.ts +0 -742
  532. package/src/devices-hap/colorbulb.ts +0 -904
  533. package/src/devices-hap/contact.ts +0 -457
  534. package/src/devices-hap/curtain.ts +0 -944
  535. package/src/devices-hap/device.ts +0 -811
  536. package/src/devices-hap/fan.ts +0 -711
  537. package/src/devices-hap/hub.ts +0 -439
  538. package/src/devices-hap/humidifier.ts +0 -669
  539. package/src/devices-hap/iosensor.ts +0 -427
  540. package/src/devices-hap/lightstrip.ts +0 -836
  541. package/src/devices-hap/lock.ts +0 -620
  542. package/src/devices-hap/meter.ts +0 -426
  543. package/src/devices-hap/meterplus.ts +0 -430
  544. package/src/devices-hap/meterpro.ts +0 -522
  545. package/src/devices-hap/motion.ts +0 -390
  546. package/src/devices-hap/plug.ts +0 -423
  547. package/src/devices-hap/relayswitch.ts +0 -727
  548. package/src/devices-hap/robotvacuumcleaner.ts +0 -568
  549. package/src/devices-hap/waterdetector.ts +0 -400
  550. package/src/devices-matter/BaseMatterAccessory.ts +0 -131
  551. package/src/devices-matter/ColorLightAccessory.ts +0 -110
  552. package/src/devices-matter/ColorTemperatureLightAccessory.ts +0 -92
  553. package/src/devices-matter/ContactSensorAccessory.ts +0 -41
  554. package/src/devices-matter/DimmableLightAccessory.ts +0 -192
  555. package/src/devices-matter/DoorLockAccessory.ts +0 -60
  556. package/src/devices-matter/ExtendedColorLightAccessory.ts +0 -123
  557. package/src/devices-matter/FanAccessory.ts +0 -95
  558. package/src/devices-matter/HumiditySensorAccessory.ts +0 -41
  559. package/src/devices-matter/LeakSensorAccessory.ts +0 -40
  560. package/src/devices-matter/LightSensorAccessory.ts +0 -41
  561. package/src/devices-matter/OccupancySensorAccessory.ts +0 -48
  562. package/src/devices-matter/OnOffLightAccessory.ts +0 -133
  563. package/src/devices-matter/OnOffOutletAccessory.ts +0 -46
  564. package/src/devices-matter/OnOffSwitchAccessory.ts +0 -51
  565. package/src/devices-matter/RoboticVacuumAccessory.ts +0 -407
  566. package/src/devices-matter/SmokeCOAlarmAccessory.ts +0 -59
  567. package/src/devices-matter/TemperatureSensorAccessory.ts +0 -43
  568. package/src/devices-matter/ThermostatAccessory.ts +0 -110
  569. package/src/devices-matter/VenetianBlindAccessory.ts +0 -115
  570. package/src/devices-matter/WindowBlindAccessory.ts +0 -92
  571. package/src/devices-matter/custom/PowerStripAccessory.ts +0 -309
  572. package/src/devices-matter/custom/index.ts +0 -8
  573. package/src/devices-matter/index.ts +0 -29
  574. package/src/index.test.ts +0 -24
  575. package/src/irdevice/airconditioner.ts +0 -533
  576. package/src/irdevice/airpurifier.ts +0 -252
  577. package/src/irdevice/camera.ts +0 -129
  578. package/src/irdevice/fan.ts +0 -226
  579. package/src/irdevice/irdevice.ts +0 -344
  580. package/src/irdevice/light.ts +0 -246
  581. package/src/irdevice/other.ts +0 -790
  582. package/src/irdevice/tv.ts +0 -378
  583. package/src/irdevice/vacuumcleaner.ts +0 -126
  584. package/src/irdevice/waterheater.ts +0 -127
  585. package/src/platform-hap.ts +0 -2997
  586. package/src/platform-matter.ts +0 -1110
  587. package/src/utils.test.ts +0 -96
  588. package/src/verifyconfig.test.ts +0 -197
@@ -1,1110 +0,0 @@
1
- import type {
2
- API,
3
- DynamicPlatformPlugin,
4
- Logging,
5
- MatterAccessory,
6
- SerializedMatterAccessory,
7
- } from 'homebridge'
8
- import type { bodyChange, device } from 'node-switchbot'
9
-
10
- import type { SwitchBotPlatformConfig } from './settings.js'
11
-
12
- import { SwitchBotBLE, SwitchBotOpenAPI } from 'node-switchbot'
13
-
14
- import {
15
- ColorLightAccessory,
16
- ColorTemperatureLightAccessory,
17
- ContactSensorAccessory,
18
- DimmableLightAccessory,
19
- DoorLockAccessory,
20
- ExtendedColorLightAccessory,
21
- FanAccessory,
22
- HumiditySensorAccessory,
23
- LeakSensorAccessory,
24
- LightSensorAccessory,
25
- OccupancySensorAccessory,
26
- OnOffLightAccessory,
27
- OnOffOutletAccessory,
28
- OnOffSwitchAccessory,
29
- PowerStripAccessory,
30
- RoboticVacuumAccessory,
31
- SmokeCOAlarmAccessory,
32
- TemperatureSensorAccessory,
33
- ThermostatAccessory,
34
- VenetianBlindAccessory,
35
- WindowBlindAccessory,
36
- } from './devices-matter/index.js'
37
- import { PLATFORM_NAME, PLUGIN_NAME } from './settings.js'
38
- import { cleanDeviceConfig, formatDeviceIdAsMac, hs2rgb, rgb2hs, sleep } from './utils.js'
39
-
40
- /**
41
- * MatterPlatform
42
- * Demonstrates all available Matter device types in Homebridge
43
- *
44
- * Organized by official Matter Specification v1.4.1 categories
45
- */
46
- export class SwitchBotMatterPlatform implements DynamicPlatformPlugin {
47
- // Track restored HAP cached accessories (required for DynamicPlatformPlugin)
48
- // This is commented out here as this plugin does not have any HAP accessories
49
- // public readonly accessories: Map<string, PlatformAccessory> = new Map()
50
-
51
- // Track restored Matter cached accessories
52
- public readonly matterAccessories: Map<string, SerializedMatterAccessory> = new Map()
53
- // node-switchbot clients
54
- private switchBotAPI?: SwitchBotOpenAPI
55
- private switchBotBLE?: SwitchBotBLE
56
- // discovered devices cache
57
- private discoveredDevices: device[] = []
58
- // BLE event handlers keyed by device MAC (formatted)
59
- private bleEventHandler: { [x: string]: (context: any) => void } = {}
60
-
61
- constructor(
62
- public readonly log: Logging,
63
- public readonly config: SwitchBotPlatformConfig,
64
- public readonly api: API,
65
- ) {
66
- this.log.debug('Finished initializing platform:', this.config.name)
67
-
68
- // Normalize deviceConfig to remove UI-inserted defaults
69
- try {
70
- if ((this.config as any).options) {
71
- const cleaned = cleanDeviceConfig((this.config as any).options.deviceConfig)
72
- if (cleaned) {
73
- ;(this.config as any).options.deviceConfig = cleaned
74
- } else {
75
- delete (this.config as any).options.deviceConfig
76
- }
77
- }
78
- } catch (e) {
79
- this.log.debug('Failed to clean deviceConfig: %s', e)
80
- }
81
-
82
- // Does the user have a version of Homebridge that is compatible with matter?
83
- if (!this.api.isMatterAvailable?.()) {
84
- this.log.warn('Matter is not available in this version of Homebridge. Please update Homebridge to use this plugin.')
85
- }
86
-
87
- // Check if the user has matter enabled, this means:
88
- // - If the plugin is running on the main bridge, then the user must have enabled matter in the Homebridge settings page in the UI
89
- // - If the plugin is running on a child bridge, then the user must have enabled matter on the plugin bridge settings section in the UI
90
- // In reality, only the below check is needed, but they are both included here for completeness
91
- // Remember to use a '?.' optional chaining operator in case the user is running an older version of Homebridge that does not have these APIs
92
- if (!this.api.isMatterEnabled?.()) {
93
- this.log.warn('Matter is not enabled in Homebridge. Please enable Matter in the Homebridge settings to use this plugin.')
94
- return
95
- }
96
-
97
- // Register Matter accessories when Homebridge has finished launching
98
- this.api.on('didFinishLaunching', () => {
99
- this.log.debug('Executed didFinishLaunching callback')
100
- // Initialize SwitchBot API clients
101
- try {
102
- if (this.config.credentials?.token && this.config.credentials?.secret) {
103
- this.switchBotAPI = new SwitchBotOpenAPI(this.config.credentials.token, this.config.credentials.secret, this.config.options?.hostname)
104
- // forward basic logs
105
- if (!this.config.options?.disableLogsforOpenAPI && this.switchBotAPI?.on) {
106
- this.switchBotAPI.on('log', (l: any) => this.log.debug('[SwitchBot OpenAPI]', l.message))
107
- }
108
- } else {
109
- this.log.debug('SwitchBot OpenAPI credentials not provided; cloud devices will be skipped')
110
- }
111
- } catch (e: any) {
112
- this.log.error('Failed to initialize SwitchBot OpenAPI:', e?.message ?? e)
113
- }
114
-
115
- try {
116
- this.switchBotBLE = new SwitchBotBLE()
117
- if (!this.config.options?.disableLogsforBLE && this.switchBotBLE?.on) {
118
- this.switchBotBLE.on('log', (l: any) => this.log.debug('[SwitchBot BLE]', l.message))
119
- }
120
- } catch (e: any) {
121
- this.log.error('Failed to initialize SwitchBot BLE client:', e?.message ?? e)
122
- }
123
-
124
- // If BLE scanning is enabled, start scanning and route advertisements to registered handlers
125
- if (this.config.options?.BLE && this.switchBotBLE) {
126
- const ble = this.switchBotBLE
127
- ;(async () => {
128
- try {
129
- await ble.startScan()
130
- } catch (e: any) {
131
- this.log.error(`Failed to start BLE scanning: ${e?.message ?? e}`)
132
- }
133
-
134
- // route advertisements to our handlers
135
- ble.onadvertisement = async (ad: any) => {
136
- try {
137
- const mac = (ad.address || '').toLowerCase()
138
- const handler = this.bleEventHandler[mac]
139
- if (handler) {
140
- await handler(ad.serviceData)
141
- }
142
- } catch (e: any) {
143
- this.log.error(`Failed to handle BLE advertisement: ${e?.message ?? e}`)
144
- }
145
- }
146
- })()
147
- }
148
-
149
- // perform device discovery from SwitchBot OpenAPI (if configured)
150
- void this.discoverDevices()
151
-
152
- this.registerMatterAccessories()
153
- })
154
- }
155
-
156
- /**
157
- * Normalize a deviceId for matching (uppercase alphanumerics only)
158
- */
159
- private normalizeDeviceId(deviceId: string) {
160
- return (deviceId ?? '').toUpperCase().replace(/[^A-Z0-9]+/g, '')
161
- }
162
-
163
- /**
164
- * Merge two arrays by deviceId. For each item in a1 (user-provided devices list),
165
- * find matching item in a2 (discovered devices) and merge them with user overrides last.
166
- */
167
- private mergeByDeviceId(a1: { deviceId: string }[], a2: any[]) {
168
- return a1.map((itm) => {
169
- const matchingItem = a2.find(item => this.normalizeDeviceId(item.deviceId) === this.normalizeDeviceId(itm.deviceId))
170
- return Object.assign({}, matchingItem, itm)
171
- })
172
- }
173
-
174
- /**
175
- * Merge discovered devices with deviceConfig (per deviceType) and per-device overrides
176
- * from `config.options.devices`, matching the behavior used in platform-hap.
177
- */
178
- private async mergeDiscoveredDevices(discovered: device[]): Promise<any[]> {
179
- // If there's no device config or per-device config, return discovered as-is
180
- if (!this.config.options?.devices && !this.config.options?.deviceConfig) {
181
- return discovered
182
- }
183
-
184
- // Step 1: Assign missing deviceType from configDeviceType and merge deviceType-level configs
185
- const devicesWithTypeConfig = await Promise.all(discovered.map(async (deviceObj) => {
186
- if (!deviceObj.deviceType) {
187
- deviceObj.deviceType = (deviceObj as any).configDeviceType !== undefined ? (deviceObj as any).configDeviceType : 'Unknown'
188
- this.log.debug(`API missing deviceType for ${deviceObj.deviceId}, using configDeviceType: ${(deviceObj as any).configDeviceType}`)
189
- }
190
- const deviceTypeConfig = this.config.options?.deviceConfig?.[deviceObj.deviceType] || {}
191
- return Object.assign({}, deviceObj, deviceTypeConfig)
192
- }))
193
-
194
- // Merge per-device overrides by matching deviceId
195
- const merged = this.mergeByDeviceId(this.config.options?.devices ?? [], devicesWithTypeConfig ?? [])
196
-
197
- // For any entries in merged (which are based on config.options.devices), ensure final per-device merges include deviceId-specific config
198
- const final: any[] = []
199
- for (const device of merged) {
200
- const deviceIdConfig = this.config.options?.devices?.[device.deviceId] || {}
201
- const deviceWithConfig = Object.assign({}, device, deviceIdConfig)
202
- final.push(deviceWithConfig)
203
- }
204
-
205
- // Also include any discovered devices that weren't present in the user devices list
206
- const userDeviceIds = new Set((this.config.options?.devices || []).map((d: any) => this.normalizeDeviceId(d.deviceId)))
207
- for (const d of devicesWithTypeConfig) {
208
- if (!userDeviceIds.has(this.normalizeDeviceId(d.deviceId))) {
209
- final.push(d)
210
- }
211
- }
212
-
213
- return final
214
- }
215
-
216
- /**
217
- * Select effective connection type for a device: prefer explicit device.connectionType,
218
- * otherwise prefer BLE when platform BLE is enabled and device provides a BLE model/id.
219
- */
220
- private chooseConnectionType(deviceObj: any): 'BLE' | 'OpenAPI' {
221
- if (deviceObj?.connectionType) {
222
- return deviceObj.connectionType === 'BLE' ? 'BLE' : 'OpenAPI'
223
- }
224
- // If platform BLE is enabled and we have a bleModel or deviceId that formats to a MAC, prefer BLE
225
- if (this.config.options?.BLE && (deviceObj?.bleModel || formatDeviceIdAsMac(deviceObj?.deviceId))) {
226
- return 'BLE'
227
- }
228
- return 'OpenAPI'
229
- }
230
-
231
- /**
232
- * Map a SwitchBot device object to a MatterAccessory using the device-specific
233
- * Matter accessory classes in `src/devices-matter`.
234
- */
235
- private async createAccessoryFromDevice(dev: device): Promise<MatterAccessory<Record<string, unknown>> | undefined> {
236
- // Basic metadata
237
- const displayName = dev.deviceName ?? dev.deviceId ?? 'SwitchBot Device'
238
- const serial = dev.deviceId ?? 'unknown'
239
- const manufacturer = 'SwitchBot'
240
- const model = dev.deviceType ?? 'SwitchBot'
241
- const firmware = (dev as any).firmware ?? (dev as any).version ?? '0.0.0'
242
-
243
- // Helper to build a default opts object consumed by the matter device classes
244
- const baseOpts = {
245
- uuid: this.api.matter.uuid.generate(serial),
246
- displayName,
247
- serialNumber: serial,
248
- manufacturer,
249
- model,
250
- firmwareRevision: String(firmware),
251
- hardwareRevision: '1.0.0',
252
- deviceId: dev.deviceId,
253
- context: { deviceId: dev.deviceId },
254
- }
255
-
256
- // Small helper to wrap common OpenAPI on/off commands
257
- // Helper to send an OpenAPI command
258
- const sendOpenAPI = async (command: string, parameter = 'default') => {
259
- const bodyChange: bodyChange = { command, parameter, commandType: 'command' }
260
- return this.retryCommand(dev, bodyChange, this.config.options?.maxRetries ?? 1, this.config.options?.delayBetweenRetries ?? 1000)
261
- }
262
-
263
- // Helper to send a BLE action if Platform BLE is enabled and switchBotBLE exists
264
- const sendBLE = async (methodName: string, ...args: any[]) => {
265
- // Provide a small retry loop for flaky BLE operations
266
- if (!this.switchBotBLE) {
267
- throw new Error('Platform BLE not available')
268
- }
269
- const id = formatDeviceIdAsMac(dev.deviceId)
270
- const maxRetries = (this.config.options as any)?.bleRetries ?? 2
271
- const retryDelay = (this.config.options as any)?.bleRetryDelay ?? 500
272
- let attempt = 0
273
- while (attempt < maxRetries) {
274
- try {
275
- const list = await this.switchBotBLE.discover({ model: (dev as any).bleModel, id })
276
- if (!Array.isArray(list) || list.length === 0) {
277
- throw new Error('BLE device not found')
278
- }
279
- const deviceInst: any = list[0]
280
- if (typeof deviceInst[methodName] !== 'function') {
281
- throw new TypeError(`BLE method ${methodName} not available on device`)
282
- }
283
- return await deviceInst[methodName](...args)
284
- } catch (e: any) {
285
- attempt++
286
- if (attempt >= maxRetries) {
287
- throw e
288
- }
289
- this.log.debug(`BLE ${methodName} attempt ${attempt} failed for ${dev.deviceId}: ${e?.message ?? e}, retrying in ${retryDelay}ms`)
290
- await sleep(retryDelay)
291
- }
292
- }
293
- throw new Error('BLE operation failed')
294
- }
295
-
296
- const makeOnOffHandlers = (uuid: string, connectionType: 'BLE' | 'OpenAPI') => ({
297
- onOff: {
298
- on: async () => {
299
- try {
300
- if (connectionType === 'BLE' && this.switchBotBLE) {
301
- await sendBLE('turnOn')
302
- } else {
303
- await sendOpenAPI('turnOn')
304
- }
305
- await this.api.matter.updateAccessoryState(uuid, this.api.matter.clusterNames.OnOff, { onOff: true })
306
- } catch (e: any) {
307
- this.log.error(`Failed to turn on device ${dev.deviceId}: ${e?.message ?? e}`)
308
- }
309
- },
310
- off: async () => {
311
- try {
312
- if (connectionType === 'BLE' && this.switchBotBLE) {
313
- await sendBLE('turnOff')
314
- } else {
315
- await sendOpenAPI('turnOff')
316
- }
317
- await this.api.matter.updateAccessoryState(uuid, this.api.matter.clusterNames.OnOff, { onOff: false })
318
- } catch (e: any) {
319
- this.log.error(`Failed to turn off device ${dev.deviceId}: ${e?.message ?? e}`)
320
- }
321
- },
322
- },
323
- })
324
-
325
- // Mapping from SwitchBot deviceType -> constructor (expanded for parity with HAP)
326
- const mapping: { [key: string]: any } = {
327
- // Plugs / Outlets
328
- 'Plug': OnOffOutletAccessory,
329
- 'Plug Mini (US)': OnOffOutletAccessory,
330
- 'Plug Mini (JP)': OnOffOutletAccessory,
331
- 'Plug Mini': OnOffOutletAccessory,
332
- 'WoPlug': OnOffOutletAccessory,
333
-
334
- // Lighting
335
- 'Color Bulb': ColorLightAccessory,
336
- 'Color Bulb Mini': ColorLightAccessory,
337
- 'Ceiling Light': ColorTemperatureLightAccessory,
338
- 'Ceiling Light Pro': ColorTemperatureLightAccessory,
339
- 'Strip Light': ExtendedColorLightAccessory,
340
- 'Light Strip': ExtendedColorLightAccessory,
341
- 'Light Strip Plus': ExtendedColorLightAccessory,
342
- 'Strip Light Pro': ExtendedColorLightAccessory,
343
- 'Dimmable Light': DimmableLightAccessory,
344
-
345
- // Robot Vacuums
346
- 'K10+': RoboticVacuumAccessory,
347
- 'K10+ Pro': RoboticVacuumAccessory,
348
- 'WoSweeper': RoboticVacuumAccessory,
349
- 'WoSweeperMini': RoboticVacuumAccessory,
350
- 'Robot Vacuum Cleaner S1': RoboticVacuumAccessory,
351
- 'Robot Vacuum Cleaner S1 Plus': RoboticVacuumAccessory,
352
- 'Robot Vacuum Cleaner S10': RoboticVacuumAccessory,
353
- 'Robot Vacuum Cleaner S1 Pro': RoboticVacuumAccessory,
354
- 'Robot Vacuum Cleaner S1 Mini': RoboticVacuumAccessory,
355
-
356
- // Locks
357
- 'Smart Lock': DoorLockAccessory,
358
- 'Smart Lock Pro': DoorLockAccessory,
359
-
360
- // Sensors
361
- 'Motion Sensor': OccupancySensorAccessory,
362
- 'Contact Sensor': ContactSensorAccessory,
363
- 'Water Detector': LeakSensorAccessory,
364
- 'Meter': TemperatureSensorAccessory,
365
- 'MeterPlus': TemperatureSensorAccessory,
366
- 'MeterPro': TemperatureSensorAccessory,
367
- 'WoIOSensor': TemperatureSensorAccessory,
368
- 'Air Purifier PM2.5': HumiditySensorAccessory,
369
- 'Air Purifier Table PM2.5': HumiditySensorAccessory,
370
- 'Air Purifier': HumiditySensorAccessory,
371
- 'Air Purifier VOC': HumiditySensorAccessory,
372
- 'Air Purifier Table VOC': HumiditySensorAccessory,
373
-
374
- // Fans
375
- 'Battery Circulator Fan': FanAccessory,
376
-
377
- // Curtains / Blinds
378
- 'Blind Tilt': VenetianBlindAccessory,
379
- 'Curtain': WindowBlindAccessory,
380
- 'Curtain2': WindowBlindAccessory,
381
- 'Curtain3': WindowBlindAccessory,
382
- 'Curtain 2': WindowBlindAccessory,
383
- 'WoRollerShade': WindowBlindAccessory,
384
- 'Roller Shade': WindowBlindAccessory,
385
- 'Venetian Blind': VenetianBlindAccessory,
386
-
387
- // Switches / Relays
388
- 'Relay Switch 1': OnOffSwitchAccessory,
389
- 'Relay Switch 1PM': OnOffSwitchAccessory,
390
- 'Relay Switch 2': OnOffSwitchAccessory,
391
- 'Relay Switch 3': OnOffSwitchAccessory,
392
-
393
- // Misc / hubs / other
394
- 'Hub 2': undefined,
395
- 'Hub 3': undefined,
396
- 'Hub Mini': undefined,
397
- 'Bot': OnOffSwitchAccessory,
398
- 'Smart Bot': OnOffSwitchAccessory,
399
- 'Humidifier': HumiditySensorAccessory,
400
- 'Humidifier2': HumiditySensorAccessory,
401
- 'Thermostat': ThermostatAccessory,
402
- 'Water Heater': ThermostatAccessory,
403
- }
404
-
405
- const Ctor = mapping[dev.deviceType ?? '']
406
- if (!Ctor) {
407
- this.log.debug(`No Matter mapping for deviceType='${dev.deviceType}', deviceId=${dev.deviceId}`)
408
- return undefined
409
- }
410
-
411
- // Build opts and handlers tailored for basic capabilities
412
- const uuid = baseOpts.uuid
413
- const handlers: Record<string, any> = {}
414
-
415
- // Choose connection type for this device (BLE vs OpenAPI)
416
- const connectionType = this.chooseConnectionType(dev)
417
-
418
- // On/Off common
419
- handlers.onOff = makeOnOffHandlers(uuid, connectionType).onOff
420
-
421
- // If this is a light, add brightness and color handlers
422
- if (['Color Bulb', 'Ceiling Light', 'Ceiling Light Pro', 'Strip Light', 'Dimmable Light'].includes(dev.deviceType ?? '')) {
423
- // levelControl
424
- handlers.levelControl = {
425
- moveToLevelWithOnOff: async (request: any) => {
426
- try {
427
- const level = request.level as number
428
- const percent = Math.round((level / 254) * 100)
429
- if (connectionType === 'BLE' && this.switchBotBLE) {
430
- await sendBLE('setBrightness', percent)
431
- } else {
432
- await sendOpenAPI('setBrightness', `${percent}`)
433
- }
434
- await this.api.matter.updateAccessoryState(uuid, this.api.matter.clusterNames.LevelControl, { currentLevel: level })
435
- } catch (e: any) {
436
- this.log.error(`Failed to set brightness for ${dev.deviceId}: ${e?.message ?? e}`)
437
- }
438
- },
439
- }
440
-
441
- // colorControl
442
- handlers.colorControl = {
443
- moveToHueAndSaturationLogic: async (request: any) => {
444
- try {
445
- const hue = request.hue as number
446
- const saturation = request.saturation as number
447
- const [r, g, b] = hs2rgb(Math.round((hue / 254) * 360), Math.round((saturation / 254) * 100))
448
- if (connectionType === 'BLE' && this.switchBotBLE) {
449
- await sendBLE('setRGB', Number(request.level ?? 100), r, g, b)
450
- } else {
451
- await sendOpenAPI('setColor', `${r}:${g}:${b}`)
452
- }
453
- await this.api.matter.updateAccessoryState(uuid, this.api.matter.clusterNames.ColorControl, { currentHue: hue, currentSaturation: saturation })
454
- } catch (e: any) {
455
- this.log.error(`Failed to set hue/sat for ${dev.deviceId}: ${e?.message ?? e}`)
456
- }
457
- },
458
- moveToColorLogic: async (request: any) => {
459
- try {
460
- // MoveToColor gives colorX/colorY values; convert to approximate RGB by mapping to 0-255 scale
461
- const colorX = request.colorX as number
462
- const colorY = request.colorY as number
463
- // Naive conversion: map X/Y into RGB via hue approximation (not colorimetrically accurate)
464
- const hueApprox = Math.round((colorX / 65535) * 360)
465
- const satApprox = Math.round((colorY / 65535) * 100)
466
- const [r, g, b] = hs2rgb(hueApprox, satApprox)
467
- if (connectionType === 'BLE' && this.switchBotBLE) {
468
- await sendBLE('setRGB', Number(request.level ?? 100), r, g, b)
469
- } else {
470
- await sendOpenAPI('setColor', `${r}:${g}:${b}`)
471
- }
472
- await this.api.matter.updateAccessoryState(uuid, this.api.matter.clusterNames.ColorControl, { currentX: colorX, currentY: colorY })
473
- } catch (e: any) {
474
- this.log.error(`Failed to set XY color for ${dev.deviceId}: ${e?.message ?? e}`)
475
- }
476
- },
477
- }
478
-
479
- // color temperature — map to kelvin and send setColorTemperature
480
- handlers.colorTemperature = {
481
- moveToColorTemperature: async (request: any) => {
482
- try {
483
- const kelvin = Math.round(1000000 / Number(request.colorTemperature))
484
- if (connectionType === 'BLE' && this.switchBotBLE) {
485
- await sendBLE('setColorTemperature', kelvin)
486
- } else {
487
- await sendOpenAPI('setColorTemperature', `${kelvin}`)
488
- }
489
- await this.api.matter.updateAccessoryState(uuid, this.api.matter.clusterNames.ColorControl, { currentX: request.colorX ?? 0, currentY: request.colorY ?? 0 })
490
- } catch (e: any) {
491
- this.log.error(`Failed to set color temperature for ${dev.deviceId}: ${e?.message ?? e}`)
492
- }
493
- },
494
- }
495
- }
496
-
497
- const opts = Object.assign({}, baseOpts, { handlers })
498
-
499
- // Instantiate the device class and return its serialized accessory
500
- const instance = new Ctor(this.api, this.log, opts)
501
-
502
- // Register BLE->Matter push handler for this device's MAC (if BLE scanning is active)
503
- try {
504
- const mac = formatDeviceIdAsMac(dev.deviceId).toLowerCase()
505
- // Handler receives advertisement/serviceData when BLE scan events arrive
506
- this.bleEventHandler[mac] = async (serviceData?: any) => {
507
- const uuidLocal = baseOpts.uuid
508
-
509
- // First try model-specific / normalized parsing of BLE advertisement
510
- try {
511
- const parsed = this.parseAdvertisementForDevice(dev, serviceData)
512
- if (parsed) {
513
- // Power
514
- if (parsed.power !== undefined) {
515
- await this.api.matter.updateAccessoryState(uuidLocal, this.api.matter.clusterNames.OnOff, { onOff: Boolean(parsed.power) })
516
- }
517
-
518
- // Brightness
519
- if (parsed.brightness !== undefined) {
520
- const level = Math.round((Number(parsed.brightness) / 100) * 254)
521
- await this.api.matter.updateAccessoryState(uuidLocal, this.api.matter.clusterNames.LevelControl, { currentLevel: level })
522
- }
523
-
524
- // Color
525
- if (parsed.color !== undefined) {
526
- const { r, g, b } = parsed.color
527
- const [h, s] = rgb2hs(r, g, b)
528
- await this.api.matter.updateAccessoryState(uuidLocal, this.api.matter.clusterNames.ColorControl, { currentHue: Math.round((h / 360) * 254), currentSaturation: Math.round((s / 100) * 254) })
529
- }
530
-
531
- // If we parsed something from serviceData prefer it and return early
532
- if (serviceData) {
533
- return
534
- }
535
- }
536
- } catch (e: any) {
537
- this.log.debug(`BLE advertisement parsing failed for ${dev.deviceId}: ${e?.message ?? e}`)
538
- }
539
-
540
- // Fallback to OpenAPI getDeviceStatus when serviceData is not present or parsing failed
541
- if (!this.switchBotAPI) {
542
- return
543
- }
544
- try {
545
- const { response, statusCode } = await this.switchBotAPI.getDeviceStatus(dev.deviceId, this.config.credentials?.token, this.config.credentials?.secret)
546
- if (!(statusCode === 100 || statusCode === 200)) {
547
- return
548
- }
549
- const respAny: any = response
550
- const body = respAny?.body ?? respAny
551
- const status = body?.status ?? body
552
-
553
- // On/Off
554
- if (status?.power !== undefined) {
555
- const on = (String(status.power).toLowerCase() === 'on' || Number(status.power) === 1)
556
- await this.api.matter.updateAccessoryState(uuidLocal, this.api.matter.clusterNames.OnOff, { onOff: on })
557
- }
558
-
559
- // Brightness
560
- if (status?.brightness !== undefined) {
561
- const level = Math.round((Number(status.brightness) / 100) * 254)
562
- await this.api.matter.updateAccessoryState(uuidLocal, this.api.matter.clusterNames.LevelControl, { currentLevel: level })
563
- }
564
-
565
- // Color
566
- if (status?.color !== undefined) {
567
- const color = String(status.color)
568
- let r = 0
569
- let g = 0
570
- let b = 0
571
- if (color.includes(':')) {
572
- const parts = color.split(':').map(Number)
573
- ;[r, g, b] = parts
574
- } else if (color.startsWith('#')) {
575
- const hex = color.replace('#', '')
576
- r = Number.parseInt(hex.substring(0, 2), 16)
577
- g = Number.parseInt(hex.substring(2, 4), 16)
578
- b = Number.parseInt(hex.substring(4, 6), 16)
579
- }
580
- const [h, s] = rgb2hs(r, g, b)
581
- await this.api.matter.updateAccessoryState(uuidLocal, this.api.matter.clusterNames.ColorControl, { currentHue: Math.round((h / 360) * 254), currentSaturation: Math.round((s / 100) * 254) })
582
- }
583
- } catch (e: any) {
584
- this.log.debug(`BLE push handler failed for ${dev.deviceId}: ${e?.message ?? e}`)
585
- }
586
- }
587
- } catch (e: any) {
588
- this.log.debug(`Failed to register BLE handler for ${dev.deviceId}: ${e?.message ?? e}`)
589
- }
590
-
591
- return instance.toAccessory()
592
- }
593
-
594
- /**
595
- * Discover devices via SwitchBot OpenAPI and cache them for later use
596
- */
597
- private async discoverDevices(): Promise<void> {
598
- if (!this.switchBotAPI) {
599
- this.log.debug('SwitchBot OpenAPI not configured; skipping discovery')
600
- return
601
- }
602
-
603
- try {
604
- const { response, statusCode } = await this.switchBotAPI.getDevices()
605
- this.log.debug(`SwitchBot getDevices response status: ${statusCode}`)
606
- if (statusCode === 100 || statusCode === 200) {
607
- const deviceList = Array.isArray(response?.body?.deviceList) ? response.body.deviceList : []
608
- this.discoveredDevices = deviceList
609
- this.log.info(`Discovered ${deviceList.length} SwitchBot device(s) from OpenAPI`)
610
- for (const d of deviceList) {
611
- this.log.debug(` - ${d.deviceName} (${d.deviceType}) id=${d.deviceId}`)
612
- }
613
- } else {
614
- this.log.warn(`SwitchBot getDevices returned status ${statusCode}`)
615
- }
616
- } catch (e: any) {
617
- this.log.error('Failed to discover SwitchBot devices:', e?.message ?? e)
618
- }
619
- }
620
-
621
- /**
622
- * Retry wrapper for control commands using SwitchBot OpenAPI
623
- */
624
- async retryCommand(deviceObj: device, bodyChange: bodyChange, maxRetries = 1, delayBetweenRetries = 1000): Promise<{ response: any, statusCode: number }> {
625
- let retryCount = 0
626
- while (retryCount < maxRetries) {
627
- try {
628
- if (!this.switchBotAPI) {
629
- throw new Error('SwitchBot OpenAPI not initialized')
630
- }
631
- const { response, statusCode } = await this.switchBotAPI.controlDevice(
632
- deviceObj.deviceId,
633
- bodyChange.command,
634
- bodyChange.parameter,
635
- bodyChange.commandType as import('node-switchbot').commandType | undefined,
636
- this.config.credentials?.token,
637
- this.config.credentials?.secret,
638
- )
639
- return { response, statusCode }
640
- } catch (e: any) {
641
- this.log.debug(`retryCommand error: ${e?.message ?? e}`)
642
- }
643
- retryCount++
644
-
645
- await sleep(delayBetweenRetries)
646
- }
647
- return { response: {}, statusCode: 500 }
648
- }
649
-
650
- /**
651
- * Parse BLE advertisement/serviceData into normalized fields for a given device.
652
- * Returns null when serviceData is falsy or parsing fails.
653
- */
654
- private parseAdvertisementForDevice(dev: device, serviceData?: any) {
655
- if (!serviceData) {
656
- return null
657
- }
658
- try {
659
- const sd = serviceData
660
- const result: any = {}
661
-
662
- // Power/on state - supports multiple field names used by different models
663
- const power = sd.power ?? sd.on ?? sd.p
664
- if (power !== undefined) {
665
- result.power = (String(power).toLowerCase() === 'on' || Number(power) === 1)
666
- }
667
-
668
- // Brightness (0-100)
669
- const brightness = sd.brightness ?? sd.b
670
- if (brightness !== undefined) {
671
- result.brightness = Number(brightness)
672
- }
673
-
674
- // Color - could be 'r:g:b', '#rrggbb' or 'rrggbb'
675
- const color = sd.color ?? sd.rgb ?? sd.c
676
- if (color !== undefined) {
677
- let r = 0
678
- let g = 0
679
- let b = 0
680
- const c = String(color)
681
- if (c.includes(':')) {
682
- const parts = c.split(':').map(Number)
683
- ;[r, g, b] = parts
684
- } else if (c.startsWith('#')) {
685
- const hex = c.replace('#', '')
686
- r = Number.parseInt(hex.substring(0, 2), 16)
687
- g = Number.parseInt(hex.substring(2, 4), 16)
688
- b = Number.parseInt(hex.substring(4, 6), 16)
689
- } else if (/^[0-9a-f]{6}$/i.test(c)) {
690
- r = Number.parseInt(c.substring(0, 2), 16)
691
- g = Number.parseInt(c.substring(2, 4), 16)
692
- b = Number.parseInt(c.substring(4, 6), 16)
693
- }
694
- result.color = { r, g, b }
695
- }
696
-
697
- // Battery (some devices use battery or batt)
698
- const battery = sd.battery ?? sd.batt
699
- if (battery !== undefined) {
700
- result.battery = Number(battery)
701
- }
702
-
703
- return result
704
- } catch (e: any) {
705
- this.log.debug(`parseAdvertisementForDevice failed for ${dev.deviceId}: ${e?.message ?? e}`)
706
- return null
707
- }
708
- }
709
-
710
- /**
711
- * Required for DynamicPlatformPlugin
712
- * Called when homebridge restores cached accessories from disk at startup
713
- */
714
- configureAccessory(/* accessory: PlatformAccessory */) {
715
- // Note this is not used for Matter accessories - use configureMatterAccessory instead
716
- // This plugin does not have any hap accessories, so here we can comment this out
717
- // this.accessories.set(accessory.UUID, accessory)
718
- }
719
-
720
- /**
721
- * Called when homebridge restores cached Matter accessories from disk at startup.
722
- *
723
- * This is where you can access the `accessory.context` object to retrieve
724
- * any custom data you stored when the accessory was originally registered.
725
- */
726
- configureMatterAccessory(accessory: SerializedMatterAccessory) {
727
- this.log.debug('Loading cached Matter accessory:', accessory.displayName)
728
- this.matterAccessories.set(accessory.uuid, accessory)
729
- }
730
-
731
- /**
732
- * Register all Matter accessories
733
- */
734
- private async registerMatterAccessories() {
735
- this.log.info('═'.repeat(80))
736
- this.log.info('Homebridge Matter Plugin')
737
- this.log.info('═'.repeat(80))
738
-
739
- // Remove accessories that are disabled in config
740
- await this.removeDisabledAccessories()
741
-
742
- // If we discovered real SwitchBot devices via OpenAPI, map and register them
743
- if (this.discoveredDevices && this.discoveredDevices.length > 0) {
744
- this.log.info(`Registering ${this.discoveredDevices.length} discovered SwitchBot device(s) as Matter accessories`)
745
- const accessories: Array<MatterAccessory<Record<string, unknown>>> = []
746
-
747
- // Merge device config (deviceConfig per deviceType and per-device overrides) to match HAP behavior
748
- const devicesToProcess = await this.mergeDiscoveredDevices(this.discoveredDevices)
749
-
750
- for (const dev of devicesToProcess) {
751
- try {
752
- const acc = await this.createAccessoryFromDevice(dev)
753
- if (acc) {
754
- accessories.push(acc)
755
- }
756
- } catch (e: any) {
757
- this.log.error(`Failed to create Matter accessory for ${dev.deviceId}: ${e?.message ?? e}`)
758
- }
759
- }
760
- if (accessories.length > 0) {
761
- this.log.info(`✓ Registered ${accessories.length} discovered device(s)`)
762
- for (const acc of accessories) {
763
- this.log.info(` - ${acc.displayName}`)
764
- }
765
- await this.api.matter.registerPlatformAccessories(PLUGIN_NAME, PLATFORM_NAME, accessories)
766
- return
767
- }
768
- this.log.info('No discovered devices were mapped to Matter accessories; falling back to example sections')
769
- }
770
-
771
- // Register example/demo devices by Matter specification sections
772
- await this.registerSection4Lighting()
773
- await this.registerSection5SmartPlugs()
774
- await this.registerSection6Switches()
775
- await this.registerSection7Sensors()
776
- await this.registerSection8Closure()
777
- await this.registerSection9HVAC()
778
- await this.registerSection12Robotic()
779
- await this.registerCustomDevices()
780
-
781
- this.log.info('═'.repeat(80))
782
- this.log.info('Finished registering Matter accessories')
783
- this.log.info('═'.repeat(80))
784
- }
785
-
786
- /**
787
- * Remove accessories that are disabled in config
788
- */
789
- private async removeDisabledAccessories() {
790
- const configMap = [
791
- { enabled: this.config.enableOnOffLight, uuid: this.api.matter.uuid.generate('matter-onoff-light'), name: 'On/Off Light' },
792
- { enabled: this.config.enableDimmableLight, uuid: this.api.matter.uuid.generate('matter-dimmable-light'), name: 'Dimmable Light' },
793
- { enabled: this.config.enableColourTemperatureLight, uuid: this.api.matter.uuid.generate('matter-colour-temp-light'), name: 'Colour Temperature Light' },
794
- { enabled: this.config.enableColourLight, uuid: this.api.matter.uuid.generate('matter-colour-light'), name: 'Colour Light (HS)' },
795
- { enabled: this.config.enableExtendedColourLight, uuid: this.api.matter.uuid.generate('matter-extended-colour-light'), name: 'Extended Colour Light' },
796
- { enabled: this.config.enableOnOffOutlet, uuid: this.api.matter.uuid.generate('matter-onoff-outlet'), name: 'On/Off Outlet' },
797
- { enabled: this.config.enableOnOffSwitch, uuid: this.api.matter.uuid.generate('matter-onoff-switch'), name: 'On/Off Switch' },
798
- { enabled: this.config.enableTemperatureSensor, uuid: this.api.matter.uuid.generate('matter-temperature-sensor'), name: 'Temperature Sensor' },
799
- { enabled: this.config.enableHumiditySensor, uuid: this.api.matter.uuid.generate('matter-humidity-sensor'), name: 'Humidity Sensor' },
800
- { enabled: this.config.enableLightSensor, uuid: this.api.matter.uuid.generate('matter-light-sensor'), name: 'Light Sensor' },
801
- { enabled: this.config.enableOccupancySensor, uuid: this.api.matter.uuid.generate('matter-occupancy-sensor'), name: 'Occupancy Sensor' },
802
- { enabled: this.config.enableContactSensor, uuid: this.api.matter.uuid.generate('matter-contact-sensor'), name: 'Contact Sensor' },
803
- { enabled: this.config.enableLeakSensor, uuid: this.api.matter.uuid.generate('matter-leak-sensor'), name: 'Leak Sensor' },
804
- { enabled: this.config.enableSmokeSensor, uuid: this.api.matter.uuid.generate('matter-smoke-sensor'), name: 'Smoke Sensor' },
805
- { enabled: this.config.enableDoorLock, uuid: this.api.matter.uuid.generate('matter-door-lock'), name: 'Door Lock' },
806
- { enabled: this.config.enableWindowBlind, uuid: this.api.matter.uuid.generate('matter-window-blind'), name: 'Window Blind' },
807
- { enabled: this.config.enableVenetianBlind, uuid: this.api.matter.uuid.generate('matter-venetian-blind'), name: 'Venetian Blind' },
808
- { enabled: this.config.enableThermostat, uuid: this.api.matter.uuid.generate('matter-thermostat'), name: 'Thermostat' },
809
- { enabled: this.config.enableFan, uuid: this.api.matter.uuid.generate('matter-fan'), name: 'Fan' },
810
- { enabled: this.config.enableRobotVacuum, uuid: this.api.matter.uuid.generate('matter-robot-vacuum'), name: 'Robot Vacuum' },
811
- { enabled: this.config.enablePowerStrip, uuid: this.api.matter.uuid.generate('matter-power-strip'), name: 'Power Strip' },
812
- ]
813
-
814
- for (const { enabled, uuid, name } of configMap) {
815
- if (enabled === false) {
816
- const existingAccessory = this.matterAccessories.get(uuid)
817
- if (existingAccessory) {
818
- this.log.info(`Removing accessory '${name}' (disabled in config)`)
819
- await this.api.matter.unregisterPlatformAccessories(PLUGIN_NAME, PLATFORM_NAME, [existingAccessory as unknown as MatterAccessory])
820
- this.matterAccessories.delete(uuid)
821
- }
822
- }
823
- }
824
- }
825
-
826
- /**
827
- * Section 4: Lighting Devices (Matter Spec § 4)
828
- */
829
- private async registerSection4Lighting() {
830
- this.log.info('═'.repeat(80))
831
- this.log.info('Section 4: Lighting Devices (Matter Spec § 4)')
832
- this.log.info('═'.repeat(80))
833
-
834
- const accessories: Array<MatterAccessory<Record<string, unknown>>> = []
835
-
836
- // On/Off Light
837
- if (this.config.enableOnOffLight !== false) {
838
- const device = new OnOffLightAccessory(this.api, this.log)
839
- accessories.push(device.toAccessory())
840
- }
841
-
842
- // Dimmable Light
843
- if (this.config.enableDimmableLight !== false) {
844
- const device = new DimmableLightAccessory(this.api, this.log)
845
- accessories.push(device.toAccessory())
846
- }
847
-
848
- // Color Temperature Light
849
- if (this.config.enableColourTemperatureLight !== false) {
850
- const device = new ColorTemperatureLightAccessory(this.api, this.log)
851
- accessories.push(device.toAccessory())
852
- }
853
-
854
- // Color Light (HS only)
855
- if (this.config.enableColourLight !== false) {
856
- const device = new ColorLightAccessory(this.api, this.log)
857
- accessories.push(device.toAccessory())
858
- }
859
-
860
- // Extended Color Light (HS+CCT)
861
- if (this.config.enableExtendedColourLight !== false) {
862
- const device = new ExtendedColorLightAccessory(this.api, this.log)
863
- accessories.push(device.toAccessory())
864
- }
865
-
866
- if (accessories.length > 0) {
867
- this.log.info(`✓ Registered ${accessories.length} lighting device(s)`)
868
- for (const acc of accessories) {
869
- this.log.info(` - ${acc.displayName}`)
870
- }
871
- await this.api.matter.registerPlatformAccessories(PLUGIN_NAME, PLATFORM_NAME, accessories)
872
- }
873
- }
874
-
875
- /**
876
- * Section 5: Smart Plugs/Actuators (Matter Spec § 5)
877
- */
878
- private async registerSection5SmartPlugs() {
879
- this.log.info('═'.repeat(80))
880
- this.log.info('Section 5: Smart Plugs/Actuators (Matter Spec § 5)')
881
- this.log.info('═'.repeat(80))
882
-
883
- const accessories: Array<MatterAccessory<Record<string, unknown>>> = []
884
-
885
- // On/Off Outlet
886
- if (this.config.enableOnOffOutlet !== false) {
887
- const device = new OnOffOutletAccessory(this.api, this.log)
888
- accessories.push(device.toAccessory())
889
- }
890
-
891
- if (accessories.length > 0) {
892
- this.log.info(`✓ Registered ${accessories.length} smart plug/actuator device(s)`)
893
- for (const acc of accessories) {
894
- this.log.info(` - ${acc.displayName}`)
895
- }
896
- await this.api.matter.registerPlatformAccessories(PLUGIN_NAME, PLATFORM_NAME, accessories)
897
- }
898
- }
899
-
900
- /**
901
- * Section 6: Switches & Controllers (Matter Spec § 6)
902
- */
903
- private async registerSection6Switches() {
904
- this.log.info('═'.repeat(80))
905
- this.log.info('Section 6: Switches & Controllers (Matter Spec § 6)')
906
- this.log.info('═'.repeat(80))
907
-
908
- const accessories: Array<MatterAccessory<Record<string, unknown>>> = []
909
-
910
- // On/Off Switch
911
- if (this.config.enableOnOffSwitch !== false) {
912
- const device = new OnOffSwitchAccessory(this.api, this.log)
913
- accessories.push(device.toAccessory())
914
- }
915
-
916
- if (accessories.length > 0) {
917
- this.log.info(`✓ Registered ${accessories.length} switch/controller device(s)`)
918
- for (const acc of accessories) {
919
- this.log.info(` - ${acc.displayName}`)
920
- }
921
- await this.api.matter.registerPlatformAccessories(PLUGIN_NAME, PLATFORM_NAME, accessories)
922
- }
923
- }
924
-
925
- /**
926
- * Section 7: Sensors (Matter Spec § 7)
927
- */
928
- private async registerSection7Sensors() {
929
- this.log.info('═'.repeat(80))
930
- this.log.info('Section 7: Sensors (Matter Spec § 7)')
931
- this.log.info('═'.repeat(80))
932
-
933
- const accessories: Array<MatterAccessory<Record<string, unknown>>> = []
934
-
935
- // Contact Sensor
936
- if (this.config.enableContactSensor !== false) {
937
- const device = new ContactSensorAccessory(this.api, this.log)
938
- accessories.push(device.toAccessory())
939
- }
940
-
941
- // Light Sensor
942
- if (this.config.enableLightSensor !== false) {
943
- const device = new LightSensorAccessory(this.api, this.log)
944
- accessories.push(device.toAccessory())
945
- }
946
-
947
- // Occupancy Sensor
948
- if (this.config.enableOccupancySensor !== false) {
949
- const device = new OccupancySensorAccessory(this.api, this.log)
950
- accessories.push(device.toAccessory())
951
- }
952
-
953
- // Temperature Sensor
954
- if (this.config.enableTemperatureSensor !== false) {
955
- const device = new TemperatureSensorAccessory(this.api, this.log)
956
- accessories.push(device.toAccessory())
957
- }
958
-
959
- // Humidity Sensor
960
- if (this.config.enableHumiditySensor !== false) {
961
- const device = new HumiditySensorAccessory(this.api, this.log)
962
- accessories.push(device.toAccessory())
963
- }
964
-
965
- // Smoke/CO Alarm
966
- if (this.config.enableSmokeSensor !== false) {
967
- const device = new SmokeCOAlarmAccessory(this.api, this.log)
968
- accessories.push(device.toAccessory())
969
- }
970
-
971
- // Leak Sensor
972
- if (this.config.enableLeakSensor !== false) {
973
- const device = new LeakSensorAccessory(this.api, this.log)
974
- accessories.push(device.toAccessory())
975
- }
976
-
977
- if (accessories.length > 0) {
978
- this.log.info(`✓ Registered ${accessories.length} sensor device(s)`)
979
- for (const acc of accessories) {
980
- this.log.info(` - ${acc.displayName}`)
981
- }
982
- await this.api.matter.registerPlatformAccessories(PLUGIN_NAME, PLATFORM_NAME, accessories)
983
- }
984
- }
985
-
986
- /**
987
- * Section 8: Closure Devices (Matter Spec § 8)
988
- */
989
- private async registerSection8Closure() {
990
- this.log.info('═'.repeat(80))
991
- this.log.info('Section 8: Closure Devices (Matter Spec § 8)')
992
- this.log.info('═'.repeat(80))
993
-
994
- const accessories: Array<MatterAccessory<Record<string, unknown>>> = []
995
-
996
- // Door Lock
997
- if (this.config.enableDoorLock !== false) {
998
- const device = new DoorLockAccessory(this.api, this.log)
999
- accessories.push(device.toAccessory())
1000
- }
1001
-
1002
- // Window Blind
1003
- if (this.config.enableWindowBlind !== false) {
1004
- const device = new WindowBlindAccessory(this.api, this.log)
1005
- accessories.push(device.toAccessory())
1006
- }
1007
-
1008
- // Venetian Blind
1009
- if (this.config.enableVenetianBlind !== false) {
1010
- const device = new VenetianBlindAccessory(this.api, this.log)
1011
- accessories.push(device.toAccessory())
1012
- }
1013
-
1014
- if (accessories.length > 0) {
1015
- this.log.info(`✓ Registered ${accessories.length} closure device(s)`)
1016
- for (const acc of accessories) {
1017
- this.log.info(` - ${acc.displayName}`)
1018
- }
1019
- await this.api.matter.registerPlatformAccessories(PLUGIN_NAME, PLATFORM_NAME, accessories)
1020
- }
1021
- }
1022
-
1023
- /**
1024
- * Section 9: HVAC (Matter Spec § 9)
1025
- */
1026
- private async registerSection9HVAC() {
1027
- this.log.info('═'.repeat(80))
1028
- this.log.info('Section 9: HVAC (Matter Spec § 9)')
1029
- this.log.info('═'.repeat(80))
1030
-
1031
- const accessories: Array<MatterAccessory<Record<string, unknown>>> = []
1032
-
1033
- // Thermostat
1034
- if (this.config.enableThermostat !== false) {
1035
- const device = new ThermostatAccessory(this.api, this.log)
1036
- accessories.push(device.toAccessory())
1037
- }
1038
-
1039
- // Fan
1040
- if (this.config.enableFan !== false) {
1041
- const device = new FanAccessory(this.api, this.log)
1042
- accessories.push(device.toAccessory())
1043
- }
1044
-
1045
- if (accessories.length > 0) {
1046
- this.log.info(`✓ Registered ${accessories.length} HVAC device(s)`)
1047
- for (const acc of accessories) {
1048
- this.log.info(` - ${acc.displayName}`)
1049
- }
1050
- await this.api.matter.registerPlatformAccessories(PLUGIN_NAME, PLATFORM_NAME, accessories)
1051
- }
1052
- }
1053
-
1054
- /**
1055
- * Section 12: Robotic Devices (Matter Spec § 12)
1056
- * ⚠️ IMPORTANT: RVC devices use a DIFFERENT PROCESS (same code) than other devices!
1057
- * When this runs, you'll see separate commissioning codes in the logs for the robot vacuum.
1058
- * Use those codes to pair the vacuum as a separate bridge in your Home app.
1059
- */
1060
- private async registerSection12Robotic() {
1061
- this.log.info('═'.repeat(80))
1062
- this.log.info('Section 12: Robotic Devices (Matter Spec § 12)')
1063
- this.log.info('═'.repeat(80))
1064
-
1065
- const accessories: Array<MatterAccessory<Record<string, unknown>>> = []
1066
-
1067
- // Robot Vacuum
1068
- if (this.config.enableRobotVacuum !== false) {
1069
- const device = new RoboticVacuumAccessory(this.api, this.log)
1070
- accessories.push(device.toAccessory())
1071
- }
1072
-
1073
- if (accessories.length > 0) {
1074
- this.log.info(`✓ Registered ${accessories.length} robot vacuum device(s)`)
1075
- for (const acc of accessories) {
1076
- this.log.info(` - ${acc.displayName} (standalone for Apple Home compatibility)`)
1077
- }
1078
- await this.api.matter.registerPlatformAccessories(PLUGIN_NAME, PLATFORM_NAME, accessories)
1079
- }
1080
- }
1081
-
1082
- /**
1083
- * Custom Devices
1084
- *
1085
- * This section demonstrates custom device implementations that go beyond
1086
- * the standard Matter device types. These examples show advanced patterns
1087
- * like managing multiple logical components within a single device.
1088
- */
1089
- private async registerCustomDevices() {
1090
- this.log.info('═'.repeat(80))
1091
- this.log.info('Custom Devices')
1092
- this.log.info('═'.repeat(80))
1093
-
1094
- const accessories: Array<MatterAccessory<Record<string, unknown>>> = []
1095
-
1096
- // Power Strip (4 Outlets)
1097
- if (this.config.enablePowerStrip !== false) {
1098
- const device = new PowerStripAccessory(this.api, this.log)
1099
- accessories.push(device.toAccessory())
1100
- }
1101
-
1102
- if (accessories.length > 0) {
1103
- this.log.info(`✓ Registered ${accessories.length} custom device(s)`)
1104
- for (const acc of accessories) {
1105
- this.log.info(` - ${acc.displayName}`)
1106
- }
1107
- await this.api.matter.registerPlatformAccessories(PLUGIN_NAME, PLATFORM_NAME, accessories)
1108
- }
1109
- }
1110
- }