@switchbot/homebridge-switchbot 5.0.0-beta.11 → 5.0.0-beta.111

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 (578) hide show
  1. package/.github/ISSUE_TEMPLATE/e2e-verification.md +36 -0
  2. package/.github/copilot-instructions.md +39 -0
  3. package/.github/workflows/ci.yml +32 -0
  4. package/.github/workflows/manual-e2e.yml +115 -0
  5. package/.github/workflows/release.yml +0 -4
  6. package/CHANGELOG.md +35 -0
  7. package/E2E-VERIFICATION.md +121 -0
  8. package/MIGRATION.md +44 -0
  9. package/README.md +56 -3
  10. package/config.schema.json +170 -14787
  11. package/dist/device-types.d.ts +31 -0
  12. package/dist/device-types.d.ts.map +1 -0
  13. package/dist/device-types.js +216 -0
  14. package/dist/device-types.js.map +1 -0
  15. package/dist/deviceFactory.d.ts +13 -0
  16. package/dist/deviceFactory.d.ts.map +1 -0
  17. package/dist/deviceFactory.js +120 -0
  18. package/dist/deviceFactory.js.map +1 -0
  19. package/dist/devices/deviceBase.d.ts +50 -0
  20. package/dist/devices/deviceBase.d.ts.map +1 -0
  21. package/dist/devices/deviceBase.js +119 -0
  22. package/dist/devices/deviceBase.js.map +1 -0
  23. package/dist/devices/genericDevice.d.ts +298 -0
  24. package/dist/devices/genericDevice.d.ts.map +1 -0
  25. package/dist/devices/genericDevice.js +1067 -0
  26. package/dist/devices/genericDevice.js.map +1 -0
  27. package/dist/homebridge-ui/endpoints/config.d.ts +3 -0
  28. package/dist/homebridge-ui/endpoints/config.d.ts.map +1 -0
  29. package/dist/homebridge-ui/endpoints/config.js +104 -0
  30. package/dist/homebridge-ui/endpoints/config.js.map +1 -0
  31. package/dist/homebridge-ui/endpoints/credentials.d.ts +6 -0
  32. package/dist/homebridge-ui/endpoints/credentials.d.ts.map +1 -0
  33. package/dist/homebridge-ui/endpoints/credentials.js +65 -0
  34. package/dist/homebridge-ui/endpoints/credentials.js.map +1 -0
  35. package/dist/homebridge-ui/endpoints/devices.d.ts +6 -0
  36. package/dist/homebridge-ui/endpoints/devices.d.ts.map +1 -0
  37. package/dist/homebridge-ui/endpoints/devices.js +351 -0
  38. package/dist/homebridge-ui/endpoints/devices.js.map +1 -0
  39. package/dist/homebridge-ui/endpoints/discovery.d.ts +7 -0
  40. package/dist/homebridge-ui/endpoints/discovery.d.ts.map +1 -0
  41. package/dist/homebridge-ui/endpoints/discovery.js +171 -0
  42. package/dist/homebridge-ui/endpoints/discovery.js.map +1 -0
  43. package/dist/homebridge-ui/public/css/styles.css +254 -0
  44. package/dist/homebridge-ui/public/index.html +112 -247
  45. package/dist/homebridge-ui/public/js/api.d.ts +23 -0
  46. package/dist/homebridge-ui/public/js/api.d.ts.map +1 -0
  47. package/dist/homebridge-ui/public/js/api.js +188 -0
  48. package/dist/homebridge-ui/public/js/api.js.map +1 -0
  49. package/dist/homebridge-ui/public/js/api.ts +215 -0
  50. package/dist/homebridge-ui/public/js/app.d.ts +2 -0
  51. package/dist/homebridge-ui/public/js/app.d.ts.map +1 -0
  52. package/dist/homebridge-ui/public/js/app.js +1815 -0
  53. package/dist/homebridge-ui/public/js/app.js.map +7 -0
  54. package/dist/homebridge-ui/public/js/app.ts +22 -0
  55. package/dist/homebridge-ui/public/js/constants.d.ts +2 -0
  56. package/dist/homebridge-ui/public/js/constants.d.ts.map +1 -0
  57. package/dist/homebridge-ui/public/js/constants.js +2 -0
  58. package/dist/homebridge-ui/public/js/constants.js.map +1 -0
  59. package/dist/homebridge-ui/public/js/constants.ts +1 -0
  60. package/dist/homebridge-ui/public/js/credentials.d.ts +3 -0
  61. package/dist/homebridge-ui/public/js/credentials.d.ts.map +1 -0
  62. package/dist/homebridge-ui/public/js/credentials.js +96 -0
  63. package/dist/homebridge-ui/public/js/credentials.js.map +1 -0
  64. package/dist/homebridge-ui/public/js/credentials.ts +100 -0
  65. package/dist/homebridge-ui/public/js/devices-delete.d.ts +3 -0
  66. package/dist/homebridge-ui/public/js/devices-delete.d.ts.map +1 -0
  67. package/dist/homebridge-ui/public/js/devices-delete.js +206 -0
  68. package/dist/homebridge-ui/public/js/devices-delete.js.map +1 -0
  69. package/dist/homebridge-ui/public/js/devices-delete.ts +236 -0
  70. package/dist/homebridge-ui/public/js/devices.d.ts +9 -0
  71. package/dist/homebridge-ui/public/js/devices.d.ts.map +1 -0
  72. package/dist/homebridge-ui/public/js/devices.js +90 -0
  73. package/dist/homebridge-ui/public/js/devices.js.map +1 -0
  74. package/dist/homebridge-ui/public/js/devices.ts +98 -0
  75. package/dist/homebridge-ui/public/js/discovery.d.ts +3 -0
  76. package/dist/homebridge-ui/public/js/discovery.d.ts.map +1 -0
  77. package/dist/homebridge-ui/public/js/discovery.js +244 -0
  78. package/dist/homebridge-ui/public/js/discovery.js.map +1 -0
  79. package/dist/homebridge-ui/public/js/discovery.ts +290 -0
  80. package/dist/homebridge-ui/public/js/logger.d.ts +6 -0
  81. package/dist/homebridge-ui/public/js/logger.d.ts.map +1 -0
  82. package/dist/homebridge-ui/public/js/logger.js +12 -0
  83. package/dist/homebridge-ui/public/js/logger.js.map +1 -0
  84. package/dist/homebridge-ui/public/js/logger.ts +11 -0
  85. package/dist/homebridge-ui/public/js/modal.d.ts +5 -0
  86. package/dist/homebridge-ui/public/js/modal.d.ts.map +1 -0
  87. package/dist/homebridge-ui/public/js/modal.js +26 -0
  88. package/dist/homebridge-ui/public/js/modal.js.map +1 -0
  89. package/dist/homebridge-ui/public/js/modal.ts +28 -0
  90. package/dist/homebridge-ui/public/js/modals.d.ts +7 -0
  91. package/dist/homebridge-ui/public/js/modals.d.ts.map +1 -0
  92. package/dist/homebridge-ui/public/js/modals.js +323 -0
  93. package/dist/homebridge-ui/public/js/modals.js.map +1 -0
  94. package/dist/homebridge-ui/public/js/modals.ts +367 -0
  95. package/dist/homebridge-ui/public/js/render.d.ts +65 -0
  96. package/dist/homebridge-ui/public/js/render.d.ts.map +1 -0
  97. package/dist/homebridge-ui/public/js/render.js +499 -0
  98. package/dist/homebridge-ui/public/js/render.js.map +1 -0
  99. package/dist/homebridge-ui/public/js/render.ts +579 -0
  100. package/dist/homebridge-ui/public/js/toast.d.ts +6 -0
  101. package/dist/homebridge-ui/public/js/toast.d.ts.map +1 -0
  102. package/dist/homebridge-ui/public/js/toast.js +29 -0
  103. package/dist/homebridge-ui/public/js/toast.js.map +1 -0
  104. package/dist/homebridge-ui/public/js/toast.ts +37 -0
  105. package/dist/homebridge-ui/public/js/types.d.ts +23 -0
  106. package/dist/homebridge-ui/public/js/types.d.ts.map +1 -0
  107. package/dist/homebridge-ui/public/js/types.js +2 -0
  108. package/dist/homebridge-ui/public/js/types.js.map +1 -0
  109. package/dist/homebridge-ui/public/js/types.ts +26 -0
  110. package/dist/homebridge-ui/server.js +11 -41
  111. package/dist/homebridge-ui/server.js.map +1 -1
  112. package/dist/homebridge-ui/utils/config-parser.d.ts +35 -0
  113. package/dist/homebridge-ui/utils/config-parser.d.ts.map +1 -0
  114. package/dist/homebridge-ui/utils/config-parser.js +87 -0
  115. package/dist/homebridge-ui/utils/config-parser.js.map +1 -0
  116. package/dist/homebridge-ui/utils/device-migration.d.ts +35 -0
  117. package/dist/homebridge-ui/utils/device-migration.d.ts.map +1 -0
  118. package/dist/homebridge-ui/utils/device-migration.js +111 -0
  119. package/dist/homebridge-ui/utils/device-migration.js.map +1 -0
  120. package/dist/homebridge-ui/utils/logger.d.ts +7 -0
  121. package/dist/homebridge-ui/utils/logger.d.ts.map +1 -0
  122. package/dist/homebridge-ui/utils/logger.js +17 -0
  123. package/dist/homebridge-ui/utils/logger.js.map +1 -0
  124. package/dist/index.d.ts.map +1 -1
  125. package/dist/index.js +4 -65
  126. package/dist/index.js.map +1 -1
  127. package/dist/platform.d.ts +35 -0
  128. package/dist/platform.d.ts.map +1 -0
  129. package/dist/platform.js +1527 -0
  130. package/dist/platform.js.map +1 -0
  131. package/dist/settings.d.ts +10 -249
  132. package/dist/settings.d.ts.map +1 -1
  133. package/dist/settings.js +5 -30
  134. package/dist/settings.js.map +1 -1
  135. package/dist/switchbotClient.d.ts +32 -0
  136. package/dist/switchbotClient.d.ts.map +1 -0
  137. package/dist/switchbotClient.js +207 -0
  138. package/dist/switchbotClient.js.map +1 -0
  139. package/dist/utils.d.ts +39 -50
  140. package/dist/utils.d.ts.map +1 -1
  141. package/dist/utils.js +40 -688
  142. package/dist/utils.js.map +1 -1
  143. package/docs/assets/highlight.css +14 -0
  144. package/docs/assets/icons.js +1 -1
  145. package/docs/assets/icons.svg +1 -1
  146. package/docs/assets/main.js +2 -2
  147. package/docs/assets/style.css +3 -3
  148. package/docs/index.html +77 -13
  149. package/docs/variables/default.html +1 -1
  150. package/eslint.config.js +7 -8
  151. package/nodemon.json +2 -2
  152. package/package.json +35 -32
  153. package/scripts/build-ui.js +36 -0
  154. package/scripts/e2e/README.md +25 -0
  155. package/scripts/e2e/curtain-e2e.sh +70 -0
  156. package/scripts/e2e/fan-e2e.sh +75 -0
  157. package/scripts/e2e/light-advanced-e2e.sh +97 -0
  158. package/scripts/e2e/light-e2e.sh +75 -0
  159. package/scripts/e2e/list-accessories.sh +19 -0
  160. package/scripts/e2e/lock-e2e.sh +65 -0
  161. package/scripts/free-dev-ports.mjs +105 -0
  162. package/scripts/generate-matter-maps.js +60 -0
  163. package/scripts/run-e2e-local.sh +14 -0
  164. package/scripts/sync-device-types.mjs +28 -0
  165. package/src/device-types.ts +230 -0
  166. package/src/deviceFactory.ts +163 -0
  167. package/src/devices/deviceBase.ts +141 -0
  168. package/src/devices/genericDevice.ts +998 -0
  169. package/src/homebridge-ui/endpoints/config.ts +123 -0
  170. package/src/homebridge-ui/endpoints/credentials.ts +74 -0
  171. package/src/homebridge-ui/endpoints/devices.ts +383 -0
  172. package/src/homebridge-ui/endpoints/discovery.ts +191 -0
  173. package/src/homebridge-ui/public/css/styles.css +254 -0
  174. package/src/homebridge-ui/public/index.html +112 -247
  175. package/src/homebridge-ui/public/js/api.ts +215 -0
  176. package/src/homebridge-ui/public/js/app.ts +22 -0
  177. package/src/homebridge-ui/public/js/constants.ts +1 -0
  178. package/src/homebridge-ui/public/js/credentials.ts +100 -0
  179. package/src/homebridge-ui/public/js/devices-delete.ts +236 -0
  180. package/src/homebridge-ui/public/js/devices.ts +98 -0
  181. package/src/homebridge-ui/public/js/discovery.ts +290 -0
  182. package/src/homebridge-ui/public/js/logger.ts +11 -0
  183. package/src/homebridge-ui/public/js/modal.ts +28 -0
  184. package/src/homebridge-ui/public/js/modals.ts +367 -0
  185. package/src/homebridge-ui/public/js/render.ts +579 -0
  186. package/src/homebridge-ui/public/js/toast.ts +37 -0
  187. package/src/homebridge-ui/public/js/types.ts +26 -0
  188. package/src/homebridge-ui/server.ts +11 -43
  189. package/src/homebridge-ui/utils/config-parser.ts +108 -0
  190. package/src/homebridge-ui/utils/device-migration.ts +144 -0
  191. package/src/homebridge-ui/utils/logger.ts +17 -0
  192. package/src/index.ts +4 -66
  193. package/src/platform.ts +1539 -0
  194. package/src/settings.ts +12 -277
  195. package/src/switchbotClient.ts +216 -0
  196. package/src/utils.ts +46 -713
  197. package/switchbot-homebridge-switchbot-5.0.0.tgz +0 -0
  198. package/test/accessory-restore.spec.ts +73 -0
  199. package/test/device-mapping.spec.ts +37 -0
  200. package/test/deviceFactory.spec.ts +18 -0
  201. package/test/e2e/run-e2e.spec.ts +50 -0
  202. package/test/fan-swing.spec.ts +29 -0
  203. package/test/helpers/matter-harness.ts +53 -0
  204. package/test/lock-users.spec.ts +44 -0
  205. package/test/matter-childbridge.spec.ts +59 -0
  206. package/test/matter-descriptors.spec.ts +97 -0
  207. package/test/matter-device-state.spec.ts +101 -0
  208. package/test/matter-integration.spec.ts +111 -0
  209. package/test/platform.integration.spec.ts +55 -0
  210. package/test/switchbot-client-debounce.spec.ts +131 -0
  211. package/test/switchbot-client-openapi.spec.ts +56 -0
  212. package/test/switchbotClient.spec.ts +10 -0
  213. package/test/utils.spec.ts +36 -0
  214. package/todo/COMPLETED.md +229 -0
  215. package/todo/README.md +59 -0
  216. package/todo/TODO.md +176 -0
  217. package/todo/mockups/filtering-sorting.svg +112 -0
  218. package/todo/mockups/modal-switchbot-theme.svg +66 -0
  219. package/todo/mockups/signal-strength-visualization.svg +94 -0
  220. package/vitest.config.ts +7 -0
  221. package/coverage/base.css +0 -224
  222. package/coverage/block-navigation.js +0 -87
  223. package/coverage/clover.xml +0 -15847
  224. package/coverage/coverage-final.json +0 -42
  225. package/coverage/docs/assets/dmt/dmt-component-data.js.html +0 -85
  226. package/coverage/docs/assets/dmt/dmt-components.js.html +0 -286
  227. package/coverage/docs/assets/dmt/index.html +0 -131
  228. package/coverage/docs/assets/hierarchy.js.html +0 -85
  229. package/coverage/docs/assets/icons.js.html +0 -136
  230. package/coverage/docs/assets/index.html +0 -146
  231. package/coverage/docs/assets/main.js.html +0 -265
  232. package/coverage/favicon.png +0 -0
  233. package/coverage/index.html +0 -191
  234. package/coverage/prettify.css +0 -1
  235. package/coverage/prettify.js +0 -2
  236. package/coverage/sort-arrow-sprite.png +0 -0
  237. package/coverage/sorter.js +0 -196
  238. package/coverage/src/device/blindtilt.ts.html +0 -3238
  239. package/coverage/src/device/bot.ts.html +0 -2803
  240. package/coverage/src/device/ceilinglight.ts.html +0 -2338
  241. package/coverage/src/device/colorbulb.ts.html +0 -2824
  242. package/coverage/src/device/contact.ts.html +0 -1465
  243. package/coverage/src/device/curtain.ts.html +0 -2869
  244. package/coverage/src/device/device.ts.html +0 -2500
  245. package/coverage/src/device/fan.ts.html +0 -2242
  246. package/coverage/src/device/hub.ts.html +0 -1408
  247. package/coverage/src/device/humidifier.ts.html +0 -2116
  248. package/coverage/src/device/index.html +0 -416
  249. package/coverage/src/device/iosensor.ts.html +0 -1375
  250. package/coverage/src/device/lightstrip.ts.html +0 -2617
  251. package/coverage/src/device/lock.ts.html +0 -1963
  252. package/coverage/src/device/meter.ts.html +0 -1372
  253. package/coverage/src/device/meterplus.ts.html +0 -1384
  254. package/coverage/src/device/meterpro.ts.html +0 -1618
  255. package/coverage/src/device/motion.ts.html +0 -1264
  256. package/coverage/src/device/plug.ts.html +0 -1372
  257. package/coverage/src/device/relayswitch.ts.html +0 -2284
  258. package/coverage/src/device/robotvacuumcleaner.ts.html +0 -1810
  259. package/coverage/src/device/waterdetector.ts.html +0 -1294
  260. package/coverage/src/homebridge-ui/index.html +0 -116
  261. package/coverage/src/homebridge-ui/server.ts.html +0 -229
  262. package/coverage/src/index.html +0 -161
  263. package/coverage/src/index.ts.html +0 -124
  264. package/coverage/src/irdevice/airconditioner.ts.html +0 -1687
  265. package/coverage/src/irdevice/airpurifier.ts.html +0 -844
  266. package/coverage/src/irdevice/camera.ts.html +0 -475
  267. package/coverage/src/irdevice/fan.ts.html +0 -766
  268. package/coverage/src/irdevice/index.html +0 -251
  269. package/coverage/src/irdevice/irdevice.ts.html +0 -1117
  270. package/coverage/src/irdevice/light.ts.html +0 -826
  271. package/coverage/src/irdevice/other.ts.html +0 -2458
  272. package/coverage/src/irdevice/tv.ts.html +0 -1222
  273. package/coverage/src/irdevice/vacuumcleaner.ts.html +0 -466
  274. package/coverage/src/irdevice/waterheater.ts.html +0 -469
  275. package/coverage/src/platform.ts.html +0 -8776
  276. package/coverage/src/settings.ts.html +0 -934
  277. package/coverage/src/utils.ts.html +0 -2092
  278. package/dist/devices-hap/airpurifier.d.ts +0 -54
  279. package/dist/devices-hap/airpurifier.d.ts.map +0 -1
  280. package/dist/devices-hap/airpurifier.js +0 -527
  281. package/dist/devices-hap/airpurifier.js.map +0 -1
  282. package/dist/devices-hap/blindtilt.d.ts +0 -90
  283. package/dist/devices-hap/blindtilt.d.ts.map +0 -1
  284. package/dist/devices-hap/blindtilt.js +0 -974
  285. package/dist/devices-hap/blindtilt.js.map +0 -1
  286. package/dist/devices-hap/bot.d.ts +0 -102
  287. package/dist/devices-hap/bot.d.ts.map +0 -1
  288. package/dist/devices-hap/bot.js +0 -811
  289. package/dist/devices-hap/bot.js.map +0 -1
  290. package/dist/devices-hap/ceilinglight.d.ts +0 -85
  291. package/dist/devices-hap/ceilinglight.d.ts.map +0 -1
  292. package/dist/devices-hap/ceilinglight.js +0 -701
  293. package/dist/devices-hap/ceilinglight.js.map +0 -1
  294. package/dist/devices-hap/colorbulb.d.ts +0 -88
  295. package/dist/devices-hap/colorbulb.d.ts.map +0 -1
  296. package/dist/devices-hap/colorbulb.js +0 -881
  297. package/dist/devices-hap/colorbulb.js.map +0 -1
  298. package/dist/devices-hap/contact.d.ts +0 -44
  299. package/dist/devices-hap/contact.d.ts.map +0 -1
  300. package/dist/devices-hap/contact.js +0 -409
  301. package/dist/devices-hap/contact.js.map +0 -1
  302. package/dist/devices-hap/curtain.d.ts +0 -73
  303. package/dist/devices-hap/curtain.d.ts.map +0 -1
  304. package/dist/devices-hap/curtain.js +0 -869
  305. package/dist/devices-hap/curtain.js.map +0 -1
  306. package/dist/devices-hap/device.d.ts +0 -98
  307. package/dist/devices-hap/device.d.ts.map +0 -1
  308. package/dist/devices-hap/device.js +0 -749
  309. package/dist/devices-hap/device.js.map +0 -1
  310. package/dist/devices-hap/fan.d.ts +0 -69
  311. package/dist/devices-hap/fan.d.ts.map +0 -1
  312. package/dist/devices-hap/fan.js +0 -649
  313. package/dist/devices-hap/fan.js.map +0 -1
  314. package/dist/devices-hap/hub.d.ts +0 -37
  315. package/dist/devices-hap/hub.d.ts.map +0 -1
  316. package/dist/devices-hap/hub.js +0 -392
  317. package/dist/devices-hap/hub.js.map +0 -1
  318. package/dist/devices-hap/humidifier.d.ts +0 -68
  319. package/dist/devices-hap/humidifier.d.ts.map +0 -1
  320. package/dist/devices-hap/humidifier.js +0 -628
  321. package/dist/devices-hap/humidifier.js.map +0 -1
  322. package/dist/devices-hap/iosensor.d.ts +0 -42
  323. package/dist/devices-hap/iosensor.d.ts.map +0 -1
  324. package/dist/devices-hap/iosensor.js +0 -382
  325. package/dist/devices-hap/iosensor.js.map +0 -1
  326. package/dist/devices-hap/lightstrip.d.ts +0 -79
  327. package/dist/devices-hap/lightstrip.d.ts.map +0 -1
  328. package/dist/devices-hap/lightstrip.js +0 -797
  329. package/dist/devices-hap/lightstrip.js.map +0 -1
  330. package/dist/devices-hap/lock.d.ts +0 -53
  331. package/dist/devices-hap/lock.d.ts.map +0 -1
  332. package/dist/devices-hap/lock.js +0 -561
  333. package/dist/devices-hap/lock.js.map +0 -1
  334. package/dist/devices-hap/meter.d.ts +0 -37
  335. package/dist/devices-hap/meter.d.ts.map +0 -1
  336. package/dist/devices-hap/meter.js +0 -379
  337. package/dist/devices-hap/meter.js.map +0 -1
  338. package/dist/devices-hap/meterplus.d.ts +0 -42
  339. package/dist/devices-hap/meterplus.d.ts.map +0 -1
  340. package/dist/devices-hap/meterplus.js +0 -384
  341. package/dist/devices-hap/meterplus.js.map +0 -1
  342. package/dist/devices-hap/meterpro.d.ts +0 -43
  343. package/dist/devices-hap/meterpro.d.ts.map +0 -1
  344. package/dist/devices-hap/meterpro.js +0 -468
  345. package/dist/devices-hap/meterpro.js.map +0 -1
  346. package/dist/devices-hap/motion.d.ts +0 -42
  347. package/dist/devices-hap/motion.d.ts.map +0 -1
  348. package/dist/devices-hap/motion.js +0 -345
  349. package/dist/devices-hap/motion.js.map +0 -1
  350. package/dist/devices-hap/plug.d.ts +0 -49
  351. package/dist/devices-hap/plug.d.ts.map +0 -1
  352. package/dist/devices-hap/plug.js +0 -395
  353. package/dist/devices-hap/plug.js.map +0 -1
  354. package/dist/devices-hap/relayswitch.d.ts +0 -96
  355. package/dist/devices-hap/relayswitch.d.ts.map +0 -1
  356. package/dist/devices-hap/relayswitch.js +0 -642
  357. package/dist/devices-hap/relayswitch.js.map +0 -1
  358. package/dist/devices-hap/robotvacuumcleaner.d.ts +0 -54
  359. package/dist/devices-hap/robotvacuumcleaner.d.ts.map +0 -1
  360. package/dist/devices-hap/robotvacuumcleaner.js +0 -523
  361. package/dist/devices-hap/robotvacuumcleaner.js.map +0 -1
  362. package/dist/devices-hap/waterdetector.d.ts +0 -41
  363. package/dist/devices-hap/waterdetector.d.ts.map +0 -1
  364. package/dist/devices-hap/waterdetector.js +0 -356
  365. package/dist/devices-hap/waterdetector.js.map +0 -1
  366. package/dist/devices-matter/BaseMatterAccessory.d.ts +0 -63
  367. package/dist/devices-matter/BaseMatterAccessory.d.ts.map +0 -1
  368. package/dist/devices-matter/BaseMatterAccessory.js +0 -100
  369. package/dist/devices-matter/BaseMatterAccessory.js.map +0 -1
  370. package/dist/devices-matter/ColorLightAccessory.d.ts +0 -20
  371. package/dist/devices-matter/ColorLightAccessory.d.ts.map +0 -1
  372. package/dist/devices-matter/ColorLightAccessory.js +0 -95
  373. package/dist/devices-matter/ColorLightAccessory.js.map +0 -1
  374. package/dist/devices-matter/ColorTemperatureLightAccessory.d.ts +0 -18
  375. package/dist/devices-matter/ColorTemperatureLightAccessory.d.ts.map +0 -1
  376. package/dist/devices-matter/ColorTemperatureLightAccessory.js +0 -78
  377. package/dist/devices-matter/ColorTemperatureLightAccessory.js.map +0 -1
  378. package/dist/devices-matter/ContactSensorAccessory.d.ts +0 -12
  379. package/dist/devices-matter/ContactSensorAccessory.d.ts.map +0 -1
  380. package/dist/devices-matter/ContactSensorAccessory.js +0 -34
  381. package/dist/devices-matter/ContactSensorAccessory.js.map +0 -1
  382. package/dist/devices-matter/DimmableLightAccessory.d.ts +0 -58
  383. package/dist/devices-matter/DimmableLightAccessory.d.ts.map +0 -1
  384. package/dist/devices-matter/DimmableLightAccessory.js +0 -167
  385. package/dist/devices-matter/DimmableLightAccessory.js.map +0 -1
  386. package/dist/devices-matter/DoorLockAccessory.d.ts +0 -14
  387. package/dist/devices-matter/DoorLockAccessory.d.ts.map +0 -1
  388. package/dist/devices-matter/DoorLockAccessory.js +0 -50
  389. package/dist/devices-matter/DoorLockAccessory.js.map +0 -1
  390. package/dist/devices-matter/ExtendedColorLightAccessory.d.ts +0 -21
  391. package/dist/devices-matter/ExtendedColorLightAccessory.d.ts.map +0 -1
  392. package/dist/devices-matter/ExtendedColorLightAccessory.js +0 -107
  393. package/dist/devices-matter/ExtendedColorLightAccessory.js.map +0 -1
  394. package/dist/devices-matter/FanAccessory.d.ts +0 -16
  395. package/dist/devices-matter/FanAccessory.d.ts.map +0 -1
  396. package/dist/devices-matter/FanAccessory.js +0 -81
  397. package/dist/devices-matter/FanAccessory.js.map +0 -1
  398. package/dist/devices-matter/HumiditySensorAccessory.d.ts +0 -12
  399. package/dist/devices-matter/HumiditySensorAccessory.d.ts.map +0 -1
  400. package/dist/devices-matter/HumiditySensorAccessory.js +0 -34
  401. package/dist/devices-matter/HumiditySensorAccessory.js.map +0 -1
  402. package/dist/devices-matter/LeakSensorAccessory.d.ts +0 -12
  403. package/dist/devices-matter/LeakSensorAccessory.d.ts.map +0 -1
  404. package/dist/devices-matter/LeakSensorAccessory.js +0 -33
  405. package/dist/devices-matter/LeakSensorAccessory.js.map +0 -1
  406. package/dist/devices-matter/LightSensorAccessory.d.ts +0 -12
  407. package/dist/devices-matter/LightSensorAccessory.d.ts.map +0 -1
  408. package/dist/devices-matter/LightSensorAccessory.js +0 -34
  409. package/dist/devices-matter/LightSensorAccessory.js.map +0 -1
  410. package/dist/devices-matter/OccupancySensorAccessory.d.ts +0 -12
  411. package/dist/devices-matter/OccupancySensorAccessory.d.ts.map +0 -1
  412. package/dist/devices-matter/OccupancySensorAccessory.js +0 -39
  413. package/dist/devices-matter/OccupancySensorAccessory.js.map +0 -1
  414. package/dist/devices-matter/OnOffLightAccessory.d.ts +0 -38
  415. package/dist/devices-matter/OnOffLightAccessory.d.ts.map +0 -1
  416. package/dist/devices-matter/OnOffLightAccessory.js +0 -118
  417. package/dist/devices-matter/OnOffLightAccessory.js.map +0 -1
  418. package/dist/devices-matter/OnOffOutletAccessory.d.ts +0 -12
  419. package/dist/devices-matter/OnOffOutletAccessory.d.ts.map +0 -1
  420. package/dist/devices-matter/OnOffOutletAccessory.js +0 -40
  421. package/dist/devices-matter/OnOffOutletAccessory.js.map +0 -1
  422. package/dist/devices-matter/OnOffSwitchAccessory.d.ts +0 -14
  423. package/dist/devices-matter/OnOffSwitchAccessory.d.ts.map +0 -1
  424. package/dist/devices-matter/OnOffSwitchAccessory.js +0 -42
  425. package/dist/devices-matter/OnOffSwitchAccessory.js.map +0 -1
  426. package/dist/devices-matter/RoboticVacuumAccessory.d.ts +0 -68
  427. package/dist/devices-matter/RoboticVacuumAccessory.d.ts.map +0 -1
  428. package/dist/devices-matter/RoboticVacuumAccessory.js +0 -334
  429. package/dist/devices-matter/RoboticVacuumAccessory.js.map +0 -1
  430. package/dist/devices-matter/SmokeCOAlarmAccessory.d.ts +0 -11
  431. package/dist/devices-matter/SmokeCOAlarmAccessory.d.ts.map +0 -1
  432. package/dist/devices-matter/SmokeCOAlarmAccessory.js +0 -49
  433. package/dist/devices-matter/SmokeCOAlarmAccessory.js.map +0 -1
  434. package/dist/devices-matter/TemperatureSensorAccessory.d.ts +0 -12
  435. package/dist/devices-matter/TemperatureSensorAccessory.d.ts.map +0 -1
  436. package/dist/devices-matter/TemperatureSensorAccessory.js +0 -36
  437. package/dist/devices-matter/TemperatureSensorAccessory.js.map +0 -1
  438. package/dist/devices-matter/ThermostatAccessory.d.ts +0 -19
  439. package/dist/devices-matter/ThermostatAccessory.d.ts.map +0 -1
  440. package/dist/devices-matter/ThermostatAccessory.js +0 -95
  441. package/dist/devices-matter/ThermostatAccessory.js.map +0 -1
  442. package/dist/devices-matter/VenetianBlindAccessory.d.ts +0 -19
  443. package/dist/devices-matter/VenetianBlindAccessory.d.ts.map +0 -1
  444. package/dist/devices-matter/VenetianBlindAccessory.js +0 -99
  445. package/dist/devices-matter/VenetianBlindAccessory.js.map +0 -1
  446. package/dist/devices-matter/WindowBlindAccessory.d.ts +0 -17
  447. package/dist/devices-matter/WindowBlindAccessory.d.ts.map +0 -1
  448. package/dist/devices-matter/WindowBlindAccessory.js +0 -80
  449. package/dist/devices-matter/WindowBlindAccessory.js.map +0 -1
  450. package/dist/devices-matter/custom/PowerStripAccessory.d.ts +0 -97
  451. package/dist/devices-matter/custom/PowerStripAccessory.d.ts.map +0 -1
  452. package/dist/devices-matter/custom/PowerStripAccessory.js +0 -265
  453. package/dist/devices-matter/custom/PowerStripAccessory.js.map +0 -1
  454. package/dist/devices-matter/custom/index.d.ts +0 -8
  455. package/dist/devices-matter/custom/index.d.ts.map +0 -1
  456. package/dist/devices-matter/custom/index.js +0 -8
  457. package/dist/devices-matter/custom/index.js.map +0 -1
  458. package/dist/devices-matter/index.d.ts +0 -29
  459. package/dist/devices-matter/index.d.ts.map +0 -1
  460. package/dist/devices-matter/index.js +0 -28
  461. package/dist/devices-matter/index.js.map +0 -1
  462. package/dist/index.test.d.ts +0 -2
  463. package/dist/index.test.d.ts.map +0 -1
  464. package/dist/index.test.js +0 -19
  465. package/dist/index.test.js.map +0 -1
  466. package/dist/irdevice/airconditioner.d.ts +0 -61
  467. package/dist/irdevice/airconditioner.d.ts.map +0 -1
  468. package/dist/irdevice/airconditioner.js +0 -472
  469. package/dist/irdevice/airconditioner.js.map +0 -1
  470. package/dist/irdevice/airpurifier.d.ts +0 -50
  471. package/dist/irdevice/airpurifier.d.ts.map +0 -1
  472. package/dist/irdevice/airpurifier.js +0 -213
  473. package/dist/irdevice/airpurifier.js.map +0 -1
  474. package/dist/irdevice/camera.d.ts +0 -32
  475. package/dist/irdevice/camera.d.ts.map +0 -1
  476. package/dist/irdevice/camera.js +0 -107
  477. package/dist/irdevice/camera.js.map +0 -1
  478. package/dist/irdevice/fan.d.ts +0 -36
  479. package/dist/irdevice/fan.d.ts.map +0 -1
  480. package/dist/irdevice/fan.js +0 -200
  481. package/dist/irdevice/fan.js.map +0 -1
  482. package/dist/irdevice/irdevice.d.ts +0 -68
  483. package/dist/irdevice/irdevice.d.ts.map +0 -1
  484. package/dist/irdevice/irdevice.js +0 -298
  485. package/dist/irdevice/irdevice.js.map +0 -1
  486. package/dist/irdevice/light.d.ts +0 -36
  487. package/dist/irdevice/light.d.ts.map +0 -1
  488. package/dist/irdevice/light.js +0 -206
  489. package/dist/irdevice/light.js.map +0 -1
  490. package/dist/irdevice/other.d.ts +0 -57
  491. package/dist/irdevice/other.d.ts.map +0 -1
  492. package/dist/irdevice/other.js +0 -778
  493. package/dist/irdevice/other.js.map +0 -1
  494. package/dist/irdevice/tv.d.ts +0 -45
  495. package/dist/irdevice/tv.d.ts.map +0 -1
  496. package/dist/irdevice/tv.js +0 -327
  497. package/dist/irdevice/tv.js.map +0 -1
  498. package/dist/irdevice/vacuumcleaner.d.ts +0 -28
  499. package/dist/irdevice/vacuumcleaner.d.ts.map +0 -1
  500. package/dist/irdevice/vacuumcleaner.js +0 -104
  501. package/dist/irdevice/vacuumcleaner.js.map +0 -1
  502. package/dist/irdevice/waterheater.d.ts +0 -30
  503. package/dist/irdevice/waterheater.d.ts.map +0 -1
  504. package/dist/irdevice/waterheater.js +0 -105
  505. package/dist/irdevice/waterheater.js.map +0 -1
  506. package/dist/platform-hap.d.ts +0 -149
  507. package/dist/platform-hap.d.ts.map +0 -1
  508. package/dist/platform-hap.js +0 -2861
  509. package/dist/platform-hap.js.map +0 -1
  510. package/dist/platform-matter.d.ts +0 -120
  511. package/dist/platform-matter.d.ts.map +0 -1
  512. package/dist/platform-matter.js +0 -984
  513. package/dist/platform-matter.js.map +0 -1
  514. package/dist/verifyconfig.test.d.ts +0 -2
  515. package/dist/verifyconfig.test.d.ts.map +0 -1
  516. package/dist/verifyconfig.test.js +0 -167
  517. package/dist/verifyconfig.test.js.map +0 -1
  518. package/src/custom.d.ts +0 -7
  519. package/src/devices-hap/airpurifier.ts +0 -563
  520. package/src/devices-hap/blindtilt.ts +0 -1049
  521. package/src/devices-hap/bot.ts +0 -900
  522. package/src/devices-hap/ceilinglight.ts +0 -742
  523. package/src/devices-hap/colorbulb.ts +0 -904
  524. package/src/devices-hap/contact.ts +0 -457
  525. package/src/devices-hap/curtain.ts +0 -944
  526. package/src/devices-hap/device.ts +0 -811
  527. package/src/devices-hap/fan.ts +0 -711
  528. package/src/devices-hap/hub.ts +0 -439
  529. package/src/devices-hap/humidifier.ts +0 -669
  530. package/src/devices-hap/iosensor.ts +0 -427
  531. package/src/devices-hap/lightstrip.ts +0 -836
  532. package/src/devices-hap/lock.ts +0 -620
  533. package/src/devices-hap/meter.ts +0 -426
  534. package/src/devices-hap/meterplus.ts +0 -430
  535. package/src/devices-hap/meterpro.ts +0 -522
  536. package/src/devices-hap/motion.ts +0 -390
  537. package/src/devices-hap/plug.ts +0 -423
  538. package/src/devices-hap/relayswitch.ts +0 -727
  539. package/src/devices-hap/robotvacuumcleaner.ts +0 -568
  540. package/src/devices-hap/waterdetector.ts +0 -400
  541. package/src/devices-matter/BaseMatterAccessory.ts +0 -131
  542. package/src/devices-matter/ColorLightAccessory.ts +0 -110
  543. package/src/devices-matter/ColorTemperatureLightAccessory.ts +0 -92
  544. package/src/devices-matter/ContactSensorAccessory.ts +0 -41
  545. package/src/devices-matter/DimmableLightAccessory.ts +0 -192
  546. package/src/devices-matter/DoorLockAccessory.ts +0 -60
  547. package/src/devices-matter/ExtendedColorLightAccessory.ts +0 -123
  548. package/src/devices-matter/FanAccessory.ts +0 -95
  549. package/src/devices-matter/HumiditySensorAccessory.ts +0 -41
  550. package/src/devices-matter/LeakSensorAccessory.ts +0 -40
  551. package/src/devices-matter/LightSensorAccessory.ts +0 -41
  552. package/src/devices-matter/OccupancySensorAccessory.ts +0 -48
  553. package/src/devices-matter/OnOffLightAccessory.ts +0 -133
  554. package/src/devices-matter/OnOffOutletAccessory.ts +0 -46
  555. package/src/devices-matter/OnOffSwitchAccessory.ts +0 -51
  556. package/src/devices-matter/RoboticVacuumAccessory.ts +0 -407
  557. package/src/devices-matter/SmokeCOAlarmAccessory.ts +0 -59
  558. package/src/devices-matter/TemperatureSensorAccessory.ts +0 -43
  559. package/src/devices-matter/ThermostatAccessory.ts +0 -110
  560. package/src/devices-matter/VenetianBlindAccessory.ts +0 -115
  561. package/src/devices-matter/WindowBlindAccessory.ts +0 -92
  562. package/src/devices-matter/custom/PowerStripAccessory.ts +0 -309
  563. package/src/devices-matter/custom/index.ts +0 -8
  564. package/src/devices-matter/index.ts +0 -29
  565. package/src/index.test.ts +0 -24
  566. package/src/irdevice/airconditioner.ts +0 -533
  567. package/src/irdevice/airpurifier.ts +0 -252
  568. package/src/irdevice/camera.ts +0 -129
  569. package/src/irdevice/fan.ts +0 -226
  570. package/src/irdevice/irdevice.ts +0 -344
  571. package/src/irdevice/light.ts +0 -246
  572. package/src/irdevice/other.ts +0 -790
  573. package/src/irdevice/tv.ts +0 -378
  574. package/src/irdevice/vacuumcleaner.ts +0 -126
  575. package/src/irdevice/waterheater.ts +0 -127
  576. package/src/platform-hap.ts +0 -2997
  577. package/src/platform-matter.ts +0 -1110
  578. package/src/verifyconfig.test.ts +0 -197
package/src/utils.ts CHANGED
@@ -1,718 +1,51 @@
1
- /* Copyright(C) 2017-2024, donavanbecker (https://github.com/donavanbecker). All rights reserved.
2
- *
3
- * util.ts: @switchbot/homebridge-switchbot platform class.
4
- */
5
- import type { blindTilt, curtain, curtain3, device } from 'node-switchbot'
6
-
7
- import type { devicesConfig } from './settings.js'
8
-
9
- export enum BlindTiltMappingMode {
10
- OnlyUp = 'only_up',
11
- OnlyDown = 'only_down',
12
- DownAndUp = 'down_and_up',
13
- UpAndDown = 'up_and_down',
14
- UseTiltForDirection = 'use_tilt_for_direction',
15
- }
16
-
17
- export function isCurtainDevice(device: device & devicesConfig): device is (curtain | curtain3) & devicesConfig {
18
- return device.deviceType === 'Curtain' || device.deviceType === 'Curtain3'
19
- }
20
-
21
- export function isBlindTiltDevice(device: device & devicesConfig): device is blindTilt & devicesConfig {
22
- return device.deviceType === 'Blind Tilt'
23
- }
24
-
25
- export function sleep(ms: number): Promise<void> {
26
- return new Promise(resolve => setTimeout(resolve, ms))
27
- }
28
- /**
29
- * Check if the humidity is within the min and max range
30
- * @param humidity - The humidity value
31
- * @param min - The minimum humidity value
32
- * @param max - The maximum humidity value
33
- * @returns The humidity value
34
- */
35
- export function validHumidity(humidity: number, min?: number, max?: number): number {
36
- if (humidity < (min || 0)) {
37
- return min ?? 0
38
- } else if (humidity > (max || 100)) {
39
- return max ?? 100
40
- }
41
- return humidity
42
- }
43
-
44
- /**
45
- * Converts the value to celsius if the temperature units are in Fahrenheit
46
- */
47
- export function convertUnits(value: number, unit: string, convert?: string): number {
48
- if (unit === 'CELSIUS' && convert === 'CELSIUS') {
49
- return Math.round((value * 9) / 5 + 32)
50
- } else if (unit === 'FAHRENHEIT' && convert === 'FAHRENHEIT') {
51
- // celsius should be to the nearest 0.5 degree
52
- return Math.round((5 / 9) * (value - 32) * 2) / 2
53
- }
54
- return value
55
- }
56
-
57
- /**
58
- * Safely serializes an object to a JSON string, handling circular references.
59
- *
60
- * @param obj - The object to be serialized.
61
- * @returns The JSON string representation of the object.
62
- */
63
- export function safeStringify(obj: any) {
64
- const seen = new WeakSet()
65
- return JSON.stringify(obj, (_key, value) => {
66
- if (typeof value === 'object' && value !== null) {
67
- if (seen.has(value)) {
68
- return
69
- }
70
- seen.add(value)
71
- }
72
- return value
73
- }, ' ')
74
- }
75
-
76
- /**
77
- * Formats a device ID as a MAC address.
78
- * Ensures the device ID does not already contain colons.
79
- *
80
- * @param deviceId - The device ID to format.
81
- * @param cassSensative - If the MAC address should be case sensitive. Default is false, which will return the MAC address in lowercase.
82
- * @returns The formatted MAC address.
83
- * @throws Will throw an error if the device ID is not a valid MAC address or a 12-character hexadecimal string.
84
- */
85
- export function formatDeviceIdAsMac(deviceId: string, cassSensative?: boolean): string {
86
- if (typeof deviceId !== 'string') {
87
- throw new TypeError('Invalid device ID format. Device ID must be a string.')
88
- }
89
-
90
- deviceId = deviceId.trim()
91
-
92
- const macAddressRegex = /^(?:[0-9a-f]{2}:){5}[0-9a-f]{2}$/i
93
- const hexRegex = /^[0-9a-f]{12}$/i
94
- const vacuumFormatRegex = /^[a-z0-9]{12,18}$/i
95
-
96
- // Check if the deviceId is already in a valid MAC address format
97
- if (macAddressRegex.test(deviceId)) {
98
- return cassSensative ? deviceId : deviceId.toLowerCase()
99
- }
100
-
101
- // Check if the deviceId is a valid 12-character hexadecimal string
102
- if (hexRegex.test(deviceId)) {
103
- const formattedDeviceId = deviceId.match(/.{1,2}/g)!.join(':')
104
- return cassSensative ? formattedDeviceId : formattedDeviceId.toLowerCase()
105
- }
106
-
107
- // Check if the deviceId matches the custom format
108
- if (vacuumFormatRegex.test(deviceId)) {
109
- const formattedDeviceId = deviceId.slice(-12).match(/.{1,2}/g)!.join(':')
110
- return cassSensative ? formattedDeviceId : formattedDeviceId.toLowerCase()
111
- }
112
-
113
- throw new Error(`Invalid device ID format. Must be a valid MAC address, a 12-character hexadecimal string, or a 12 to 18-character alphanumeric string. Device ID: ${deviceId}`)
114
- }
115
-
116
- export function rgb2hs(r: any, g: any, b: any) {
117
- /**
118
- * Credit:
119
- * https://github.com/WickyNilliams/pure-color
120
- */
121
- r = Number.parseInt(r)
122
- g = Number.parseInt(g)
123
- b = Number.parseInt(b)
124
- const min = Math.min(r, g, b)
125
- const max = Math.max(r, g, b)
126
- const delta = max - min
127
- let h
128
- let s
129
- if (max === 0) {
130
- s = 0
131
- } else {
132
- s = (delta / max) * 100
133
- }
134
- if (max === min) {
135
- h = 0
136
- } else if (r === max) {
137
- h = (g - b) / delta
138
- } else if (g === max) {
139
- h = 2 + (b - r) / delta
140
- } else if (b === max) {
141
- h = 4 + (r - g) / delta
142
- }
143
- h = Math.min(h * 60, 360)
144
-
145
- if (h < 0) {
146
- h += 360
147
- }
148
- return [Math.round(h), Math.round(s)]
149
- }
150
-
151
- export function hs2rgb(h: any, s: any) {
152
- /*
153
- Credit:
154
- https://github.com/WickyNilliams/pure-color
155
- */
156
- h = Number.parseInt(h) / 60
157
- s = Number.parseInt(s) / 100
158
- const f = h - Math.floor(h)
159
- const p = 255 * (1 - s)
160
- const q = 255 * (1 - s * f)
161
- const t = 255 * (1 - s * (1 - f))
162
- let rgb
163
- switch (Math.floor(h) % 6) {
164
- case 0:
165
- rgb = [255, t, p]
166
- break
167
- case 1:
168
- rgb = [q, 255, p]
169
- break
170
- case 2:
171
- rgb = [p, 255, t]
172
- break
173
- case 3:
174
- rgb = [p, q, 255]
175
- break
176
- case 4:
177
- rgb = [t, p, 255]
178
- break
179
- case 5:
180
- rgb = [255, p, q]
181
- break
182
- }
183
- if (rgb[0] === 255) {
184
- rgb[1] *= 0.8
185
- rgb[2] *= 0.8
186
- if (rgb[1] <= 25 && rgb[2] <= 25) {
187
- rgb[1] = 0
188
- rgb[2] = 0
189
- }
190
- }
191
- return [Math.round(rgb[0]), Math.round(rgb[1]), Math.round(rgb[2])]
192
- }
193
-
194
- export function k2rgb(k: number) {
195
- // Set kelvin to nearest 100, between 2000 and 7100
196
- k = Math.round(k / 100) * 100
197
- k = Math.max(Math.min(k, 7100), 2000)
198
-
199
- // k should now appear in our table of kelvin to rgb
200
- const values = {
201
- 2000: [255, 141, 11],
202
- 2100: [255, 146, 29],
203
- 2200: [255, 147, 44],
204
- 2300: [255, 152, 54],
205
- 2400: [255, 157, 63],
206
- 2500: [255, 166, 69],
207
- 2600: [255, 170, 77],
208
- 2700: [255, 174, 84],
209
- 2800: [255, 173, 94],
210
- 2900: [255, 177, 101],
211
- 3000: [255, 180, 107],
212
- 3100: [255, 189, 111],
213
- 3200: [255, 187, 120],
214
- 3300: [255, 195, 124],
215
- 3400: [255, 198, 130],
216
- 3500: [255, 201, 135],
217
- 3600: [255, 203, 141],
218
- 3700: [255, 206, 146],
219
- 3800: [255, 204, 153],
220
- 3900: [255, 206, 159],
221
- 4000: [255, 213, 161],
222
- 4100: [255, 215, 166],
223
- 4200: [255, 217, 171],
224
- 4300: [255, 219, 175],
225
- 4400: [255, 221, 180],
226
- 4500: [255, 223, 184],
227
- 4600: [255, 225, 188],
228
- 4700: [255, 226, 192],
229
- 4800: [255, 228, 196],
230
- 4900: [255, 229, 200],
231
- 5000: [255, 231, 204],
232
- 5100: [255, 230, 210],
233
- 5200: [255, 234, 211],
234
- 5300: [255, 235, 215],
235
- 5400: [255, 237, 218],
236
- 5500: [255, 236, 224],
237
- 5700: [255, 240, 228],
238
- 5800: [255, 241, 231],
239
- 5900: [255, 243, 234],
240
- 6000: [255, 244, 237],
241
- 6100: [255, 245, 240],
242
- 6200: [255, 246, 243],
243
- 6300: [255, 247, 247],
244
- 6400: [255, 248, 251],
245
- 6500: [255, 249, 253],
246
- 6600: [254, 249, 255],
247
- 6700: [252, 247, 255],
248
- 6800: [249, 246, 255],
249
- 6900: [247, 245, 255],
250
- 7000: [245, 243, 255],
251
- 7100: [243, 242, 255],
252
- }
253
-
254
- // Return the value
255
- return values[k]
256
- }
257
-
258
- export function m2hs(m) {
259
- /*
260
- Credit:
261
- https://github.com/homebridge/HAP-NodeJS
262
- */
263
- const table = {
264
- 100: [19, 222.1],
265
- 101: [18.7, 222.2],
266
- 102: [18.4, 222.3],
267
- 103: [18.2, 222.3],
268
- 104: [17.9, 222.4],
269
- 105: [17.6, 222.5],
270
- 106: [17.3, 222.7],
271
- 107: [17, 222.8],
272
- 108: [16.7, 222.9],
273
- 109: [16.4, 223],
274
- 110: [16.1, 223.2],
275
- 111: [15.8, 223.3],
276
- 112: [15.4, 223.4],
277
- 113: [15.2, 223.6],
278
- 114: [14.9, 223.8],
279
- 115: [14.7, 223.9],
280
- 116: [14.3, 224.1],
281
- 117: [14.1, 224.2],
282
- 118: [13.8, 224.4],
283
- 119: [13.5, 224.6],
284
- 120: [13.2, 224.8],
285
- 121: [12.9, 225],
286
- 122: [12.5, 225.3],
287
- 123: [12.2, 225.6],
288
- 124: [11.8, 225.9],
289
- 125: [11.4, 226.3],
290
- 126: [11.1, 226.7],
291
- 127: [10.7, 227.1],
292
- 128: [10.3, 227.6],
293
- 129: [9.9, 228],
294
- 130: [9.6, 228.5],
295
- 131: [9.3, 229.1],
296
- 132: [8.9, 229.6],
297
- 133: [8.5, 230.2],
298
- 134: [8.2, 230.9],
299
- 135: [7.8, 231.6],
300
- 136: [7.5, 232.5],
301
- 137: [7.1, 233.5],
302
- 138: [6.7, 234.6],
303
- 139: [6.3, 235.8],
304
- 140: [6, 237.1],
305
- 141: [5.6, 238.9],
306
- 142: [5.2, 240.9],
307
- 143: [5, 242.9],
308
- 144: [4.8, 244.9],
309
- 145: [4.6, 246.9],
310
- 146: [4.4, 249.3],
311
- 147: [4.3, 251.9],
312
- 148: [4.1, 254.9],
313
- 149: [3.9, 258],
314
- 150: [3.7, 261.8],
315
- 151: [3.4, 265.9],
316
- 152: [3.2, 271],
317
- 153: [3, 276.4],
318
- 154: [2.8, 283.6],
319
- 155: [2.6, 290.4],
320
- 156: [2.3, 295.3],
321
- 157: [2.1, 300],
322
- 158: [1.9, 300],
323
- 159: [1.6, 300],
324
- 160: [1.4, 195.8],
325
- 161: [1.2, 84.3],
326
- 162: [1.3, 58.2],
327
- 163: [1.5, 55.9],
328
- 164: [1.7, 53.2],
329
- 165: [1.9, 50.2],
330
- 166: [2.1, 47.1],
331
- 167: [2.4, 44.5],
332
- 168: [2.6, 42.6],
333
- 169: [2.9, 40.9],
334
- 170: [3.1, 39.5],
335
- 171: [3.4, 38.3],
336
- 172: [3.7, 37.3],
337
- 173: [3.9, 36.5],
338
- 174: [4.2, 35.7],
339
- 175: [4.4, 35.1],
340
- 176: [4.6, 34.5],
341
- 177: [4.9, 34],
342
- 178: [5.1, 33.5],
343
- 179: [5.3, 33],
344
- 180: [5.6, 32.7],
345
- 181: [5.8, 32.3],
346
- 182: [6, 32],
347
- 183: [6.3, 31.7],
348
- 184: [6.5, 31.4],
349
- 185: [6.7, 31.2],
350
- 186: [7, 30.9],
351
- 187: [7.2, 30.7],
352
- 188: [7.4, 30.5],
353
- 189: [7.6, 30.3],
354
- 190: [7.9, 30.1],
355
- 191: [8.1, 29.9],
356
- 192: [8.4, 29.7],
357
- 193: [8.6, 29.6],
358
- 194: [8.9, 29.5],
359
- 195: [9.1, 29.3],
360
- 196: [9.4, 29.2],
361
- 197: [9.6, 29.1],
362
- 198: [9.8, 29],
363
- 199: [10, 28.9],
364
- 200: [10.2, 28.7],
365
- 201: [10.5, 28.7],
366
- 202: [10.7, 28.6],
367
- 203: [11, 28.5],
368
- 204: [11.2, 28.4],
369
- 205: [11.4, 28.3],
370
- 206: [11.6, 28.3],
371
- 207: [11.8, 28.2],
372
- 208: [12.1, 28.1],
373
- 209: [12.3, 28.1],
374
- 210: [12.5, 28],
375
- 211: [12.7, 28],
376
- 212: [12.9, 27.9],
377
- 213: [13.2, 27.8],
378
- 214: [13.4, 27.8],
379
- 215: [13.6, 27.7],
380
- 216: [13.8, 27.7],
381
- 217: [14, 27.7],
382
- 218: [14.3, 27.6],
383
- 219: [14.5, 27.6],
384
- 220: [14.7, 27.5],
385
- 221: [14.9, 27.5],
386
- 222: [15.1, 27.5],
387
- 223: [15.3, 27.4],
388
- 224: [15.5, 27.4],
389
- 225: [15.8, 27.4],
390
- 226: [16, 27.3],
391
- 227: [16.2, 27.3],
392
- 228: [16.4, 27.3],
393
- 229: [16.6, 27.3],
394
- 230: [16.8, 27.2],
395
- 231: [17, 27.2],
396
- 232: [17.2, 27.2],
397
- 233: [17.4, 27.2],
398
- 234: [17.6, 27.2],
399
- 235: [17.8, 27.1],
400
- 236: [18, 27.1],
401
- 237: [18.2, 27.1],
402
- 238: [18.4, 27.1],
403
- 239: [18.7, 27.1],
404
- 240: [18.8, 27],
405
- 241: [19, 27],
406
- 242: [19.2, 27],
407
- 243: [19.4, 27],
408
- 244: [19.6, 27],
409
- 245: [19.8, 27],
410
- 246: [20, 27],
411
- 247: [20.3, 26.9],
412
- 248: [20.5, 26.9],
413
- 249: [20.6, 26.9],
414
- 250: [20.8, 26.9],
415
- 251: [21, 26.9],
416
- 252: [21.3, 26.9],
417
- 253: [21.5, 26.9],
418
- 254: [21.6, 26.9],
419
- 255: [21.8, 26.8],
420
- 256: [22, 26.8],
421
- 257: [22.2, 26.8],
422
- 258: [22.4, 26.8],
423
- 259: [22.6, 26.8],
424
- 260: [22.8, 26.8],
425
- 261: [23, 26.8],
426
- 262: [23.2, 26.8],
427
- 263: [23.4, 26.8],
428
- 264: [23.6, 26.8],
429
- 265: [23.8, 26.8],
430
- 266: [24, 26.8],
431
- 267: [24.1, 26.8],
432
- 268: [24.3, 26.8],
433
- 269: [24.5, 26.8],
434
- 270: [24.7, 26.8],
435
- 271: [24.8, 26.8],
436
- 272: [25.1, 26.7],
437
- 273: [25.3, 26.7],
438
- 274: [25.4, 26.7],
439
- 275: [25.6, 26.7],
440
- 276: [25.8, 26.7],
441
- 277: [26, 26.7],
442
- 278: [26.1, 26.7],
443
- 279: [26.3, 26.7],
444
- 280: [26.5, 26.7],
445
- 281: [26.7, 26.7],
446
- 282: [26.9, 26.7],
447
- 283: [27.1, 26.7],
448
- 284: [27.3, 26.7],
449
- 285: [27.5, 26.7],
450
- 286: [27.7, 26.7],
451
- 287: [27.8, 26.7],
452
- 288: [28, 26.7],
453
- 289: [28.2, 26.7],
454
- 290: [28.4, 26.7],
455
- 291: [28.6, 26.7],
456
- 292: [28.8, 26.7],
457
- 293: [28.9, 26.7],
458
- 294: [29.1, 26.7],
459
- 295: [29.3, 26.7],
460
- 296: [29.5, 26.7],
461
- 297: [29.6, 26.7],
462
- 298: [29.8, 26.7],
463
- 299: [30, 26.7],
464
- 300: [30.2, 26.7],
465
- 301: [30.4, 26.7],
466
- 302: [30.5, 26.7],
467
- 303: [30.7, 26.7],
468
- 304: [30.9, 26.7],
469
- 305: [31.1, 26.7],
470
- 306: [31.2, 26.7],
471
- 307: [31.4, 26.7],
472
- 308: [31.6, 26.7],
473
- 309: [31.8, 26.8],
474
- 310: [31.9, 26.8],
475
- 311: [32.1, 26.8],
476
- 312: [32.3, 26.8],
477
- 313: [32.5, 26.8],
478
- 314: [32.6, 26.8],
479
- 315: [32.8, 26.8],
480
- 316: [33, 26.8],
481
- 317: [33.2, 26.8],
482
- 318: [33.3, 26.8],
483
- 319: [33.5, 26.8],
484
- 320: [33.7, 26.8],
485
- 321: [33.8, 26.8],
486
- 322: [34, 26.8],
487
- 323: [34.2, 26.8],
488
- 324: [34.4, 26.8],
489
- 325: [34.5, 26.8],
490
- 326: [34.7, 26.8],
491
- 327: [34.9, 26.8],
492
- 328: [35.1, 26.8],
493
- 329: [35.2, 26.8],
494
- 330: [35.4, 26.8],
495
- 331: [35.5, 26.8],
496
- 332: [35.7, 26.8],
497
- 333: [35.9, 26.8],
498
- 334: [36.1, 26.8],
499
- 335: [36.3, 26.9],
500
- 336: [36.5, 26.9],
501
- 337: [36.7, 26.9],
502
- 338: [36.9, 26.9],
503
- 339: [37.1, 26.9],
504
- 340: [37.2, 26.9],
505
- 341: [37.4, 26.9],
506
- 342: [37.5, 26.9],
507
- 343: [37.7, 26.9],
508
- 344: [37.9, 26.9],
509
- 345: [38.1, 26.9],
510
- 346: [38.3, 26.9],
511
- 347: [38.5, 26.9],
512
- 348: [38.7, 26.9],
513
- 349: [38.9, 26.9],
514
- 350: [39, 26.9],
515
- 351: [39.2, 26.9],
516
- 352: [39.3, 27],
517
- 353: [39.5, 27],
518
- 354: [39.7, 27],
519
- 355: [39.9, 27],
520
- 356: [40.1, 27],
521
- 357: [40.2, 27],
522
- 358: [40.4, 27],
523
- 359: [40.6, 27],
524
- 360: [40.8, 27],
525
- 361: [40.9, 27],
526
- 362: [41.1, 27],
527
- 363: [41.2, 27],
528
- 364: [41.4, 27],
529
- 365: [41.6, 27],
530
- 366: [41.8, 27],
531
- 367: [42, 27],
532
- 368: [42.1, 27.1],
533
- 369: [42.3, 27.1],
534
- 370: [42.4, 27.1],
535
- 371: [42.6, 27.1],
536
- 372: [42.8, 27.1],
537
- 373: [43, 27.1],
538
- 374: [43.1, 27.1],
539
- 375: [43.2, 27.1],
540
- 376: [43.4, 27.1],
541
- 377: [43.6, 27.1],
542
- 378: [43.8, 27.1],
543
- 379: [43.9, 27.1],
544
- 380: [44.1, 27.1],
545
- 381: [44.3, 27.2],
546
- 382: [44.4, 27.2],
547
- 383: [44.6, 27.2],
548
- 384: [44.7, 27.2],
549
- 385: [44.9, 27.2],
550
- 386: [45.1, 27.2],
551
- 387: [45.3, 27.2],
552
- 388: [45.5, 27.2],
553
- 389: [45.6, 27.2],
554
- 390: [45.8, 27.2],
555
- 391: [46, 27.2],
556
- 392: [46.2, 27.3],
557
- 393: [46.4, 27.3],
558
- 394: [46.5, 27.3],
559
- 395: [46.7, 27.3],
560
- 396: [46.9, 27.3],
561
- 397: [47.1, 27.3],
562
- 398: [47.2, 27.3],
563
- 399: [47.4, 27.3],
564
- 400: [47.6, 27.3],
565
- 401: [47.7, 27.3],
566
- 402: [47.9, 27.3],
567
- 403: [48.1, 27.3],
568
- 404: [48.3, 27.3],
569
- 405: [48.5, 27.4],
570
- 406: [48.7, 27.4],
571
- 407: [48.8, 27.4],
572
- 408: [49, 27.4],
573
- 409: [49.2, 27.4],
574
- 410: [49.4, 27.4],
575
- 411: [49.6, 27.4],
576
- 412: [49.7, 27.4],
577
- 413: [49.9, 27.4],
578
- 414: [50.1, 27.4],
579
- 415: [50.2, 27.4],
580
- 416: [50.4, 27.4],
581
- 417: [50.6, 27.5],
582
- 418: [50.7, 27.5],
583
- 419: [50.9, 27.5],
584
- 420: [51.1, 27.5],
585
- 421: [51.2, 27.5],
586
- 422: [51.4, 27.5],
587
- 423: [51.6, 27.5],
588
- 424: [51.7, 27.5],
589
- 425: [51.9, 27.5],
590
- 426: [52.1, 27.5],
591
- 427: [51.2, 27.6],
592
- 428: [52.4, 27.6],
593
- 429: [52.5, 27.6],
594
- 430: [52.7, 27.6],
595
- 431: [52.9, 27.6],
596
- 432: [53.1, 27.6],
597
- 433: [53.2, 27.6],
598
- 434: [53.4, 27.6],
599
- 435: [53.6, 27.6],
600
- 436: [53.7, 27.6],
601
- 437: [53.9, 27.6],
602
- 438: [54.1, 27.7],
603
- 439: [54.2, 27.7],
604
- 440: [54.3, 27.7],
605
- 441: [54.5, 27.7],
606
- 442: [54.7, 27.7],
607
- 443: [54.8, 27.7],
608
- 444: [55, 27.7],
609
- 445: [55.2, 27.7],
610
- 446: [55.3, 27.7],
611
- 447: [55.5, 27.7],
612
- 448: [55.7, 27.7],
613
- 449: [55.8, 27.8],
614
- 450: [56, 27.8],
615
- 451: [56.2, 27.8],
616
- 452: [56.3, 27.8],
617
- 453: [56.5, 27.8],
618
- 454: [56.7, 27.8],
619
- 455: [56.8, 27.8],
620
- 456: [57, 27.8],
621
- 457: [57.2, 27.8],
622
- 458: [57.3, 27.9],
623
- 459: [57.4, 27.9],
624
- 460: [57.6, 27.9],
625
- 461: [57.8, 27.9],
626
- 462: [57.9, 27.9],
627
- 463: [58.1, 27.9],
628
- 464: [58.3, 27.9],
629
- 465: [58.4, 27.9],
630
- 466: [58.6, 27.9],
631
- 467: [58.8, 27.9],
632
- 468: [59, 28],
633
- 469: [59.1, 28],
634
- 470: [59.2, 28],
635
- 471: [59.4, 28],
636
- 472: [59.6, 28],
637
- 473: [59.7, 28],
638
- 474: [60, 28],
639
- 475: [60.1, 28],
640
- 476: [60.2, 28],
641
- 477: [60.4, 28],
642
- 478: [60.6, 28.1],
643
- 479: [60.7, 28.1],
644
- 480: [60.9, 28.1],
645
- 481: [60.1, 28.1],
646
- 482: [60.3, 28.1],
647
- 483: [61.4, 28.1],
648
- 484: [61.5, 28.1],
649
- 485: [61.7, 28.1],
650
- 486: [61.9, 28.1],
651
- 487: [62, 28.2],
652
- 488: [62.2, 28.2],
653
- 489: [62.3, 28.2],
654
- 490: [62.5, 28.2],
655
- 491: [62.7, 28.2],
656
- 492: [62.8, 28.2],
657
- 493: [63, 28.2],
658
- 494: [63.2, 28.2],
659
- 495: [63.3, 28.2],
660
- 496: [63.4, 28.2],
661
- 497: [63.6, 28.2],
662
- 498: [63.8, 28.3],
663
- 499: [63.9, 28.3],
664
- 500: [64.1, 28.3],
665
- }
666
- const input = Math.min(Math.max(Math.round(m), 140), 500)
667
- const toReturn = table[input]
668
- return [Math.round(toReturn[1]), Math.round(toReturn[0])]
669
- }
670
-
671
- /**
672
- * Remove deviceConfig entries that contain only default/empty values.
673
- * Returns undefined if nothing meaningful remains.
674
- */
675
- export function cleanDeviceConfig(deviceConfig?: Record<string, Record<string, any>>): Record<string, Record<string, any>> | undefined {
676
- if (!deviceConfig || typeof deviceConfig !== 'object') {
677
- return undefined
678
- }
679
-
680
- const cleaned: Record<string, Record<string, any>> = {}
681
-
682
- for (const [deviceName, cfg] of Object.entries(deviceConfig)) {
683
- if (!cfg || typeof cfg !== 'object') {
684
- continue
685
- }
686
-
687
- const hasMeaningful = Object.values(cfg).some((v) => {
688
- if (v === null || v === undefined) {
689
- return false
1
+ import type { PlatformConfig } from 'homebridge'
2
+ import type { SwitchBotPluginConfig } from './settings.js'
3
+
4
+ // Canonical Matter cluster ID mapping (from matter.js clusters)
5
+ export const MATTER_CLUSTER_IDS = {
6
+ OnOff: 0x0006,
7
+ LevelControl: 0x0008,
8
+ ColorControl: 0x0300,
9
+ WindowCovering: 0x0102,
10
+ DoorLock: 0x0101,
11
+ FanControl: 0x0202,
12
+ RelativeHumidityMeasurement: 0x0405,
13
+ } as const
14
+
15
+ // Common Matter attribute IDs grouped by cluster
16
+ export const MATTER_ATTRIBUTE_IDS = {
17
+ OnOff: { OnOff: 0x0000 },
18
+ LevelControl: { CurrentLevel: 0x0000 },
19
+ ColorControl: { CurrentHue: 0x0000, CurrentSaturation: 0x0001, ColorTemperatureMireds: 0x0002 },
20
+ WindowCovering: { CurrentPosition: 0x0000, TargetPosition: 0x0001 },
21
+ FanControl: { SpeedCurrent: 0x0000 },
22
+ DoorLock: { LockState: 0x0000 },
23
+ RelativeHumidityMeasurement: { MeasuredValue: 0x0000 },
24
+ } as const
25
+
26
+ export function normalizeConfig(raw?: PlatformConfig): SwitchBotPluginConfig {
27
+ if (!raw) return {}
28
+ return { ...(raw as any) } as SwitchBotPluginConfig
29
+ }
30
+
31
+ // Create a Proxy constructor that instantiates the right platform implementation at runtime.
32
+ export function createPlatformProxy(HAPPlatform: any, MatterPlatform: any): any {
33
+ return class SwitchBotPlatformProxy {
34
+ private impl: any
35
+ constructor(log: any, config: PlatformConfig, api: any) {
36
+ const cfg = normalizeConfig(config)
37
+ const preferMatter = cfg.preferMatter ?? true
38
+ const enableMatter = cfg.enableMatter ?? true
39
+ const matterAvailable = !!(api?.isMatterAvailable?.() && api?.isMatterEnabled?.())
40
+
41
+ if (enableMatter && preferMatter && MatterPlatform && matterAvailable) {
42
+ this.impl = new MatterPlatform(log, cfg, api)
43
+ return this.impl
690
44
  }
691
- if (typeof v === 'boolean') {
692
- return v === true
693
- }
694
- if (typeof v === 'string') {
695
- return v.trim().length > 0
696
- }
697
- if (typeof v === 'number') {
698
- return Number.isFinite(v)
699
- }
700
- if (Array.isArray(v)) {
701
- return v.length > 0
702
- }
703
- if (typeof v === 'object') {
704
- return Object.keys(v).length > 0
705
- }
706
- return true
707
- })
708
45
 
709
- if (hasMeaningful) {
710
- cleaned[deviceName] = cfg
46
+ // Fallback to HAP
47
+ this.impl = new HAPPlatform(log, cfg, api)
48
+ return this.impl
711
49
  }
712
50
  }
713
-
714
- if (Object.keys(cleaned).length > 0) {
715
- return cleaned
716
- }
717
- return undefined
718
51
  }