homebridge-tsvesync 1.4.7 → 1.4.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/AGENTS.md +31 -0
- package/CHANGELOG.md +27 -0
- package/dist/accessories/humidifier.accessory.d.ts +22 -0
- package/dist/accessories/humidifier.accessory.d.ts.map +1 -1
- package/dist/accessories/humidifier.accessory.js +163 -219
- package/dist/accessories/humidifier.accessory.js.map +1 -1
- package/package.json +2 -2
- package/src/__tests__/accessories/humidifier-write-consistency.test.ts +516 -0
- package/src/accessories/humidifier.accessory.ts +219 -313
- package/tsconfig.json +2 -1
- package/dist/__tests__/setup.d.ts +0 -10
- package/dist/__tests__/setup.d.ts.map +0 -1
- package/dist/__tests__/setup.js +0 -82
- package/dist/__tests__/setup.js.map +0 -1
- package/dist/__tests__/utils/test-helpers.d.ts +0 -279
- package/dist/__tests__/utils/test-helpers.d.ts.map +0 -1
- package/dist/__tests__/utils/test-helpers.js +0 -831
- package/dist/__tests__/utils/test-helpers.js.map +0 -1
|
@@ -0,0 +1,516 @@
|
|
|
1
|
+
import { Logger, PlatformAccessory } from 'homebridge';
|
|
2
|
+
import { HumidifierAccessory } from '../../accessories/humidifier.accessory';
|
|
3
|
+
import { TSVESyncPlatform } from '../../platform';
|
|
4
|
+
import { createMockLogger } from '../utils/test-helpers';
|
|
5
|
+
|
|
6
|
+
type CharacteristicStub = {
|
|
7
|
+
onSet: jest.Mock;
|
|
8
|
+
onGet: jest.Mock;
|
|
9
|
+
updateValue: jest.Mock;
|
|
10
|
+
setProps: jest.Mock;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
const createCharacteristic = (name: string) => ({ name });
|
|
14
|
+
|
|
15
|
+
const createCharacteristicStub = (): CharacteristicStub => ({
|
|
16
|
+
onSet: jest.fn().mockReturnThis(),
|
|
17
|
+
onGet: jest.fn().mockReturnThis(),
|
|
18
|
+
updateValue: jest.fn().mockReturnThis(),
|
|
19
|
+
setProps: jest.fn().mockReturnThis(),
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
const createMockService = () => {
|
|
23
|
+
const characteristicStubs = new Map<any, CharacteristicStub>();
|
|
24
|
+
|
|
25
|
+
return {
|
|
26
|
+
getCharacteristic: jest.fn((characteristic: any) => {
|
|
27
|
+
if (!characteristicStubs.has(characteristic)) {
|
|
28
|
+
characteristicStubs.set(characteristic, createCharacteristicStub());
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
return characteristicStubs.get(characteristic);
|
|
32
|
+
}),
|
|
33
|
+
setCharacteristic: jest.fn().mockReturnThis(),
|
|
34
|
+
updateCharacteristic: jest.fn().mockReturnThis(),
|
|
35
|
+
addCharacteristic: jest.fn((characteristic: any) => {
|
|
36
|
+
if (!characteristicStubs.has(characteristic)) {
|
|
37
|
+
characteristicStubs.set(characteristic, createCharacteristicStub());
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
return characteristicStubs.get(characteristic);
|
|
41
|
+
}),
|
|
42
|
+
removeCharacteristic: jest.fn().mockReturnThis(),
|
|
43
|
+
testCharacteristic: jest.fn().mockReturnValue(true),
|
|
44
|
+
};
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
const createMockPlatform = (logger: jest.Mocked<Logger>) => {
|
|
48
|
+
const Characteristic = {
|
|
49
|
+
Active: createCharacteristic('Active'),
|
|
50
|
+
Brightness: createCharacteristic('Brightness'),
|
|
51
|
+
CurrentHumidifierDehumidifierState: createCharacteristic('CurrentHumidifierDehumidifierState'),
|
|
52
|
+
CurrentRelativeHumidity: createCharacteristic('CurrentRelativeHumidity'),
|
|
53
|
+
LockPhysicalControls: createCharacteristic('LockPhysicalControls'),
|
|
54
|
+
Manufacturer: createCharacteristic('Manufacturer'),
|
|
55
|
+
Model: createCharacteristic('Model'),
|
|
56
|
+
Name: createCharacteristic('Name'),
|
|
57
|
+
On: createCharacteristic('On'),
|
|
58
|
+
RelativeHumidityHumidifierThreshold: createCharacteristic('RelativeHumidityHumidifierThreshold'),
|
|
59
|
+
RotationSpeed: createCharacteristic('RotationSpeed'),
|
|
60
|
+
SerialNumber: createCharacteristic('SerialNumber'),
|
|
61
|
+
TargetHumidifierDehumidifierState: createCharacteristic('TargetHumidifierDehumidifierState'),
|
|
62
|
+
WaterLevel: createCharacteristic('WaterLevel'),
|
|
63
|
+
} as const;
|
|
64
|
+
|
|
65
|
+
const Service = {
|
|
66
|
+
AccessoryInformation: 'AccessoryInformation',
|
|
67
|
+
HumidifierDehumidifier: 'HumidifierDehumidifier',
|
|
68
|
+
Lightbulb: 'Lightbulb',
|
|
69
|
+
} as const;
|
|
70
|
+
|
|
71
|
+
return {
|
|
72
|
+
log: logger,
|
|
73
|
+
Service,
|
|
74
|
+
Characteristic,
|
|
75
|
+
api: {
|
|
76
|
+
updatePlatformAccessories: jest.fn(),
|
|
77
|
+
},
|
|
78
|
+
config: {
|
|
79
|
+
debug: true,
|
|
80
|
+
retry: {
|
|
81
|
+
maxRetries: 3,
|
|
82
|
+
},
|
|
83
|
+
},
|
|
84
|
+
} as unknown as jest.Mocked<TSVESyncPlatform>;
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
const createMockAccessory = (platform: jest.Mocked<TSVESyncPlatform>) => {
|
|
88
|
+
const humidifierService = createMockService();
|
|
89
|
+
const lightService = createMockService();
|
|
90
|
+
const accessoryInformationService = {
|
|
91
|
+
setCharacteristic: jest.fn().mockReturnThis(),
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
const accessory = {
|
|
95
|
+
context: {
|
|
96
|
+
device: {
|
|
97
|
+
details: {},
|
|
98
|
+
},
|
|
99
|
+
},
|
|
100
|
+
displayName: 'Test Humidifier',
|
|
101
|
+
getService: jest.fn((service: any) => {
|
|
102
|
+
if (service === platform.Service.AccessoryInformation) {
|
|
103
|
+
return accessoryInformationService;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
if (service === platform.Service.HumidifierDehumidifier) {
|
|
107
|
+
return humidifierService;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
if (service === 'Night Light') {
|
|
111
|
+
return null;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
return null;
|
|
115
|
+
}),
|
|
116
|
+
addService: jest.fn((service: any) => {
|
|
117
|
+
if (service === platform.Service.HumidifierDehumidifier) {
|
|
118
|
+
return humidifierService;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
if (service === platform.Service.Lightbulb) {
|
|
122
|
+
return lightService;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
return humidifierService;
|
|
126
|
+
}),
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
return {
|
|
130
|
+
accessory: accessory as unknown as jest.Mocked<PlatformAccessory>,
|
|
131
|
+
accessoryInformationService,
|
|
132
|
+
humidifierService,
|
|
133
|
+
lightService,
|
|
134
|
+
};
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
const createMockHumidifier = (options?: {
|
|
138
|
+
deviceStatus?: 'on' | 'off';
|
|
139
|
+
mode?: 'auto' | 'manual';
|
|
140
|
+
staleRefresh?: (state: {
|
|
141
|
+
currentHumidity: number;
|
|
142
|
+
deviceStatus: 'on' | 'off';
|
|
143
|
+
mistLevel: number;
|
|
144
|
+
mode: 'auto' | 'manual';
|
|
145
|
+
targetHumidity: number;
|
|
146
|
+
}) => void;
|
|
147
|
+
}) => {
|
|
148
|
+
const state = {
|
|
149
|
+
currentHumidity: 40,
|
|
150
|
+
deviceStatus: options?.deviceStatus ?? 'off',
|
|
151
|
+
mistLevel: 2,
|
|
152
|
+
mode: options?.mode ?? 'manual',
|
|
153
|
+
targetHumidity: 55,
|
|
154
|
+
};
|
|
155
|
+
|
|
156
|
+
const syncState = () => {
|
|
157
|
+
mockDevice.currentHumidity = state.currentHumidity;
|
|
158
|
+
mockDevice.deviceStatus = state.deviceStatus;
|
|
159
|
+
mockDevice.details = {
|
|
160
|
+
...mockDevice.details,
|
|
161
|
+
current_humidity: state.currentHumidity,
|
|
162
|
+
mode: state.mode,
|
|
163
|
+
target_humidity: state.targetHumidity,
|
|
164
|
+
water_lacks: false,
|
|
165
|
+
water_tank_lifted: false,
|
|
166
|
+
};
|
|
167
|
+
mockDevice.humidity = state.targetHumidity;
|
|
168
|
+
mockDevice.mistLevel = state.mistLevel;
|
|
169
|
+
mockDevice.mode = state.mode;
|
|
170
|
+
};
|
|
171
|
+
|
|
172
|
+
const mockDevice = {
|
|
173
|
+
cid: 'cid',
|
|
174
|
+
configModule: 'Humidifier',
|
|
175
|
+
connectionStatus: 'online',
|
|
176
|
+
currentHumidity: state.currentHumidity,
|
|
177
|
+
deviceName: 'Dual 200S',
|
|
178
|
+
deviceRegion: 'US',
|
|
179
|
+
deviceStatus: state.deviceStatus,
|
|
180
|
+
deviceType: 'Dual200S',
|
|
181
|
+
details: {
|
|
182
|
+
current_humidity: state.currentHumidity,
|
|
183
|
+
mode: state.mode,
|
|
184
|
+
target_humidity: state.targetHumidity,
|
|
185
|
+
water_lacks: false,
|
|
186
|
+
water_tank_lifted: false,
|
|
187
|
+
},
|
|
188
|
+
hasFeature: jest.fn().mockReturnValue(false),
|
|
189
|
+
humidity: state.targetHumidity,
|
|
190
|
+
macId: '00:11:22:33:44:55',
|
|
191
|
+
mistLevel: state.mistLevel,
|
|
192
|
+
mode: state.mode,
|
|
193
|
+
speed: 0,
|
|
194
|
+
turnOn: jest.fn().mockImplementation(async () => {
|
|
195
|
+
state.deviceStatus = 'on';
|
|
196
|
+
syncState();
|
|
197
|
+
return true;
|
|
198
|
+
}),
|
|
199
|
+
turnOff: jest.fn().mockImplementation(async () => {
|
|
200
|
+
state.deviceStatus = 'off';
|
|
201
|
+
syncState();
|
|
202
|
+
return true;
|
|
203
|
+
}),
|
|
204
|
+
setAutoMode: jest.fn().mockImplementation(async () => {
|
|
205
|
+
state.deviceStatus = 'on';
|
|
206
|
+
state.mode = 'auto';
|
|
207
|
+
syncState();
|
|
208
|
+
return true;
|
|
209
|
+
}),
|
|
210
|
+
setManualMode: jest.fn().mockImplementation(async () => {
|
|
211
|
+
state.deviceStatus = 'on';
|
|
212
|
+
state.mode = 'manual';
|
|
213
|
+
syncState();
|
|
214
|
+
return true;
|
|
215
|
+
}),
|
|
216
|
+
setMode: jest.fn().mockImplementation(async (mode: 'auto' | 'manual') => {
|
|
217
|
+
state.deviceStatus = 'on';
|
|
218
|
+
state.mode = mode;
|
|
219
|
+
syncState();
|
|
220
|
+
return true;
|
|
221
|
+
}),
|
|
222
|
+
setMistLevel: jest.fn().mockResolvedValue(true),
|
|
223
|
+
changeFanSpeed: jest.fn().mockResolvedValue(true),
|
|
224
|
+
uuid: 'uuid',
|
|
225
|
+
getDetails: jest.fn().mockImplementation(async () => {
|
|
226
|
+
if (options?.staleRefresh) {
|
|
227
|
+
options.staleRefresh(state);
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
syncState();
|
|
231
|
+
return true;
|
|
232
|
+
}),
|
|
233
|
+
};
|
|
234
|
+
|
|
235
|
+
syncState();
|
|
236
|
+
|
|
237
|
+
return mockDevice;
|
|
238
|
+
};
|
|
239
|
+
|
|
240
|
+
describe('HumidifierAccessory write consistency', () => {
|
|
241
|
+
let logger: jest.Mocked<Logger>;
|
|
242
|
+
let platform: jest.Mocked<TSVESyncPlatform>;
|
|
243
|
+
|
|
244
|
+
beforeEach(() => {
|
|
245
|
+
logger = createMockLogger();
|
|
246
|
+
platform = createMockPlatform(logger);
|
|
247
|
+
});
|
|
248
|
+
|
|
249
|
+
it('keeps HomeKit on when the first Dual200S refresh is stale after turning on', async () => {
|
|
250
|
+
const { accessory, humidifierService } = createMockAccessory(platform);
|
|
251
|
+
const device = createMockHumidifier({
|
|
252
|
+
deviceStatus: 'off',
|
|
253
|
+
mode: 'manual',
|
|
254
|
+
staleRefresh: (state) => {
|
|
255
|
+
state.deviceStatus = 'off';
|
|
256
|
+
state.mode = 'manual';
|
|
257
|
+
},
|
|
258
|
+
});
|
|
259
|
+
|
|
260
|
+
const humidifier = new HumidifierAccessory(platform, accessory, device as any);
|
|
261
|
+
humidifierService.updateCharacteristic.mockClear();
|
|
262
|
+
logger.warn.mockClear();
|
|
263
|
+
|
|
264
|
+
await (humidifier as any).setActive(1);
|
|
265
|
+
|
|
266
|
+
expect(device.turnOn).toHaveBeenCalledTimes(1);
|
|
267
|
+
expect(humidifierService.updateCharacteristic.mock.calls).toContainEqual([
|
|
268
|
+
platform.Characteristic.Active,
|
|
269
|
+
1,
|
|
270
|
+
]);
|
|
271
|
+
expect(humidifierService.updateCharacteristic.mock.calls).toContainEqual([
|
|
272
|
+
platform.Characteristic.CurrentHumidifierDehumidifierState,
|
|
273
|
+
2,
|
|
274
|
+
]);
|
|
275
|
+
expect(humidifierService.updateCharacteristic.mock.calls).not.toContainEqual([
|
|
276
|
+
platform.Characteristic.Active,
|
|
277
|
+
0,
|
|
278
|
+
]);
|
|
279
|
+
expect(logger.warn).not.toHaveBeenCalledWith(
|
|
280
|
+
expect.stringContaining('did not change to desired state'),
|
|
281
|
+
);
|
|
282
|
+
});
|
|
283
|
+
|
|
284
|
+
it('keeps HomeKit in manual mode when the first Dual200S refresh is stale after setting mode', async () => {
|
|
285
|
+
const { accessory, humidifierService } = createMockAccessory(platform);
|
|
286
|
+
const device = createMockHumidifier({
|
|
287
|
+
deviceStatus: 'on',
|
|
288
|
+
mode: 'auto',
|
|
289
|
+
staleRefresh: (state) => {
|
|
290
|
+
state.deviceStatus = 'on';
|
|
291
|
+
state.mode = 'auto';
|
|
292
|
+
},
|
|
293
|
+
});
|
|
294
|
+
|
|
295
|
+
const humidifier = new HumidifierAccessory(platform, accessory, device as any);
|
|
296
|
+
humidifierService.updateCharacteristic.mockClear();
|
|
297
|
+
logger.warn.mockClear();
|
|
298
|
+
|
|
299
|
+
// HomeKit state 0 = "Auto" in Home app → VeSync manual for Dual200S
|
|
300
|
+
await (humidifier as any).setTargetState(0);
|
|
301
|
+
|
|
302
|
+
expect(device.setManualMode).toHaveBeenCalledTimes(1);
|
|
303
|
+
expect(humidifierService.updateCharacteristic.mock.calls).toContainEqual([
|
|
304
|
+
platform.Characteristic.TargetHumidifierDehumidifierState,
|
|
305
|
+
0,
|
|
306
|
+
]);
|
|
307
|
+
expect(humidifierService.updateCharacteristic.mock.calls).not.toContainEqual([
|
|
308
|
+
platform.Characteristic.TargetHumidifierDehumidifierState,
|
|
309
|
+
1,
|
|
310
|
+
]);
|
|
311
|
+
expect(logger.warn).not.toHaveBeenCalledWith(
|
|
312
|
+
expect.stringContaining('did not change to desired mode'),
|
|
313
|
+
);
|
|
314
|
+
});
|
|
315
|
+
|
|
316
|
+
it('maps Dual200S auto mode to HomeKit target state 1 (Humidity/slider)', async () => {
|
|
317
|
+
const { accessory, humidifierService } = createMockAccessory(platform);
|
|
318
|
+
const device = createMockHumidifier({
|
|
319
|
+
deviceStatus: 'on',
|
|
320
|
+
mode: 'manual',
|
|
321
|
+
});
|
|
322
|
+
|
|
323
|
+
const humidifier = new HumidifierAccessory(platform, accessory, device as any);
|
|
324
|
+
humidifierService.updateCharacteristic.mockClear();
|
|
325
|
+
|
|
326
|
+
// HomeKit state 1 = HUMIDIFIER ("Humidity" in Home app, shows slider)
|
|
327
|
+
// For Dual200S, this should trigger VeSync auto mode
|
|
328
|
+
await (humidifier as any).setTargetState(1);
|
|
329
|
+
|
|
330
|
+
expect(device.setAutoMode).toHaveBeenCalledTimes(1);
|
|
331
|
+
expect(device.setManualMode).not.toHaveBeenCalled();
|
|
332
|
+
});
|
|
333
|
+
|
|
334
|
+
it('maps Dual200S manual mode to HomeKit target state 0 (Auto/no slider)', async () => {
|
|
335
|
+
const { accessory, humidifierService } = createMockAccessory(platform);
|
|
336
|
+
const device = createMockHumidifier({
|
|
337
|
+
deviceStatus: 'on',
|
|
338
|
+
mode: 'auto',
|
|
339
|
+
});
|
|
340
|
+
|
|
341
|
+
const humidifier = new HumidifierAccessory(platform, accessory, device as any);
|
|
342
|
+
humidifierService.updateCharacteristic.mockClear();
|
|
343
|
+
|
|
344
|
+
// HomeKit state 0 = HUMIDIFIER_OR_DEHUMIDIFIER ("Auto" in Home app, no slider)
|
|
345
|
+
// For Dual200S, this should trigger VeSync manual mode
|
|
346
|
+
await (humidifier as any).setTargetState(0);
|
|
347
|
+
|
|
348
|
+
expect(device.setManualMode).toHaveBeenCalledTimes(1);
|
|
349
|
+
expect(device.setAutoMode).not.toHaveBeenCalled();
|
|
350
|
+
});
|
|
351
|
+
|
|
352
|
+
it('reports Dual200S auto mode as HomeKit target state 1 in state sync', async () => {
|
|
353
|
+
const { accessory, humidifierService } = createMockAccessory(platform);
|
|
354
|
+
const device = createMockHumidifier({
|
|
355
|
+
deviceStatus: 'on',
|
|
356
|
+
mode: 'auto',
|
|
357
|
+
});
|
|
358
|
+
|
|
359
|
+
const humidifier = new HumidifierAccessory(platform, accessory, device as any);
|
|
360
|
+
humidifierService.updateCharacteristic.mockClear();
|
|
361
|
+
|
|
362
|
+
(humidifier as any).applyDeviceStatesToHomeKit(device);
|
|
363
|
+
|
|
364
|
+
expect(humidifierService.updateCharacteristic).toHaveBeenCalledWith(
|
|
365
|
+
platform.Characteristic.TargetHumidifierDehumidifierState,
|
|
366
|
+
1,
|
|
367
|
+
);
|
|
368
|
+
});
|
|
369
|
+
|
|
370
|
+
it('reports Dual200S manual mode as HomeKit target state 0 in state sync', async () => {
|
|
371
|
+
const { accessory, humidifierService } = createMockAccessory(platform);
|
|
372
|
+
const device = createMockHumidifier({
|
|
373
|
+
deviceStatus: 'on',
|
|
374
|
+
mode: 'manual',
|
|
375
|
+
});
|
|
376
|
+
|
|
377
|
+
const humidifier = new HumidifierAccessory(platform, accessory, device as any);
|
|
378
|
+
humidifierService.updateCharacteristic.mockClear();
|
|
379
|
+
|
|
380
|
+
(humidifier as any).applyDeviceStatesToHomeKit(device);
|
|
381
|
+
|
|
382
|
+
expect(humidifierService.updateCharacteristic).toHaveBeenCalledWith(
|
|
383
|
+
platform.Characteristic.TargetHumidifierDehumidifierState,
|
|
384
|
+
0,
|
|
385
|
+
);
|
|
386
|
+
});
|
|
387
|
+
|
|
388
|
+
it('detects LUH-D301S-WEU as isHumidDual200S and isHumid200300S', () => {
|
|
389
|
+
const { accessory } = createMockAccessory(platform);
|
|
390
|
+
const device = createMockHumidifier({ deviceStatus: 'off', mode: 'manual' });
|
|
391
|
+
(device as any).deviceType = 'LUH-D301S-WEU';
|
|
392
|
+
|
|
393
|
+
const humidifier = new HumidifierAccessory(platform, accessory, device as any);
|
|
394
|
+
|
|
395
|
+
expect((humidifier as any).isHumidDual200S).toBe(true);
|
|
396
|
+
expect((humidifier as any).isHumid200300S).toBe(true);
|
|
397
|
+
expect((humidifier as any).isHumid200S).toBe(false);
|
|
398
|
+
});
|
|
399
|
+
|
|
400
|
+
it('detects Dual200S as isHumidDual200S, not isHumid200S', () => {
|
|
401
|
+
const { accessory } = createMockAccessory(platform);
|
|
402
|
+
const device = createMockHumidifier({ deviceStatus: 'off', mode: 'manual' });
|
|
403
|
+
|
|
404
|
+
const humidifier = new HumidifierAccessory(platform, accessory, device as any);
|
|
405
|
+
|
|
406
|
+
expect((humidifier as any).isHumidDual200S).toBe(true);
|
|
407
|
+
expect((humidifier as any).isHumid200300S).toBe(true);
|
|
408
|
+
expect((humidifier as any).isHumid200S).toBe(false);
|
|
409
|
+
});
|
|
410
|
+
|
|
411
|
+
it('maps Dual200S mist level 1 to 50% rotation speed', async () => {
|
|
412
|
+
const { accessory, humidifierService } = createMockAccessory(platform);
|
|
413
|
+
const device = createMockHumidifier({ deviceStatus: 'on', mode: 'manual' });
|
|
414
|
+
device.mistLevel = 1;
|
|
415
|
+
|
|
416
|
+
const humidifier = new HumidifierAccessory(platform, accessory, device as any);
|
|
417
|
+
humidifierService.updateCharacteristic.mockClear();
|
|
418
|
+
|
|
419
|
+
(humidifier as any).applyDeviceStatesToHomeKit(device);
|
|
420
|
+
|
|
421
|
+
expect(humidifierService.updateCharacteristic).toHaveBeenCalledWith(
|
|
422
|
+
platform.Characteristic.RotationSpeed,
|
|
423
|
+
50,
|
|
424
|
+
);
|
|
425
|
+
});
|
|
426
|
+
|
|
427
|
+
it('maps Dual200S mist level 2 to 100% rotation speed', async () => {
|
|
428
|
+
const { accessory, humidifierService } = createMockAccessory(platform);
|
|
429
|
+
const device = createMockHumidifier({ deviceStatus: 'on', mode: 'manual' });
|
|
430
|
+
device.mistLevel = 2;
|
|
431
|
+
|
|
432
|
+
const humidifier = new HumidifierAccessory(platform, accessory, device as any);
|
|
433
|
+
humidifierService.updateCharacteristic.mockClear();
|
|
434
|
+
|
|
435
|
+
(humidifier as any).applyDeviceStatesToHomeKit(device);
|
|
436
|
+
|
|
437
|
+
expect(humidifierService.updateCharacteristic).toHaveBeenCalledWith(
|
|
438
|
+
platform.Characteristic.RotationSpeed,
|
|
439
|
+
100,
|
|
440
|
+
);
|
|
441
|
+
});
|
|
442
|
+
|
|
443
|
+
it('converts Dual200S rotation speed 50% to mist level 1', async () => {
|
|
444
|
+
const { accessory } = createMockAccessory(platform);
|
|
445
|
+
const device = createMockHumidifier({ deviceStatus: 'on', mode: 'manual' });
|
|
446
|
+
device.setMistLevel = jest.fn().mockResolvedValue(true);
|
|
447
|
+
|
|
448
|
+
const humidifier = new HumidifierAccessory(platform, accessory, device as any);
|
|
449
|
+
|
|
450
|
+
await (humidifier as any).handleSetRotationSpeed(50);
|
|
451
|
+
|
|
452
|
+
expect(device.setMistLevel).toHaveBeenCalledWith(1);
|
|
453
|
+
});
|
|
454
|
+
|
|
455
|
+
it('converts Dual200S rotation speed 100% to mist level 2', async () => {
|
|
456
|
+
const { accessory } = createMockAccessory(platform);
|
|
457
|
+
const device = createMockHumidifier({ deviceStatus: 'on', mode: 'manual' });
|
|
458
|
+
device.setMistLevel = jest.fn().mockResolvedValue(true);
|
|
459
|
+
|
|
460
|
+
const humidifier = new HumidifierAccessory(platform, accessory, device as any);
|
|
461
|
+
|
|
462
|
+
await (humidifier as any).handleSetRotationSpeed(100);
|
|
463
|
+
|
|
464
|
+
expect(device.setMistLevel).toHaveBeenCalledWith(2);
|
|
465
|
+
});
|
|
466
|
+
|
|
467
|
+
it('snaps Dual200S rotation speed 30% down to mist level 1', async () => {
|
|
468
|
+
const { accessory } = createMockAccessory(platform);
|
|
469
|
+
const device = createMockHumidifier({ deviceStatus: 'on', mode: 'manual' });
|
|
470
|
+
device.setMistLevel = jest.fn().mockResolvedValue(true);
|
|
471
|
+
|
|
472
|
+
const humidifier = new HumidifierAccessory(platform, accessory, device as any);
|
|
473
|
+
|
|
474
|
+
await (humidifier as any).handleSetRotationSpeed(30);
|
|
475
|
+
|
|
476
|
+
expect(device.setMistLevel).toHaveBeenCalledWith(1);
|
|
477
|
+
});
|
|
478
|
+
|
|
479
|
+
it('snaps Dual200S rotation speed 80% up to mist level 2', async () => {
|
|
480
|
+
const { accessory } = createMockAccessory(platform);
|
|
481
|
+
const device = createMockHumidifier({ deviceStatus: 'on', mode: 'manual' });
|
|
482
|
+
device.setMistLevel = jest.fn().mockResolvedValue(true);
|
|
483
|
+
|
|
484
|
+
const humidifier = new HumidifierAccessory(platform, accessory, device as any);
|
|
485
|
+
|
|
486
|
+
await (humidifier as any).handleSetRotationSpeed(80);
|
|
487
|
+
|
|
488
|
+
expect(device.setMistLevel).toHaveBeenCalledWith(2);
|
|
489
|
+
});
|
|
490
|
+
|
|
491
|
+
it('switches Dual200S from auto to manual mode when adjusting rotation speed', async () => {
|
|
492
|
+
const { accessory } = createMockAccessory(platform);
|
|
493
|
+
const device = createMockHumidifier({ deviceStatus: 'on', mode: 'auto' });
|
|
494
|
+
device.setMistLevel = jest.fn().mockResolvedValue(true);
|
|
495
|
+
|
|
496
|
+
const humidifier = new HumidifierAccessory(platform, accessory, device as any);
|
|
497
|
+
|
|
498
|
+
await (humidifier as any).handleSetRotationSpeed(100);
|
|
499
|
+
|
|
500
|
+
expect(device.setManualMode).toHaveBeenCalledTimes(1);
|
|
501
|
+
expect(device.setMistLevel).toHaveBeenCalledWith(2);
|
|
502
|
+
});
|
|
503
|
+
|
|
504
|
+
it('does not switch mode when Dual200S is already in manual mode', async () => {
|
|
505
|
+
const { accessory } = createMockAccessory(platform);
|
|
506
|
+
const device = createMockHumidifier({ deviceStatus: 'on', mode: 'manual' });
|
|
507
|
+
device.setMistLevel = jest.fn().mockResolvedValue(true);
|
|
508
|
+
|
|
509
|
+
const humidifier = new HumidifierAccessory(platform, accessory, device as any);
|
|
510
|
+
|
|
511
|
+
await (humidifier as any).handleSetRotationSpeed(50);
|
|
512
|
+
|
|
513
|
+
expect(device.setManualMode).not.toHaveBeenCalled();
|
|
514
|
+
expect(device.setMistLevel).toHaveBeenCalledWith(1);
|
|
515
|
+
});
|
|
516
|
+
});
|