@switchbot/homebridge-switchbot 5.0.0-beta.99 → 5.1.0-beta.0
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/.changeset/config.json +14 -0
- package/.github/copilot-instructions.md +39 -0
- package/.github/workflows/ci.yml +4 -1
- package/.github/workflows/manual-e2e.yml +6 -3
- package/.github/workflows/release.yml +64 -15
- package/.github/workflows/stale.yml +2 -4
- package/.husky/pre-push +15 -0
- package/CHANGELOG.md +140 -135
- package/MIGRATION.md +21 -6
- package/README.md +109 -3
- package/TODO.md +263 -0
- package/config.schema.json +240 -36
- package/dist/SwitchBotHAPPlatform.d.ts +133 -0
- package/dist/SwitchBotHAPPlatform.d.ts.map +1 -0
- package/dist/SwitchBotHAPPlatform.js +584 -0
- package/dist/SwitchBotHAPPlatform.js.map +1 -0
- package/dist/SwitchBotMatterPlatform.d.ts +142 -0
- package/dist/SwitchBotMatterPlatform.d.ts.map +1 -0
- package/dist/SwitchBotMatterPlatform.js +569 -0
- package/dist/SwitchBotMatterPlatform.js.map +1 -0
- package/dist/device-types.d.ts +31 -0
- package/dist/device-types.d.ts.map +1 -0
- package/dist/device-types.js +246 -0
- package/dist/device-types.js.map +1 -0
- package/dist/deviceCommandMapper.d.ts +10 -0
- package/dist/deviceCommandMapper.d.ts.map +1 -0
- package/dist/deviceCommandMapper.js +319 -0
- package/dist/deviceCommandMapper.js.map +1 -0
- package/dist/deviceFactory.d.ts +3 -2
- package/dist/deviceFactory.d.ts.map +1 -1
- package/dist/deviceFactory.js +107 -29
- package/dist/deviceFactory.js.map +1 -1
- package/dist/devices/genericDevice.d.ts +59 -37
- package/dist/devices/genericDevice.d.ts.map +1 -1
- package/dist/devices/genericDevice.js +376 -78
- package/dist/devices/genericDevice.js.map +1 -1
- package/dist/errors.d.ts +38 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +32 -0
- package/dist/errors.js.map +1 -0
- package/dist/homebridge-ui/device-types.js +246 -0
- package/dist/homebridge-ui/device-types.js.map +1 -0
- package/dist/homebridge-ui/deviceCommandMapper.js +319 -0
- package/dist/homebridge-ui/deviceCommandMapper.js.map +1 -0
- package/dist/homebridge-ui/endpoints/config.d.ts +3 -0
- package/dist/homebridge-ui/endpoints/config.d.ts.map +1 -0
- package/dist/homebridge-ui/endpoints/config.js +90 -0
- package/dist/homebridge-ui/endpoints/config.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 +144 -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 +219 -0
- package/dist/homebridge-ui/endpoints/discovery.js.map +1 -0
- package/dist/homebridge-ui/errors.js +32 -0
- package/dist/homebridge-ui/errors.js.map +1 -0
- package/dist/homebridge-ui/homebridge-ui/endpoints/config.js +90 -0
- package/dist/homebridge-ui/homebridge-ui/endpoints/config.js.map +1 -0
- package/dist/homebridge-ui/homebridge-ui/endpoints/devices.js +144 -0
- package/dist/homebridge-ui/homebridge-ui/endpoints/devices.js.map +1 -0
- package/dist/homebridge-ui/homebridge-ui/endpoints/discovery.js +219 -0
- package/dist/homebridge-ui/homebridge-ui/endpoints/discovery.js.map +1 -0
- package/dist/homebridge-ui/homebridge-ui/server.js +11 -0
- package/dist/homebridge-ui/homebridge-ui/server.js.map +1 -0
- package/dist/homebridge-ui/homebridge-ui/utils/config-parser.js +108 -0
- package/dist/homebridge-ui/homebridge-ui/utils/config-parser.js.map +1 -0
- package/dist/homebridge-ui/homebridge-ui/utils/device-migration.js +111 -0
- package/dist/homebridge-ui/homebridge-ui/utils/device-migration.js.map +1 -0
- package/dist/homebridge-ui/homebridge-ui/utils/logger.js +17 -0
- package/dist/homebridge-ui/homebridge-ui/utils/logger.js.map +1 -0
- package/dist/homebridge-ui/public/css/styles.css +483 -0
- package/dist/homebridge-ui/public/index.html +197 -621
- package/dist/homebridge-ui/public/js/advanced-settings.d.ts +3 -0
- package/dist/homebridge-ui/public/js/advanced-settings.d.ts.map +1 -0
- package/dist/homebridge-ui/public/js/advanced-settings.js +95 -0
- package/dist/homebridge-ui/public/js/advanced-settings.js.map +1 -0
- package/dist/homebridge-ui/public/js/advanced-settings.ts +94 -0
- package/dist/homebridge-ui/public/js/api.d.ts +72 -0
- package/dist/homebridge-ui/public/js/api.d.ts.map +1 -0
- package/dist/homebridge-ui/public/js/api.js +313 -0
- package/dist/homebridge-ui/public/js/api.js.map +1 -0
- package/dist/homebridge-ui/public/js/api.ts +385 -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 +3798 -0
- package/dist/homebridge-ui/public/js/app.js.map +7 -0
- package/dist/homebridge-ui/public/js/app.ts +22 -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 +99 -0
- package/dist/homebridge-ui/public/js/credentials.js.map +1 -0
- package/dist/homebridge-ui/public/js/credentials.ts +105 -0
- package/dist/homebridge-ui/public/js/devices-delete.d.ts +3 -0
- package/dist/homebridge-ui/public/js/devices-delete.d.ts.map +1 -0
- package/dist/homebridge-ui/public/js/devices-delete.js +199 -0
- package/dist/homebridge-ui/public/js/devices-delete.js.map +1 -0
- package/dist/homebridge-ui/public/js/devices-delete.ts +227 -0
- package/dist/homebridge-ui/public/js/devices.d.ts +9 -0
- package/dist/homebridge-ui/public/js/devices.d.ts.map +1 -0
- package/dist/homebridge-ui/public/js/devices.js +104 -0
- package/dist/homebridge-ui/public/js/devices.js.map +1 -0
- package/dist/homebridge-ui/public/js/devices.ts +112 -0
- package/dist/homebridge-ui/public/js/discovery.d.ts +9 -0
- package/dist/homebridge-ui/public/js/discovery.d.ts.map +1 -0
- package/dist/homebridge-ui/public/js/discovery.js +1201 -0
- package/dist/homebridge-ui/public/js/discovery.js.map +1 -0
- package/dist/homebridge-ui/public/js/discovery.ts +1335 -0
- package/dist/homebridge-ui/public/js/logger.d.ts +7 -0
- package/dist/homebridge-ui/public/js/logger.d.ts.map +1 -0
- package/dist/homebridge-ui/public/js/logger.js +17 -0
- package/dist/homebridge-ui/public/js/logger.js.map +1 -0
- package/dist/homebridge-ui/public/js/logger.ts +17 -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 +35 -0
- package/dist/homebridge-ui/public/js/modal.js.map +1 -0
- package/dist/homebridge-ui/public/js/modal.ts +35 -0
- package/dist/homebridge-ui/public/js/modals.d.ts +16 -0
- package/dist/homebridge-ui/public/js/modals.d.ts.map +1 -0
- package/dist/homebridge-ui/public/js/modals.js +728 -0
- package/dist/homebridge-ui/public/js/modals.js.map +1 -0
- package/dist/homebridge-ui/public/js/modals.ts +823 -0
- package/dist/homebridge-ui/public/js/render.d.ts +71 -0
- package/dist/homebridge-ui/public/js/render.d.ts.map +1 -0
- package/dist/homebridge-ui/public/js/render.js +961 -0
- package/dist/homebridge-ui/public/js/render.js.map +1 -0
- package/dist/homebridge-ui/public/js/render.ts +1085 -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 +38 -0
- package/dist/homebridge-ui/public/js/toast.js.map +1 -0
- package/dist/homebridge-ui/public/js/toast.ts +44 -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 +8 -471
- package/dist/homebridge-ui/server.js.map +1 -1
- package/dist/homebridge-ui/settings.js +8 -0
- package/dist/homebridge-ui/settings.js.map +1 -0
- package/dist/homebridge-ui/switchbotClient.js +247 -0
- package/dist/homebridge-ui/switchbotClient.js.map +1 -0
- package/dist/homebridge-ui/utils/config-parser.d.ts +39 -0
- package/dist/homebridge-ui/utils/config-parser.d.ts.map +1 -0
- package/dist/homebridge-ui/utils/config-parser.js +108 -0
- package/dist/homebridge-ui/utils/config-parser.js.map +1 -0
- package/dist/homebridge-ui/utils/device-migration.d.ts +35 -0
- package/dist/homebridge-ui/utils/device-migration.d.ts.map +1 -0
- package/dist/homebridge-ui/utils/device-migration.js +111 -0
- package/dist/homebridge-ui/utils/device-migration.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/index.d.ts +10 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +12 -2
- package/dist/index.js.map +1 -1
- package/dist/settings.d.ts +12 -0
- package/dist/settings.d.ts.map +1 -1
- package/dist/settings.js +1 -0
- package/dist/settings.js.map +1 -1
- package/dist/switchbotClient.d.ts +12 -10
- package/dist/switchbotClient.d.ts.map +1 -1
- package/dist/switchbotClient.js +156 -103
- package/dist/switchbotClient.js.map +1 -1
- package/dist/utils.d.ts +81 -1
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +1148 -4
- package/dist/utils.js.map +1 -1
- package/docs/assets/highlight.css +29 -15
- package/docs/assets/main.js +1 -1
- package/docs/index.html +100 -6
- package/docs/variables/default.html +3 -1
- package/eslint.config.js +9 -5
- package/nodemon.json +2 -2
- package/package.json +34 -21
- package/scripts/build-ui.js +37 -0
- package/scripts/free-dev-ports.mjs +105 -0
- package/scripts/generate-matter-maps.js +34 -17
- package/scripts/sync-device-types.mjs +31 -0
- package/src/SwitchBotHAPPlatform.ts +583 -0
- package/src/SwitchBotMatterPlatform.ts +566 -0
- package/src/device-types.js +246 -0
- package/src/device-types.js.map +1 -0
- package/src/device-types.ts +261 -0
- package/src/deviceCommandMapper.js +319 -0
- package/src/deviceCommandMapper.js.map +1 -0
- package/src/deviceCommandMapper.ts +333 -0
- package/src/deviceFactory.ts +125 -45
- package/src/devices/genericDevice.ts +411 -69
- package/src/errors.js +32 -0
- package/src/errors.js.map +1 -0
- package/src/errors.ts +35 -0
- package/src/homebridge-ui/endpoints/config.ts +110 -0
- package/src/homebridge-ui/endpoints/devices.ts +153 -0
- package/src/homebridge-ui/endpoints/discovery.ts +240 -0
- package/src/homebridge-ui/public/css/styles.css +483 -0
- package/src/homebridge-ui/public/index.html +197 -621
- package/src/homebridge-ui/public/js/advanced-settings.ts +94 -0
- package/src/homebridge-ui/public/js/api.ts +385 -0
- package/src/homebridge-ui/public/js/app.ts +22 -0
- package/src/homebridge-ui/public/js/constants.ts +1 -0
- package/src/homebridge-ui/public/js/credentials.ts +105 -0
- package/src/homebridge-ui/public/js/devices-delete.ts +227 -0
- package/src/homebridge-ui/public/js/devices.ts +112 -0
- package/src/homebridge-ui/public/js/discovery.ts +1335 -0
- package/src/homebridge-ui/public/js/logger.ts +17 -0
- package/src/homebridge-ui/public/js/modal.ts +35 -0
- package/src/homebridge-ui/public/js/modals.ts +823 -0
- package/src/homebridge-ui/public/js/render.ts +1085 -0
- package/src/homebridge-ui/public/js/toast.ts +44 -0
- package/src/homebridge-ui/public/js/types.ts +26 -0
- package/src/homebridge-ui/server.ts +9 -554
- package/src/homebridge-ui/utils/config-parser.ts +125 -0
- package/src/homebridge-ui/utils/device-migration.ts +144 -0
- package/src/homebridge-ui/utils/logger.ts +17 -0
- package/src/index.ts +12 -2
- package/src/settings.js +8 -0
- package/src/settings.js.map +1 -0
- package/src/settings.ts +14 -0
- package/src/switchbotClient.js +247 -0
- package/src/switchbotClient.js.map +1 -0
- package/src/switchbotClient.ts +177 -114
- package/src/utils.ts +1164 -5
- 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 +64 -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/genericDevice-blepoll.spec.ts +47 -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/e2e/run-e2e.spec.ts +18 -19
- package/test/errors/errors.spec.ts +10 -0
- package/test/helpers/matter-harness.ts +20 -9
- package/test/homebridge-ui/server.spec.ts +9 -0
- package/test/platform/accessory-restore.spec.ts +37 -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 +73 -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 +68 -0
- package/todo/TODO.md +80 -0
- package/tsconfig.ui.json +11 -0
- package/.github/workflows/beta-release.yml +0 -52
- package/dist/platform.d.ts +0 -35
- package/dist/platform.d.ts.map +0 -1
- package/dist/platform.js +0 -945
- package/dist/platform.js.map +0 -1
- package/src/platform.ts +0 -963
- package/test/accessory-restore.spec.ts +0 -73
- package/test/device-mapping.spec.ts +0 -37
- package/test/deviceFactory.spec.ts +0 -18
- package/test/fan-swing.spec.ts +0 -29
- package/test/lock-users.spec.ts +0 -44
- package/test/matter-childbridge.spec.ts +0 -55
- package/test/matter-descriptors.spec.ts +0 -97
- package/test/matter-device-state.spec.ts +0 -101
- package/test/matter-integration.spec.ts +0 -70
- package/test/platform.integration.spec.ts +0 -55
- package/test/switchbot-client-debounce.spec.ts +0 -131
- package/test/switchbot-client-openapi.spec.ts +0 -56
- package/test/switchbotClient.spec.ts +0 -10
- package/test/utils.spec.ts +0 -20
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest'
|
|
2
|
+
|
|
3
|
+
import SwitchBotHAPPlatform from '../../src/SwitchBotHAPPlatform.js'
|
|
4
|
+
import { SwitchBotMatterPlatform } from '../../src/SwitchBotMatterPlatform.js'
|
|
5
|
+
|
|
6
|
+
const mockLogger = {
|
|
7
|
+
info: () => {},
|
|
8
|
+
warn: () => {},
|
|
9
|
+
error: () => {},
|
|
10
|
+
debug: () => {},
|
|
11
|
+
success: () => {},
|
|
12
|
+
log: () => {},
|
|
13
|
+
}
|
|
14
|
+
const mockApi = { isMatterAvailable: () => false, isMatterEnabled: () => false } as any
|
|
15
|
+
|
|
16
|
+
describe('platform edge cases', () => {
|
|
17
|
+
const platforms = [
|
|
18
|
+
{ name: 'SwitchBotHAPPlatform', Platform: SwitchBotHAPPlatform },
|
|
19
|
+
{ name: 'SwitchBotMatterPlatform', Platform: SwitchBotMatterPlatform },
|
|
20
|
+
]
|
|
21
|
+
|
|
22
|
+
for (const { name, Platform } of platforms) {
|
|
23
|
+
describe(`${name}`, () => {
|
|
24
|
+
it('should handle missing config', () => {
|
|
25
|
+
expect(() => new Platform(mockLogger, { platform: 'SwitchBot' }, mockApi as any)).not.toThrow()
|
|
26
|
+
})
|
|
27
|
+
|
|
28
|
+
it('should handle undefined config', () => {
|
|
29
|
+
expect(() => new Platform(mockLogger, undefined as any, mockApi)).not.toThrow()
|
|
30
|
+
})
|
|
31
|
+
|
|
32
|
+
it('should handle null config', () => {
|
|
33
|
+
expect(() => new Platform(mockLogger, null as any, mockApi)).not.toThrow()
|
|
34
|
+
})
|
|
35
|
+
|
|
36
|
+
it('should handle missing api', () => {
|
|
37
|
+
expect(() => new Platform(mockLogger, { platform: 'SwitchBot' }, undefined as any)).not.toThrow()
|
|
38
|
+
})
|
|
39
|
+
|
|
40
|
+
it('should handle null api', () => {
|
|
41
|
+
expect(() => new Platform(mockLogger, { platform: 'SwitchBot' }, null as any)).not.toThrow()
|
|
42
|
+
})
|
|
43
|
+
|
|
44
|
+
it('should handle missing logger', () => {
|
|
45
|
+
expect(() => new Platform(undefined as any, { platform: 'SwitchBot' }, mockApi)).toThrow()
|
|
46
|
+
})
|
|
47
|
+
|
|
48
|
+
it('should handle null logger', () => {
|
|
49
|
+
expect(() => new Platform(null as any, { platform: 'SwitchBot' }, mockApi)).toThrow()
|
|
50
|
+
})
|
|
51
|
+
|
|
52
|
+
it('should not throw with minimal valid config', () => {
|
|
53
|
+
const config = { name: 'SwitchBot', platform: 'SwitchBot' }
|
|
54
|
+
expect(() => new Platform(mockLogger, config, mockApi)).not.toThrow()
|
|
55
|
+
})
|
|
56
|
+
|
|
57
|
+
it('should fallback gracefully if isMatterAvailable returns true but isMatterEnabled returns false', () => {
|
|
58
|
+
const api = { ...mockApi, isMatterAvailable: () => true, isMatterEnabled: () => false }
|
|
59
|
+
expect(() => new Platform(mockLogger, { platform: 'SwitchBot' }, api)).not.toThrow()
|
|
60
|
+
})
|
|
61
|
+
|
|
62
|
+
it('should fallback gracefully if isMatterAvailable returns false', () => {
|
|
63
|
+
const api = { ...mockApi, isMatterAvailable: () => false }
|
|
64
|
+
expect(() => new Platform(mockLogger, { platform: 'SwitchBot' }, api)).not.toThrow()
|
|
65
|
+
})
|
|
66
|
+
|
|
67
|
+
it('should not throw if config has extra unknown properties', () => {
|
|
68
|
+
const config = { name: 'SwitchBot', platform: 'SwitchBot', extra: 123 }
|
|
69
|
+
expect(() => new Platform(mockLogger, config, mockApi)).not.toThrow()
|
|
70
|
+
})
|
|
71
|
+
})
|
|
72
|
+
}
|
|
73
|
+
})
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { describe, expect, it, vi } from 'vitest'
|
|
2
|
+
|
|
3
|
+
import { SwitchBotHAPPlatform } from '../../src/SwitchBotHAPPlatform.js'
|
|
4
|
+
|
|
5
|
+
describe('hAP platform integration', () => {
|
|
6
|
+
class TestHAPPlatform extends SwitchBotHAPPlatform {
|
|
7
|
+
constructor(logger: any, config: any, api: any) { super(logger, config, api) }
|
|
8
|
+
setCache(cache: any[]) { (this as any)._accessoryCache = cache }
|
|
9
|
+
getRestored() { return (this as any)._accessoryCache }
|
|
10
|
+
registerAccessory(acc: any) { (this as any)._accessoryCache.push(acc) }
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const logger = { info: vi.fn(), warn: vi.fn(), error: vi.fn(), debug: vi.fn() }
|
|
14
|
+
const config = {}
|
|
15
|
+
const api = {}
|
|
16
|
+
|
|
17
|
+
it('should restore accessories from cache', () => {
|
|
18
|
+
const platform = new TestHAPPlatform(logger, config, api)
|
|
19
|
+
platform.setCache([{ uuid: 'hap-acc-1', context: { type: 'Bot' } }])
|
|
20
|
+
const restored = platform.getRestored()
|
|
21
|
+
expect(restored).toHaveLength(1)
|
|
22
|
+
expect(restored[0].uuid).toBe('hap-acc-1')
|
|
23
|
+
})
|
|
24
|
+
|
|
25
|
+
it('should register a new accessory', () => {
|
|
26
|
+
const platform = new TestHAPPlatform(logger, config, api)
|
|
27
|
+
platform.setCache([])
|
|
28
|
+
const newAcc = { uuid: 'hap-acc-2', context: { type: 'Curtain' } }
|
|
29
|
+
platform.registerAccessory(newAcc)
|
|
30
|
+
const restored = platform.getRestored()
|
|
31
|
+
expect(restored).toHaveLength(1)
|
|
32
|
+
expect(restored[0].uuid).toBe('hap-acc-2')
|
|
33
|
+
})
|
|
34
|
+
})
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest'
|
|
2
|
+
|
|
3
|
+
import * as utils from '../../src/utils'
|
|
4
|
+
|
|
5
|
+
describe('extra utils', () => {
|
|
6
|
+
it('normalizeConfig returns empty object for undefined', () => {
|
|
7
|
+
expect(utils.normalizeConfig(undefined)).toEqual({})
|
|
8
|
+
})
|
|
9
|
+
// Add more utility tests as needed
|
|
10
|
+
})
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { describe, expect, it, vi } from 'vitest'
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
createPlatformProxy,
|
|
5
|
+
MATTER_ATTRIBUTE_IDS,
|
|
6
|
+
MATTER_CLUSTER_IDS,
|
|
7
|
+
normalizeConfig,
|
|
8
|
+
resolveExternalPublishProtocol,
|
|
9
|
+
} from '../../src/utils'
|
|
10
|
+
|
|
11
|
+
describe('utils', () => {
|
|
12
|
+
it('should expose correct MATTER_CLUSTER_IDS', () => {
|
|
13
|
+
expect(MATTER_CLUSTER_IDS.OnOff).toBe(0x0006)
|
|
14
|
+
expect(MATTER_CLUSTER_IDS.FanControl).toBe(0x0202)
|
|
15
|
+
})
|
|
16
|
+
|
|
17
|
+
it('should expose correct MATTER_ATTRIBUTE_IDS', () => {
|
|
18
|
+
expect(MATTER_ATTRIBUTE_IDS.OnOff.OnOff).toBe(0x0000)
|
|
19
|
+
expect(MATTER_ATTRIBUTE_IDS.ColorControl.CurrentHue).toBe(0x0000)
|
|
20
|
+
})
|
|
21
|
+
|
|
22
|
+
it('normalizeConfig returns empty object for undefined', () => {
|
|
23
|
+
expect(normalizeConfig(undefined)).toEqual({})
|
|
24
|
+
})
|
|
25
|
+
|
|
26
|
+
it('normalizeConfig returns shallow copy of config', () => {
|
|
27
|
+
const input = { foo: 'bar', preferMatter: false }
|
|
28
|
+
const result = normalizeConfig(input as any)
|
|
29
|
+
expect(result).toMatchObject(input)
|
|
30
|
+
expect(result).not.toBe(input)
|
|
31
|
+
})
|
|
32
|
+
|
|
33
|
+
it('createPlatformProxy instantiates MatterPlatform if available and enabled', () => {
|
|
34
|
+
const HAP = vi.fn()
|
|
35
|
+
const Matter = vi.fn()
|
|
36
|
+
const api = { isMatterAvailable: () => true, isMatterEnabled: () => true }
|
|
37
|
+
const config = { enableMatter: true, preferMatter: true }
|
|
38
|
+
const Proxy = createPlatformProxy(HAP, Matter)
|
|
39
|
+
new Proxy('log', config, api)
|
|
40
|
+
expect(Matter).toHaveBeenCalled()
|
|
41
|
+
expect(HAP).not.toHaveBeenCalled()
|
|
42
|
+
})
|
|
43
|
+
|
|
44
|
+
it('createPlatformProxy falls back to HAPPlatform if Matter not available', () => {
|
|
45
|
+
const HAP = vi.fn()
|
|
46
|
+
const Matter = vi.fn()
|
|
47
|
+
const api = { isMatterAvailable: () => false, isMatterEnabled: () => false }
|
|
48
|
+
const config = { enableMatter: true, preferMatter: true }
|
|
49
|
+
const Proxy = createPlatformProxy(HAP, Matter)
|
|
50
|
+
new Proxy('log', config, api)
|
|
51
|
+
expect(HAP).toHaveBeenCalled()
|
|
52
|
+
expect(Matter).not.toHaveBeenCalled()
|
|
53
|
+
})
|
|
54
|
+
|
|
55
|
+
it('resolveExternalPublishProtocol normalizes known values and aliases', () => {
|
|
56
|
+
expect(resolveExternalPublishProtocol({ externalPublishProtocol: 'hap' })).toBe('hap')
|
|
57
|
+
expect(resolveExternalPublishProtocol({ externalPublishProtocol: 'matter' })).toBe('matter')
|
|
58
|
+
expect(resolveExternalPublishProtocol({ externalPublishProtocol: 'none' })).toBe('none')
|
|
59
|
+
expect(resolveExternalPublishProtocol({ externalPublishProtocol: 'homekit' })).toBe('hap')
|
|
60
|
+
expect(resolveExternalPublishProtocol({ publishExternal: true })).toBe('hap')
|
|
61
|
+
expect(resolveExternalPublishProtocol({ publishExternal: false })).toBe('none')
|
|
62
|
+
})
|
|
63
|
+
|
|
64
|
+
it('resolveExternalPublishProtocol defaults to none for unknown values', () => {
|
|
65
|
+
expect(resolveExternalPublishProtocol({ externalPublishProtocol: 'invalid' })).toBe('none')
|
|
66
|
+
expect(resolveExternalPublishProtocol({})).toBe('none')
|
|
67
|
+
})
|
|
68
|
+
})
|
package/todo/TODO.md
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
# SwitchBot Plugin TODO List
|
|
2
|
+
|
|
3
|
+
- [ ] Implement battery level trending (if historical data available)
|
|
4
|
+
- [ ] Add "Export Results" button (JSON format)
|
|
5
|
+
- [ ] Add "Import Results" for comparison or troubleshooting
|
|
6
|
+
- [ ] Share with support for debugging
|
|
7
|
+
- [ ] Compare current vs previous discovery (show differences)
|
|
8
|
+
- [ ] Generate discovery report (formatted summary)
|
|
9
|
+
- [ ] **Test discovery with real hardware**
|
|
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
|
|
15
|
+
- [ ] **Add error handling improvements**
|
|
16
|
+
- [ ] Better error messages for users
|
|
17
|
+
- [ ] Retry logic with exponential backoff
|
|
18
|
+
- [ ] Graceful degradation when BLE unavailable
|
|
19
|
+
- [ ] Network timeout handling
|
|
20
|
+
- [ ] **Update README with discovery features**
|
|
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
|
|
25
|
+
- [ ] **Create developer documentation**
|
|
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
|
|
39
|
+
- [ ] Add checkboxes to select multiple devices
|
|
40
|
+
- [ ] Add "Add Selected to Config" button
|
|
41
|
+
- [ ] Implement bulk configuration with smart defaults
|
|
42
|
+
- [ ] Add "Needs Attention" section at top
|
|
43
|
+
- [ ] Implement battery level trending (if historical data available)
|
|
44
|
+
- [ ] Add "Export Results" button (JSON format)
|
|
45
|
+
- [ ] Add "Import Results" for comparison or troubleshooting
|
|
46
|
+
- [ ] Share with support for debugging
|
|
47
|
+
- [ ] Compare current vs previous discovery (show differences)
|
|
48
|
+
- [ ] Generate discovery report (formatted summary)
|
|
49
|
+
- [ ] Add tests for battery level trending logic
|
|
50
|
+
- [ ] **Test discovery with real hardware**
|
|
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
|
|
57
|
+
- [ ] **Add error handling improvements**
|
|
58
|
+
- [ ] Better error messages for users
|
|
59
|
+
- [ ] Retry logic with exponential backoff
|
|
60
|
+
- [ ] Graceful degradation when BLE unavailable
|
|
61
|
+
- [ ] Network timeout handling
|
|
62
|
+
- [ ] **Update README with discovery features**
|
|
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
|
|
67
|
+
- [ ] **Create developer documentation**
|
|
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
|
package/tsconfig.ui.json
ADDED
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
name: Beta Release
|
|
2
|
-
|
|
3
|
-
on:
|
|
4
|
-
push:
|
|
5
|
-
branches: [beta-*.*.*, beta]
|
|
6
|
-
workflow_dispatch:
|
|
7
|
-
|
|
8
|
-
jobs:
|
|
9
|
-
build_and_test:
|
|
10
|
-
uses: homebridge/.github/.github/workflows/nodejs-build-and-test.yml@latest
|
|
11
|
-
with:
|
|
12
|
-
enable_coverage: false
|
|
13
|
-
secrets:
|
|
14
|
-
token: ${{ secrets.GITHUB_TOKEN }}
|
|
15
|
-
lint:
|
|
16
|
-
needs: build_and_test
|
|
17
|
-
uses: homebridge/.github/.github/workflows/eslint.yml@latest
|
|
18
|
-
|
|
19
|
-
publish:
|
|
20
|
-
needs: lint
|
|
21
|
-
permissions:
|
|
22
|
-
id-token: write
|
|
23
|
-
uses: homebridge/.github/.github/workflows/npm-publish-esm.yml@latest
|
|
24
|
-
with:
|
|
25
|
-
tag: 'beta'
|
|
26
|
-
dynamically_adjust_version: true
|
|
27
|
-
npm_version_command: 'pre'
|
|
28
|
-
pre_id: 'beta'
|
|
29
|
-
secrets:
|
|
30
|
-
npm_auth_token: ${{ secrets.npm_token }}
|
|
31
|
-
|
|
32
|
-
pre-release:
|
|
33
|
-
needs: publish
|
|
34
|
-
uses: homebridge/.github/.github/workflows/pre-release.yml@latest
|
|
35
|
-
with:
|
|
36
|
-
npm_version: ${{ needs.publish.outputs.NPM_VERSION }}
|
|
37
|
-
body: |
|
|
38
|
-
**Beta Release**
|
|
39
|
-
**Version**: v${{ needs.publish.outputs.NPM_VERSION }}
|
|
40
|
-
[How To Test Beta Releases](https://github.com/OpenWonderLabs/homebridge-switchbot/wiki/Beta-Version)
|
|
41
|
-
|
|
42
|
-
github-releases-to-discord:
|
|
43
|
-
name: Discord Webhooks
|
|
44
|
-
needs: [build_and_test,publish]
|
|
45
|
-
uses: homebridge/.github/.github/workflows/discord-webhooks.yml@latest
|
|
46
|
-
with:
|
|
47
|
-
title: "SwitchBot Beta Release"
|
|
48
|
-
description: |
|
|
49
|
-
Version `v${{ needs.publish.outputs.NPM_VERSION }}`
|
|
50
|
-
url: "https://github.com/OpenWonderLabs/homebridge-switchbot/releases/tag/v${{ needs.publish.outputs.NPM_VERSION }}"
|
|
51
|
-
secrets:
|
|
52
|
-
DISCORD_WEBHOOK: ${{ secrets.DISCORD_WEBHOOK_URL_LATEST }}
|
package/dist/platform.d.ts
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import type { SwitchBotPluginConfig } from './settings.js';
|
|
2
|
-
import type { API, Logger, PlatformConfig } from 'homebridge';
|
|
3
|
-
export declare class SwitchBotHAPPlatform {
|
|
4
|
-
api: API | undefined;
|
|
5
|
-
log: Logger;
|
|
6
|
-
config: SwitchBotPluginConfig;
|
|
7
|
-
devices: any[];
|
|
8
|
-
accessories: Map<string, any>;
|
|
9
|
-
private lastConfigHash;
|
|
10
|
-
private configReloadInterval;
|
|
11
|
-
constructor(log: Logger, config: PlatformConfig, api?: API);
|
|
12
|
-
private getConfigHash;
|
|
13
|
-
private checkAndReloadDevices;
|
|
14
|
-
loadDevices(): Promise<void>;
|
|
15
|
-
configureAccessory(accessory: any): Promise<void>;
|
|
16
|
-
configureMatterAccessory?(accessory: any): void;
|
|
17
|
-
}
|
|
18
|
-
export declare class SwitchBotMatterPlatform {
|
|
19
|
-
api: API | undefined;
|
|
20
|
-
log: Logger;
|
|
21
|
-
config: SwitchBotPluginConfig;
|
|
22
|
-
devices: any[];
|
|
23
|
-
accessories: Map<string, any>;
|
|
24
|
-
private lastConfigHash;
|
|
25
|
-
private configReloadInterval;
|
|
26
|
-
constructor(log: Logger, config: PlatformConfig, api?: API);
|
|
27
|
-
loadDevices(): Promise<void>;
|
|
28
|
-
private getConfigHash;
|
|
29
|
-
private checkAndReloadDevices;
|
|
30
|
-
configureAccessory(accessory: any): Promise<void>;
|
|
31
|
-
configureMatterAccessory(accessory: any): void;
|
|
32
|
-
registerMatterAccessories(): Promise<void>;
|
|
33
|
-
}
|
|
34
|
-
export default SwitchBotHAPPlatform;
|
|
35
|
-
//# sourceMappingURL=platform.d.ts.map
|
package/dist/platform.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"platform.d.ts","sourceRoot":"","sources":["../src/platform.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAA;AAC1D,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,YAAY,CAAA;AAwV7D,qBAAa,oBAAoB;IAC/B,GAAG,EAAE,GAAG,GAAG,SAAS,CAAA;IACpB,GAAG,EAAE,MAAM,CAAA;IACX,MAAM,EAAE,qBAAqB,CAAA;IAC7B,OAAO,EAAE,GAAG,EAAE,CAAK;IAEnB,WAAW,EAAE,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;IAE7B,OAAO,CAAC,cAAc,CAAa;IACnC,OAAO,CAAC,oBAAoB,CAA8B;gBAE9C,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,cAAc,EAAE,GAAG,CAAC,EAAE,GAAG;IA2C1D,OAAO,CAAC,aAAa;YAUP,qBAAqB;IAU7B,WAAW;IAoMX,kBAAkB,CAAC,SAAS,EAAE,GAAG;IAYvC,wBAAwB,CAAC,CAAC,SAAS,EAAE,GAAG;CASzC;AAGD,qBAAa,uBAAuB;IAClC,GAAG,EAAE,GAAG,GAAG,SAAS,CAAA;IACpB,GAAG,EAAE,MAAM,CAAA;IACX,MAAM,EAAE,qBAAqB,CAAA;IAC7B,OAAO,EAAE,GAAG,EAAE,CAAK;IACnB,WAAW,EAAE,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;IAE7B,OAAO,CAAC,cAAc,CAAa;IACnC,OAAO,CAAC,oBAAoB,CAA8B;gBAE9C,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,cAAc,EAAE,GAAG,CAAC,EAAE,GAAG;IA8CpD,WAAW;IAyEjB,OAAO,CAAC,aAAa;YAUP,qBAAqB;IAU7B,kBAAkB,CAAC,SAAS,EAAE,GAAG;IAWvC,wBAAwB,CAAC,SAAS,EAAE,GAAG;IAWjC,yBAAyB;CAsJhC;AAED,eAAe,oBAAoB,CAAA"}
|