@switchbot/homebridge-switchbot 5.0.0-beta.1 → 5.0.0-beta.100

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 +298 -0
  19. package/dist/devices/genericDevice.d.ts.map +1 -0
  20. package/dist/devices/genericDevice.js +1065 -0
  21. package/dist/devices/genericDevice.js.map +1 -0
  22. package/dist/homebridge-ui/public/index.html +636 -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 +467 -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 -7
  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 +1562 -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 +995 -0
  67. package/src/homebridge-ui/public/index.html +636 -246
  68. package/src/homebridge-ui/server.ts +552 -41
  69. package/src/index.ts +4 -7
  70. package/src/platform.ts +1561 -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 -18
  241. package/dist/devices-matter/ColorLightAccessory.d.ts.map +0 -1
  242. package/dist/devices-matter/ColorLightAccessory.js +0 -96
  243. package/dist/devices-matter/ColorLightAccessory.js.map +0 -1
  244. package/dist/devices-matter/ColorTemperatureLightAccessory.d.ts +0 -16
  245. package/dist/devices-matter/ColorTemperatureLightAccessory.d.ts.map +0 -1
  246. package/dist/devices-matter/ColorTemperatureLightAccessory.js +0 -83
  247. package/dist/devices-matter/ColorTemperatureLightAccessory.js.map +0 -1
  248. package/dist/devices-matter/ContactSensorAccessory.d.ts +0 -10
  249. package/dist/devices-matter/ContactSensorAccessory.d.ts.map +0 -1
  250. package/dist/devices-matter/ContactSensorAccessory.js +0 -31
  251. package/dist/devices-matter/ContactSensorAccessory.js.map +0 -1
  252. package/dist/devices-matter/DimmableLightAccessory.d.ts +0 -56
  253. package/dist/devices-matter/DimmableLightAccessory.d.ts.map +0 -1
  254. package/dist/devices-matter/DimmableLightAccessory.js +0 -170
  255. package/dist/devices-matter/DimmableLightAccessory.js.map +0 -1
  256. package/dist/devices-matter/DoorLockAccessory.d.ts +0 -12
  257. package/dist/devices-matter/DoorLockAccessory.d.ts.map +0 -1
  258. package/dist/devices-matter/DoorLockAccessory.js +0 -47
  259. package/dist/devices-matter/DoorLockAccessory.js.map +0 -1
  260. package/dist/devices-matter/ExtendedColorLightAccessory.d.ts +0 -19
  261. package/dist/devices-matter/ExtendedColorLightAccessory.d.ts.map +0 -1
  262. package/dist/devices-matter/ExtendedColorLightAccessory.js +0 -108
  263. package/dist/devices-matter/ExtendedColorLightAccessory.js.map +0 -1
  264. package/dist/devices-matter/FanAccessory.d.ts +0 -14
  265. package/dist/devices-matter/FanAccessory.d.ts.map +0 -1
  266. package/dist/devices-matter/FanAccessory.js +0 -73
  267. package/dist/devices-matter/FanAccessory.js.map +0 -1
  268. package/dist/devices-matter/HumiditySensorAccessory.d.ts +0 -10
  269. package/dist/devices-matter/HumiditySensorAccessory.d.ts.map +0 -1
  270. package/dist/devices-matter/HumiditySensorAccessory.js +0 -33
  271. package/dist/devices-matter/HumiditySensorAccessory.js.map +0 -1
  272. package/dist/devices-matter/LeakSensorAccessory.d.ts +0 -10
  273. package/dist/devices-matter/LeakSensorAccessory.d.ts.map +0 -1
  274. package/dist/devices-matter/LeakSensorAccessory.js +0 -30
  275. package/dist/devices-matter/LeakSensorAccessory.js.map +0 -1
  276. package/dist/devices-matter/LightSensorAccessory.d.ts +0 -10
  277. package/dist/devices-matter/LightSensorAccessory.d.ts.map +0 -1
  278. package/dist/devices-matter/LightSensorAccessory.js +0 -33
  279. package/dist/devices-matter/LightSensorAccessory.js.map +0 -1
  280. package/dist/devices-matter/OccupancySensorAccessory.d.ts +0 -10
  281. package/dist/devices-matter/OccupancySensorAccessory.d.ts.map +0 -1
  282. package/dist/devices-matter/OccupancySensorAccessory.js +0 -43
  283. package/dist/devices-matter/OccupancySensorAccessory.js.map +0 -1
  284. package/dist/devices-matter/OnOffLightAccessory.d.ts +0 -36
  285. package/dist/devices-matter/OnOffLightAccessory.d.ts.map +0 -1
  286. package/dist/devices-matter/OnOffLightAccessory.js +0 -117
  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 -43
  291. package/dist/devices-matter/OnOffOutletAccessory.js.map +0 -1
  292. package/dist/devices-matter/OnOffSwitchAccessory.d.ts +0 -12
  293. package/dist/devices-matter/OnOffSwitchAccessory.d.ts.map +0 -1
  294. package/dist/devices-matter/OnOffSwitchAccessory.js +0 -43
  295. package/dist/devices-matter/OnOffSwitchAccessory.js.map +0 -1
  296. package/dist/devices-matter/RoboticVacuumAccessory.d.ts +0 -66
  297. package/dist/devices-matter/RoboticVacuumAccessory.d.ts.map +0 -1
  298. package/dist/devices-matter/RoboticVacuumAccessory.js +0 -402
  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 -10
  305. package/dist/devices-matter/TemperatureSensorAccessory.d.ts.map +0 -1
  306. package/dist/devices-matter/TemperatureSensorAccessory.js +0 -33
  307. package/dist/devices-matter/TemperatureSensorAccessory.js.map +0 -1
  308. package/dist/devices-matter/ThermostatAccessory.d.ts +0 -17
  309. package/dist/devices-matter/ThermostatAccessory.d.ts.map +0 -1
  310. package/dist/devices-matter/ThermostatAccessory.js +0 -87
  311. package/dist/devices-matter/ThermostatAccessory.js.map +0 -1
  312. package/dist/devices-matter/VenetianBlindAccessory.d.ts +0 -17
  313. package/dist/devices-matter/VenetianBlindAccessory.d.ts.map +0 -1
  314. package/dist/devices-matter/VenetianBlindAccessory.js +0 -100
  315. package/dist/devices-matter/VenetianBlindAccessory.js.map +0 -1
  316. package/dist/devices-matter/WindowBlindAccessory.d.ts +0 -15
  317. package/dist/devices-matter/WindowBlindAccessory.d.ts.map +0 -1
  318. package/dist/devices-matter/WindowBlindAccessory.js +0 -81
  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 -2849
  379. package/dist/platform-hap.js.map +0 -1
  380. package/dist/platform-matter.d.ts +0 -75
  381. package/dist/platform-matter.d.ts.map +0 -1
  382. package/dist/platform-matter.js +0 -379
  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 -113
  413. package/src/devices-matter/ColorTemperatureLightAccessory.ts +0 -98
  414. package/src/devices-matter/ContactSensorAccessory.ts +0 -37
  415. package/src/devices-matter/DimmableLightAccessory.ts +0 -196
  416. package/src/devices-matter/DoorLockAccessory.ts +0 -56
  417. package/src/devices-matter/ExtendedColorLightAccessory.ts +0 -127
  418. package/src/devices-matter/FanAccessory.ts +0 -87
  419. package/src/devices-matter/HumiditySensorAccessory.ts +0 -39
  420. package/src/devices-matter/LeakSensorAccessory.ts +0 -36
  421. package/src/devices-matter/LightSensorAccessory.ts +0 -39
  422. package/src/devices-matter/OccupancySensorAccessory.ts +0 -52
  423. package/src/devices-matter/OnOffLightAccessory.ts +0 -133
  424. package/src/devices-matter/OnOffOutletAccessory.ts +0 -52
  425. package/src/devices-matter/OnOffSwitchAccessory.ts +0 -52
  426. package/src/devices-matter/RoboticVacuumAccessory.ts +0 -484
  427. package/src/devices-matter/SmokeCOAlarmAccessory.ts +0 -59
  428. package/src/devices-matter/TemperatureSensorAccessory.ts +0 -39
  429. package/src/devices-matter/ThermostatAccessory.ts +0 -105
  430. package/src/devices-matter/VenetianBlindAccessory.ts +0 -118
  431. package/src/devices-matter/WindowBlindAccessory.ts +0 -94
  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 -2986
  447. package/src/platform-matter.ts +0 -465
  448. package/src/verifyconfig.test.ts +0 -197
@@ -1,2849 +0,0 @@
1
- import { readFileSync } from 'node:fs';
2
- import { argv } from 'node:process';
3
- import asyncmqtt from 'async-mqtt';
4
- import fakegato from 'fakegato-history';
5
- import { EveHomeKitTypes } from 'homebridge-lib/EveHomeKitTypes';
6
- import { LogLevel, SwitchBotBLE, SwitchBotModel, SwitchBotOpenAPI } from 'node-switchbot';
7
- import { queueScheduler } from 'rxjs';
8
- import { AirPurifier } from './devices-hap/airpurifier.js';
9
- import { BlindTilt } from './devices-hap/blindtilt.js';
10
- import { Bot } from './devices-hap/bot.js';
11
- import { CeilingLight } from './devices-hap/ceilinglight.js';
12
- import { ColorBulb } from './devices-hap/colorbulb.js';
13
- import { Contact } from './devices-hap/contact.js';
14
- import { Curtain } from './devices-hap/curtain.js';
15
- import { Fan } from './devices-hap/fan.js';
16
- import { Hub } from './devices-hap/hub.js';
17
- import { Humidifier } from './devices-hap/humidifier.js';
18
- import { IOSensor } from './devices-hap/iosensor.js';
19
- import { StripLight } from './devices-hap/lightstrip.js';
20
- import { Lock } from './devices-hap/lock.js';
21
- import { Meter } from './devices-hap/meter.js';
22
- import { MeterPlus } from './devices-hap/meterplus.js';
23
- import { MeterPro } from './devices-hap/meterpro.js';
24
- import { Motion } from './devices-hap/motion.js';
25
- import { Plug } from './devices-hap/plug.js';
26
- import { RelaySwitch } from './devices-hap/relayswitch.js';
27
- import { RobotVacuumCleaner } from './devices-hap/robotvacuumcleaner.js';
28
- import { WaterDetector } from './devices-hap/waterdetector.js';
29
- import { AirConditioner } from './irdevice/airconditioner.js';
30
- import { AirPurifierIR } from './irdevice/airpurifier.js';
31
- import { Camera } from './irdevice/camera.js';
32
- import { IRFan } from './irdevice/fan.js';
33
- import { Light } from './irdevice/light.js';
34
- import { Others } from './irdevice/other.js';
35
- import { TV } from './irdevice/tv.js';
36
- import { VacuumCleaner } from './irdevice/vacuumcleaner.js';
37
- import { WaterHeater } from './irdevice/waterheater.js';
38
- import { PLATFORM_NAME, PLUGIN_NAME } from './settings.js';
39
- import { cleanDeviceConfig, formatDeviceIdAsMac, isBlindTiltDevice, isCurtainDevice, safeStringify, sleep } from './utils.js';
40
- /**
41
- * HomebridgePlatform
42
- * This class is the main constructor for your plugin, this is where you should
43
- * parse the user config and discover/register accessories with Homebridge.
44
- */
45
- export class SwitchBotHAPPlatform {
46
- // Platform properties
47
- accessories = [];
48
- api;
49
- log;
50
- // Configuration properties
51
- platformConfig;
52
- platformLogging;
53
- platformRefreshRate;
54
- platformPushRate;
55
- platformUpdateRate;
56
- platformMaxRetries;
57
- platformDelayBetweenRetries;
58
- config;
59
- debugMode;
60
- version;
61
- // MQTT and Webhook properties
62
- mqttClient = null;
63
- webhookEventListener = null;
64
- // SwitchBot APIs
65
- switchBotAPI;
66
- switchBotBLE;
67
- // External APIs
68
- eve;
69
- fakegatoAPI;
70
- // Event Handlers
71
- webhookEventHandler = {};
72
- bleEventHandler = {};
73
- constructor(log, config, api) {
74
- this.api = api;
75
- this.log = log;
76
- // only load if configured
77
- if (!config) {
78
- this.log.error('No configuration found for the plugin, please check your config.');
79
- return;
80
- }
81
- // Plugin options into our config variables.
82
- this.config = {
83
- platform: 'SwitchBotPlatform',
84
- name: config.name,
85
- credentials: config.credentials,
86
- options: config.options,
87
- devices: config.devices,
88
- };
89
- // Normalize deviceConfig to remove UI-inserted defaults (lots of false/empty values)
90
- try {
91
- if (this.config.options) {
92
- const cleaned = cleanDeviceConfig(this.config.options.deviceConfig);
93
- if (cleaned) {
94
- ;
95
- this.config.options.deviceConfig = cleaned;
96
- }
97
- else {
98
- // remove the empty deviceConfig so downstream checks treat it as absent
99
- delete this.config.options.deviceConfig;
100
- }
101
- }
102
- }
103
- catch (e) {
104
- this.debugErrorLog(`Failed to clean deviceConfig: ${e}`);
105
- }
106
- // Plugin Configuration
107
- this.getPlatformLogSettings();
108
- this.getPlatformRateSettings();
109
- this.getPlatformConfigSettings();
110
- this.getVersion();
111
- // Finish initializing the platform
112
- this.debugLog(`Finished initializing platform: ${config.name}`);
113
- // verify the config
114
- try {
115
- this.verifyConfig();
116
- this.debugLog('Config OK');
117
- }
118
- catch (e) {
119
- this.errorLog(`Verify Config, Error Message: ${e.message ?? e}, Submit Bugs Here: ` + 'https://tinyurl.com/SwitchBotBug');
120
- this.debugErrorLog(`Verify Config, Error: ${e.message ?? e}`);
121
- return;
122
- }
123
- // SwitchBot OpenAPI
124
- if (this.config.credentials?.token && this.config.credentials?.secret) {
125
- this.switchBotAPI = new SwitchBotOpenAPI(this.config.credentials.token, this.config.credentials.secret, this.config.options?.hostname);
126
- }
127
- else {
128
- this.debugErrorLog('Missing SwitchBot API credentials (token or secret).');
129
- }
130
- // Listen for log events
131
- if (!this.config.options?.disableLogsforOpenAPI && this.switchBotAPI) {
132
- this.switchBotAPI.on('log', (log) => {
133
- switch (log.level) {
134
- case LogLevel.SUCCESS:
135
- this.successLog(log.message);
136
- break;
137
- case LogLevel.DEBUGSUCCESS:
138
- this.debugSuccessLog(log.message);
139
- break;
140
- case LogLevel.WARN:
141
- this.warnLog(log.message);
142
- break;
143
- case LogLevel.DEBUGWARN:
144
- this.debugWarnLog(log.message);
145
- break;
146
- case LogLevel.ERROR:
147
- this.errorLog(log.message);
148
- break;
149
- case LogLevel.DEBUGERROR:
150
- this.debugErrorLog(log.message);
151
- break;
152
- case LogLevel.DEBUG:
153
- this.debugLog(log.message);
154
- break;
155
- case LogLevel.INFO:
156
- default:
157
- this.infoLog(log.message);
158
- }
159
- });
160
- }
161
- else {
162
- this.debugErrorLog(`SwitchBot OpenAPI logs are disabled, enable it by setting disableLogsforOpenAPI to false.`);
163
- this.debugLog(`SwitchBot OpenAPI: ${JSON.stringify(this.switchBotAPI)}, disableLogsforOpenAPI: ${this.config.options?.disableLogsforOpenAPI}`);
164
- }
165
- // import fakegato-history module and EVE characteristics
166
- this.fakegatoAPI = fakegato(api);
167
- this.eve = new EveHomeKitTypes(api);
168
- // When this event is fired it means Homebridge has restored all cached accessories from disk.
169
- // Dynamic Platform plugins should only register new accessories after this event was fired,
170
- // in order to ensure they weren't added to homebridge already. This event can also be used
171
- // to start discovery of new accessories.
172
- this.api.on('didFinishLaunching', async () => {
173
- this.debugLog('Executed didFinishLaunching callback');
174
- // run the method to discover / register your devices as accessories
175
- try {
176
- await this.discoverDevices();
177
- }
178
- catch (e) {
179
- this.errorLog(`Failed to Discover, Error Message: ${e.message ?? e}, Submit Bugs Here: ` + 'https://tinyurl.com/SwitchBotBug');
180
- this.debugErrorLog(`Failed to Discover, Error: ${e.message ?? e}`);
181
- }
182
- });
183
- try {
184
- this.setupMqtt();
185
- }
186
- catch (e) {
187
- this.errorLog(`Setup MQTT, Error Message: ${e.message ?? e}, Submit Bugs Here: ` + 'https://tinyurl.com/SwitchBotBug');
188
- }
189
- try {
190
- this.setupwebhook();
191
- }
192
- catch (e) {
193
- this.errorLog(`Setup Webhook, Error Message: ${e.message ?? e}, Submit Bugs Here: ` + 'https://tinyurl.com/SwitchBotBug');
194
- }
195
- try {
196
- this.setupBlE();
197
- }
198
- catch (e) {
199
- this.errorLog(`Setup Platform BLE, Error Message: ${e.message ?? e}, Submit Bugs Here: ` + 'https://tinyurl.com/SwitchBotBug');
200
- }
201
- }
202
- async setupMqtt() {
203
- if (this.config.options?.mqttURL) {
204
- try {
205
- const { connectAsync } = asyncmqtt;
206
- this.mqttClient = await connectAsync(this.config.options?.mqttURL, this.config.options.mqttOptions || {});
207
- this.debugLog('MQTT connection has been established successfully.');
208
- this.mqttClient.on('error', async (e) => {
209
- this.errorLog(`Failed to publish MQTT messages. ${e.message ?? e}`);
210
- });
211
- if (!this.config.options?.webhookURL) {
212
- // receive webhook events via MQTT
213
- this.infoLog(`Webhook is configured to be received through ${this.config.options.mqttURL}/homebridge-switchbot/webhook.`);
214
- this.mqttClient.subscribe('homebridge-switchbot/webhook/+');
215
- this.mqttClient.on('message', async (topic, message) => {
216
- try {
217
- this.debugLog(`Received Webhook via MQTT: ${topic}=${message}`);
218
- const context = JSON.parse(message.toString());
219
- this.webhookEventHandler[context.deviceMac]?.(context);
220
- }
221
- catch (e) {
222
- this.errorLog(`Failed to handle webhook event. Error: ${e.message ?? e}`);
223
- }
224
- });
225
- }
226
- }
227
- catch (e) {
228
- this.mqttClient = null;
229
- this.errorLog(`Failed to establish MQTT connection. ${e.message ?? e}`);
230
- }
231
- }
232
- }
233
- async setupwebhook() {
234
- // webhook configuration
235
- if (this.config.options?.webhookURL) {
236
- const url = this.config.options?.webhookURL;
237
- try {
238
- this.switchBotAPI.setupWebhook(url);
239
- // Listen for webhook events
240
- this.switchBotAPI.on('webhookEvent', (body) => {
241
- if (this.config.options?.mqttURL) {
242
- const mac = body.context.deviceMac?.toLowerCase().match(/[\s\S]{1,2}/g)?.join(':');
243
- const options = this.config.options?.mqttPubOptions || {};
244
- this.mqttClient?.publish(`homebridge-switchbot/webhook/${mac}`, `${JSON.stringify(body.context)}`, options);
245
- }
246
- this.webhookEventHandler[body.context.deviceMac]?.(body.context);
247
- });
248
- }
249
- catch (e) {
250
- this.errorLog(`Failed to setup webhook. Error: ${e.message ?? e}`);
251
- }
252
- this.api.on('shutdown', async () => {
253
- try {
254
- this.switchBotAPI.deleteWebhook(url);
255
- }
256
- catch (e) {
257
- this.errorLog(`Failed to delete webhook. Error: ${e.message ?? e}`);
258
- }
259
- });
260
- }
261
- }
262
- async setupBlE() {
263
- this.switchBotBLE = new SwitchBotBLE();
264
- // Listen for log events
265
- if (!this.config.options?.disableLogsforBLE) {
266
- this.switchBotBLE.on('log', (log) => {
267
- switch (log.level) {
268
- case LogLevel.SUCCESS:
269
- this.successLog(log.message);
270
- break;
271
- case LogLevel.DEBUGSUCCESS:
272
- this.debugSuccessLog(log.message);
273
- break;
274
- case LogLevel.WARN:
275
- this.warnLog(log.message);
276
- break;
277
- case LogLevel.DEBUGWARN:
278
- this.debugWarnLog(log.message);
279
- break;
280
- case LogLevel.ERROR:
281
- this.errorLog(log.message);
282
- break;
283
- case LogLevel.DEBUGERROR:
284
- this.debugErrorLog(log.message);
285
- break;
286
- case LogLevel.DEBUG:
287
- this.debugLog(log.message);
288
- break;
289
- case LogLevel.INFO:
290
- default:
291
- this.infoLog(log.message);
292
- }
293
- });
294
- }
295
- if (this.config.options?.BLE) {
296
- this.debugLog('setupBLE');
297
- if (this.switchBotBLE === undefined) {
298
- this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${JSON.stringify(this.switchBotBLE)}`);
299
- }
300
- else {
301
- // Start to monitor advertisement packets
302
- (async () => {
303
- // Start to monitor advertisement packets
304
- this.debugLog('Scanning for BLE SwitchBot devices...');
305
- try {
306
- await this.switchBotBLE.startScan();
307
- }
308
- catch (e) {
309
- this.errorLog(`Failed to start BLE scanning. Error: ${e.message ?? e}`);
310
- }
311
- // Set an event handler to monitor advertisement packets
312
- this.switchBotBLE.onadvertisement = async (ad) => {
313
- try {
314
- this.bleEventHandler[ad.address]?.(ad.serviceData);
315
- }
316
- catch (e) {
317
- this.errorLog(`Failed to handle BLE event. Error: ${e.message ?? e}`);
318
- }
319
- };
320
- })();
321
- this.api.on('shutdown', async () => {
322
- try {
323
- // this.switchBotBLE.stopScan()
324
- this.infoLog('Stopped BLE scanning to close listening.');
325
- }
326
- catch (e) {
327
- this.errorLog(`Failed to stop Platform BLE scanning. Error: ${e.message ?? e}`);
328
- }
329
- });
330
- }
331
- }
332
- else {
333
- this.debugLog('Platform BLE is not enabled');
334
- }
335
- }
336
- /**
337
- * This function is invoked when homebridge restores cached accessories from disk at startup.
338
- * It should be used to setup event handlers for characteristics and update respective values.
339
- */
340
- async configureAccessory(accessory) {
341
- const { displayName } = accessory;
342
- this.debugLog(`Loading accessory from cache: ${displayName}`);
343
- // add the restored accessory to the accessories cache so we can track if it has already been registered
344
- this.accessories.push(accessory);
345
- }
346
- /**
347
- * Verify the config passed to the plugin is valid
348
- */
349
- async verifyConfig() {
350
- this.debugLog('Verifying Config');
351
- this.config = this.config || {};
352
- this.config.options = this.config.options || {};
353
- if (this.config.options) {
354
- // Device Config
355
- if (this.config.options.devices) {
356
- for (const deviceConfig of this.config.options.devices) {
357
- if (!deviceConfig.hide_device) {
358
- if (!deviceConfig.deviceId) {
359
- this.errorLog('The devices config section is missing the *Device ID* in the config. Please check your config.');
360
- }
361
- if (!deviceConfig.configDeviceType && deviceConfig.connectionType) {
362
- this.errorLog('The devices config section is missing the *Device Type* in the config. Please check your config.');
363
- }
364
- }
365
- }
366
- }
367
- // IR Device Config
368
- if (this.config.options.irdevices) {
369
- for (const irDeviceConfig of this.config.options.irdevices) {
370
- if (!irDeviceConfig.hide_device) {
371
- if (!irDeviceConfig.deviceId) {
372
- this.errorLog('The devices config section is missing the *Device ID* in the config. Please check your config.');
373
- }
374
- if (!irDeviceConfig.deviceId && !irDeviceConfig.configRemoteType) {
375
- this.errorLog('The devices config section is missing the *Device Type* in the config. Please check your config.');
376
- }
377
- }
378
- }
379
- }
380
- }
381
- if (!this.config.credentials && !this.config.options) {
382
- this.debugWarnLog('Missing Credentials');
383
- }
384
- else if (this.config.credentials && !this.config.credentials.notice) {
385
- if (!this.config.credentials?.token) {
386
- this.debugErrorLog('Missing token');
387
- this.debugWarnLog('Cloud Enabled SwitchBot Devices & IR Devices will not work');
388
- }
389
- if (this.config.credentials?.token) {
390
- if (!this.config.credentials?.secret) {
391
- this.debugErrorLog('Missing secret');
392
- this.debugWarnLog('Cloud Enabled SwitchBot Devices & IR Devices will not work');
393
- }
394
- }
395
- }
396
- }
397
- async discoverDevices() {
398
- if (!this.config.credentials?.token) {
399
- return this.handleManualConfig();
400
- }
401
- let retryCount = 0;
402
- const maxRetries = this.platformMaxRetries ?? 5;
403
- const delayBetweenRetries = this.platformDelayBetweenRetries || 5000;
404
- this.debugWarnLog(`Retry Count: ${retryCount}`);
405
- this.debugWarnLog(`Max Retries: ${this.platformMaxRetries}`);
406
- this.debugWarnLog(`Delay Between Retries: ${this.platformDelayBetweenRetries}`);
407
- while (retryCount < maxRetries) {
408
- try {
409
- const { response, statusCode } = await this.switchBotAPI.getDevices();
410
- this.debugLog(`response: ${JSON.stringify(response)}`);
411
- if (this.isSuccessfulResponse(statusCode)) {
412
- await this.handleDevices(Array.isArray(response.body.deviceList) ? response.body.deviceList : []);
413
- await this.handleIRDevices(Array.isArray(response.body.infraredRemoteList) ? response.body.infraredRemoteList : []);
414
- break;
415
- }
416
- else {
417
- await this.handleErrorResponse(statusCode, retryCount, maxRetries, delayBetweenRetries);
418
- retryCount++;
419
- }
420
- }
421
- catch (e) {
422
- retryCount++;
423
- this.debugErrorLog(`Failed to Discover Devices, Error Message: ${JSON.stringify(e.message)}, Submit Bugs Here: https://tinyurl.com/SwitchBotBug`);
424
- this.debugErrorLog(`Failed to Discover Devices, Error: ${e.message ?? e}`);
425
- }
426
- }
427
- }
428
- async handleManualConfig() {
429
- if (this.config.options?.devices) {
430
- this.debugLog(`SwitchBot Device Manual Config Set: ${JSON.stringify(this.config.options?.devices)}`);
431
- const devices = this.config.options.devices.map((v) => v);
432
- for (const device of devices) {
433
- device.deviceType = device.configDeviceType !== undefined ? device.configDeviceType : 'Unknown';
434
- device.deviceName = device.configDeviceName !== undefined ? device.configDeviceName : 'Unknown';
435
- try {
436
- device.deviceId = formatDeviceIdAsMac(device.deviceId, true);
437
- this.debugLog(`deviceId: ${device.deviceId}`);
438
- if (device.deviceType) {
439
- await this.createDevice(device);
440
- }
441
- }
442
- catch (error) {
443
- this.errorLog(`failed to format device ID as MAC, Error: ${error}`);
444
- }
445
- }
446
- }
447
- else {
448
- this.errorLog('Neither SwitchBot Token or Device Config are set.');
449
- }
450
- }
451
- isSuccessfulResponse(apiStatusCode) {
452
- return (apiStatusCode === 200 || apiStatusCode === 100);
453
- }
454
- async handleDevices(deviceLists) {
455
- if (!this.config.options?.devices && !this.config.options?.deviceConfig) {
456
- this.debugLog(`SwitchBot Device Config Not Set: ${JSON.stringify(this.config.options?.devices)}`);
457
- if (deviceLists.length === 0) {
458
- this.debugLog('SwitchBot API Has No Devices With Cloud Services Enabled');
459
- }
460
- else {
461
- for (const device of deviceLists) {
462
- if (device.deviceType) {
463
- if (device.configDeviceName) {
464
- device.deviceName = device.configDeviceName;
465
- }
466
- await this.createDevice(device);
467
- }
468
- }
469
- }
470
- }
471
- else if (this.config.options?.devices || this.config.options?.deviceConfig) {
472
- this.debugLog(`SwitchBot Device Config Set: ${JSON.stringify(this.config.options?.devices)}`);
473
- // Step 1: Check and assign configDeviceType to deviceType if deviceType is not present
474
- const devicesWithTypeConfigPromises = deviceLists.map(async (device) => {
475
- if (!device.deviceType) {
476
- device.deviceType = device.configDeviceType !== undefined ? device.configDeviceType : 'Unknown';
477
- this.warnLog(`API is displaying no deviceType: ${device.deviceType}, So using configDeviceType: ${device.configDeviceType}`);
478
- }
479
- // Retrieve deviceTypeConfig for each device and merge it
480
- const deviceTypeConfig = this.config.options?.deviceConfig?.[device.deviceType] || {};
481
- return Object.assign({}, device, deviceTypeConfig);
482
- });
483
- // Wait for all promises to resolve
484
- const devicesWithTypeConfig = (await Promise.all(devicesWithTypeConfigPromises)).filter(device => device !== null); // Filter out skipped devices
485
- const devices = this.mergeByDeviceId(this.config.options.devices ?? [], devicesWithTypeConfig ?? []);
486
- this.debugLog(`SwitchBot Devices: ${JSON.stringify(devices)}`);
487
- for (const device of devices) {
488
- const deviceIdConfig = this.config.options?.devices?.[device.deviceId] || {};
489
- const deviceWithConfig = Object.assign({}, device, deviceIdConfig);
490
- if (device.configDeviceName) {
491
- device.deviceName = device.configDeviceName;
492
- }
493
- // Pass the merged device object to createDevice
494
- await this.createDevice(deviceWithConfig);
495
- }
496
- }
497
- }
498
- async handleIRDevices(irDeviceLists) {
499
- if (!this.config.options?.irdevices && !this.config.options?.irdeviceConfig) {
500
- this.debugLog(`IR Device Config Not Set: ${JSON.stringify(this.config.options?.irdevices)}`);
501
- for (const device of irDeviceLists) {
502
- if (device.remoteType) {
503
- await this.createIRDevice(device);
504
- }
505
- }
506
- }
507
- else if (this.config.options?.irdevices || this.config.options?.irdeviceConfig) {
508
- this.debugLog(`IR Device Config Set: ${JSON.stringify(this.config.options?.irdevices)}`);
509
- // Step 1: Check and assign configRemoteType to remoteType if remoteType is not present
510
- const devicesWithTypeConfigPromises = irDeviceLists.map(async (device) => {
511
- if (!device.remoteType && device.configRemoteType) {
512
- device.remoteType = device.configRemoteType;
513
- this.warnLog(`API is displaying no remoteType: ${device.remoteType}, So using configRemoteType: ${device.configRemoteType}`);
514
- }
515
- else if (!device.remoteType && !device.configDeviceName) {
516
- this.errorLog('No remoteType or configRemoteType for device. No device will be created.');
517
- return null; // Skip this device
518
- }
519
- // Retrieve remoteTypeConfig for each device and merge it
520
- const remoteTypeConfig = this.config.options?.irdeviceConfig?.[device.remoteType] || {};
521
- return Object.assign({}, device, remoteTypeConfig);
522
- });
523
- // Wait for all promises to resolve
524
- const devicesWithRemoteTypeConfig = (await Promise.all(devicesWithTypeConfigPromises)).filter(device => device !== null); // Filter out skipped devices
525
- const devices = this.mergeByDeviceId(this.config.options.irdevices ?? [], devicesWithRemoteTypeConfig ?? []);
526
- this.debugLog(`IR Devices: ${JSON.stringify(devices)}`);
527
- for (const device of devices) {
528
- const irdeviceIdConfig = this.config.options?.irdevices?.[device.deviceId] || {};
529
- const irdeviceWithConfig = Object.assign({}, device, irdeviceIdConfig);
530
- if (device.configDeviceName) {
531
- device.deviceName = device.configDeviceName;
532
- }
533
- await this.createIRDevice(irdeviceWithConfig);
534
- }
535
- }
536
- }
537
- mergeByDeviceId(a1, a2) {
538
- const normalizeDeviceId = (deviceId) => deviceId.toUpperCase().replace(/[^A-Z0-9]+/g, '');
539
- return a1.map((itm) => {
540
- const matchingItem = a2.find(item => normalizeDeviceId(item.deviceId) === normalizeDeviceId(itm.deviceId));
541
- return { ...matchingItem, ...itm };
542
- });
543
- }
544
- async handleErrorResponse(apiStatusCode, retryCount, maxRetries, delayBetweenRetries) {
545
- await this.statusCode(apiStatusCode);
546
- if (apiStatusCode === 500) {
547
- this.infoLog(`statusCode: ${apiStatusCode} Attempt ${retryCount + 1} of ${maxRetries}`);
548
- await sleep(delayBetweenRetries);
549
- }
550
- }
551
- async createDevice(device) {
552
- const deviceTypeHandlers = {
553
- 'Humidifier': this.createHumidifier.bind(this),
554
- 'Humidifier2': this.createHumidifier.bind(this),
555
- 'Hub 2': this.createHub2.bind(this),
556
- 'Hub 3': this.createHub2.bind(this),
557
- 'Bot': this.createBot.bind(this),
558
- 'Relay Switch 1': this.createRelaySwitch.bind(this),
559
- 'Relay Switch 1PM': this.createRelaySwitch.bind(this),
560
- 'Meter': this.createMeter.bind(this),
561
- 'MeterPlus': this.createMeterPlus.bind(this),
562
- 'Meter Plus (JP)': this.createMeterPlus.bind(this),
563
- 'MeterPro': this.createMeterPro.bind(this),
564
- 'MeterPro(CO2)': this.createMeterPro.bind(this),
565
- 'WoIOSensor': this.createIOSensor.bind(this),
566
- 'Water Detector': this.createWaterDetector.bind(this),
567
- 'Motion Sensor': this.createMotion.bind(this),
568
- 'Contact Sensor': this.createContact.bind(this),
569
- 'Curtain': this.createCurtain.bind(this),
570
- 'Curtain3': this.createCurtain.bind(this),
571
- 'WoRollerShade': this.createCurtain.bind(this),
572
- 'Roller Shade': this.createCurtain.bind(this),
573
- 'Blind Tilt': this.createBlindTilt.bind(this),
574
- 'Plug': this.createPlug.bind(this),
575
- 'Plug Mini (US)': this.createPlug.bind(this),
576
- 'Plug Mini (JP)': this.createPlug.bind(this),
577
- 'Smart Lock': this.createLock.bind(this),
578
- 'Smart Lock Pro': this.createLock.bind(this),
579
- 'Color Bulb': this.createColorBulb.bind(this),
580
- 'K10+': this.createRobotVacuumCleaner.bind(this),
581
- 'K10+ Pro': this.createRobotVacuumCleaner.bind(this),
582
- 'WoSweeper': this.createRobotVacuumCleaner.bind(this),
583
- 'WoSweeperMini': this.createRobotVacuumCleaner.bind(this),
584
- 'Robot Vacuum Cleaner S1': this.createRobotVacuumCleaner.bind(this),
585
- 'Robot Vacuum Cleaner S1 Plus': this.createRobotVacuumCleaner.bind(this),
586
- 'Robot Vacuum Cleaner S10': this.createRobotVacuumCleaner.bind(this),
587
- 'Ceiling Light': this.createCeilingLight.bind(this),
588
- 'Ceiling Light Pro': this.createCeilingLight.bind(this),
589
- 'Strip Light': this.createStripLight.bind(this),
590
- 'Battery Circulator Fan': this.createFan.bind(this),
591
- 'Air Purifier PM2.5': this.createAirPurifier.bind(this),
592
- 'Air Purifier Table PM2.5': this.createAirPurifier.bind(this),
593
- 'Air Purifier VOC': this.createAirPurifier.bind(this),
594
- 'Air Purifier Table VOC': this.createAirPurifier.bind(this),
595
- };
596
- if (deviceTypeHandlers[device.deviceType]) {
597
- this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId}`);
598
- await deviceTypeHandlers[device.deviceType](device);
599
- }
600
- else if (['Hub Mini', 'Hub Plus', 'Remote', 'Indoor Cam', 'remote with screen'].includes(device.deviceType)) {
601
- this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId}, is currently not supported, device: ${JSON.stringify(device)}`);
602
- }
603
- else {
604
- this.warnLog(`Device: ${device.deviceName} with Device Type: ${device.deviceType}, is currently not supported. Submit Feature Requests Here: https://tinyurl.com/SwitchBotFeatureRequest, device: ${JSON.stringify(device)}`);
605
- }
606
- }
607
- async createIRDevice(device) {
608
- device.connectionType = device.connectionType ?? 'OpenAPI';
609
- const deviceTypeHandlers = {
610
- 'TV': this.createTV.bind(this),
611
- 'DIY TV': this.createTV.bind(this),
612
- 'Projector': this.createTV.bind(this),
613
- 'DIY Projector': this.createTV.bind(this),
614
- 'Set Top Box': this.createTV.bind(this),
615
- 'DIY Set Top Box': this.createTV.bind(this),
616
- 'IPTV': this.createTV.bind(this),
617
- 'DIY IPTV': this.createTV.bind(this),
618
- 'DVD': this.createTV.bind(this),
619
- 'DIY DVD': this.createTV.bind(this),
620
- 'Speaker': this.createTV.bind(this),
621
- 'DIY Speaker': this.createTV.bind(this),
622
- 'Fan': this.createIRFan.bind(this),
623
- 'DIY Fan': this.createIRFan.bind(this),
624
- 'Air Conditioner': this.createAirConditioner.bind(this),
625
- 'DIY Air Conditioner': this.createAirConditioner.bind(this),
626
- 'Light': this.createLight.bind(this),
627
- 'DIY Light': this.createLight.bind(this),
628
- 'Air Purifier': this.createAirPurifierIR.bind(this),
629
- 'DIY Air Purifier': this.createAirPurifierIR.bind(this),
630
- 'Water Heater': this.createWaterHeater.bind(this),
631
- 'DIY Water Heater': this.createWaterHeater.bind(this),
632
- 'Vacuum Cleaner': this.createVacuumCleaner.bind(this),
633
- 'DIY Vacuum Cleaner': this.createVacuumCleaner.bind(this),
634
- 'Camera': this.createCamera.bind(this),
635
- 'DIY Camera': this.createCamera.bind(this),
636
- 'Others': this.createOthers.bind(this),
637
- };
638
- if (deviceTypeHandlers[device.remoteType]) {
639
- this.debugLog(`Discovered ${device.remoteType}: ${device.deviceId}`);
640
- if (device.remoteType.startsWith('DIY') && device.external === undefined) {
641
- device.external = true;
642
- }
643
- await deviceTypeHandlers[device.remoteType](device);
644
- }
645
- else {
646
- this.warnLog(`Device: ${device.deviceName} with Device Type: ${device.remoteType}, is currently not supported. Submit Feature Requests Here: https://tinyurl.com/SwitchBotFeatureRequest, device: ${JSON.stringify(device)}`);
647
- }
648
- }
649
- async createHumidifier(device) {
650
- const uuid = this.api.hap.uuid.generate(`${device.deviceId}-${device.deviceType}`);
651
- // see if an accessory with the same uuid has already been registered and restored from
652
- // the cached devices we stored in the `configureAccessory` method above
653
- const existingAccessory = this.accessories.find(accessory => accessory.UUID === uuid);
654
- if (existingAccessory) {
655
- // the accessory already exists
656
- if (await this.registerDevice(device)) {
657
- // if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
658
- existingAccessory.context.device = device;
659
- existingAccessory.context.deviceId = device.deviceId;
660
- existingAccessory.context.deviceType = device.deviceType;
661
- existingAccessory.context.model = device.deviceType === 'Humidifier2' ? SwitchBotModel.Humidifier2 : SwitchBotModel.Humidifier;
662
- existingAccessory.displayName = device.configDeviceName
663
- ? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
664
- : await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName);
665
- existingAccessory.context.connectionType = await this.connectionType(device);
666
- existingAccessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
667
- this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`);
668
- this.api.updatePlatformAccessories([existingAccessory]);
669
- // create the accessory handler for the restored accessory
670
- // this is imported from `platformAccessory.ts`
671
- new Humidifier(this, existingAccessory, device);
672
- this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${existingAccessory.UUID})`);
673
- }
674
- else {
675
- this.unregisterPlatformAccessories(existingAccessory);
676
- }
677
- }
678
- else if (await this.registerDevice(device)) {
679
- // create a new accessory
680
- const accessory = new this.api.platformAccessory(device.configDeviceName
681
- ? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
682
- : await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName), uuid);
683
- // store a copy of the device object in the `accessory.context`
684
- // the `context` property can be used to store any data about the accessory you may need
685
- accessory.context.device = device;
686
- accessory.context.deviceId = device.deviceId;
687
- accessory.context.deviceType = device.deviceType;
688
- accessory.context.model = device.deviceType === 'Humidifier2' ? SwitchBotModel.Humidifier2 : SwitchBotModel.Humidifier;
689
- accessory.displayName = device.configDeviceName
690
- ? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
691
- : await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName);
692
- accessory.context.connectionType = await this.connectionType(device);
693
- accessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
694
- const newOrExternal = !device.external ? 'Adding new' : 'Loading external';
695
- this.infoLog(`${newOrExternal} accessory: ${accessory.displayName} deviceId: ${device.deviceId}`);
696
- // create the accessory handler for the newly create accessory
697
- // this is imported from `platformAccessory.ts`
698
- new Humidifier(this, accessory, device);
699
- this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`);
700
- // publish device externally or link the accessory to your platform
701
- this.externalOrPlatform(device, accessory);
702
- this.accessories.push(accessory);
703
- }
704
- else {
705
- this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} deviceId: ${device.deviceId}`);
706
- }
707
- }
708
- async createBot(device) {
709
- const uuid = this.api.hap.uuid.generate(`${device.deviceId}-${device.deviceType}`);
710
- // see if an accessory with the same uuid has already been registered and restored from
711
- // the cached devices we stored in the `configureAccessory` method above
712
- const existingAccessory = this.accessories.find(accessory => accessory.UUID === uuid);
713
- if (existingAccessory) {
714
- // the accessory already exists
715
- if (await this.registerDevice(device)) {
716
- // if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
717
- existingAccessory.context.device = device;
718
- existingAccessory.context.deviceId = device.deviceId;
719
- existingAccessory.context.deviceType = device.deviceType;
720
- existingAccessory.context.model = SwitchBotModel.Bot;
721
- existingAccessory.displayName = device.configDeviceName
722
- ? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
723
- : await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName);
724
- existingAccessory.context.connectionType = await this.connectionType(device);
725
- existingAccessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
726
- this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`);
727
- this.api.updatePlatformAccessories([existingAccessory]);
728
- // create the accessory handler for the restored accessory
729
- // this is imported from `platformAccessory.ts`
730
- new Bot(this, existingAccessory, device);
731
- this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${existingAccessory.UUID})`);
732
- }
733
- else {
734
- this.unregisterPlatformAccessories(existingAccessory);
735
- }
736
- }
737
- else if (await this.registerDevice(device)) {
738
- // create a new accessory
739
- const accessory = new this.api.platformAccessory(device.configDeviceName
740
- ? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
741
- : await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName), uuid);
742
- // store a copy of the device object in the `accessory.context`
743
- // the `context` property can be used to store any data about the accessory you may need
744
- accessory.context.device = device;
745
- accessory.context.deviceId = device.deviceId;
746
- accessory.context.deviceType = device.deviceType;
747
- accessory.context.model = SwitchBotModel.Bot;
748
- accessory.displayName = device.configDeviceName
749
- ? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
750
- : await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName);
751
- accessory.context.connectionType = await this.connectionType(device);
752
- accessory.context.connectionType = await this.connectionType(device);
753
- accessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
754
- const newOrExternal = !device.external ? 'Adding new' : 'Loading external';
755
- this.infoLog(`${newOrExternal} accessory: ${accessory.displayName} deviceId: ${device.deviceId}`);
756
- // accessory.context.version = findaccessories.accessoryAttribute.softwareRevision;
757
- // create the accessory handler for the newly create accessory
758
- // this is imported from `platformAccessory.ts`
759
- new Bot(this, accessory, device);
760
- this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`);
761
- // publish device externally or link the accessory to your platform
762
- this.externalOrPlatform(device, accessory);
763
- this.accessories.push(accessory);
764
- }
765
- else {
766
- this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} deviceId: ${device.deviceId}`);
767
- }
768
- }
769
- async createRelaySwitch(device) {
770
- const uuid = this.api.hap.uuid.generate(`${device.deviceId}-${device.deviceType}`);
771
- // see if an accessory with the same uuid has already been registered and restored from
772
- // the cached devices we stored in the `configureAccessory` method above
773
- const existingAccessory = this.accessories.find(accessory => accessory.UUID === uuid);
774
- if (existingAccessory) {
775
- // the accessory already exists
776
- if (await this.registerDevice(device)) {
777
- // if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
778
- existingAccessory.context.device = device;
779
- existingAccessory.context.deviceId = device.deviceId;
780
- existingAccessory.context.deviceType = device.deviceType;
781
- existingAccessory.context.model = device.deviceType === 'Relay Switch 1' ? SwitchBotModel.RelaySwitch1 : SwitchBotModel.RelaySwitch1PM;
782
- existingAccessory.displayName = device.configDeviceName
783
- ? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
784
- : await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName);
785
- existingAccessory.context.connectionType = await this.connectionType(device);
786
- existingAccessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
787
- this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`);
788
- this.api.updatePlatformAccessories([existingAccessory]);
789
- // create the accessory handler for the restored accessory
790
- // this is imported from `platformAccessory.ts`
791
- new RelaySwitch(this, existingAccessory, device);
792
- this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${existingAccessory.UUID})`);
793
- }
794
- else {
795
- this.unregisterPlatformAccessories(existingAccessory);
796
- }
797
- }
798
- else if (await this.registerDevice(device)) {
799
- // create a new accessory
800
- const accessory = new this.api.platformAccessory(device.configDeviceName
801
- ? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
802
- : await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName), uuid);
803
- // store a copy of the device object in the `accessory.context`
804
- // the `context` property can be used to store any data about the accessory you may need
805
- accessory.context.device = device;
806
- accessory.context.deviceId = device.deviceId;
807
- accessory.context.deviceType = device.deviceType;
808
- accessory.context.model = device.deviceType === 'Relay Switch 1' ? SwitchBotModel.RelaySwitch1 : SwitchBotModel.RelaySwitch1PM;
809
- accessory.displayName = device.configDeviceName
810
- ? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
811
- : await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName);
812
- accessory.context.connectionType = await this.connectionType(device);
813
- accessory.context.connectionType = await this.connectionType(device);
814
- accessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
815
- const newOrExternal = !device.external ? 'Adding new' : 'Loading external';
816
- this.infoLog(`${newOrExternal} accessory: ${accessory.displayName} deviceId: ${device.deviceId}`);
817
- // accessory.context.version = findaccessories.accessoryAttribute.softwareRevision;
818
- // create the accessory handler for the newly create accessory
819
- // this is imported from `platformAccessory.ts`
820
- new RelaySwitch(this, accessory, device);
821
- this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`);
822
- // publish device externally or link the accessory to your platform
823
- this.externalOrPlatform(device, accessory);
824
- this.accessories.push(accessory);
825
- }
826
- else {
827
- this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} deviceId: ${device.deviceId}`);
828
- }
829
- }
830
- async createMeter(device) {
831
- const uuid = this.api.hap.uuid.generate(`${device.deviceId}-${device.deviceType}`);
832
- // see if an accessory with the same uuid has already been registered and restored from
833
- // the cached devices we stored in the `configureAccessory` method above
834
- const existingAccessory = this.accessories.find(accessory => accessory.UUID === uuid);
835
- if (existingAccessory) {
836
- // the accessory already exists
837
- if (await this.registerDevice(device)) {
838
- // if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
839
- existingAccessory.context.device = device;
840
- existingAccessory.context.model = SwitchBotModel.Meter;
841
- existingAccessory.context.deviceId = device.deviceId;
842
- existingAccessory.context.deviceType = device.deviceType;
843
- existingAccessory.displayName = device.configDeviceName
844
- ? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
845
- : await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName);
846
- existingAccessory.context.connectionType = await this.connectionType(device);
847
- existingAccessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
848
- this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`);
849
- this.api.updatePlatformAccessories([existingAccessory]);
850
- // create the accessory handler for the restored accessory
851
- // this is imported from `platformAccessory.ts`
852
- new Meter(this, existingAccessory, device);
853
- this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${existingAccessory.UUID})`);
854
- }
855
- else {
856
- this.unregisterPlatformAccessories(existingAccessory);
857
- }
858
- }
859
- else if (await this.registerDevice(device)) {
860
- // create a new accessory
861
- const accessory = new this.api.platformAccessory(device.configDeviceName
862
- ? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
863
- : await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName), uuid);
864
- // store a copy of the device object in the `accessory.context`
865
- // the `context` property can be used to store any data about the accessory you may need
866
- accessory.context.device = device;
867
- accessory.context.model = SwitchBotModel.Meter;
868
- accessory.context.deviceId = device.deviceId;
869
- accessory.context.deviceType = device.deviceType;
870
- accessory.displayName = device.configDeviceName
871
- ? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
872
- : await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName);
873
- accessory.context.connectionType = await this.connectionType(device);
874
- accessory.context.connectionType = await this.connectionType(device);
875
- accessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
876
- const newOrExternal = !device.external ? 'Adding new' : 'Loading external';
877
- this.infoLog(`${newOrExternal} accessory: ${accessory.displayName} deviceId: ${device.deviceId}`);
878
- // create the accessory handler for the newly create accessory
879
- // this is imported from `platformAccessory.ts`
880
- new Meter(this, accessory, device);
881
- this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`);
882
- // publish device externally or link the accessory to your platform
883
- this.externalOrPlatform(device, accessory);
884
- this.accessories.push(accessory);
885
- }
886
- else {
887
- this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} deviceId: ${device.deviceId}`);
888
- }
889
- }
890
- async createMeterPlus(device) {
891
- const uuid = this.api.hap.uuid.generate(`${device.deviceId}-${device.deviceType}`);
892
- // see if an accessory with the same uuid has already been registered and restored from
893
- // the cached devices we stored in the `configureAccessory` method above
894
- const existingAccessory = this.accessories.find(accessory => accessory.UUID === uuid);
895
- if (existingAccessory) {
896
- // the accessory already exists
897
- if (await this.registerDevice(device)) {
898
- // console.log("existingAccessory", existingAccessory);
899
- // if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
900
- existingAccessory.context.device = device;
901
- existingAccessory.context.model = SwitchBotModel.MeterPlusUS ?? SwitchBotModel.MeterPlusJP;
902
- existingAccessory.context.deviceId = device.deviceId;
903
- existingAccessory.context.deviceType = device.deviceType;
904
- existingAccessory.displayName = device.configDeviceName
905
- ? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
906
- : await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName);
907
- existingAccessory.context.connectionType = await this.connectionType(device);
908
- existingAccessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
909
- this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`);
910
- this.api.updatePlatformAccessories([existingAccessory]);
911
- // create the accessory handler for the restored accessory
912
- // this is imported from `platformAccessory.ts`
913
- new MeterPlus(this, existingAccessory, device);
914
- this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${existingAccessory.UUID})`);
915
- }
916
- else {
917
- this.unregisterPlatformAccessories(existingAccessory);
918
- }
919
- }
920
- else if (await this.registerDevice(device)) {
921
- // create a new accessory
922
- const accessory = new this.api.platformAccessory(device.configDeviceName
923
- ? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
924
- : await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName), uuid);
925
- // store a copy of the device object in the `accessory.context`
926
- // the `context` property can be used to store any data about the accessory you may need
927
- accessory.context.device = device;
928
- accessory.context.model = SwitchBotModel.MeterPlusUS ?? SwitchBotModel.MeterPlusJP;
929
- accessory.context.deviceId = device.deviceId;
930
- accessory.context.deviceType = device.deviceType;
931
- accessory.displayName = device.configDeviceName
932
- ? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
933
- : await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName);
934
- accessory.context.connectionType = await this.connectionType(device);
935
- accessory.context.connectionType = await this.connectionType(device);
936
- accessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
937
- const newOrExternal = !device.external ? 'Adding new' : 'Loading external';
938
- this.infoLog(`${newOrExternal} accessory: ${accessory.displayName} deviceId: ${device.deviceId}`);
939
- // create the accessory handler for the newly create accessory
940
- // this is imported from `platformAccessory.ts`
941
- new MeterPlus(this, accessory, device);
942
- this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`);
943
- // publish device externally or link the accessory to your platform
944
- this.externalOrPlatform(device, accessory);
945
- this.accessories.push(accessory);
946
- }
947
- else {
948
- this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} deviceId: ${device.deviceId}`);
949
- }
950
- }
951
- async createMeterPro(device) {
952
- const uuid = this.api.hap.uuid.generate(`${device.deviceId}-${device.deviceType}`);
953
- // see if an accessory with the same uuid has already been registered and restored from
954
- // the cached devices we stored in the `configureAccessory` method above
955
- const existingAccessory = this.accessories.find(accessory => accessory.UUID === uuid);
956
- if (existingAccessory) {
957
- // the accessory already exists
958
- if (await this.registerDevice(device)) {
959
- // console.log("existingAccessory", existingAccessory);
960
- // if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
961
- existingAccessory.context.device = device;
962
- existingAccessory.context.model = SwitchBotModel.MeterPro ?? SwitchBotModel.MeterProCO2;
963
- existingAccessory.context.deviceId = device.deviceId;
964
- existingAccessory.context.deviceType = device.deviceType;
965
- existingAccessory.displayName = device.configDeviceName
966
- ? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
967
- : await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName);
968
- existingAccessory.context.connectionType = await this.connectionType(device);
969
- existingAccessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
970
- this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`);
971
- this.api.updatePlatformAccessories([existingAccessory]);
972
- // create the accessory handler for the restored accessory
973
- // this is imported from `platformAccessory.ts`
974
- new MeterPro(this, existingAccessory, device);
975
- this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${existingAccessory.UUID})`);
976
- }
977
- else {
978
- this.unregisterPlatformAccessories(existingAccessory);
979
- }
980
- }
981
- else if (await this.registerDevice(device)) {
982
- // create a new accessory
983
- const accessory = new this.api.platformAccessory(device.configDeviceName
984
- ? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
985
- : await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName), uuid);
986
- // store a copy of the device object in the `accessory.context`
987
- // the `context` property can be used to store any data about the accessory you may need
988
- accessory.context.device = device;
989
- accessory.context.model = SwitchBotModel.MeterPro ?? SwitchBotModel.MeterProCO2;
990
- accessory.context.deviceId = device.deviceId;
991
- accessory.context.deviceType = device.deviceType;
992
- accessory.displayName = device.configDeviceName
993
- ? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
994
- : await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName);
995
- accessory.context.connectionType = await this.connectionType(device);
996
- accessory.context.connectionType = await this.connectionType(device);
997
- accessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
998
- const newOrExternal = !device.external ? 'Adding new' : 'Loading external';
999
- this.infoLog(`${newOrExternal} accessory: ${accessory.displayName} deviceId: ${device.deviceId}`);
1000
- // create the accessory handler for the newly create accessory
1001
- // this is imported from `platformAccessory.ts`
1002
- new MeterPro(this, accessory, device);
1003
- this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`);
1004
- // publish device externally or link the accessory to your platform
1005
- this.externalOrPlatform(device, accessory);
1006
- this.accessories.push(accessory);
1007
- }
1008
- else {
1009
- this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} deviceId: ${device.deviceId}`);
1010
- }
1011
- }
1012
- async createHub2(device) {
1013
- const uuid = this.api.hap.uuid.generate(`${device.deviceId}-${device.deviceType}`);
1014
- // see if an accessory with the same uuid has already been registered and restored from
1015
- // the cached devices we stored in the `configureAccessory` method above
1016
- const existingAccessory = this.accessories.find(accessory => accessory.UUID === uuid);
1017
- if (existingAccessory) {
1018
- // the accessory already exists
1019
- if (await this.registerDevice(device)) {
1020
- // console.log("existingAccessory", existingAccessory);
1021
- // if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
1022
- existingAccessory.context.device = device;
1023
- existingAccessory.context.model = SwitchBotModel.Hub2;
1024
- existingAccessory.context.deviceId = device.deviceId;
1025
- existingAccessory.context.deviceType = device.deviceType;
1026
- existingAccessory.displayName = device.configDeviceName
1027
- ? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
1028
- : await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName);
1029
- existingAccessory.context.connectionType = await this.connectionType(device);
1030
- existingAccessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
1031
- this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`);
1032
- this.api.updatePlatformAccessories([existingAccessory]);
1033
- // create the accessory handler for the restored accessory
1034
- // this is imported from `platformAccessory.ts`
1035
- new Hub(this, existingAccessory, device);
1036
- this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${existingAccessory.UUID})`);
1037
- }
1038
- else {
1039
- this.unregisterPlatformAccessories(existingAccessory);
1040
- }
1041
- }
1042
- else if (await this.registerDevice(device)) {
1043
- // create a new accessory
1044
- const accessory = new this.api.platformAccessory(device.configDeviceName
1045
- ? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
1046
- : await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName), uuid);
1047
- // store a copy of the device object in the `accessory.context`
1048
- // the `context` property can be used to store any data about the accessory you may need
1049
- accessory.context.device = device;
1050
- accessory.context.model = SwitchBotModel.Hub2;
1051
- accessory.context.deviceId = device.deviceId;
1052
- accessory.context.deviceType = device.deviceType;
1053
- accessory.displayName = device.configDeviceName
1054
- ? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
1055
- : await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName);
1056
- accessory.context.connectionType = await this.connectionType(device);
1057
- accessory.context.connectionType = await this.connectionType(device);
1058
- accessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
1059
- const newOrExternal = !device.external ? 'Adding new' : 'Loading external';
1060
- this.infoLog(`${newOrExternal} accessory: ${accessory.displayName} deviceId: ${device.deviceId}`);
1061
- // create the accessory handler for the newly create accessory
1062
- // this is imported from `platformAccessory.ts`
1063
- new Hub(this, accessory, device);
1064
- this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`);
1065
- // publish device externally or link the accessory to your platform
1066
- this.externalOrPlatform(device, accessory);
1067
- this.accessories.push(accessory);
1068
- }
1069
- else {
1070
- this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} deviceId: ${device.deviceId}`);
1071
- }
1072
- }
1073
- async createIOSensor(device) {
1074
- const uuid = this.api.hap.uuid.generate(`${device.deviceId}-${device.deviceType}`);
1075
- // see if an accessory with the same uuid has already been registered and restored from
1076
- // the cached devices we stored in the `configureAccessory` method above
1077
- const existingAccessory = this.accessories.find(accessory => accessory.UUID === uuid);
1078
- if (existingAccessory) {
1079
- // the accessory already exists
1080
- if (await this.registerDevice(device)) {
1081
- // if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
1082
- existingAccessory.context.device = device;
1083
- existingAccessory.context.model = SwitchBotModel.OutdoorMeter;
1084
- existingAccessory.context.deviceId = device.deviceId;
1085
- existingAccessory.context.deviceType = device.deviceType;
1086
- existingAccessory.displayName = device.configDeviceName
1087
- ? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
1088
- : await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName);
1089
- existingAccessory.context.connectionType = await this.connectionType(device);
1090
- existingAccessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
1091
- this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`);
1092
- this.api.updatePlatformAccessories([existingAccessory]);
1093
- // create the accessory handler for the restored accessory
1094
- // this is imported from `platformAccessory.ts`
1095
- new IOSensor(this, existingAccessory, device);
1096
- this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${existingAccessory.UUID})`);
1097
- }
1098
- else {
1099
- this.unregisterPlatformAccessories(existingAccessory);
1100
- }
1101
- }
1102
- else if (await this.registerDevice(device)) {
1103
- // create a new accessory
1104
- const accessory = new this.api.platformAccessory(device.configDeviceName
1105
- ? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
1106
- : await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName), uuid);
1107
- // store a copy of the device object in the `accessory.context`
1108
- // the `context` property can be used to store any data about the accessory you may need
1109
- accessory.context.device = device;
1110
- accessory.context.model = SwitchBotModel.OutdoorMeter;
1111
- accessory.context.deviceId = device.deviceId;
1112
- accessory.context.deviceType = device.deviceType;
1113
- accessory.displayName = device.configDeviceName
1114
- ? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
1115
- : await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName);
1116
- accessory.context.connectionType = await this.connectionType(device);
1117
- accessory.context.connectionType = await this.connectionType(device);
1118
- accessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
1119
- const newOrExternal = !device.external ? 'Adding new' : 'Loading external';
1120
- this.infoLog(`${newOrExternal} accessory: ${accessory.displayName} deviceId: ${device.deviceId}`);
1121
- // create the accessory handler for the newly create accessory
1122
- // this is imported from `platformAccessory.ts`
1123
- new IOSensor(this, accessory, device);
1124
- this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`);
1125
- // publish device externally or link the accessory to your platform
1126
- this.externalOrPlatform(device, accessory);
1127
- this.accessories.push(accessory);
1128
- }
1129
- else {
1130
- this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} deviceId: ${device.deviceId}`);
1131
- }
1132
- }
1133
- async createWaterDetector(device) {
1134
- const uuid = this.api.hap.uuid.generate(`${device.deviceId}-${device.deviceType}`);
1135
- // see if an accessory with the same uuid has already been registered and restored from
1136
- // the cached devices we stored in the `configureAccessory` method above
1137
- const existingAccessory = this.accessories.find(accessory => accessory.UUID === uuid);
1138
- if (existingAccessory) {
1139
- // the accessory already exists
1140
- if (await this.registerDevice(device)) {
1141
- // if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
1142
- existingAccessory.context.device = device;
1143
- existingAccessory.context.deviceId = device.deviceId;
1144
- existingAccessory.context.deviceType = device.deviceType;
1145
- existingAccessory.context.model = SwitchBotModel.WaterDetector;
1146
- existingAccessory.displayName = device.configDeviceName
1147
- ? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
1148
- : await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName);
1149
- existingAccessory.context.connectionType = await this.connectionType(device);
1150
- existingAccessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
1151
- this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`);
1152
- this.api.updatePlatformAccessories([existingAccessory]);
1153
- // create the accessory handler for the restored accessory
1154
- // this is imported from `platformAccessory.ts`
1155
- new WaterDetector(this, existingAccessory, device);
1156
- this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${existingAccessory.UUID})`);
1157
- }
1158
- else {
1159
- this.unregisterPlatformAccessories(existingAccessory);
1160
- }
1161
- }
1162
- else if (await this.registerDevice(device)) {
1163
- // create a new accessory
1164
- const accessory = new this.api.platformAccessory(device.configDeviceName
1165
- ? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
1166
- : await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName), uuid);
1167
- // store a copy of the device object in the `accessory.context`
1168
- // the `context` property can be used to store any data about the accessory you may need
1169
- accessory.context.device = device;
1170
- accessory.context.deviceId = device.deviceId;
1171
- accessory.context.deviceType = device.deviceType;
1172
- accessory.context.model = SwitchBotModel.WaterDetector;
1173
- accessory.displayName = device.configDeviceName
1174
- ? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
1175
- : await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName);
1176
- accessory.context.connectionType = await this.connectionType(device);
1177
- accessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
1178
- accessory.context.connectionType = await this.connectionType(device);
1179
- const newOrExternal = !device.external ? 'Adding new' : 'Loading external';
1180
- this.infoLog(`${newOrExternal} accessory: ${accessory.displayName} deviceId: ${device.deviceId}`);
1181
- // create the accessory handler for the newly create accessory
1182
- // this is imported from `platformAccessory.ts`
1183
- new WaterDetector(this, accessory, device);
1184
- this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`);
1185
- // publish device externally or link the accessory to your platform
1186
- this.externalOrPlatform(device, accessory);
1187
- this.accessories.push(accessory);
1188
- }
1189
- else {
1190
- this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} deviceId: ${device.deviceId}`);
1191
- }
1192
- }
1193
- async createMotion(device) {
1194
- const uuid = this.api.hap.uuid.generate(`${device.deviceId}-${device.deviceType}`);
1195
- // see if an accessory with the same uuid has already been registered and restored from
1196
- // the cached devices we stored in the `configureAccessory` method above
1197
- const existingAccessory = this.accessories.find(accessory => accessory.UUID === uuid);
1198
- if (existingAccessory) {
1199
- // the accessory already exists
1200
- if (await this.registerDevice(device)) {
1201
- // if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
1202
- existingAccessory.context.device = device;
1203
- existingAccessory.context.deviceId = device.deviceId;
1204
- existingAccessory.context.deviceType = device.deviceType;
1205
- existingAccessory.context.model = SwitchBotModel.MotionSensor;
1206
- existingAccessory.displayName = device.configDeviceName
1207
- ? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
1208
- : await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName);
1209
- existingAccessory.context.connectionType = await this.connectionType(device);
1210
- existingAccessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
1211
- this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`);
1212
- this.api.updatePlatformAccessories([existingAccessory]);
1213
- // create the accessory handler for the restored accessory
1214
- // this is imported from `platformAccessory.ts`
1215
- new Motion(this, existingAccessory, device);
1216
- this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${existingAccessory.UUID})`);
1217
- }
1218
- else {
1219
- this.unregisterPlatformAccessories(existingAccessory);
1220
- }
1221
- }
1222
- else if (await this.registerDevice(device)) {
1223
- // create a new accessory
1224
- const accessory = new this.api.platformAccessory(device.configDeviceName
1225
- ? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
1226
- : await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName), uuid);
1227
- // store a copy of the device object in the `accessory.context`
1228
- // the `context` property can be used to store any data about the accessory you may need
1229
- accessory.context.device = device;
1230
- accessory.context.deviceId = device.deviceId;
1231
- accessory.context.deviceType = device.deviceType;
1232
- accessory.context.model = SwitchBotModel.MotionSensor;
1233
- accessory.displayName = device.configDeviceName
1234
- ? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
1235
- : await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName);
1236
- accessory.context.connectionType = await this.connectionType(device);
1237
- accessory.context.connectionType = await this.connectionType(device);
1238
- accessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
1239
- const newOrExternal = !device.external ? 'Adding new' : 'Loading external';
1240
- this.infoLog(`${newOrExternal} accessory: ${accessory.displayName} deviceId: ${device.deviceId}`);
1241
- // create the accessory handler for the newly create accessory
1242
- // this is imported from `platformAccessory.ts`
1243
- new Motion(this, accessory, device);
1244
- this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`);
1245
- // publish device externally or link the accessory to your platform
1246
- this.externalOrPlatform(device, accessory);
1247
- this.accessories.push(accessory);
1248
- }
1249
- else {
1250
- this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} deviceId: ${device.deviceId}`);
1251
- }
1252
- }
1253
- async createContact(device) {
1254
- const uuid = this.api.hap.uuid.generate(`${device.deviceId}-${device.deviceType}`);
1255
- // see if an accessory with the same uuid has already been registered and restored from
1256
- // the cached devices we stored in the `configureAccessory` method above
1257
- const existingAccessory = this.accessories.find(accessory => accessory.UUID === uuid);
1258
- if (existingAccessory) {
1259
- // the accessory already exists
1260
- if (await this.registerDevice(device)) {
1261
- // if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
1262
- existingAccessory.context.device = device;
1263
- existingAccessory.context.deviceId = device.deviceId;
1264
- existingAccessory.context.deviceType = device.deviceType;
1265
- existingAccessory.context.model = SwitchBotModel.ContactSensor;
1266
- existingAccessory.displayName = device.configDeviceName
1267
- ? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
1268
- : await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName);
1269
- existingAccessory.context.connectionType = await this.connectionType(device);
1270
- existingAccessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
1271
- this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`);
1272
- this.api.updatePlatformAccessories([existingAccessory]);
1273
- // create the accessory handler for the restored accessory
1274
- // this is imported from `platformAccessory.ts`
1275
- new Contact(this, existingAccessory, device);
1276
- this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${existingAccessory.UUID})`);
1277
- }
1278
- else {
1279
- this.unregisterPlatformAccessories(existingAccessory);
1280
- }
1281
- }
1282
- else if (await this.registerDevice(device)) {
1283
- // create a new accessory
1284
- const accessory = new this.api.platformAccessory(device.configDeviceName
1285
- ? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
1286
- : await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName), uuid);
1287
- // store a copy of the device object in the `accessory.context`
1288
- // the `context` property can be used to store any data about the accessory you may need
1289
- accessory.context.device = device;
1290
- accessory.context.deviceId = device.deviceId;
1291
- accessory.context.deviceType = device.deviceType;
1292
- accessory.context.model = SwitchBotModel.ContactSensor;
1293
- accessory.displayName = device.configDeviceName
1294
- ? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
1295
- : await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName);
1296
- accessory.context.connectionType = await this.connectionType(device);
1297
- accessory.context.connectionType = await this.connectionType(device);
1298
- accessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
1299
- const newOrExternal = !device.external ? 'Adding new' : 'Loading external';
1300
- this.infoLog(`${newOrExternal} accessory: ${accessory.displayName} deviceId: ${device.deviceId}`);
1301
- // create the accessory handler for the newly create accessory
1302
- // this is imported from `platformAccessory.ts`
1303
- new Contact(this, accessory, device);
1304
- this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`);
1305
- // publish device externally or link the accessory to your platform
1306
- this.externalOrPlatform(device, accessory);
1307
- this.accessories.push(accessory);
1308
- }
1309
- else {
1310
- this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} deviceId: ${device.deviceId}`);
1311
- }
1312
- }
1313
- async createBlindTilt(device) {
1314
- const uuid = this.api.hap.uuid.generate(`${device.deviceId}-${device.deviceType}`);
1315
- // see if an accessory with the same uuid has already been registered and restored from
1316
- // the cached devices we stored in the `configureAccessory` method above
1317
- const existingAccessory = this.accessories.find(accessory => accessory.UUID === uuid);
1318
- if (existingAccessory) {
1319
- // the accessory already exists
1320
- if (await this.registerDevice(device)) {
1321
- // if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
1322
- existingAccessory.context.device = device;
1323
- existingAccessory.context.deviceId = device.deviceId;
1324
- existingAccessory.context.deviceType = device.deviceType;
1325
- existingAccessory.context.model = SwitchBotModel.BlindTilt;
1326
- existingAccessory.displayName = device.configDeviceName
1327
- ? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
1328
- : await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName);
1329
- existingAccessory.context.connectionType = await this.connectionType(device);
1330
- existingAccessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
1331
- this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`);
1332
- this.api.updatePlatformAccessories([existingAccessory]);
1333
- // create the accessory handler for the restored accessory
1334
- // this is imported from `platformAccessory.ts`
1335
- new BlindTilt(this, existingAccessory, device);
1336
- this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${existingAccessory.UUID})`);
1337
- }
1338
- else {
1339
- this.unregisterPlatformAccessories(existingAccessory);
1340
- }
1341
- }
1342
- else if (await this.registerDevice(device)) {
1343
- if (isBlindTiltDevice(device)) {
1344
- if (device.group && !device.disable_group) {
1345
- this.debugLog('Your Curtains are grouped, '
1346
- + `, Secondary curtain automatically hidden. Main Curtain: ${device.deviceName}, deviceId: ${device.deviceId}`);
1347
- }
1348
- else {
1349
- if (device.master) {
1350
- this.warnLog(`Main Curtain: ${device.deviceName}, deviceId: ${device.deviceId}`);
1351
- }
1352
- else {
1353
- this.errorLog(`Secondary Curtain: ${device.deviceName}, deviceId: ${device.deviceId}`);
1354
- }
1355
- }
1356
- }
1357
- // create a new accessory
1358
- const accessory = new this.api.platformAccessory(device.configDeviceName
1359
- ? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
1360
- : await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName), uuid);
1361
- // store a copy of the device object in the `accessory.context`
1362
- // the `context` property can be used to store any data about the accessory you may need
1363
- accessory.context.device = device;
1364
- accessory.context.deviceId = device.deviceId;
1365
- accessory.context.deviceType = device.deviceType;
1366
- accessory.context.model = SwitchBotModel.BlindTilt;
1367
- accessory.displayName = device.configDeviceName
1368
- ? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
1369
- : await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName);
1370
- accessory.context.connectionType = await this.connectionType(device);
1371
- accessory.context.connectionType = await this.connectionType(device);
1372
- accessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
1373
- const newOrExternal = !device.external ? 'Adding new' : 'Loading external';
1374
- this.infoLog(`${newOrExternal} accessory: ${accessory.displayName} deviceId: ${device.deviceId}`);
1375
- // create the accessory handler for the newly create accessory
1376
- // this is imported from `platformAccessory.ts`
1377
- new BlindTilt(this, accessory, device);
1378
- this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`);
1379
- // publish device externally or link the accessory to your platform
1380
- this.externalOrPlatform(device, accessory);
1381
- this.accessories.push(accessory);
1382
- }
1383
- else {
1384
- this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} deviceId: ${device.deviceId}`);
1385
- }
1386
- }
1387
- async createCurtain(device) {
1388
- const uuid = this.api.hap.uuid.generate(`${device.deviceId}-${device.deviceType}`);
1389
- // see if an accessory with the same uuid has already been registered and restored from
1390
- // the cached devices we stored in the `configureAccessory` method above
1391
- const existingAccessory = this.accessories.find(accessory => accessory.UUID === uuid);
1392
- if (existingAccessory) {
1393
- // the accessory already exists
1394
- if (await this.registerDevice(device)) {
1395
- // if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
1396
- existingAccessory.context.device = device;
1397
- existingAccessory.context.deviceId = device.deviceId;
1398
- existingAccessory.context.deviceType = device.deviceType;
1399
- existingAccessory.context.model = device.deviceType === 'Curtain3' ? SwitchBotModel.Curtain3 : SwitchBotModel.Curtain;
1400
- existingAccessory.displayName = device.configDeviceName
1401
- ? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
1402
- : await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName);
1403
- existingAccessory.context.connectionType = await this.connectionType(device);
1404
- existingAccessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
1405
- this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`);
1406
- this.api.updatePlatformAccessories([existingAccessory]);
1407
- // create the accessory handler for the restored accessory
1408
- // this is imported from `platformAccessory.ts`
1409
- new Curtain(this, existingAccessory, device);
1410
- this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${existingAccessory.UUID})`);
1411
- }
1412
- else {
1413
- this.unregisterPlatformAccessories(existingAccessory);
1414
- }
1415
- }
1416
- else if (await this.registerDevice(device)) {
1417
- if (isCurtainDevice(device)) {
1418
- if (device.group && !device.disable_group) {
1419
- this.debugLog('Your Curtains are grouped, '
1420
- + `, Secondary curtain automatically hidden. Main Curtain: ${device.deviceName}, deviceId: ${device.deviceId}`);
1421
- }
1422
- else {
1423
- if (device.master) {
1424
- this.warnLog(`Main Curtain: ${device.deviceName}, deviceId: ${device.deviceId}`);
1425
- }
1426
- else {
1427
- this.errorLog(`Secondary Curtain: ${device.deviceName}, deviceId: ${device.deviceId}`);
1428
- }
1429
- }
1430
- }
1431
- // create a new accessory
1432
- const accessory = new this.api.platformAccessory(device.configDeviceName
1433
- ? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
1434
- : await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName), uuid);
1435
- // store a copy of the device object in the `accessory.context`
1436
- // the `context` property can be used to store any data about the accessory you may need
1437
- accessory.context.device = device;
1438
- accessory.context.deviceId = device.deviceId;
1439
- accessory.context.deviceType = device.deviceType;
1440
- accessory.context.model = device.deviceType === 'Curtain3' ? SwitchBotModel.Curtain3 : SwitchBotModel.Curtain;
1441
- accessory.displayName = device.configDeviceName
1442
- ? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
1443
- : await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName);
1444
- accessory.context.connectionType = await this.connectionType(device);
1445
- accessory.context.connectionType = await this.connectionType(device);
1446
- accessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
1447
- const newOrExternal = !device.external ? 'Adding new' : 'Loading external';
1448
- this.infoLog(`${newOrExternal} accessory: ${accessory.displayName} deviceId: ${device.deviceId}`);
1449
- // create the accessory handler for the newly create accessory
1450
- // this is imported from `platformAccessory.ts`
1451
- new Curtain(this, accessory, device);
1452
- this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`);
1453
- // publish device externally or link the accessory to your platform
1454
- this.externalOrPlatform(device, accessory);
1455
- this.accessories.push(accessory);
1456
- }
1457
- else {
1458
- this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} deviceId: ${device.deviceId}`);
1459
- }
1460
- }
1461
- async createPlug(device) {
1462
- const uuid = this.api.hap.uuid.generate(`${device.deviceId}-${device.deviceType}`);
1463
- // see if an accessory with the same uuid has already been registered and restored from
1464
- // the cached devices we stored in the `configureAccessory` method above
1465
- const existingAccessory = this.accessories.find(accessory => accessory.UUID === uuid);
1466
- if (existingAccessory) {
1467
- // the accessory already exists
1468
- if (await this.registerDevice(device)) {
1469
- // if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
1470
- existingAccessory.context.device = device;
1471
- existingAccessory.context.deviceId = device.deviceId;
1472
- existingAccessory.context.deviceType = device.deviceType;
1473
- existingAccessory.context.model = device.deviceType === 'Plug Mini (US)'
1474
- ? SwitchBotModel.PlugMiniUS
1475
- : device.deviceType === 'Plug Mini (JP)'
1476
- ? SwitchBotModel.PlugMiniJP
1477
- : SwitchBotModel.Plug;
1478
- existingAccessory.displayName = device.configDeviceName
1479
- ? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
1480
- : await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName);
1481
- existingAccessory.context.connectionType = await this.connectionType(device);
1482
- existingAccessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
1483
- this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`);
1484
- this.api.updatePlatformAccessories([existingAccessory]);
1485
- // create the accessory handler for the restored accessory
1486
- // this is imported from `platformAccessory.ts`
1487
- new Plug(this, existingAccessory, device);
1488
- this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${existingAccessory.UUID})`);
1489
- }
1490
- else {
1491
- this.unregisterPlatformAccessories(existingAccessory);
1492
- }
1493
- }
1494
- else if (await this.registerDevice(device)) {
1495
- // create a new accessory
1496
- const accessory = new this.api.platformAccessory(device.configDeviceName
1497
- ? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
1498
- : await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName), uuid);
1499
- // store a copy of the device object in the `accessory.context`
1500
- // the `context` property can be used to store any data about the accessory you may need
1501
- accessory.context.device = device;
1502
- accessory.context.deviceId = device.deviceId;
1503
- accessory.context.deviceType = device.deviceType;
1504
- accessory.context.model = device.deviceType === 'Plug Mini (US)'
1505
- ? SwitchBotModel.PlugMiniUS
1506
- : device.deviceType === 'Plug Mini (JP)'
1507
- ? SwitchBotModel.PlugMiniJP
1508
- : SwitchBotModel.Plug;
1509
- accessory.displayName = device.configDeviceName
1510
- ? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
1511
- : await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName);
1512
- accessory.context.connectionType = await this.connectionType(device);
1513
- accessory.context.connectionType = await this.connectionType(device);
1514
- accessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
1515
- const newOrExternal = !device.external ? 'Adding new' : 'Loading external';
1516
- this.infoLog(`${newOrExternal} accessory: ${accessory.displayName} deviceId: ${device.deviceId}`);
1517
- // create the accessory handler for the newly create accessory
1518
- // this is imported from `platformAccessory.ts`
1519
- new Plug(this, accessory, device);
1520
- this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`);
1521
- // publish device externally or link the accessory to your platform
1522
- this.externalOrPlatform(device, accessory);
1523
- this.accessories.push(accessory);
1524
- }
1525
- else {
1526
- this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} deviceId: ${device.deviceId}`);
1527
- }
1528
- }
1529
- async createLock(device) {
1530
- const uuid = this.api.hap.uuid.generate(`${device.deviceId}-${device.deviceType}`);
1531
- // see if an accessory with the same uuid has already been registered and restored from
1532
- // the cached devices we stored in the `configureAccessory` method above
1533
- const existingAccessory = this.accessories.find(accessory => accessory.UUID === uuid);
1534
- if (existingAccessory) {
1535
- // the accessory already exists
1536
- if (await this.registerDevice(device)) {
1537
- // if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
1538
- existingAccessory.context.device = device;
1539
- existingAccessory.context.deviceId = device.deviceId;
1540
- existingAccessory.context.deviceType = device.deviceType;
1541
- existingAccessory.context.model = device.deviceType === 'Smart Lock Pro' ? SwitchBotModel.LockPro : SwitchBotModel.Lock;
1542
- existingAccessory.displayName = device.configDeviceName
1543
- ? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
1544
- : await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName);
1545
- existingAccessory.context.connectionType = await this.connectionType(device);
1546
- existingAccessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
1547
- this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`);
1548
- this.api.updatePlatformAccessories([existingAccessory]);
1549
- // create the accessory handler for the restored accessory
1550
- // this is imported from `platformAccessory.ts`
1551
- new Lock(this, existingAccessory, device);
1552
- this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${existingAccessory.UUID})`);
1553
- }
1554
- else {
1555
- this.unregisterPlatformAccessories(existingAccessory);
1556
- }
1557
- }
1558
- else if (await this.registerDevice(device)) {
1559
- // create a new accessory
1560
- const accessory = new this.api.platformAccessory(device.configDeviceName
1561
- ? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
1562
- : await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName), uuid);
1563
- // store a copy of the device object in the `accessory.context`
1564
- // the `context` property can be used to store any data about the accessory you may need
1565
- accessory.context.device = device;
1566
- accessory.context.deviceId = device.deviceId;
1567
- accessory.context.deviceType = device.deviceType;
1568
- accessory.context.model = device.deviceType === 'Smart Lock Pro' ? SwitchBotModel.LockPro : SwitchBotModel.Lock;
1569
- accessory.displayName = device.configDeviceName
1570
- ? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
1571
- : await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName);
1572
- accessory.context.connectionType = await this.connectionType(device);
1573
- accessory.context.connectionType = await this.connectionType(device);
1574
- accessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
1575
- const newOrExternal = !device.external ? 'Adding new' : 'Loading external';
1576
- this.infoLog(`${newOrExternal} accessory: ${accessory.displayName} deviceId: ${device.deviceId}`);
1577
- // create the accessory handler for the newly create accessory
1578
- // this is imported from `platformAccessory.ts`
1579
- new Lock(this, accessory, device);
1580
- this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`);
1581
- // publish device externally or link the accessory to your platform
1582
- this.externalOrPlatform(device, accessory);
1583
- this.accessories.push(accessory);
1584
- }
1585
- else {
1586
- this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} deviceId: ${device.deviceId}`);
1587
- }
1588
- }
1589
- async createColorBulb(device) {
1590
- const uuid = this.api.hap.uuid.generate(`${device.deviceId}-${device.deviceType}`);
1591
- // see if an accessory with the same uuid has already been registered and restored from
1592
- // the cached devices we stored in the `configureAccessory` method above
1593
- const existingAccessory = this.accessories.find(accessory => accessory.UUID === uuid);
1594
- if (existingAccessory) {
1595
- // the accessory already exists
1596
- if (await this.registerDevice(device)) {
1597
- // if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
1598
- existingAccessory.context.device = device;
1599
- existingAccessory.context.deviceId = device.deviceId;
1600
- existingAccessory.context.deviceType = device.deviceType;
1601
- existingAccessory.context.model = SwitchBotModel.ColorBulb;
1602
- existingAccessory.displayName = device.configDeviceName
1603
- ? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
1604
- : await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName);
1605
- existingAccessory.context.connectionType = await this.connectionType(device);
1606
- existingAccessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
1607
- this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`);
1608
- this.api.updatePlatformAccessories([existingAccessory]);
1609
- // create the accessory handler for the restored accessory
1610
- // this is imported from `platformAccessory.ts`
1611
- new ColorBulb(this, existingAccessory, device);
1612
- this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${existingAccessory.UUID})`);
1613
- }
1614
- else {
1615
- this.unregisterPlatformAccessories(existingAccessory);
1616
- }
1617
- }
1618
- else if (await this.registerDevice(device)) {
1619
- // create a new accessory
1620
- const accessory = new this.api.platformAccessory(device.configDeviceName
1621
- ? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
1622
- : await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName), uuid);
1623
- // store a copy of the device object in the `accessory.context`
1624
- // the `context` property can be used to store any data about the accessory you may need
1625
- accessory.context.device = device;
1626
- accessory.context.deviceId = device.deviceId;
1627
- accessory.context.deviceType = device.deviceType;
1628
- accessory.context.model = SwitchBotModel.ColorBulb;
1629
- accessory.displayName = device.configDeviceName
1630
- ? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
1631
- : await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName);
1632
- accessory.context.connectionType = await this.connectionType(device);
1633
- accessory.context.connectionType = await this.connectionType(device);
1634
- accessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
1635
- const newOrExternal = !device.external ? 'Adding new' : 'Loading external';
1636
- this.infoLog(`${newOrExternal} accessory: ${accessory.displayName} deviceId: ${device.deviceId}`);
1637
- // create the accessory handler for the newly create accessory
1638
- // this is imported from `platformAccessory.ts`
1639
- new ColorBulb(this, accessory, device);
1640
- this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`);
1641
- // publish device externally or link the accessory to your platform
1642
- this.externalOrPlatform(device, accessory);
1643
- this.accessories.push(accessory);
1644
- }
1645
- else {
1646
- this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} deviceId: ${device.deviceId}`);
1647
- }
1648
- }
1649
- async createCeilingLight(device) {
1650
- const uuid = this.api.hap.uuid.generate(`${device.deviceId}-${device.deviceType}`);
1651
- // see if an accessory with the same uuid has already been registered and restored from
1652
- // the cached devices we stored in the `configureAccessory` method above
1653
- const existingAccessory = this.accessories.find(accessory => accessory.UUID === uuid);
1654
- if (existingAccessory) {
1655
- // the accessory already exists
1656
- if (await this.registerDevice(device)) {
1657
- // if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
1658
- existingAccessory.context.device = device;
1659
- existingAccessory.context.deviceId = device.deviceId;
1660
- existingAccessory.context.deviceType = device.deviceType;
1661
- existingAccessory.context.model = device.deviceType === 'Ceiling Light Pro' ? SwitchBotModel.CeilingLightPro : SwitchBotModel.CeilingLight;
1662
- existingAccessory.displayName = device.configDeviceName
1663
- ? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
1664
- : await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName);
1665
- existingAccessory.context.connectionType = await this.connectionType(device);
1666
- existingAccessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
1667
- this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`);
1668
- this.api.updatePlatformAccessories([existingAccessory]);
1669
- // create the accessory handler for the restored accessory
1670
- // this is imported from `platformAccessory.ts`
1671
- new CeilingLight(this, existingAccessory, device);
1672
- this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${existingAccessory.UUID})`);
1673
- }
1674
- else {
1675
- this.unregisterPlatformAccessories(existingAccessory);
1676
- }
1677
- }
1678
- else if (await this.registerDevice(device)) {
1679
- // create a new accessory
1680
- const accessory = new this.api.platformAccessory(device.configDeviceName
1681
- ? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
1682
- : await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName), uuid);
1683
- // store a copy of the device object in the `accessory.context`
1684
- // the `context` property can be used to store any data about the accessory you may need
1685
- accessory.context.device = device;
1686
- accessory.context.deviceId = device.deviceId;
1687
- accessory.context.deviceType = device.deviceType;
1688
- accessory.context.model = device.deviceType === 'Ceiling Light Pro' ? SwitchBotModel.CeilingLightPro : SwitchBotModel.CeilingLight;
1689
- accessory.displayName = device.configDeviceName
1690
- ? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
1691
- : await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName);
1692
- accessory.context.connectionType = await this.connectionType(device);
1693
- accessory.context.connectionType = await this.connectionType(device);
1694
- accessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
1695
- const newOrExternal = !device.external ? 'Adding new' : 'Loading external';
1696
- this.infoLog(`${newOrExternal} accessory: ${accessory.displayName} deviceId: ${device.deviceId}`);
1697
- // create the accessory handler for the newly create accessory
1698
- // this is imported from `platformAccessory.ts`
1699
- new CeilingLight(this, accessory, device);
1700
- this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`);
1701
- // publish device externally or link the accessory to your platform
1702
- this.externalOrPlatform(device, accessory);
1703
- this.accessories.push(accessory);
1704
- }
1705
- else {
1706
- this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} deviceId: ${device.deviceId}`);
1707
- }
1708
- }
1709
- async createStripLight(device) {
1710
- const uuid = this.api.hap.uuid.generate(`${device.deviceId}-${device.deviceType}`);
1711
- // see if an accessory with the same uuid has already been registered and restored from
1712
- // the cached devices we stored in the `configureAccessory` method above
1713
- const existingAccessory = this.accessories.find(accessory => accessory.UUID === uuid);
1714
- if (existingAccessory) {
1715
- // the accessory already exists
1716
- if (await this.registerDevice(device)) {
1717
- // if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
1718
- existingAccessory.context.device = device;
1719
- existingAccessory.context.deviceId = device.deviceId;
1720
- existingAccessory.context.deviceType = device.deviceType;
1721
- existingAccessory.context.model = SwitchBotModel.StripLight;
1722
- existingAccessory.displayName = device.configDeviceName
1723
- ? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
1724
- : await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName);
1725
- existingAccessory.context.connectionType = await this.connectionType(device);
1726
- existingAccessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
1727
- this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`);
1728
- this.api.updatePlatformAccessories([existingAccessory]);
1729
- // create the accessory handler for the restored accessory
1730
- // this is imported from `platformAccessory.ts`
1731
- new StripLight(this, existingAccessory, device);
1732
- this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${existingAccessory.UUID})`);
1733
- }
1734
- else {
1735
- this.unregisterPlatformAccessories(existingAccessory);
1736
- }
1737
- }
1738
- else if (await this.registerDevice(device)) {
1739
- // create a new accessory
1740
- const accessory = new this.api.platformAccessory(device.configDeviceName
1741
- ? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
1742
- : await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName), uuid);
1743
- // store a copy of the device object in the `accessory.context`
1744
- // the `context` property can be used to store any data about the accessory you may need
1745
- accessory.context.device = device;
1746
- accessory.context.deviceId = device.deviceId;
1747
- accessory.context.deviceType = device.deviceType;
1748
- accessory.context.model = SwitchBotModel.StripLight;
1749
- accessory.displayName = device.configDeviceName
1750
- ? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
1751
- : await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName);
1752
- accessory.context.connectionType = await this.connectionType(device);
1753
- accessory.context.connectionType = await this.connectionType(device);
1754
- accessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
1755
- const newOrExternal = !device.external ? 'Adding new' : 'Loading external';
1756
- this.infoLog(`${newOrExternal} accessory: ${accessory.displayName} deviceId: ${device.deviceId}`);
1757
- // create the accessory handler for the newly create accessory
1758
- // this is imported from `platformAccessory.ts`
1759
- new StripLight(this, accessory, device);
1760
- this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`);
1761
- // publish device externally or link the accessory to your platform
1762
- this.externalOrPlatform(device, accessory);
1763
- this.accessories.push(accessory);
1764
- }
1765
- else {
1766
- this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} deviceId: ${device.deviceId}`);
1767
- }
1768
- }
1769
- async createFan(device) {
1770
- const uuid = this.api.hap.uuid.generate(`${device.deviceId}-${device.deviceType}`);
1771
- // see if an accessory with the same uuid has already been registered and restored from
1772
- // the cached devices we stored in the `configureAccessory` method above
1773
- const existingAccessory = this.accessories.find(accessory => accessory.UUID === uuid);
1774
- if (existingAccessory) {
1775
- // the accessory already exists
1776
- if (await this.registerDevice(device)) {
1777
- // if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
1778
- existingAccessory.context.device = device;
1779
- existingAccessory.context.deviceId = device.deviceId;
1780
- existingAccessory.context.deviceType = device.deviceType;
1781
- existingAccessory.context.model = SwitchBotModel.BatteryCirculatorFan;
1782
- existingAccessory.displayName = device.configDeviceName
1783
- ? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
1784
- : await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName);
1785
- existingAccessory.context.connectionType = await this.connectionType(device);
1786
- existingAccessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
1787
- this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`);
1788
- this.api.updatePlatformAccessories([existingAccessory]);
1789
- // create the accessory handler for the restored accessory
1790
- // this is imported from `platformAccessory.ts`
1791
- new Fan(this, existingAccessory, device);
1792
- this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${existingAccessory.UUID})`);
1793
- }
1794
- else {
1795
- this.unregisterPlatformAccessories(existingAccessory);
1796
- }
1797
- }
1798
- else if (await this.registerDevice(device)) {
1799
- // create a new accessory
1800
- const accessory = new this.api.platformAccessory(device.configDeviceName
1801
- ? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
1802
- : await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName), uuid);
1803
- // store a copy of the device object in the `accessory.context`
1804
- // the `context` property can be used to store any data about the accessory you may need
1805
- accessory.context.device = device;
1806
- accessory.context.deviceId = device.deviceId;
1807
- accessory.context.deviceType = device.deviceType;
1808
- accessory.context.model = SwitchBotModel.BatteryCirculatorFan;
1809
- accessory.displayName = device.configDeviceName
1810
- ? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
1811
- : await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName);
1812
- accessory.context.connectionType = await this.connectionType(device);
1813
- accessory.context.connectionType = await this.connectionType(device);
1814
- accessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
1815
- const newOrExternal = !device.external ? 'Adding new' : 'Loading external';
1816
- this.infoLog(`${newOrExternal} accessory: ${accessory.displayName} deviceId: ${device.deviceId}`);
1817
- // create the accessory handler for the newly create accessory
1818
- // this is imported from `platformAccessory.ts`
1819
- new Fan(this, accessory, device);
1820
- this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`);
1821
- // publish device externally or link the accessory to your platform
1822
- this.externalOrPlatform(device, accessory);
1823
- this.accessories.push(accessory);
1824
- }
1825
- else {
1826
- this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} deviceId: ${device.deviceId}`);
1827
- }
1828
- }
1829
- async createAirPurifier(device) {
1830
- const uuid = this.api.hap.uuid.generate(`${device.deviceId}-${device.deviceType}`);
1831
- // see if an accessory with the same uuid has already been registered and restored from
1832
- // the cached devices we stored in the `configureAccessory` method above
1833
- const existingAccessory = this.accessories.find(accessory => accessory.UUID === uuid);
1834
- if (existingAccessory) {
1835
- // the accessory already exists
1836
- if (await this.registerDevice(device)) {
1837
- // if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
1838
- existingAccessory.context.device = device;
1839
- existingAccessory.context.deviceId = device.deviceId;
1840
- existingAccessory.context.deviceType = device.deviceType;
1841
- existingAccessory.context.model = SwitchBotModel.BatteryCirculatorFan;
1842
- existingAccessory.displayName = device.configDeviceName
1843
- ? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
1844
- : await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName);
1845
- existingAccessory.context.connectionType = await this.connectionType(device);
1846
- existingAccessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
1847
- this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`);
1848
- this.api.updatePlatformAccessories([existingAccessory]);
1849
- // create the accessory handler for the restored accessory
1850
- // this is imported from `platformAccessory.ts`
1851
- new AirPurifier(this, existingAccessory, device);
1852
- this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${existingAccessory.UUID})`);
1853
- }
1854
- else {
1855
- this.unregisterPlatformAccessories(existingAccessory);
1856
- }
1857
- }
1858
- else if (await this.registerDevice(device)) {
1859
- // create a new accessory
1860
- const accessory = new this.api.platformAccessory(device.configDeviceName
1861
- ? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
1862
- : await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName), uuid);
1863
- // store a copy of the device object in the `accessory.context`
1864
- // the `context` property can be used to store any data about the accessory you may need
1865
- accessory.context.device = device;
1866
- accessory.context.deviceId = device.deviceId;
1867
- accessory.context.deviceType = device.deviceType;
1868
- accessory.context.model = SwitchBotModel.BatteryCirculatorFan;
1869
- accessory.displayName = device.configDeviceName
1870
- ? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
1871
- : await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName);
1872
- accessory.context.connectionType = await this.connectionType(device);
1873
- accessory.context.connectionType = await this.connectionType(device);
1874
- accessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
1875
- const newOrExternal = !device.external ? 'Adding new' : 'Loading external';
1876
- this.infoLog(`${newOrExternal} accessory: ${accessory.displayName} deviceId: ${device.deviceId}`);
1877
- // create the accessory handler for the newly create accessory
1878
- // this is imported from `platformAccessory.ts`
1879
- new AirPurifier(this, accessory, device);
1880
- this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`);
1881
- // publish device externally or link the accessory to your platform
1882
- this.externalOrPlatform(device, accessory);
1883
- this.accessories.push(accessory);
1884
- }
1885
- else {
1886
- this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} deviceId: ${device.deviceId}`);
1887
- }
1888
- }
1889
- async createRobotVacuumCleaner(device) {
1890
- const uuid = this.api.hap.uuid.generate(`${device.deviceId}-${device.deviceType}`);
1891
- // see if an accessory with the same uuid has already been registered and restored from
1892
- // the cached devices we stored in the `configureAccessory` method above
1893
- const existingAccessory = this.accessories.find(accessory => accessory.UUID === uuid);
1894
- if (existingAccessory) {
1895
- // the accessory already exists
1896
- if (await this.registerDevice(device)) {
1897
- // if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
1898
- existingAccessory.context.device = device;
1899
- existingAccessory.context.deviceId = device.deviceId;
1900
- existingAccessory.context.deviceType = device.deviceType;
1901
- existingAccessory.context.model = device.deviceType === 'Robot Vacuum Cleaner S1'
1902
- ? SwitchBotModel.RobotVacuumCleanerS1
1903
- : device.deviceType === 'Robot Vacuum Cleaner S1 Plus'
1904
- ? SwitchBotModel.RobotVacuumCleanerS1Plus
1905
- : device.deviceType === 'Robot Vacuum Cleaner S10'
1906
- ? SwitchBotModel.RobotVacuumCleanerS10
1907
- : device.deviceType === 'WoSweeper'
1908
- ? SwitchBotModel.WoSweeper
1909
- : device.deviceType === 'WoSweeperMini'
1910
- ? SwitchBotModel.WoSweeperMini
1911
- : SwitchBotModel.Unknown;
1912
- existingAccessory.displayName = device.configDeviceName
1913
- ? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
1914
- : await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName);
1915
- existingAccessory.context.connectionType = await this.connectionType(device);
1916
- existingAccessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
1917
- this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`);
1918
- this.api.updatePlatformAccessories([existingAccessory]);
1919
- // create the accessory handler for the restored accessory
1920
- // this is imported from `platformAccessory.ts`
1921
- new RobotVacuumCleaner(this, existingAccessory, device);
1922
- this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${existingAccessory.UUID})`);
1923
- }
1924
- else {
1925
- this.unregisterPlatformAccessories(existingAccessory);
1926
- }
1927
- }
1928
- else if (await this.registerDevice(device)) {
1929
- // create a new accessory
1930
- const accessory = new this.api.platformAccessory(device.configDeviceName
1931
- ? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
1932
- : await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName), uuid);
1933
- // store a copy of the device object in the `accessory.context`
1934
- // the `context` property can be used to store any data about the accessory you may need
1935
- accessory.context.device = device;
1936
- accessory.context.deviceId = device.deviceId;
1937
- accessory.context.deviceType = device.deviceType;
1938
- accessory.context.model = device.deviceType === 'Robot Vacuum Cleaner S1'
1939
- ? SwitchBotModel.RobotVacuumCleanerS1
1940
- : device.deviceType === 'Robot Vacuum Cleaner S1 Plus'
1941
- ? SwitchBotModel.RobotVacuumCleanerS1Plus
1942
- : device.deviceType === 'Robot Vacuum Cleaner S10'
1943
- ? SwitchBotModel.RobotVacuumCleanerS10
1944
- : device.deviceType === 'WoSweeper'
1945
- ? SwitchBotModel.WoSweeper
1946
- : device.deviceType === 'WoSweeperMini'
1947
- ? SwitchBotModel.WoSweeperMini
1948
- : SwitchBotModel.Unknown;
1949
- accessory.displayName = device.configDeviceName
1950
- ? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
1951
- : await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName);
1952
- accessory.context.connectionType = await this.connectionType(device);
1953
- accessory.context.connectionType = await this.connectionType(device);
1954
- accessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
1955
- const newOrExternal = !device.external ? 'Adding new' : 'Loading external';
1956
- this.infoLog(`${newOrExternal} accessory: ${accessory.displayName} deviceId: ${device.deviceId}`);
1957
- // create the accessory handler for the newly create accessory
1958
- // this is imported from `platformAccessory.ts`
1959
- new RobotVacuumCleaner(this, accessory, device);
1960
- this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`);
1961
- // publish device externally or link the accessory to your platform
1962
- this.externalOrPlatform(device, accessory);
1963
- this.accessories.push(accessory);
1964
- }
1965
- else {
1966
- this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} deviceId: ${device.deviceId}`);
1967
- }
1968
- }
1969
- async createTV(device) {
1970
- const uuid = this.api.hap.uuid.generate(`${device.deviceId}-${device.remoteType}`);
1971
- // see if an accessory with the same uuid has already been registered and restored from
1972
- // the cached devices we stored in the `configureAccessory` method above
1973
- const existingAccessory = this.accessories.find(accessory => accessory.UUID === uuid);
1974
- if (!device.hide_device && existingAccessory) {
1975
- // if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
1976
- existingAccessory.context.device = device;
1977
- existingAccessory.context.deviceId = device.deviceId;
1978
- existingAccessory.context.deviceType = `IR: ${device.remoteType}`;
1979
- existingAccessory.context.model = device.remoteType;
1980
- existingAccessory.displayName = device.configDeviceName
1981
- ? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
1982
- : await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName);
1983
- this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`);
1984
- existingAccessory.context.connectionType = device.connectionType;
1985
- this.api.updatePlatformAccessories([existingAccessory]);
1986
- // create the accessory handler for the restored accessory
1987
- // this is imported from `platformAccessory.ts`
1988
- new TV(this, existingAccessory, device);
1989
- this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${existingAccessory.UUID})`);
1990
- }
1991
- else if (!device.hide_device && device.hubDeviceId) {
1992
- // create a new accessory
1993
- const accessory = new this.api.platformAccessory(device.configDeviceName
1994
- ? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
1995
- : await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName), uuid);
1996
- // store a copy of the device object in the `accessory.context`
1997
- // the `context` property can be used to store any data about the accessory you may need
1998
- accessory.context.device = device;
1999
- accessory.context.deviceId = device.deviceId;
2000
- accessory.context.deviceType = `IR: ${device.remoteType}`;
2001
- accessory.context.model = device.remoteType;
2002
- accessory.displayName = device.configDeviceName
2003
- ? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
2004
- : await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName);
2005
- accessory.context.connectionType = await this.connectionType(device);
2006
- accessory.context.version = device.firmware ?? this.version ?? '0.0.0';
2007
- const newOrExternal = !device.external ? 'Adding new' : 'Loading external';
2008
- this.infoLog(`${newOrExternal} accessory: ${accessory.displayName} deviceId: ${device.deviceId}`);
2009
- // create the accessory handler for the newly create accessory
2010
- // this is imported from `platformAccessory.ts`
2011
- new TV(this, accessory, device);
2012
- this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${accessory.UUID})`);
2013
- this.externalOrPlatform(device, accessory);
2014
- this.accessories.push(accessory);
2015
- }
2016
- else {
2017
- this.debugLog(`Device not registered: ${device.deviceName} ${device.remoteType} deviceId: ${device.deviceId}`);
2018
- }
2019
- }
2020
- async createIRFan(device) {
2021
- const uuid = this.api.hap.uuid.generate(`${device.deviceId}-${device.remoteType}`);
2022
- // see if an accessory with the same uuid has already been registered and restored from
2023
- // the cached devices we stored in the `configureAccessory` method above
2024
- const existingAccessory = this.accessories.find(accessory => accessory.UUID === uuid);
2025
- if (existingAccessory) {
2026
- // the accessory already exists
2027
- if (!device.hide_device && device.hubDeviceId) {
2028
- // if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
2029
- existingAccessory.context.device = device;
2030
- existingAccessory.context.deviceId = device.deviceId;
2031
- existingAccessory.context.deviceType = `IR: ${device.remoteType}`;
2032
- existingAccessory.context.model = device.remoteType;
2033
- existingAccessory.displayName = device.configDeviceName
2034
- ? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
2035
- : await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName);
2036
- this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`);
2037
- existingAccessory.context.connectionType = device.connectionType;
2038
- this.api.updatePlatformAccessories([existingAccessory]);
2039
- // create the accessory handler for the restored accessory
2040
- // this is imported from `platformAccessory.ts`
2041
- new IRFan(this, existingAccessory, device);
2042
- this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${existingAccessory.UUID})`);
2043
- }
2044
- else {
2045
- this.unregisterPlatformAccessories(existingAccessory);
2046
- }
2047
- }
2048
- else if (!device.hide_device && device.hubDeviceId) {
2049
- // create a new accessory
2050
- const accessory = new this.api.platformAccessory(device.configDeviceName
2051
- ? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
2052
- : await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName), uuid);
2053
- // store a copy of the device object in the `accessory.context`
2054
- // the `context` property can be used to store any data about the accessory you may need
2055
- accessory.context.device = device;
2056
- accessory.context.deviceId = device.deviceId;
2057
- accessory.context.deviceType = `IR: ${device.remoteType}`;
2058
- accessory.context.model = device.remoteType;
2059
- accessory.displayName = device.configDeviceName
2060
- ? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
2061
- : await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName);
2062
- accessory.context.connectionType = await this.connectionType(device);
2063
- accessory.context.version = device.firmware ?? this.version ?? '0.0.0';
2064
- const newOrExternal = !device.external ? 'Adding new' : 'Loading external';
2065
- this.infoLog(`${newOrExternal} accessory: ${accessory.displayName} deviceId: ${device.deviceId}`);
2066
- // create the accessory handler for the newly create accessory
2067
- // this is imported from `platformAccessory.ts`
2068
- new IRFan(this, accessory, device);
2069
- this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${accessory.UUID})`);
2070
- // publish device externally or link the accessory to your platform
2071
- this.externalOrPlatform(device, accessory);
2072
- this.accessories.push(accessory);
2073
- }
2074
- else {
2075
- this.debugLog(`Device not registered: ${device.deviceName} ${device.remoteType} deviceId: ${device.deviceId}`);
2076
- }
2077
- }
2078
- async createLight(device) {
2079
- const uuid = this.api.hap.uuid.generate(`${device.deviceId}-${device.remoteType}`);
2080
- // see if an accessory with the same uuid has already been registered and restored from
2081
- // the cached devices we stored in the `configureAccessory` method above
2082
- const existingAccessory = this.accessories.find(accessory => accessory.UUID === uuid);
2083
- if (existingAccessory) {
2084
- // the accessory already exists
2085
- if (!device.hide_device && device.hubDeviceId) {
2086
- // if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
2087
- existingAccessory.context.device = device;
2088
- existingAccessory.context.deviceId = device.deviceId;
2089
- existingAccessory.context.deviceType = `IR: ${device.remoteType}`;
2090
- existingAccessory.context.model = device.remoteType;
2091
- existingAccessory.displayName = device.configDeviceName
2092
- ? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
2093
- : await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName);
2094
- this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`);
2095
- existingAccessory.context.connectionType = device.connectionType;
2096
- this.api.updatePlatformAccessories([existingAccessory]);
2097
- // create the accessory handler for the restored accessory
2098
- // this is imported from `platformAccessory.ts`
2099
- new Light(this, existingAccessory, device);
2100
- this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${existingAccessory.UUID})`);
2101
- }
2102
- else {
2103
- this.unregisterPlatformAccessories(existingAccessory);
2104
- }
2105
- }
2106
- else if (!device.hide_device && device.hubDeviceId) {
2107
- // create a new accessory
2108
- const accessory = new this.api.platformAccessory(device.configDeviceName
2109
- ? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
2110
- : await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName), uuid);
2111
- // store a copy of the device object in the `accessory.context`
2112
- // the `context` property can be used to store any data about the accessory you may need
2113
- accessory.context.device = device;
2114
- accessory.context.deviceId = device.deviceId;
2115
- accessory.context.deviceType = `IR: ${device.remoteType}`;
2116
- accessory.context.model = device.remoteType;
2117
- accessory.displayName = device.configDeviceName
2118
- ? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
2119
- : await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName);
2120
- accessory.context.connectionType = await this.connectionType(device);
2121
- accessory.context.version = device.firmware ?? this.version ?? '0.0.0';
2122
- const newOrExternal = !device.external ? 'Adding new' : 'Loading external';
2123
- this.infoLog(`${newOrExternal} accessory: ${accessory.displayName} deviceId: ${device.deviceId}`);
2124
- // create the accessory handler for the newly create accessory
2125
- // this is imported from `platformAccessory.ts`
2126
- new Light(this, accessory, device);
2127
- this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${accessory.UUID})`);
2128
- // publish device externally or link the accessory to your platform
2129
- this.externalOrPlatform(device, accessory);
2130
- this.accessories.push(accessory);
2131
- }
2132
- else {
2133
- this.debugLog(`Device not registered: ${device.deviceName} ${device.remoteType} deviceId: ${device.deviceId}`);
2134
- }
2135
- }
2136
- async createAirConditioner(device) {
2137
- const uuid = this.api.hap.uuid.generate(`${device.deviceId}-${device.remoteType}`);
2138
- // see if an accessory with the same uuid has already been registered and restored from
2139
- // the cached devices we stored in the `configureAccessory` method above
2140
- const existingAccessory = this.accessories.find(accessory => accessory.UUID === uuid);
2141
- if (existingAccessory) {
2142
- // the accessory already exists
2143
- if (!device.hide_device && device.hubDeviceId) {
2144
- // if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
2145
- existingAccessory.context.device = device;
2146
- existingAccessory.context.deviceId = device.deviceId;
2147
- existingAccessory.context.deviceType = `IR: ${device.remoteType}`;
2148
- existingAccessory.context.model = device.remoteType;
2149
- existingAccessory.displayName = device.configDeviceName
2150
- ? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
2151
- : await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName);
2152
- this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`);
2153
- existingAccessory.context.connectionType = device.connectionType;
2154
- this.api.updatePlatformAccessories([existingAccessory]);
2155
- // create the accessory handler for the restored accessory
2156
- // this is imported from `platformAccessory.ts`
2157
- new AirConditioner(this, existingAccessory, device);
2158
- this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${existingAccessory.UUID})`);
2159
- }
2160
- else {
2161
- this.unregisterPlatformAccessories(existingAccessory);
2162
- }
2163
- }
2164
- else if (!device.hide_device && device.hubDeviceId) {
2165
- // create a new accessory
2166
- const accessory = new this.api.platformAccessory(device.configDeviceName
2167
- ? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
2168
- : await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName), uuid);
2169
- // store a copy of the device object in the `accessory.context`
2170
- // the `context` property can be used to store any data about the accessory you may need
2171
- accessory.context.device = device;
2172
- accessory.context.deviceId = device.deviceId;
2173
- accessory.context.deviceType = `IR: ${device.remoteType}`;
2174
- accessory.context.model = device.remoteType;
2175
- accessory.displayName = device.configDeviceName
2176
- ? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
2177
- : await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName);
2178
- accessory.context.connectionType = await this.connectionType(device);
2179
- accessory.context.version = device.firmware ?? this.version ?? '0.0.0';
2180
- const newOrExternal = !device.external ? 'Adding new' : 'Loading external';
2181
- this.infoLog(`${newOrExternal} accessory: ${accessory.displayName} deviceId: ${device.deviceId}`);
2182
- // create the accessory handler for the newly create accessory
2183
- // this is imported from `platformAccessory.ts`
2184
- new AirConditioner(this, accessory, device);
2185
- this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${accessory.UUID})`);
2186
- // publish device externally or link the accessory to your platform
2187
- this.externalOrPlatform(device, accessory);
2188
- this.accessories.push(accessory);
2189
- }
2190
- else {
2191
- this.debugLog(`Device not registered: ${device.deviceName} ${device.remoteType} deviceId: ${device.deviceId}`);
2192
- }
2193
- }
2194
- async createAirPurifierIR(device) {
2195
- const uuid = this.api.hap.uuid.generate(`${device.deviceId}-${device.remoteType}`);
2196
- // see if an accessory with the same uuid has already been registered and restored from
2197
- // the cached devices we stored in the `configureAccessory` method above
2198
- const existingAccessory = this.accessories.find(accessory => accessory.UUID === uuid);
2199
- if (existingAccessory) {
2200
- // the accessory already exists
2201
- if (!device.hide_device && device.hubDeviceId) {
2202
- // if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
2203
- existingAccessory.context.device = device;
2204
- existingAccessory.context.deviceId = device.deviceId;
2205
- existingAccessory.context.deviceType = `IR: ${device.remoteType}`;
2206
- existingAccessory.context.model = device.remoteType;
2207
- existingAccessory.displayName = device.configDeviceName
2208
- ? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
2209
- : await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName);
2210
- this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`);
2211
- existingAccessory.context.connectionType = device.connectionType;
2212
- this.api.updatePlatformAccessories([existingAccessory]);
2213
- // create the accessory handler for the restored accessory
2214
- // this is imported from `platformAccessory.ts`
2215
- new AirPurifierIR(this, existingAccessory, device);
2216
- this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${existingAccessory.UUID})`);
2217
- }
2218
- else {
2219
- this.unregisterPlatformAccessories(existingAccessory);
2220
- }
2221
- }
2222
- else if (!device.hide_device && device.hubDeviceId) {
2223
- // create a new accessory
2224
- const accessory = new this.api.platformAccessory(device.configDeviceName
2225
- ? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
2226
- : await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName), uuid);
2227
- // store a copy of the device object in the `accessory.context`
2228
- // the `context` property can be used to store any data about the accessory you may need
2229
- accessory.context.device = device;
2230
- accessory.context.deviceId = device.deviceId;
2231
- accessory.context.deviceType = `IR: ${device.remoteType}`;
2232
- accessory.context.model = device.remoteType;
2233
- accessory.displayName = device.configDeviceName
2234
- ? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
2235
- : await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName);
2236
- accessory.context.connectionType = await this.connectionType(device);
2237
- accessory.context.version = device.firmware ?? this.version ?? '0.0.0';
2238
- const newOrExternal = !device.external ? 'Adding new' : 'Loading external';
2239
- this.infoLog(`${newOrExternal} accessory: ${accessory.displayName} deviceId: ${device.deviceId}`);
2240
- // create the accessory handler for the newly create accessory
2241
- // this is imported from `platformAccessory.ts`
2242
- new AirPurifierIR(this, accessory, device);
2243
- this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${accessory.UUID})`);
2244
- // publish device externally or link the accessory to your platform
2245
- this.externalOrPlatform(device, accessory);
2246
- this.accessories.push(accessory);
2247
- }
2248
- else {
2249
- this.debugLog(`Device not registered: ${device.deviceName} ${device.remoteType} deviceId: ${device.deviceId}`);
2250
- }
2251
- }
2252
- async createWaterHeater(device) {
2253
- const uuid = this.api.hap.uuid.generate(`${device.deviceId}-${device.remoteType}`);
2254
- // see if an accessory with the same uuid has already been registered and restored from
2255
- // the cached devices we stored in the `configureAccessory` method above
2256
- const existingAccessory = this.accessories.find(accessory => accessory.UUID === uuid);
2257
- if (existingAccessory) {
2258
- // the accessory already exists
2259
- if (!device.hide_device && device.hubDeviceId) {
2260
- // if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
2261
- existingAccessory.context.device = device;
2262
- existingAccessory.context.deviceId = device.deviceId;
2263
- existingAccessory.context.deviceType = `IR: ${device.remoteType}`;
2264
- existingAccessory.context.model = device.remoteType;
2265
- existingAccessory.displayName = device.configDeviceName
2266
- ? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
2267
- : await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName);
2268
- this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`);
2269
- existingAccessory.context.connectionType = device.connectionType;
2270
- this.api.updatePlatformAccessories([existingAccessory]);
2271
- // create the accessory handler for the restored accessory
2272
- // this is imported from `platformAccessory.ts`
2273
- new WaterHeater(this, existingAccessory, device);
2274
- this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${existingAccessory.UUID})`);
2275
- }
2276
- else {
2277
- this.unregisterPlatformAccessories(existingAccessory);
2278
- }
2279
- }
2280
- else if (!device.hide_device && device.hubDeviceId) {
2281
- // create a new accessory
2282
- const accessory = new this.api.platformAccessory(device.configDeviceName
2283
- ? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
2284
- : await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName), uuid);
2285
- // store a copy of the device object in the `accessory.context`
2286
- // the `context` property can be used to store any data about the accessory you may need
2287
- accessory.context.device = device;
2288
- accessory.context.deviceId = device.deviceId;
2289
- accessory.context.deviceType = `IR: ${device.remoteType}`;
2290
- accessory.context.model = device.remoteType;
2291
- accessory.displayName = device.configDeviceName
2292
- ? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
2293
- : await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName);
2294
- accessory.context.connectionType = await this.connectionType(device);
2295
- accessory.context.version = device.firmware ?? this.version ?? '0.0.0';
2296
- const newOrExternal = !device.external ? 'Adding new' : 'Loading external';
2297
- this.infoLog(`${newOrExternal} accessory: ${accessory.displayName} deviceId: ${device.deviceId}`);
2298
- // create the accessory handler for the newly create accessory
2299
- // this is imported from `platformAccessory.ts`
2300
- new WaterHeater(this, accessory, device);
2301
- this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${accessory.UUID})`);
2302
- // publish device externally or link the accessory to your platform
2303
- this.externalOrPlatform(device, accessory);
2304
- this.accessories.push(accessory);
2305
- }
2306
- else {
2307
- this.debugLog(`Device not registered: ${device.deviceName} ${device.remoteType} deviceId: ${device.deviceId}`);
2308
- }
2309
- }
2310
- async createVacuumCleaner(device) {
2311
- const uuid = this.api.hap.uuid.generate(`${device.deviceId}-${device.remoteType}`);
2312
- // see if an accessory with the same uuid has already been registered and restored from
2313
- // the cached devices we stored in the `configureAccessory` method above
2314
- const existingAccessory = this.accessories.find(accessory => accessory.UUID === uuid);
2315
- if (existingAccessory) {
2316
- // the accessory already exists
2317
- if (!device.hide_device && device.hubDeviceId) {
2318
- // if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
2319
- existingAccessory.context.device = device;
2320
- existingAccessory.context.deviceId = device.deviceId;
2321
- existingAccessory.context.deviceType = `IR: ${device.remoteType}`;
2322
- existingAccessory.context.model = device.remoteType;
2323
- existingAccessory.displayName = device.configDeviceName
2324
- ? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
2325
- : await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName);
2326
- this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`);
2327
- existingAccessory.context.connectionType = device.connectionType;
2328
- this.api.updatePlatformAccessories([existingAccessory]);
2329
- // create the accessory handler for the restored accessory
2330
- // this is imported from `platformAccessory.ts`
2331
- new VacuumCleaner(this, existingAccessory, device);
2332
- this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${existingAccessory.UUID})`);
2333
- }
2334
- else {
2335
- this.unregisterPlatformAccessories(existingAccessory);
2336
- }
2337
- }
2338
- else if (!device.hide_device && device.hubDeviceId) {
2339
- // create a new accessory
2340
- const accessory = new this.api.platformAccessory(device.configDeviceName
2341
- ? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
2342
- : await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName), uuid);
2343
- // store a copy of the device object in the `accessory.context`
2344
- // the `context` property can be used to store any data about the accessory you may need
2345
- accessory.context.device = device;
2346
- accessory.context.deviceId = device.deviceId;
2347
- accessory.context.deviceType = `IR: ${device.remoteType}`;
2348
- accessory.context.model = device.remoteType;
2349
- accessory.displayName = device.configDeviceName
2350
- ? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
2351
- : await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName);
2352
- accessory.context.connectionType = await this.connectionType(device);
2353
- accessory.context.version = device.firmware ?? this.version ?? '0.0.0';
2354
- const newOrExternal = !device.external ? 'Adding new' : 'Loading external';
2355
- this.infoLog(`${newOrExternal} accessory: ${accessory.displayName} deviceId: ${device.deviceId}`);
2356
- // create the accessory handler for the newly create accessory
2357
- // this is imported from `platformAccessory.ts`
2358
- new VacuumCleaner(this, accessory, device);
2359
- this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${accessory.UUID})`);
2360
- // publish device externally or link the accessory to your platform
2361
- this.externalOrPlatform(device, accessory);
2362
- this.accessories.push(accessory);
2363
- }
2364
- else {
2365
- this.debugLog(`Device not registered: ${device.deviceName} ${device.remoteType} deviceId: ${device.deviceId}`);
2366
- }
2367
- }
2368
- async createCamera(device) {
2369
- const uuid = this.api.hap.uuid.generate(`${device.deviceId}-${device.remoteType}`);
2370
- // see if an accessory with the same uuid has already been registered and restored from
2371
- // the cached devices we stored in the `configureAccessory` method above
2372
- const existingAccessory = this.accessories.find(accessory => accessory.UUID === uuid);
2373
- if (existingAccessory) {
2374
- // the accessory already exists
2375
- if (!device.hide_device && device.hubDeviceId) {
2376
- // if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
2377
- existingAccessory.context.device = device;
2378
- existingAccessory.context.deviceId = device.deviceId;
2379
- existingAccessory.context.deviceType = `IR: ${device.remoteType}`;
2380
- existingAccessory.context.model = device.remoteType;
2381
- existingAccessory.displayName = device.configDeviceName
2382
- ? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
2383
- : await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName);
2384
- this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`);
2385
- existingAccessory.context.connectionType = device.connectionType;
2386
- this.api.updatePlatformAccessories([existingAccessory]);
2387
- // create the accessory handler for the restored accessory
2388
- // this is imported from `platformAccessory.ts`
2389
- new Camera(this, existingAccessory, device);
2390
- this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${existingAccessory.UUID})`);
2391
- }
2392
- else {
2393
- this.unregisterPlatformAccessories(existingAccessory);
2394
- }
2395
- }
2396
- else if (!device.hide_device && device.hubDeviceId) {
2397
- // create a new accessory
2398
- const accessory = new this.api.platformAccessory(device.configDeviceName
2399
- ? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
2400
- : await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName), uuid);
2401
- // store a copy of the device object in the `accessory.context`
2402
- // the `context` property can be used to store any data about the accessory you may need
2403
- accessory.context.device = device;
2404
- accessory.context.deviceId = device.deviceId;
2405
- accessory.context.deviceType = `IR: ${device.remoteType}`;
2406
- accessory.context.model = device.remoteType;
2407
- accessory.displayName = device.configDeviceName
2408
- ? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
2409
- : await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName);
2410
- accessory.context.connectionType = await this.connectionType(device);
2411
- accessory.context.version = device.firmware ?? this.version ?? '0.0.0';
2412
- const newOrExternal = !device.external ? 'Adding new' : 'Loading external';
2413
- this.infoLog(`${newOrExternal} accessory: ${accessory.displayName} deviceId: ${device.deviceId}`);
2414
- // create the accessory handler for the newly create accessory
2415
- // this is imported from `platformAccessory.ts`
2416
- new Camera(this, accessory, device);
2417
- this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${accessory.UUID})`);
2418
- // publish device externally or link the accessory to your platform
2419
- this.externalOrPlatform(device, accessory);
2420
- this.accessories.push(accessory);
2421
- }
2422
- else {
2423
- this.debugLog(`Device not registered: ${device.deviceName} ${device.remoteType} deviceId: ${device.deviceId}`);
2424
- }
2425
- }
2426
- async createOthers(device) {
2427
- const uuid = this.api.hap.uuid.generate(`${device.deviceId}-${device.remoteType}`);
2428
- // see if an accessory with the same uuid has already been registered and restored from
2429
- // the cached devices we stored in the `configureAccessory` method above
2430
- const existingAccessory = this.accessories.find(accessory => accessory.UUID === uuid);
2431
- if (existingAccessory) {
2432
- // the accessory already exists
2433
- if (!device.hide_device && device.hubDeviceId) {
2434
- // if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
2435
- existingAccessory.context.device = device;
2436
- existingAccessory.context.deviceId = device.deviceId;
2437
- existingAccessory.context.deviceType = `IR: ${device.remoteType}`;
2438
- existingAccessory.context.model = device.remoteType;
2439
- existingAccessory.displayName = device.configDeviceName
2440
- ? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
2441
- : await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName);
2442
- this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`);
2443
- existingAccessory.context.connectionType = device.connectionType;
2444
- this.api.updatePlatformAccessories([existingAccessory]);
2445
- // create the accessory handler for the restored accessory
2446
- // this is imported from `platformAccessory.ts`
2447
- new Others(this, existingAccessory, device);
2448
- this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${existingAccessory.UUID})`);
2449
- }
2450
- else {
2451
- this.unregisterPlatformAccessories(existingAccessory);
2452
- }
2453
- }
2454
- else if (!device.hide_device && device.hubDeviceId) {
2455
- // create a new accessory
2456
- const accessory = new this.api.platformAccessory(device.configDeviceName
2457
- ? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
2458
- : await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName), uuid);
2459
- // store a copy of the device object in the `accessory.context`
2460
- // the `context` property can be used to store any data about the accessory you may need
2461
- accessory.context.device = device;
2462
- accessory.context.deviceId = device.deviceId;
2463
- accessory.context.deviceType = `IR: ${device.remoteType}`;
2464
- accessory.context.model = device.remoteType;
2465
- accessory.displayName = device.configDeviceName
2466
- ? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
2467
- : await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName);
2468
- accessory.context.connectionType = await this.connectionType(device);
2469
- accessory.context.version = device.firmware ?? this.version ?? '0.0.0';
2470
- const newOrExternal = !device.external ? 'Adding new' : 'Loading external';
2471
- this.infoLog(`${newOrExternal} accessory: ${accessory.displayName} deviceId: ${device.deviceId}`);
2472
- // create the accessory handler for the newly create accessory
2473
- // this is imported from `platformAccessory.ts`
2474
- new Others(this, accessory, device);
2475
- this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${accessory.UUID})`);
2476
- // publish device externally or link the accessory to your platform
2477
- this.externalOrPlatform(device, accessory);
2478
- this.accessories.push(accessory);
2479
- }
2480
- else {
2481
- this.debugLog(`Device not registered: ${device.deviceName} ${device.remoteType} deviceId: ${device.deviceId}`);
2482
- }
2483
- }
2484
- async registerCurtains(device) {
2485
- let registerWindowCovering;
2486
- if (isCurtainDevice(device)) {
2487
- this.debugWarnLog(`deviceName: ${device.deviceName} deviceId: ${device.deviceId}, curtainDevicesIds: ${device.curtainDevicesIds},x master: ${device.master}, group: ${device.group}, disable_group: ${device.disable_group}, connectionType: ${device.connectionType}`);
2488
- registerWindowCovering = await this.registerWindowCovering(device);
2489
- }
2490
- else if (isBlindTiltDevice(device)) {
2491
- this.debugWarnLog(`deviceName: ${device.deviceName} deviceId: ${device.deviceId}, blindTiltDevicesIds: ${device.blindTiltDevicesIds}, master: ${device.master}, group: ${device.group}, disable_group: ${device.disable_group}, connectionType: ${device.connectionType}`);
2492
- registerWindowCovering = await this.registerWindowCovering(device);
2493
- }
2494
- else {
2495
- registerWindowCovering = false;
2496
- }
2497
- return registerWindowCovering;
2498
- }
2499
- async registerWindowCovering(device) {
2500
- this.debugLog(`master: ${device.master}`);
2501
- let registerCurtain;
2502
- if (device.master && device.group) {
2503
- // OpenAPI: Master Curtains/Blind Tilt in Group
2504
- registerCurtain = true;
2505
- this.debugLog(`deviceName: ${device.deviceName} [${device.deviceType} Config] device.master: ${device.master}, device.group: ${device.group} connectionType; ${device.connectionType}`);
2506
- this.debugWarnLog(`Device: ${device.deviceName} registerCurtains: ${registerCurtain}`);
2507
- }
2508
- else if (!device.master && device.disable_group) {
2509
- registerCurtain = true;
2510
- this.debugLog(`deviceName: ${device.deviceName} [${device.deviceType} Config] device.master: ${device.master}, disable_group: ${device.disable_group}, connectionType; ${device.connectionType}`);
2511
- this.debugWarnLog(`Device: ${device.deviceName} registerCurtains: ${registerCurtain}`);
2512
- }
2513
- else if (device.master && !device.group) {
2514
- // OpenAPI: Master Curtains/Blind Tilts not in Group
2515
- registerCurtain = true;
2516
- this.debugLog(`deviceName: ${device.deviceName} [${device.deviceType} Config] device.master: ${device.master}, device.group: ${device.group} connectionType; ${device.connectionType}`);
2517
- this.debugWarnLog(`Device: ${device.deviceName} registerCurtains: ${registerCurtain}`);
2518
- }
2519
- else if (device.connectionType === 'BLE') {
2520
- // BLE: Curtains/Blind Tilt
2521
- registerCurtain = true;
2522
- this.debugLog(`deviceName: ${device.deviceName} [${device.deviceType} Config] connectionType: ${device.connectionType}, group: ${device.group}`);
2523
- this.debugWarnLog(`Device: ${device.deviceName} registerCurtains: ${registerCurtain}`);
2524
- }
2525
- else {
2526
- registerCurtain = false;
2527
- this.debugErrorLog(`deviceName: ${device.deviceName} [${device.deviceType} Config] disable_group: ${device.disable_group}, device.master: ${device.master}, device.group: ${device.group}`);
2528
- this.debugWarnLog(`Device: ${device.deviceName} registerCurtains: ${registerCurtain}, device.connectionType: ${device.connectionType}`);
2529
- }
2530
- return registerCurtain;
2531
- }
2532
- async connectionType(device) {
2533
- let connectionType;
2534
- if (!device.connectionType && this.config.credentials?.token && this.config.credentials.secret) {
2535
- connectionType = 'OpenAPI';
2536
- }
2537
- else {
2538
- connectionType = device.connectionType;
2539
- }
2540
- return connectionType;
2541
- }
2542
- async registerDevice(device) {
2543
- device.connectionType = await this.connectionType(device);
2544
- let registerDevice;
2545
- const shouldRegister = !device.hide_device && (device.connectionType === 'BLE/OpenAPI' || (device.deviceId && device.configDeviceType && device.configDeviceName && device.connectionType === 'BLE') || device.connectionType === 'OpenAPI' || device.connectionType === 'Disabled');
2546
- if (shouldRegister) {
2547
- registerDevice = await this.handleDeviceRegistration(device);
2548
- }
2549
- else {
2550
- registerDevice = false;
2551
- this.debugErrorLog(`Device: ${device.deviceName} connectionType: ${device.connectionType}, hide_device: ${device.hide_device}, will not display in HomeKit`);
2552
- }
2553
- return registerDevice;
2554
- }
2555
- async handleDeviceRegistration(device) {
2556
- let registerDevice;
2557
- switch (device.deviceType) {
2558
- case 'Curtain':
2559
- case 'Curtain3':
2560
- case 'Blind Tilt':
2561
- registerDevice = await this.registerCurtains(device);
2562
- this.debugWarnLog(`Device: ${device.deviceName} ${device.deviceType} registerDevice: ${registerDevice}`);
2563
- break;
2564
- default:
2565
- registerDevice = true;
2566
- this.debugWarnLog(`Device: ${device.deviceName} registerDevice: ${registerDevice}`);
2567
- }
2568
- if (registerDevice) {
2569
- this.debugWarnLog(`Device: ${device.deviceName} connectionType: ${device.connectionType}, will display in HomeKit`);
2570
- }
2571
- else {
2572
- this.debugErrorLog(`Device: ${device.deviceName} connectionType: ${device.connectionType}, will not display in HomeKit`);
2573
- }
2574
- return registerDevice;
2575
- }
2576
- async externalOrPlatform(device, accessory) {
2577
- const { displayName } = accessory;
2578
- const isExternal = device.external ?? false;
2579
- if (isExternal) {
2580
- this.debugWarnLog(`${displayName} External Accessory Mode`);
2581
- this.api.publishExternalAccessories(PLUGIN_NAME, [accessory]);
2582
- }
2583
- else {
2584
- this.debugLog(`${displayName} External Accessory Mode: ${isExternal}`);
2585
- this.api.registerPlatformAccessories(PLUGIN_NAME, PLATFORM_NAME, [accessory]);
2586
- }
2587
- }
2588
- unregisterPlatformAccessories(existingAccessory) {
2589
- const { displayName } = existingAccessory;
2590
- // remove platform accessories when no longer present
2591
- this.api.unregisterPlatformAccessories(PLUGIN_NAME, PLATFORM_NAME, [existingAccessory]);
2592
- this.warnLog(`Removing existing accessory from cache: ${displayName}`);
2593
- }
2594
- /**
2595
- * Handles the status codes returned by the device and logs appropriate messages.
2596
- *
2597
- * @param statusCode - The status code returned by the device.
2598
- * @returns A promise that resolves when the logging is complete.
2599
- */
2600
- async statusCode(statusCode) {
2601
- const messages = {
2602
- 151: `Command not supported by this device type, statusCode: ${statusCode}, Submit Feature Request Here:
2603
- https://tinyurl.com/SwitchBotFeatureRequest`,
2604
- 152: `Device not found, statusCode: ${statusCode}`,
2605
- 160: `Command is not supported, statusCode: ${statusCode}, Submit Bugs Here: https://tinyurl.com/SwitchBotBug`,
2606
- 161: `Device is offline, statusCode: ${statusCode}`,
2607
- 171: `is offline, statusCode: ${statusCode}`,
2608
- 190: `Requests reached the daily limit, statusCode: ${statusCode}`,
2609
- 100: `Command successfully sent, statusCode: ${statusCode}`,
2610
- 200: `Request successful, statusCode: ${statusCode}`,
2611
- 400: `Bad Request, The client has issued an invalid request. This is commonly used to specify validation errors in a request payload,
2612
- statusCode: ${statusCode}`,
2613
- 401: `Unauthorized, Authorization for the API is required, but the request has not been authenticated, statusCode: ${statusCode}`,
2614
- 403: `Forbidden, The request has been authenticated but does not have appropriate permissions, or a requested resource is not found,
2615
- statusCode: ${statusCode}`,
2616
- 404: `Not Found, Specifies the requested path does not exist, statusCode: ${statusCode}`,
2617
- 406: `Not Acceptable, The client has requested a MIME type via the Accept header for a value not supported by the server,
2618
- statusCode: ${statusCode}`,
2619
- 415: `Unsupported Media Type, The client has defined a contentType header that is not supported by the server, statusCode: ${statusCode}`,
2620
- 422: `Unprocessable Entity, The client has made a valid request, but the server cannot process it. This is often used for APIs for which
2621
- certain limits have been exceeded, statusCode: ${statusCode}`,
2622
- 429: `Too Many Requests, The client has exceeded the number of requests allowed for a given time window, statusCode: ${statusCode}`,
2623
- 500: `Internal Server Error, An unexpected error on the SmartThings servers has occurred. These errors should be rare,
2624
- statusCode: ${statusCode}`,
2625
- };
2626
- const message = messages[statusCode] ?? `Unknown statusCode, statusCode: ${statusCode}, Submit Bugs Here: https://tinyurl.com/SwitchBotBug`;
2627
- if ([100, 200].includes(statusCode)) {
2628
- this.debugLog(message);
2629
- }
2630
- else {
2631
- this.errorLog(message);
2632
- }
2633
- }
2634
- async retryRequest(device, deviceMaxRetries, deviceDelayBetweenRetries) {
2635
- let retryCount = 0;
2636
- const maxRetries = deviceMaxRetries;
2637
- const delayBetweenRetries = deviceDelayBetweenRetries;
2638
- while (retryCount < maxRetries) {
2639
- try {
2640
- const { response, statusCode } = await this.switchBotAPI.getDeviceStatus(device.deviceId, this.config.credentials?.token, this.config.credentials?.secret);
2641
- this.debugLog(`response: ${JSON.stringify(response)}`);
2642
- return { response, statusCode };
2643
- }
2644
- catch (error) {
2645
- this.errorLog(`Error making request: ${error.message}`);
2646
- }
2647
- retryCount++;
2648
- this.debugLog(`Retry attempt ${retryCount} of ${maxRetries}`);
2649
- await sleep(delayBetweenRetries);
2650
- }
2651
- return { response: {
2652
- deviceId: '',
2653
- deviceType: '',
2654
- hubDeviceId: '',
2655
- version: 0,
2656
- deviceName: '',
2657
- }, statusCode: 500 };
2658
- }
2659
- async retryCommand(device, bodyChange, deviceMaxRetries, deviceDelayBetweenRetries) {
2660
- let retryCount = 0;
2661
- const maxRetries = deviceMaxRetries ?? 1;
2662
- const delayBetweenRetries = deviceDelayBetweenRetries ?? 1000;
2663
- while (retryCount < maxRetries) {
2664
- try {
2665
- const { response, statusCode } = await this.switchBotAPI.controlDevice(device.deviceId, bodyChange.command, bodyChange.parameter, bodyChange.commandType, this.config.credentials?.token, this.config.credentials?.secret);
2666
- this.debugLog(`response: ${JSON.stringify(response)}`);
2667
- return { response, statusCode };
2668
- }
2669
- catch (error) {
2670
- this.errorLog(`Error making request: ${error.message}`);
2671
- }
2672
- retryCount++;
2673
- this.debugLog(`Retry attempt ${retryCount} of ${maxRetries}`);
2674
- await sleep(delayBetweenRetries);
2675
- }
2676
- return { response: {}, statusCode: 500 };
2677
- }
2678
- // BLE Connection
2679
- async connectBLE(accessory, device) {
2680
- try {
2681
- queueScheduler.schedule(async () => this.switchBotBLE);
2682
- this.debugLog(`${device.deviceType}: ${accessory.displayName} 'node-switchbot' found: ${safeStringify(this.switchBotBLE)}`);
2683
- return this.switchBotBLE;
2684
- }
2685
- catch (e) {
2686
- this.errorLog(`${device.deviceType}: ${accessory.displayName} 'node-switchbot' not found, Error: ${e.message ?? e}`);
2687
- return false;
2688
- }
2689
- }
2690
- async getPlatformConfigSettings() {
2691
- if (this.config.options) {
2692
- const platformConfig = {
2693
- platform: 'Resideo',
2694
- };
2695
- platformConfig.logging = this.config.options.logging ? this.config.options.logging : undefined;
2696
- platformConfig.refreshRate = this.config.options.refreshRate ? this.config.options.refreshRate : undefined;
2697
- platformConfig.updateRate = this.config.options.updateRate ? this.config.options.updateRate : undefined;
2698
- platformConfig.pushRate = this.config.options.pushRate ? this.config.options.pushRate : undefined;
2699
- platformConfig.maxRetries = this.config.options.maxRetries ? this.config.options.maxRetries : undefined;
2700
- platformConfig.delayBetweenRetries = this.config.options.delayBetweenRetries ? this.config.options.delayBetweenRetries : undefined;
2701
- if (Object.entries(platformConfig).length !== 0) {
2702
- await this.debugLog(`Platform Config: ${JSON.stringify(platformConfig)}`);
2703
- }
2704
- this.platformConfig = platformConfig;
2705
- }
2706
- }
2707
- async getPlatformRateSettings() {
2708
- // RefreshRate
2709
- this.platformRefreshRate = this.config.options?.refreshRate ? this.config.options.refreshRate : undefined;
2710
- const refreshRate = this.config.options?.refreshRate ? 'Using Platform Config refreshRate' : 'Platform Config refreshRate Not Set';
2711
- await this.debugLog(`${refreshRate}: ${this.platformRefreshRate}`);
2712
- // UpdateRate
2713
- this.platformUpdateRate = this.config.options?.updateRate ? this.config.options.updateRate : undefined;
2714
- const updateRate = this.config.options?.updateRate ? 'Using Platform Config updateRate' : 'Platform Config updateRate Not Set';
2715
- await this.debugLog(`${updateRate}: ${this.platformUpdateRate}`);
2716
- // PushRate
2717
- this.platformPushRate = this.config.options?.pushRate ? this.config.options.pushRate : undefined;
2718
- const pushRate = this.config.options?.pushRate ? 'Using Platform Config pushRate' : 'Platform Config pushRate Not Set';
2719
- await this.debugLog(`${pushRate}: ${this.platformPushRate}`);
2720
- // MaxRetries
2721
- this.platformMaxRetries = this.config.options?.maxRetries ? this.config.options.maxRetries : undefined;
2722
- const maxRetries = this.config.options?.maxRetries ? 'Using Platform Config maxRetries' : 'Platform Config maxRetries Not Set';
2723
- await this.debugLog(`${maxRetries}: ${this.platformMaxRetries}`);
2724
- // DelayBetweenRetries
2725
- this.platformDelayBetweenRetries = this.config.options?.delayBetweenRetries ? this.config.options.delayBetweenRetries : undefined;
2726
- const delayBetweenRetries = this.config.options?.delayBetweenRetries ? 'Using Platform Config delayBetweenRetries' : 'Platform Config delayBetweenRetries Not Set';
2727
- await this.debugLog(`${delayBetweenRetries}: ${this.platformDelayBetweenRetries}`);
2728
- }
2729
- async getPlatformLogSettings() {
2730
- this.debugMode = argv.includes('-D') ?? argv.includes('--debug');
2731
- this.platformLogging = (this.config.options?.logging === 'debug' || this.config.options?.logging === 'standard'
2732
- || this.config.options?.logging === 'none')
2733
- ? this.config.options.logging
2734
- : this.debugMode ? 'debugMode' : 'standard';
2735
- const logging = this.config.options?.logging ? 'Platform Config' : this.debugMode ? 'debugMode' : 'Default';
2736
- await this.debugLog(`Using ${logging} Logging: ${this.platformLogging}`);
2737
- }
2738
- /**
2739
- * Asynchronously retrieves the version of the plugin from the package.json file.
2740
- *
2741
- * This method reads the package.json file located in the parent directory,
2742
- * parses its content to extract the version, and logs the version using the debug logger.
2743
- * The extracted version is then assigned to the `version` property of the class.
2744
- *
2745
- * @returns {Promise<void>} A promise that resolves when the version has been retrieved and logged.
2746
- */
2747
- async getVersion() {
2748
- const { version } = JSON.parse(readFileSync(new URL('../package.json', import.meta.url), 'utf-8'));
2749
- this.debugLog(`Plugin Version: ${version}`);
2750
- this.version = version;
2751
- }
2752
- /**
2753
- * Validate and clean a string value for a Name Characteristic.
2754
- * @param displayName - The display name of the accessory.
2755
- * @param name - The name of the characteristic.
2756
- * @param value - The value to be validated and cleaned.
2757
- * @returns The cleaned string value.
2758
- */
2759
- async validateAndCleanDisplayName(displayName, name, value) {
2760
- if (this.config.options?.allowInvalidCharacters) {
2761
- return value;
2762
- }
2763
- else {
2764
- const validPattern = /^[\p{L}\p{N}][\p{L}\p{N} ']*[\p{L}\p{N}]$/u;
2765
- const invalidCharsPattern = /[^\p{L}\p{N} ']/gu;
2766
- const invalidStartEndPattern = /^[^\p{L}\p{N}]+|[^\p{L}\p{N}]+$/gu;
2767
- if (typeof value === 'string' && !validPattern.test(value)) {
2768
- this.warnLog(`WARNING: The accessory '${displayName}' has an invalid '${name}' characteristic ('${value}'). Please use only alphanumeric, space, and apostrophe characters. Ensure it starts and ends with an alphabetic or numeric character, and avoid emojis. This may prevent the accessory from being added in the Home App or cause unresponsiveness.`);
2769
- // Remove invalid characters
2770
- if (invalidCharsPattern.test(value)) {
2771
- const before = value;
2772
- this.warnLog(`Removing invalid characters from '${name}' characteristic, if you feel this is incorrect, please enable \'allowInvalidCharacter\' in the config to allow all characters`);
2773
- value = value.replace(invalidCharsPattern, '');
2774
- this.warnLog(`${name} Before: '${before}' After: '${value}'`);
2775
- }
2776
- // Ensure it starts and ends with an alphanumeric character
2777
- if (invalidStartEndPattern.test(value)) {
2778
- const before = value;
2779
- this.warnLog(`Removing invalid starting or ending characters from '${name}' characteristic, if you feel this is incorrect, please enable \'allowInvalidCharacter\' in the config to allow all characters`);
2780
- value = value.replace(invalidStartEndPattern, '');
2781
- this.warnLog(`${name} Before: '${before}' After: '${value}'`);
2782
- }
2783
- }
2784
- return value;
2785
- }
2786
- }
2787
- /**
2788
- * If device level logging is turned on, log to log.warn
2789
- * Otherwise send debug logs to log.debug
2790
- */
2791
- async infoLog(...log) {
2792
- if (await this.enablingPlatformLogging()) {
2793
- this.log.info(String(...log));
2794
- }
2795
- }
2796
- async successLog(...log) {
2797
- if (await this.enablingPlatformLogging()) {
2798
- this.log.success(String(...log));
2799
- }
2800
- }
2801
- async debugSuccessLog(...log) {
2802
- if (await this.enablingPlatformLogging()) {
2803
- if (await this.loggingIsDebug()) {
2804
- this.log.success('[DEBUG]', String(...log));
2805
- }
2806
- }
2807
- }
2808
- async warnLog(...log) {
2809
- if (await this.enablingPlatformLogging()) {
2810
- this.log.warn(String(...log));
2811
- }
2812
- }
2813
- async debugWarnLog(...log) {
2814
- if (await this.enablingPlatformLogging()) {
2815
- if (await this.loggingIsDebug()) {
2816
- this.log.warn('[DEBUG]', String(...log));
2817
- }
2818
- }
2819
- }
2820
- async errorLog(...log) {
2821
- if (await this.enablingPlatformLogging()) {
2822
- this.log.error(String(...log));
2823
- }
2824
- }
2825
- async debugErrorLog(...log) {
2826
- if (await this.enablingPlatformLogging()) {
2827
- if (await this.loggingIsDebug()) {
2828
- this.log.error('[DEBUG]', String(...log));
2829
- }
2830
- }
2831
- }
2832
- async debugLog(...log) {
2833
- if (await this.enablingPlatformLogging()) {
2834
- if (this.platformLogging === 'debug') {
2835
- this.log.info('[DEBUG]', String(...log));
2836
- }
2837
- else if (this.platformLogging === 'debugMode') {
2838
- this.log.debug(String(...log));
2839
- }
2840
- }
2841
- }
2842
- async loggingIsDebug() {
2843
- return this.platformLogging === 'debugMode' || this.platformLogging === 'debug';
2844
- }
2845
- async enablingPlatformLogging() {
2846
- return this.platformLogging === 'debugMode' || this.platformLogging === 'debug' || this.platformLogging === 'standard';
2847
- }
2848
- }
2849
- //# sourceMappingURL=platform-hap.js.map