@switchbot/homebridge-switchbot 5.0.0-beta.13 → 5.0.0-beta.131

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 (593) 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 +198 -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 +165 -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 +277 -0
  25. package/dist/devices/genericDevice.d.ts.map +1 -0
  26. package/dist/devices/genericDevice.js +1396 -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 +212 -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 +62 -0
  51. package/dist/homebridge-ui/public/js/api.d.ts.map +1 -0
  52. package/dist/homebridge-ui/public/js/api.js +225 -0
  53. package/dist/homebridge-ui/public/js/api.js.map +1 -0
  54. package/dist/homebridge-ui/public/js/api.ts +279 -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 +3600 -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 +94 -0
  78. package/dist/homebridge-ui/public/js/devices.js.map +1 -0
  79. package/dist/homebridge-ui/public/js/devices.ts +114 -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 +494 -0
  98. package/dist/homebridge-ui/public/js/modals.js.map +1 -0
  99. package/dist/homebridge-ui/public/js/modals.ts +546 -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 +1587 -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 +208 -0
  172. package/src/devices/deviceBase.ts +141 -0
  173. package/src/devices/genericDevice.ts +1345 -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 +233 -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 +279 -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 +114 -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 +546 -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 +1601 -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 +110 -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/baseMatterAccessory.test.d.ts +0 -2
  284. package/dist/baseMatterAccessory.test.d.ts.map +0 -1
  285. package/dist/baseMatterAccessory.test.js +0 -71
  286. package/dist/baseMatterAccessory.test.js.map +0 -1
  287. package/dist/devices-hap/airpurifier.d.ts +0 -54
  288. package/dist/devices-hap/airpurifier.d.ts.map +0 -1
  289. package/dist/devices-hap/airpurifier.js +0 -527
  290. package/dist/devices-hap/airpurifier.js.map +0 -1
  291. package/dist/devices-hap/blindtilt.d.ts +0 -90
  292. package/dist/devices-hap/blindtilt.d.ts.map +0 -1
  293. package/dist/devices-hap/blindtilt.js +0 -974
  294. package/dist/devices-hap/blindtilt.js.map +0 -1
  295. package/dist/devices-hap/bot.d.ts +0 -102
  296. package/dist/devices-hap/bot.d.ts.map +0 -1
  297. package/dist/devices-hap/bot.js +0 -811
  298. package/dist/devices-hap/bot.js.map +0 -1
  299. package/dist/devices-hap/ceilinglight.d.ts +0 -85
  300. package/dist/devices-hap/ceilinglight.d.ts.map +0 -1
  301. package/dist/devices-hap/ceilinglight.js +0 -701
  302. package/dist/devices-hap/ceilinglight.js.map +0 -1
  303. package/dist/devices-hap/colorbulb.d.ts +0 -88
  304. package/dist/devices-hap/colorbulb.d.ts.map +0 -1
  305. package/dist/devices-hap/colorbulb.js +0 -881
  306. package/dist/devices-hap/colorbulb.js.map +0 -1
  307. package/dist/devices-hap/contact.d.ts +0 -44
  308. package/dist/devices-hap/contact.d.ts.map +0 -1
  309. package/dist/devices-hap/contact.js +0 -409
  310. package/dist/devices-hap/contact.js.map +0 -1
  311. package/dist/devices-hap/curtain.d.ts +0 -73
  312. package/dist/devices-hap/curtain.d.ts.map +0 -1
  313. package/dist/devices-hap/curtain.js +0 -869
  314. package/dist/devices-hap/curtain.js.map +0 -1
  315. package/dist/devices-hap/device.d.ts +0 -98
  316. package/dist/devices-hap/device.d.ts.map +0 -1
  317. package/dist/devices-hap/device.js +0 -749
  318. package/dist/devices-hap/device.js.map +0 -1
  319. package/dist/devices-hap/fan.d.ts +0 -69
  320. package/dist/devices-hap/fan.d.ts.map +0 -1
  321. package/dist/devices-hap/fan.js +0 -649
  322. package/dist/devices-hap/fan.js.map +0 -1
  323. package/dist/devices-hap/hub.d.ts +0 -37
  324. package/dist/devices-hap/hub.d.ts.map +0 -1
  325. package/dist/devices-hap/hub.js +0 -392
  326. package/dist/devices-hap/hub.js.map +0 -1
  327. package/dist/devices-hap/humidifier.d.ts +0 -68
  328. package/dist/devices-hap/humidifier.d.ts.map +0 -1
  329. package/dist/devices-hap/humidifier.js +0 -628
  330. package/dist/devices-hap/humidifier.js.map +0 -1
  331. package/dist/devices-hap/iosensor.d.ts +0 -42
  332. package/dist/devices-hap/iosensor.d.ts.map +0 -1
  333. package/dist/devices-hap/iosensor.js +0 -382
  334. package/dist/devices-hap/iosensor.js.map +0 -1
  335. package/dist/devices-hap/lightstrip.d.ts +0 -79
  336. package/dist/devices-hap/lightstrip.d.ts.map +0 -1
  337. package/dist/devices-hap/lightstrip.js +0 -797
  338. package/dist/devices-hap/lightstrip.js.map +0 -1
  339. package/dist/devices-hap/lock.d.ts +0 -53
  340. package/dist/devices-hap/lock.d.ts.map +0 -1
  341. package/dist/devices-hap/lock.js +0 -561
  342. package/dist/devices-hap/lock.js.map +0 -1
  343. package/dist/devices-hap/meter.d.ts +0 -37
  344. package/dist/devices-hap/meter.d.ts.map +0 -1
  345. package/dist/devices-hap/meter.js +0 -379
  346. package/dist/devices-hap/meter.js.map +0 -1
  347. package/dist/devices-hap/meterplus.d.ts +0 -42
  348. package/dist/devices-hap/meterplus.d.ts.map +0 -1
  349. package/dist/devices-hap/meterplus.js +0 -384
  350. package/dist/devices-hap/meterplus.js.map +0 -1
  351. package/dist/devices-hap/meterpro.d.ts +0 -43
  352. package/dist/devices-hap/meterpro.d.ts.map +0 -1
  353. package/dist/devices-hap/meterpro.js +0 -468
  354. package/dist/devices-hap/meterpro.js.map +0 -1
  355. package/dist/devices-hap/motion.d.ts +0 -42
  356. package/dist/devices-hap/motion.d.ts.map +0 -1
  357. package/dist/devices-hap/motion.js +0 -345
  358. package/dist/devices-hap/motion.js.map +0 -1
  359. package/dist/devices-hap/plug.d.ts +0 -49
  360. package/dist/devices-hap/plug.d.ts.map +0 -1
  361. package/dist/devices-hap/plug.js +0 -395
  362. package/dist/devices-hap/plug.js.map +0 -1
  363. package/dist/devices-hap/relayswitch.d.ts +0 -96
  364. package/dist/devices-hap/relayswitch.d.ts.map +0 -1
  365. package/dist/devices-hap/relayswitch.js +0 -642
  366. package/dist/devices-hap/relayswitch.js.map +0 -1
  367. package/dist/devices-hap/robotvacuumcleaner.d.ts +0 -54
  368. package/dist/devices-hap/robotvacuumcleaner.d.ts.map +0 -1
  369. package/dist/devices-hap/robotvacuumcleaner.js +0 -523
  370. package/dist/devices-hap/robotvacuumcleaner.js.map +0 -1
  371. package/dist/devices-hap/waterdetector.d.ts +0 -41
  372. package/dist/devices-hap/waterdetector.d.ts.map +0 -1
  373. package/dist/devices-hap/waterdetector.js +0 -356
  374. package/dist/devices-hap/waterdetector.js.map +0 -1
  375. package/dist/devices-matter/BaseMatterAccessory.d.ts +0 -78
  376. package/dist/devices-matter/BaseMatterAccessory.d.ts.map +0 -1
  377. package/dist/devices-matter/BaseMatterAccessory.js +0 -220
  378. package/dist/devices-matter/BaseMatterAccessory.js.map +0 -1
  379. package/dist/devices-matter/ColorLightAccessory.d.ts +0 -20
  380. package/dist/devices-matter/ColorLightAccessory.d.ts.map +0 -1
  381. package/dist/devices-matter/ColorLightAccessory.js +0 -95
  382. package/dist/devices-matter/ColorLightAccessory.js.map +0 -1
  383. package/dist/devices-matter/ColorTemperatureLightAccessory.d.ts +0 -18
  384. package/dist/devices-matter/ColorTemperatureLightAccessory.d.ts.map +0 -1
  385. package/dist/devices-matter/ColorTemperatureLightAccessory.js +0 -76
  386. package/dist/devices-matter/ColorTemperatureLightAccessory.js.map +0 -1
  387. package/dist/devices-matter/ContactSensorAccessory.d.ts +0 -12
  388. package/dist/devices-matter/ContactSensorAccessory.d.ts.map +0 -1
  389. package/dist/devices-matter/ContactSensorAccessory.js +0 -34
  390. package/dist/devices-matter/ContactSensorAccessory.js.map +0 -1
  391. package/dist/devices-matter/DimmableLightAccessory.d.ts +0 -58
  392. package/dist/devices-matter/DimmableLightAccessory.d.ts.map +0 -1
  393. package/dist/devices-matter/DimmableLightAccessory.js +0 -167
  394. package/dist/devices-matter/DimmableLightAccessory.js.map +0 -1
  395. package/dist/devices-matter/DoorLockAccessory.d.ts +0 -14
  396. package/dist/devices-matter/DoorLockAccessory.d.ts.map +0 -1
  397. package/dist/devices-matter/DoorLockAccessory.js +0 -50
  398. package/dist/devices-matter/DoorLockAccessory.js.map +0 -1
  399. package/dist/devices-matter/ExtendedColorLightAccessory.d.ts +0 -21
  400. package/dist/devices-matter/ExtendedColorLightAccessory.d.ts.map +0 -1
  401. package/dist/devices-matter/ExtendedColorLightAccessory.js +0 -106
  402. package/dist/devices-matter/ExtendedColorLightAccessory.js.map +0 -1
  403. package/dist/devices-matter/FanAccessory.d.ts +0 -16
  404. package/dist/devices-matter/FanAccessory.d.ts.map +0 -1
  405. package/dist/devices-matter/FanAccessory.js +0 -81
  406. package/dist/devices-matter/FanAccessory.js.map +0 -1
  407. package/dist/devices-matter/HumiditySensorAccessory.d.ts +0 -12
  408. package/dist/devices-matter/HumiditySensorAccessory.d.ts.map +0 -1
  409. package/dist/devices-matter/HumiditySensorAccessory.js +0 -34
  410. package/dist/devices-matter/HumiditySensorAccessory.js.map +0 -1
  411. package/dist/devices-matter/LeakSensorAccessory.d.ts +0 -12
  412. package/dist/devices-matter/LeakSensorAccessory.d.ts.map +0 -1
  413. package/dist/devices-matter/LeakSensorAccessory.js +0 -33
  414. package/dist/devices-matter/LeakSensorAccessory.js.map +0 -1
  415. package/dist/devices-matter/LightSensorAccessory.d.ts +0 -12
  416. package/dist/devices-matter/LightSensorAccessory.d.ts.map +0 -1
  417. package/dist/devices-matter/LightSensorAccessory.js +0 -34
  418. package/dist/devices-matter/LightSensorAccessory.js.map +0 -1
  419. package/dist/devices-matter/OccupancySensorAccessory.d.ts +0 -12
  420. package/dist/devices-matter/OccupancySensorAccessory.d.ts.map +0 -1
  421. package/dist/devices-matter/OccupancySensorAccessory.js +0 -39
  422. package/dist/devices-matter/OccupancySensorAccessory.js.map +0 -1
  423. package/dist/devices-matter/OnOffLightAccessory.d.ts +0 -38
  424. package/dist/devices-matter/OnOffLightAccessory.d.ts.map +0 -1
  425. package/dist/devices-matter/OnOffLightAccessory.js +0 -110
  426. package/dist/devices-matter/OnOffLightAccessory.js.map +0 -1
  427. package/dist/devices-matter/OnOffOutletAccessory.d.ts +0 -14
  428. package/dist/devices-matter/OnOffOutletAccessory.d.ts.map +0 -1
  429. package/dist/devices-matter/OnOffOutletAccessory.js +0 -43
  430. package/dist/devices-matter/OnOffOutletAccessory.js.map +0 -1
  431. package/dist/devices-matter/OnOffSwitchAccessory.d.ts +0 -14
  432. package/dist/devices-matter/OnOffSwitchAccessory.d.ts.map +0 -1
  433. package/dist/devices-matter/OnOffSwitchAccessory.js +0 -42
  434. package/dist/devices-matter/OnOffSwitchAccessory.js.map +0 -1
  435. package/dist/devices-matter/RoboticVacuumAccessory.d.ts +0 -68
  436. package/dist/devices-matter/RoboticVacuumAccessory.d.ts.map +0 -1
  437. package/dist/devices-matter/RoboticVacuumAccessory.js +0 -334
  438. package/dist/devices-matter/RoboticVacuumAccessory.js.map +0 -1
  439. package/dist/devices-matter/SmokeCOAlarmAccessory.d.ts +0 -11
  440. package/dist/devices-matter/SmokeCOAlarmAccessory.d.ts.map +0 -1
  441. package/dist/devices-matter/SmokeCOAlarmAccessory.js +0 -49
  442. package/dist/devices-matter/SmokeCOAlarmAccessory.js.map +0 -1
  443. package/dist/devices-matter/TemperatureSensorAccessory.d.ts +0 -12
  444. package/dist/devices-matter/TemperatureSensorAccessory.d.ts.map +0 -1
  445. package/dist/devices-matter/TemperatureSensorAccessory.js +0 -36
  446. package/dist/devices-matter/TemperatureSensorAccessory.js.map +0 -1
  447. package/dist/devices-matter/ThermostatAccessory.d.ts +0 -19
  448. package/dist/devices-matter/ThermostatAccessory.d.ts.map +0 -1
  449. package/dist/devices-matter/ThermostatAccessory.js +0 -95
  450. package/dist/devices-matter/ThermostatAccessory.js.map +0 -1
  451. package/dist/devices-matter/VenetianBlindAccessory.d.ts +0 -19
  452. package/dist/devices-matter/VenetianBlindAccessory.d.ts.map +0 -1
  453. package/dist/devices-matter/VenetianBlindAccessory.js +0 -99
  454. package/dist/devices-matter/VenetianBlindAccessory.js.map +0 -1
  455. package/dist/devices-matter/WindowBlindAccessory.d.ts +0 -17
  456. package/dist/devices-matter/WindowBlindAccessory.d.ts.map +0 -1
  457. package/dist/devices-matter/WindowBlindAccessory.js +0 -80
  458. package/dist/devices-matter/WindowBlindAccessory.js.map +0 -1
  459. package/dist/devices-matter/custom/PowerStripAccessory.d.ts +0 -97
  460. package/dist/devices-matter/custom/PowerStripAccessory.d.ts.map +0 -1
  461. package/dist/devices-matter/custom/PowerStripAccessory.js +0 -265
  462. package/dist/devices-matter/custom/PowerStripAccessory.js.map +0 -1
  463. package/dist/devices-matter/custom/index.d.ts +0 -8
  464. package/dist/devices-matter/custom/index.d.ts.map +0 -1
  465. package/dist/devices-matter/custom/index.js +0 -8
  466. package/dist/devices-matter/custom/index.js.map +0 -1
  467. package/dist/devices-matter/index.d.ts +0 -29
  468. package/dist/devices-matter/index.d.ts.map +0 -1
  469. package/dist/devices-matter/index.js +0 -28
  470. package/dist/devices-matter/index.js.map +0 -1
  471. package/dist/index.test.d.ts +0 -2
  472. package/dist/index.test.d.ts.map +0 -1
  473. package/dist/index.test.js +0 -19
  474. package/dist/index.test.js.map +0 -1
  475. package/dist/irdevice/airconditioner.d.ts +0 -61
  476. package/dist/irdevice/airconditioner.d.ts.map +0 -1
  477. package/dist/irdevice/airconditioner.js +0 -472
  478. package/dist/irdevice/airconditioner.js.map +0 -1
  479. package/dist/irdevice/airpurifier.d.ts +0 -50
  480. package/dist/irdevice/airpurifier.d.ts.map +0 -1
  481. package/dist/irdevice/airpurifier.js +0 -213
  482. package/dist/irdevice/airpurifier.js.map +0 -1
  483. package/dist/irdevice/camera.d.ts +0 -32
  484. package/dist/irdevice/camera.d.ts.map +0 -1
  485. package/dist/irdevice/camera.js +0 -107
  486. package/dist/irdevice/camera.js.map +0 -1
  487. package/dist/irdevice/fan.d.ts +0 -36
  488. package/dist/irdevice/fan.d.ts.map +0 -1
  489. package/dist/irdevice/fan.js +0 -200
  490. package/dist/irdevice/fan.js.map +0 -1
  491. package/dist/irdevice/irdevice.d.ts +0 -68
  492. package/dist/irdevice/irdevice.d.ts.map +0 -1
  493. package/dist/irdevice/irdevice.js +0 -298
  494. package/dist/irdevice/irdevice.js.map +0 -1
  495. package/dist/irdevice/light.d.ts +0 -36
  496. package/dist/irdevice/light.d.ts.map +0 -1
  497. package/dist/irdevice/light.js +0 -206
  498. package/dist/irdevice/light.js.map +0 -1
  499. package/dist/irdevice/other.d.ts +0 -57
  500. package/dist/irdevice/other.d.ts.map +0 -1
  501. package/dist/irdevice/other.js +0 -778
  502. package/dist/irdevice/other.js.map +0 -1
  503. package/dist/irdevice/tv.d.ts +0 -45
  504. package/dist/irdevice/tv.d.ts.map +0 -1
  505. package/dist/irdevice/tv.js +0 -327
  506. package/dist/irdevice/tv.js.map +0 -1
  507. package/dist/irdevice/vacuumcleaner.d.ts +0 -28
  508. package/dist/irdevice/vacuumcleaner.d.ts.map +0 -1
  509. package/dist/irdevice/vacuumcleaner.js +0 -104
  510. package/dist/irdevice/vacuumcleaner.js.map +0 -1
  511. package/dist/irdevice/waterheater.d.ts +0 -30
  512. package/dist/irdevice/waterheater.d.ts.map +0 -1
  513. package/dist/irdevice/waterheater.js +0 -105
  514. package/dist/irdevice/waterheater.js.map +0 -1
  515. package/dist/platform-hap.d.ts +0 -149
  516. package/dist/platform-hap.d.ts.map +0 -1
  517. package/dist/platform-hap.js +0 -2861
  518. package/dist/platform-hap.js.map +0 -1
  519. package/dist/platform-matter.d.ts +0 -120
  520. package/dist/platform-matter.d.ts.map +0 -1
  521. package/dist/platform-matter.js +0 -999
  522. package/dist/platform-matter.js.map +0 -1
  523. package/dist/utils.test.d.ts +0 -2
  524. package/dist/utils.test.d.ts.map +0 -1
  525. package/dist/utils.test.js +0 -95
  526. package/dist/utils.test.js.map +0 -1
  527. package/dist/verifyconfig.test.d.ts +0 -2
  528. package/dist/verifyconfig.test.d.ts.map +0 -1
  529. package/dist/verifyconfig.test.js +0 -167
  530. package/dist/verifyconfig.test.js.map +0 -1
  531. package/src/baseMatterAccessory.test.ts +0 -88
  532. package/src/custom.d.ts +0 -7
  533. package/src/devices-hap/airpurifier.ts +0 -563
  534. package/src/devices-hap/blindtilt.ts +0 -1049
  535. package/src/devices-hap/bot.ts +0 -900
  536. package/src/devices-hap/ceilinglight.ts +0 -742
  537. package/src/devices-hap/colorbulb.ts +0 -904
  538. package/src/devices-hap/contact.ts +0 -457
  539. package/src/devices-hap/curtain.ts +0 -944
  540. package/src/devices-hap/device.ts +0 -811
  541. package/src/devices-hap/fan.ts +0 -711
  542. package/src/devices-hap/hub.ts +0 -439
  543. package/src/devices-hap/humidifier.ts +0 -669
  544. package/src/devices-hap/iosensor.ts +0 -427
  545. package/src/devices-hap/lightstrip.ts +0 -836
  546. package/src/devices-hap/lock.ts +0 -620
  547. package/src/devices-hap/meter.ts +0 -426
  548. package/src/devices-hap/meterplus.ts +0 -430
  549. package/src/devices-hap/meterpro.ts +0 -522
  550. package/src/devices-hap/motion.ts +0 -390
  551. package/src/devices-hap/plug.ts +0 -423
  552. package/src/devices-hap/relayswitch.ts +0 -727
  553. package/src/devices-hap/robotvacuumcleaner.ts +0 -568
  554. package/src/devices-hap/waterdetector.ts +0 -400
  555. package/src/devices-matter/BaseMatterAccessory.ts +0 -249
  556. package/src/devices-matter/ColorLightAccessory.ts +0 -110
  557. package/src/devices-matter/ColorTemperatureLightAccessory.ts +0 -90
  558. package/src/devices-matter/ContactSensorAccessory.ts +0 -41
  559. package/src/devices-matter/DimmableLightAccessory.ts +0 -192
  560. package/src/devices-matter/DoorLockAccessory.ts +0 -60
  561. package/src/devices-matter/ExtendedColorLightAccessory.ts +0 -122
  562. package/src/devices-matter/FanAccessory.ts +0 -95
  563. package/src/devices-matter/HumiditySensorAccessory.ts +0 -41
  564. package/src/devices-matter/LeakSensorAccessory.ts +0 -40
  565. package/src/devices-matter/LightSensorAccessory.ts +0 -41
  566. package/src/devices-matter/OccupancySensorAccessory.ts +0 -48
  567. package/src/devices-matter/OnOffLightAccessory.ts +0 -125
  568. package/src/devices-matter/OnOffOutletAccessory.ts +0 -51
  569. package/src/devices-matter/OnOffSwitchAccessory.ts +0 -51
  570. package/src/devices-matter/RoboticVacuumAccessory.ts +0 -407
  571. package/src/devices-matter/SmokeCOAlarmAccessory.ts +0 -59
  572. package/src/devices-matter/TemperatureSensorAccessory.ts +0 -43
  573. package/src/devices-matter/ThermostatAccessory.ts +0 -110
  574. package/src/devices-matter/VenetianBlindAccessory.ts +0 -115
  575. package/src/devices-matter/WindowBlindAccessory.ts +0 -92
  576. package/src/devices-matter/custom/PowerStripAccessory.ts +0 -309
  577. package/src/devices-matter/custom/index.ts +0 -8
  578. package/src/devices-matter/index.ts +0 -29
  579. package/src/index.test.ts +0 -24
  580. package/src/irdevice/airconditioner.ts +0 -533
  581. package/src/irdevice/airpurifier.ts +0 -252
  582. package/src/irdevice/camera.ts +0 -129
  583. package/src/irdevice/fan.ts +0 -226
  584. package/src/irdevice/irdevice.ts +0 -344
  585. package/src/irdevice/light.ts +0 -246
  586. package/src/irdevice/other.ts +0 -790
  587. package/src/irdevice/tv.ts +0 -378
  588. package/src/irdevice/vacuumcleaner.ts +0 -126
  589. package/src/irdevice/waterheater.ts +0 -127
  590. package/src/platform-hap.ts +0 -2997
  591. package/src/platform-matter.ts +0 -1124
  592. package/src/utils.test.ts +0 -96
  593. package/src/verifyconfig.test.ts +0 -197
@@ -1,1124 +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
- // Inject handy platform-side helpers into the accessory `context` so Matter
254
- // accessory classes can perform OpenAPI/BLE actions without reaching into
255
- // the platform implementation directly.
256
- context: {
257
- deviceId: dev.deviceId,
258
- },
259
- }
260
-
261
- // Small helper to wrap common OpenAPI on/off commands
262
- // Helper to send an OpenAPI command
263
- const sendOpenAPI = async (command: string, parameter = 'default') => {
264
- const bodyChange: bodyChange = { command, parameter, commandType: 'command' }
265
- return this.retryCommand(dev, bodyChange, this.config.options?.maxRetries ?? 1, this.config.options?.delayBetweenRetries ?? 1000)
266
- }
267
-
268
- // Helper to send a BLE action if Platform BLE is enabled and switchBotBLE exists
269
- const sendBLE = async (methodName: string, ...args: any[]) => {
270
- // Provide a small retry loop for flaky BLE operations
271
- if (!this.switchBotBLE) {
272
- throw new Error('Platform BLE not available')
273
- }
274
- const id = formatDeviceIdAsMac(dev.deviceId)
275
- const maxRetries = (this.config.options as any)?.bleRetries ?? 2
276
- const retryDelay = (this.config.options as any)?.bleRetryDelay ?? 500
277
- let attempt = 0
278
- while (attempt < maxRetries) {
279
- try {
280
- const list = await this.switchBotBLE.discover({ model: (dev as any).bleModel, id })
281
- if (!Array.isArray(list) || list.length === 0) {
282
- throw new Error('BLE device not found')
283
- }
284
- const deviceInst: any = list[0]
285
- if (typeof deviceInst[methodName] !== 'function') {
286
- throw new TypeError(`BLE method ${methodName} not available on device`)
287
- }
288
- return await deviceInst[methodName](...args)
289
- } catch (e: any) {
290
- attempt++
291
- if (attempt >= maxRetries) {
292
- throw e
293
- }
294
- this.log.debug(`BLE ${methodName} attempt ${attempt} failed for ${dev.deviceId}: ${e?.message ?? e}, retrying in ${retryDelay}ms`)
295
- await sleep(retryDelay)
296
- }
297
- }
298
- throw new Error('BLE operation failed')
299
- }
300
-
301
- const makeOnOffHandlers = (uuid: string, connectionType: 'BLE' | 'OpenAPI') => ({
302
- onOff: {
303
- on: async () => {
304
- try {
305
- if (connectionType === 'BLE' && this.switchBotBLE) {
306
- await sendBLE('turnOn')
307
- } else {
308
- await sendOpenAPI('turnOn')
309
- }
310
- await this.api.matter.updateAccessoryState(uuid, this.api.matter.clusterNames.OnOff, { onOff: true })
311
- } catch (e: any) {
312
- this.log.error(`Failed to turn on device ${dev.deviceId}: ${e?.message ?? e}`)
313
- }
314
- },
315
- off: async () => {
316
- try {
317
- if (connectionType === 'BLE' && this.switchBotBLE) {
318
- await sendBLE('turnOff')
319
- } else {
320
- await sendOpenAPI('turnOff')
321
- }
322
- await this.api.matter.updateAccessoryState(uuid, this.api.matter.clusterNames.OnOff, { onOff: false })
323
- } catch (e: any) {
324
- this.log.error(`Failed to turn off device ${dev.deviceId}: ${e?.message ?? e}`)
325
- }
326
- },
327
- },
328
- })
329
-
330
- // Mapping from SwitchBot deviceType -> constructor (expanded for parity with HAP)
331
- const mapping: { [key: string]: any } = {
332
- // Plugs / Outlets
333
- 'Plug': OnOffOutletAccessory,
334
- 'Plug Mini (US)': OnOffOutletAccessory,
335
- 'Plug Mini (JP)': OnOffOutletAccessory,
336
- 'Plug Mini': OnOffOutletAccessory,
337
- 'WoPlug': OnOffOutletAccessory,
338
-
339
- // Lighting
340
- 'Color Bulb': ColorLightAccessory,
341
- 'Color Bulb Mini': ColorLightAccessory,
342
- 'Ceiling Light': ColorTemperatureLightAccessory,
343
- 'Ceiling Light Pro': ColorTemperatureLightAccessory,
344
- 'Strip Light': ExtendedColorLightAccessory,
345
- 'Light Strip': ExtendedColorLightAccessory,
346
- 'Light Strip Plus': ExtendedColorLightAccessory,
347
- 'Strip Light Pro': ExtendedColorLightAccessory,
348
- 'Dimmable Light': DimmableLightAccessory,
349
-
350
- // Robot Vacuums
351
- 'K10+': RoboticVacuumAccessory,
352
- 'K10+ Pro': RoboticVacuumAccessory,
353
- 'WoSweeper': RoboticVacuumAccessory,
354
- 'WoSweeperMini': RoboticVacuumAccessory,
355
- 'Robot Vacuum Cleaner S1': RoboticVacuumAccessory,
356
- 'Robot Vacuum Cleaner S1 Plus': RoboticVacuumAccessory,
357
- 'Robot Vacuum Cleaner S10': RoboticVacuumAccessory,
358
- 'Robot Vacuum Cleaner S1 Pro': RoboticVacuumAccessory,
359
- 'Robot Vacuum Cleaner S1 Mini': RoboticVacuumAccessory,
360
-
361
- // Locks
362
- 'Smart Lock': DoorLockAccessory,
363
- 'Smart Lock Pro': DoorLockAccessory,
364
-
365
- // Sensors
366
- 'Motion Sensor': OccupancySensorAccessory,
367
- 'Contact Sensor': ContactSensorAccessory,
368
- 'Water Detector': LeakSensorAccessory,
369
- 'Meter': TemperatureSensorAccessory,
370
- 'MeterPlus': TemperatureSensorAccessory,
371
- 'MeterPro': TemperatureSensorAccessory,
372
- 'WoIOSensor': TemperatureSensorAccessory,
373
- 'Air Purifier PM2.5': HumiditySensorAccessory,
374
- 'Air Purifier Table PM2.5': HumiditySensorAccessory,
375
- 'Air Purifier': HumiditySensorAccessory,
376
- 'Air Purifier VOC': HumiditySensorAccessory,
377
- 'Air Purifier Table VOC': HumiditySensorAccessory,
378
-
379
- // Fans
380
- 'Battery Circulator Fan': FanAccessory,
381
-
382
- // Curtains / Blinds
383
- 'Blind Tilt': VenetianBlindAccessory,
384
- 'Curtain': WindowBlindAccessory,
385
- 'Curtain2': WindowBlindAccessory,
386
- 'Curtain3': WindowBlindAccessory,
387
- 'Curtain 2': WindowBlindAccessory,
388
- 'WoRollerShade': WindowBlindAccessory,
389
- 'Roller Shade': WindowBlindAccessory,
390
- 'Venetian Blind': VenetianBlindAccessory,
391
-
392
- // Switches / Relays
393
- 'Relay Switch 1': OnOffSwitchAccessory,
394
- 'Relay Switch 1PM': OnOffSwitchAccessory,
395
- 'Relay Switch 2': OnOffSwitchAccessory,
396
- 'Relay Switch 3': OnOffSwitchAccessory,
397
-
398
- // Misc / hubs / other
399
- 'Hub 2': undefined,
400
- 'Hub 3': undefined,
401
- 'Hub Mini': undefined,
402
- 'Bot': OnOffSwitchAccessory,
403
- 'Smart Bot': OnOffSwitchAccessory,
404
- 'Humidifier': HumiditySensorAccessory,
405
- 'Humidifier2': HumiditySensorAccessory,
406
- 'Thermostat': ThermostatAccessory,
407
- 'Water Heater': ThermostatAccessory,
408
- }
409
-
410
- const Ctor = mapping[dev.deviceType ?? '']
411
- if (!Ctor) {
412
- this.log.debug(`No Matter mapping for deviceType='${dev.deviceType}', deviceId=${dev.deviceId}`)
413
- return undefined
414
- }
415
-
416
- // Build opts and handlers tailored for basic capabilities
417
- const uuid = baseOpts.uuid
418
- const handlers: Record<string, any> = {}
419
-
420
- // Choose connection type for this device (BLE vs OpenAPI)
421
- const connectionType = this.chooseConnectionType(dev)
422
-
423
- // On/Off common
424
- handlers.onOff = makeOnOffHandlers(uuid, connectionType).onOff
425
-
426
- // If this is a light, add brightness and color handlers
427
- if (['Color Bulb', 'Ceiling Light', 'Ceiling Light Pro', 'Strip Light', 'Dimmable Light'].includes(dev.deviceType ?? '')) {
428
- // levelControl
429
- handlers.levelControl = {
430
- moveToLevelWithOnOff: async (request: any) => {
431
- try {
432
- const level = request.level as number
433
- const percent = Math.round((level / 254) * 100)
434
- if (connectionType === 'BLE' && this.switchBotBLE) {
435
- await sendBLE('setBrightness', percent)
436
- } else {
437
- await sendOpenAPI('setBrightness', `${percent}`)
438
- }
439
- await this.api.matter.updateAccessoryState(uuid, this.api.matter.clusterNames.LevelControl, { currentLevel: level })
440
- } catch (e: any) {
441
- this.log.error(`Failed to set brightness for ${dev.deviceId}: ${e?.message ?? e}`)
442
- }
443
- },
444
- }
445
-
446
- // colorControl
447
- handlers.colorControl = {
448
- moveToHueAndSaturationLogic: async (request: any) => {
449
- try {
450
- const hue = request.hue as number
451
- const saturation = request.saturation as number
452
- const [r, g, b] = hs2rgb(Math.round((hue / 254) * 360), Math.round((saturation / 254) * 100))
453
- if (connectionType === 'BLE' && this.switchBotBLE) {
454
- await sendBLE('setRGB', Number(request.level ?? 100), r, g, b)
455
- } else {
456
- await sendOpenAPI('setColor', `${r}:${g}:${b}`)
457
- }
458
- await this.api.matter.updateAccessoryState(uuid, this.api.matter.clusterNames.ColorControl, { currentHue: hue, currentSaturation: saturation })
459
- } catch (e: any) {
460
- this.log.error(`Failed to set hue/sat for ${dev.deviceId}: ${e?.message ?? e}`)
461
- }
462
- },
463
- moveToColorLogic: async (request: any) => {
464
- try {
465
- // MoveToColor gives colorX/colorY values; convert to approximate RGB by mapping to 0-255 scale
466
- const colorX = request.colorX as number
467
- const colorY = request.colorY as number
468
- // Naive conversion: map X/Y into RGB via hue approximation (not colorimetrically accurate)
469
- const hueApprox = Math.round((colorX / 65535) * 360)
470
- const satApprox = Math.round((colorY / 65535) * 100)
471
- const [r, g, b] = hs2rgb(hueApprox, satApprox)
472
- if (connectionType === 'BLE' && this.switchBotBLE) {
473
- await sendBLE('setRGB', Number(request.level ?? 100), r, g, b)
474
- } else {
475
- await sendOpenAPI('setColor', `${r}:${g}:${b}`)
476
- }
477
- await this.api.matter.updateAccessoryState(uuid, this.api.matter.clusterNames.ColorControl, { currentX: colorX, currentY: colorY })
478
- } catch (e: any) {
479
- this.log.error(`Failed to set XY color for ${dev.deviceId}: ${e?.message ?? e}`)
480
- }
481
- },
482
- }
483
-
484
- // color temperature — map to kelvin and send setColorTemperature
485
- handlers.colorTemperature = {
486
- moveToColorTemperature: async (request: any) => {
487
- try {
488
- const kelvin = Math.round(1000000 / Number(request.colorTemperature))
489
- if (connectionType === 'BLE' && this.switchBotBLE) {
490
- await sendBLE('setColorTemperature', kelvin)
491
- } else {
492
- await sendOpenAPI('setColorTemperature', `${kelvin}`)
493
- }
494
- await this.api.matter.updateAccessoryState(uuid, this.api.matter.clusterNames.ColorControl, { currentX: request.colorX ?? 0, currentY: request.colorY ?? 0 })
495
- } catch (e: any) {
496
- this.log.error(`Failed to set color temperature for ${dev.deviceId}: ${e?.message ?? e}`)
497
- }
498
- },
499
- }
500
- }
501
-
502
- // Expose platform helpers to the accessory via context so accessory
503
- // classes can call OpenAPI/BLE actions (sendOpenAPI/sendBLE) and know
504
- // the effective connection type.
505
- try {
506
- ;(baseOpts as any).context = Object.assign({}, (baseOpts as any).context, { sendOpenAPI, sendBLE, connectionType })
507
- } catch (e: any) {
508
- this.log.debug('Failed to attach platform helpers to baseOpts.context: %s', e?.message ?? e)
509
- }
510
-
511
- const opts = Object.assign({}, baseOpts, { handlers })
512
-
513
- // Instantiate the device class and return its serialized accessory
514
- const instance = new Ctor(this.api, this.log, opts)
515
-
516
- // Register BLE->Matter push handler for this device's MAC (if BLE scanning is active)
517
- try {
518
- const mac = formatDeviceIdAsMac(dev.deviceId).toLowerCase()
519
- // Handler receives advertisement/serviceData when BLE scan events arrive
520
- this.bleEventHandler[mac] = async (serviceData?: any) => {
521
- const uuidLocal = baseOpts.uuid
522
-
523
- // First try model-specific / normalized parsing of BLE advertisement
524
- try {
525
- const parsed = this.parseAdvertisementForDevice(dev, serviceData)
526
- if (parsed) {
527
- // Power
528
- if (parsed.power !== undefined) {
529
- await this.api.matter.updateAccessoryState(uuidLocal, this.api.matter.clusterNames.OnOff, { onOff: Boolean(parsed.power) })
530
- }
531
-
532
- // Brightness
533
- if (parsed.brightness !== undefined) {
534
- const level = Math.round((Number(parsed.brightness) / 100) * 254)
535
- await this.api.matter.updateAccessoryState(uuidLocal, this.api.matter.clusterNames.LevelControl, { currentLevel: level })
536
- }
537
-
538
- // Color
539
- if (parsed.color !== undefined) {
540
- const { r, g, b } = parsed.color
541
- const [h, s] = rgb2hs(r, g, b)
542
- await this.api.matter.updateAccessoryState(uuidLocal, this.api.matter.clusterNames.ColorControl, { currentHue: Math.round((h / 360) * 254), currentSaturation: Math.round((s / 100) * 254) })
543
- }
544
-
545
- // If we parsed something from serviceData prefer it and return early
546
- if (serviceData) {
547
- return
548
- }
549
- }
550
- } catch (e: any) {
551
- this.log.debug(`BLE advertisement parsing failed for ${dev.deviceId}: ${e?.message ?? e}`)
552
- }
553
-
554
- // Fallback to OpenAPI getDeviceStatus when serviceData is not present or parsing failed
555
- if (!this.switchBotAPI) {
556
- return
557
- }
558
- try {
559
- const { response, statusCode } = await this.switchBotAPI.getDeviceStatus(dev.deviceId, this.config.credentials?.token, this.config.credentials?.secret)
560
- if (!(statusCode === 100 || statusCode === 200)) {
561
- return
562
- }
563
- const respAny: any = response
564
- const body = respAny?.body ?? respAny
565
- const status = body?.status ?? body
566
-
567
- // On/Off
568
- if (status?.power !== undefined) {
569
- const on = (String(status.power).toLowerCase() === 'on' || Number(status.power) === 1)
570
- await this.api.matter.updateAccessoryState(uuidLocal, this.api.matter.clusterNames.OnOff, { onOff: on })
571
- }
572
-
573
- // Brightness
574
- if (status?.brightness !== undefined) {
575
- const level = Math.round((Number(status.brightness) / 100) * 254)
576
- await this.api.matter.updateAccessoryState(uuidLocal, this.api.matter.clusterNames.LevelControl, { currentLevel: level })
577
- }
578
-
579
- // Color
580
- if (status?.color !== undefined) {
581
- const color = String(status.color)
582
- let r = 0
583
- let g = 0
584
- let b = 0
585
- if (color.includes(':')) {
586
- const parts = color.split(':').map(Number)
587
- ;[r, g, b] = parts
588
- } else if (color.startsWith('#')) {
589
- const hex = color.replace('#', '')
590
- r = Number.parseInt(hex.substring(0, 2), 16)
591
- g = Number.parseInt(hex.substring(2, 4), 16)
592
- b = Number.parseInt(hex.substring(4, 6), 16)
593
- }
594
- const [h, s] = rgb2hs(r, g, b)
595
- await this.api.matter.updateAccessoryState(uuidLocal, this.api.matter.clusterNames.ColorControl, { currentHue: Math.round((h / 360) * 254), currentSaturation: Math.round((s / 100) * 254) })
596
- }
597
- } catch (e: any) {
598
- this.log.debug(`BLE push handler failed for ${dev.deviceId}: ${e?.message ?? e}`)
599
- }
600
- }
601
- } catch (e: any) {
602
- this.log.debug(`Failed to register BLE handler for ${dev.deviceId}: ${e?.message ?? e}`)
603
- }
604
-
605
- return instance.toAccessory()
606
- }
607
-
608
- /**
609
- * Discover devices via SwitchBot OpenAPI and cache them for later use
610
- */
611
- private async discoverDevices(): Promise<void> {
612
- if (!this.switchBotAPI) {
613
- this.log.debug('SwitchBot OpenAPI not configured; skipping discovery')
614
- return
615
- }
616
-
617
- try {
618
- const { response, statusCode } = await this.switchBotAPI.getDevices()
619
- this.log.debug(`SwitchBot getDevices response status: ${statusCode}`)
620
- if (statusCode === 100 || statusCode === 200) {
621
- const deviceList = Array.isArray(response?.body?.deviceList) ? response.body.deviceList : []
622
- this.discoveredDevices = deviceList
623
- this.log.info(`Discovered ${deviceList.length} SwitchBot device(s) from OpenAPI`)
624
- for (const d of deviceList) {
625
- this.log.debug(` - ${d.deviceName} (${d.deviceType}) id=${d.deviceId}`)
626
- }
627
- } else {
628
- this.log.warn(`SwitchBot getDevices returned status ${statusCode}`)
629
- }
630
- } catch (e: any) {
631
- this.log.error('Failed to discover SwitchBot devices:', e?.message ?? e)
632
- }
633
- }
634
-
635
- /**
636
- * Retry wrapper for control commands using SwitchBot OpenAPI
637
- */
638
- async retryCommand(deviceObj: device, bodyChange: bodyChange, maxRetries = 1, delayBetweenRetries = 1000): Promise<{ response: any, statusCode: number }> {
639
- let retryCount = 0
640
- while (retryCount < maxRetries) {
641
- try {
642
- if (!this.switchBotAPI) {
643
- throw new Error('SwitchBot OpenAPI not initialized')
644
- }
645
- const { response, statusCode } = await this.switchBotAPI.controlDevice(
646
- deviceObj.deviceId,
647
- bodyChange.command,
648
- bodyChange.parameter,
649
- bodyChange.commandType as import('node-switchbot').commandType | undefined,
650
- this.config.credentials?.token,
651
- this.config.credentials?.secret,
652
- )
653
- return { response, statusCode }
654
- } catch (e: any) {
655
- this.log.debug(`retryCommand error: ${e?.message ?? e}`)
656
- }
657
- retryCount++
658
-
659
- await sleep(delayBetweenRetries)
660
- }
661
- return { response: {}, statusCode: 500 }
662
- }
663
-
664
- /**
665
- * Parse BLE advertisement/serviceData into normalized fields for a given device.
666
- * Returns null when serviceData is falsy or parsing fails.
667
- */
668
- private parseAdvertisementForDevice(dev: device, serviceData?: any) {
669
- if (!serviceData) {
670
- return null
671
- }
672
- try {
673
- const sd = serviceData
674
- const result: any = {}
675
-
676
- // Power/on state - supports multiple field names used by different models
677
- const power = sd.power ?? sd.on ?? sd.p
678
- if (power !== undefined) {
679
- result.power = (String(power).toLowerCase() === 'on' || Number(power) === 1)
680
- }
681
-
682
- // Brightness (0-100)
683
- const brightness = sd.brightness ?? sd.b
684
- if (brightness !== undefined) {
685
- result.brightness = Number(brightness)
686
- }
687
-
688
- // Color - could be 'r:g:b', '#rrggbb' or 'rrggbb'
689
- const color = sd.color ?? sd.rgb ?? sd.c
690
- if (color !== undefined) {
691
- let r = 0
692
- let g = 0
693
- let b = 0
694
- const c = String(color)
695
- if (c.includes(':')) {
696
- const parts = c.split(':').map(Number)
697
- ;[r, g, b] = parts
698
- } else if (c.startsWith('#')) {
699
- const hex = c.replace('#', '')
700
- r = Number.parseInt(hex.substring(0, 2), 16)
701
- g = Number.parseInt(hex.substring(2, 4), 16)
702
- b = Number.parseInt(hex.substring(4, 6), 16)
703
- } else if (/^[0-9a-f]{6}$/i.test(c)) {
704
- r = Number.parseInt(c.substring(0, 2), 16)
705
- g = Number.parseInt(c.substring(2, 4), 16)
706
- b = Number.parseInt(c.substring(4, 6), 16)
707
- }
708
- result.color = { r, g, b }
709
- }
710
-
711
- // Battery (some devices use battery or batt)
712
- const battery = sd.battery ?? sd.batt
713
- if (battery !== undefined) {
714
- result.battery = Number(battery)
715
- }
716
-
717
- return result
718
- } catch (e: any) {
719
- this.log.debug(`parseAdvertisementForDevice failed for ${dev.deviceId}: ${e?.message ?? e}`)
720
- return null
721
- }
722
- }
723
-
724
- /**
725
- * Required for DynamicPlatformPlugin
726
- * Called when homebridge restores cached accessories from disk at startup
727
- */
728
- configureAccessory(/* accessory: PlatformAccessory */) {
729
- // Note this is not used for Matter accessories - use configureMatterAccessory instead
730
- // This plugin does not have any hap accessories, so here we can comment this out
731
- // this.accessories.set(accessory.UUID, accessory)
732
- }
733
-
734
- /**
735
- * Called when homebridge restores cached Matter accessories from disk at startup.
736
- *
737
- * This is where you can access the `accessory.context` object to retrieve
738
- * any custom data you stored when the accessory was originally registered.
739
- */
740
- configureMatterAccessory(accessory: SerializedMatterAccessory) {
741
- this.log.debug('Loading cached Matter accessory:', accessory.displayName)
742
- this.matterAccessories.set(accessory.uuid, accessory)
743
- }
744
-
745
- /**
746
- * Register all Matter accessories
747
- */
748
- private async registerMatterAccessories() {
749
- this.log.debug('═'.repeat(80))
750
- this.log.info('Homebridge Matter Plugin')
751
- this.log.debug('═'.repeat(80))
752
-
753
- // Remove accessories that are disabled in config
754
- await this.removeDisabledAccessories()
755
-
756
- // If we discovered real SwitchBot devices via OpenAPI, map and register them
757
- if (this.discoveredDevices && this.discoveredDevices.length > 0) {
758
- this.log.info(`Registering ${this.discoveredDevices.length} discovered SwitchBot device(s) as Matter accessories`)
759
- const accessories: Array<MatterAccessory<Record<string, unknown>>> = []
760
-
761
- // Merge device config (deviceConfig per deviceType and per-device overrides) to match HAP behavior
762
- const devicesToProcess = await this.mergeDiscoveredDevices(this.discoveredDevices)
763
-
764
- for (const dev of devicesToProcess) {
765
- try {
766
- const acc = await this.createAccessoryFromDevice(dev)
767
- if (acc) {
768
- accessories.push(acc)
769
- }
770
- } catch (e: any) {
771
- this.log.error(`Failed to create Matter accessory for ${dev.deviceId}: ${e?.message ?? e}`)
772
- }
773
- }
774
- if (accessories.length > 0) {
775
- this.log.info(`✓ Registered ${accessories.length} discovered device(s)`)
776
- for (const acc of accessories) {
777
- this.log.info(` - ${acc.displayName}`)
778
- }
779
- await this.api.matter.registerPlatformAccessories(PLUGIN_NAME, PLATFORM_NAME, accessories)
780
- return
781
- }
782
- this.log.info('No discovered devices were mapped to Matter accessories; falling back to example sections')
783
- }
784
-
785
- // Register example/demo devices by Matter specification sections
786
- await this.registerSection4Lighting()
787
- await this.registerSection5SmartPlugs()
788
- await this.registerSection6Switches()
789
- await this.registerSection7Sensors()
790
- await this.registerSection8Closure()
791
- await this.registerSection9HVAC()
792
- await this.registerSection12Robotic()
793
- await this.registerCustomDevices()
794
-
795
- this.log.debug('═'.repeat(80))
796
- this.log.debug('Finished registering Matter accessories')
797
- this.log.debug('═'.repeat(80))
798
- }
799
-
800
- /**
801
- * Remove accessories that are disabled in config
802
- */
803
- private async removeDisabledAccessories() {
804
- const configMap = [
805
- { enabled: this.config.enableOnOffLight, uuid: this.api.matter.uuid.generate('matter-onoff-light'), name: 'On/Off Light' },
806
- { enabled: this.config.enableDimmableLight, uuid: this.api.matter.uuid.generate('matter-dimmable-light'), name: 'Dimmable Light' },
807
- { enabled: this.config.enableColourTemperatureLight, uuid: this.api.matter.uuid.generate('matter-colour-temp-light'), name: 'Colour Temperature Light' },
808
- { enabled: this.config.enableColourLight, uuid: this.api.matter.uuid.generate('matter-colour-light'), name: 'Colour Light (HS)' },
809
- { enabled: this.config.enableExtendedColourLight, uuid: this.api.matter.uuid.generate('matter-extended-colour-light'), name: 'Extended Colour Light' },
810
- { enabled: this.config.enableOnOffOutlet, uuid: this.api.matter.uuid.generate('matter-onoff-outlet'), name: 'On/Off Outlet' },
811
- { enabled: this.config.enableOnOffSwitch, uuid: this.api.matter.uuid.generate('matter-onoff-switch'), name: 'On/Off Switch' },
812
- { enabled: this.config.enableTemperatureSensor, uuid: this.api.matter.uuid.generate('matter-temperature-sensor'), name: 'Temperature Sensor' },
813
- { enabled: this.config.enableHumiditySensor, uuid: this.api.matter.uuid.generate('matter-humidity-sensor'), name: 'Humidity Sensor' },
814
- { enabled: this.config.enableLightSensor, uuid: this.api.matter.uuid.generate('matter-light-sensor'), name: 'Light Sensor' },
815
- { enabled: this.config.enableOccupancySensor, uuid: this.api.matter.uuid.generate('matter-occupancy-sensor'), name: 'Occupancy Sensor' },
816
- { enabled: this.config.enableContactSensor, uuid: this.api.matter.uuid.generate('matter-contact-sensor'), name: 'Contact Sensor' },
817
- { enabled: this.config.enableLeakSensor, uuid: this.api.matter.uuid.generate('matter-leak-sensor'), name: 'Leak Sensor' },
818
- { enabled: this.config.enableSmokeSensor, uuid: this.api.matter.uuid.generate('matter-smoke-sensor'), name: 'Smoke Sensor' },
819
- { enabled: this.config.enableDoorLock, uuid: this.api.matter.uuid.generate('matter-door-lock'), name: 'Door Lock' },
820
- { enabled: this.config.enableWindowBlind, uuid: this.api.matter.uuid.generate('matter-window-blind'), name: 'Window Blind' },
821
- { enabled: this.config.enableVenetianBlind, uuid: this.api.matter.uuid.generate('matter-venetian-blind'), name: 'Venetian Blind' },
822
- { enabled: this.config.enableThermostat, uuid: this.api.matter.uuid.generate('matter-thermostat'), name: 'Thermostat' },
823
- { enabled: this.config.enableFan, uuid: this.api.matter.uuid.generate('matter-fan'), name: 'Fan' },
824
- { enabled: this.config.enableRobotVacuum, uuid: this.api.matter.uuid.generate('matter-robot-vacuum'), name: 'Robot Vacuum' },
825
- { enabled: this.config.enablePowerStrip, uuid: this.api.matter.uuid.generate('matter-power-strip'), name: 'Power Strip' },
826
- ]
827
-
828
- for (const { enabled, uuid, name } of configMap) {
829
- if (enabled === false) {
830
- const existingAccessory = this.matterAccessories.get(uuid)
831
- if (existingAccessory) {
832
- this.log.info(`Removing accessory '${name}' (disabled in config)`)
833
- await this.api.matter.unregisterPlatformAccessories(PLUGIN_NAME, PLATFORM_NAME, [existingAccessory as unknown as MatterAccessory])
834
- this.matterAccessories.delete(uuid)
835
- }
836
- }
837
- }
838
- }
839
-
840
- /**
841
- * Section 4: Lighting Devices (Matter Spec § 4)
842
- */
843
- private async registerSection4Lighting() {
844
- this.log.debug('═'.repeat(80))
845
- this.log.info('Section 4: Lighting Devices (Matter Spec § 4)')
846
- this.log.debug('═'.repeat(80))
847
-
848
- const accessories: Array<MatterAccessory<Record<string, unknown>>> = []
849
-
850
- // On/Off Light
851
- if (this.config.enableOnOffLight !== false) {
852
- const device = new OnOffLightAccessory(this.api, this.log)
853
- accessories.push(device.toAccessory())
854
- }
855
-
856
- // Dimmable Light
857
- if (this.config.enableDimmableLight !== false) {
858
- const device = new DimmableLightAccessory(this.api, this.log)
859
- accessories.push(device.toAccessory())
860
- }
861
-
862
- // Color Temperature Light
863
- if (this.config.enableColourTemperatureLight !== false) {
864
- const device = new ColorTemperatureLightAccessory(this.api, this.log)
865
- accessories.push(device.toAccessory())
866
- }
867
-
868
- // Color Light (HS only)
869
- if (this.config.enableColourLight !== false) {
870
- const device = new ColorLightAccessory(this.api, this.log)
871
- accessories.push(device.toAccessory())
872
- }
873
-
874
- // Extended Color Light (HS+CCT)
875
- if (this.config.enableExtendedColourLight !== false) {
876
- const device = new ExtendedColorLightAccessory(this.api, this.log)
877
- accessories.push(device.toAccessory())
878
- }
879
-
880
- if (accessories.length > 0) {
881
- this.log.info(`✓ Registered ${accessories.length} lighting device(s)`)
882
- for (const acc of accessories) {
883
- this.log.info(` - ${acc.displayName}`)
884
- }
885
- await this.api.matter.registerPlatformAccessories(PLUGIN_NAME, PLATFORM_NAME, accessories)
886
- }
887
- }
888
-
889
- /**
890
- * Section 5: Smart Plugs/Actuators (Matter Spec § 5)
891
- */
892
- private async registerSection5SmartPlugs() {
893
- this.log.debug('═'.repeat(80))
894
- this.log.info('Section 5: Smart Plugs/Actuators (Matter Spec § 5)')
895
- this.log.debug('═'.repeat(80))
896
-
897
- const accessories: Array<MatterAccessory<Record<string, unknown>>> = []
898
-
899
- // On/Off Outlet
900
- if (this.config.enableOnOffOutlet !== false) {
901
- const device = new OnOffOutletAccessory(this.api, this.log)
902
- accessories.push(device.toAccessory())
903
- }
904
-
905
- if (accessories.length > 0) {
906
- this.log.info(`✓ Registered ${accessories.length} smart plug/actuator device(s)`)
907
- for (const acc of accessories) {
908
- this.log.info(` - ${acc.displayName}`)
909
- }
910
- await this.api.matter.registerPlatformAccessories(PLUGIN_NAME, PLATFORM_NAME, accessories)
911
- }
912
- }
913
-
914
- /**
915
- * Section 6: Switches & Controllers (Matter Spec § 6)
916
- */
917
- private async registerSection6Switches() {
918
- this.log.debug('═'.repeat(80))
919
- this.log.info('Section 6: Switches & Controllers (Matter Spec § 6)')
920
- this.log.debug('═'.repeat(80))
921
-
922
- const accessories: Array<MatterAccessory<Record<string, unknown>>> = []
923
-
924
- // On/Off Switch
925
- if (this.config.enableOnOffSwitch !== false) {
926
- const device = new OnOffSwitchAccessory(this.api, this.log)
927
- accessories.push(device.toAccessory())
928
- }
929
-
930
- if (accessories.length > 0) {
931
- this.log.info(`✓ Registered ${accessories.length} switch/controller device(s)`)
932
- for (const acc of accessories) {
933
- this.log.info(` - ${acc.displayName}`)
934
- }
935
- await this.api.matter.registerPlatformAccessories(PLUGIN_NAME, PLATFORM_NAME, accessories)
936
- }
937
- }
938
-
939
- /**
940
- * Section 7: Sensors (Matter Spec § 7)
941
- */
942
- private async registerSection7Sensors() {
943
- this.log.debug('═'.repeat(80))
944
- this.log.info('Section 7: Sensors (Matter Spec § 7)')
945
- this.log.debug('═'.repeat(80))
946
-
947
- const accessories: Array<MatterAccessory<Record<string, unknown>>> = []
948
-
949
- // Contact Sensor
950
- if (this.config.enableContactSensor !== false) {
951
- const device = new ContactSensorAccessory(this.api, this.log)
952
- accessories.push(device.toAccessory())
953
- }
954
-
955
- // Light Sensor
956
- if (this.config.enableLightSensor !== false) {
957
- const device = new LightSensorAccessory(this.api, this.log)
958
- accessories.push(device.toAccessory())
959
- }
960
-
961
- // Occupancy Sensor
962
- if (this.config.enableOccupancySensor !== false) {
963
- const device = new OccupancySensorAccessory(this.api, this.log)
964
- accessories.push(device.toAccessory())
965
- }
966
-
967
- // Temperature Sensor
968
- if (this.config.enableTemperatureSensor !== false) {
969
- const device = new TemperatureSensorAccessory(this.api, this.log)
970
- accessories.push(device.toAccessory())
971
- }
972
-
973
- // Humidity Sensor
974
- if (this.config.enableHumiditySensor !== false) {
975
- const device = new HumiditySensorAccessory(this.api, this.log)
976
- accessories.push(device.toAccessory())
977
- }
978
-
979
- // Smoke/CO Alarm
980
- if (this.config.enableSmokeSensor !== false) {
981
- const device = new SmokeCOAlarmAccessory(this.api, this.log)
982
- accessories.push(device.toAccessory())
983
- }
984
-
985
- // Leak Sensor
986
- if (this.config.enableLeakSensor !== false) {
987
- const device = new LeakSensorAccessory(this.api, this.log)
988
- accessories.push(device.toAccessory())
989
- }
990
-
991
- if (accessories.length > 0) {
992
- this.log.info(`✓ Registered ${accessories.length} sensor device(s)`)
993
- for (const acc of accessories) {
994
- this.log.info(` - ${acc.displayName}`)
995
- }
996
- await this.api.matter.registerPlatformAccessories(PLUGIN_NAME, PLATFORM_NAME, accessories)
997
- }
998
- }
999
-
1000
- /**
1001
- * Section 8: Closure Devices (Matter Spec § 8)
1002
- */
1003
- private async registerSection8Closure() {
1004
- this.log.debug('═'.repeat(80))
1005
- this.log.info('Section 8: Closure Devices (Matter Spec § 8)')
1006
- this.log.debug('═'.repeat(80))
1007
-
1008
- const accessories: Array<MatterAccessory<Record<string, unknown>>> = []
1009
-
1010
- // Door Lock
1011
- if (this.config.enableDoorLock !== false) {
1012
- const device = new DoorLockAccessory(this.api, this.log)
1013
- accessories.push(device.toAccessory())
1014
- }
1015
-
1016
- // Window Blind
1017
- if (this.config.enableWindowBlind !== false) {
1018
- const device = new WindowBlindAccessory(this.api, this.log)
1019
- accessories.push(device.toAccessory())
1020
- }
1021
-
1022
- // Venetian Blind
1023
- if (this.config.enableVenetianBlind !== false) {
1024
- const device = new VenetianBlindAccessory(this.api, this.log)
1025
- accessories.push(device.toAccessory())
1026
- }
1027
-
1028
- if (accessories.length > 0) {
1029
- this.log.info(`✓ Registered ${accessories.length} closure device(s)`)
1030
- for (const acc of accessories) {
1031
- this.log.info(` - ${acc.displayName}`)
1032
- }
1033
- await this.api.matter.registerPlatformAccessories(PLUGIN_NAME, PLATFORM_NAME, accessories)
1034
- }
1035
- }
1036
-
1037
- /**
1038
- * Section 9: HVAC (Matter Spec § 9)
1039
- */
1040
- private async registerSection9HVAC() {
1041
- this.log.debug('═'.repeat(80))
1042
- this.log.info('Section 9: HVAC (Matter Spec § 9)')
1043
- this.log.debug('═'.repeat(80))
1044
-
1045
- const accessories: Array<MatterAccessory<Record<string, unknown>>> = []
1046
-
1047
- // Thermostat
1048
- if (this.config.enableThermostat !== false) {
1049
- const device = new ThermostatAccessory(this.api, this.log)
1050
- accessories.push(device.toAccessory())
1051
- }
1052
-
1053
- // Fan
1054
- if (this.config.enableFan !== false) {
1055
- const device = new FanAccessory(this.api, this.log)
1056
- accessories.push(device.toAccessory())
1057
- }
1058
-
1059
- if (accessories.length > 0) {
1060
- this.log.info(`✓ Registered ${accessories.length} HVAC device(s)`)
1061
- for (const acc of accessories) {
1062
- this.log.info(` - ${acc.displayName}`)
1063
- }
1064
- await this.api.matter.registerPlatformAccessories(PLUGIN_NAME, PLATFORM_NAME, accessories)
1065
- }
1066
- }
1067
-
1068
- /**
1069
- * Section 12: Robotic Devices (Matter Spec § 12)
1070
- * ⚠️ IMPORTANT: RVC devices use a DIFFERENT PROCESS (same code) than other devices!
1071
- * When this runs, you'll see separate commissioning codes in the logs for the robot vacuum.
1072
- * Use those codes to pair the vacuum as a separate bridge in your Home app.
1073
- */
1074
- private async registerSection12Robotic() {
1075
- this.log.debug('═'.repeat(80))
1076
- this.log.info('Section 12: Robotic Devices (Matter Spec § 12)')
1077
- this.log.debug('═'.repeat(80))
1078
-
1079
- const accessories: Array<MatterAccessory<Record<string, unknown>>> = []
1080
-
1081
- // Robot Vacuum
1082
- if (this.config.enableRobotVacuum !== false) {
1083
- const device = new RoboticVacuumAccessory(this.api, this.log)
1084
- accessories.push(device.toAccessory())
1085
- }
1086
-
1087
- if (accessories.length > 0) {
1088
- this.log.info(`✓ Registered ${accessories.length} robot vacuum device(s)`)
1089
- for (const acc of accessories) {
1090
- this.log.info(` - ${acc.displayName} (standalone for Apple Home compatibility)`)
1091
- }
1092
- await this.api.matter.registerPlatformAccessories(PLUGIN_NAME, PLATFORM_NAME, accessories)
1093
- }
1094
- }
1095
-
1096
- /**
1097
- * Custom Devices
1098
- *
1099
- * This section demonstrates custom device implementations that go beyond
1100
- * the standard Matter device types. These examples show advanced patterns
1101
- * like managing multiple logical components within a single device.
1102
- */
1103
- private async registerCustomDevices() {
1104
- this.log.debug('═'.repeat(80))
1105
- this.log.info('Custom Devices')
1106
- this.log.debug('═'.repeat(80))
1107
-
1108
- const accessories: Array<MatterAccessory<Record<string, unknown>>> = []
1109
-
1110
- // Power Strip (4 Outlets)
1111
- if (this.config.enablePowerStrip !== false) {
1112
- const device = new PowerStripAccessory(this.api, this.log)
1113
- accessories.push(device.toAccessory())
1114
- }
1115
-
1116
- if (accessories.length > 0) {
1117
- this.log.info(`✓ Registered ${accessories.length} custom device(s)`)
1118
- for (const acc of accessories) {
1119
- this.log.info(` - ${acc.displayName}`)
1120
- }
1121
- await this.api.matter.registerPlatformAccessories(PLUGIN_NAME, PLATFORM_NAME, accessories)
1122
- }
1123
- }
1124
- }