@switchbot/homebridge-switchbot 5.0.0-beta.99 → 5.0.1

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 (287) hide show
  1. package/.changeset/config.json +14 -0
  2. package/.github/copilot-instructions.md +39 -0
  3. package/.github/scripts/normalize-changelog-header.cjs +86 -0
  4. package/.github/scripts/npm-version-script-esm-auto.js +201 -0
  5. package/.github/scripts/resolve-version-bump-esm.js +118 -0
  6. package/.github/workflows/ci.yml +4 -1
  7. package/.github/workflows/manual-e2e.yml +6 -3
  8. package/.github/workflows/release.yml +120 -22
  9. package/.github/workflows/stale.yml +2 -4
  10. package/.husky/pre-push +15 -0
  11. package/CHANGELOG.md +133 -137
  12. package/MIGRATION.md +16 -6
  13. package/README.md +84 -3
  14. package/TODO.md +263 -0
  15. package/config.schema.json +229 -36
  16. package/dist/SwitchBotHAPPlatform.d.ts +133 -0
  17. package/dist/SwitchBotHAPPlatform.d.ts.map +1 -0
  18. package/dist/SwitchBotHAPPlatform.js +555 -0
  19. package/dist/SwitchBotHAPPlatform.js.map +1 -0
  20. package/dist/SwitchBotMatterPlatform.d.ts +141 -0
  21. package/dist/SwitchBotMatterPlatform.d.ts.map +1 -0
  22. package/dist/SwitchBotMatterPlatform.js +536 -0
  23. package/dist/SwitchBotMatterPlatform.js.map +1 -0
  24. package/dist/device-types.d.ts +31 -0
  25. package/dist/device-types.d.ts.map +1 -0
  26. package/dist/device-types.js +246 -0
  27. package/dist/device-types.js.map +1 -0
  28. package/dist/deviceCommandMapper.d.ts +10 -0
  29. package/dist/deviceCommandMapper.d.ts.map +1 -0
  30. package/dist/deviceCommandMapper.js +319 -0
  31. package/dist/deviceCommandMapper.js.map +1 -0
  32. package/dist/deviceFactory.d.ts +3 -2
  33. package/dist/deviceFactory.d.ts.map +1 -1
  34. package/dist/deviceFactory.js +107 -29
  35. package/dist/deviceFactory.js.map +1 -1
  36. package/dist/devices/genericDevice.d.ts +59 -37
  37. package/dist/devices/genericDevice.d.ts.map +1 -1
  38. package/dist/devices/genericDevice.js +376 -78
  39. package/dist/devices/genericDevice.js.map +1 -1
  40. package/dist/errors.d.ts +38 -0
  41. package/dist/errors.d.ts.map +1 -0
  42. package/dist/errors.js +32 -0
  43. package/dist/errors.js.map +1 -0
  44. package/dist/homebridge-ui/device-types.js +246 -0
  45. package/dist/homebridge-ui/device-types.js.map +1 -0
  46. package/dist/homebridge-ui/deviceCommandMapper.js +319 -0
  47. package/dist/homebridge-ui/deviceCommandMapper.js.map +1 -0
  48. package/dist/homebridge-ui/endpoints/config.d.ts +3 -0
  49. package/dist/homebridge-ui/endpoints/config.d.ts.map +1 -0
  50. package/dist/homebridge-ui/endpoints/config.js +90 -0
  51. package/dist/homebridge-ui/endpoints/config.js.map +1 -0
  52. package/dist/homebridge-ui/endpoints/devices.d.ts +6 -0
  53. package/dist/homebridge-ui/endpoints/devices.d.ts.map +1 -0
  54. package/dist/homebridge-ui/endpoints/devices.js +144 -0
  55. package/dist/homebridge-ui/endpoints/devices.js.map +1 -0
  56. package/dist/homebridge-ui/endpoints/discovery.d.ts +7 -0
  57. package/dist/homebridge-ui/endpoints/discovery.d.ts.map +1 -0
  58. package/dist/homebridge-ui/endpoints/discovery.js +219 -0
  59. package/dist/homebridge-ui/endpoints/discovery.js.map +1 -0
  60. package/dist/homebridge-ui/errors.js +32 -0
  61. package/dist/homebridge-ui/errors.js.map +1 -0
  62. package/dist/homebridge-ui/homebridge-ui/endpoints/config.js +90 -0
  63. package/dist/homebridge-ui/homebridge-ui/endpoints/config.js.map +1 -0
  64. package/dist/homebridge-ui/homebridge-ui/endpoints/devices.js +144 -0
  65. package/dist/homebridge-ui/homebridge-ui/endpoints/devices.js.map +1 -0
  66. package/dist/homebridge-ui/homebridge-ui/endpoints/discovery.js +219 -0
  67. package/dist/homebridge-ui/homebridge-ui/endpoints/discovery.js.map +1 -0
  68. package/dist/homebridge-ui/homebridge-ui/server.js +11 -0
  69. package/dist/homebridge-ui/homebridge-ui/server.js.map +1 -0
  70. package/dist/homebridge-ui/homebridge-ui/utils/config-parser.js +108 -0
  71. package/dist/homebridge-ui/homebridge-ui/utils/config-parser.js.map +1 -0
  72. package/dist/homebridge-ui/homebridge-ui/utils/device-migration.js +111 -0
  73. package/dist/homebridge-ui/homebridge-ui/utils/device-migration.js.map +1 -0
  74. package/dist/homebridge-ui/homebridge-ui/utils/logger.js +17 -0
  75. package/dist/homebridge-ui/homebridge-ui/utils/logger.js.map +1 -0
  76. package/dist/homebridge-ui/public/css/styles.css +483 -0
  77. package/dist/homebridge-ui/public/index.html +197 -621
  78. package/dist/homebridge-ui/public/js/advanced-settings.d.ts +3 -0
  79. package/dist/homebridge-ui/public/js/advanced-settings.d.ts.map +1 -0
  80. package/dist/homebridge-ui/public/js/advanced-settings.js +95 -0
  81. package/dist/homebridge-ui/public/js/advanced-settings.js.map +1 -0
  82. package/dist/homebridge-ui/public/js/advanced-settings.ts +94 -0
  83. package/dist/homebridge-ui/public/js/api.d.ts +67 -0
  84. package/dist/homebridge-ui/public/js/api.d.ts.map +1 -0
  85. package/dist/homebridge-ui/public/js/api.js +308 -0
  86. package/dist/homebridge-ui/public/js/api.js.map +1 -0
  87. package/dist/homebridge-ui/public/js/api.ts +370 -0
  88. package/dist/homebridge-ui/public/js/app.d.ts +2 -0
  89. package/dist/homebridge-ui/public/js/app.d.ts.map +1 -0
  90. package/dist/homebridge-ui/public/js/app.js +3723 -0
  91. package/dist/homebridge-ui/public/js/app.js.map +7 -0
  92. package/dist/homebridge-ui/public/js/app.ts +22 -0
  93. package/dist/homebridge-ui/public/js/constants.d.ts +2 -0
  94. package/dist/homebridge-ui/public/js/constants.d.ts.map +1 -0
  95. package/dist/homebridge-ui/public/js/constants.js +2 -0
  96. package/dist/homebridge-ui/public/js/constants.js.map +1 -0
  97. package/dist/homebridge-ui/public/js/constants.ts +1 -0
  98. package/dist/homebridge-ui/public/js/credentials.d.ts +3 -0
  99. package/dist/homebridge-ui/public/js/credentials.d.ts.map +1 -0
  100. package/dist/homebridge-ui/public/js/credentials.js +99 -0
  101. package/dist/homebridge-ui/public/js/credentials.js.map +1 -0
  102. package/dist/homebridge-ui/public/js/credentials.ts +105 -0
  103. package/dist/homebridge-ui/public/js/devices-delete.d.ts +3 -0
  104. package/dist/homebridge-ui/public/js/devices-delete.d.ts.map +1 -0
  105. package/dist/homebridge-ui/public/js/devices-delete.js +199 -0
  106. package/dist/homebridge-ui/public/js/devices-delete.js.map +1 -0
  107. package/dist/homebridge-ui/public/js/devices-delete.ts +227 -0
  108. package/dist/homebridge-ui/public/js/devices.d.ts +9 -0
  109. package/dist/homebridge-ui/public/js/devices.d.ts.map +1 -0
  110. package/dist/homebridge-ui/public/js/devices.js +98 -0
  111. package/dist/homebridge-ui/public/js/devices.js.map +1 -0
  112. package/dist/homebridge-ui/public/js/devices.ts +106 -0
  113. package/dist/homebridge-ui/public/js/discovery.d.ts +9 -0
  114. package/dist/homebridge-ui/public/js/discovery.d.ts.map +1 -0
  115. package/dist/homebridge-ui/public/js/discovery.js +1201 -0
  116. package/dist/homebridge-ui/public/js/discovery.js.map +1 -0
  117. package/dist/homebridge-ui/public/js/discovery.ts +1335 -0
  118. package/dist/homebridge-ui/public/js/logger.d.ts +7 -0
  119. package/dist/homebridge-ui/public/js/logger.d.ts.map +1 -0
  120. package/dist/homebridge-ui/public/js/logger.js +17 -0
  121. package/dist/homebridge-ui/public/js/logger.js.map +1 -0
  122. package/dist/homebridge-ui/public/js/logger.ts +17 -0
  123. package/dist/homebridge-ui/public/js/modal.d.ts +5 -0
  124. package/dist/homebridge-ui/public/js/modal.d.ts.map +1 -0
  125. package/dist/homebridge-ui/public/js/modal.js +35 -0
  126. package/dist/homebridge-ui/public/js/modal.js.map +1 -0
  127. package/dist/homebridge-ui/public/js/modal.ts +35 -0
  128. package/dist/homebridge-ui/public/js/modals.d.ts +15 -0
  129. package/dist/homebridge-ui/public/js/modals.d.ts.map +1 -0
  130. package/dist/homebridge-ui/public/js/modals.js +675 -0
  131. package/dist/homebridge-ui/public/js/modals.js.map +1 -0
  132. package/dist/homebridge-ui/public/js/modals.ts +765 -0
  133. package/dist/homebridge-ui/public/js/render.d.ts +71 -0
  134. package/dist/homebridge-ui/public/js/render.d.ts.map +1 -0
  135. package/dist/homebridge-ui/public/js/render.js +948 -0
  136. package/dist/homebridge-ui/public/js/render.js.map +1 -0
  137. package/dist/homebridge-ui/public/js/render.ts +1070 -0
  138. package/dist/homebridge-ui/public/js/toast.d.ts +6 -0
  139. package/dist/homebridge-ui/public/js/toast.d.ts.map +1 -0
  140. package/dist/homebridge-ui/public/js/toast.js +37 -0
  141. package/dist/homebridge-ui/public/js/toast.js.map +1 -0
  142. package/dist/homebridge-ui/public/js/toast.ts +43 -0
  143. package/dist/homebridge-ui/public/js/types.d.ts +23 -0
  144. package/dist/homebridge-ui/public/js/types.d.ts.map +1 -0
  145. package/dist/homebridge-ui/public/js/types.js +2 -0
  146. package/dist/homebridge-ui/public/js/types.js.map +1 -0
  147. package/dist/homebridge-ui/public/js/types.ts +26 -0
  148. package/dist/homebridge-ui/server.d.ts +1 -3
  149. package/dist/homebridge-ui/server.d.ts.map +1 -1
  150. package/dist/homebridge-ui/server.js +8 -471
  151. package/dist/homebridge-ui/server.js.map +1 -1
  152. package/dist/homebridge-ui/settings.js +8 -0
  153. package/dist/homebridge-ui/settings.js.map +1 -0
  154. package/dist/homebridge-ui/switchbotClient.js +247 -0
  155. package/dist/homebridge-ui/switchbotClient.js.map +1 -0
  156. package/dist/homebridge-ui/utils/config-parser.d.ts +39 -0
  157. package/dist/homebridge-ui/utils/config-parser.d.ts.map +1 -0
  158. package/dist/homebridge-ui/utils/config-parser.js +108 -0
  159. package/dist/homebridge-ui/utils/config-parser.js.map +1 -0
  160. package/dist/homebridge-ui/utils/device-migration.d.ts +35 -0
  161. package/dist/homebridge-ui/utils/device-migration.d.ts.map +1 -0
  162. package/dist/homebridge-ui/utils/device-migration.js +111 -0
  163. package/dist/homebridge-ui/utils/device-migration.js.map +1 -0
  164. package/dist/homebridge-ui/utils/logger.d.ts +7 -0
  165. package/dist/homebridge-ui/utils/logger.d.ts.map +1 -0
  166. package/dist/homebridge-ui/utils/logger.js +17 -0
  167. package/dist/homebridge-ui/utils/logger.js.map +1 -0
  168. package/dist/index.d.ts +10 -0
  169. package/dist/index.d.ts.map +1 -1
  170. package/dist/index.js +12 -2
  171. package/dist/index.js.map +1 -1
  172. package/dist/settings.d.ts +1 -0
  173. package/dist/settings.d.ts.map +1 -1
  174. package/dist/settings.js +1 -0
  175. package/dist/settings.js.map +1 -1
  176. package/dist/switchbotClient.d.ts +12 -10
  177. package/dist/switchbotClient.d.ts.map +1 -1
  178. package/dist/switchbotClient.js +156 -103
  179. package/dist/switchbotClient.js.map +1 -1
  180. package/dist/utils.d.ts +76 -1
  181. package/dist/utils.d.ts.map +1 -1
  182. package/dist/utils.js +1121 -4
  183. package/dist/utils.js.map +1 -1
  184. package/docs/assets/highlight.css +16 -2
  185. package/docs/assets/icons.js +1 -1
  186. package/docs/assets/icons.svg +1 -1
  187. package/docs/assets/main.js +3 -3
  188. package/docs/index.html +82 -5
  189. package/docs/variables/default.html +3 -1
  190. package/eslint.config.js +9 -5
  191. package/nodemon.json +2 -2
  192. package/package.json +35 -22
  193. package/scripts/build-ui.js +37 -0
  194. package/scripts/free-dev-ports.mjs +105 -0
  195. package/scripts/generate-matter-maps.js +34 -17
  196. package/scripts/sync-device-types.mjs +31 -0
  197. package/src/SwitchBotHAPPlatform.ts +558 -0
  198. package/src/SwitchBotMatterPlatform.ts +538 -0
  199. package/src/device-types.js +246 -0
  200. package/src/device-types.js.map +1 -0
  201. package/src/device-types.ts +261 -0
  202. package/src/deviceCommandMapper.js +319 -0
  203. package/src/deviceCommandMapper.js.map +1 -0
  204. package/src/deviceCommandMapper.ts +333 -0
  205. package/src/deviceFactory.ts +125 -45
  206. package/src/devices/genericDevice.ts +411 -69
  207. package/src/errors.js +32 -0
  208. package/src/errors.js.map +1 -0
  209. package/src/errors.ts +35 -0
  210. package/src/homebridge-ui/endpoints/config.ts +110 -0
  211. package/src/homebridge-ui/endpoints/devices.ts +153 -0
  212. package/src/homebridge-ui/endpoints/discovery.ts +240 -0
  213. package/src/homebridge-ui/public/css/styles.css +483 -0
  214. package/src/homebridge-ui/public/index.html +197 -621
  215. package/src/homebridge-ui/public/js/advanced-settings.ts +94 -0
  216. package/src/homebridge-ui/public/js/api.ts +370 -0
  217. package/src/homebridge-ui/public/js/app.ts +22 -0
  218. package/src/homebridge-ui/public/js/constants.ts +1 -0
  219. package/src/homebridge-ui/public/js/credentials.ts +105 -0
  220. package/src/homebridge-ui/public/js/devices-delete.ts +227 -0
  221. package/src/homebridge-ui/public/js/devices.ts +106 -0
  222. package/src/homebridge-ui/public/js/discovery.ts +1335 -0
  223. package/src/homebridge-ui/public/js/logger.ts +17 -0
  224. package/src/homebridge-ui/public/js/modal.ts +35 -0
  225. package/src/homebridge-ui/public/js/modals.ts +765 -0
  226. package/src/homebridge-ui/public/js/render.ts +1070 -0
  227. package/src/homebridge-ui/public/js/toast.ts +43 -0
  228. package/src/homebridge-ui/public/js/types.ts +26 -0
  229. package/src/homebridge-ui/server.ts +9 -554
  230. package/src/homebridge-ui/utils/config-parser.ts +125 -0
  231. package/src/homebridge-ui/utils/device-migration.ts +144 -0
  232. package/src/homebridge-ui/utils/logger.ts +17 -0
  233. package/src/index.ts +12 -2
  234. package/src/settings.js +8 -0
  235. package/src/settings.js.map +1 -0
  236. package/src/settings.ts +2 -0
  237. package/src/switchbotClient.js +247 -0
  238. package/src/switchbotClient.js.map +1 -0
  239. package/src/switchbotClient.ts +177 -114
  240. package/src/utils.ts +1133 -5
  241. package/test/client/switchbot-client-debounce.spec.ts +35 -0
  242. package/test/client/switchbot-client-openapi.spec.ts +19 -0
  243. package/test/client/switchbotClient.spec.ts +64 -0
  244. package/test/device/device-mapping.spec.ts +23 -0
  245. package/test/device/deviceBase.spec.ts +26 -0
  246. package/test/device/deviceFactory-edge.spec.ts +15 -0
  247. package/test/device/deviceFactory.spec.ts +33 -0
  248. package/test/device/fan-swing.spec.ts +34 -0
  249. package/test/device/genericDevice-blepoll.spec.ts +47 -0
  250. package/test/device/irdevice.spec.ts +9 -0
  251. package/test/device/lock-users.spec.ts +35 -0
  252. package/test/device/matter-descriptors.spec.ts +22 -0
  253. package/test/device/matter-device-state.spec.ts +37 -0
  254. package/test/e2e/run-e2e.spec.ts +18 -19
  255. package/test/errors/errors.spec.ts +10 -0
  256. package/test/helpers/matter-harness.ts +20 -9
  257. package/test/homebridge-ui/server.spec.ts +9 -0
  258. package/test/platform/accessory-restore.spec.ts +37 -0
  259. package/test/platform/matter-childbridge.spec.ts +34 -0
  260. package/test/platform/matter-integration.spec.ts +33 -0
  261. package/test/platform/platform-edge.spec.ts +73 -0
  262. package/test/platform/platform.integration.spec.ts +34 -0
  263. package/test/utils/utils-extra.spec.ts +10 -0
  264. package/test/utils/utils.spec.ts +53 -0
  265. package/todo/TODO.md +80 -0
  266. package/tsconfig.ui.json +11 -0
  267. package/.github/npm-version-script-esm.js +0 -97
  268. package/.github/workflows/beta-release.yml +0 -52
  269. package/dist/platform.d.ts +0 -35
  270. package/dist/platform.d.ts.map +0 -1
  271. package/dist/platform.js +0 -945
  272. package/dist/platform.js.map +0 -1
  273. package/src/platform.ts +0 -963
  274. package/test/accessory-restore.spec.ts +0 -73
  275. package/test/device-mapping.spec.ts +0 -37
  276. package/test/deviceFactory.spec.ts +0 -18
  277. package/test/fan-swing.spec.ts +0 -29
  278. package/test/lock-users.spec.ts +0 -44
  279. package/test/matter-childbridge.spec.ts +0 -55
  280. package/test/matter-descriptors.spec.ts +0 -97
  281. package/test/matter-device-state.spec.ts +0 -101
  282. package/test/matter-integration.spec.ts +0 -70
  283. package/test/platform.integration.spec.ts +0 -55
  284. package/test/switchbot-client-debounce.spec.ts +0 -131
  285. package/test/switchbot-client-openapi.spec.ts +0 -56
  286. package/test/switchbotClient.spec.ts +0 -10
  287. package/test/utils.spec.ts +0 -20
package/docs/index.html CHANGED
@@ -19,6 +19,27 @@
19
19
  <li>Click <strong>Install</strong></li>
20
20
  </ol>
21
21
  <h2 id="configuration" class="tsd-anchor-link">Configuration<a href="#configuration" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="assets/icons.svg#icon-anchor"></use></svg></a></h2>
22
+ <h3 id="openapi-pollingrate-advanced-settings-ui" class="tsd-anchor-link">OpenAPI Polling/Rate Advanced Settings (UI)<a href="#openapi-pollingrate-advanced-settings-ui" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="assets/icons.svg#icon-anchor"></use></svg></a></h3>
23
+ <p>You can now configure global OpenAPI polling and rate-limiting options directly from the Homebridge UI:</p>
24
+ <ul>
25
+ <li>Go to the SwitchBot plugin settings in Homebridge Config UI X.</li>
26
+ <li>Scroll to the <strong>Advanced Settings</strong> section at the bottom of the page.</li>
27
+ <li>Adjust the following options as needed:
28
+ <ul>
29
+ <li><strong>OpenAPI Polling Interval (seconds):</strong> How often to poll devices via OpenAPI for status. Default: 300 (5 min). Min: 30. Can be overridden per device.</li>
30
+ <li><strong>Enable Batched OpenAPI Polling:</strong> Poll all OpenAPI devices in a single batch at the configured interval. Devices with per-device refreshRate are excluded from the batch.</li>
31
+ <li><strong>OpenAPI Batch Polling Interval (seconds):</strong> Interval for batched OpenAPI polling. Falls back to OpenAPI Polling Interval if not set. Default: 300.</li>
32
+ <li><strong>OpenAPI Daily Request Limit:</strong> Maximum OpenAPI requests per day allowed by the plugin. Default: 10000.</li>
33
+ <li><strong>OpenAPI Reserve for Commands:</strong> Requests reserved for user actions. When remaining budget reaches this value, background polling pauses. Default: 1000.</li>
34
+ <li><strong>Reset OpenAPI Counter at Local Midnight:</strong> If true, resets the daily OpenAPI request counter at local midnight. If false, resets at UTC midnight.</li>
35
+ <li><strong>Only Allow Webhooks on Reserve:</strong> When remaining OpenAPI budget reaches the reserve, only webhooks and user commands are allowed. Background polling/discovery pauses.</li>
36
+ <li><strong>OpenAPI Batch Concurrency:</strong> Maximum number of parallel OpenAPI status calls during a batch. Default: 5.</li>
37
+ <li><strong>OpenAPI Batch Jitter (seconds):</strong> Random startup delay before the first batch to reduce synchronized spikes. Default: 0.</li>
38
+ </ul>
39
+ </li>
40
+ </ul>
41
+ <p>Click <strong>Save Advanced Settings</strong> to apply changes. These settings match the options available in <code>config.schema.json</code> and can be overridden per device.</p>
42
+ <!-- Optionally add a screenshot here -->
22
43
  <ul>
23
44
  <li>
24
45
  <h3 id="if-using-openapi-connection" class="tsd-anchor-link">If using OpenAPI Connection<a href="#if-using-openapi-connection" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="assets/icons.svg#icon-anchor"></use></svg></a></h3>
@@ -281,6 +302,15 @@ Without this step, then you will receive the following error when the swichbot p
281
302
  </li>
282
303
  </ul>
283
304
  </li>
305
+ <li><a href="https://us.switch-bot.com/products/switchbot-hub-mini-2">SwitchBot Hub Mini 2</a>
306
+ <ul>
307
+ <li>Supports OpenAPI &amp; Bluetooth Low Energy (BLE) Connections
308
+ <ul>
309
+ <li>Enables Humidity, Temperature, and Light Sensor</li>
310
+ </ul>
311
+ </li>
312
+ </ul>
313
+ </li>
284
314
  <li><a href="https://us.switch-bot.com/products/switchbot-hub-3">SwitchBot Hub 3</a>
285
315
  <ul>
286
316
  <li>Supports OpenAPI &amp; Bluetooth Low Energy (BLE) Connections
@@ -301,8 +331,34 @@ Without this step, then you will receive the following error when the swichbot p
301
331
  </ul>
302
332
  </li>
303
333
  </ul>
334
+ <h2 id="ble-encryption-support" class="tsd-anchor-link">BLE Encryption Support<a href="#ble-encryption-support" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="assets/icons.svg#icon-anchor"></use></svg></a></h2>
335
+ <h3 id="ble-encryption-key-and-key-id" class="tsd-anchor-link">BLE Encryption Key and Key ID<a href="#ble-encryption-key-and-key-id" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="assets/icons.svg#icon-anchor"></use></svg></a></h3>
336
+ <p>Some SwitchBot devices (notably newer locks, curtains, and select sensors) require a BLE encryption key and keyId for secure Bluetooth communication. This plugin supports configuring these fields for each device.</p>
337
+ <h4 id="how-to-obtain-ble-encryption-key-and-key-id" class="tsd-anchor-link">How to Obtain BLE Encryption Key and Key ID<a href="#how-to-obtain-ble-encryption-key-and-key-id" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="assets/icons.svg#icon-anchor"></use></svg></a></h4>
338
+ <ol>
339
+ <li><strong>Open the SwitchBot App</strong> and select your device.</li>
340
+ <li>Go to <strong>Device Settings</strong> (gear icon).</li>
341
+ <li>Tap <strong>Device Info</strong>.</li>
342
+ <li>If your device supports BLE encryption, you will see fields for <strong>Encryption Key</strong> and <strong>Key ID</strong>. (If not visible, your device may not require encryption or may need a firmware update.)</li>
343
+ <li>Copy the <strong>Encryption Key</strong> and <strong>Key ID</strong> values.</li>
344
+ </ol>
345
+ <h4 id="how-to-configure-in-homebridge" class="tsd-anchor-link">How to Configure in Homebridge<a href="#how-to-configure-in-homebridge" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="assets/icons.svg#icon-anchor"></use></svg></a></h4>
346
+ <p>In the Homebridge UI, when adding or editing a SwitchBot device, enter the <strong>Encryption Key</strong> and <strong>Key ID</strong> in the provided fields. These values will be securely used for BLE communication with your device.</p>
347
+ <p><strong>Example device config excerpt:</strong></p>
348
+ <pre><code class="json"><span class="hl-1">{</span><br/><span class="hl-1"> </span><span class="hl-6">&quot;deviceId&quot;</span><span class="hl-1">: </span><span class="hl-7">&quot;E7F8A1B2C3D4&quot;</span><span class="hl-1">,</span><br/><span class="hl-1"> </span><span class="hl-6">&quot;deviceName&quot;</span><span class="hl-1">: </span><span class="hl-7">&quot;SwitchBot Lock&quot;</span><span class="hl-1">,</span><br/><span class="hl-1"> </span><span class="hl-6">&quot;enableBLE&quot;</span><span class="hl-1">: </span><span class="hl-8">true</span><span class="hl-1">,</span><br/><span class="hl-1"> </span><span class="hl-6">&quot;encryptionKey&quot;</span><span class="hl-1">: </span><span class="hl-7">&quot;0123456789abcdef0123456789abcdef&quot;</span><span class="hl-1">,</span><br/><span class="hl-1"> </span><span class="hl-6">&quot;keyId&quot;</span><span class="hl-1">: </span><span class="hl-7">&quot;01&quot;</span><br/><span class="hl-1">}</span>
349
+ </code><button type="button">Copy</button></pre>
350
+
351
+ <h4 id="which-devices-require-ble-encryption" class="tsd-anchor-link">Which Devices Require BLE Encryption?<a href="#which-devices-require-ble-encryption" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="assets/icons.svg#icon-anchor"></use></svg></a></h4>
352
+ <ul>
353
+ <li>SwitchBot Lock (and Lock Pro)</li>
354
+ <li>SwitchBot Curtain 3 (and some Curtain 2 with updated firmware)</li>
355
+ <li>Some sensors and new device models (see device info in app)</li>
356
+ </ul>
357
+ <p>If you are unsure, check your device's info in the SwitchBot app. If the fields are present, copy them into the plugin config.</p>
358
+ <p><strong>Note:</strong> If you enter an incorrect key or keyId, BLE communication will fail for that device. Double-check values if you encounter connection issues.</p>
359
+ <hr>
304
360
  <h2 id="supported-ir-devices" class="tsd-anchor-link">Supported IR Devices<a href="#supported-ir-devices" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="assets/icons.svg#icon-anchor"></use></svg></a></h2>
305
- <h3 id="all-ir-devices-require-switchbot-hub-2-switchbot-hub-3-or-hub-mini" class="tsd-anchor-link"><em>(All IR Devices require <a href="https://us.switch-bot.com/products/switchbot-hub-2">SwitchBot Hub 2</a>, <a href="https://us.switch-bot.com/products/switchbot-hub-3">SwitchBot Hub 3</a>, or <a href="https://www.switch-bot.com/products/switchbot-hub-mini">Hub Mini</a>)</em><a href="#all-ir-devices-require-switchbot-hub-2-switchbot-hub-3-or-hub-mini" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="assets/icons.svg#icon-anchor"></use></svg></a></h3>
361
+ <h3 id="all-ir-devices-require-switchbot-hub-2-switchbot-hub-mini-2-switchbot-hub-3-or-hub-mini" class="tsd-anchor-link"><em>(All IR Devices require <a href="https://us.switch-bot.com/products/switchbot-hub-2">SwitchBot Hub 2</a>, <a href="https://us.switch-bot.com/products/switchbot-hub-mini-2">SwitchBot Hub Mini 2</a>, <a href="https://us.switch-bot.com/products/switchbot-hub-3">SwitchBot Hub 3</a>, or <a href="https://www.switch-bot.com/products/switchbot-hub-mini">Hub Mini</a>)</em><a href="#all-ir-devices-require-switchbot-hub-2-switchbot-hub-mini-2-switchbot-hub-3-or-hub-mini" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="assets/icons.svg#icon-anchor"></use></svg></a></h3>
306
362
  <ul>
307
363
  <li>TV
308
364
  <ul>
@@ -404,13 +460,16 @@ Without this step, then you will receive the following error when the swichbot p
404
460
  <li>The batch worklist is randomized every cycle to further distribute API load.</li>
405
461
  </ul>
406
462
  <p>These controls keep API usage smooth and predictable while preserving per-device control when needed.</p>
407
- <h2 id="whats-new-in-the-v4-beta-summary" class="tsd-anchor-link">What's new in the v4 beta (summary)<a href="#whats-new-in-the-v4-beta-summary" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="assets/icons.svg#icon-anchor"></use></svg></a></h2>
463
+ <h2 id="whats-new-with-node-switchbot-v400" class="tsd-anchor-link">What's new with node-switchbot v4.0.0<a href="#whats-new-with-node-switchbot-v400" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="assets/icons.svg#icon-anchor"></use></svg></a></h2>
408
464
  <ul>
409
465
  <li>
410
466
  <p>Matter-first: when Homebridge Matter is available the plugin now prefers registering Matter accessories (with HAP fallback).</p>
411
467
  </li>
412
468
  <li>
413
- <p>Hybrid client: the plugin dynamically imports <code>node-switchbot@4</code> if available and falls back to OpenAPI when <code>openApiToken</code> is configured.</p>
469
+ <p>Hybrid client: the plugin uses <code>node-switchbot@^4.0.0</code> with BLE + OpenAPI discovery and OpenAPI fallback.</p>
470
+ </li>
471
+ <li>
472
+ <p>OpenAPI credentials: cloud discovery and cloud fallback paths require both <code>openApiToken</code> and <code>openApiSecret</code>.</p>
414
473
  </li>
415
474
  <li>
416
475
  <p>UI always served: the plugin UI is packaged into <code>dist/homebridge-ui</code> and is always served when Homebridge UI support is present; there is no platform-level opt-out.</p>
@@ -419,6 +478,9 @@ Without this step, then you will receive the following error when the swichbot p
419
478
  <p>OpenAPI hardening: OpenAPI calls have AbortController timeouts, jittered exponential backoff, per-device retry limits and cooldowns, and safe response parsing for resilient behavior.</p>
420
479
  </li>
421
480
  <li>
481
+ <p>v4 resilience enabled in discovery: plugin discovery enables retry, circuit-breaker, and connection-intelligence flags from <code>node-switchbot</code> v4.</p>
482
+ </li>
483
+ <li>
422
484
  <p>Write coalescing (debounce): command writes to the same device are coalesced by default to avoid command floods. Configure with <code>writeDebounceMs</code> (milliseconds, default 100). Set to <code>0</code> to disable coalescing.</p>
423
485
  </li>
424
486
  </ul>
@@ -432,7 +494,7 @@ Without this step, then you will receive the following error when the swichbot p
432
494
  <li><code>dailyApiResetLocalMidnight</code> (boolean, default false): if true, resets the daily counter at local midnight; when false, resets at UTC midnight.</li>
433
495
  </ul>
434
496
  <p>Example (excerpt):</p>
435
- <pre><code class="json"><span class="hl-1">{</span><br/><span class="hl-1"> </span><span class="hl-6">&quot;options&quot;</span><span class="hl-1">: {</span><br/><span class="hl-1"> </span><span class="hl-6">&quot;dailyApiLimit&quot;</span><span class="hl-1">: </span><span class="hl-5">10000</span><span class="hl-1">,</span><br/><span class="hl-1"> </span><span class="hl-6">&quot;dailyApiReserveForCommands&quot;</span><span class="hl-1">: </span><span class="hl-5">1000</span><span class="hl-1">,</span><br/><span class="hl-1"> </span><span class="hl-6">&quot;webhookOnlyOnReserve&quot;</span><span class="hl-1">: </span><span class="hl-7">false</span><span class="hl-1">,</span><br/><span class="hl-1"> </span><span class="hl-6">&quot;dailyApiResetLocalMidnight&quot;</span><span class="hl-1">: </span><span class="hl-7">true</span><br/><span class="hl-1"> }</span><br/><span class="hl-1">}</span>
497
+ <pre><code class="json"><span class="hl-1">{</span><br/><span class="hl-1"> </span><span class="hl-6">&quot;options&quot;</span><span class="hl-1">: {</span><br/><span class="hl-1"> </span><span class="hl-6">&quot;dailyApiLimit&quot;</span><span class="hl-1">: </span><span class="hl-5">10000</span><span class="hl-1">,</span><br/><span class="hl-1"> </span><span class="hl-6">&quot;dailyApiReserveForCommands&quot;</span><span class="hl-1">: </span><span class="hl-5">1000</span><span class="hl-1">,</span><br/><span class="hl-1"> </span><span class="hl-6">&quot;webhookOnlyOnReserve&quot;</span><span class="hl-1">: </span><span class="hl-8">false</span><span class="hl-1">,</span><br/><span class="hl-1"> </span><span class="hl-6">&quot;dailyApiResetLocalMidnight&quot;</span><span class="hl-1">: </span><span class="hl-8">true</span><br/><span class="hl-1"> }</span><br/><span class="hl-1">}</span>
436
498
  </code><button type="button">Copy</button></pre>
437
499
 
438
500
  <h2 id="switchbot-apis" class="tsd-anchor-link">SwitchBot APIs<a href="#switchbot-apis" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="assets/icons.svg#icon-anchor"></use></svg></a></h2>
@@ -444,10 +506,25 @@ Without this step, then you will receive the following error when the swichbot p
444
506
  </ul>
445
507
  </li>
446
508
  </ul>
509
+ <h2 id="development-tests" class="tsd-anchor-link">Development / Tests<a href="#development-tests" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="assets/icons.svg#icon-anchor"></use></svg></a></h2>
510
+ <ul>
511
+ <li>
512
+ <p>Run unit tests:</p>
513
+ <pre><code class="bash"><span class="hl-9">npm</span><span class="hl-1"> </span><span class="hl-7">run</span><span class="hl-1"> </span><span class="hl-7">test</span>
514
+ </code><button type="button">Copy</button></pre>
515
+
516
+ </li>
517
+ <li>
518
+ <p>Notes:</p>
519
+ <ul>
520
+ <li>Added Lock Ultra (Cloud + BLE) support with <code>node-switchbot</code> v4.</li>
521
+ </ul>
522
+ </li>
523
+ </ul>
447
524
  <h2 id="community" class="tsd-anchor-link">Community<a href="#community" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="assets/icons.svg#icon-anchor"></use></svg></a></h2>
448
525
  <ul>
449
526
  <li><a href="https://www.switch-bot.com/">SwitchBot (Official website)</a></li>
450
527
  <li><a href="https://www.facebook.com/SwitchBotRobot/">Facebook @SwitchBotRobot</a></li>
451
528
  <li><a href="https://twitter.com/switchbot">Twitter @SwitchBot</a></li>
452
529
  </ul>
453
- </div></div><div class="col-sidebar"><div class="page-menu"><div class="tsd-navigation settings"><details class="tsd-accordion"><summary class="tsd-accordion-summary"><svg width="20" height="20" viewBox="0 0 24 24" fill="none" aria-hidden="true"><use href="assets/icons.svg#icon-chevronDown"></use></svg><h3>Settings</h3></summary><div class="tsd-accordion-details"><div class="tsd-filter-visibility"><span class="settings-label">Member Visibility</span><ul id="tsd-filter-options"><li class="tsd-filter-item"><label class="tsd-filter-input"><input type="checkbox" id="tsd-filter-inherited" name="inherited" checked/><svg width="32" height="32" viewBox="0 0 32 32" aria-hidden="true"><rect class="tsd-checkbox-background" width="30" height="30" x="1" y="1" rx="6" fill="none"></rect><path class="tsd-checkbox-checkmark" d="M8.35422 16.8214L13.2143 21.75L24.6458 10.25" stroke="none" stroke-width="3.5" stroke-linejoin="round" fill="none"></path></svg><span>Inherited</span></label></li></ul></div><div class="tsd-theme-toggle"><label class="settings-label" for="tsd-theme">Theme</label><select id="tsd-theme"><option value="os">OS</option><option value="light">Light</option><option value="dark">Dark</option></select></div></div></details></div><details open class="tsd-accordion tsd-page-navigation"><summary class="tsd-accordion-summary"><svg width="20" height="20" viewBox="0 0 24 24" fill="none" aria-hidden="true"><use href="assets/icons.svg#icon-chevronDown"></use></svg><h3>On This Page</h3></summary><div class="tsd-accordion-details"><a href="#switchbothomebridge-switchbot"><span>@switchbot/homebridge-<wbr/>switchbot</span></a><ul><li><a href="#installation"><span>Installation</span></a></li><li><a href="#configuration"><span>Configuration</span></a></li><li><ul><li><a href="#if-using-openapi-connection"><span>If using <wbr/>Open<wbr/>API <wbr/>Connection</span></a></li><li><a href="#if-using-ble-connection"><span>If using <wbr/>BLE <wbr/>Connection</span></a></li></ul></li><li><a href="#troubleshooting"><span>Troubleshooting</span></a></li><li><ul><li><a href="#if-using-linux-raspberry-pi-os"><span>If using <wbr/>Linux / <wbr/>Raspberry <wbr/>Pi <wbr/>OS</span></a></li><li><a href="#if-using-macos"><span>If using <wbr/>Mac<wbr/>OS</span></a></li></ul></li><li><a href="#supported-switchbot-devices"><span>Supported <wbr/>Switch<wbr/>Bot <wbr/>Devices</span></a></li><li><a href="#supported-ir-devices"><span>Supported <wbr/>IR <wbr/>Devices</span></a></li><li><ul><li><a href="#all-ir-devices-require-switchbot-hub-2-switchbot-hub-3-or-hub-mini"><span>(<wbr/>All <wbr/>IR <wbr/>Devices require <wbr/>Switch<wbr/>Bot <wbr/>Hub 2, <wbr/>Switch<wbr/>Bot <wbr/>Hub 3, or <wbr/>Hub <wbr/>Mini)</span></a></li></ul></li><li><a href="#matter-platform"><span>Matter <wbr/>Platform</span></a></li><li><ul><li><a href="#batched-refresh-and-api-load-control"><span>Batched refresh and <wbr/>API load control</span></a></li></ul></li><li><a href="#whats-new-in-the-v4-beta-summary"><span>What&#39;s new in the v4 beta (summary)</span></a></li><li><a href="#openapi-rate-limiting-and-daily-budget"><span>Open<wbr/>API rate limiting and daily budget</span></a></li><li><a href="#switchbot-apis"><span>Switch<wbr/>Bot <wbr/>AP<wbr/>Is</span></a></li><li><a href="#community"><span>Community</span></a></li></ul></div></details></div><div class="site-menu"><nav class="tsd-navigation"><a href="modules.html">@switchbot/homebridge-switchbot</a><ul class="tsd-small-nested-navigation" id="tsd-nav-container"><li>Loading...</li></ul></nav></div></div></div><footer></footer><div class="overlay"></div></body></html>
530
+ </div></div><div class="col-sidebar"><div class="page-menu"><div class="tsd-navigation settings"><details class="tsd-accordion"><summary class="tsd-accordion-summary"><svg width="20" height="20" viewBox="0 0 24 24" fill="none" aria-hidden="true"><use href="assets/icons.svg#icon-chevronDown"></use></svg><h3>Settings</h3></summary><div class="tsd-accordion-details"><div class="tsd-filter-visibility"><span class="settings-label">Member Visibility</span><ul id="tsd-filter-options"><li class="tsd-filter-item"><label class="tsd-filter-input"><input type="checkbox" id="tsd-filter-inherited" name="inherited" checked/><svg width="32" height="32" viewBox="0 0 32 32" aria-hidden="true"><rect class="tsd-checkbox-background" width="30" height="30" x="1" y="1" rx="6" fill="none"></rect><path class="tsd-checkbox-checkmark" d="M8.35422 16.8214L13.2143 21.75L24.6458 10.25" stroke="none" stroke-width="3.5" stroke-linejoin="round" fill="none"></path></svg><span>Inherited</span></label></li></ul></div><div class="tsd-theme-toggle"><label class="settings-label" for="tsd-theme">Theme</label><select id="tsd-theme"><option value="os">OS</option><option value="light">Light</option><option value="dark">Dark</option></select></div></div></details></div><details open class="tsd-accordion tsd-page-navigation"><summary class="tsd-accordion-summary"><svg width="20" height="20" viewBox="0 0 24 24" fill="none" aria-hidden="true"><use href="assets/icons.svg#icon-chevronDown"></use></svg><h3>On This Page</h3></summary><div class="tsd-accordion-details"><a href="#switchbothomebridge-switchbot"><span>@switchbot/homebridge-<wbr/>switchbot</span></a><ul><li><a href="#installation"><span>Installation</span></a></li><li><a href="#configuration"><span>Configuration</span></a></li><li><ul><li><a href="#openapi-pollingrate-advanced-settings-ui"><span>Open<wbr/>API <wbr/>Polling/<wbr/>Rate <wbr/>Advanced <wbr/>Settings (<wbr/>UI)</span></a></li><li><a href="#if-using-openapi-connection"><span>If using <wbr/>Open<wbr/>API <wbr/>Connection</span></a></li><li><a href="#if-using-ble-connection"><span>If using <wbr/>BLE <wbr/>Connection</span></a></li></ul></li><li><a href="#troubleshooting"><span>Troubleshooting</span></a></li><li><ul><li><a href="#if-using-linux-raspberry-pi-os"><span>If using <wbr/>Linux / <wbr/>Raspberry <wbr/>Pi <wbr/>OS</span></a></li><li><a href="#if-using-macos"><span>If using <wbr/>Mac<wbr/>OS</span></a></li></ul></li><li><a href="#supported-switchbot-devices"><span>Supported <wbr/>Switch<wbr/>Bot <wbr/>Devices</span></a></li><li><a href="#ble-encryption-support"><span>BLE <wbr/>Encryption <wbr/>Support</span></a></li><li><ul><li><a href="#ble-encryption-key-and-key-id"><span>BLE <wbr/>Encryption <wbr/>Key and <wbr/>Key <wbr/>ID</span></a></li><li><ul><li><a href="#how-to-obtain-ble-encryption-key-and-key-id"><span>How to <wbr/>Obtain <wbr/>BLE <wbr/>Encryption <wbr/>Key and <wbr/>Key <wbr/>ID</span></a></li><li><a href="#how-to-configure-in-homebridge"><span>How to <wbr/>Configure in <wbr/>Homebridge</span></a></li><li><a href="#which-devices-require-ble-encryption"><span>Which <wbr/>Devices <wbr/>Require <wbr/>BLE <wbr/>Encryption?</span></a></li></ul></li></ul></li><li><a href="#supported-ir-devices"><span>Supported <wbr/>IR <wbr/>Devices</span></a></li><li><ul><li><a href="#all-ir-devices-require-switchbot-hub-2-switchbot-hub-mini-2-switchbot-hub-3-or-hub-mini"><span>(<wbr/>All <wbr/>IR <wbr/>Devices require <wbr/>Switch<wbr/>Bot <wbr/>Hub 2, <wbr/>Switch<wbr/>Bot <wbr/>Hub <wbr/>Mini 2, <wbr/>Switch<wbr/>Bot <wbr/>Hub 3, or <wbr/>Hub <wbr/>Mini)</span></a></li></ul></li><li><a href="#matter-platform"><span>Matter <wbr/>Platform</span></a></li><li><ul><li><a href="#batched-refresh-and-api-load-control"><span>Batched refresh and <wbr/>API load control</span></a></li></ul></li><li><a href="#whats-new-with-node-switchbot-v400"><span>What&#39;s new with node-<wbr/>switchbot v4.0.0</span></a></li><li><a href="#openapi-rate-limiting-and-daily-budget"><span>Open<wbr/>API rate limiting and daily budget</span></a></li><li><a href="#switchbot-apis"><span>Switch<wbr/>Bot <wbr/>AP<wbr/>Is</span></a></li><li><a href="#development-tests"><span>Development / <wbr/>Tests</span></a></li><li><a href="#community"><span>Community</span></a></li></ul></div></details></div><div class="site-menu"><nav class="tsd-navigation"><a href="modules.html">@switchbot/homebridge-switchbot</a><ul class="tsd-small-nested-navigation" id="tsd-nav-container"><li>Loading...</li></ul></nav></div></div></div><footer></footer><div class="overlay"></div></body></html>
@@ -1 +1,3 @@
1
- <!DOCTYPE html><html class="default" lang="en" data-base="../"><head><meta charset="utf-8"/><meta http-equiv="x-ua-compatible" content="IE=edge"/><title>default | @switchbot/homebridge-switchbot</title><meta name="description" content="Documentation for @switchbot/homebridge-switchbot"/><meta name="viewport" content="width=device-width, initial-scale=1"/><link rel="stylesheet" href="../assets/style.css"/><link rel="stylesheet" href="../assets/highlight.css"/><script defer src="../assets/main.js"></script><script async src="../assets/icons.js" id="tsd-icons-script"></script><script async src="../assets/search.js" id="tsd-search-script"></script><script async src="../assets/navigation.js" id="tsd-nav-script"></script></head><body><script>document.documentElement.dataset.theme = localStorage.getItem("tsd-theme") || "os";document.body.style.display="none";setTimeout(() => window.app?app.showPage():document.body.style.removeProperty("display"),500)</script><header class="tsd-page-toolbar"><div class="tsd-toolbar-contents container"><a href="../index.html" class="title">@switchbot/homebridge-switchbot</a><div id="tsd-toolbar-links"></div><button id="tsd-search-trigger" class="tsd-widget" aria-label="Search"><svg width="16" height="16" viewBox="0 0 16 16" fill="none" aria-hidden="true"><use href="../assets/icons.svg#icon-search"></use></svg></button><dialog id="tsd-search" aria-label="Search"><input role="combobox" id="tsd-search-input" aria-controls="tsd-search-results" aria-autocomplete="list" aria-expanded="true" autocapitalize="off" autocomplete="off" placeholder="Search the docs" maxLength="100"/><ul role="listbox" id="tsd-search-results"></ul><div id="tsd-search-status" aria-live="polite" aria-atomic="true"><div>Preparing search index...</div></div></dialog><a href="#" class="tsd-widget menu" id="tsd-toolbar-menu-trigger" data-toggle="menu" aria-label="Menu"><svg width="16" height="16" viewBox="0 0 16 16" fill="none" aria-hidden="true"><use href="../assets/icons.svg#icon-menu"></use></svg></a></div></header><div class="container container-main"><div class="col-content"><div class="tsd-page-title"><ul class="tsd-breadcrumb" aria-label="Breadcrumb"><li><a href="" aria-current="page">default</a></li></ul><h1>Variable default</h1></div><div class="tsd-signature"><span class="tsd-kind-variable">default</span><span class="tsd-signature-symbol">:</span> <span class="tsd-signature-symbol">(</span><span class="tsd-kind-parameter">api</span><span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">API</span><span class="tsd-signature-symbol">)</span> <span class="tsd-signature-symbol">=&gt;</span> <span class="tsd-signature-type">void</span></div><div class="tsd-type-declaration"><h4>Type Declaration</h4><ul class="tsd-parameters"><li class="tsd-parameter-signature"><ul class="tsd-signatures"><li class="tsd-signature" id="__type"><span class="tsd-signature-symbol">(</span><span class="tsd-kind-parameter">api</span><span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">API</span><span class="tsd-signature-symbol">)</span><span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">void</span></li><li class="tsd-description"><div class="tsd-parameters"><h4 class="tsd-parameters-title">Parameters</h4><ul class="tsd-parameter-list"><li><span><span class="tsd-kind-parameter">api</span>: <span class="tsd-signature-type">API</span></span></li></ul></div><h4 class="tsd-returns-title">Returns <span class="tsd-signature-type">void</span></h4></li></ul></li></ul></div><aside class="tsd-sources"><ul><li>Defined in <a href="https://github.com/OpenWonderLabs/homebridge-switchbot/blob/dbdf57e1761be5ce89ad468b26d416a09f504972/src/index.ts#L12">index.ts:12</a></li></ul></aside></div><div class="col-sidebar"><div class="page-menu"><div class="tsd-navigation settings"><details class="tsd-accordion"><summary class="tsd-accordion-summary"><svg width="20" height="20" viewBox="0 0 24 24" fill="none" aria-hidden="true"><use href="../assets/icons.svg#icon-chevronDown"></use></svg><h3>Settings</h3></summary><div class="tsd-accordion-details"><div class="tsd-filter-visibility"><span class="settings-label">Member Visibility</span><ul id="tsd-filter-options"><li class="tsd-filter-item"><label class="tsd-filter-input"><input type="checkbox" id="tsd-filter-inherited" name="inherited" checked/><svg width="32" height="32" viewBox="0 0 32 32" aria-hidden="true"><rect class="tsd-checkbox-background" width="30" height="30" x="1" y="1" rx="6" fill="none"></rect><path class="tsd-checkbox-checkmark" d="M8.35422 16.8214L13.2143 21.75L24.6458 10.25" stroke="none" stroke-width="3.5" stroke-linejoin="round" fill="none"></path></svg><span>Inherited</span></label></li></ul></div><div class="tsd-theme-toggle"><label class="settings-label" for="tsd-theme">Theme</label><select id="tsd-theme"><option value="os">OS</option><option value="light">Light</option><option value="dark">Dark</option></select></div></div></details></div></div><div class="site-menu"><nav class="tsd-navigation"><a href="../modules.html">@switchbot/homebridge-switchbot</a><ul class="tsd-small-nested-navigation" id="tsd-nav-container"><li>Loading...</li></ul></nav></div></div></div><footer></footer><div class="overlay"></div></body></html>
1
+ <!DOCTYPE html><html class="default" lang="en" data-base="../"><head><meta charset="utf-8"/><meta http-equiv="x-ua-compatible" content="IE=edge"/><title>default | @switchbot/homebridge-switchbot</title><meta name="description" content="Documentation for @switchbot/homebridge-switchbot"/><meta name="viewport" content="width=device-width, initial-scale=1"/><link rel="stylesheet" href="../assets/style.css"/><link rel="stylesheet" href="../assets/highlight.css"/><script defer src="../assets/main.js"></script><script async src="../assets/icons.js" id="tsd-icons-script"></script><script async src="../assets/search.js" id="tsd-search-script"></script><script async src="../assets/navigation.js" id="tsd-nav-script"></script></head><body><script>document.documentElement.dataset.theme = localStorage.getItem("tsd-theme") || "os";document.body.style.display="none";setTimeout(() => window.app?app.showPage():document.body.style.removeProperty("display"),500)</script><header class="tsd-page-toolbar"><div class="tsd-toolbar-contents container"><a href="../index.html" class="title">@switchbot/homebridge-switchbot</a><div id="tsd-toolbar-links"></div><button id="tsd-search-trigger" class="tsd-widget" aria-label="Search"><svg width="16" height="16" viewBox="0 0 16 16" fill="none" aria-hidden="true"><use href="../assets/icons.svg#icon-search"></use></svg></button><dialog id="tsd-search" aria-label="Search"><input role="combobox" id="tsd-search-input" aria-controls="tsd-search-results" aria-autocomplete="list" aria-expanded="true" autocapitalize="off" autocomplete="off" placeholder="Search the docs" maxLength="100"/><ul role="listbox" id="tsd-search-results"></ul><div id="tsd-search-status" aria-live="polite" aria-atomic="true"><div>Preparing search index...</div></div></dialog><a href="#" class="tsd-widget menu" id="tsd-toolbar-menu-trigger" data-toggle="menu" aria-label="Menu"><svg width="16" height="16" viewBox="0 0 16 16" fill="none" aria-hidden="true"><use href="../assets/icons.svg#icon-menu"></use></svg></a></div></header><div class="container container-main"><div class="col-content"><div class="tsd-page-title"><ul class="tsd-breadcrumb" aria-label="Breadcrumb"><li><a href="" aria-current="page">default</a></li></ul><h1>Variable default</h1></div><div class="tsd-signature"><span class="tsd-kind-variable">default</span><span class="tsd-signature-symbol">:</span> <span class="tsd-signature-symbol">(</span><span class="tsd-kind-parameter">api</span><span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">API</span><span class="tsd-signature-symbol">)</span> <span class="tsd-signature-symbol">=&gt;</span> <span class="tsd-signature-type">void</span></div><div class="tsd-comment tsd-typography"><p>Registers the SwitchBot platform with Homebridge.</p>
2
+ </div><div class="tsd-type-declaration"><h4>Type Declaration</h4><ul class="tsd-parameters"><li class="tsd-parameter-signature"><ul class="tsd-signatures"><li class="tsd-signature" id="__type"><span class="tsd-signature-symbol">(</span><span class="tsd-kind-parameter">api</span><span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">API</span><span class="tsd-signature-symbol">)</span><span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">void</span></li><li class="tsd-description"><div class="tsd-parameters"><h4 class="tsd-parameters-title">Parameters</h4><ul class="tsd-parameter-list"><li><span><span class="tsd-kind-parameter">api</span>: <span class="tsd-signature-type">API</span></span><div class="tsd-comment tsd-typography"><p>The Homebridge API instance.</p>
3
+ </div></li></ul></div><h4 class="tsd-returns-title">Returns <span class="tsd-signature-type">void</span></h4></li></ul></li></ul></div><aside class="tsd-sources"><ul><li>Defined in <a href="https://github.com/OpenWonderLabs/homebridge-switchbot/blob/d950b8418492383290fb3f20b573b22faa39f964/src/index.ts#L22">index.ts:22</a></li></ul></aside></div><div class="col-sidebar"><div class="page-menu"><div class="tsd-navigation settings"><details class="tsd-accordion"><summary class="tsd-accordion-summary"><svg width="20" height="20" viewBox="0 0 24 24" fill="none" aria-hidden="true"><use href="../assets/icons.svg#icon-chevronDown"></use></svg><h3>Settings</h3></summary><div class="tsd-accordion-details"><div class="tsd-filter-visibility"><span class="settings-label">Member Visibility</span><ul id="tsd-filter-options"><li class="tsd-filter-item"><label class="tsd-filter-input"><input type="checkbox" id="tsd-filter-inherited" name="inherited" checked/><svg width="32" height="32" viewBox="0 0 32 32" aria-hidden="true"><rect class="tsd-checkbox-background" width="30" height="30" x="1" y="1" rx="6" fill="none"></rect><path class="tsd-checkbox-checkmark" d="M8.35422 16.8214L13.2143 21.75L24.6458 10.25" stroke="none" stroke-width="3.5" stroke-linejoin="round" fill="none"></path></svg><span>Inherited</span></label></li></ul></div><div class="tsd-theme-toggle"><label class="settings-label" for="tsd-theme">Theme</label><select id="tsd-theme"><option value="os">OS</option><option value="light">Light</option><option value="dark">Dark</option></select></div></div></details></div></div><div class="site-menu"><nav class="tsd-navigation"><a href="../modules.html">@switchbot/homebridge-switchbot</a><ul class="tsd-small-nested-navigation" id="tsd-nav-container"><li>Loading...</li></ul></nav></div></div></div><footer></footer><div class="overlay"></div></body></html>
package/eslint.config.js CHANGED
@@ -10,15 +10,22 @@ export default antfu(
10
10
  },
11
11
  rules: {
12
12
  'curly': ['error', 'multi-line'],
13
+ 'import/order': 0,
13
14
  'jsdoc/check-alignment': 'error',
14
15
  'jsdoc/check-line-alignment': 'error',
16
+ 'no-new': 0,
17
+ 'no-undef': 0,
15
18
  'perfectionist/sort-exports': 'error',
16
19
  'perfectionist/sort-imports': [
17
20
  'error',
18
21
  {
19
22
  groups: [
20
- 'type',
21
- ['builtin', 'external'],
23
+ 'type-builtin',
24
+ 'type-external',
25
+ 'type-internal',
26
+ ['type-parent', 'type-sibling', 'type-index'],
27
+ 'builtin',
28
+ 'external',
22
29
  'internal',
23
30
  ['parent', 'sibling', 'index'],
24
31
  'unknown',
@@ -35,9 +42,6 @@ export default antfu(
35
42
  'test/no-only-tests': 'error',
36
43
  'unicorn/no-useless-spread': 'error',
37
44
  'unused-imports/no-unused-vars': ['error', { caughtErrors: 'none' }],
38
- 'no-new': 0, // Disable the no-new rule
39
- 'new-cap': 0, // Disable the new-cap rule
40
- 'no-undef': 0, // Disable the no-undef rule
41
45
  },
42
46
  },
43
47
  )
package/nodemon.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "watch": ["src"],
3
- "ext": "ts, html, json",
3
+ "ext": "ts,html,json",
4
4
  "ignore": [],
5
- "exec": "DEBUG= tsc && homebridge -T -D -P -I -U ~/.homebridge-dev ..",
5
+ "exec": "npm run build",
6
6
  "signal": "SIGTERM",
7
7
  "env": {
8
8
  "NODE_OPTIONS": "--trace-warnings"
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@switchbot/homebridge-switchbot",
3
3
  "displayName": "SwitchBot",
4
4
  "type": "module",
5
- "version": "5.0.0-beta.99",
5
+ "version": "5.0.1",
6
6
  "description": "The SwitchBot plugin allows you to access your SwitchBot device(s) from HomeKit.",
7
7
  "author": "SwitchBot <support@wondertechlabs.com> (https://github.com/SwitchBot)",
8
8
  "contributors": [
@@ -56,20 +56,29 @@
56
56
  "icon": "https://raw.githubusercontent.com/OpenWonderLabs/homebridge-switchbot/latest/branding/icon.png",
57
57
  "engineStrict": true,
58
58
  "engines": {
59
- "homebridge": "^2.0.0-beta.50",
60
- "node": "^20 || ^22 || ^24"
59
+ "homebridge": "^2.0.0-beta.89",
60
+ "node": "^22 || ^24"
61
61
  },
62
62
  "directories": {
63
63
  "doc": "docs"
64
64
  },
65
65
  "scripts": {
66
+ "sync:device-types": "node scripts/sync-device-types.mjs",
66
67
  "check": "npm install && npm outdated",
67
- "lint": "eslint src/**/*.ts",
68
- "lint:fix": "eslint src/**/*.ts --fix",
69
- "watch": "npm run build && npm run plugin-ui && npm link && nodemon",
70
- "plugin-ui": "mkdir -p ./dist/homebridge-ui/public && if [ -d ./src/homebridge-ui/public ]; then rsync -a ./src/homebridge-ui/public/ ./dist/homebridge-ui/public/; fi",
71
- "build": "npm run clean && tsc && npm run plugin-ui",
72
- "prepublishOnly": "npm run lint && npm run build && npm run plugin-ui && npm run docs && npm run docs:lint",
68
+ "ports:free": "node scripts/free-dev-ports.mjs",
69
+ "typecheck": "tsc --noEmit",
70
+ "lint": "eslint --no-warn-ignored src/**/*.ts test/**/*.ts src/homebridge-ui/**/*.html src/homebridge-ui/public/js/*.ts && npm run typecheck",
71
+ "lint:src": "eslint --no-warn-ignored src/**/*.ts",
72
+ "lint:test": "eslint --no-warn-ignored test/**/*.ts",
73
+ "lint:ui": "eslint --no-warn-ignored src/homebridge-ui/**/*.html",
74
+ "lint:fix": "eslint --no-warn-ignored src/**/*.ts test/**/*.ts src/homebridge-ui/**/*.html src/homebridge-ui/public/js/*.ts --fix && npm run typecheck",
75
+ "watch": "npm run ports:free && npm run build && npm run build:ui && npm run plugin-ui && npm link && nodemon",
76
+ "watch:ui": "npm run ports:free && bash -c 'npx homebridge -I -U -D ~/.homebridge-dev & HB_PID=$!; sleep 6; UIX_STORAGE_PATH=~/.homebridge-dev node ./node_modules/homebridge-config-ui-x/dist/bin/standalone.js & npm run watch:files'",
77
+ "watch:files": "nodemon",
78
+ "plugin-ui": "mkdir -p ./dist/homebridge-ui/public && if [ -d ./src/homebridge-ui/public ]; then rsync -a ./src/homebridge-ui/public/ ./dist/homebridge-ui/public/; fi && node scripts/build-ui.js",
79
+ "build": "npm run sync:device-types && npm run clean && tsc && npm run plugin-ui",
80
+ "build:ui": "tsc --project tsconfig.ui.json",
81
+ "prepublishOnly": "npm run lint && npm run build && npm run build:ui && npm run plugin-ui && npm run docs && npm run docs:lint",
73
82
  "postpublish": "npm run clean && npm ci",
74
83
  "clean": "shx rm -rf ./dist",
75
84
  "test": "vitest run",
@@ -82,25 +91,29 @@
82
91
  "access": "public"
83
92
  },
84
93
  "dependencies": {
85
- "@homebridge/plugin-ui-utils": "^2.2.1",
86
- "node-switchbot": "^4.0.0-beta.3"
94
+ "@homebridge/plugin-ui-utils": "^2.2.3",
95
+ "class-validator": "^0.15.1",
96
+ "node-switchbot": "^4.0.1"
87
97
  },
88
98
  "devDependencies": {
89
- "@antfu/eslint-config": "^7.6.1",
90
- "@types/debug": "^4.1.12",
99
+ "@antfu/eslint-config": "^8.2.0",
100
+ "@types/debug": "^4.1.13",
91
101
  "@types/fs-extra": "^11.0.4",
92
- "@types/node": "^25.3.3",
102
+ "@types/node": "^25.6.0",
93
103
  "@types/semver": "^7.7.1",
94
104
  "@types/source-map-support": "^0.5.10",
95
- "@vitest/coverage-v8": "^4.0.18",
96
- "eslint": "^10.0.2",
105
+ "@vitest/coverage-v8": "^4.1.4",
106
+ "esbuild": "^0.28.0",
107
+ "eslint": "^10.2.0",
97
108
  "eslint-plugin-format": "^2.0.1",
98
- "homebridge": "^2.0.0-beta.77",
99
- "homebridge-config-ui-x": "^5.19.0",
109
+ "eslint-plugin-html": "^8.1.4",
110
+ "eslint-plugin-perfectionist": "^5.8.0",
111
+ "homebridge": "^2.0.0-beta.89",
112
+ "homebridge-config-ui-x": "^5.21.0",
100
113
  "nodemon": "^3.1.14",
101
114
  "shx": "^0.4.0",
102
- "typedoc": "^0.28.17",
103
- "typescript": "^5.9.3",
104
- "vitest": "^4.0.18"
115
+ "typedoc": "^0.28.19",
116
+ "typescript": "^6.0.2",
117
+ "vitest": "^4.1.4"
105
118
  }
106
- }
119
+ }
@@ -0,0 +1,37 @@
1
+ #!/usr/bin/env node
2
+
3
+ import esbuild from 'esbuild'
4
+ import fs from 'node:fs'
5
+ import path from 'node:path'
6
+ import process from 'node:process'
7
+ import { fileURLToPath } from 'node:url'
8
+
9
+ const __dirname = path.dirname(fileURLToPath(import.meta.url))
10
+
11
+ const srcDir = path.resolve(__dirname, '../src/homebridge-ui/public/js')
12
+ const outputDir = path.resolve(__dirname, '../dist/homebridge-ui/public/js')
13
+
14
+ // Ensure output directory exists
15
+ fs.mkdirSync(outputDir, { recursive: true })
16
+
17
+ // Transpile TypeScript to JavaScript with esbuild
18
+ esbuild
19
+ .build({
20
+ entryPoints: [path.join(srcDir, 'app.ts')],
21
+ outfile: path.join(outputDir, 'app.js'),
22
+ bundle: true,
23
+ target: 'es2020',
24
+ platform: 'browser',
25
+ format: 'esm',
26
+ sourcemap: true,
27
+ external: [],
28
+ minify: false,
29
+ logLevel: 'info',
30
+ })
31
+ .then(() => {
32
+ console.log('✓ UI bundling complete')
33
+ })
34
+ .catch((error) => {
35
+ console.error('✗ UI bundling failed:', error)
36
+ process.exit(1)
37
+ })
@@ -0,0 +1,105 @@
1
+ import { execSync } from 'node:child_process'
2
+ import { readFileSync } from 'node:fs'
3
+ import { homedir } from 'node:os'
4
+ import { resolve } from 'node:path'
5
+
6
+ function resolvePorts() {
7
+ let bridgePort = 51829
8
+ let uiPort = 8581
9
+
10
+ try {
11
+ const configPath = resolve(homedir(), '.homebridge-dev', 'config.json')
12
+ const config = JSON.parse(readFileSync(configPath, 'utf8'))
13
+
14
+ if (typeof config?.bridge?.port === 'number') {
15
+ bridgePort = config.bridge.port
16
+ }
17
+
18
+ const configUiPlatform = Array.isArray(config?.platforms)
19
+ ? config.platforms.find(platform => platform?.platform === 'config')
20
+ : undefined
21
+
22
+ if (typeof configUiPlatform?.port === 'number') {
23
+ uiPort = configUiPlatform.port
24
+ }
25
+ } catch {}
26
+
27
+ return [...new Set([bridgePort, uiPort])]
28
+ }
29
+
30
+ function pidsForPort(port) {
31
+ try {
32
+ const output = execSync(`lsof -ti tcp:${port}`, { stdio: ['ignore', 'pipe', 'ignore'] }).toString().trim()
33
+ return output ? output.split('\n').filter(Boolean) : []
34
+ } catch {
35
+ return []
36
+ }
37
+ }
38
+
39
+ function freePort(port) {
40
+ const initialPids = pidsForPort(port)
41
+ if (initialPids.length === 0) {
42
+ return
43
+ }
44
+
45
+ try {
46
+ execSync(`lsof -ti tcp:${port} | xargs -r kill -TERM`, { stdio: ['ignore', 'ignore', 'ignore'] })
47
+ } catch {}
48
+
49
+ const remainingPids = pidsForPort(port)
50
+ if (remainingPids.length > 0) {
51
+ try {
52
+ execSync(`lsof -ti tcp:${port} | xargs -r kill -KILL`, { stdio: ['ignore', 'ignore', 'ignore'] })
53
+ } catch {}
54
+ }
55
+ }
56
+
57
+ function cleanupDevProcesses() {
58
+ let output = ''
59
+ try {
60
+ output = execSync('ps -axo pid=,command=', { stdio: ['ignore', 'pipe', 'ignore'] }).toString()
61
+ } catch {
62
+ return
63
+ }
64
+
65
+ const targetPids = output
66
+ .split('\n')
67
+ .map(line => line.trim())
68
+ .filter(Boolean)
69
+ .map((line) => {
70
+ const firstSpace = line.indexOf(' ')
71
+ if (firstSpace === -1) {
72
+ return null
73
+ }
74
+
75
+ const pid = Number(line.slice(0, firstSpace).trim())
76
+ const command = line.slice(firstSpace + 1)
77
+ return Number.isFinite(pid) ? { pid, command } : null
78
+ })
79
+ .filter((entry) => {
80
+ if (!entry) {
81
+ return false
82
+ }
83
+
84
+ if (entry.pid === process.pid || entry.pid === process.ppid) {
85
+ return false
86
+ }
87
+
88
+ const isNodemonProcess = entry.command.includes('homebridge-switchbot/node_modules/.bin/nodemon')
89
+ const isConfigUiProcess = entry.command.trim().startsWith('homebridge-config-ui-x')
90
+ return isNodemonProcess || isConfigUiProcess
91
+ })
92
+ .map(entry => entry.pid)
93
+
94
+ for (const pid of targetPids) {
95
+ try {
96
+ process.kill(pid, 'SIGTERM')
97
+ } catch {}
98
+ }
99
+ }
100
+
101
+ cleanupDevProcesses()
102
+
103
+ for (const port of resolvePorts()) {
104
+ freePort(port)
105
+ }
@@ -1,6 +1,6 @@
1
- #!/usr/bin/env node
2
- const fs = require('fs')
3
- const path = require('path')
1
+ const fs = require('node:fs')
2
+ const path = require('node:path')
3
+ const process = require('node:process')
4
4
 
5
5
  function usage() {
6
6
  console.error('Usage: node scripts/generate-matter-maps.js <input-json> [output-file]')
@@ -10,39 +10,50 @@ function usage() {
10
10
  const input = process.argv[2]
11
11
  const outFile = process.argv[3] || path.join(__dirname, '..', 'src', 'matter-maps.generated.ts')
12
12
 
13
- if (!input) usage()
13
+ if (!input) {
14
+ usage()
15
+ }
14
16
  if (!fs.existsSync(input)) {
15
17
  console.error('Input file not found:', input)
16
18
  process.exit(2)
17
19
  }
18
20
 
19
- const json = JSON.parse(fs.readFileSync(input, 'utf8'))
21
+ let json
22
+ try {
23
+ json = JSON.parse(fs.readFileSync(input, 'utf8'))
24
+ } catch (e) {
25
+ console.error('Failed to parse input JSON:', e.message)
26
+ process.exit(2)
27
+ }
20
28
 
21
29
  // Expecting structure: { clusters: [{ name, id, attributes: [{ name, id }, ...] }, ...] }
22
- const clusters = json.clusters || []
30
+ const clusters = Array.isArray(json.clusters) ? json.clusters : []
23
31
 
24
32
  const clusterMapEntries = []
25
33
  const attrGroups = {}
26
34
 
27
35
  for (const c of clusters) {
28
- if (!c.name || typeof c.id === 'undefined') continue
29
- const key = c.name.replace(/[^A-Za-z0-9_]/g, '')
30
- clusterMapEntries.push(` ${key}: 0x${parseInt(String(c.id), 10).toString(16)}`)
36
+ if (!c.name || typeof c.id === 'undefined') {
37
+ continue
38
+ }
39
+ const key = c.name.replace(/\W/g, '')
40
+ clusterMapEntries.push(` ${key}: 0x${Number.parseInt(String(c.id), 10).toString(16)}`)
31
41
  const attrs = {}
32
42
  if (Array.isArray(c.attributes)) {
33
43
  for (const a of c.attributes) {
34
- if (!a.name || typeof a.id === 'undefined') continue
35
- const an = a.name.replace(/[^A-Za-z0-9_]/g, '')
36
- attrs[an] = `0x${parseInt(String(a.id), 10).toString(16)}`
44
+ if (!a.name || typeof a.id === 'undefined') {
45
+ continue
46
+ }
47
+ const an = a.name.replace(/\W/g, '')
48
+ attrs[an] = `0x${Number.parseInt(String(a.id), 10).toString(16)}`
37
49
  }
38
50
  }
39
- if (Object.keys(attrs).length) attrGroups[key] = attrs
51
+ if (Object.keys(attrs).length) {
52
+ attrGroups[key] = attrs
53
+ }
40
54
  }
41
55
 
42
- const clusterMap = `export const MATTER_CLUSTER_IDS = {
43
- ${clusterMapEntries.join(',\n')}
44
- } as const
45
- \n`
56
+ const clusterMap = `export const MATTER_CLUSTER_IDS = {\n${clusterMapEntries.join(',\n')}\n} as const\n\n`
46
57
 
47
58
  let attrText = 'export const MATTER_ATTRIBUTE_IDS = {\n'
48
59
  for (const [k, v] of Object.entries(attrGroups)) {
@@ -56,5 +67,11 @@ attrText += `} as const\n`
56
67
 
57
68
  const fileContent = `// GENERATED FILE - do not edit by hand.\n// Run: node scripts/generate-matter-maps.js <zap-matter.json>\n\n${clusterMap}\n${attrText}`
58
69
 
70
+ // Ensure output directory exists
71
+ const outDir = path.dirname(outFile)
72
+ if (!fs.existsSync(outDir)) {
73
+ fs.mkdirSync(outDir, { recursive: true })
74
+ }
75
+
59
76
  fs.writeFileSync(outFile, fileContent, 'utf8')
60
77
  console.log('Wrote', outFile)