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

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