@switchbot/homebridge-switchbot 5.2.9-beta.1 → 5.2.9
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/devices/genericDevice.d.ts.map +1 -1
- package/dist/devices/genericDevice.js +528 -118
- package/dist/devices/genericDevice.js.map +1 -1
- package/dist/homebridge-ui/public/js/advanced-settings.d.ts.map +1 -1
- package/dist/homebridge-ui/public/js/advanced-settings.js +3 -1
- package/dist/homebridge-ui/public/js/advanced-settings.js.map +1 -1
- package/dist/homebridge-ui/public/js/advanced-settings.ts +3 -1
- package/dist/homebridge-ui/public/js/api.d.ts.map +1 -1
- package/dist/homebridge-ui/public/js/api.js +21 -7
- package/dist/homebridge-ui/public/js/api.js.map +1 -1
- package/dist/homebridge-ui/public/js/api.ts +21 -7
- package/dist/homebridge-ui/public/js/app.js +74 -16
- package/dist/homebridge-ui/public/js/app.js.map +2 -2
- package/dist/homebridge-ui/public/js/credentials.d.ts.map +1 -1
- package/dist/homebridge-ui/public/js/credentials.js +9 -3
- package/dist/homebridge-ui/public/js/credentials.js.map +1 -1
- package/dist/homebridge-ui/public/js/credentials.ts +9 -3
- package/dist/homebridge-ui/public/js/devices-delete.d.ts.map +1 -1
- package/dist/homebridge-ui/public/js/devices-delete.js +6 -2
- package/dist/homebridge-ui/public/js/devices-delete.js.map +1 -1
- package/dist/homebridge-ui/public/js/devices-delete.ts +6 -2
- package/dist/homebridge-ui/public/js/devices.d.ts.map +1 -1
- package/dist/homebridge-ui/public/js/devices.js +3 -1
- package/dist/homebridge-ui/public/js/devices.js.map +1 -1
- package/dist/homebridge-ui/public/js/devices.ts +3 -1
- package/dist/homebridge-ui/public/js/discovery.d.ts.map +1 -1
- package/dist/homebridge-ui/public/js/discovery.js +89 -25
- package/dist/homebridge-ui/public/js/discovery.js.map +1 -1
- package/dist/homebridge-ui/public/js/discovery.ts +89 -25
- package/dist/homebridge-ui/public/js/modals.d.ts.map +1 -1
- package/dist/homebridge-ui/public/js/modals.js +13 -3
- package/dist/homebridge-ui/public/js/modals.js.map +1 -1
- package/dist/homebridge-ui/public/js/modals.ts +13 -3
- package/dist/homebridge-ui/public/js/render.d.ts.map +1 -1
- package/dist/homebridge-ui/public/js/render.js +67 -17
- package/dist/homebridge-ui/public/js/render.js.map +1 -1
- package/dist/homebridge-ui/public/js/render.ts +67 -17
- package/dist/homebridge-ui/public/js/toast.d.ts.map +1 -1
- package/dist/homebridge-ui/public/js/toast.js +6 -2
- package/dist/homebridge-ui/public/js/toast.js.map +1 -1
- package/dist/homebridge-ui/public/js/toast.ts +6 -2
- package/docs/variables/default.html +1 -1
- package/package.json +9 -9
- package/src/devices/genericDevice.ts +529 -129
- package/src/homebridge-ui/public/js/advanced-settings.ts +3 -1
- package/src/homebridge-ui/public/js/api.ts +21 -7
- package/src/homebridge-ui/public/js/credentials.ts +9 -3
- package/src/homebridge-ui/public/js/devices-delete.ts +6 -2
- package/src/homebridge-ui/public/js/devices.ts +3 -1
- package/src/homebridge-ui/public/js/discovery.ts +89 -25
- package/src/homebridge-ui/public/js/modals.ts +13 -3
- package/src/homebridge-ui/public/js/render.ts +67 -17
- package/src/homebridge-ui/public/js/toast.ts +6 -2
- package/test/client/node-switchbot-commands.spec.ts +44 -8
- package/test/client/switchbot-client-debounce.spec.ts +24 -3
- package/test/client/switchbot-client-discovery.spec.ts +26 -5
- package/test/client/switchbot-client-keys.spec.ts +30 -7
- package/test/client/switchbot-client-openapi.spec.ts +6 -1
- package/test/client/switchbotClient.spec.ts +30 -6
- package/test/device/bot-hap.spec.ts +131 -22
- package/test/device/curtain-ble-position.spec.ts +15 -3
- package/test/device/deviceBase.spec.ts +6 -1
- package/test/device/deviceFactory-edge.spec.ts +12 -2
- package/test/device/deviceFactory.spec.ts +6 -1
- package/test/device/fan-swing.spec.ts +9 -2
- package/test/device/genericDevice-blepoll.spec.ts +17 -3
- package/test/device/getstate-cache.spec.ts +37 -6
- package/test/device/getstate-returns-status.spec.ts +65 -13
- package/test/device/lock-users.spec.ts +24 -7
- package/test/device/matter-descriptors.spec.ts +6 -1
- package/test/device/matter-device-state.spec.ts +6 -1
- package/test/device/meter-battery.spec.ts +86 -14
- package/test/device/meter-co2.spec.ts +65 -10
- package/test/device/model-identities.spec.ts +6 -1
- package/test/device/water-detector-battery.spec.ts +19 -3
- package/test/device/water-detector-leak.spec.ts +6 -1
- package/test/helpers/matter-harness.ts +21 -4
- package/test/platform/accessory-restore.spec.ts +18 -3
- package/test/platform/hap-cache-restart.spec.ts +66 -13
- package/test/platform/matter-childbridge.spec.ts +16 -3
- package/test/platform/matter-integration.spec.ts +6 -1
- package/test/platform/matter-registration.spec.ts +47 -10
- package/test/platform/platform-edge.spec.ts +13 -3
- package/test/platform/platform.integration.spec.ts +16 -3
- package/test/utils/utils.spec.ts +42 -8
- package/.github/npm-version-script-esm.js +0 -103
|
@@ -8,7 +8,13 @@ import { describe, expect, it, vi } from 'vitest'
|
|
|
8
8
|
import { createDevice } from '../../src/deviceFactory.js'
|
|
9
9
|
import { GenericDevice, MeterDevice } from '../../src/devices/genericDevice.js'
|
|
10
10
|
|
|
11
|
-
const log: any = {
|
|
11
|
+
const log: any = {
|
|
12
|
+
info: vi.fn(),
|
|
13
|
+
warn: vi.fn(),
|
|
14
|
+
error: vi.fn(),
|
|
15
|
+
debug: vi.fn(),
|
|
16
|
+
success: vi.fn(),
|
|
17
|
+
}
|
|
12
18
|
|
|
13
19
|
/** A node-switchbot style device: identity on the instance, readings via getStatus(). */
|
|
14
20
|
function switchBotDevice(status: any) {
|
|
@@ -21,15 +27,28 @@ function switchBotDevice(status: any) {
|
|
|
21
27
|
}
|
|
22
28
|
}
|
|
23
29
|
|
|
24
|
-
const STATUS = {
|
|
30
|
+
const STATUS = {
|
|
31
|
+
deviceId: 'B0E9FED044E3',
|
|
32
|
+
temperature: 23.7,
|
|
33
|
+
humidity: 59,
|
|
34
|
+
battery: 100,
|
|
35
|
+
connectionType: 'api',
|
|
36
|
+
}
|
|
25
37
|
|
|
26
38
|
function deviceWith(client: any) {
|
|
27
|
-
return new GenericDevice({
|
|
39
|
+
return new GenericDevice({
|
|
40
|
+
id: 'B0E9FED044E3',
|
|
41
|
+
type: 'meter',
|
|
42
|
+
name: 'Meter',
|
|
43
|
+
log,
|
|
44
|
+
}, { log, _client: client } as any)
|
|
28
45
|
}
|
|
29
46
|
|
|
30
47
|
describe('genericDevice.getState', () => {
|
|
31
48
|
it('returns the status rather than the device instance', async () => {
|
|
32
|
-
const state = await deviceWith({
|
|
49
|
+
const state = await deviceWith({
|
|
50
|
+
getDevice: async () => switchBotDevice(STATUS),
|
|
51
|
+
}).getState()
|
|
33
52
|
|
|
34
53
|
expect(state).toEqual(STATUS)
|
|
35
54
|
expect(state.temperature).toBe(23.7)
|
|
@@ -37,22 +56,39 @@ describe('genericDevice.getState', () => {
|
|
|
37
56
|
})
|
|
38
57
|
|
|
39
58
|
it('passes through a plain status object unchanged', async () => {
|
|
40
|
-
const state = await deviceWith({
|
|
59
|
+
const state = await deviceWith({
|
|
60
|
+
getDevice: async () => ({ temperature: 20, humidity: 40 }),
|
|
61
|
+
}).getState()
|
|
41
62
|
|
|
42
63
|
expect(state).toEqual({ temperature: 20, humidity: 40 })
|
|
43
64
|
})
|
|
44
65
|
|
|
45
66
|
it('unwraps an API-shaped body', async () => {
|
|
46
|
-
const state = await deviceWith({
|
|
67
|
+
const state = await deviceWith({
|
|
68
|
+
getDevice: async () => ({
|
|
69
|
+
body: { temperature: 19 },
|
|
70
|
+
}),
|
|
71
|
+
}).getState()
|
|
47
72
|
|
|
48
73
|
expect(state).toEqual({ temperature: 19 })
|
|
49
74
|
})
|
|
50
75
|
|
|
51
76
|
it.each([
|
|
52
|
-
[
|
|
53
|
-
|
|
77
|
+
[
|
|
78
|
+
'throws',
|
|
79
|
+
async () => { throw new Error('unreachable') },
|
|
80
|
+
],
|
|
81
|
+
[
|
|
82
|
+
'returns null',
|
|
83
|
+
async () => null,
|
|
84
|
+
],
|
|
54
85
|
])('reports minimal info when getStatus() %s', async (_label, getStatus) => {
|
|
55
|
-
const client = {
|
|
86
|
+
const client = {
|
|
87
|
+
getDevice: async () => ({
|
|
88
|
+
...switchBotDevice(STATUS),
|
|
89
|
+
getStatus,
|
|
90
|
+
}),
|
|
91
|
+
}
|
|
56
92
|
|
|
57
93
|
const state = await deviceWith(client).getState()
|
|
58
94
|
|
|
@@ -64,9 +100,17 @@ describe('genericDevice.getState', () => {
|
|
|
64
100
|
|
|
65
101
|
describe('createDevice', () => {
|
|
66
102
|
it('does not replace the device getState with the raw client device', async () => {
|
|
67
|
-
const client = {
|
|
103
|
+
const client = {
|
|
104
|
+
init: async () => {},
|
|
105
|
+
getDevice: async () => switchBotDevice(STATUS),
|
|
106
|
+
}
|
|
68
107
|
const created: any = await createDevice(
|
|
69
|
-
{
|
|
108
|
+
{
|
|
109
|
+
id: 'B0E9FED044E3',
|
|
110
|
+
type: 'meter',
|
|
111
|
+
name: 'Meter',
|
|
112
|
+
log,
|
|
113
|
+
} as any,
|
|
70
114
|
{ log, _client: client } as any,
|
|
71
115
|
false,
|
|
72
116
|
)
|
|
@@ -78,8 +122,16 @@ describe('createDevice', () => {
|
|
|
78
122
|
})
|
|
79
123
|
|
|
80
124
|
it('lets a meter report a real temperature end to end', async () => {
|
|
81
|
-
const client = {
|
|
82
|
-
|
|
125
|
+
const client = {
|
|
126
|
+
init: async () => {},
|
|
127
|
+
getDevice: async () => switchBotDevice(STATUS),
|
|
128
|
+
}
|
|
129
|
+
const device = new MeterDevice({
|
|
130
|
+
id: 'B0E9FED044E3',
|
|
131
|
+
type: 'meter',
|
|
132
|
+
name: 'Meter',
|
|
133
|
+
log,
|
|
134
|
+
} as any, { log, _client: client } as any)
|
|
83
135
|
|
|
84
136
|
const services = device.createHAPAccessory(null).services
|
|
85
137
|
const temperature = services.find((s: any) => s.type === 'TemperatureSensor')
|
|
@@ -2,33 +2,50 @@ import { describe, expect, it, vi } from 'vitest'
|
|
|
2
2
|
|
|
3
3
|
import { LockDevice } from '../../src/devices/genericDevice'
|
|
4
4
|
|
|
5
|
-
const mockLogger = {
|
|
5
|
+
const mockLogger = {
|
|
6
|
+
info: () => {},
|
|
7
|
+
warn: () => {},
|
|
8
|
+
error: () => {},
|
|
9
|
+
debug: () => {},
|
|
10
|
+
}
|
|
6
11
|
|
|
7
12
|
const failRegex = /fail/
|
|
8
13
|
|
|
9
14
|
describe('lockDevice user management', () => {
|
|
10
15
|
function makeLock(id: string) {
|
|
11
16
|
const lock = new LockDevice({ id, type: 'Smart Lock' }, { log: mockLogger });
|
|
12
|
-
(lock as any).client = {
|
|
17
|
+
(lock as any).client = {
|
|
18
|
+
setDeviceState: vi.fn().mockResolvedValue({ status: 'success' }),
|
|
19
|
+
}
|
|
13
20
|
return lock
|
|
14
21
|
}
|
|
15
22
|
|
|
16
23
|
it('should add a user', async () => {
|
|
17
24
|
const lock = makeLock('lock1')
|
|
18
|
-
await lock.setState({
|
|
19
|
-
|
|
25
|
+
await lock.setState({
|
|
26
|
+
addUser: { name: 'Alice', code: '1234' },
|
|
27
|
+
})
|
|
28
|
+
expect((lock as any).client.setDeviceState).toHaveBeenCalledWith('lock1', {
|
|
29
|
+
addUser: { name: 'Alice', code: '1234' },
|
|
30
|
+
})
|
|
20
31
|
})
|
|
21
32
|
|
|
22
33
|
it('should remove a user', async () => {
|
|
23
34
|
const lock = makeLock('lock2')
|
|
24
|
-
await lock.setState({
|
|
25
|
-
|
|
35
|
+
await lock.setState({
|
|
36
|
+
removeUser: { name: 'Bob' },
|
|
37
|
+
})
|
|
38
|
+
expect((lock as any).client.setDeviceState).toHaveBeenCalledWith('lock2', {
|
|
39
|
+
removeUser: { name: 'Bob' },
|
|
40
|
+
})
|
|
26
41
|
})
|
|
27
42
|
|
|
28
43
|
it('should return error if setDeviceState fails', async () => {
|
|
29
44
|
const lock = makeLock('lock3');
|
|
30
45
|
((lock as any).client.setDeviceState as any).mockRejectedValueOnce(new Error('fail'))
|
|
31
|
-
const result = await lock.setState({
|
|
46
|
+
const result = await lock.setState({
|
|
47
|
+
addUser: { name: 'Eve', code: '9999' },
|
|
48
|
+
})
|
|
32
49
|
expect(result.success).toBe(false)
|
|
33
50
|
expect(result.reason).toMatch(failRegex)
|
|
34
51
|
})
|
|
@@ -2,7 +2,12 @@ import { describe, expect, it } from 'vitest'
|
|
|
2
2
|
|
|
3
3
|
import { BotDevice, CurtainDevice } from '../../src/devices/genericDevice'
|
|
4
4
|
|
|
5
|
-
const mockLogger = {
|
|
5
|
+
const mockLogger = {
|
|
6
|
+
info: () => {},
|
|
7
|
+
warn: () => {},
|
|
8
|
+
error: () => {},
|
|
9
|
+
debug: () => {},
|
|
10
|
+
}
|
|
6
11
|
|
|
7
12
|
describe('matter device descriptors', () => {
|
|
8
13
|
it('should expose correct clusters for BotDevice', async () => {
|
|
@@ -2,7 +2,12 @@ import { describe, expect, it } from 'vitest'
|
|
|
2
2
|
|
|
3
3
|
import { BotDevice, CurtainDevice } from '../../src/devices/genericDevice'
|
|
4
4
|
|
|
5
|
-
const mockLogger = {
|
|
5
|
+
const mockLogger = {
|
|
6
|
+
info: () => {},
|
|
7
|
+
warn: () => {},
|
|
8
|
+
error: () => {},
|
|
9
|
+
debug: () => {},
|
|
10
|
+
}
|
|
6
11
|
describe('matter device state translation', () => {
|
|
7
12
|
it('should map Bot state to Matter OnOff', async () => {
|
|
8
13
|
const bot = new BotDevice({ id: 'bot1', type: 'Bot' }, { log: mockLogger })
|
|
@@ -9,25 +9,53 @@ import { describe, expect, it, vi } from 'vitest'
|
|
|
9
9
|
import { createDevice } from '../../src/deviceFactory.js'
|
|
10
10
|
import { MeterDevice } from '../../src/devices/genericDevice.js'
|
|
11
11
|
|
|
12
|
-
const log: any = {
|
|
12
|
+
const log: any = {
|
|
13
|
+
info: vi.fn(),
|
|
14
|
+
warn: vi.fn(),
|
|
15
|
+
error: vi.fn(),
|
|
16
|
+
debug: vi.fn(),
|
|
17
|
+
success: vi.fn(),
|
|
18
|
+
}
|
|
13
19
|
|
|
14
20
|
class HapStatusError extends Error {
|
|
15
21
|
constructor(public hapStatus: number) {
|
|
16
22
|
super(`HAP status ${hapStatus}`)
|
|
17
23
|
}
|
|
18
24
|
}
|
|
19
|
-
const api: any = {
|
|
25
|
+
const api: any = {
|
|
26
|
+
hap: {
|
|
27
|
+
HapStatusError,
|
|
28
|
+
HAPStatus: { SERVICE_COMMUNICATION_FAILURE: -70402 },
|
|
29
|
+
},
|
|
30
|
+
}
|
|
20
31
|
|
|
21
32
|
function battery(status: Record<string, unknown>, deviceType = 'Meter') {
|
|
22
|
-
const device = new MeterDevice({
|
|
33
|
+
const device = new MeterDevice({
|
|
34
|
+
id: 'B0E9FED044E3',
|
|
35
|
+
type: 'meter',
|
|
36
|
+
deviceType,
|
|
37
|
+
name: 'Meter',
|
|
38
|
+
log,
|
|
39
|
+
} as any, { log } as any)
|
|
23
40
|
vi.spyOn(device, 'getState').mockResolvedValue(status)
|
|
24
41
|
const service = device.createHAPAccessory(api).services.find((s: any) => s.type === 'Battery')
|
|
25
42
|
return service.characteristics
|
|
26
43
|
}
|
|
27
44
|
|
|
28
45
|
describe('meterDevice Battery service', () => {
|
|
29
|
-
it.each([
|
|
30
|
-
|
|
46
|
+
it.each([
|
|
47
|
+
'Meter',
|
|
48
|
+
'Meter Plus',
|
|
49
|
+
'MeterPro',
|
|
50
|
+
'MeterPro(CO2)',
|
|
51
|
+
])('is added for %s', (deviceType) => {
|
|
52
|
+
const device = new MeterDevice({
|
|
53
|
+
id: 'x',
|
|
54
|
+
type: 'meter',
|
|
55
|
+
deviceType,
|
|
56
|
+
name: 'M',
|
|
57
|
+
log,
|
|
58
|
+
} as any, { log } as any)
|
|
31
59
|
|
|
32
60
|
expect(device.createHAPAccessory(api).services.map((s: any) => s.type)).toContain('Battery')
|
|
33
61
|
})
|
|
@@ -43,7 +71,12 @@ describe('meterDevice Battery service', () => {
|
|
|
43
71
|
})
|
|
44
72
|
|
|
45
73
|
// Same threshold as the water detector.
|
|
46
|
-
it.each([
|
|
74
|
+
it.each([
|
|
75
|
+
[100, 0],
|
|
76
|
+
[20, 0],
|
|
77
|
+
[19, 1],
|
|
78
|
+
[0, 1],
|
|
79
|
+
])('maps %i%% to low battery %i', async (level, expected) => {
|
|
47
80
|
await expect(battery({ battery: level }).StatusLowBattery.get()).resolves.toBe(expected)
|
|
48
81
|
})
|
|
49
82
|
|
|
@@ -55,9 +88,18 @@ describe('meterDevice Battery service', () => {
|
|
|
55
88
|
// alert, and 100% would hide a real one.
|
|
56
89
|
it.each([
|
|
57
90
|
['missing', {}],
|
|
58
|
-
[
|
|
59
|
-
|
|
60
|
-
|
|
91
|
+
[
|
|
92
|
+
'null',
|
|
93
|
+
{ battery: null },
|
|
94
|
+
],
|
|
95
|
+
[
|
|
96
|
+
'text',
|
|
97
|
+
{ battery: 'full' },
|
|
98
|
+
],
|
|
99
|
+
[
|
|
100
|
+
'unreadable device',
|
|
101
|
+
{ id: 'x', type: 'meter', unreadable: true },
|
|
102
|
+
],
|
|
61
103
|
])('reports Not Available when the level is %s', async (_label, status) => {
|
|
62
104
|
const chars = battery(status)
|
|
63
105
|
|
|
@@ -66,14 +108,44 @@ describe('meterDevice Battery service', () => {
|
|
|
66
108
|
})
|
|
67
109
|
|
|
68
110
|
it('reports the level end to end through node-switchbot', async () => {
|
|
69
|
-
const apiBody = {
|
|
111
|
+
const apiBody = {
|
|
112
|
+
version: 'V1.8',
|
|
113
|
+
temperature: 22.7,
|
|
114
|
+
battery: 100,
|
|
115
|
+
humidity: 55,
|
|
116
|
+
CO2: 483,
|
|
117
|
+
deviceId: 'B0E9FED044E3',
|
|
118
|
+
deviceType: 'MeterPro(CO2)',
|
|
119
|
+
hubDeviceId: '000000000000',
|
|
120
|
+
}
|
|
70
121
|
const switchBotDevice = new WoSensorTHProCO2(
|
|
71
|
-
{
|
|
72
|
-
|
|
122
|
+
{
|
|
123
|
+
id: 'B0E9FED044E3',
|
|
124
|
+
name: 'Meter Pro CO2 Monitor',
|
|
125
|
+
deviceType: 'MeterPro(CO2)',
|
|
126
|
+
connectionTypes: ['api'],
|
|
127
|
+
} as any,
|
|
128
|
+
{
|
|
129
|
+
apiClient: {
|
|
130
|
+
getStatus: async () => apiBody,
|
|
131
|
+
},
|
|
132
|
+
} as any,
|
|
73
133
|
)
|
|
74
134
|
const created: any = await createDevice(
|
|
75
|
-
{
|
|
76
|
-
|
|
135
|
+
{
|
|
136
|
+
id: 'B0E9FED044E3',
|
|
137
|
+
type: 'meter',
|
|
138
|
+
deviceType: 'MeterPro(CO2)',
|
|
139
|
+
name: 'Meter Pro CO2 Monitor',
|
|
140
|
+
log,
|
|
141
|
+
} as any,
|
|
142
|
+
{
|
|
143
|
+
log,
|
|
144
|
+
_client: {
|
|
145
|
+
init: async () => {},
|
|
146
|
+
getDevice: async () => switchBotDevice,
|
|
147
|
+
},
|
|
148
|
+
} as any,
|
|
77
149
|
false,
|
|
78
150
|
)
|
|
79
151
|
const service = created.createAccessory(api).services.find((s: any) => s.type === 'Battery')
|
|
@@ -9,10 +9,22 @@ import { describe, expect, it, vi } from 'vitest'
|
|
|
9
9
|
import { createDevice } from '../../src/deviceFactory.js'
|
|
10
10
|
import { MeterDevice } from '../../src/devices/genericDevice.js'
|
|
11
11
|
|
|
12
|
-
const log: any = {
|
|
12
|
+
const log: any = {
|
|
13
|
+
info: vi.fn(),
|
|
14
|
+
warn: vi.fn(),
|
|
15
|
+
error: vi.fn(),
|
|
16
|
+
debug: vi.fn(),
|
|
17
|
+
success: vi.fn(),
|
|
18
|
+
}
|
|
13
19
|
|
|
14
20
|
function meter(deviceType: string | undefined, status: Record<string, unknown>, cfg: Record<string, unknown> = {}) {
|
|
15
|
-
const device = new MeterDevice({
|
|
21
|
+
const device = new MeterDevice({
|
|
22
|
+
id: 'B0E9FED044E3',
|
|
23
|
+
type: 'meter',
|
|
24
|
+
deviceType,
|
|
25
|
+
name: 'Meter',
|
|
26
|
+
log,
|
|
27
|
+
} as any, { log, ...cfg } as any)
|
|
16
28
|
vi.spyOn(device, 'getState').mockResolvedValue(status)
|
|
17
29
|
return device
|
|
18
30
|
}
|
|
@@ -30,10 +42,21 @@ const READING = { temperature: 22.7, humidity: 55, co2: 483 }
|
|
|
30
42
|
|
|
31
43
|
describe('meterDevice CO2 service', () => {
|
|
32
44
|
it.each(['MeterPro(CO2)', 'Meter Pro (CO2)'])('is added for %s', (deviceType) => {
|
|
33
|
-
expect(serviceTypes(meter(deviceType, READING))).toEqual([
|
|
45
|
+
expect(serviceTypes(meter(deviceType, READING))).toEqual([
|
|
46
|
+
'TemperatureSensor',
|
|
47
|
+
'HumiditySensor',
|
|
48
|
+
'CarbonDioxideSensor',
|
|
49
|
+
'Battery',
|
|
50
|
+
])
|
|
34
51
|
})
|
|
35
52
|
|
|
36
|
-
it.each([
|
|
53
|
+
it.each([
|
|
54
|
+
'Meter',
|
|
55
|
+
'Meter Plus',
|
|
56
|
+
'MeterPro',
|
|
57
|
+
'Outdoor Meter',
|
|
58
|
+
undefined,
|
|
59
|
+
])('is not added for %s', (deviceType) => {
|
|
37
60
|
expect(serviceTypes(meter(deviceType, READING))).toEqual(['TemperatureSensor', 'HumiditySensor', 'Battery'])
|
|
38
61
|
})
|
|
39
62
|
|
|
@@ -63,7 +86,12 @@ describe('meterDevice CO2 detected threshold', () => {
|
|
|
63
86
|
await expect(detected(800, { co2AbnormalThreshold: 800 })).resolves.toBe(1)
|
|
64
87
|
})
|
|
65
88
|
|
|
66
|
-
it.each([
|
|
89
|
+
it.each([
|
|
90
|
+
['zero', 0],
|
|
91
|
+
['negative', -1],
|
|
92
|
+
['text', 'high'],
|
|
93
|
+
['missing', undefined],
|
|
94
|
+
])(
|
|
67
95
|
'falls back to 1000 when the setting is %s',
|
|
68
96
|
async (_label, value) => {
|
|
69
97
|
await expect(detected(999, { co2AbnormalThreshold: value })).resolves.toBe(0)
|
|
@@ -76,15 +104,42 @@ describe('meterDevice CO2 detected threshold', () => {
|
|
|
76
104
|
// fed the status body a real Meter Pro (CO2) returned from the OpenAPI.
|
|
77
105
|
describe('a Meter Pro (CO2) end to end', () => {
|
|
78
106
|
it('reports CO2 to HomeKit through node-switchbot', async () => {
|
|
79
|
-
const apiBody = {
|
|
107
|
+
const apiBody = {
|
|
108
|
+
version: 'V1.8',
|
|
109
|
+
temperature: 22.7,
|
|
110
|
+
battery: 100,
|
|
111
|
+
humidity: 55,
|
|
112
|
+
CO2: 483,
|
|
113
|
+
deviceId: 'B0E9FED044E3',
|
|
114
|
+
deviceType: 'MeterPro(CO2)',
|
|
115
|
+
hubDeviceId: '000000000000',
|
|
116
|
+
}
|
|
80
117
|
const switchBotDevice = new WoSensorTHProCO2(
|
|
81
|
-
{
|
|
82
|
-
|
|
118
|
+
{
|
|
119
|
+
id: 'B0E9FED044E3',
|
|
120
|
+
name: 'Meter Pro CO2 Monitor',
|
|
121
|
+
deviceType: 'MeterPro(CO2)',
|
|
122
|
+
connectionTypes: ['api'],
|
|
123
|
+
} as any,
|
|
124
|
+
{
|
|
125
|
+
apiClient: {
|
|
126
|
+
getStatus: async () => apiBody,
|
|
127
|
+
},
|
|
128
|
+
} as any,
|
|
83
129
|
)
|
|
84
|
-
const client = {
|
|
130
|
+
const client = {
|
|
131
|
+
init: async () => {},
|
|
132
|
+
getDevice: async () => switchBotDevice,
|
|
133
|
+
}
|
|
85
134
|
|
|
86
135
|
const created: any = await createDevice(
|
|
87
|
-
{
|
|
136
|
+
{
|
|
137
|
+
id: 'B0E9FED044E3',
|
|
138
|
+
type: 'meter',
|
|
139
|
+
deviceType: 'MeterPro(CO2)',
|
|
140
|
+
name: 'Meter Pro CO2 Monitor',
|
|
141
|
+
log,
|
|
142
|
+
} as any,
|
|
88
143
|
{ log, _client: client } as any,
|
|
89
144
|
false,
|
|
90
145
|
)
|
|
@@ -6,7 +6,12 @@ import { createDevice } from '../../src/deviceFactory'
|
|
|
6
6
|
// node-switchbot 5 reports product-specific identities (pySwitchbot 3.0.0 parity).
|
|
7
7
|
// Every identity must reach the same accessory class as its canonical display name.
|
|
8
8
|
describe('product-specific model identities', () => {
|
|
9
|
-
const mockLogger = {
|
|
9
|
+
const mockLogger = {
|
|
10
|
+
info: () => {},
|
|
11
|
+
warn: () => {},
|
|
12
|
+
error: () => {},
|
|
13
|
+
debug: () => {},
|
|
14
|
+
}
|
|
10
15
|
const dummyConfig = { logger: mockLogger, log: mockLogger }
|
|
11
16
|
|
|
12
17
|
it.each([
|
|
@@ -17,7 +17,12 @@ vi.mock('node-switchbot', () => ({
|
|
|
17
17
|
OpenAPIClient: openApiMocks.OpenAPIClient,
|
|
18
18
|
}))
|
|
19
19
|
|
|
20
|
-
const mockLogger = {
|
|
20
|
+
const mockLogger = {
|
|
21
|
+
info: vi.fn(),
|
|
22
|
+
warn: vi.fn(),
|
|
23
|
+
error: vi.fn(),
|
|
24
|
+
debug: vi.fn(),
|
|
25
|
+
}
|
|
21
26
|
|
|
22
27
|
const mockApi = {
|
|
23
28
|
hap: {
|
|
@@ -34,8 +39,19 @@ const mockApi = {
|
|
|
34
39
|
|
|
35
40
|
function makeDevice(config: Record<string, unknown> = {}) {
|
|
36
41
|
return new WaterDetectorDevice(
|
|
37
|
-
{
|
|
38
|
-
|
|
42
|
+
{
|
|
43
|
+
id: 'wd1',
|
|
44
|
+
type: 'waterdetector',
|
|
45
|
+
name: 'Fridge',
|
|
46
|
+
log: mockLogger,
|
|
47
|
+
blePollingEnabled: false,
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
log: mockLogger,
|
|
51
|
+
openApiToken: 'token',
|
|
52
|
+
openApiSecret: 'secret',
|
|
53
|
+
...config,
|
|
54
|
+
} as any,
|
|
39
55
|
)
|
|
40
56
|
}
|
|
41
57
|
|
|
@@ -2,7 +2,12 @@ import { describe, expect, it } from 'vitest'
|
|
|
2
2
|
|
|
3
3
|
import { WaterDetectorDevice } from '../../src/devices/genericDevice'
|
|
4
4
|
|
|
5
|
-
const mockLogger = {
|
|
5
|
+
const mockLogger = {
|
|
6
|
+
info: () => {},
|
|
7
|
+
warn: () => {},
|
|
8
|
+
error: () => {},
|
|
9
|
+
debug: () => {},
|
|
10
|
+
}
|
|
6
11
|
|
|
7
12
|
const mockApi = {
|
|
8
13
|
hap: {
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
export function makeFakeMatterApi() {
|
|
2
2
|
const registered: any[] = []
|
|
3
3
|
return {
|
|
4
|
-
uuid: {
|
|
4
|
+
uuid: {
|
|
5
|
+
generate: (s: string) => `m-${s}`,
|
|
6
|
+
},
|
|
5
7
|
registerPlatformAccessories: async (_plugin: string, _name: string, accs: any[]) => {
|
|
6
8
|
registered.push(...accs)
|
|
7
9
|
},
|
|
@@ -11,9 +13,24 @@ export function makeFakeMatterApi() {
|
|
|
11
13
|
|
|
12
14
|
export function makeFakeHap() {
|
|
13
15
|
return {
|
|
14
|
-
uuid: {
|
|
15
|
-
|
|
16
|
-
|
|
16
|
+
uuid: {
|
|
17
|
+
generate: (s: string) => `h-${s}`,
|
|
18
|
+
},
|
|
19
|
+
Service: {
|
|
20
|
+
Switch: 'Switch',
|
|
21
|
+
Lightbulb: 'Lightbulb',
|
|
22
|
+
Fan: 'Fan',
|
|
23
|
+
WindowCovering: 'WindowCovering',
|
|
24
|
+
LockMechanism: 'LockMechanism',
|
|
25
|
+
HumiditySensor: 'HumiditySensor',
|
|
26
|
+
},
|
|
27
|
+
Characteristic: {
|
|
28
|
+
On: 'On',
|
|
29
|
+
Brightness: 'Brightness',
|
|
30
|
+
RotationSpeed: 'RotationSpeed',
|
|
31
|
+
CurrentPosition: 'CurrentPosition',
|
|
32
|
+
TargetPosition: 'TargetPosition',
|
|
33
|
+
},
|
|
17
34
|
}
|
|
18
35
|
}
|
|
19
36
|
|
|
@@ -15,13 +15,23 @@ describe('accessory restoration', () => {
|
|
|
15
15
|
getRestored() { return (this as any)._accessoryCache }
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
-
const logger = {
|
|
18
|
+
const logger = {
|
|
19
|
+
info: () => {},
|
|
20
|
+
warn: () => {},
|
|
21
|
+
error: () => {},
|
|
22
|
+
debug: () => {},
|
|
23
|
+
}
|
|
19
24
|
const config = {}
|
|
20
25
|
const api = {}
|
|
21
26
|
|
|
22
27
|
it('should restore HAP accessories from cache', () => {
|
|
23
28
|
const platform = new TestHAPPlatform(logger, config, api)
|
|
24
|
-
platform.setCache([
|
|
29
|
+
platform.setCache([
|
|
30
|
+
{
|
|
31
|
+
uuid: 'hap-1',
|
|
32
|
+
context: { type: 'Bot' },
|
|
33
|
+
},
|
|
34
|
+
])
|
|
25
35
|
const restored = platform.getRestored()
|
|
26
36
|
expect(restored).toHaveLength(1)
|
|
27
37
|
expect(restored[0].uuid).toBe('hap-1')
|
|
@@ -29,7 +39,12 @@ describe('accessory restoration', () => {
|
|
|
29
39
|
|
|
30
40
|
it('should restore Matter accessories from cache', () => {
|
|
31
41
|
const platform = new TestMatterPlatform(logger, config, api)
|
|
32
|
-
platform.setCache([
|
|
42
|
+
platform.setCache([
|
|
43
|
+
{
|
|
44
|
+
uuid: 'matter-1',
|
|
45
|
+
context: { type: 'Curtain' },
|
|
46
|
+
},
|
|
47
|
+
])
|
|
33
48
|
const restored = platform.getRestored()
|
|
34
49
|
expect(restored).toHaveLength(1)
|
|
35
50
|
expect(restored[0].uuid).toBe('matter-1')
|