@switchbot/homebridge-switchbot 5.0.0-beta.136 → 5.0.0-beta.138
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/dist/errors.d.ts +37 -4
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +31 -50
- package/dist/errors.js.map +1 -1
- package/dist/homebridge-ui/endpoints/devices.d.ts.map +1 -1
- package/dist/homebridge-ui/endpoints/devices.js.map +1 -1
- package/dist/platform.d.ts +2 -1
- package/dist/platform.d.ts.map +1 -1
- package/dist/platform.js +1 -1
- package/dist/platform.js.map +1 -1
- package/dist/switchbotClient.d.ts +0 -4
- package/dist/switchbotClient.d.ts.map +1 -1
- package/dist/switchbotClient.js +16 -90
- package/dist/switchbotClient.js.map +1 -1
- package/docs/variables/default.html +1 -1
- package/package.json +3 -3
- package/src/errors.ts +30 -38
- package/src/homebridge-ui/endpoints/devices.ts +29 -14
- package/src/platform.ts +1 -1
- package/src/switchbotClient.ts +16 -90
- package/test/client/switchbot-client-debounce.spec.ts +35 -0
- package/test/client/switchbot-client-openapi.spec.ts +19 -0
- package/test/client/switchbotClient.spec.ts +23 -0
- package/test/device/device-mapping.spec.ts +23 -0
- package/test/device/deviceBase.spec.ts +26 -0
- package/test/device/deviceFactory-edge.spec.ts +15 -0
- package/test/device/deviceFactory.spec.ts +33 -0
- package/test/device/fan-swing.spec.ts +34 -0
- package/test/device/irdevice.spec.ts +9 -0
- package/test/device/lock-users.spec.ts +35 -0
- package/test/device/matter-descriptors.spec.ts +22 -0
- package/test/device/matter-device-state.spec.ts +37 -0
- package/test/errors/errors.spec.ts +10 -0
- package/test/homebridge-ui/server.spec.ts +9 -0
- package/test/platform/accessory-restore.spec.ts +36 -0
- package/test/platform/matter-childbridge.spec.ts +34 -0
- package/test/platform/matter-integration.spec.ts +33 -0
- package/test/platform/platform-edge.spec.ts +72 -0
- package/test/platform/platform.integration.spec.ts +34 -0
- package/test/utils/utils-extra.spec.ts +10 -0
- package/test/utils/utils.spec.ts +53 -0
- package/todo/TODO.md +55 -165
- package/test/accessory-restore.spec.ts +0 -74
- package/test/device-mapping.spec.ts +0 -38
- package/test/deviceFactory.spec.ts +0 -19
- package/test/fan-swing.spec.ts +0 -30
- package/test/lock-users.spec.ts +0 -44
- package/test/matter-childbridge.spec.ts +0 -62
- package/test/matter-descriptors.spec.ts +0 -110
- package/test/matter-device-state.spec.ts +0 -117
- package/test/matter-integration.spec.ts +0 -183
- package/test/platform.integration.spec.ts +0 -57
- package/test/switchbot-client-debounce.spec.ts +0 -127
- package/test/switchbot-client-openapi.spec.ts +0 -63
- package/test/switchbotClient.spec.ts +0 -11
- package/test/utils.spec.ts +0 -37
- package/todo/COMPLETED.md +0 -542
- package/todo/README.md +0 -59
- package/todo/mockups/filtering-sorting.svg +0 -112
- package/todo/mockups/modal-switchbot-theme.svg +0 -66
- package/todo/mockups/signal-strength-visualization.svg +0 -94
package/todo/TODO.md
CHANGED
|
@@ -1,190 +1,80 @@
|
|
|
1
|
-
# SwitchBot Plugin TODO List
|
|
1
|
+
# SwitchBot Plugin TODO List
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
#### 8. Batch Import
|
|
5
|
-
|
|
6
|
-
- [x] Add checkboxes to select multiple devices
|
|
7
|
-
- [x] Add "Add Selected to Config" button
|
|
8
|
-
- [x] Implement bulk configuration with smart defaults
|
|
9
|
-
|
|
10
|
-
- [x] Show firmware update available indicators
|
|
11
|
-
- [x] Show offline/unreachable warnings
|
|
12
|
-
- [x] Add "Needs Attention" section at top
|
|
13
3
|
- [ ] Implement battery level trending (if historical data available)
|
|
14
|
-
|
|
15
|
-
#### 10. Export/Import Discovery
|
|
16
|
-
|
|
17
4
|
- [ ] Add "Export Results" button (JSON format)
|
|
18
5
|
- [ ] Add "Import Results" for comparison or troubleshooting
|
|
19
6
|
- [ ] Share with support for debugging
|
|
20
7
|
- [ ] Compare current vs previous discovery (show differences)
|
|
21
8
|
- [ ] Generate discovery report (formatted summary)
|
|
22
|
-
|
|
23
|
-
---
|
|
24
|
-
|
|
25
|
-
## Bug Fixes & Technical Debt
|
|
26
|
-
|
|
27
|
-
### Testing & Quality Assurance
|
|
28
|
-
|
|
29
9
|
- [ ] **Test discovery with real hardware**
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
10
|
+
- [ ] Test BLE discovery with nearby devices
|
|
11
|
+
- [ ] Test OpenAPI discovery with cloud-registered devices
|
|
12
|
+
- [ ] Test with mixed BLE+API devices
|
|
13
|
+
- [ ] Test connection type badge display
|
|
14
|
+
- [ ] Verify deduplication works correctly
|
|
36
15
|
- [ ] **Add error handling improvements**
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
---
|
|
43
|
-
|
|
44
|
-
## Documentation
|
|
45
|
-
|
|
16
|
+
- [ ] Better error messages for users
|
|
17
|
+
- [ ] Retry logic with exponential backoff
|
|
18
|
+
- [ ] Graceful degradation when BLE unavailable
|
|
19
|
+
- [ ] Network timeout handling
|
|
46
20
|
- [ ] **Update README with discovery features**
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
21
|
+
- [ ] Document BLE vs OpenAPI discovery
|
|
22
|
+
- [ ] Add screenshots of new UI features
|
|
23
|
+
- [ ] Explain connection type badges
|
|
24
|
+
- [ ] Add troubleshooting guide for discovery issues
|
|
52
25
|
- [ ] **Create developer documentation**
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
1. Connection Recommendations
|
|
68
|
-
2. Device Grouping
|
|
69
|
-
3. Test discovery with real hardware
|
|
70
|
-
4. Update README with new features
|
|
71
|
-
|
|
72
|
-
### Nice to Have (Future)
|
|
73
|
-
|
|
74
|
-
1. Configurable BLE Scan
|
|
75
|
-
2. Discovery History/Cache
|
|
76
|
-
3. Connection Testing
|
|
77
|
-
4. Batch Import
|
|
78
|
-
5. Device Health Dashboard
|
|
79
|
-
|
|
80
|
-
---
|
|
81
|
-
|
|
82
|
-
## Notes
|
|
83
|
-
|
|
84
|
-
- See [COMPLETED.md](COMPLETED.md) for all completed features
|
|
85
|
-
- UI mockups available in [mockups/](mockups/) directory
|
|
86
|
-
- Consider user feedback on most-wanted features
|
|
87
|
-
- Test all changes with real SwitchBot devices
|
|
88
|
-
- Maintain backwards compatibility with existing configs
|
|
89
|
-
- Keep UI responsive and fast (< 500ms interactions)
|
|
90
|
-
- Follow Homebridge UI/UX conventions
|
|
91
|
-
# Integration: node-switchbot Beta Updates (March 2026)
|
|
92
|
-
|
|
93
|
-
## Tasks to Integrate Latest node-switchbot Features
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
## Next Features
|
|
97
|
-
|
|
98
|
-
### Advanced Features (Priority: Low)
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
#### 8. Batch Import
|
|
104
|
-
|
|
26
|
+
- [ ] Document new modular structure
|
|
27
|
+
- [ ] API documentation for endpoints
|
|
28
|
+
- [ ] Contributing guidelines for UI changes
|
|
29
|
+
- [ ] Better Loading States
|
|
30
|
+
- [ ] Connection Recommendations
|
|
31
|
+
- [ ] Device Grouping
|
|
32
|
+
- [ ] Test discovery with real hardware
|
|
33
|
+
- [ ] Update README with new features
|
|
34
|
+
- [ ] Configurable BLE Scan
|
|
35
|
+
- [ ] Discovery History/Cache
|
|
36
|
+
- [ ] Connection Testing
|
|
37
|
+
- [ ] Batch Import
|
|
38
|
+
- [ ] Device Health Dashboard
|
|
105
39
|
- [ ] Add checkboxes to select multiple devices
|
|
106
40
|
- [ ] Add "Add Selected to Config" button
|
|
107
41
|
- [ ] Implement bulk configuration with smart defaults
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
- [x] Show firmware update available indicators
|
|
111
|
-
- [x] Show offline/unreachable warnings
|
|
112
42
|
- [ ] Add "Needs Attention" section at top
|
|
113
43
|
- [ ] Implement battery level trending (if historical data available)
|
|
114
|
-
|
|
115
|
-
#### 10. Export/Import Discovery
|
|
116
|
-
|
|
117
44
|
- [ ] Add "Export Results" button (JSON format)
|
|
118
45
|
- [ ] Add "Import Results" for comparison or troubleshooting
|
|
119
46
|
- [ ] Share with support for debugging
|
|
120
47
|
- [ ] Compare current vs previous discovery (show differences)
|
|
121
48
|
- [ ] Generate discovery report (formatted summary)
|
|
122
|
-
|
|
123
|
-
---
|
|
124
|
-
|
|
125
|
-
## Bug Fixes & Technical Debt
|
|
126
|
-
|
|
127
|
-
### Testing & Quality Assurance
|
|
128
|
-
|
|
49
|
+
- [ ] Add tests for battery level trending logic
|
|
129
50
|
- [ ] **Test discovery with real hardware**
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
51
|
+
- [ ] Add tests for battery level trending logic
|
|
52
|
+
- [ ] Test BLE discovery with nearby devices
|
|
53
|
+
- [ ] Test OpenAPI discovery with cloud-registered devices
|
|
54
|
+
- [ ] Test with mixed BLE+API devices
|
|
55
|
+
- [ ] Test connection type badge display
|
|
56
|
+
- [ ] Verify deduplication works correctly
|
|
136
57
|
- [ ] **Add error handling improvements**
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
---
|
|
143
|
-
|
|
144
|
-
## Documentation
|
|
145
|
-
|
|
58
|
+
- [ ] Better error messages for users
|
|
59
|
+
- [ ] Retry logic with exponential backoff
|
|
60
|
+
- [ ] Graceful degradation when BLE unavailable
|
|
61
|
+
- [ ] Network timeout handling
|
|
146
62
|
- [ ] **Update README with discovery features**
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
63
|
+
- [ ] Document BLE vs OpenAPI discovery
|
|
64
|
+
- [ ] Add screenshots of new UI features
|
|
65
|
+
- [ ] Explain connection type badges
|
|
66
|
+
- [ ] Add troubleshooting guide for discovery issues
|
|
152
67
|
- [ ] **Create developer documentation**
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
1. Connection Recommendations
|
|
168
|
-
2. Device Grouping
|
|
169
|
-
3. Test discovery with real hardware
|
|
170
|
-
4. Update README with new features
|
|
171
|
-
|
|
172
|
-
### Nice to Have (Future)
|
|
173
|
-
|
|
174
|
-
1. Configurable BLE Scan
|
|
175
|
-
2. Discovery History/Cache
|
|
176
|
-
3. Connection Testing
|
|
177
|
-
4. Batch Import
|
|
178
|
-
5. Device Health Dashboard
|
|
179
|
-
|
|
180
|
-
---
|
|
181
|
-
|
|
182
|
-
## Notes
|
|
183
|
-
|
|
184
|
-
- See [COMPLETED.md](COMPLETED.md) for all completed features
|
|
185
|
-
- UI mockups available in [mockups/](mockups/) directory
|
|
186
|
-
- Consider user feedback on most-wanted features
|
|
187
|
-
- Test all changes with real SwitchBot devices
|
|
188
|
-
- Maintain backwards compatibility with existing configs
|
|
189
|
-
- Keep UI responsive and fast (< 500ms interactions)
|
|
190
|
-
- Follow Homebridge UI/UX conventions
|
|
68
|
+
- [ ] Document new modular structure
|
|
69
|
+
- [ ] API documentation for endpoints
|
|
70
|
+
- [ ] Contributing guidelines for UI changes
|
|
71
|
+
- [ ] Better Loading States
|
|
72
|
+
- [ ] Connection Recommendations
|
|
73
|
+
- [ ] Device Grouping
|
|
74
|
+
- [ ] Test discovery with real hardware
|
|
75
|
+
- [ ] Update README with new features
|
|
76
|
+
- [ ] Configurable BLE Scan
|
|
77
|
+
- [ ] Discovery History/Cache
|
|
78
|
+
- [ ] Connection Testing
|
|
79
|
+
- [ ] Batch Import
|
|
80
|
+
- [ ] Device Health Dashboard
|
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from 'vitest'
|
|
2
|
-
|
|
3
|
-
import { SwitchBotHAPPlatform, SwitchBotMatterPlatform } from '../src/platform'
|
|
4
|
-
|
|
5
|
-
const log = { info: () => {}, warn: () => {}, error: () => {}, debug: () => {} }
|
|
6
|
-
|
|
7
|
-
describe('accessory restore', () => {
|
|
8
|
-
it('reuses restored HAP accessory by context.deviceId and avoids re-register', async () => {
|
|
9
|
-
const registered: any[] = []
|
|
10
|
-
const hap = { uuid: { generate: (s: string) => `uuid-${s}` }, Service: {}, Characteristic: {} }
|
|
11
|
-
|
|
12
|
-
function PlatformAccessory(this: any, name: string, uuid: string) {
|
|
13
|
-
this.displayName = name
|
|
14
|
-
this.UUID = uuid
|
|
15
|
-
this.context = {}
|
|
16
|
-
this.getService = () => undefined
|
|
17
|
-
this.addService = () => undefined
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
const api: any = {
|
|
21
|
-
hap,
|
|
22
|
-
platformAccessory: PlatformAccessory as any,
|
|
23
|
-
registerPlatformAccessories: (_p: string, _n: string, accs: any[]) => registered.push(...accs),
|
|
24
|
-
on: () => {},
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
const platform = new SwitchBotHAPPlatform(log as any, { platform: 'SwitchBot', devices: [{ id: 'dev1', type: 'light', name: 'NewName' }] }, api)
|
|
28
|
-
|
|
29
|
-
// Simulate restored accessory with different uuid but correct deviceId in context
|
|
30
|
-
const restored = new (api.platformAccessory)('OldName', 'old-uuid')
|
|
31
|
-
restored.context = { deviceId: 'dev1', type: 'light' }
|
|
32
|
-
platform.configureAccessory(restored)
|
|
33
|
-
|
|
34
|
-
// Load devices should reuse restored accessory by context.deviceId
|
|
35
|
-
await (platform as any).loadDevices()
|
|
36
|
-
|
|
37
|
-
// No new registration for this device because restored accessory was reused
|
|
38
|
-
expect(registered.length).toBe(0)
|
|
39
|
-
// The restored accessory should remain in the platform's accessory map
|
|
40
|
-
const keys = [...(platform as any).accessories.keys()]
|
|
41
|
-
expect(keys).toContain('old-uuid')
|
|
42
|
-
const acc = (platform as any).accessories.get('old-uuid')
|
|
43
|
-
expect(acc.context.deviceId).toBe('dev1')
|
|
44
|
-
})
|
|
45
|
-
|
|
46
|
-
it('reuses restored Matter accessory by context.deviceId when registering', async () => {
|
|
47
|
-
const captured: any[] = []
|
|
48
|
-
const matter = { uuid: { generate: (s: string) => `uuid-${s}` }, clusterNames: {} }
|
|
49
|
-
const api: any = {
|
|
50
|
-
matter,
|
|
51
|
-
isMatterAvailable: () => true,
|
|
52
|
-
isMatterEnabled: () => true,
|
|
53
|
-
on: () => {},
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
const platform = new SwitchBotMatterPlatform(log as any, { platform: 'SwitchBot', devices: [{ id: 'm1', type: 'light', name: 'M1' }] }, api)
|
|
57
|
-
|
|
58
|
-
// Simulate restored Matter accessory with a different uuid but matching deviceId
|
|
59
|
-
const restored = { uuid: 'restored-uuid', displayName: 'OldM', context: { deviceId: 'm1', type: 'light' } }
|
|
60
|
-
;(platform as any).accessories.set(restored.uuid, restored)
|
|
61
|
-
|
|
62
|
-
// stub matter.registerPlatformAccessories to capture what is registered
|
|
63
|
-
api.matter.registerPlatformAccessories = async (_p: string, _n: string, accs: any[]) => captured.push(...accs)
|
|
64
|
-
|
|
65
|
-
// call registerMatterAccessories
|
|
66
|
-
await (platform as any).registerMatterAccessories()
|
|
67
|
-
|
|
68
|
-
// The restored accessory should still be present and associated with deviceId
|
|
69
|
-
const keys = [...(platform as any).accessories.keys()]
|
|
70
|
-
expect(keys).toContain(restored.uuid)
|
|
71
|
-
const acc = (platform as any).accessories.get(restored.uuid)
|
|
72
|
-
expect(acc.context.deviceId).toBe('m1')
|
|
73
|
-
})
|
|
74
|
-
})
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from 'vitest'
|
|
2
|
-
|
|
3
|
-
import { createDevice } from '../src/deviceFactory'
|
|
4
|
-
|
|
5
|
-
const DEVICE_TYPES = [
|
|
6
|
-
'bot',
|
|
7
|
-
'curtain',
|
|
8
|
-
'fan',
|
|
9
|
-
'light',
|
|
10
|
-
'lightstrip',
|
|
11
|
-
'motion',
|
|
12
|
-
'contact',
|
|
13
|
-
'vacuum',
|
|
14
|
-
'lock',
|
|
15
|
-
'humidifier',
|
|
16
|
-
'temperature',
|
|
17
|
-
]
|
|
18
|
-
|
|
19
|
-
describe('device mapping', () => {
|
|
20
|
-
it('maps known device types to device descriptors (HAP)', async () => {
|
|
21
|
-
for (const t of DEVICE_TYPES) {
|
|
22
|
-
const created = await createDevice({ id: `dev-${t}`, type: t, name: `Name-${t}` }, { log: console, logger: console }, false)
|
|
23
|
-
expect(created).toHaveProperty('instance')
|
|
24
|
-
expect(created).toHaveProperty('createAccessory')
|
|
25
|
-
const acc = created.createAccessory?.(undefined)
|
|
26
|
-
expect(acc).toBeDefined()
|
|
27
|
-
// descriptor should include services for HAP devices
|
|
28
|
-
if (created.protocol === 'hap') {
|
|
29
|
-
expect(acc).toHaveProperty('services')
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
})
|
|
33
|
-
|
|
34
|
-
it('returns matter protocol when requested', async () => {
|
|
35
|
-
const created = await createDevice({ id: 'm1', type: 'light', name: 'M1' }, { preferMatter: true, enableMatter: true, log: console, logger: console }, true)
|
|
36
|
-
expect(created.protocol).toBe('matter')
|
|
37
|
-
})
|
|
38
|
-
})
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from 'vitest'
|
|
2
|
-
|
|
3
|
-
import { createDevice } from '../src/deviceFactory'
|
|
4
|
-
|
|
5
|
-
describe('deviceFactory', () => {
|
|
6
|
-
it('creates HAP device descriptor for light', async () => {
|
|
7
|
-
const created = await createDevice({ id: 'dev1', type: 'light', name: 'L1' }, { log: console, logger: console }, false)
|
|
8
|
-
expect(created).toHaveProperty('instance')
|
|
9
|
-
expect(created).toHaveProperty('createAccessory')
|
|
10
|
-
expect(created.protocol).toBe('hap')
|
|
11
|
-
const acc = created.createAccessory?.(undefined)
|
|
12
|
-
expect(acc).toHaveProperty('services')
|
|
13
|
-
})
|
|
14
|
-
|
|
15
|
-
it('creates Matter descriptor when useMatter=true', async () => {
|
|
16
|
-
const created = await createDevice({ id: 'dev2', type: 'light', name: 'L2' }, { preferMatter: true, enableMatter: true, log: console, logger: console }, true)
|
|
17
|
-
expect(created.protocol).toBe('matter')
|
|
18
|
-
})
|
|
19
|
-
})
|
package/test/fan-swing.spec.ts
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it, vi } from 'vitest'
|
|
2
|
-
|
|
3
|
-
import { FanDevice } from '../src/devices/genericDevice'
|
|
4
|
-
|
|
5
|
-
describe('fan swing commands', () => {
|
|
6
|
-
it('sends setSwing on boolean swing', async () => {
|
|
7
|
-
const mockClient = { setDeviceState: vi.fn(async (id: string, body: any) => ({ id, body })) }
|
|
8
|
-
const d = new FanDevice({ id: 'fan1', type: 'fan', name: 'F' }, { _client: mockClient, log: console } as any)
|
|
9
|
-
await d.init()
|
|
10
|
-
await d.setState({ swing: true })
|
|
11
|
-
expect(mockClient.setDeviceState).toHaveBeenCalled()
|
|
12
|
-
expect((mockClient.setDeviceState as any).mock.calls[0][1]).toEqual({ command: 'setSwing', parameter: 'on', commandType: 'command' })
|
|
13
|
-
})
|
|
14
|
-
|
|
15
|
-
it('sends setSwing with angle', async () => {
|
|
16
|
-
const mockClient = { setDeviceState: vi.fn(async (id: string, body: any) => ({ id, body })) }
|
|
17
|
-
const d = new FanDevice({ id: 'fan2', type: 'fan', name: 'F2' }, { _client: mockClient, log: console } as any)
|
|
18
|
-
await d.init()
|
|
19
|
-
await d.setState({ swingAngle: 45 })
|
|
20
|
-
expect((mockClient.setDeviceState as any).mock.calls[0][1]).toEqual({ command: 'setSwing', parameter: '45', commandType: 'command' })
|
|
21
|
-
})
|
|
22
|
-
|
|
23
|
-
it('sends setSwing with mode', async () => {
|
|
24
|
-
const mockClient = { setDeviceState: vi.fn(async (id: string, body: any) => ({ id, body })) }
|
|
25
|
-
const d = new FanDevice({ id: 'fan3', type: 'fan', name: 'F3' }, { _client: mockClient, log: console } as any)
|
|
26
|
-
await d.init()
|
|
27
|
-
await d.setState({ swingMode: 'vertical' })
|
|
28
|
-
expect((mockClient.setDeviceState as any).mock.calls[0][1]).toEqual({ command: 'setSwing', parameter: 'vertical', commandType: 'command' })
|
|
29
|
-
})
|
|
30
|
-
})
|
package/test/lock-users.spec.ts
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect, vi } from 'vitest'
|
|
2
|
-
import { LockDevice } from '../src/devices/genericDevice'
|
|
3
|
-
|
|
4
|
-
describe('Lock user management', () => {
|
|
5
|
-
it('sets lock pin via pin field', async () => {
|
|
6
|
-
const mockClient = { setDeviceState: vi.fn(async (id: string, body: any) => ({ id, body })) }
|
|
7
|
-
const d = new LockDevice({ id: 'lock1', type: 'lock', name: 'L1' }, { _client: mockClient, log: console } as any)
|
|
8
|
-
await d.init()
|
|
9
|
-
await d.setState({ pin: '1234' })
|
|
10
|
-
expect((mockClient.setDeviceState as any).mock.calls[0][1]).toEqual({ command: 'setLockPin', parameter: '1234', commandType: 'command' })
|
|
11
|
-
})
|
|
12
|
-
|
|
13
|
-
it('adds a user code with addUser action', async () => {
|
|
14
|
-
const mockClient = { setDeviceState: vi.fn(async (id: string, body: any) => ({ id, body })) }
|
|
15
|
-
const d = new LockDevice({ id: 'lock2', type: 'lock', name: 'L2' }, { _client: mockClient, log: console } as any)
|
|
16
|
-
await d.init()
|
|
17
|
-
await d.setState({ action: 'addUser', user: 'user1', pin: '9999' })
|
|
18
|
-
expect((mockClient.setDeviceState as any).mock.calls[0][1]).toEqual({ command: 'addUserCode', parameter: 'user1:9999', commandType: 'command' })
|
|
19
|
-
})
|
|
20
|
-
|
|
21
|
-
it('removes a user code with removeUser action', async () => {
|
|
22
|
-
const mockClient = { setDeviceState: vi.fn(async (id: string, body: any) => ({ id, body })) }
|
|
23
|
-
const d = new LockDevice({ id: 'lock3', type: 'lock', name: 'L3' }, { _client: mockClient, log: console } as any)
|
|
24
|
-
await d.init()
|
|
25
|
-
await d.setState({ action: 'removeUser', user: 'user1' })
|
|
26
|
-
expect((mockClient.setDeviceState as any).mock.calls[0][1]).toEqual({ command: 'removeUserCode', parameter: 'user1', commandType: 'command' })
|
|
27
|
-
})
|
|
28
|
-
|
|
29
|
-
it('lists users with listUsers action', async () => {
|
|
30
|
-
const mockClient = { setDeviceState: vi.fn(async (id: string, body: any) => ({ id, body })) }
|
|
31
|
-
const d = new LockDevice({ id: 'lock4', type: 'lock', name: 'L4' }, { _client: mockClient, log: console } as any)
|
|
32
|
-
await d.init()
|
|
33
|
-
await d.setState({ action: 'listUsers' })
|
|
34
|
-
expect((mockClient.setDeviceState as any).mock.calls[0][1]).toEqual({ command: 'listUsers', parameter: 'default', commandType: 'command' })
|
|
35
|
-
})
|
|
36
|
-
|
|
37
|
-
it('unlocks with pin using unlockWithPin action', async () => {
|
|
38
|
-
const mockClient = { setDeviceState: vi.fn(async (id: string, body: any) => ({ id, body })) }
|
|
39
|
-
const d = new LockDevice({ id: 'lock5', type: 'lock', name: 'L5' }, { _client: mockClient, log: console } as any)
|
|
40
|
-
await d.init()
|
|
41
|
-
await d.setState({ action: 'unlockWithPin', pin: '5555' })
|
|
42
|
-
expect((mockClient.setDeviceState as any).mock.calls[0][1]).toEqual({ command: 'unlockWithPin', parameter: '5555', commandType: 'command' })
|
|
43
|
-
})
|
|
44
|
-
})
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from 'vitest'
|
|
2
|
-
|
|
3
|
-
import { createPlatformProxy } from '../src/utils'
|
|
4
|
-
|
|
5
|
-
// This is a lightweight integration-style unit test that verifies the
|
|
6
|
-
// platform will attempt Matter registration when MatterPlatform is
|
|
7
|
-
// provided by the proxy and will still restore cached accessories.
|
|
8
|
-
|
|
9
|
-
describe('platform integration (Matter)', () => {
|
|
10
|
-
it('creates Matter descriptors when useMatter=true and restores accessories', async () => {
|
|
11
|
-
// Create a fake MatterPlatform class that records register calls
|
|
12
|
-
class FakeMatterPlatform {
|
|
13
|
-
public registered: any[] = []
|
|
14
|
-
constructor(public log: any, public cfg: any, public api: any) {}
|
|
15
|
-
async registerMatterAccessories(accessories: any[]) {
|
|
16
|
-
this.registered.push(...accessories)
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
// simulate configureAccessory hook for restored matter accessories
|
|
20
|
-
configureMatterAccessory() {
|
|
21
|
-
// no-op
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
// lightweight loadDevices implementation that uses an injected discover hook if present
|
|
25
|
-
async loadDevices() {
|
|
26
|
-
const devices = (this.cfg?.devices) || (this as any)._discoverDevices ? await (this as any)._discoverDevices() : []
|
|
27
|
-
// Simulate preparing descriptors and immediately registering them
|
|
28
|
-
const serialized = devices.map((d: any) => ({ id: d.id ?? d.deviceId ?? d, protocol: 'matter', name: d.name }))
|
|
29
|
-
if (serialized.length > 0) {
|
|
30
|
-
await this.registerMatterAccessories(serialized)
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
// Create proxy that would choose the fake matter platform when preferred
|
|
36
|
-
const Proxy = createPlatformProxy(() => {}, FakeMatterPlatform)
|
|
37
|
-
const matterApi = {
|
|
38
|
-
isMatterAvailable: () => true,
|
|
39
|
-
isMatterEnabled: () => true,
|
|
40
|
-
}
|
|
41
|
-
const platform = new (Proxy as any)(console, { preferMatter: true, enableMatter: true }, matterApi)
|
|
42
|
-
|
|
43
|
-
// Make a small device descriptor to load
|
|
44
|
-
const device = { id: 'dev-m-1', type: 'light', name: 'MatterLight' }
|
|
45
|
-
// Simulate platform method that loads devices (use same method name used in code)
|
|
46
|
-
if (typeof platform.loadDevices === 'function') {
|
|
47
|
-
// Add an internal method to return our single device for creation
|
|
48
|
-
platform._discoverDevices = async () => [device]
|
|
49
|
-
// Call loadDevices which should call the MatterPlatform.registerMatterAccessories
|
|
50
|
-
await platform.loadDevices()
|
|
51
|
-
|
|
52
|
-
// Verify FakeMatterPlatform received the accessory
|
|
53
|
-
expect(platform).toBeInstanceOf(FakeMatterPlatform)
|
|
54
|
-
expect((platform as any).registered.length).toBeGreaterThanOrEqual(1)
|
|
55
|
-
const registered = (platform as any).registered[0]
|
|
56
|
-
expect(registered).toHaveProperty('protocol', 'matter')
|
|
57
|
-
expect(registered).toHaveProperty('id', device.id)
|
|
58
|
-
} else {
|
|
59
|
-
throw new TypeError('platform.loadDevices not implemented')
|
|
60
|
-
}
|
|
61
|
-
})
|
|
62
|
-
})
|
|
@@ -1,110 +0,0 @@
|
|
|
1
|
-
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
|
2
|
-
|
|
3
|
-
import { CurtainDevice, FanDevice, LightDevice, LockDevice } from '../src/devices/genericDevice'
|
|
4
|
-
|
|
5
|
-
describe('matter descriptors and translations (per-device)', () => {
|
|
6
|
-
beforeEach(() => {
|
|
7
|
-
vi.restoreAllMocks()
|
|
8
|
-
})
|
|
9
|
-
|
|
10
|
-
it('fan: maps oscillation and swing to setDeviceState commands', async () => {
|
|
11
|
-
const calls: any[] = []
|
|
12
|
-
const fakeClient: any = { setDeviceState: async (id: string, body: any) => {
|
|
13
|
-
calls.push({ id, body })
|
|
14
|
-
return { ok: true }
|
|
15
|
-
} }
|
|
16
|
-
const d = new FanDevice({ id: 'f1', type: 'fan' } as any, { _client: fakeClient, log: console } as any)
|
|
17
|
-
|
|
18
|
-
// Oscillate
|
|
19
|
-
await d.setState({ oscillate: true })
|
|
20
|
-
expect(calls.pop()?.body.command).toBe('setOscillation')
|
|
21
|
-
|
|
22
|
-
// Swing boolean
|
|
23
|
-
await d.setState({ swing: true })
|
|
24
|
-
expect(calls.pop()?.body.command).toBe('setSwing')
|
|
25
|
-
|
|
26
|
-
// Swing angle
|
|
27
|
-
await d.setState({ swingAngle: 45 })
|
|
28
|
-
const last = calls.pop()
|
|
29
|
-
expect(last.body.command).toBe('setSwing')
|
|
30
|
-
expect(last.body.parameter).toBe('45')
|
|
31
|
-
})
|
|
32
|
-
|
|
33
|
-
it('light: color/CT mapping and setState commands', async () => {
|
|
34
|
-
const calls: any[] = []
|
|
35
|
-
const fakeClient: any = { setDeviceState: async (id: string, body: any) => {
|
|
36
|
-
calls.push(body)
|
|
37
|
-
return { ok: true }
|
|
38
|
-
} }
|
|
39
|
-
const d = new LightDevice({ id: 'l1', type: 'light' } as any, { _client: fakeClient, log: console } as any)
|
|
40
|
-
|
|
41
|
-
// color temperature (mired)
|
|
42
|
-
await d.setState({ colorTemperature: 300 })
|
|
43
|
-
expect(calls.pop()?.command).toBe('setColorTemperature')
|
|
44
|
-
|
|
45
|
-
// hue + saturation
|
|
46
|
-
await d.setState({ hue: 120, saturation: 50 })
|
|
47
|
-
const c = calls.pop()
|
|
48
|
-
expect(c.command).toBe('setColor')
|
|
49
|
-
expect(c.parameter).toBe('120,50')
|
|
50
|
-
|
|
51
|
-
// hex color string
|
|
52
|
-
await d.setState({ color: '#ff0000' })
|
|
53
|
-
expect(calls.pop()?.command).toBe('setColor')
|
|
54
|
-
})
|
|
55
|
-
|
|
56
|
-
it('curtain: position mapping and Matter attribute writes', async () => {
|
|
57
|
-
const calls: any[] = []
|
|
58
|
-
const fakeClient: any = { setDeviceState: async (id: string, body: any) => {
|
|
59
|
-
calls.push(body)
|
|
60
|
-
return { ok: true }
|
|
61
|
-
} }
|
|
62
|
-
const d = new CurtainDevice({ id: 'c1', type: 'curtain' } as any, { _client: fakeClient, log: console } as any)
|
|
63
|
-
|
|
64
|
-
// Setting position via HAP-style setState
|
|
65
|
-
await d.setState({ position: 25 })
|
|
66
|
-
expect(calls.pop()?.command).toBe('setPosition')
|
|
67
|
-
|
|
68
|
-
// Matter descriptor write: call targetPositionLiftPercent100ths write handler
|
|
69
|
-
const matter = await d.createMatterAccessory({})
|
|
70
|
-
const cluster = matter.clusters.find((c: any) => c.type === 'WindowCovering')
|
|
71
|
-
// targetPositionLiftPercent100ths attribute exists and has a write function
|
|
72
|
-
expect(cluster.attributes.targetPositionLiftPercent100ths.write).toBeTypeOf('function')
|
|
73
|
-
await cluster.attributes.targetPositionLiftPercent100ths.write(8000)
|
|
74
|
-
expect(calls.pop()?.command).toBe('setPosition')
|
|
75
|
-
})
|
|
76
|
-
|
|
77
|
-
it('lock: user management actions map to correct commands', async () => {
|
|
78
|
-
const calls: any[] = []
|
|
79
|
-
const fakeClient: any = { setDeviceState: async (id: string, body: any) => {
|
|
80
|
-
calls.push(body)
|
|
81
|
-
return { ok: true }
|
|
82
|
-
} }
|
|
83
|
-
const d = new LockDevice({ id: 'lock1', type: 'lock' } as any, { _client: fakeClient, log: console } as any)
|
|
84
|
-
|
|
85
|
-
// addUser via setState
|
|
86
|
-
await d.setState({ action: 'addUser', user: 'u1', pin: '1234' })
|
|
87
|
-
let last = calls.pop()
|
|
88
|
-
expect(last.command).toBe('addUserCode')
|
|
89
|
-
expect(last.parameter).toBe('u1:1234')
|
|
90
|
-
|
|
91
|
-
// removeUser
|
|
92
|
-
await d.setState({ action: 'removeUser', user: 'u1' })
|
|
93
|
-
last = calls.pop()
|
|
94
|
-
expect(last.command).toBe('removeUserCode')
|
|
95
|
-
|
|
96
|
-
// unlockWithPin
|
|
97
|
-
await d.setState({ action: 'unlockWithPin', pin: '0000' })
|
|
98
|
-
last = calls.pop()
|
|
99
|
-
expect(last.command).toBe('unlockWithPin')
|
|
100
|
-
|
|
101
|
-
// Matter descriptor write for addUser
|
|
102
|
-
const matter = await d.createMatterAccessory({})
|
|
103
|
-
const mgmt = matter.clusters.find((c: any) => c.type === 'DoorLockUserManagement')
|
|
104
|
-
expect(mgmt.attributes.addUser.write).toBeTypeOf('function')
|
|
105
|
-
await mgmt.attributes.addUser.write({ user: 'u2', pin: '4321' })
|
|
106
|
-
last = calls.pop()
|
|
107
|
-
expect(last.command).toBe('addUserCode')
|
|
108
|
-
expect(last.parameter).toBe('u2:4321')
|
|
109
|
-
})
|
|
110
|
-
})
|