@switchbot/homebridge-switchbot 5.0.0-beta.111 → 5.0.0-beta.113

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 (85) hide show
  1. package/MIGRATION.md +10 -0
  2. package/README.md +43 -0
  3. package/TODO.md +263 -0
  4. package/config.schema.json +27 -10
  5. package/dist/device-types.d.ts.map +1 -1
  6. package/dist/device-types.js +93 -63
  7. package/dist/device-types.js.map +1 -1
  8. package/dist/deviceFactory.d.ts.map +1 -1
  9. package/dist/deviceFactory.js +55 -33
  10. package/dist/deviceFactory.js.map +1 -1
  11. package/dist/devices/genericDevice.d.ts +12 -1
  12. package/dist/devices/genericDevice.d.ts.map +1 -1
  13. package/dist/devices/genericDevice.js +121 -1
  14. package/dist/devices/genericDevice.js.map +1 -1
  15. package/dist/errors.d.ts +5 -0
  16. package/dist/errors.d.ts.map +1 -0
  17. package/dist/errors.js +51 -0
  18. package/dist/errors.js.map +1 -0
  19. package/dist/homebridge-ui/endpoints/devices.d.ts.map +1 -1
  20. package/dist/homebridge-ui/endpoints/devices.js +80 -1
  21. package/dist/homebridge-ui/endpoints/devices.js.map +1 -1
  22. package/dist/homebridge-ui/endpoints/discovery.d.ts.map +1 -1
  23. package/dist/homebridge-ui/endpoints/discovery.js +73 -41
  24. package/dist/homebridge-ui/endpoints/discovery.js.map +1 -1
  25. package/dist/homebridge-ui/public/css/styles.css +209 -16
  26. package/dist/homebridge-ui/public/index.html +87 -56
  27. package/dist/homebridge-ui/public/js/api.d.ts +24 -1
  28. package/dist/homebridge-ui/public/js/api.d.ts.map +1 -1
  29. package/dist/homebridge-ui/public/js/api.js +33 -2
  30. package/dist/homebridge-ui/public/js/api.js.map +1 -1
  31. package/dist/homebridge-ui/public/js/api.ts +52 -3
  32. package/dist/homebridge-ui/public/js/app.js +1604 -143
  33. package/dist/homebridge-ui/public/js/app.js.map +3 -3
  34. package/dist/homebridge-ui/public/js/app.ts +2 -1
  35. package/dist/homebridge-ui/public/js/devices.d.ts.map +1 -1
  36. package/dist/homebridge-ui/public/js/devices.js +2 -0
  37. package/dist/homebridge-ui/public/js/devices.js.map +1 -1
  38. package/dist/homebridge-ui/public/js/devices.ts +13 -1
  39. package/dist/homebridge-ui/public/js/discovery.d.ts +1 -0
  40. package/dist/homebridge-ui/public/js/discovery.d.ts.map +1 -1
  41. package/dist/homebridge-ui/public/js/discovery.js +1244 -124
  42. package/dist/homebridge-ui/public/js/discovery.js.map +1 -1
  43. package/dist/homebridge-ui/public/js/discovery.ts +1344 -142
  44. package/dist/homebridge-ui/public/js/modals.d.ts.map +1 -1
  45. package/dist/homebridge-ui/public/js/modals.js +42 -0
  46. package/dist/homebridge-ui/public/js/modals.js.map +1 -1
  47. package/dist/homebridge-ui/public/js/modals.ts +50 -1
  48. package/dist/homebridge-ui/public/js/render.d.ts +3 -0
  49. package/dist/homebridge-ui/public/js/render.d.ts.map +1 -1
  50. package/dist/homebridge-ui/public/js/render.js +389 -36
  51. package/dist/homebridge-ui/public/js/render.js.map +1 -1
  52. package/dist/homebridge-ui/public/js/render.ts +421 -38
  53. package/dist/platform.d.ts +1 -0
  54. package/dist/platform.d.ts.map +1 -1
  55. package/dist/platform.js +3 -4
  56. package/dist/platform.js.map +1 -1
  57. package/dist/switchbotClient.d.ts.map +1 -1
  58. package/dist/switchbotClient.js +51 -5
  59. package/dist/switchbotClient.js.map +1 -1
  60. package/docs/assets/highlight.css +9 -2
  61. package/docs/index.html +28 -2
  62. package/docs/variables/default.html +1 -1
  63. package/package.json +9 -8
  64. package/src/device-types.ts +95 -64
  65. package/src/deviceFactory.ts +55 -33
  66. package/src/devices/genericDevice.ts +113 -1
  67. package/src/errors.ts +43 -0
  68. package/src/homebridge-ui/endpoints/devices.ts +82 -1
  69. package/src/homebridge-ui/endpoints/discovery.ts +78 -44
  70. package/src/homebridge-ui/public/css/styles.css +209 -16
  71. package/src/homebridge-ui/public/index.html +87 -56
  72. package/src/homebridge-ui/public/js/api.ts +52 -3
  73. package/src/homebridge-ui/public/js/app.ts +2 -1
  74. package/src/homebridge-ui/public/js/devices.ts +13 -1
  75. package/src/homebridge-ui/public/js/discovery.ts +1344 -142
  76. package/src/homebridge-ui/public/js/modals.ts +50 -1
  77. package/src/homebridge-ui/public/js/render.ts +421 -38
  78. package/src/platform.ts +3 -4
  79. package/src/switchbotClient.ts +44 -9
  80. package/test/e2e/run-e2e.spec.ts +12 -10
  81. package/test/helpers/matter-harness.ts +2 -2
  82. package/test/matter-integration.spec.ts +21 -0
  83. package/todo/COMPLETED.md +313 -0
  84. package/todo/TODO.md +80 -66
  85. package/switchbot-homebridge-switchbot-5.0.0.tgz +0 -0
@@ -100,9 +100,18 @@ export async function fetchDevices(): Promise<any[]> {
100
100
  }
101
101
  }
102
102
 
103
- export async function discoverDevices(): Promise<any[]> {
103
+ export type DiscoverRequestOptions = {
104
+ bleEnabled?: boolean
105
+ bleScanDurationSeconds?: number
106
+ bleTimeoutSeconds?: number
107
+ }
108
+
109
+ export async function discoverDevices(
110
+ mode: 'all' | 'ble' | 'openapi' = 'all',
111
+ options?: DiscoverRequestOptions,
112
+ ): Promise<any[]> {
104
113
  try {
105
- const resp = await homebridge.request('/discover', {})
114
+ const resp = await homebridge.request('/discover', { mode, ...options })
106
115
  uiLog.info('Discover response:', resp)
107
116
 
108
117
  if (!resp || resp.success === false) {
@@ -115,17 +124,57 @@ export async function discoverDevices(): Promise<any[]> {
115
124
  }
116
125
  }
117
126
 
127
+ export async function fetchBluetoothStatus(): Promise<{ available: boolean, message: string }> {
128
+ try {
129
+ const resp = await homebridge.request('/ble-status', {})
130
+ if (!resp || resp.success === false) {
131
+ return { available: false, message: 'Bluetooth status unavailable' }
132
+ }
133
+ return resp.data || { available: false, message: 'Bluetooth status unavailable' }
134
+ } catch (_e) {
135
+ return { available: false, message: 'Bluetooth status unavailable' }
136
+ }
137
+ }
138
+
139
+ export async function testDeviceConnection(payload: {
140
+ deviceId: string
141
+ connectionType?: string
142
+ address?: string
143
+ }): Promise<{
144
+ success: boolean
145
+ deviceId: string
146
+ method: string
147
+ latencyMs: number
148
+ message: string
149
+ state?: Record<string, any>
150
+ }> {
151
+ const resp = await homebridge.request('/test-connection', payload)
152
+ if (!resp || resp.success === false) {
153
+ throw new Error(resp?.data?.message || 'Connection test failed')
154
+ }
155
+
156
+ return resp.data || {
157
+ success: false,
158
+ deviceId: payload.deviceId,
159
+ method: 'Auto',
160
+ latencyMs: 0,
161
+ message: 'Connection test failed',
162
+ }
163
+ }
164
+
118
165
  export async function addDevice(
119
166
  deviceId: string,
120
167
  name: string,
121
168
  type: string,
122
- options?: { address?: string, model?: string, rssi?: number },
169
+ options?: { address?: string, model?: string, rssi?: number, encryptionKey?: string, keyId?: string },
123
170
  ): Promise<any> {
124
171
  try {
125
172
  const payload: any = { deviceId, name, type }
126
173
  if (options?.address) { payload.address = options.address }
127
174
  if (options?.model) { payload.model = options.model }
128
175
  if (options?.rssi !== undefined && options?.rssi !== null && options?.rssi !== 0) { payload.rssi = options.rssi }
176
+ if (options?.encryptionKey) { payload.encryptionKey = options.encryptionKey }
177
+ if (options?.keyId) { payload.keyId = options.keyId }
129
178
 
130
179
  uiLog.info('Adding device to config:', payload)
131
180
  const resp = await homebridge.request('/add-device', payload)