@switchbot/homebridge-switchbot 5.0.0-beta.110 → 5.0.0-beta.112

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 (57) hide show
  1. package/.github/copilot-instructions.md +39 -0
  2. package/dist/homebridge-ui/endpoints/devices.d.ts.map +1 -1
  3. package/dist/homebridge-ui/endpoints/devices.js +10 -1
  4. package/dist/homebridge-ui/endpoints/devices.js.map +1 -1
  5. package/dist/homebridge-ui/public/css/styles.css +111 -16
  6. package/dist/homebridge-ui/public/index.html +34 -60
  7. package/dist/homebridge-ui/public/js/api.d.ts +5 -1
  8. package/dist/homebridge-ui/public/js/api.d.ts.map +1 -1
  9. package/dist/homebridge-ui/public/js/api.js +13 -3
  10. package/dist/homebridge-ui/public/js/api.js.map +1 -1
  11. package/dist/homebridge-ui/public/js/api.ts +13 -3
  12. package/dist/homebridge-ui/public/js/app.js +338 -42
  13. package/dist/homebridge-ui/public/js/app.js.map +3 -3
  14. package/dist/homebridge-ui/public/js/devices.d.ts.map +1 -1
  15. package/dist/homebridge-ui/public/js/devices.js +12 -3
  16. package/dist/homebridge-ui/public/js/devices.js.map +1 -1
  17. package/dist/homebridge-ui/public/js/devices.ts +13 -3
  18. package/dist/homebridge-ui/public/js/discovery.d.ts.map +1 -1
  19. package/dist/homebridge-ui/public/js/discovery.js +37 -3
  20. package/dist/homebridge-ui/public/js/discovery.js.map +1 -1
  21. package/dist/homebridge-ui/public/js/discovery.ts +39 -2
  22. package/dist/homebridge-ui/public/js/modals.d.ts +5 -0
  23. package/dist/homebridge-ui/public/js/modals.d.ts.map +1 -1
  24. package/dist/homebridge-ui/public/js/modals.js +146 -0
  25. package/dist/homebridge-ui/public/js/modals.js.map +1 -1
  26. package/dist/homebridge-ui/public/js/modals.ts +167 -0
  27. package/dist/homebridge-ui/public/js/render.d.ts +3 -1
  28. package/dist/homebridge-ui/public/js/render.d.ts.map +1 -1
  29. package/dist/homebridge-ui/public/js/render.js +135 -32
  30. package/dist/homebridge-ui/public/js/render.js.map +1 -1
  31. package/dist/homebridge-ui/public/js/render.ts +145 -32
  32. package/dist/platform.d.ts.map +1 -1
  33. package/dist/platform.js +64 -109
  34. package/dist/platform.js.map +1 -1
  35. package/dist/utils.d.ts.map +1 -1
  36. package/dist/utils.js +2 -1
  37. package/dist/utils.js.map +1 -1
  38. package/docs/variables/default.html +1 -1
  39. package/package.json +9 -8
  40. package/src/homebridge-ui/endpoints/devices.ts +5 -2
  41. package/src/homebridge-ui/public/css/styles.css +111 -16
  42. package/src/homebridge-ui/public/index.html +34 -60
  43. package/src/homebridge-ui/public/js/api.ts +13 -3
  44. package/src/homebridge-ui/public/js/devices.ts +13 -3
  45. package/src/homebridge-ui/public/js/discovery.ts +39 -2
  46. package/src/homebridge-ui/public/js/modals.ts +167 -0
  47. package/src/homebridge-ui/public/js/render.ts +145 -32
  48. package/src/platform.ts +77 -109
  49. package/src/utils.ts +2 -1
  50. package/test/e2e/run-e2e.spec.ts +12 -10
  51. package/test/helpers/matter-harness.ts +2 -2
  52. package/test/matter-childbridge.spec.ts +5 -1
  53. package/test/matter-integration.spec.ts +41 -0
  54. package/test/utils.spec.ts +18 -2
  55. package/todo/COMPLETED.md +53 -0
  56. package/todo/TODO.md +13 -42
  57. package/switchbot-homebridge-switchbot-5.0.0.tgz +0 -0
@@ -2,11 +2,15 @@ import { describe, it, expect } from 'vitest'
2
2
  import { createPlatformProxy } from '../src/utils'
3
3
 
4
4
  describe('createPlatformProxy', () => {
5
- it('returns Matter platform when preferMatter and enabled', () => {
5
+ it('returns Matter platform when preferMatter, enabled, and Matter API is available', () => {
6
6
  class HAP {}
7
7
  class Matter {}
8
8
  const ProxyCtor: any = createPlatformProxy(HAP, Matter)
9
- const impl = new (ProxyCtor as any)(console, { preferMatter: true, enableMatter: true }, undefined)
9
+ const api = {
10
+ isMatterAvailable: () => true,
11
+ isMatterEnabled: () => true,
12
+ }
13
+ const impl = new (ProxyCtor as any)(console, { preferMatter: true, enableMatter: true }, api)
10
14
  expect(impl).toBeInstanceOf(Matter)
11
15
  })
12
16
 
@@ -17,4 +21,16 @@ describe('createPlatformProxy', () => {
17
21
  const impl = new (ProxyCtor as any)(console, { preferMatter: false, enableMatter: true }, undefined)
18
22
  expect(impl).toBeInstanceOf(HAP)
19
23
  })
24
+
25
+ it('returns HAP platform when Matter API is unavailable', () => {
26
+ class HAP {}
27
+ class Matter {}
28
+ const ProxyCtor: any = createPlatformProxy(HAP, Matter)
29
+ const api = {
30
+ isMatterAvailable: () => false,
31
+ isMatterEnabled: () => false,
32
+ }
33
+ const impl = new (ProxyCtor as any)(console, { preferMatter: true, enableMatter: true }, api)
34
+ expect(impl).toBeInstanceOf(HAP)
35
+ })
20
36
  })
package/todo/COMPLETED.md CHANGED
@@ -23,6 +23,17 @@ This file tracks all completed features and improvements for the SwitchBot Homeb
23
23
 
24
24
  ## Bug Fixes
25
25
 
26
+ ### Matter Window Covering Conformance ✅ COMPLETED
27
+
28
+ - [x] **Fix Matter window covering Drapery enum validation error**
29
+ - [x] **Issue:** Matter accessory registration failed for Curtain devices
30
+ - [x] **Error:** `Conformance "LF & !TL": Matter does not allow enum value Drapery (ID 4) here`
31
+ - [x] **Related Runtime Failure:** `[Matter/Server] Failed to register Matter accessory ... [endpoint-behaviors] Behaviors have errors` with rollback from Matter transaction initialization
32
+ - [x] **Root Cause:** `windowCovering.type` used `Drapery` for lift-only curtain mappings
33
+ - [x] **Fix:** Updated curtain Matter default to a compliant lift-only covering enum and added regression coverage
34
+
35
+ **Status:** Curtain-type Matter accessories now register without the Drapery conformance failure.
36
+
26
37
  ### Invalid Device Type Validation ✅ COMPLETED
27
38
 
28
39
  - [x] **Fix invalid device type in config schema validation**
@@ -137,10 +148,52 @@ This file tracks all completed features and improvements for the SwitchBot Homeb
137
148
  - Real-time search box
138
149
  - All preferences saved and restored on next discovery
139
150
 
151
+ ### One-Click Device Import ✅ COMPLETED
152
+
153
+ - [x] Added "Add to Config" button for each discovered device
154
+ - [x] Added auto-populated import modal with discovered name/type defaults
155
+ - [x] Added BLE MAC pre-fill in import flow and persistence to config on single add
156
+ - [x] Added confirmation toast/status messaging on successful import
157
+
158
+ **Implementation:**
159
+ - Updated discovery row action in `render.ts` to use explicit "Add to Config" CTA
160
+ - Added `importDiscoveredDevice()` modal in `modals.ts` for prefilled import settings
161
+ - Extended single-add client payload in `api.ts` to include optional `address`, `model`, and `rssi`
162
+ - Extended `/add-device` endpoint in `devices.ts` to persist discovered metadata (MAC/model/RSSI)
163
+
164
+ **Status:** One-click import now supports prefilled configuration and BLE MAC carry-through for direct connection setup.
165
+
166
+ ### Duplicate Detection ✅ COMPLETED
167
+
168
+ - [x] Check if discovered device ID already exists in config
169
+ - [x] Show badge: "✓ Already Added" (green) or "➕ New Device" (blue)
170
+ - [x] Disable/hide "Add" button for already-added devices
171
+ - [x] Add "View in Config" link for existing devices
172
+
173
+ **Implementation:**
174
+ - Discovery view now fetches configured device IDs and tags discovered rows as existing/new
175
+ - Existing devices show `Already Added` state with disabled add action
176
+ - Existing devices include a `View in Config` action that scrolls and highlights the configured entry
177
+
178
+ **Status:** Duplicate devices are clearly identified at discovery time, preventing accidental re-adds and improving navigation to existing config entries.
179
+
140
180
  ---
141
181
 
142
182
  ## Bug Fixes & Technical Debt
143
183
 
184
+ ### Fix Discovery Not Showing Devices ✅ COMPLETED
185
+
186
+ - [x] **Issue:** No devices appear in discovery results after clicking "Discover Devices"
187
+ - [x] **Root Cause:** Discovery UI cleared the `#discoveredList` div (including the `<ul id="discoveredDevices">` element), but then tried to replace a non-existent element when rendering discovered devices
188
+ - [x] **Effect:** `document.getElementById('discoveredDevices')?.replaceWith(ul)` silently failed due to optional chaining, leaving the list empty
189
+
190
+ **Implementation:**
191
+ - Modified `discoverDevices()` in `discovery.ts` to create a new `<ul id="discoveredDevices">` container if it doesn't exist after clearing controls
192
+ - Updated `updateDiscoveryView()` to check if the element exists before using `replaceWith()`, with fallback to append if element is missing
193
+ - Added proper element lifecycle management for discovery list rendering
194
+
195
+ **Status:** Discovery now properly displays all discovered devices. Devices appear correctly with filters, sorting, and duplicate detection badges.
196
+
144
197
  ### Fix lint & lint:fix scripts ✅ COMPLETED
145
198
 
146
199
  - [x] Update ESLint configuration to include `src/homebridge-ui/**/*.ts` files
package/todo/TODO.md CHANGED
@@ -4,19 +4,7 @@
4
4
 
5
5
  ### Bug Fixes (Priority: Critical)
6
6
 
7
- #### Matter Window Covering Conformance Issue
8
-
9
- - [ ] **Fix Matter window covering Drapery enum validation error**
10
- - [ ] **Issue:** Matter accessory registration fails for Curtain devices
11
- - [ ] **Error:** `Conformance "LF & !TL": Matter does not allow enum value Drapery (ID 4) here`
12
- - [ ] **Root Cause:** windowCovering.state.type is set to "Drapery" but Matter spec requires "LF & !TL" conformance (Lift Fail without Tilt)
13
- - [ ] **Solution:** Need to validate/correct window covering type mappings for Matter compatibility
14
- - [ ] **Affected Devices:** Curtain-type devices (e.g., "Master Bathroom Left Curtain")
15
- - [ ] **Steps to Fix:**
16
- - [ ] Check Matter window covering specification for valid type combinations
17
- - [ ] Update device type mapping to use compliant enum values
18
- - [ ] Validate conformance rules for Lift/Tilt combinations
19
- - [ ] Test with Curtain, Curtain3, and Roller Shade devices
7
+ - No active critical bug fixes right now.
20
8
 
21
9
  ---
22
10
 
@@ -24,21 +12,7 @@
24
12
 
25
13
  ### Quick Wins (Priority: High)
26
14
 
27
- #### 1. One-Click Device Import
28
-
29
- - [ ] Add "Add to Config" button next to each discovered device
30
- - [ ] Implement auto-populate device configuration modal with discovered values
31
- - [ ] Pre-fill MAC address for BLE devices to enable direct connection
32
- - [ ] Add confirmation toast message on successful import
33
-
34
- #### 2. Duplicate Detection
35
-
36
- - [ ] Check if discovered device ID already exists in config
37
- - [ ] Show badge: "✓ Already Added" (green) or "➕ New Device" (blue)
38
- - [ ] Disable/hide "Add" button for already-added devices
39
- - [ ] Add "View in Config" link for existing devices
40
-
41
- #### 3. Better Loading States
15
+ #### 1. Better Loading States
42
16
 
43
17
  - [ ] Show progress indicator: "Scanning BLE... (5s)" → "Fetching OpenAPI..." → "Complete"
44
18
  - [ ] Add progress bar or spinner for each discovery phase
@@ -48,7 +22,7 @@
48
22
 
49
23
  ### Medium Effort (Priority: Medium)
50
24
 
51
- #### 4. Device Grouping
25
+ #### 2. Device Grouping
52
26
 
53
27
  - [ ] Implement grouping by Hub (show which devices are on which hub)
54
28
  - [ ] Implement grouping by Connection Type
@@ -56,14 +30,14 @@
56
30
  - [ ] Show device count per group
57
31
  - [ ] Remember expanded/collapsed state
58
32
 
59
- #### 5. Connection Recommendations
33
+ #### 3. Connection Recommendations
60
34
 
61
35
  - [ ] Add badge: "⚡ Recommended: BLE" for devices with strong signal (> -70 dBm)
62
36
  - [ ] Add badge: "☁️ Recommended: API" for hub-dependent devices
63
37
  - [ ] Show tooltip explaining why recommendation is made
64
38
  - [ ] Consider device type (some work better with BLE vs API)
65
39
 
66
- #### 6. Configurable BLE Scan
40
+ #### 4. Configurable BLE Scan
67
41
 
68
42
  - [ ] Add settings panel with scan duration options (3s/5s/10s/15s)
69
43
  - [ ] Add option to disable BLE scanning if no Bluetooth adapter
@@ -71,7 +45,7 @@
71
45
  - [ ] Remember user preferences in localStorage
72
46
  - [ ] Show system Bluetooth availability status
73
47
 
74
- #### 7. Discovery History/Cache
48
+ #### 5. Discovery History/Cache
75
49
 
76
50
  - [ ] Cache last discovery results for 5 minutes
77
51
  - [ ] Show "Last scanned: X minutes ago" with timestamp
@@ -79,7 +53,7 @@
79
53
  - [ ] Show cached results immediately on page load
80
54
  - [ ] Auto-refresh option with configurable interval
81
55
 
82
- #### 8. Detailed Device Info Panel
56
+ #### 6. Detailed Device Info Panel
83
57
 
84
58
  - [ ] Add click-to-expand device details panel
85
59
  - [ ] Show extended information:
@@ -93,14 +67,14 @@
93
67
 
94
68
  ### Advanced Features (Priority: Low)
95
69
 
96
- #### 9. Real-Time BLE Scanning
70
+ #### 7. Real-Time BLE Scanning
97
71
 
98
72
  - [ ] Show devices as they're discovered (streaming results)
99
73
  - [ ] Add animated "pulsing" indicator for active BLE scan
100
74
  - [ ] Update RSSI values in real-time during scan
101
75
  - [ ] Show "X devices found..." counter during scan
102
76
 
103
- #### 10. Connection Testing
77
+ #### 8. Connection Testing
104
78
 
105
79
  - [ ] Add "Test Connection" button per device
106
80
  - [ ] Attempt to connect and read basic device status
@@ -108,7 +82,7 @@
108
82
  - [ ] Display connection latency
109
83
  - [ ] Show which connection method succeeded (BLE/API)
110
84
 
111
- #### 11. Batch Import
85
+ #### 9. Batch Import
112
86
 
113
87
  - [ ] Add checkboxes to select multiple devices
114
88
  - [ ] Add "Add Selected to Config" button
@@ -116,7 +90,7 @@
116
90
  - [ ] Show progress for batch operations
117
91
  - [ ] Allow batch enable/disable of devices
118
92
 
119
- #### 12. Device Health Dashboard
93
+ #### 10. Device Health Dashboard
120
94
 
121
95
  - [ ] Show battery warnings (< 20%) with yellow/red indicators
122
96
  - [ ] Show firmware update available indicators
@@ -124,7 +98,7 @@
124
98
  - [ ] Add "Needs Attention" section at top
125
99
  - [ ] Implement battery level trending (if historical data available)
126
100
 
127
- #### 13. Export/Import Discovery
101
+ #### 11. Export/Import Discovery
128
102
 
129
103
  - [ ] Add "Export Results" button (JSON format)
130
104
  - [ ] Add "Import Results" for comparison or troubleshooting
@@ -172,10 +146,7 @@
172
146
 
173
147
  ### Must Do (Next Release)
174
148
 
175
- 1. Fix Matter window covering conformance issue (CRITICAL)
176
- 2. One-Click Device Import
177
- 3. Duplicate Detection
178
- 4. Better Loading States
149
+ 1. Better Loading States
179
150
 
180
151
  ### Should Do (Soon)
181
152