@homebridge-plugins/homebridge-tuya 2.6.0 → 2.7.1-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/CHANGELOG.md +39 -0
- package/README.md +10 -10
- package/SUPPORTED_DEVICES.md +2 -1
- package/dist/accessory/AccessoryFactory.js +7 -0
- package/dist/accessory/AccessoryFactory.js.map +1 -1
- package/dist/accessory/BaseAccessory.js +2 -2
- package/dist/accessory/BaseAccessory.js.map +1 -1
- package/dist/accessory/CatToiletAccessory.js +130 -0
- package/dist/accessory/CatToiletAccessory.js.map +1 -0
- package/dist/accessory/FanAccessory.js +14 -2
- package/dist/accessory/FanAccessory.js.map +1 -1
- package/dist/accessory/IRAirConditionerAccessory.js +2 -2
- package/dist/accessory/IRAirConditionerAccessory.js.map +1 -1
- package/dist/accessory/LocationWeatherAccessory.js +2 -2
- package/dist/accessory/LocationWeatherAccessory.js.map +1 -1
- package/dist/accessory/LockAccessory.js +254 -3
- package/dist/accessory/LockAccessory.js.map +1 -1
- package/dist/accessory/SaunaAccessory.js +144 -0
- package/dist/accessory/SaunaAccessory.js.map +1 -0
- package/dist/accessory/SecuritySystemAccessory.js +2 -2
- package/dist/accessory/SecuritySystemAccessory.js.map +1 -1
- package/dist/accessory/WindowCoveringAccessory.js +18 -127
- package/dist/accessory/WindowCoveringAccessory.js.map +1 -1
- package/dist/accessory/characteristic/CurrentPosition.js +111 -0
- package/dist/accessory/characteristic/CurrentPosition.js.map +1 -0
- package/dist/accessory/characteristic/Light.js +25 -4
- package/dist/accessory/characteristic/Light.js.map +1 -1
- package/dist/accessory/characteristic/PositionState.js +76 -0
- package/dist/accessory/characteristic/PositionState.js.map +1 -0
- package/dist/accessory/characteristic/TargetPosition.js +84 -0
- package/dist/accessory/characteristic/TargetPosition.js.map +1 -0
- package/dist/core/TuyaOpenAPI.js +20 -6
- package/dist/core/TuyaOpenAPI.js.map +1 -1
- package/dist/core/TuyaOpenMQ.js +0 -1
- package/dist/core/TuyaOpenMQ.js.map +1 -1
- package/dist/device/TuyaDeviceManager.js +37 -0
- package/dist/device/TuyaDeviceManager.js.map +1 -1
- package/dist/platform.js +0 -1
- package/dist/platform.js.map +1 -1
- package/dist/util/Logger.js +15 -13
- package/dist/util/Logger.js.map +1 -1
- package/dist/util/TuyaStreamDelegate.js.map +1 -1
- package/dist/util/util.js +73 -0
- package/dist/util/util.js.map +1 -1
- package/package.json +1 -1
- package/test/FanAccessory.test.ts +457 -0
- package/test/Light.test.ts +186 -0
- package/test/accessory/lockAccessory.test.ts +549 -0
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
|
+
import { describe, expect, test, jest, beforeEach } from '@jest/globals';
|
|
3
|
+
import { configureLight } from '../src/accessory/characteristic/Light';
|
|
4
|
+
|
|
5
|
+
describe('configureLight - ON handler bundles brightness', () => {
|
|
6
|
+
let mockAccessory: any;
|
|
7
|
+
let mockService: any;
|
|
8
|
+
let handlers: Record<string, { onGet?: Function; onSet?: Function }>;
|
|
9
|
+
|
|
10
|
+
beforeEach(() => {
|
|
11
|
+
handlers = {};
|
|
12
|
+
|
|
13
|
+
const makeCharChain = (name: string) => ({
|
|
14
|
+
onGet: jest.fn(function (this: any, handler: Function) {
|
|
15
|
+
handlers[name] = handlers[name] || {};
|
|
16
|
+
handlers[name].onGet = handler;
|
|
17
|
+
return this;
|
|
18
|
+
}),
|
|
19
|
+
onSet: jest.fn(function (this: any, handler: Function) {
|
|
20
|
+
handlers[name] = handlers[name] || {};
|
|
21
|
+
handlers[name].onSet = handler;
|
|
22
|
+
return this;
|
|
23
|
+
}),
|
|
24
|
+
setProps: jest.fn().mockReturnThis(),
|
|
25
|
+
updateValue: jest.fn().mockReturnThis(),
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
const onChar = makeCharChain('On');
|
|
29
|
+
const brightChar = makeCharChain('Brightness');
|
|
30
|
+
|
|
31
|
+
mockService = {
|
|
32
|
+
getCharacteristic: jest.fn((charType: any) => {
|
|
33
|
+
if (charType === 'MockOn') {
|
|
34
|
+
return onChar;
|
|
35
|
+
}
|
|
36
|
+
if (charType === 'MockBrightness') {
|
|
37
|
+
return brightChar;
|
|
38
|
+
}
|
|
39
|
+
return makeCharChain('other');
|
|
40
|
+
}),
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
mockAccessory = {
|
|
44
|
+
Characteristic: { On: 'MockOn', Brightness: 'MockBrightness' },
|
|
45
|
+
Service: { Lightbulb: 'MockLightbulb' },
|
|
46
|
+
accessory: {
|
|
47
|
+
displayName: 'Test Light',
|
|
48
|
+
getService: jest.fn(() => null),
|
|
49
|
+
addService: jest.fn(() => mockService),
|
|
50
|
+
},
|
|
51
|
+
log: { info: jest.fn(), debug: jest.fn(), warn: jest.fn() },
|
|
52
|
+
platform: { getDeviceConfig: jest.fn(() => undefined) },
|
|
53
|
+
checkOnlineStatus: jest.fn(),
|
|
54
|
+
getStatus: jest.fn((code: string) => {
|
|
55
|
+
if (code === 'light') {
|
|
56
|
+
return { code: 'light', value: true };
|
|
57
|
+
}
|
|
58
|
+
if (code === 'bright_value') {
|
|
59
|
+
return { code: 'bright_value', value: 420 };
|
|
60
|
+
}
|
|
61
|
+
if (code === 'switch_led') {
|
|
62
|
+
return { code: 'switch_led', value: false };
|
|
63
|
+
}
|
|
64
|
+
if (code === 'bright_value_1') {
|
|
65
|
+
return { code: 'bright_value_1', value: 100 };
|
|
66
|
+
}
|
|
67
|
+
return undefined;
|
|
68
|
+
}),
|
|
69
|
+
sendCommands: jest.fn(),
|
|
70
|
+
};
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
function makeSchema(code: string, type = 'Boolean', property: any = {}) {
|
|
74
|
+
return { code, mode: 'rw', type, property };
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
function brightSchema(code = 'bright_value') {
|
|
78
|
+
return makeSchema(code, 'Integer', { min: 10, max: 1000, scale: 0, step: 1 });
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
test('LightType.C: ON sends both on + cached brightness', async () => {
|
|
82
|
+
configureLight(
|
|
83
|
+
mockAccessory,
|
|
84
|
+
mockService,
|
|
85
|
+
makeSchema('light') as any,
|
|
86
|
+
brightSchema() as any,
|
|
87
|
+
);
|
|
88
|
+
|
|
89
|
+
expect(handlers['On']?.onSet).toBeDefined();
|
|
90
|
+
await handlers['On'].onSet!(true);
|
|
91
|
+
|
|
92
|
+
expect(mockAccessory.sendCommands).toHaveBeenCalledWith(
|
|
93
|
+
[
|
|
94
|
+
{ code: 'light', value: true },
|
|
95
|
+
{ code: 'bright_value', value: 420 },
|
|
96
|
+
],
|
|
97
|
+
true,
|
|
98
|
+
);
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
test('LightType.C: OFF sends only the on command (no brightness)', async () => {
|
|
102
|
+
configureLight(
|
|
103
|
+
mockAccessory,
|
|
104
|
+
mockService,
|
|
105
|
+
makeSchema('light') as any,
|
|
106
|
+
brightSchema() as any,
|
|
107
|
+
);
|
|
108
|
+
|
|
109
|
+
await handlers['On'].onSet!(false);
|
|
110
|
+
|
|
111
|
+
expect(mockAccessory.sendCommands).toHaveBeenCalledWith(
|
|
112
|
+
[{ code: 'light', value: false }],
|
|
113
|
+
true,
|
|
114
|
+
);
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
test('dual-light warm channel: ON bundles warm brightness', async () => {
|
|
118
|
+
configureLight(
|
|
119
|
+
mockAccessory,
|
|
120
|
+
mockService,
|
|
121
|
+
makeSchema('light') as any,
|
|
122
|
+
brightSchema('bright_value') as any,
|
|
123
|
+
);
|
|
124
|
+
|
|
125
|
+
await handlers['On'].onSet!(true);
|
|
126
|
+
|
|
127
|
+
expect(mockAccessory.sendCommands).toHaveBeenCalledWith(
|
|
128
|
+
[
|
|
129
|
+
{ code: 'light', value: true },
|
|
130
|
+
{ code: 'bright_value', value: 420 },
|
|
131
|
+
],
|
|
132
|
+
true,
|
|
133
|
+
);
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
test('dual-light white channel: ON bundles white brightness', async () => {
|
|
137
|
+
configureLight(
|
|
138
|
+
mockAccessory,
|
|
139
|
+
mockService,
|
|
140
|
+
makeSchema('switch_led') as any,
|
|
141
|
+
brightSchema('bright_value_1') as any,
|
|
142
|
+
);
|
|
143
|
+
|
|
144
|
+
await handlers['On'].onSet!(true);
|
|
145
|
+
|
|
146
|
+
expect(mockAccessory.sendCommands).toHaveBeenCalledWith(
|
|
147
|
+
[
|
|
148
|
+
{ code: 'switch_led', value: true },
|
|
149
|
+
{ code: 'bright_value_1', value: 100 },
|
|
150
|
+
],
|
|
151
|
+
true,
|
|
152
|
+
);
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
test('brightness-only set does not include on command', async () => {
|
|
156
|
+
configureLight(
|
|
157
|
+
mockAccessory,
|
|
158
|
+
mockService,
|
|
159
|
+
makeSchema('light') as any,
|
|
160
|
+
brightSchema() as any,
|
|
161
|
+
);
|
|
162
|
+
|
|
163
|
+
await handlers['Brightness'].onSet!(42);
|
|
164
|
+
|
|
165
|
+
expect(mockAccessory.sendCommands).toHaveBeenCalledWith(
|
|
166
|
+
[{ code: 'bright_value', value: 420 }],
|
|
167
|
+
true,
|
|
168
|
+
);
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
test('ON without brightness schema does not crash', async () => {
|
|
172
|
+
configureLight(
|
|
173
|
+
mockAccessory,
|
|
174
|
+
mockService,
|
|
175
|
+
makeSchema('light') as any,
|
|
176
|
+
);
|
|
177
|
+
|
|
178
|
+
expect(handlers['On']?.onSet).toBeDefined();
|
|
179
|
+
await handlers['On'].onSet!(true);
|
|
180
|
+
|
|
181
|
+
expect(mockAccessory.sendCommands).toHaveBeenCalledWith(
|
|
182
|
+
[{ code: 'light', value: true }],
|
|
183
|
+
true,
|
|
184
|
+
);
|
|
185
|
+
});
|
|
186
|
+
});
|