@switchbot/homebridge-switchbot 5.0.0-beta.9 → 5.0.0-beta.91

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