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

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