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

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