@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
@@ -0,0 +1,1067 @@
1
+ import { MATTER_ATTRIBUTE_IDS, MATTER_CLUSTER_IDS } from '../utils.js';
2
+ import { DeviceBase } from './deviceBase.js';
3
+ // Module-scope regex pattern to avoid recompilation
4
+ const HEX_COLOR_REGEX = /^#?[0-9A-F]{6}$/i;
5
+ export class GenericDevice extends DeviceBase {
6
+ constructor(opts, cfg) {
7
+ super(opts, cfg);
8
+ }
9
+ async getState() {
10
+ // Default: return minimal info; implementations should override
11
+ if (this.client && typeof this.client.getDevice === 'function') {
12
+ try {
13
+ const raw = await this.client.getDevice(this.opts.id);
14
+ // Normalize common response shapes
15
+ try {
16
+ const device = raw?.body ?? raw;
17
+ return device;
18
+ }
19
+ catch (e) {
20
+ return raw;
21
+ }
22
+ }
23
+ catch (e) {
24
+ // ignore and fallback
25
+ }
26
+ }
27
+ return { id: this.opts.id, type: this.opts.type };
28
+ }
29
+ async setState(change) {
30
+ // Apply change via SwitchBot API in real implementation
31
+ // Translate common high-level changes into SwitchBot OpenAPI commands
32
+ if (!this.client) {
33
+ return { success: false, reason: 'no client', change };
34
+ }
35
+ const cmdBody = {};
36
+ if (typeof change.on === 'boolean') {
37
+ cmdBody.command = change.on ? 'turnOn' : 'turnOff';
38
+ cmdBody.parameter = 'default';
39
+ cmdBody.commandType = 'command';
40
+ }
41
+ else if (typeof change.brightness === 'number') {
42
+ const v = Math.max(0, Math.min(100, Number(change.brightness)));
43
+ cmdBody.command = 'setBrightness';
44
+ cmdBody.parameter = String(v);
45
+ cmdBody.commandType = 'command';
46
+ }
47
+ else if (typeof change.speed === 'number') {
48
+ const v = Math.max(0, Math.min(100, Number(change.speed)));
49
+ cmdBody.command = 'setFanSpeed';
50
+ cmdBody.parameter = String(v);
51
+ cmdBody.commandType = 'command';
52
+ }
53
+ else if (typeof change.position === 'number') {
54
+ const v = Math.max(0, Math.min(100, Number(change.position)));
55
+ cmdBody.command = 'setPosition';
56
+ cmdBody.parameter = String(v);
57
+ cmdBody.commandType = 'command';
58
+ }
59
+ else if (typeof change.locked === 'boolean') {
60
+ cmdBody.command = change.locked ? 'lock' : 'unlock';
61
+ cmdBody.parameter = 'default';
62
+ cmdBody.commandType = 'command';
63
+ }
64
+ else if (typeof change.start === 'boolean') {
65
+ cmdBody.command = change.start ? 'start' : 'stop';
66
+ cmdBody.parameter = 'default';
67
+ cmdBody.commandType = 'command';
68
+ }
69
+ else {
70
+ // If caller supplied an explicit command body, pass through
71
+ if (change && typeof change.command === 'string') {
72
+ Object.assign(cmdBody, change);
73
+ }
74
+ else {
75
+ // Fallback: send raw change to client setDeviceState
76
+ try {
77
+ if (typeof this.client.setDeviceState === 'function') {
78
+ return await this.client.setDeviceState(this.opts.id, change);
79
+ }
80
+ if (typeof this.client.sendCommand === 'function') {
81
+ return await this.client.sendCommand(this.opts.id, change);
82
+ }
83
+ }
84
+ catch (err) {
85
+ const e = err;
86
+ return { success: false, reason: e?.message ?? String(e) };
87
+ }
88
+ return { success: false, reason: 'unsupported change', change };
89
+ }
90
+ }
91
+ try {
92
+ return await this.client.setDeviceState(this.opts.id, cmdBody);
93
+ }
94
+ catch (err) {
95
+ // try alternative client API if available
96
+ try {
97
+ if (typeof this.client.sendCommand === 'function') {
98
+ return await this.client.sendCommand(this.opts.id, cmdBody);
99
+ }
100
+ }
101
+ catch (e2) {
102
+ // ignore
103
+ }
104
+ const e = err;
105
+ return { success: false, reason: e?.message ?? String(e) };
106
+ }
107
+ }
108
+ createHAPAccessory(api) {
109
+ // Default HAP descriptor: a Switch service with On characteristic
110
+ return {
111
+ services: [
112
+ {
113
+ type: 'Switch',
114
+ characteristics: {
115
+ On: {
116
+ get: async () => {
117
+ const s = await this.getState();
118
+ return !!(s && (s.on === true || s.state === 'on' || s.power === 'on'));
119
+ },
120
+ set: async (v) => {
121
+ await this.setState({ on: !!v });
122
+ },
123
+ },
124
+ },
125
+ },
126
+ ],
127
+ };
128
+ }
129
+ // Default Matter descriptor mirrors HAP descriptor structure so the
130
+ // platform can construct a Matter accessory representation when
131
+ // Homebridge Matter APIs are available. Device subclasses may override
132
+ // this to provide Matter-specific clusters/attributes if desired.
133
+ createMatterAccessory(api) {
134
+ const hapDesc = this.createHAPAccessory(api);
135
+ const clusters = [];
136
+ const mapCharacteristic = (charName) => {
137
+ switch (charName) {
138
+ case 'On':
139
+ return { attr: 'onOff', get: async () => { const s = await this.getState(); return !!(s && (s.on === true || s.state === 'on' || s.power === 'on')); }, set: async (v) => this.setState({ on: !!v }) };
140
+ case 'Brightness':
141
+ return { attr: 'brightness', get: async () => { const s = await this.getState(); return typeof s.brightness === 'number' ? s.brightness : 100; }, set: async (v) => this.setState({ brightness: Number(v) }) };
142
+ case 'Hue':
143
+ return { attr: 'colorHue', get: async () => { const s = await this.getState(); return typeof s.hue === 'number' ? s.hue : 0; }, set: async (v) => this.setState({ hue: Number(v) }) };
144
+ case 'Saturation':
145
+ return { attr: 'colorSaturation', get: async () => { const s = await this.getState(); return typeof s.saturation === 'number' ? s.saturation : 0; }, set: async (v) => this.setState({ saturation: Number(v) }) };
146
+ case 'ColorTemperature':
147
+ return { attr: 'colorTemperature', get: async () => {
148
+ const s = await this.getState();
149
+ if (typeof s.colorTemperature === 'number') {
150
+ return s.colorTemperature;
151
+ }
152
+ if (typeof s.kelvin === 'number') {
153
+ return Math.round(1000000 / s.kelvin);
154
+ }
155
+ return 400;
156
+ }, set: async (v) => this.setState({ colorTemperature: Number(v) }) };
157
+ case 'RotationSpeed':
158
+ return { attr: 'rotationSpeed', get: async () => { const s = await this.getState(); return typeof s.speed === 'number' ? s.speed : 0; }, set: async (v) => this.setState({ speed: Number(v) }) };
159
+ case 'TargetPosition':
160
+ case 'CurrentPosition':
161
+ return { attr: 'position', get: async () => { const s = await this.getState(); return typeof s.position === 'number' ? s.position : 0; }, set: async (v) => this.setState({ position: Number(v) }) };
162
+ case 'LockCurrentState':
163
+ case 'LockTargetState':
164
+ return { attr: 'locked', get: async () => { const s = await this.getState(); return !!(s && s.locked); }, set: async (v) => this.setState({ locked: !!v }) };
165
+ case 'MotionDetected':
166
+ return { attr: 'motionDetected', get: async () => { const s = await this.getState(); return !!(s && s.motion === true); }, set: undefined };
167
+ case 'ContactSensorState':
168
+ return { attr: 'contact', get: async () => { const s = await this.getState(); return s && s.open ? 1 : 0; }, set: undefined };
169
+ default:
170
+ return null;
171
+ }
172
+ };
173
+ for (const s of (hapDesc.services || [])) {
174
+ const clusterType = (() => {
175
+ switch ((s.type || '').toLowerCase()) {
176
+ case 'lightbulb': return 'OnOff/LevelControl/ColorControl';
177
+ case 'fan': return 'FanControl';
178
+ case 'windowscovering': return 'Shade';
179
+ case 'motionsensor': return 'OccupancySensing';
180
+ case 'contactsensor': return 'DoorState';
181
+ case 'lockmechanism': return 'DoorLock';
182
+ case 'switch': return 'OnOff';
183
+ default: return s.type || 'Generic';
184
+ }
185
+ })();
186
+ const attributes = {};
187
+ for (const [charName] of Object.entries(s.characteristics || {})) {
188
+ const mapped = mapCharacteristic(charName);
189
+ if (mapped) {
190
+ attributes[mapped.attr] = { read: typeof mapped.get === 'function' ? mapped.get : undefined, write: typeof mapped.set === 'function' ? mapped.set : undefined };
191
+ }
192
+ }
193
+ clusters.push({ type: clusterType, attributes });
194
+ }
195
+ return {
196
+ id: this.opts.id,
197
+ name: this.opts.name ?? this.opts.type,
198
+ protocol: 'matter',
199
+ clusters,
200
+ };
201
+ }
202
+ }
203
+ // Specific device classes can extend GenericDevice for custom behavior.
204
+ export class BotDevice extends GenericDevice {
205
+ }
206
+ export class CurtainDevice extends GenericDevice {
207
+ createHAPAccessory(api) {
208
+ return {
209
+ services: [
210
+ {
211
+ type: 'WindowCovering',
212
+ characteristics: {
213
+ CurrentPosition: {
214
+ get: async () => {
215
+ const s = await this.getState();
216
+ return typeof s.position === 'number' ? s.position : 0;
217
+ },
218
+ },
219
+ TargetPosition: {
220
+ get: async () => {
221
+ const s = await this.getState();
222
+ return typeof s.position === 'number' ? s.position : 0;
223
+ },
224
+ set: async (v) => {
225
+ await this.setState({ position: Number(v) });
226
+ },
227
+ },
228
+ },
229
+ },
230
+ ],
231
+ };
232
+ }
233
+ // Matter-specific descriptor for Curtain (Shade cluster)
234
+ createMatterAccessory(api) {
235
+ return {
236
+ id: this.opts.id,
237
+ name: this.opts.name ?? this.opts.type,
238
+ protocol: 'matter',
239
+ clusters: [
240
+ {
241
+ // Shade cluster
242
+ type: 'Shade',
243
+ clusterId: MATTER_CLUSTER_IDS.WindowCovering,
244
+ attributes: {
245
+ currentPosition: { read: async () => { const s = await this.getState(); return typeof s.position === 'number' ? s.position : 0; }, write: undefined },
246
+ [MATTER_ATTRIBUTE_IDS.WindowCovering.CurrentPosition]: { read: async () => { const s = await this.getState(); return typeof s.position === 'number' ? s.position : 0; }, write: undefined },
247
+ targetPosition: { read: async () => { const s = await this.getState(); return typeof s.position === 'number' ? s.position : 0; }, write: async (v) => this.setState({ position: Number(v) }) },
248
+ [MATTER_ATTRIBUTE_IDS.WindowCovering.TargetPosition]: { read: async () => { const s = await this.getState(); return typeof s.position === 'number' ? s.position : 0; }, write: async (v) => this.setState({ position: Number(v) }) },
249
+ },
250
+ },
251
+ ],
252
+ };
253
+ }
254
+ }
255
+ export class FanDevice extends GenericDevice {
256
+ createHAPAccessory(api) {
257
+ return {
258
+ services: [
259
+ {
260
+ type: 'Fan',
261
+ characteristics: {
262
+ On: {
263
+ get: async () => {
264
+ const s = await this.getState();
265
+ return !!(s && (s.on === true || s.state === 'on'));
266
+ },
267
+ set: async (v) => {
268
+ await this.setState({ on: !!v });
269
+ },
270
+ },
271
+ RotationSpeed: {
272
+ get: async () => {
273
+ const s = await this.getState();
274
+ return typeof s.speed === 'number' ? s.speed : 0;
275
+ },
276
+ set: async (v) => {
277
+ await this.setState({ speed: Number(v) });
278
+ },
279
+ },
280
+ },
281
+ },
282
+ ],
283
+ };
284
+ }
285
+ async setState(change) {
286
+ if (!this.client) {
287
+ return { success: false, reason: 'no client' };
288
+ }
289
+ // Oscillation support
290
+ if (typeof change.oscillate === 'boolean') {
291
+ const body = { command: 'setOscillation', parameter: change.oscillate ? 'on' : 'off', commandType: 'command' };
292
+ try {
293
+ return await this.client.setDeviceState(this.opts.id, body);
294
+ }
295
+ catch (err) {
296
+ try {
297
+ if (typeof this.client.sendCommand === 'function') {
298
+ return await this.client.sendCommand(this.opts.id, body);
299
+ }
300
+ }
301
+ catch (e) { }
302
+ const e = err;
303
+ return { success: false, reason: e?.message ?? String(e) };
304
+ }
305
+ }
306
+ // Swing / sweep support (angle or mode)
307
+ if (change && (typeof change.swing === 'boolean' || typeof change.swingAngle === 'number' || typeof change.swingMode === 'string')) {
308
+ let param = 'default';
309
+ if (typeof change.swingMode === 'string') {
310
+ param = change.swingMode;
311
+ }
312
+ else if (typeof change.swingAngle === 'number') {
313
+ param = String(Number(change.swingAngle));
314
+ }
315
+ else {
316
+ param = change.swing ? 'on' : 'off';
317
+ }
318
+ const body = { command: 'setSwing', parameter: param, commandType: 'command' };
319
+ try {
320
+ return await this.client.setDeviceState(this.opts.id, body);
321
+ }
322
+ catch (err) {
323
+ try {
324
+ if (typeof this.client.sendCommand === 'function') {
325
+ return await this.client.sendCommand(this.opts.id, body);
326
+ }
327
+ }
328
+ catch (e) { }
329
+ const e = err;
330
+ return { success: false, reason: e?.message ?? String(e) };
331
+ }
332
+ }
333
+ return super.setState(change);
334
+ }
335
+ // Matter-specific descriptor for Fan
336
+ createMatterAccessory(api) {
337
+ return {
338
+ id: this.opts.id,
339
+ name: this.opts.name ?? this.opts.type,
340
+ protocol: 'matter',
341
+ clusters: [
342
+ {
343
+ // OnOff cluster
344
+ type: 'OnOff',
345
+ clusterId: MATTER_CLUSTER_IDS.OnOff,
346
+ attributes: {
347
+ onOff: { read: async () => { const s = await this.getState(); return !!(s && (s.on === true || s.state === 'on')); }, write: async (v) => this.setState({ on: !!v }) },
348
+ // numeric attribute id for onOff
349
+ [MATTER_ATTRIBUTE_IDS.OnOff.OnOff]: { read: async () => { const s = await this.getState(); return !!(s && (s.on === true || s.state === 'on')); }, write: async (v) => this.setState({ on: !!v }) },
350
+ },
351
+ },
352
+ {
353
+ // Fan Control cluster
354
+ type: 'FanControl',
355
+ clusterId: MATTER_CLUSTER_IDS.FanControl,
356
+ attributes: {
357
+ rotationSpeed: { read: async () => { const s = await this.getState(); return typeof s.speed === 'number' ? s.speed : 0; }, write: async (v) => this.setState({ speed: Number(v) }) },
358
+ [MATTER_ATTRIBUTE_IDS.FanControl.SpeedCurrent]: { read: async () => { const s = await this.getState(); return typeof s.speed === 'number' ? s.speed : 0; }, write: async (v) => this.setState({ speed: Number(v) }) },
359
+ oscillation: { read: async () => { const s = await this.getState(); return !!s?.oscillating; }, write: async (v) => this.setState({ oscillate: !!v }) },
360
+ swingMode: { read: async () => { const s = await this.getState(); return s?.swingMode ?? null; }, write: async (v) => this.setState({ swingMode: v }) },
361
+ },
362
+ },
363
+ ],
364
+ };
365
+ }
366
+ }
367
+ export class LightDevice extends GenericDevice {
368
+ createHAPAccessory(api) {
369
+ return {
370
+ services: [
371
+ {
372
+ type: 'Lightbulb',
373
+ characteristics: {
374
+ On: {
375
+ get: async () => {
376
+ const s = await this.getState();
377
+ return !!(s && (s.on === true || s.state === 'on' || s.power === 'on'));
378
+ },
379
+ set: async (v) => {
380
+ await this.setState({ on: !!v });
381
+ },
382
+ },
383
+ Brightness: {
384
+ props: { minValue: 0, maxValue: 100, minStep: 1 },
385
+ get: async () => {
386
+ const s = await this.getState();
387
+ return typeof s.brightness === 'number' ? s.brightness : 100;
388
+ },
389
+ set: async (v) => {
390
+ await this.setState({ brightness: Number(v) });
391
+ },
392
+ },
393
+ Hue: {
394
+ props: { minValue: 0, maxValue: 360, minStep: 1 },
395
+ get: async () => {
396
+ const s = await this.getState();
397
+ // prefer explicit hue if provided
398
+ if (s && typeof s.hue === 'number') {
399
+ return s.hue;
400
+ }
401
+ // try HSV from color hex
402
+ const hex = s?.color || s?.colorHex || s?.colour;
403
+ if (typeof hex === 'string' && HEX_COLOR_REGEX.test(hex)) {
404
+ const h = (() => {
405
+ const hsl = (h, s, l) => ({ h, s, l });
406
+ // convert hex -> rgb -> hsv
407
+ const cleaned = hex.replace('#', '');
408
+ const r = Number.parseInt(cleaned.substr(0, 2), 16) / 255;
409
+ const g = Number.parseInt(cleaned.substr(2, 2), 16) / 255;
410
+ const b = Number.parseInt(cleaned.substr(4, 2), 16) / 255;
411
+ const mx = Math.max(r, g, b);
412
+ const mn = Math.min(r, g, b);
413
+ const d = mx - mn;
414
+ if (d === 0) {
415
+ return 0;
416
+ }
417
+ let hue = 0;
418
+ switch (mx) {
419
+ case r:
420
+ hue = ((g - b) / d) % 6;
421
+ break;
422
+ case g:
423
+ hue = (b - r) / d + 2;
424
+ break;
425
+ case b:
426
+ hue = (r - g) / d + 4;
427
+ break;
428
+ }
429
+ hue = Math.round(hue * 60);
430
+ if (hue < 0) {
431
+ hue += 360;
432
+ }
433
+ return hue;
434
+ })();
435
+ return h;
436
+ }
437
+ return 0;
438
+ },
439
+ set: async (v) => {
440
+ await this.setState({ hue: Number(v) });
441
+ },
442
+ },
443
+ Saturation: {
444
+ props: { minValue: 0, maxValue: 100, minStep: 1 },
445
+ get: async () => {
446
+ const s = await this.getState();
447
+ if (s && typeof s.saturation === 'number') {
448
+ return s.saturation;
449
+ }
450
+ // if color hex is available, derive saturation from rgb
451
+ const hex = s?.color || s?.colorHex || s?.colour;
452
+ if (typeof hex === 'string' && HEX_COLOR_REGEX.test(hex)) {
453
+ const cleaned = hex.replace('#', '');
454
+ const r = Number.parseInt(cleaned.substr(0, 2), 16) / 255;
455
+ const g = Number.parseInt(cleaned.substr(2, 2), 16) / 255;
456
+ const b = Number.parseInt(cleaned.substr(4, 2), 16) / 255;
457
+ const mx = Math.max(r, g, b);
458
+ const mn = Math.min(r, g, b);
459
+ const d = mx - mn;
460
+ const sat = mx === 0 ? 0 : Math.round((d / mx) * 100);
461
+ return sat;
462
+ }
463
+ return 0;
464
+ },
465
+ set: async (v) => {
466
+ await this.setState({ saturation: Number(v) });
467
+ },
468
+ },
469
+ ColorTemperature: {
470
+ props: { minValue: 153, maxValue: 500, minStep: 1 },
471
+ get: async () => {
472
+ const s = await this.getState();
473
+ // prefer mired if provided
474
+ if (s && typeof s.colorTemperature === 'number') {
475
+ return s.colorTemperature;
476
+ }
477
+ if (s && typeof s.color_temp === 'number') {
478
+ return s.color_temp;
479
+ }
480
+ // some devices provide kelvin
481
+ if (s && typeof s.kelvin === 'number' && s.kelvin > 0) {
482
+ return Math.round(1000000 / s.kelvin);
483
+ }
484
+ return 400;
485
+ },
486
+ set: async (v) => {
487
+ await this.setState({ colorTemperature: Number(v) });
488
+ },
489
+ },
490
+ },
491
+ },
492
+ ],
493
+ };
494
+ }
495
+ async setState(change) {
496
+ if (!this.client) {
497
+ return { success: false, reason: 'no client' };
498
+ }
499
+ // Color temperature (mired) or brightness/hue/sat
500
+ if (typeof change.colorTemperature === 'number' || typeof change.color_temp === 'number') {
501
+ const v = String(Number(change.colorTemperature ?? change.color_temp));
502
+ const body = { command: 'setColorTemperature', parameter: v, commandType: 'command' };
503
+ try {
504
+ return await this.client.setDeviceState(this.opts.id, body);
505
+ }
506
+ catch (err) {
507
+ try {
508
+ if (typeof this.client.sendCommand === 'function') {
509
+ return await this.client.sendCommand(this.opts.id, body);
510
+ }
511
+ }
512
+ catch (e) { }
513
+ const e = err;
514
+ return { success: false, reason: e?.message ?? String(e) };
515
+ }
516
+ }
517
+ if (typeof change.hue === 'number' && typeof change.saturation === 'number') {
518
+ const body = { command: 'setColor', parameter: `${Number(change.hue)},${Number(change.saturation)}`, commandType: 'command' };
519
+ try {
520
+ return await this.client.setDeviceState(this.opts.id, body);
521
+ }
522
+ catch (err) {
523
+ try {
524
+ if (typeof this.client.sendCommand === 'function') {
525
+ return await this.client.sendCommand(this.opts.id, body);
526
+ }
527
+ }
528
+ catch (e) { }
529
+ const e = err;
530
+ return { success: false, reason: e?.message ?? String(e) };
531
+ }
532
+ }
533
+ if (change && typeof change.color === 'string') {
534
+ const body = { command: 'setColor', parameter: change.color, commandType: 'command' };
535
+ try {
536
+ return await this.client.setDeviceState(this.opts.id, body);
537
+ }
538
+ catch (err) {
539
+ try {
540
+ if (typeof this.client.sendCommand === 'function') {
541
+ return await this.client.sendCommand(this.opts.id, body);
542
+ }
543
+ }
544
+ catch (e) { }
545
+ const e = err;
546
+ return { success: false, reason: e?.message ?? String(e) };
547
+ }
548
+ }
549
+ // Fallback to generic handler (brightness/on)
550
+ return super.setState(change);
551
+ }
552
+ // Matter-specific descriptor for lights (OnOff + Level + Color)
553
+ createMatterAccessory(api) {
554
+ return {
555
+ id: this.opts.id,
556
+ name: this.opts.name ?? this.opts.type,
557
+ protocol: 'matter',
558
+ clusters: [
559
+ {
560
+ // OnOff cluster
561
+ type: 'OnOff',
562
+ clusterId: MATTER_CLUSTER_IDS.OnOff,
563
+ attributes: {
564
+ onOff: { read: async () => { const s = await this.getState(); return !!(s && (s.on === true || s.state === 'on' || s.power === 'on')); }, write: async (v) => this.setState({ on: !!v }) },
565
+ [MATTER_ATTRIBUTE_IDS.OnOff.OnOff]: { read: async () => { const s = await this.getState(); return !!(s && (s.on === true || s.state === 'on' || s.power === 'on')); }, write: async (v) => this.setState({ on: !!v }) },
566
+ },
567
+ },
568
+ {
569
+ // Level Control cluster
570
+ type: 'LevelControl',
571
+ clusterId: MATTER_CLUSTER_IDS.LevelControl,
572
+ attributes: {
573
+ currentLevel: { read: async () => { const s = await this.getState(); return typeof s.brightness === 'number' ? s.brightness : 100; }, write: async (v) => this.setState({ brightness: Number(v) }) },
574
+ [MATTER_ATTRIBUTE_IDS.LevelControl.CurrentLevel]: { read: async () => { const s = await this.getState(); return typeof s.brightness === 'number' ? s.brightness : 100; }, write: async (v) => this.setState({ brightness: Number(v) }) },
575
+ },
576
+ },
577
+ {
578
+ // Color Control cluster
579
+ type: 'ColorControl',
580
+ clusterId: MATTER_CLUSTER_IDS.ColorControl,
581
+ attributes: {
582
+ colorHue: { read: async () => { const s = await this.getState(); return typeof s.hue === 'number' ? s.hue : 0; }, write: async (v) => this.setState({ hue: Number(v) }) },
583
+ [MATTER_ATTRIBUTE_IDS.ColorControl.CurrentHue]: { read: async () => { const s = await this.getState(); return typeof s.hue === 'number' ? s.hue : 0; }, write: async (v) => this.setState({ hue: Number(v) }) },
584
+ colorSaturation: { read: async () => { const s = await this.getState(); return typeof s.saturation === 'number' ? s.saturation : 0; }, write: async (v) => this.setState({ saturation: Number(v) }) },
585
+ [MATTER_ATTRIBUTE_IDS.ColorControl.CurrentSaturation]: { read: async () => { const s = await this.getState(); return typeof s.saturation === 'number' ? s.saturation : 0; }, write: async (v) => this.setState({ saturation: Number(v) }) },
586
+ colorTemperature: { read: async () => {
587
+ const s = await this.getState();
588
+ if (typeof s.colorTemperature === 'number') {
589
+ return s.colorTemperature;
590
+ }
591
+ if (typeof s.kelvin === 'number') {
592
+ return Math.round(1000000 / s.kelvin);
593
+ }
594
+ return 400;
595
+ }, write: async (v) => this.setState({ colorTemperature: Number(v) }) },
596
+ [MATTER_ATTRIBUTE_IDS.ColorControl.ColorTemperatureMireds]: { read: async () => {
597
+ const s = await this.getState();
598
+ if (typeof s.colorTemperature === 'number') {
599
+ return s.colorTemperature;
600
+ }
601
+ if (typeof s.kelvin === 'number') {
602
+ return Math.round(1000000 / s.kelvin);
603
+ }
604
+ return 400;
605
+ }, write: async (v) => this.setState({ colorTemperature: Number(v) }) },
606
+ },
607
+ },
608
+ ],
609
+ };
610
+ }
611
+ }
612
+ export class LightStripDevice extends LightDevice {
613
+ }
614
+ export class MotionSensorDevice extends GenericDevice {
615
+ createHAPAccessory(api) {
616
+ return {
617
+ services: [
618
+ {
619
+ type: 'MotionSensor',
620
+ characteristics: {
621
+ MotionDetected: {
622
+ get: async () => {
623
+ const s = await this.getState();
624
+ return !!(s && s.motion === true);
625
+ },
626
+ },
627
+ },
628
+ },
629
+ ],
630
+ };
631
+ }
632
+ async setState(change) {
633
+ if (!this.client) {
634
+ return { success: false, reason: 'no client' };
635
+ }
636
+ // Oscillation support
637
+ if (typeof change.oscillate === 'boolean') {
638
+ const body = { command: 'setOscillation', parameter: change.oscillate ? 'on' : 'off', commandType: 'command' };
639
+ try {
640
+ return await this.client.setDeviceState(this.opts.id, body);
641
+ }
642
+ catch (err) {
643
+ try {
644
+ if (typeof this.client.sendCommand === 'function') {
645
+ return await this.client.sendCommand(this.opts.id, body);
646
+ }
647
+ }
648
+ catch (e) { }
649
+ const e = err;
650
+ return { success: false, reason: e?.message ?? String(e) };
651
+ }
652
+ }
653
+ // Swing / sweep support (angle or mode)
654
+ if (change && (typeof change.swing === 'boolean' || typeof change.swingAngle === 'number' || typeof change.swingMode === 'string')) {
655
+ let param = 'default';
656
+ if (typeof change.swingMode === 'string') {
657
+ param = change.swingMode;
658
+ }
659
+ else if (typeof change.swingAngle === 'number') {
660
+ param = String(Number(change.swingAngle));
661
+ }
662
+ else {
663
+ param = change.swing ? 'on' : 'off';
664
+ }
665
+ const body = { command: 'setSwing', parameter: param, commandType: 'command' };
666
+ try {
667
+ return await this.client.setDeviceState(this.opts.id, body);
668
+ }
669
+ catch (err) {
670
+ try {
671
+ if (typeof this.client.sendCommand === 'function') {
672
+ return await this.client.sendCommand(this.opts.id, body);
673
+ }
674
+ }
675
+ catch (e) { }
676
+ const e = err;
677
+ return { success: false, reason: e?.message ?? String(e) };
678
+ }
679
+ }
680
+ return super.setState(change);
681
+ }
682
+ }
683
+ export class ContactSensorDevice extends GenericDevice {
684
+ createHAPAccessory(api) {
685
+ return {
686
+ services: [
687
+ {
688
+ type: 'ContactSensor',
689
+ characteristics: {
690
+ ContactSensorState: {
691
+ get: async () => {
692
+ const s = await this.getState();
693
+ return s && s.open ? 1 : 0;
694
+ },
695
+ },
696
+ },
697
+ },
698
+ ],
699
+ };
700
+ }
701
+ }
702
+ export class VacuumDevice extends GenericDevice {
703
+ // Use DeviceBase defaults (Switch-style) — no override needed
704
+ createHAPAccessory(api) {
705
+ return super.createHAPAccessory(api);
706
+ }
707
+ }
708
+ export class LockDevice extends GenericDevice {
709
+ createHAPAccessory(api) {
710
+ return {
711
+ services: [
712
+ {
713
+ type: 'LockMechanism',
714
+ characteristics: {
715
+ LockCurrentState: {
716
+ get: async () => {
717
+ const s = await this.getState();
718
+ return s && s.locked ? 1 : 0;
719
+ },
720
+ },
721
+ LockTargetState: {
722
+ get: async () => {
723
+ const s = await this.getState();
724
+ return s && s.locked ? 1 : 0;
725
+ },
726
+ set: async (v) => {
727
+ await this.setState({ locked: !!v });
728
+ },
729
+ },
730
+ },
731
+ },
732
+ ],
733
+ };
734
+ }
735
+ async setState(change) {
736
+ if (!this.client) {
737
+ return { success: false, reason: 'no client' };
738
+ }
739
+ // User management actions: add/remove/list users, unlock with pin
740
+ if (change && typeof change.action === 'string') {
741
+ const action = change.action;
742
+ try {
743
+ if (action === 'addUser' && (change.user || change.userId) && (change.pin || change.code)) {
744
+ const user = change.user ?? change.userId;
745
+ const p = String(change.pin ?? change.code);
746
+ const body = { command: 'addUserCode', parameter: `${user}:${p}`, commandType: 'command' };
747
+ return await this.client.setDeviceState(this.opts.id, body);
748
+ }
749
+ if (action === 'removeUser' && (change.user || change.userId)) {
750
+ const user = change.user ?? change.userId;
751
+ const body = { command: 'removeUserCode', parameter: String(user), commandType: 'command' };
752
+ return await this.client.setDeviceState(this.opts.id, body);
753
+ }
754
+ if (action === 'listUsers') {
755
+ const body = { command: 'listUsers', parameter: 'default', commandType: 'command' };
756
+ return await this.client.setDeviceState(this.opts.id, body);
757
+ }
758
+ if (action === 'unlockWithPin' && (change.pin || change.code)) {
759
+ const p = String(change.pin ?? change.code);
760
+ const body = { command: 'unlockWithPin', parameter: p, commandType: 'command' };
761
+ return await this.client.setDeviceState(this.opts.id, body);
762
+ }
763
+ }
764
+ catch (err) {
765
+ try {
766
+ if (typeof this.client.sendCommand === 'function') {
767
+ return await this.client.sendCommand(this.opts.id, { command: action, parameter: change.parameter ?? 'default', commandType: 'command' });
768
+ }
769
+ }
770
+ catch (e) { }
771
+ const e = err;
772
+ return { success: false, reason: e?.message ?? String(e) };
773
+ }
774
+ }
775
+ // Support setting lock PIN/passcode via `pin` or `passcode` (fallback)
776
+ const pin = change?.pin ?? change?.passcode ?? change?.code;
777
+ if (typeof pin === 'string' || typeof pin === 'number') {
778
+ const body = { command: 'setLockPin', parameter: String(pin), commandType: 'command' };
779
+ try {
780
+ return await this.client.setDeviceState(this.opts.id, body);
781
+ }
782
+ catch (err) {
783
+ try {
784
+ if (typeof this.client.sendCommand === 'function') {
785
+ return await this.client.sendCommand(this.opts.id, body);
786
+ }
787
+ }
788
+ catch (e) { }
789
+ const e = err;
790
+ return { success: false, reason: e?.message ?? String(e) };
791
+ }
792
+ }
793
+ return super.setState(change);
794
+ }
795
+ // Matter DoorLock descriptor including simple user-management actions
796
+ createMatterAccessory(api) {
797
+ return {
798
+ id: this.opts.id,
799
+ name: this.opts.name ?? this.opts.type,
800
+ protocol: 'matter',
801
+ clusters: [
802
+ {
803
+ // DoorLock cluster
804
+ type: 'DoorLock',
805
+ clusterId: MATTER_CLUSTER_IDS.DoorLock,
806
+ attributes: {
807
+ lockState: { read: async () => { const s = await this.getState(); return !!(s && s.locked); }, write: async (v) => this.setState({ locked: !!v }) },
808
+ [MATTER_ATTRIBUTE_IDS.DoorLock.LockState]: { read: async () => { const s = await this.getState(); return !!(s && s.locked); }, write: async (v) => this.setState({ locked: !!v }) },
809
+ },
810
+ },
811
+ {
812
+ // DoorLock user mgmt cluster (conceptual)
813
+ type: 'DoorLockUserManagement',
814
+ clusterId: 0x0301,
815
+ attributes: {
816
+ addUser: { write: async (v) => this.setState({ action: 'addUser', user: v?.user, pin: v?.pin }) },
817
+ removeUser: { write: async (v) => this.setState({ action: 'removeUser', user: v?.user }) },
818
+ listUsers: { read: async () => { const r = await this.setState({ action: 'listUsers' }); return r; }, write: undefined },
819
+ unlockWithPin: { write: async (v) => this.setState({ action: 'unlockWithPin', pin: v?.pin }) },
820
+ },
821
+ },
822
+ ],
823
+ };
824
+ }
825
+ }
826
+ export class HumidifierDevice extends GenericDevice {
827
+ createHAPAccessory(api) {
828
+ return {
829
+ services: [
830
+ {
831
+ type: 'HumidifierDehumidifier',
832
+ characteristics: {
833
+ Active: {
834
+ get: async () => {
835
+ const s = await this.getState();
836
+ return s && s.on ? 1 : 0;
837
+ },
838
+ set: async (v) => {
839
+ await this.setState({ on: v === 1 });
840
+ },
841
+ },
842
+ CurrentHumidifierDehumidifierState: {
843
+ get: async () => {
844
+ const s = await this.getState();
845
+ return s && s.on ? 2 : 0; // 0 = Inactive, 2 = Humidifying
846
+ },
847
+ },
848
+ TargetHumidifierDehumidifierState: {
849
+ get: async () => 1, // 1 = Humidifier
850
+ set: async (v) => {
851
+ // Support humidifier mode
852
+ },
853
+ },
854
+ CurrentRelativeHumidity: {
855
+ get: async () => {
856
+ const s = await this.getState();
857
+ return typeof s.humidity === 'number' ? s.humidity : 0;
858
+ },
859
+ },
860
+ RelativeHumidityHumidifierThreshold: {
861
+ get: async () => {
862
+ const s = await this.getState();
863
+ return typeof s.targetHumidity === 'number' ? s.targetHumidity : 50;
864
+ },
865
+ set: async (v) => {
866
+ await this.setState({ humidity: Number(v) });
867
+ },
868
+ },
869
+ },
870
+ },
871
+ ],
872
+ };
873
+ }
874
+ async setState(change) {
875
+ if (!this.client) {
876
+ return { success: false, reason: 'no client' };
877
+ }
878
+ if (typeof change.humidity === 'number') {
879
+ const v = String(Number(change.humidity));
880
+ const body = { command: 'setHumidity', parameter: v, commandType: 'command' };
881
+ try {
882
+ return await this.client.setDeviceState(this.opts.id, body);
883
+ }
884
+ catch (err) {
885
+ try {
886
+ if (typeof this.client.sendCommand === 'function') {
887
+ return await this.client.sendCommand(this.opts.id, body);
888
+ }
889
+ }
890
+ catch (e) { }
891
+ const e = err;
892
+ return { success: false, reason: e?.message ?? String(e) };
893
+ }
894
+ }
895
+ if (typeof change.dry === 'boolean') {
896
+ const body = { command: 'setDry', parameter: change.dry ? 'on' : 'off', commandType: 'command' };
897
+ try {
898
+ return await this.client.setDeviceState(this.opts.id, body);
899
+ }
900
+ catch (err) {
901
+ try {
902
+ if (typeof this.client.sendCommand === 'function') {
903
+ return await this.client.sendCommand(this.opts.id, body);
904
+ }
905
+ }
906
+ catch (e) { }
907
+ const e = err;
908
+ return { success: false, reason: e?.message ?? String(e) };
909
+ }
910
+ }
911
+ return super.setState(change);
912
+ }
913
+ }
914
+ // Provide Matter descriptor for humidifier (humidity and on/off)
915
+ export class HumidifierMatterDevice extends HumidifierDevice {
916
+ createMatterAccessory(api) {
917
+ return {
918
+ id: this.opts.id,
919
+ name: this.opts.name ?? this.opts.type,
920
+ protocol: 'matter',
921
+ clusters: [
922
+ {
923
+ // Relative Humidity Sensor cluster
924
+ type: 'RelativeHumiditySensor',
925
+ clusterId: MATTER_CLUSTER_IDS.RelativeHumidityMeasurement,
926
+ attributes: {
927
+ currentRelativeHumidity: { read: async () => { const s = await this.getState(); return typeof s.humidity === 'number' ? s.humidity : 0; }, write: undefined },
928
+ [MATTER_ATTRIBUTE_IDS.RelativeHumidityMeasurement.MeasuredValue]: { read: async () => { const s = await this.getState(); return typeof s.humidity === 'number' ? s.humidity : 0; }, write: undefined },
929
+ },
930
+ },
931
+ {
932
+ type: 'OnOff',
933
+ clusterId: MATTER_CLUSTER_IDS.OnOff,
934
+ attributes: {
935
+ onOff: { read: async () => { const s = await this.getState(); return !!s?.on; }, write: async (v) => this.setState({ on: !!v }) },
936
+ [MATTER_ATTRIBUTE_IDS.OnOff.OnOff]: { read: async () => { const s = await this.getState(); return !!s?.on; }, write: async (v) => this.setState({ on: !!v }) },
937
+ },
938
+ },
939
+ ],
940
+ };
941
+ }
942
+ }
943
+ export class TemperatureSensorDevice extends GenericDevice {
944
+ createHAPAccessory(api) {
945
+ return {
946
+ services: [
947
+ {
948
+ type: 'TemperatureSensor',
949
+ characteristics: {
950
+ CurrentTemperature: {
951
+ get: async () => {
952
+ const s = await this.getState();
953
+ return typeof s.temperature === 'number' ? s.temperature : 0;
954
+ },
955
+ },
956
+ },
957
+ },
958
+ ],
959
+ };
960
+ }
961
+ }
962
+ // Additional device classes (aliases / specialized variants)
963
+ export class RelaySwitchDevice extends GenericDevice {
964
+ }
965
+ export class RelaySwitch1PMDevice extends GenericDevice {
966
+ }
967
+ export class PlugDevice extends GenericDevice {
968
+ createHAPAccessory(api) {
969
+ return {
970
+ services: [
971
+ {
972
+ type: 'Outlet',
973
+ characteristics: {
974
+ On: {
975
+ get: async () => {
976
+ const s = await this.getState();
977
+ return !!(s && (s.on === true || s.state === 'on'));
978
+ },
979
+ set: async (v) => {
980
+ await this.setState({ on: !!v });
981
+ },
982
+ },
983
+ OutletInUse: {
984
+ get: async () => {
985
+ const s = await this.getState();
986
+ return s && s.inUse ? 1 : 0;
987
+ },
988
+ },
989
+ },
990
+ },
991
+ ],
992
+ };
993
+ }
994
+ }
995
+ export class PlugMiniDevice extends PlugDevice {
996
+ }
997
+ export class BlindTiltDevice extends CurtainDevice {
998
+ }
999
+ export class Curtain3Device extends CurtainDevice {
1000
+ }
1001
+ export class RollerShadeDevice extends CurtainDevice {
1002
+ }
1003
+ export class Hub2Device extends GenericDevice {
1004
+ }
1005
+ export class MeterDevice extends GenericDevice {
1006
+ createHAPAccessory(api) {
1007
+ return {
1008
+ services: [
1009
+ {
1010
+ type: 'TemperatureSensor',
1011
+ characteristics: {
1012
+ CurrentTemperature: {
1013
+ get: async () => {
1014
+ const s = await this.getState();
1015
+ return typeof s.temperature === 'number' ? s.temperature : 0;
1016
+ },
1017
+ },
1018
+ },
1019
+ },
1020
+ {
1021
+ type: 'HumiditySensor',
1022
+ characteristics: {
1023
+ CurrentRelativeHumidity: {
1024
+ get: async () => {
1025
+ const s = await this.getState();
1026
+ return typeof s.humidity === 'number' ? s.humidity : 0;
1027
+ },
1028
+ },
1029
+ },
1030
+ },
1031
+ ],
1032
+ };
1033
+ }
1034
+ }
1035
+ export class WaterDetectorDevice extends GenericDevice {
1036
+ createHAPAccessory(api) {
1037
+ return {
1038
+ services: [
1039
+ {
1040
+ type: 'LeakSensor',
1041
+ characteristics: {
1042
+ LeakDetected: {
1043
+ get: async () => {
1044
+ const s = await this.getState();
1045
+ return s && s.leak ? 1 : 0;
1046
+ },
1047
+ },
1048
+ },
1049
+ },
1050
+ ],
1051
+ };
1052
+ }
1053
+ }
1054
+ export class SmartFanDevice extends FanDevice {
1055
+ }
1056
+ export class StripLightDevice extends LightStripDevice {
1057
+ }
1058
+ export class WalletFinderDevice extends GenericDevice {
1059
+ }
1060
+ // K10 / WoSweeper variants map to VacuumDevice
1061
+ export class WoSweeperDevice extends VacuumDevice {
1062
+ }
1063
+ export class WoSweeperMiniDevice extends VacuumDevice {
1064
+ }
1065
+ export class WoSweeperMiniProDevice extends VacuumDevice {
1066
+ }
1067
+ //# sourceMappingURL=genericDevice.js.map