@switchbot/homebridge-switchbot 5.0.0-beta.7 → 5.0.0-beta.71

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