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