@switchbot/homebridge-switchbot 5.0.0-beta.108 → 5.0.0-beta.109
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.
- package/TODO.md +564 -0
- package/config.schema.json +100 -25
- package/dist/device-types.d.ts +15 -0
- package/dist/device-types.d.ts.map +1 -0
- package/dist/device-types.js +145 -0
- package/dist/device-types.js.map +1 -0
- package/dist/deviceFactory.d.ts +1 -1
- package/dist/deviceFactory.d.ts.map +1 -1
- package/dist/deviceFactory.js +55 -17
- package/dist/deviceFactory.js.map +1 -1
- package/dist/devices/genericDevice.d.ts +1 -1
- package/dist/devices/genericDevice.d.ts.map +1 -1
- package/dist/devices/genericDevice.js +4 -2
- package/dist/devices/genericDevice.js.map +1 -1
- package/dist/homebridge-ui/endpoints/config.d.ts +6 -0
- package/dist/homebridge-ui/endpoints/config.d.ts.map +1 -0
- package/dist/homebridge-ui/endpoints/config.js +73 -0
- package/dist/homebridge-ui/endpoints/config.js.map +1 -0
- package/dist/homebridge-ui/endpoints/credentials.d.ts +6 -0
- package/dist/homebridge-ui/endpoints/credentials.d.ts.map +1 -0
- package/dist/homebridge-ui/endpoints/credentials.js +65 -0
- package/dist/homebridge-ui/endpoints/credentials.js.map +1 -0
- package/dist/homebridge-ui/endpoints/devices.d.ts +6 -0
- package/dist/homebridge-ui/endpoints/devices.d.ts.map +1 -0
- package/dist/homebridge-ui/endpoints/devices.js +285 -0
- package/dist/homebridge-ui/endpoints/devices.js.map +1 -0
- package/dist/homebridge-ui/endpoints/discovery.d.ts +7 -0
- package/dist/homebridge-ui/endpoints/discovery.d.ts.map +1 -0
- package/dist/homebridge-ui/endpoints/discovery.js +171 -0
- package/dist/homebridge-ui/endpoints/discovery.js.map +1 -0
- package/dist/homebridge-ui/public/index.html +144 -624
- package/dist/homebridge-ui/public/js/api.d.ts +15 -0
- package/dist/homebridge-ui/public/js/api.d.ts.map +1 -0
- package/dist/homebridge-ui/public/js/api.js +164 -0
- package/dist/homebridge-ui/public/js/api.js.map +1 -0
- package/dist/homebridge-ui/public/js/api.ts +189 -0
- package/dist/homebridge-ui/public/js/app.d.ts +2 -0
- package/dist/homebridge-ui/public/js/app.d.ts.map +1 -0
- package/dist/homebridge-ui/public/js/app.js +1069 -0
- package/dist/homebridge-ui/public/js/app.js.map +7 -0
- package/dist/homebridge-ui/public/js/app.ts +21 -0
- package/dist/homebridge-ui/public/js/constants.d.ts +2 -0
- package/dist/homebridge-ui/public/js/constants.d.ts.map +1 -0
- package/dist/homebridge-ui/public/js/constants.js +2 -0
- package/dist/homebridge-ui/public/js/constants.js.map +1 -0
- package/dist/homebridge-ui/public/js/constants.ts +1 -0
- package/dist/homebridge-ui/public/js/credentials.d.ts +3 -0
- package/dist/homebridge-ui/public/js/credentials.d.ts.map +1 -0
- package/dist/homebridge-ui/public/js/credentials.js +96 -0
- package/dist/homebridge-ui/public/js/credentials.js.map +1 -0
- package/dist/homebridge-ui/public/js/credentials.ts +100 -0
- package/dist/homebridge-ui/public/js/devices-delete.d.ts +2 -0
- package/dist/homebridge-ui/public/js/devices-delete.d.ts.map +1 -0
- package/dist/homebridge-ui/public/js/devices-delete.js +99 -0
- package/dist/homebridge-ui/public/js/devices-delete.js.map +1 -0
- package/dist/homebridge-ui/public/js/devices-delete.ts +113 -0
- package/dist/homebridge-ui/public/js/devices.d.ts +8 -0
- package/dist/homebridge-ui/public/js/devices.d.ts.map +1 -0
- package/dist/homebridge-ui/public/js/devices.js +71 -0
- package/dist/homebridge-ui/public/js/devices.js.map +1 -0
- package/dist/homebridge-ui/public/js/devices.ts +78 -0
- package/dist/homebridge-ui/public/js/discovery.d.ts +3 -0
- package/dist/homebridge-ui/public/js/discovery.d.ts.map +1 -0
- package/dist/homebridge-ui/public/js/discovery.js +107 -0
- package/dist/homebridge-ui/public/js/discovery.js.map +1 -0
- package/dist/homebridge-ui/public/js/discovery.ts +123 -0
- package/dist/homebridge-ui/public/js/logger.d.ts +6 -0
- package/dist/homebridge-ui/public/js/logger.d.ts.map +1 -0
- package/dist/homebridge-ui/public/js/logger.js +12 -0
- package/dist/homebridge-ui/public/js/logger.js.map +1 -0
- package/dist/homebridge-ui/public/js/logger.ts +11 -0
- package/dist/homebridge-ui/public/js/modal.d.ts +5 -0
- package/dist/homebridge-ui/public/js/modal.d.ts.map +1 -0
- package/dist/homebridge-ui/public/js/modal.js +26 -0
- package/dist/homebridge-ui/public/js/modal.js.map +1 -0
- package/dist/homebridge-ui/public/js/modal.ts +28 -0
- package/dist/homebridge-ui/public/js/modals.d.ts +2 -0
- package/dist/homebridge-ui/public/js/modals.d.ts.map +1 -0
- package/dist/homebridge-ui/public/js/modals.js +132 -0
- package/dist/homebridge-ui/public/js/modals.js.map +1 -0
- package/dist/homebridge-ui/public/js/modals.ts +153 -0
- package/dist/homebridge-ui/public/js/render.d.ts +6 -0
- package/dist/homebridge-ui/public/js/render.d.ts.map +1 -0
- package/dist/homebridge-ui/public/js/render.js +166 -0
- package/dist/homebridge-ui/public/js/render.js.map +1 -0
- package/dist/homebridge-ui/public/js/render.ts +190 -0
- package/dist/homebridge-ui/public/js/toast.d.ts +6 -0
- package/dist/homebridge-ui/public/js/toast.d.ts.map +1 -0
- package/dist/homebridge-ui/public/js/toast.js +29 -0
- package/dist/homebridge-ui/public/js/toast.js.map +1 -0
- package/dist/homebridge-ui/public/js/toast.ts +37 -0
- package/dist/homebridge-ui/public/js/types.d.ts +23 -0
- package/dist/homebridge-ui/public/js/types.d.ts.map +1 -0
- package/dist/homebridge-ui/public/js/types.js +2 -0
- package/dist/homebridge-ui/public/js/types.js.map +1 -0
- package/dist/homebridge-ui/public/js/types.ts +26 -0
- package/dist/homebridge-ui/server.d.ts +1 -3
- package/dist/homebridge-ui/server.d.ts.map +1 -1
- package/dist/homebridge-ui/server.js +10 -561
- package/dist/homebridge-ui/server.js.map +1 -1
- package/dist/homebridge-ui/utils/config-parser.d.ts +35 -0
- package/dist/homebridge-ui/utils/config-parser.d.ts.map +1 -0
- package/dist/homebridge-ui/utils/config-parser.js +87 -0
- package/dist/homebridge-ui/utils/config-parser.js.map +1 -0
- package/dist/homebridge-ui/utils/logger.d.ts +7 -0
- package/dist/homebridge-ui/utils/logger.d.ts.map +1 -0
- package/dist/homebridge-ui/utils/logger.js +17 -0
- package/dist/homebridge-ui/utils/logger.js.map +1 -0
- package/dist/platform.d.ts.map +1 -1
- package/dist/platform.js +6 -2
- package/dist/platform.js.map +1 -1
- package/dist/switchbotClient.d.ts.map +1 -1
- package/dist/switchbotClient.js +2 -0
- package/dist/switchbotClient.js.map +1 -1
- package/docs/variables/default.html +1 -1
- package/eslint.config.js +5 -0
- package/nodemon.json +2 -2
- package/package.json +20 -10
- package/scripts/build-ui.js +36 -0
- package/scripts/free-dev-ports.mjs +105 -0
- package/scripts/sync-device-types.mjs +28 -0
- package/src/device-types.ts +145 -0
- package/src/deviceFactory.ts +71 -31
- package/src/devices/genericDevice.ts +5 -2
- package/src/homebridge-ui/endpoints/config.ts +79 -0
- package/src/homebridge-ui/endpoints/credentials.ts +74 -0
- package/src/homebridge-ui/endpoints/devices.ts +321 -0
- package/src/homebridge-ui/endpoints/discovery.ts +191 -0
- package/src/homebridge-ui/public/index.html +144 -624
- package/src/homebridge-ui/public/js/api.ts +189 -0
- package/src/homebridge-ui/public/js/app.ts +21 -0
- package/src/homebridge-ui/public/js/constants.ts +1 -0
- package/src/homebridge-ui/public/js/credentials.ts +100 -0
- package/src/homebridge-ui/public/js/devices-delete.ts +113 -0
- package/src/homebridge-ui/public/js/devices.ts +78 -0
- package/src/homebridge-ui/public/js/discovery.ts +123 -0
- package/src/homebridge-ui/public/js/logger.ts +11 -0
- package/src/homebridge-ui/public/js/modal.ts +28 -0
- package/src/homebridge-ui/public/js/modals.ts +153 -0
- package/src/homebridge-ui/public/js/render.ts +190 -0
- package/src/homebridge-ui/public/js/toast.ts +37 -0
- package/src/homebridge-ui/public/js/types.ts +26 -0
- package/src/homebridge-ui/server.ts +11 -647
- package/src/homebridge-ui/utils/config-parser.ts +108 -0
- package/src/homebridge-ui/utils/logger.ts +17 -0
- package/src/platform.ts +6 -2
- package/src/switchbotClient.ts +2 -0
- package/switchbot-homebridge-switchbot-5.0.0.tgz +0 -0
package/TODO.md
ADDED
|
@@ -0,0 +1,564 @@
|
|
|
1
|
+
# SwitchBot Plugin TODO List
|
|
2
|
+
|
|
3
|
+
## Code Refactoring & Architecture
|
|
4
|
+
|
|
5
|
+
### Server-Side Refactoring (Priority: High)
|
|
6
|
+
|
|
7
|
+
- [ ] **Split `server.ts` into modular structure**
|
|
8
|
+
- [ ] Create `src/homebridge-ui/endpoints/discovery.ts` - Discovery endpoint (~140 lines)
|
|
9
|
+
- [ ] Create `src/homebridge-ui/endpoints/config.ts` - Config management endpoint
|
|
10
|
+
- [ ] Create `src/homebridge-ui/endpoints/devices.ts` - Device CRUD operations
|
|
11
|
+
- [ ] Create `src/homebridge-ui/utils/switchbot-client.ts` - SwitchBot client initialization
|
|
12
|
+
- [ ] Create `src/homebridge-ui/utils/config-parser.ts` - Config parsing helpers
|
|
13
|
+
- [ ] Update `src/homebridge-ui/server.ts` - Main entry point (import and register endpoints)
|
|
14
|
+
|
|
15
|
+
### Client-Side Refactoring (Priority: Medium)
|
|
16
|
+
|
|
17
|
+
#### Phase 1: Quick Wins
|
|
18
|
+
|
|
19
|
+
- [ ] **Extract DEVICE_TYPES constant** (~100 lines)
|
|
20
|
+
- [ ] Create `src/homebridge-ui/public/js/constants.js` with device types
|
|
21
|
+
- [ ] Update `index.html` to import constants
|
|
22
|
+
|
|
23
|
+
- [ ] **Extract CSS styles**
|
|
24
|
+
- [ ] Create `src/homebridge-ui/public/css/styles.css`
|
|
25
|
+
- [ ] Move all inline styles from `index.html`
|
|
26
|
+
- [ ] Update HTML to link stylesheet
|
|
27
|
+
|
|
28
|
+
#### Phase 2: JavaScript Modularization
|
|
29
|
+
|
|
30
|
+
- [ ] **Create JavaScript modules**
|
|
31
|
+
- [ ] Create `src/homebridge-ui/public/js/api.js` - API client functions
|
|
32
|
+
- [ ] Create `src/homebridge-ui/public/js/discovery.js` - Discovery UI rendering
|
|
33
|
+
- [ ] Create `src/homebridge-ui/public/js/modals.js` - Modal management
|
|
34
|
+
- [ ] Create `src/homebridge-ui/public/js/forms.js` - Form handling
|
|
35
|
+
- [ ] Update `index.html` to use ES modules or add bundler
|
|
36
|
+
|
|
37
|
+
- [ ] **Update build process**
|
|
38
|
+
- [ ] Ensure `npm run plugin-ui` copies all new files
|
|
39
|
+
- [ ] Consider adding bundler (webpack/rollup) if needed
|
|
40
|
+
- [ ] Test that UI still works after refactoring
|
|
41
|
+
|
|
42
|
+
---
|
|
43
|
+
|
|
44
|
+
## Discovery System Enhancements
|
|
45
|
+
|
|
46
|
+
### Quick Wins (Priority: High)
|
|
47
|
+
|
|
48
|
+
#### 1. One-Click Device Import
|
|
49
|
+
|
|
50
|
+
- [ ] Add "Add to Config" button next to each discovered device
|
|
51
|
+
- [ ] Implement auto-populate device configuration modal with discovered values
|
|
52
|
+
- [ ] Pre-fill MAC address for BLE devices to enable direct connection
|
|
53
|
+
- [ ] Add confirmation toast message on successful import
|
|
54
|
+
|
|
55
|
+
#### 2. Signal Strength Visualization
|
|
56
|
+
|
|
57
|
+
- [ ] Implement RSSI color-coding system:
|
|
58
|
+
- [ ] Green: > -60 dBm (excellent)
|
|
59
|
+
- [ ] Yellow: -60 to -75 dBm (good)
|
|
60
|
+
- [ ] Orange: -75 to -85 dBm (fair)
|
|
61
|
+
- [ ] Red: < -85 dBm (poor/unreliable)
|
|
62
|
+
- [ ] Add signal strength bars visual indicator
|
|
63
|
+
- [ ] Add tooltip explaining signal quality
|
|
64
|
+
|
|
65
|
+
#### 3. Duplicate Detection
|
|
66
|
+
|
|
67
|
+
- [ ] Check if discovered device ID already exists in config
|
|
68
|
+
- [ ] Show badge: "✓ Already Added" (green) or "➕ New Device" (blue)
|
|
69
|
+
- [ ] Disable/hide "Add" button for already-added devices
|
|
70
|
+
- [ ] Add "View in Config" link for existing devices
|
|
71
|
+
|
|
72
|
+
#### 4. Filtering & Sorting
|
|
73
|
+
|
|
74
|
+
- [ ] Add filter buttons: "All | BLE Only | API Only | Both | IR Devices"
|
|
75
|
+
- [ ] Add sort dropdown: "Signal Strength | Name | Type | Connection"
|
|
76
|
+
- [ ] Add search box to filter by name/ID/type (real-time filtering)
|
|
77
|
+
- [ ] Persist filter/sort preferences in localStorage
|
|
78
|
+
|
|
79
|
+
#### 5. Better Loading States
|
|
80
|
+
|
|
81
|
+
- [ ] Show progress indicator: "Scanning BLE... (5s)" → "Fetching OpenAPI..." → "Complete"
|
|
82
|
+
- [ ] Add progress bar or spinner for each discovery phase
|
|
83
|
+
- [ ] Display partial results as they arrive (streaming)
|
|
84
|
+
- [ ] Show elapsed time for each phase
|
|
85
|
+
- [ ] Add "Cancel" button to abort long scans
|
|
86
|
+
|
|
87
|
+
### Medium Effort (Priority: Medium)
|
|
88
|
+
|
|
89
|
+
#### 6. Device Grouping
|
|
90
|
+
|
|
91
|
+
- [ ] Implement grouping by Hub (show which devices are on which hub)
|
|
92
|
+
- [ ] Implement grouping by Connection Type
|
|
93
|
+
- [ ] Add expandable/collapsible group headers
|
|
94
|
+
- [ ] Show device count per group
|
|
95
|
+
- [ ] Remember expanded/collapsed state
|
|
96
|
+
|
|
97
|
+
#### 7. Connection Recommendations
|
|
98
|
+
|
|
99
|
+
- [ ] Add badge: "⚡ Recommended: BLE" for devices with strong signal (> -70 dBm)
|
|
100
|
+
- [ ] Add badge: "☁️ Recommended: API" for hub-dependent devices
|
|
101
|
+
- [ ] Show tooltip explaining why recommendation is made
|
|
102
|
+
- [ ] Consider device type (some work better with BLE vs API)
|
|
103
|
+
|
|
104
|
+
#### 8. Configurable BLE Scan
|
|
105
|
+
|
|
106
|
+
- [ ] Add settings panel with scan duration options (3s/5s/10s/15s)
|
|
107
|
+
- [ ] Add option to disable BLE scanning if no Bluetooth adapter
|
|
108
|
+
- [ ] Add option to adjust BLE timeout
|
|
109
|
+
- [ ] Remember user preferences in localStorage
|
|
110
|
+
- [ ] Show system Bluetooth availability status
|
|
111
|
+
|
|
112
|
+
#### 9. Discovery History/Cache
|
|
113
|
+
|
|
114
|
+
- [ ] Cache last discovery results for 5 minutes
|
|
115
|
+
- [ ] Show "Last scanned: X minutes ago" with timestamp
|
|
116
|
+
- [ ] Add "Refresh" button to re-scan
|
|
117
|
+
- [ ] Show cached results immediately on page load
|
|
118
|
+
- [ ] Auto-refresh option with configurable interval
|
|
119
|
+
|
|
120
|
+
#### 10. Detailed Device Info Panel
|
|
121
|
+
|
|
122
|
+
- [ ] Add click-to-expand device details panel
|
|
123
|
+
- [ ] Show extended information:
|
|
124
|
+
- [ ] Battery level (if available)
|
|
125
|
+
- [ ] Firmware version
|
|
126
|
+
- [ ] Cloud service enabled/disabled status
|
|
127
|
+
- [ ] Last seen timestamp
|
|
128
|
+
- [ ] Full MAC address
|
|
129
|
+
- [ ] Device capabilities/features
|
|
130
|
+
- [ ] Add "Copy ID" and "Copy MAC" buttons
|
|
131
|
+
|
|
132
|
+
### Advanced Features (Priority: Low)
|
|
133
|
+
|
|
134
|
+
#### 11. Real-Time BLE Scanning
|
|
135
|
+
|
|
136
|
+
- [ ] Show devices as they're discovered (streaming results)
|
|
137
|
+
- [ ] Add animated "pulsing" indicator for active BLE scan
|
|
138
|
+
- [ ] Update RSSI values in real-time during scan
|
|
139
|
+
- [ ] Show "X devices found..." counter during scan
|
|
140
|
+
|
|
141
|
+
#### 12. Connection Testing
|
|
142
|
+
|
|
143
|
+
- [ ] Add "Test Connection" button per device
|
|
144
|
+
- [ ] Attempt to connect and read basic device status
|
|
145
|
+
- [ ] Show success/failure indicator with details
|
|
146
|
+
- [ ] Display connection latency
|
|
147
|
+
- [ ] Show which connection method succeeded (BLE/API)
|
|
148
|
+
|
|
149
|
+
#### 13. Batch Import
|
|
150
|
+
|
|
151
|
+
- [ ] Add checkboxes to select multiple devices
|
|
152
|
+
- [ ] Add "Add Selected to Config" button
|
|
153
|
+
- [ ] Implement bulk configuration with smart defaults
|
|
154
|
+
- [ ] Show progress for batch operations
|
|
155
|
+
- [ ] Allow batch enable/disable of devices
|
|
156
|
+
|
|
157
|
+
#### 14. Device Health Dashboard
|
|
158
|
+
|
|
159
|
+
- [ ] Show battery warnings (< 20%) with yellow/red indicators
|
|
160
|
+
- [ ] Show firmware update available indicators
|
|
161
|
+
- [ ] Show offline/unreachable warnings
|
|
162
|
+
- [ ] Add "Needs Attention" section at top
|
|
163
|
+
- [ ] Implement battery level trending (if historical data available)
|
|
164
|
+
|
|
165
|
+
#### 15. Export/Import Discovery
|
|
166
|
+
|
|
167
|
+
- [ ] Add "Export Results" button (JSON format)
|
|
168
|
+
- [ ] Add "Import Results" for comparison or troubleshooting
|
|
169
|
+
- [ ] Share with support for debugging
|
|
170
|
+
- [ ] Compare current vs previous discovery (show differences)
|
|
171
|
+
- [ ] Generate discovery report (formatted summary)
|
|
172
|
+
|
|
173
|
+
---
|
|
174
|
+
|
|
175
|
+
## Bug Fixes & Technical Debt
|
|
176
|
+
|
|
177
|
+
### Critical Issues (Priority: Critical)
|
|
178
|
+
|
|
179
|
+
- [x] **Fix lint & lint:fix scripts to cover all code** ✅ COMPLETED
|
|
180
|
+
- [x] Update ESLint configuration to include `src/homebridge-ui/**/*.ts` files
|
|
181
|
+
- [x] Add HTML linting for `src/homebridge-ui/**/*.html` files
|
|
182
|
+
- [x] Installed `eslint-plugin-html` for inline JavaScript in HTML
|
|
183
|
+
- [x] Update `npm run lint` script to lint both plugin and UI code
|
|
184
|
+
- [x] Update `npm run lint:fix` script to auto-fix both plugin and UI code
|
|
185
|
+
- [x] Fixed existing ESLint errors (regex patterns, multi-statement lines)
|
|
186
|
+
- [x] Lint now passes successfully
|
|
187
|
+
- [x] Test that `npm run lint` runs successfully without errors
|
|
188
|
+
|
|
189
|
+
**Changes Made:**
|
|
190
|
+
- Installed `eslint-plugin-html` package
|
|
191
|
+
- Updated `eslint.config.js` to import and configure HTML plugin
|
|
192
|
+
- Added `html: true` to formatters in ESLint config
|
|
193
|
+
- Updated package.json scripts: `lint` and `lint:fix` now include `src/homebridge-ui/**/*.html`
|
|
194
|
+
- Moved regex patterns to module scope in `server.ts` and `genericDevice.ts`
|
|
195
|
+
- Split multi-statement lines to comply with `style/max-statements-per-line` rule
|
|
196
|
+
- All lint errors fixed - `npm run lint` passes with 0 errors
|
|
197
|
+
|
|
198
|
+
### Current Issues
|
|
199
|
+
|
|
200
|
+
- [x] **Fix TypeScript compilation errors in discovery endpoint** ✅ COMPLETED
|
|
201
|
+
- [x] Fixed: Changed `discover({ duration: 5000 })` to `discover({ timeout: 5000 })`
|
|
202
|
+
- [x] Fixed: Changed `switchbot.getDevices()` to use `switchbot.getAPIClient()?.getDevices()`
|
|
203
|
+
- [x] Reviewed node-switchbot v4.0.0-beta.3 API documentation and type definitions
|
|
204
|
+
- [x] Updated discovery implementation to use correct API types (APIDevice, APIInfraredRemote)
|
|
205
|
+
- [x] Fixed property names: `deviceId`, `deviceName`, `deviceType`, `remoteType`
|
|
206
|
+
- [x] Removed references to non-existent properties (`id`, `name`, `type`, `model`, `deviceModel`)
|
|
207
|
+
|
|
208
|
+
**Changes Made:**
|
|
209
|
+
- Updated BLE discovery to use `timeout` parameter instead of `duration`
|
|
210
|
+
- Changed OpenAPI access to use `switchbot.getAPIClient()?.getDevices()`
|
|
211
|
+
- Simplified response parsing: `apiData.deviceList` and `apiData.infraredRemoteList` (no `body` wrapper)
|
|
212
|
+
- Fixed all property accesses to match APIDevice and APIInfraredRemote interfaces
|
|
213
|
+
- Build now succeeds with 0 TypeScript errors
|
|
214
|
+
- All 39 tests still pass
|
|
215
|
+
|
|
216
|
+
- [ ] **Test discovery with real hardware**
|
|
217
|
+
- [ ] Test BLE discovery with nearby devices
|
|
218
|
+
- [ ] Test OpenAPI discovery with cloud-registered devices
|
|
219
|
+
- [ ] Test with mixed BLE+API devices
|
|
220
|
+
- [ ] Test connection type badge display
|
|
221
|
+
- [ ] Verify deduplication works correctly
|
|
222
|
+
|
|
223
|
+
- [ ] **Add error handling improvements**
|
|
224
|
+
- [ ] Better error messages for users
|
|
225
|
+
- [ ] Retry logic with exponential backoff
|
|
226
|
+
- [ ] Graceful degradation when BLE unavailable
|
|
227
|
+
- [ ] Network timeout handling
|
|
228
|
+
|
|
229
|
+
---
|
|
230
|
+
|
|
231
|
+
## Documentation
|
|
232
|
+
|
|
233
|
+
- [ ] **Update README with discovery features**
|
|
234
|
+
- [ ] Document BLE vs OpenAPI discovery
|
|
235
|
+
- [ ] Add screenshots of new UI features
|
|
236
|
+
- [ ] Explain connection type badges
|
|
237
|
+
- [ ] Add troubleshooting guide for discovery issues
|
|
238
|
+
|
|
239
|
+
- [ ] **Create developer documentation**
|
|
240
|
+
- [ ] Document new modular structure
|
|
241
|
+
- [ ] API documentation for endpoints
|
|
242
|
+
- [ ] Contributing guidelines for UI changes
|
|
243
|
+
|
|
244
|
+
---
|
|
245
|
+
|
|
246
|
+
## Priority Summary
|
|
247
|
+
|
|
248
|
+
### Must Do (Next Release)
|
|
249
|
+
|
|
250
|
+
1. **Fix lint & lint:fix scripts** (blocks clean CI/CD)
|
|
251
|
+
2. Fix TypeScript compilation errors in discovery
|
|
252
|
+
3. One-Click Device Import
|
|
253
|
+
4. Duplicate Detection
|
|
254
|
+
5. Signal Strength Visualization
|
|
255
|
+
6. Better Loading States
|
|
256
|
+
|
|
257
|
+
### Should Do (Soon)
|
|
258
|
+
|
|
259
|
+
1. Split server.ts into modules
|
|
260
|
+
2. Extract DEVICE_TYPES constant
|
|
261
|
+
3. Filtering & Sorting
|
|
262
|
+
4. Connection Recommendations
|
|
263
|
+
5. Device Grouping
|
|
264
|
+
|
|
265
|
+
### Nice to Have (Future)
|
|
266
|
+
|
|
267
|
+
1. Extract all CSS and JavaScript
|
|
268
|
+
2. Configurable BLE Scan
|
|
269
|
+
3. Discovery History/Cache
|
|
270
|
+
4. Connection Testing
|
|
271
|
+
5. Batch Import
|
|
272
|
+
|
|
273
|
+
---
|
|
274
|
+
|
|
275
|
+
## Notes
|
|
276
|
+
|
|
277
|
+
- Consider user feedback on most-wanted features
|
|
278
|
+
- Test all changes with real SwitchBot devices
|
|
279
|
+
- Maintain backwards compatibility with existing configs
|
|
280
|
+
- Keep UI responsive and fast (< 500ms interactions)
|
|
281
|
+
- Follow Homebridge UI/UX conventions
|
|
282
|
+
|
|
283
|
+
---
|
|
284
|
+
|
|
285
|
+
## Detailed Implementation Steps: HTML/CSS/JS Split
|
|
286
|
+
|
|
287
|
+
### Overview
|
|
288
|
+
|
|
289
|
+
Split `src/homebridge-ui/public/index.html` (764 lines) into modular structure using native ES6 modules (no bundler required).
|
|
290
|
+
|
|
291
|
+
**Target Structure:**
|
|
292
|
+
|
|
293
|
+
```
|
|
294
|
+
src/homebridge-ui/public/
|
|
295
|
+
├── index.html # Clean HTML structure (~100 lines)
|
|
296
|
+
├── css/
|
|
297
|
+
│ └── styles.css # All styles (~150 lines)
|
|
298
|
+
└── js/
|
|
299
|
+
├── constants.js # Device types (~100 lines)
|
|
300
|
+
├── api.js # API client (~150 lines)
|
|
301
|
+
├── discovery.js # Discovery rendering (~200 lines)
|
|
302
|
+
├── modals.js # Modal management (~100 lines)
|
|
303
|
+
├── forms.js # Form handling (~50 lines)
|
|
304
|
+
└── app.js # Main entry point (~50 lines)
|
|
305
|
+
```
|
|
306
|
+
|
|
307
|
+
### Step 1: Extract CSS Styles
|
|
308
|
+
|
|
309
|
+
**Goal:** Move all inline styles to external stylesheet
|
|
310
|
+
|
|
311
|
+
- [ ] **Create CSS file**
|
|
312
|
+
- [ ] Create `src/homebridge-ui/public/css/styles.css`
|
|
313
|
+
- [ ] Copy entire `<style>` block contents from `index.html` (~100 lines)
|
|
314
|
+
- [ ] Verify no dynamic styles are being generated (all should be static CSS)
|
|
315
|
+
|
|
316
|
+
- [ ] **Update HTML**
|
|
317
|
+
- [ ] Remove `<style>` block from `index.html`
|
|
318
|
+
- [ ] Add `<link rel="stylesheet" href="css/styles.css">` to `<head>`
|
|
319
|
+
- [ ] Test that styles still load correctly
|
|
320
|
+
|
|
321
|
+
- [ ] **Build & Test**
|
|
322
|
+
- [ ] Run `npm run build`
|
|
323
|
+
- [ ] Verify `dist/homebridge-ui/public/css/styles.css` exists
|
|
324
|
+
- [ ] Test UI in browser (all styles should work)
|
|
325
|
+
|
|
326
|
+
### Step 2: Extract DEVICE_TYPES Constant
|
|
327
|
+
|
|
328
|
+
**Goal:** Extract large device types constant to separate module
|
|
329
|
+
|
|
330
|
+
- [ ] **Create constants module**
|
|
331
|
+
- [ ] Create `src/homebridge-ui/public/js/constants.js`
|
|
332
|
+
- [ ] Copy DEVICE_TYPES constant (~100 lines)
|
|
333
|
+
- [ ] Add `export` statement: `export const DEVICE_TYPES = { ... }`
|
|
334
|
+
- [ ] Add any other constants currently in HTML
|
|
335
|
+
|
|
336
|
+
- [ ] **Update HTML**
|
|
337
|
+
- [ ] Remove DEVICE_TYPES constant from `<script>` block
|
|
338
|
+
- [ ] Add at top of script block: `import { DEVICE_TYPES } from './js/constants.js'`
|
|
339
|
+
- [ ] Change `<script>` to `<script type="module">`
|
|
340
|
+
- [ ] Verify all DEVICE_TYPES references still work
|
|
341
|
+
|
|
342
|
+
- [ ] **Build & Test**
|
|
343
|
+
- [ ] Run `npm run build`
|
|
344
|
+
- [ ] Verify `dist/homebridge-ui/public/js/constants.js` exists
|
|
345
|
+
- [ ] Test device type dropdown still populates correctly
|
|
346
|
+
|
|
347
|
+
### Step 3: Extract API Functions
|
|
348
|
+
|
|
349
|
+
**Goal:** Move all API/fetch functions to dedicated module
|
|
350
|
+
|
|
351
|
+
- [ ] **Create API module**
|
|
352
|
+
- [ ] Create `src/homebridge-ui/public/js/api.js`
|
|
353
|
+
- [ ] Extract and export these functions:
|
|
354
|
+
- [ ] `loadConfig()` - Fetch platform config
|
|
355
|
+
- [ ] `saveConfig(config)` - Save platform config
|
|
356
|
+
- [ ] `discoverDevices()` - Trigger device discovery
|
|
357
|
+
- [ ] `addDevice(device)` - Add device to config
|
|
358
|
+
- [ ] `updateDevice(device)` - Update device in config
|
|
359
|
+
- [ ] `deleteDevice(id)` - Remove device from config
|
|
360
|
+
- [ ] Keep error handling in each function
|
|
361
|
+
- [ ] Add JSDoc comments for each function
|
|
362
|
+
|
|
363
|
+
- [ ] **Update HTML**
|
|
364
|
+
- [ ] Remove API functions from `<script>` block
|
|
365
|
+
- [ ] Add import: `import * as api from './js/api.js'`
|
|
366
|
+
- [ ] Update all function calls: `loadConfig()` → `api.loadConfig()`
|
|
367
|
+
- [ ] Test all API interactions work
|
|
368
|
+
|
|
369
|
+
- [ ] **Build & Test**
|
|
370
|
+
- [ ] Run `npm run build`
|
|
371
|
+
- [ ] Test load config on page load
|
|
372
|
+
- [ ] Test save config
|
|
373
|
+
- [ ] Test discovery
|
|
374
|
+
|
|
375
|
+
### Step 4: Extract Discovery Rendering
|
|
376
|
+
|
|
377
|
+
**Goal:** Move discovery UI rendering logic to separate module
|
|
378
|
+
|
|
379
|
+
- [ ] **Create discovery module**
|
|
380
|
+
- [ ] Create `src/homebridge-ui/public/js/discovery.js`
|
|
381
|
+
- [ ] Extract and export these functions:
|
|
382
|
+
- [ ] `renderDiscoveredDevices(devices, irDevices)` - Main render function
|
|
383
|
+
- [ ] `createDeviceListItem(device)` - Create single device element
|
|
384
|
+
- [ ] `createConnectionBadge(type)` - Create connection type badge
|
|
385
|
+
- [ ] `createIRBadge()` - Create IR device badge
|
|
386
|
+
- [ ] `formatDeviceDetails(device)` - Format detail text
|
|
387
|
+
- [ ] Keep all DOM manipulation in this module
|
|
388
|
+
|
|
389
|
+
- [ ] **Update HTML**
|
|
390
|
+
- [ ] Remove discovery rendering functions from `<script>` block
|
|
391
|
+
- [ ] Add import: `import * as discovery from './js/discovery.js'`
|
|
392
|
+
- [ ] Update function calls to use imported module
|
|
393
|
+
- [ ] Test discovery results render correctly
|
|
394
|
+
|
|
395
|
+
- [ ] **Build & Test**
|
|
396
|
+
- [ ] Run `npm run build`
|
|
397
|
+
- [ ] Test discovery UI rendering
|
|
398
|
+
- [ ] Verify badges display correctly
|
|
399
|
+
- [ ] Test with empty results
|
|
400
|
+
|
|
401
|
+
### Step 5: Extract Modal Management
|
|
402
|
+
|
|
403
|
+
**Goal:** Move modal logic to dedicated module
|
|
404
|
+
|
|
405
|
+
- [ ] **Create modals module**
|
|
406
|
+
- [ ] Create `src/homebridge-ui/public/js/modals.js`
|
|
407
|
+
- [ ] Extract and export these functions:
|
|
408
|
+
- [ ] `showEditModal(device)` - Show edit/add device modal
|
|
409
|
+
- [ ] `hideEditModal()` - Close edit modal
|
|
410
|
+
- [ ] `showDeleteModal(device)` - Show delete confirmation
|
|
411
|
+
- [ ] `hideDeleteModal()` - Close delete modal
|
|
412
|
+
- [ ] `populateModalForm(device)` - Fill form with device data
|
|
413
|
+
- [ ] `getModalFormData()` - Extract form data
|
|
414
|
+
- [ ] Keep modal state management in module
|
|
415
|
+
|
|
416
|
+
- [ ] **Update HTML**
|
|
417
|
+
- [ ] Remove modal functions from `<script>` block
|
|
418
|
+
- [ ] Add import: `import * as modals from './js/modals.js'`
|
|
419
|
+
- [ ] Update all modal calls to use imported module
|
|
420
|
+
- [ ] Test modal open/close/submit
|
|
421
|
+
|
|
422
|
+
- [ ] **Build & Test**
|
|
423
|
+
- [ ] Run `npm run build`
|
|
424
|
+
- [ ] Test add device modal
|
|
425
|
+
- [ ] Test edit device modal
|
|
426
|
+
- [ ] Test delete confirmation modal
|
|
427
|
+
- [ ] Verify form validation works
|
|
428
|
+
|
|
429
|
+
### Step 6: Extract Form Handling
|
|
430
|
+
|
|
431
|
+
**Goal:** Move form validation and submission logic
|
|
432
|
+
|
|
433
|
+
- [ ] **Create forms module**
|
|
434
|
+
- [ ] Create `src/homebridge-ui/public/js/forms.js`
|
|
435
|
+
- [ ] Extract and export these functions:
|
|
436
|
+
- [ ] `validateDeviceForm(formData)` - Validate form inputs
|
|
437
|
+
- [ ] `handleDeviceSubmit(formData)` - Process form submission
|
|
438
|
+
- [ ] `resetForm()` - Clear form fields
|
|
439
|
+
- [ ] `formatFormData(rawData)` - Format form data for API
|
|
440
|
+
- [ ] `showFormError(field, message)` - Display validation error
|
|
441
|
+
- [ ] `clearFormErrors()` - Clear all validation errors
|
|
442
|
+
|
|
443
|
+
- [ ] **Update HTML**
|
|
444
|
+
- [ ] Remove form handling functions from `<script>` block
|
|
445
|
+
- [ ] Add import: `import * as forms from './js/forms.js'`
|
|
446
|
+
- [ ] Update event handlers to use imported functions
|
|
447
|
+
- [ ] Test form validation and submission
|
|
448
|
+
|
|
449
|
+
- [ ] **Build & Test**
|
|
450
|
+
- [ ] Run `npm run build`
|
|
451
|
+
- [ ] Test form validation (empty fields, invalid data)
|
|
452
|
+
- [ ] Test form submission (add/edit device)
|
|
453
|
+
- [ ] Verify error messages display correctly
|
|
454
|
+
|
|
455
|
+
### Step 7: Create Main App Module
|
|
456
|
+
|
|
457
|
+
**Goal:** Create central app initialization and coordination
|
|
458
|
+
|
|
459
|
+
- [ ] **Create app module**
|
|
460
|
+
- [ ] Create `src/homebridge-ui/public/js/app.js`
|
|
461
|
+
- [ ] Export `init()` function that:
|
|
462
|
+
- [ ] Loads initial config on page load
|
|
463
|
+
- [ ] Sets up all event listeners
|
|
464
|
+
- [ ] Initializes UI components
|
|
465
|
+
- [ ] Handles global state
|
|
466
|
+
- [ ] Move event listeners from HTML to app.js
|
|
467
|
+
- [ ] Coordinate between all other modules
|
|
468
|
+
|
|
469
|
+
- [ ] **Update HTML**
|
|
470
|
+
- [ ] Remove all remaining JavaScript from `<script>` block
|
|
471
|
+
- [ ] Keep only imports and single line: `import { init } from './js/app.js'; init();`
|
|
472
|
+
- [ ] Or use DOMContentLoaded: `document.addEventListener('DOMContentLoaded', () => init())`
|
|
473
|
+
- [ ] Remove now-empty `<script>` block if all code moved
|
|
474
|
+
|
|
475
|
+
- [ ] **Build & Test**
|
|
476
|
+
- [ ] Run `npm run build`
|
|
477
|
+
- [ ] Test complete page load and initialization
|
|
478
|
+
- [ ] Test all features end-to-end
|
|
479
|
+
- [ ] Verify no console errors
|
|
480
|
+
|
|
481
|
+
### Step 8: Final Cleanup and Verification
|
|
482
|
+
|
|
483
|
+
**Goal:** Ensure everything works and clean up
|
|
484
|
+
|
|
485
|
+
- [ ] **Verify build output**
|
|
486
|
+
- [ ] Check all files copied to `dist/homebridge-ui/public/`
|
|
487
|
+
- [ ] Verify file structure matches source
|
|
488
|
+
- [ ] Check file sizes (modules should be reasonable)
|
|
489
|
+
|
|
490
|
+
- [ ] **Test all functionality**
|
|
491
|
+
- [ ] Load config on page open
|
|
492
|
+
- [ ] Add new device
|
|
493
|
+
- [ ] Edit existing device
|
|
494
|
+
- [ ] Delete device
|
|
495
|
+
- [ ] Run discovery
|
|
496
|
+
- [ ] Test all filters/sorting (if implemented)
|
|
497
|
+
- [ ] Test on different browsers (Chrome, Safari, Firefox)
|
|
498
|
+
|
|
499
|
+
- [ ] **Code cleanup**
|
|
500
|
+
- [ ] Remove any unused functions
|
|
501
|
+
- [ ] Add JSDoc comments to all exports
|
|
502
|
+
- [ ] Ensure consistent code style
|
|
503
|
+
- [ ] Remove console.log statements (or convert to proper logging)
|
|
504
|
+
|
|
505
|
+
- [ ] **Documentation**
|
|
506
|
+
- [ ] Update comments in code
|
|
507
|
+
- [ ] Document module dependencies
|
|
508
|
+
- [ ] Add README in `src/homebridge-ui/public/js/` if needed
|
|
509
|
+
- [ ] Update main README if UI architecture changed significantly
|
|
510
|
+
|
|
511
|
+
### Step 9: Optional Enhancements
|
|
512
|
+
|
|
513
|
+
**Goal:** Further improvements after basic split
|
|
514
|
+
|
|
515
|
+
- [ ] **Add TypeScript for UI code**
|
|
516
|
+
- [ ] Rename `.js` files to `.ts`
|
|
517
|
+
- [ ] Add type definitions
|
|
518
|
+
- [ ] Update build to compile UI TypeScript
|
|
519
|
+
- [ ] Add type checking to lint scripts
|
|
520
|
+
|
|
521
|
+
- [ ] **Add minification**
|
|
522
|
+
- [ ] Consider adding Terser for JS minification
|
|
523
|
+
- [ ] Consider adding cssnano for CSS minification
|
|
524
|
+
- [ ] Update build script for production builds
|
|
525
|
+
|
|
526
|
+
- [ ] **Add source maps**
|
|
527
|
+
- [ ] Generate source maps for easier debugging
|
|
528
|
+
- [ ] Configure build to include maps
|
|
529
|
+
- [ ] Test debugging in browser DevTools
|
|
530
|
+
|
|
531
|
+
---
|
|
532
|
+
|
|
533
|
+
## Implementation Notes
|
|
534
|
+
|
|
535
|
+
### Why Native ES6 Modules?
|
|
536
|
+
|
|
537
|
+
- ✅ No bundler needed (simpler build process)
|
|
538
|
+
- ✅ Native browser support (Safari 11+, Chrome 61+, Firefox 60+)
|
|
539
|
+
- ✅ Easier debugging (direct source code visibility)
|
|
540
|
+
- ✅ Suitable for local Homebridge UI (no network latency concerns)
|
|
541
|
+
- ✅ Hot reload friendly (just refresh browser)
|
|
542
|
+
|
|
543
|
+
### Browser Compatibility
|
|
544
|
+
|
|
545
|
+
- ES6 modules work in all modern browsers (2017+)
|
|
546
|
+
- Homebridge UI runs locally, so old browser support not critical
|
|
547
|
+
- Most Homebridge users have up-to-date browsers
|
|
548
|
+
|
|
549
|
+
### Build Process
|
|
550
|
+
|
|
551
|
+
- Current: `npm run plugin-ui` copies `src/homebridge-ui/public` → `dist/homebridge-ui/public`
|
|
552
|
+
- After split: Same command, just copies more files (no changes needed)
|
|
553
|
+
- Glob pattern `**/*` already handles subdirectories
|
|
554
|
+
|
|
555
|
+
### Testing Checklist
|
|
556
|
+
|
|
557
|
+
Each step should be tested before moving to next:
|
|
558
|
+
|
|
559
|
+
1. Build succeeds without errors
|
|
560
|
+
2. Files copied to dist/ correctly
|
|
561
|
+
3. UI loads in browser without errors
|
|
562
|
+
4. All functionality works as before
|
|
563
|
+
5. No console errors or warnings
|
|
564
|
+
6. Performance is same or better
|