matterbridge-roborock-vacuum-plugin-regions 1.1.1-jb.1
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/.github/workflows/build.yml +56 -0
- package/.github/workflows/coverage.yml +59 -0
- package/.github/workflows/publish.yml +37 -0
- package/.tarignore +5 -0
- package/CHANGELOG.md +62 -0
- package/LICENSE +202 -0
- package/README.md +135 -0
- package/README_CLEANMODE.md +29 -0
- package/README_DEV.md +75 -0
- package/README_REPORT_ISSUE.md +34 -0
- package/README_SUPPORTED.md +67 -0
- package/dist/behaviorFactory.js +26 -0
- package/dist/behaviors/BehaviorDeviceGeneric.js +22 -0
- package/dist/behaviors/roborock.vacuum/default/default.js +183 -0
- package/dist/behaviors/roborock.vacuum/default/initalData.js +143 -0
- package/dist/behaviors/roborock.vacuum/default/runtimes.js +21 -0
- package/dist/behaviors/roborock.vacuum/smart/initalData.js +18 -0
- package/dist/behaviors/roborock.vacuum/smart/runtimes.js +11 -0
- package/dist/behaviors/roborock.vacuum/smart/smart.js +119 -0
- package/dist/clientManager.js +17 -0
- package/dist/helper.js +76 -0
- package/dist/index.js +4 -0
- package/dist/initialData/getBatteryStatus.js +24 -0
- package/dist/initialData/getOperationalStates.js +82 -0
- package/dist/initialData/getSupportedAreas.js +120 -0
- package/dist/initialData/getSupportedCleanModes.js +17 -0
- package/dist/initialData/getSupportedRunModes.js +11 -0
- package/dist/initialData/getSupportedScenes.js +26 -0
- package/dist/initialData/index.js +6 -0
- package/dist/model/CloudMessageModel.js +1 -0
- package/dist/model/DockingStationStatus.js +26 -0
- package/dist/model/ExperimentalFeatureSetting.js +30 -0
- package/dist/model/RoomMap.js +19 -0
- package/dist/model/roomIndexMap.js +21 -0
- package/dist/notifyMessageTypes.js +9 -0
- package/dist/platform.js +312 -0
- package/dist/platformRunner.js +90 -0
- package/dist/roborockCommunication/RESTAPI/roborockAuthenticateApi.js +213 -0
- package/dist/roborockCommunication/RESTAPI/roborockIoTApi.js +95 -0
- package/dist/roborockCommunication/Zenum/additionalPropCode.js +4 -0
- package/dist/roborockCommunication/Zenum/authenticateResponseCode.js +7 -0
- package/dist/roborockCommunication/Zenum/dockType.js +4 -0
- package/dist/roborockCommunication/Zenum/operationStatusCode.js +44 -0
- package/dist/roborockCommunication/Zenum/vacuumAndDockErrorCode.js +68 -0
- package/dist/roborockCommunication/Zmodel/apiResponse.js +1 -0
- package/dist/roborockCommunication/Zmodel/authenticateFlowState.js +1 -0
- package/dist/roborockCommunication/Zmodel/authenticateResponse.js +1 -0
- package/dist/roborockCommunication/Zmodel/baseURL.js +1 -0
- package/dist/roborockCommunication/Zmodel/batteryMessage.js +1 -0
- package/dist/roborockCommunication/Zmodel/device.js +1 -0
- package/dist/roborockCommunication/Zmodel/deviceModel.js +28 -0
- package/dist/roborockCommunication/Zmodel/deviceSchema.js +1 -0
- package/dist/roborockCommunication/Zmodel/deviceStatus.js +22 -0
- package/dist/roborockCommunication/Zmodel/dockInfo.js +6 -0
- package/dist/roborockCommunication/Zmodel/home.js +1 -0
- package/dist/roborockCommunication/Zmodel/homeInfo.js +1 -0
- package/dist/roborockCommunication/Zmodel/map.js +1 -0
- package/dist/roborockCommunication/Zmodel/mapInfo.js +29 -0
- package/dist/roborockCommunication/Zmodel/messageResult.js +7 -0
- package/dist/roborockCommunication/Zmodel/multipleMap.js +1 -0
- package/dist/roborockCommunication/Zmodel/networkInfo.js +1 -0
- package/dist/roborockCommunication/Zmodel/product.js +1 -0
- package/dist/roborockCommunication/Zmodel/room.js +1 -0
- package/dist/roborockCommunication/Zmodel/roomInfo.js +22 -0
- package/dist/roborockCommunication/Zmodel/scene.js +16 -0
- package/dist/roborockCommunication/Zmodel/userData.js +1 -0
- package/dist/roborockCommunication/Zmodel/vacuumError.js +27 -0
- package/dist/roborockCommunication/broadcast/abstractClient.js +55 -0
- package/dist/roborockCommunication/broadcast/client/LocalNetworkClient.js +174 -0
- package/dist/roborockCommunication/broadcast/client/LocalNetworkUDPClient.js +129 -0
- package/dist/roborockCommunication/broadcast/client/MQTTClient.js +139 -0
- package/dist/roborockCommunication/broadcast/client.js +1 -0
- package/dist/roborockCommunication/broadcast/clientRouter.js +82 -0
- package/dist/roborockCommunication/broadcast/listener/abstractConnectionListener.js +1 -0
- package/dist/roborockCommunication/broadcast/listener/abstractMessageHandler.js +1 -0
- package/dist/roborockCommunication/broadcast/listener/abstractMessageListener.js +1 -0
- package/dist/roborockCommunication/broadcast/listener/implementation/chainedConnectionListener.js +26 -0
- package/dist/roborockCommunication/broadcast/listener/implementation/chainedMessageListener.js +11 -0
- package/dist/roborockCommunication/broadcast/listener/implementation/connectionStateListener.js +43 -0
- package/dist/roborockCommunication/broadcast/listener/implementation/generalSyncMessageListener.js +28 -0
- package/dist/roborockCommunication/broadcast/listener/implementation/simpleMessageListener.js +27 -0
- package/dist/roborockCommunication/broadcast/listener/implementation/syncMessageListener.js +33 -0
- package/dist/roborockCommunication/broadcast/listener/index.js +1 -0
- package/dist/roborockCommunication/broadcast/messageProcessor.js +148 -0
- package/dist/roborockCommunication/broadcast/model/contentMessage.js +1 -0
- package/dist/roborockCommunication/broadcast/model/dps.js +1 -0
- package/dist/roborockCommunication/broadcast/model/headerMessage.js +1 -0
- package/dist/roborockCommunication/broadcast/model/messageContext.js +37 -0
- package/dist/roborockCommunication/broadcast/model/protocol.js +28 -0
- package/dist/roborockCommunication/broadcast/model/requestMessage.js +38 -0
- package/dist/roborockCommunication/broadcast/model/responseMessage.js +14 -0
- package/dist/roborockCommunication/helper/chunkBuffer.js +17 -0
- package/dist/roborockCommunication/helper/cryptoHelper.js +23 -0
- package/dist/roborockCommunication/helper/messageDeserializer.js +98 -0
- package/dist/roborockCommunication/helper/messageSerializer.js +84 -0
- package/dist/roborockCommunication/helper/nameDecoder.js +66 -0
- package/dist/roborockCommunication/helper/sequence.js +16 -0
- package/dist/roborockCommunication/index.js +13 -0
- package/dist/roborockService.js +494 -0
- package/dist/runtimes/handleCloudMessage.js +110 -0
- package/dist/runtimes/handleHomeDataMessage.js +57 -0
- package/dist/runtimes/handleLocalMessage.js +169 -0
- package/dist/rvc.js +51 -0
- package/dist/settings.js +1 -0
- package/dist/share/function.js +93 -0
- package/dist/share/runtimeHelper.js +17 -0
- package/dist/tests/testData/mockData.js +359 -0
- package/eslint.config.js +80 -0
- package/jest.config.js +22 -0
- package/jest.setup.js +2 -0
- package/logo.png +0 -0
- package/matterbridge-roborock-vacuum-plugin.config.json +46 -0
- package/matterbridge-roborock-vacuum-plugin.schema.json +293 -0
- package/misc/status.md +119 -0
- package/package.json +111 -0
- package/prettier.config.js +49 -0
- package/screenshot/IMG_1.PNG +0 -0
- package/screenshot/IMG_2.PNG +0 -0
- package/screenshot/IMG_3.PNG +0 -0
- package/screenshot/IMG_4.PNG +0 -0
- package/screenshot/IMG_5.PNG +0 -0
- package/screenshot/IMG_6.PNG +0 -0
- package/screenshot/IMG_7.PNG +0 -0
- package/src/behaviorFactory.ts +41 -0
- package/src/behaviors/BehaviorDeviceGeneric.ts +31 -0
- package/src/behaviors/roborock.vacuum/default/default.ts +238 -0
- package/src/behaviors/roborock.vacuum/default/initalData.ts +152 -0
- package/src/behaviors/roborock.vacuum/default/runtimes.ts +23 -0
- package/src/behaviors/roborock.vacuum/smart/initalData.ts +20 -0
- package/src/behaviors/roborock.vacuum/smart/runtimes.ts +15 -0
- package/src/behaviors/roborock.vacuum/smart/smart.ts +159 -0
- package/src/clientManager.ts +23 -0
- package/src/helper.ts +97 -0
- package/src/index.ts +16 -0
- package/src/initialData/getBatteryStatus.ts +26 -0
- package/src/initialData/getOperationalStates.ts +94 -0
- package/src/initialData/getSupportedAreas.ts +162 -0
- package/src/initialData/getSupportedCleanModes.ts +22 -0
- package/src/initialData/getSupportedRunModes.ts +14 -0
- package/src/initialData/getSupportedScenes.ts +32 -0
- package/src/initialData/index.ts +6 -0
- package/src/model/CloudMessageModel.ts +11 -0
- package/src/model/DockingStationStatus.ts +41 -0
- package/src/model/ExperimentalFeatureSetting.ts +77 -0
- package/src/model/RoomMap.ts +38 -0
- package/src/model/roomIndexMap.ts +26 -0
- package/src/notifyMessageTypes.ts +8 -0
- package/src/platform.ts +424 -0
- package/src/platformRunner.ts +103 -0
- package/src/roborockCommunication/RESTAPI/roborockAuthenticateApi.ts +302 -0
- package/src/roborockCommunication/RESTAPI/roborockIoTApi.ts +107 -0
- package/src/roborockCommunication/Zenum/additionalPropCode.ts +3 -0
- package/src/roborockCommunication/Zenum/authenticateResponseCode.ts +6 -0
- package/src/roborockCommunication/Zenum/dockType.ts +3 -0
- package/src/roborockCommunication/Zenum/operationStatusCode.ts +43 -0
- package/src/roborockCommunication/Zenum/vacuumAndDockErrorCode.ts +68 -0
- package/src/roborockCommunication/Zmodel/apiResponse.ts +3 -0
- package/src/roborockCommunication/Zmodel/authenticateFlowState.ts +6 -0
- package/src/roborockCommunication/Zmodel/authenticateResponse.ts +5 -0
- package/src/roborockCommunication/Zmodel/baseURL.ts +5 -0
- package/src/roborockCommunication/Zmodel/batteryMessage.ts +16 -0
- package/src/roborockCommunication/Zmodel/device.ts +50 -0
- package/src/roborockCommunication/Zmodel/deviceModel.ts +27 -0
- package/src/roborockCommunication/Zmodel/deviceSchema.ts +8 -0
- package/src/roborockCommunication/Zmodel/deviceStatus.ts +30 -0
- package/src/roborockCommunication/Zmodel/dockInfo.ts +9 -0
- package/src/roborockCommunication/Zmodel/home.ts +13 -0
- package/src/roborockCommunication/Zmodel/homeInfo.ts +5 -0
- package/src/roborockCommunication/Zmodel/map.ts +20 -0
- package/src/roborockCommunication/Zmodel/mapInfo.ts +54 -0
- package/src/roborockCommunication/Zmodel/messageResult.ts +75 -0
- package/src/roborockCommunication/Zmodel/multipleMap.ts +8 -0
- package/src/roborockCommunication/Zmodel/networkInfo.ts +7 -0
- package/src/roborockCommunication/Zmodel/product.ts +9 -0
- package/src/roborockCommunication/Zmodel/room.ts +4 -0
- package/src/roborockCommunication/Zmodel/roomInfo.ts +30 -0
- package/src/roborockCommunication/Zmodel/scene.ts +44 -0
- package/src/roborockCommunication/Zmodel/userData.ts +26 -0
- package/src/roborockCommunication/Zmodel/vacuumError.ts +35 -0
- package/src/roborockCommunication/broadcast/abstractClient.ts +80 -0
- package/src/roborockCommunication/broadcast/client/LocalNetworkClient.ts +218 -0
- package/src/roborockCommunication/broadcast/client/LocalNetworkUDPClient.ts +157 -0
- package/src/roborockCommunication/broadcast/client/MQTTClient.ts +174 -0
- package/src/roborockCommunication/broadcast/client.ts +19 -0
- package/src/roborockCommunication/broadcast/clientRouter.ts +104 -0
- package/src/roborockCommunication/broadcast/listener/abstractConnectionListener.ts +6 -0
- package/src/roborockCommunication/broadcast/listener/abstractMessageHandler.ts +11 -0
- package/src/roborockCommunication/broadcast/listener/abstractMessageListener.ts +5 -0
- package/src/roborockCommunication/broadcast/listener/implementation/chainedConnectionListener.ts +33 -0
- package/src/roborockCommunication/broadcast/listener/implementation/chainedMessageListener.ts +16 -0
- package/src/roborockCommunication/broadcast/listener/implementation/connectionStateListener.ts +57 -0
- package/src/roborockCommunication/broadcast/listener/implementation/generalSyncMessageListener.ts +38 -0
- package/src/roborockCommunication/broadcast/listener/implementation/simpleMessageListener.ts +37 -0
- package/src/roborockCommunication/broadcast/listener/implementation/syncMessageListener.ts +50 -0
- package/src/roborockCommunication/broadcast/listener/index.ts +3 -0
- package/src/roborockCommunication/broadcast/messageProcessor.ts +184 -0
- package/src/roborockCommunication/broadcast/model/contentMessage.ts +5 -0
- package/src/roborockCommunication/broadcast/model/dps.ts +19 -0
- package/src/roborockCommunication/broadcast/model/headerMessage.ts +7 -0
- package/src/roborockCommunication/broadcast/model/messageContext.ts +53 -0
- package/src/roborockCommunication/broadcast/model/protocol.ts +28 -0
- package/src/roborockCommunication/broadcast/model/requestMessage.ts +51 -0
- package/src/roborockCommunication/broadcast/model/responseMessage.ts +19 -0
- package/src/roborockCommunication/helper/chunkBuffer.ts +18 -0
- package/src/roborockCommunication/helper/cryptoHelper.ts +30 -0
- package/src/roborockCommunication/helper/messageDeserializer.ts +119 -0
- package/src/roborockCommunication/helper/messageSerializer.ts +101 -0
- package/src/roborockCommunication/helper/nameDecoder.ts +78 -0
- package/src/roborockCommunication/helper/sequence.ts +18 -0
- package/src/roborockCommunication/index.ts +25 -0
- package/src/roborockService.ts +657 -0
- package/src/runtimes/handleCloudMessage.ts +134 -0
- package/src/runtimes/handleHomeDataMessage.ts +67 -0
- package/src/runtimes/handleLocalMessage.ts +209 -0
- package/src/rvc.ts +97 -0
- package/src/settings.ts +1 -0
- package/src/share/function.ts +103 -0
- package/src/share/runtimeHelper.ts +23 -0
- package/src/tests/behaviors/roborock.vacuum/default/default.test.ts +134 -0
- package/src/tests/behaviors/roborock.vacuum/smart/runtimes.test.ts +64 -0
- package/src/tests/behaviors/roborock.vacuum/smart/smart.test.ts +215 -0
- package/src/tests/helper.test.ts +162 -0
- package/src/tests/initialData/getSupportedAreas.test.ts +181 -0
- package/src/tests/model/DockingStationStatus.test.ts +39 -0
- package/src/tests/platformRunner.test.ts +188 -0
- package/src/tests/platformRunner2.test.ts +228 -0
- package/src/tests/platformRunner3.test.ts +46 -0
- package/src/tests/roborockCommunication/RESTAPI/roborockAuthenticateApi.test.ts +144 -0
- package/src/tests/roborockCommunication/RESTAPI/roborockIoTApi.test.ts +106 -0
- package/src/tests/roborockCommunication/broadcast/client/LocalNetworkClient.test.ts +189 -0
- package/src/tests/roborockCommunication/broadcast/client/MQTTClient.test.ts +208 -0
- package/src/tests/roborockCommunication/broadcast/clientRouter.test.ts +168 -0
- package/src/tests/roborockCommunication/broadcast/listener/implementation/chainedConnectionListener.test.ts +59 -0
- package/src/tests/roborockCommunication/broadcast/listener/implementation/chainedMessageListener.test.ts +46 -0
- package/src/tests/roborockCommunication/broadcast/listener/implementation/simpleMessageListener.test.ts +71 -0
- package/src/tests/roborockCommunication/broadcast/listener/implementation/syncMessageListener.test.ts +86 -0
- package/src/tests/roborockCommunication/broadcast/messageProcessor.test.ts +126 -0
- package/src/tests/roborockService.setSelectedAreas.test.ts +61 -0
- package/src/tests/roborockService.test.ts +517 -0
- package/src/tests/roborockService2.test.ts +69 -0
- package/src/tests/roborockService3.test.ts +133 -0
- package/src/tests/roborockService4.test.ts +76 -0
- package/src/tests/roborockService5.test.ts +79 -0
- package/src/tests/runtimes/handleCloudMessage.test.ts +200 -0
- package/src/tests/runtimes/handleHomeDataMessage.test.ts +54 -0
- package/src/tests/runtimes/handleLocalMessage.test.ts +227 -0
- package/src/tests/testData/mockData.ts +370 -0
- package/src/tests/testData/mockHomeData-a187.json +286 -0
- package/tsconfig.jest.json +21 -0
- package/tsconfig.json +37 -0
- package/tsconfig.production.json +19 -0
- package/tslint.json +9 -0
- package/web-for-testing/README.md +47 -0
- package/web-for-testing/nodemon.json +7 -0
- package/web-for-testing/package-lock.json +6600 -0
- package/web-for-testing/package.json +36 -0
- package/web-for-testing/src/app.ts +194 -0
- package/web-for-testing/tsconfig-ext.json +19 -0
- package/web-for-testing/tsconfig.json +23 -0
- package/web-for-testing/views/index.ejs +172 -0
- package/web-for-testing/watch.mjs +93 -0
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
import { RequestMessage, UserData } from '../../../roborockCommunication';
|
|
2
|
+
import { ClientRouter } from '../../../roborockCommunication/broadcast/clientRouter';
|
|
3
|
+
|
|
4
|
+
describe('ClientRouter', () => {
|
|
5
|
+
let mockLogger: any;
|
|
6
|
+
let mockUserData: UserData;
|
|
7
|
+
|
|
8
|
+
let mockMQTTClient: any;
|
|
9
|
+
let mockLocalNetworkClient: any;
|
|
10
|
+
|
|
11
|
+
beforeEach(() => {
|
|
12
|
+
mockLogger = { debug: jest.fn(), notice: jest.fn() };
|
|
13
|
+
mockUserData = {
|
|
14
|
+
uid: '123',
|
|
15
|
+
token: '123:123/lfrZhw==:123',
|
|
16
|
+
rruid: '123',
|
|
17
|
+
region: 'eu',
|
|
18
|
+
countrycode: '33',
|
|
19
|
+
country: 'FR',
|
|
20
|
+
nickname: '123',
|
|
21
|
+
rriot: {
|
|
22
|
+
u: '123',
|
|
23
|
+
s: '123',
|
|
24
|
+
h: '123',
|
|
25
|
+
k: '123',
|
|
26
|
+
r: {
|
|
27
|
+
r: 'EU',
|
|
28
|
+
a: 'https://api-eu.roborock.com',
|
|
29
|
+
m: 'ssl://mqtt-eu-2.roborock.com:8883',
|
|
30
|
+
l: 'https://wood-eu.roborock.com',
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
mockMQTTClient = {
|
|
36
|
+
isConnected: jest.fn().mockReturnValue(true),
|
|
37
|
+
connect: jest.fn(),
|
|
38
|
+
disconnect: jest.fn(),
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
mockLocalNetworkClient = {
|
|
42
|
+
isConnected: jest.fn().mockReturnValue(true),
|
|
43
|
+
connect: jest.fn(),
|
|
44
|
+
disconnect: jest.fn(),
|
|
45
|
+
send: jest.fn(),
|
|
46
|
+
get: jest.fn(),
|
|
47
|
+
};
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
it('registerConnectionListener should call connectionListeners.register', () => {
|
|
51
|
+
const router = new ClientRouter(mockLogger, mockUserData);
|
|
52
|
+
const listener = {};
|
|
53
|
+
const spy = jest.spyOn(router['connectionListeners'], 'register');
|
|
54
|
+
router.registerConnectionListener(listener as any);
|
|
55
|
+
expect(spy).toHaveBeenCalledWith(listener);
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
it('registerMessageListener should call messageListeners.register', () => {
|
|
59
|
+
const router = new ClientRouter(mockLogger, mockUserData);
|
|
60
|
+
const listener = {};
|
|
61
|
+
const spy = jest.spyOn(router['messageListeners'], 'register');
|
|
62
|
+
router.registerMessageListener(listener as any);
|
|
63
|
+
expect(spy).toHaveBeenCalledWith(listener);
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
it('isConnected should return mqttClient.isConnected', () => {
|
|
67
|
+
const router = new ClientRouter(mockLogger, mockUserData);
|
|
68
|
+
mockMQTTClient = {
|
|
69
|
+
isConnected: jest.fn().mockReturnValue(true),
|
|
70
|
+
};
|
|
71
|
+
router['mqttClient'] = mockMQTTClient;
|
|
72
|
+
expect(router.isConnected()).toBe(true);
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
it('connect should call connect on mqttClient and all localClients', () => {
|
|
76
|
+
const router = new ClientRouter(mockLogger, mockUserData);
|
|
77
|
+
router['mqttClient'] = mockMQTTClient;
|
|
78
|
+
|
|
79
|
+
router.registerClient('duid', '127.0.0.1');
|
|
80
|
+
router['localClients'].set('duid', mockLocalNetworkClient);
|
|
81
|
+
|
|
82
|
+
router.connect();
|
|
83
|
+
expect(mockMQTTClient.connect).toHaveBeenCalled();
|
|
84
|
+
expect(mockLocalNetworkClient.connect).toHaveBeenCalled();
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
it('disconnect should call disconnect on mqttClient and all localClients', async () => {
|
|
88
|
+
const router = new ClientRouter(mockLogger, mockUserData);
|
|
89
|
+
router.registerClient('duid', '127.0.0.1');
|
|
90
|
+
mockMQTTClient = {
|
|
91
|
+
isConnected: jest.fn().mockReturnValue(false),
|
|
92
|
+
connect: jest.fn(),
|
|
93
|
+
disconnect: jest.fn(),
|
|
94
|
+
};
|
|
95
|
+
router['mqttClient'] = mockMQTTClient;
|
|
96
|
+
|
|
97
|
+
router['localClients'].set('duid', mockLocalNetworkClient);
|
|
98
|
+
|
|
99
|
+
await router.disconnect();
|
|
100
|
+
expect(mockMQTTClient.disconnect).toHaveBeenCalled();
|
|
101
|
+
expect(mockLocalNetworkClient.disconnect).toHaveBeenCalled();
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
it('send should use mqttClient for secure requests', async () => {
|
|
105
|
+
mockMQTTClient = {
|
|
106
|
+
isConnected: jest.fn().mockReturnValue(false),
|
|
107
|
+
connect: jest.fn(),
|
|
108
|
+
disconnect: jest.fn(),
|
|
109
|
+
send: jest.fn(),
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
const router = new ClientRouter(mockLogger, mockUserData);
|
|
113
|
+
const request: RequestMessage = { secure: true } as any;
|
|
114
|
+
|
|
115
|
+
router['mqttClient'] = mockMQTTClient;
|
|
116
|
+
await router.send('duid', request);
|
|
117
|
+
expect(mockMQTTClient.send).toHaveBeenCalledWith('duid', request);
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
it('send should use localClient for non-secure requests', async () => {
|
|
121
|
+
const router = new ClientRouter(mockLogger, mockUserData);
|
|
122
|
+
router.registerClient('duid', '127.0.0.1');
|
|
123
|
+
const request: RequestMessage = { secure: false } as any;
|
|
124
|
+
router['localClients'].set('duid', mockLocalNetworkClient);
|
|
125
|
+
await router.send('duid', request);
|
|
126
|
+
expect(mockLocalNetworkClient.send).toHaveBeenCalledWith('duid', request);
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
it('get should use mqttClient for secure requests', async () => {
|
|
130
|
+
const router = new ClientRouter(mockLogger, mockUserData);
|
|
131
|
+
const request: RequestMessage = { secure: true } as any;
|
|
132
|
+
|
|
133
|
+
mockMQTTClient = {
|
|
134
|
+
isConnected: jest.fn().mockReturnValue(false),
|
|
135
|
+
connect: jest.fn(),
|
|
136
|
+
disconnect: jest.fn(),
|
|
137
|
+
send: jest.fn(),
|
|
138
|
+
get: jest.fn(),
|
|
139
|
+
};
|
|
140
|
+
router['mqttClient'] = mockMQTTClient;
|
|
141
|
+
await router.get('duid', request);
|
|
142
|
+
expect(mockMQTTClient.get).toHaveBeenCalledWith('duid', request);
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
it('get should use localClient for non-secure requests', async () => {
|
|
146
|
+
const router = new ClientRouter(mockLogger, mockUserData);
|
|
147
|
+
router.registerClient('duid', '127.0.0.1');
|
|
148
|
+
const request: RequestMessage = { secure: false } as any;
|
|
149
|
+
router['localClients'].set('duid', mockLocalNetworkClient);
|
|
150
|
+
await router.get('duid', request);
|
|
151
|
+
expect(mockLocalNetworkClient.get).toHaveBeenCalledWith('duid', request);
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
it('getClient should return localClient if connected', () => {
|
|
155
|
+
const router = new ClientRouter(mockLogger, mockUserData);
|
|
156
|
+
router.registerClient('duid', '127.0.0.1');
|
|
157
|
+
router['localClients'].set('duid', mockLocalNetworkClient);
|
|
158
|
+
expect(router['getClient']('duid')).toBe(mockLocalNetworkClient);
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
it('getClient should return mqttClient if localClient not connected', () => {
|
|
162
|
+
mockLocalNetworkClient.isConnected.mockReturnValue(false);
|
|
163
|
+
const router = new ClientRouter(mockLogger, mockUserData);
|
|
164
|
+
router.registerClient('duid', '127.0.0.1');
|
|
165
|
+
router['mqttClient'] = mockMQTTClient;
|
|
166
|
+
expect(router['getClient']('duid')).toBe(mockMQTTClient);
|
|
167
|
+
});
|
|
168
|
+
});
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { ChainedConnectionListener } from '../../../../../roborockCommunication/broadcast/listener/implementation/chainedConnectionListener';
|
|
2
|
+
|
|
3
|
+
describe('ChainedConnectionListener', () => {
|
|
4
|
+
let chained: ChainedConnectionListener;
|
|
5
|
+
let listener1: any;
|
|
6
|
+
let listener2: any;
|
|
7
|
+
|
|
8
|
+
beforeEach(() => {
|
|
9
|
+
chained = new ChainedConnectionListener();
|
|
10
|
+
listener1 = {
|
|
11
|
+
onConnected: jest.fn().mockResolvedValue(undefined),
|
|
12
|
+
onDisconnected: jest.fn().mockResolvedValue(undefined),
|
|
13
|
+
onError: jest.fn().mockResolvedValue(undefined),
|
|
14
|
+
};
|
|
15
|
+
listener2 = {
|
|
16
|
+
onConnected: jest.fn().mockResolvedValue(undefined),
|
|
17
|
+
onDisconnected: jest.fn().mockResolvedValue(undefined),
|
|
18
|
+
onError: jest.fn().mockResolvedValue(undefined),
|
|
19
|
+
};
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
it('should register listeners', () => {
|
|
23
|
+
chained.register(listener1);
|
|
24
|
+
chained.register(listener2);
|
|
25
|
+
|
|
26
|
+
// @ts-expect-error Accessing private property for testing
|
|
27
|
+
expect(chained.listeners).toEqual([listener1, listener2]);
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
it('should call onConnected on all listeners', async () => {
|
|
31
|
+
chained.register(listener1);
|
|
32
|
+
chained.register(listener2);
|
|
33
|
+
await chained.onConnected('test-duid');
|
|
34
|
+
expect(listener1.onConnected).toHaveBeenCalled();
|
|
35
|
+
expect(listener2.onConnected).toHaveBeenCalled();
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it('should call onDisconnected on all listeners', async () => {
|
|
39
|
+
chained.register(listener1);
|
|
40
|
+
chained.register(listener2);
|
|
41
|
+
await chained.onDisconnected('test-duid');
|
|
42
|
+
expect(listener1.onDisconnected).toHaveBeenCalled();
|
|
43
|
+
expect(listener2.onDisconnected).toHaveBeenCalled();
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
it('should call onError on all listeners with the same message', async () => {
|
|
47
|
+
chained.register(listener1);
|
|
48
|
+
chained.register(listener2);
|
|
49
|
+
await chained.onError('test-duid', 'error message');
|
|
50
|
+
expect(listener1.onError).toHaveBeenCalledWith('test-duid', 'error message');
|
|
51
|
+
expect(listener2.onError).toHaveBeenCalledWith('test-duid', 'error message');
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
it('should work with no listeners registered', async () => {
|
|
55
|
+
await expect(chained.onConnected('test-duid')).resolves.toBeUndefined();
|
|
56
|
+
await expect(chained.onDisconnected('test-duid')).resolves.toBeUndefined();
|
|
57
|
+
await expect(chained.onError('test-duid', 'msg')).resolves.toBeUndefined();
|
|
58
|
+
});
|
|
59
|
+
});
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { ChainedMessageListener } from '../../../../../roborockCommunication/broadcast/listener/implementation/chainedMessageListener';
|
|
2
|
+
import { AbstractMessageListener } from '../../../../../roborockCommunication/broadcast/listener/abstractMessageListener';
|
|
3
|
+
|
|
4
|
+
describe('ChainedMessageListener', () => {
|
|
5
|
+
let chained: ChainedMessageListener;
|
|
6
|
+
let listener1: jest.Mocked<AbstractMessageListener>;
|
|
7
|
+
let listener2: jest.Mocked<AbstractMessageListener>;
|
|
8
|
+
const message = { foo: 'bar' } as any;
|
|
9
|
+
|
|
10
|
+
beforeEach(() => {
|
|
11
|
+
chained = new ChainedMessageListener();
|
|
12
|
+
listener1 = { onMessage: jest.fn().mockResolvedValue(undefined) } as any;
|
|
13
|
+
listener2 = { onMessage: jest.fn().mockResolvedValue(undefined) } as any;
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
it('should call onMessage on all registered listeners', async () => {
|
|
17
|
+
chained.register(listener1);
|
|
18
|
+
chained.register(listener2);
|
|
19
|
+
|
|
20
|
+
await chained.onMessage(message);
|
|
21
|
+
|
|
22
|
+
expect(listener1.onMessage).toHaveBeenCalledWith(message);
|
|
23
|
+
expect(listener2.onMessage).toHaveBeenCalledWith(message);
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
it('should not fail if no listeners registered', async () => {
|
|
27
|
+
await expect(chained.onMessage(message)).resolves.toBeUndefined();
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
it('should call listeners in order', async () => {
|
|
31
|
+
const callOrder: string[] = [];
|
|
32
|
+
listener1.onMessage.mockImplementation(async () => {
|
|
33
|
+
callOrder.push('first');
|
|
34
|
+
});
|
|
35
|
+
listener2.onMessage.mockImplementation(async () => {
|
|
36
|
+
callOrder.push('second');
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
chained.register(listener1);
|
|
40
|
+
chained.register(listener2);
|
|
41
|
+
|
|
42
|
+
await chained.onMessage(message);
|
|
43
|
+
|
|
44
|
+
expect(callOrder).toEqual(['first', 'second']);
|
|
45
|
+
});
|
|
46
|
+
});
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { SimpleMessageListener } from '../../../../../roborockCommunication/broadcast/listener/implementation/simpleMessageListener';
|
|
2
|
+
import { Protocol } from '../../../../../roborockCommunication/broadcast/model/protocol';
|
|
3
|
+
|
|
4
|
+
describe('SimpleMessageListener', () => {
|
|
5
|
+
let listener: SimpleMessageListener;
|
|
6
|
+
let handler: any;
|
|
7
|
+
let message: any;
|
|
8
|
+
|
|
9
|
+
beforeEach(() => {
|
|
10
|
+
listener = new SimpleMessageListener();
|
|
11
|
+
handler = {
|
|
12
|
+
onStatusChanged: jest.fn().mockResolvedValue(undefined),
|
|
13
|
+
onError: jest.fn().mockResolvedValue(undefined),
|
|
14
|
+
onBatteryUpdate: jest.fn().mockResolvedValue(undefined),
|
|
15
|
+
onAdditionalProps: jest.fn().mockResolvedValue(undefined),
|
|
16
|
+
};
|
|
17
|
+
message = {
|
|
18
|
+
contain: jest.fn(),
|
|
19
|
+
get: jest.fn(),
|
|
20
|
+
};
|
|
21
|
+
listener.registerListener(handler);
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
it('should do nothing if no handler registered', async () => {
|
|
25
|
+
const l = new SimpleMessageListener();
|
|
26
|
+
await expect(l.onMessage(message)).resolves.toBeUndefined();
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
it('should do nothing if message is rpc_response or map_response', async () => {
|
|
30
|
+
message.contain.mockImplementation((proto: Protocol) => proto === Protocol.rpc_response || proto === Protocol.map_response);
|
|
31
|
+
await listener.onMessage(message);
|
|
32
|
+
expect(handler.onStatusChanged).not.toHaveBeenCalled();
|
|
33
|
+
expect(handler.onError).not.toHaveBeenCalled();
|
|
34
|
+
expect(handler.onBatteryUpdate).not.toHaveBeenCalled();
|
|
35
|
+
expect(handler.onAdditionalProps).not.toHaveBeenCalled();
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it('should call onStatusChanged if status_update present', async () => {
|
|
39
|
+
message.contain.mockImplementation((proto: Protocol) => proto === Protocol.status_update);
|
|
40
|
+
await listener.onMessage(message);
|
|
41
|
+
expect(handler.onStatusChanged).toHaveBeenCalled();
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
it('should call onError if error present', async () => {
|
|
45
|
+
message.contain.mockImplementation((proto: Protocol) => proto === Protocol.error);
|
|
46
|
+
message.get.mockReturnValue('42');
|
|
47
|
+
await listener.onMessage(message);
|
|
48
|
+
expect(handler.onError).toHaveBeenCalledWith(42);
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
it('should call onBatteryUpdate if battery present', async () => {
|
|
52
|
+
message.contain.mockImplementation((proto: Protocol) => proto === Protocol.battery);
|
|
53
|
+
message.get.mockReturnValue('77');
|
|
54
|
+
await listener.onMessage(message);
|
|
55
|
+
expect(handler.onBatteryUpdate).toHaveBeenCalledWith(77);
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
it('should call onAdditionalProps if additional_props present', async () => {
|
|
59
|
+
message.contain.mockImplementation((proto: Protocol) => proto === Protocol.additional_props);
|
|
60
|
+
message.get.mockReturnValue('99');
|
|
61
|
+
await listener.onMessage(message);
|
|
62
|
+
expect(handler.onAdditionalProps).toHaveBeenCalledWith(99);
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
it('should not call handler methods if they are undefined', async () => {
|
|
66
|
+
const handlerPartial = {};
|
|
67
|
+
listener.registerListener(handlerPartial as any);
|
|
68
|
+
message.contain.mockReturnValue(true);
|
|
69
|
+
await expect(listener.onMessage(message)).resolves.toBeUndefined();
|
|
70
|
+
});
|
|
71
|
+
});
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { SyncMessageListener } from '../../../../../roborockCommunication/broadcast/listener/implementation/syncMessageListener';
|
|
2
|
+
import { Protocol } from '../../../../../roborockCommunication/broadcast/model/protocol';
|
|
3
|
+
import { RequestMessage } from '../../../../../roborockCommunication/broadcast/model/requestMessage';
|
|
4
|
+
|
|
5
|
+
describe('SyncMessageListener', () => {
|
|
6
|
+
let listener: SyncMessageListener;
|
|
7
|
+
let logger: any;
|
|
8
|
+
|
|
9
|
+
beforeEach(() => {
|
|
10
|
+
logger = { info: jest.fn(), error: jest.fn(), debug: jest.fn(), warn: jest.fn() };
|
|
11
|
+
listener = new SyncMessageListener(logger);
|
|
12
|
+
jest.useFakeTimers();
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
afterEach(() => {
|
|
16
|
+
jest.clearAllTimers();
|
|
17
|
+
jest.useRealTimers();
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
it('should call resolve and remove pending on rpc_response', async () => {
|
|
21
|
+
const resolve = jest.fn();
|
|
22
|
+
const reject = jest.fn();
|
|
23
|
+
const messageId = 123;
|
|
24
|
+
listener.waitFor(messageId, { method: 'test' } as RequestMessage, resolve, reject);
|
|
25
|
+
|
|
26
|
+
const dps = { id: messageId, result: { foo: 'bar' } };
|
|
27
|
+
const message = {
|
|
28
|
+
contain: (proto: Protocol) => proto === Protocol.rpc_response,
|
|
29
|
+
get: () => dps,
|
|
30
|
+
} as any;
|
|
31
|
+
|
|
32
|
+
await listener.onMessage(message);
|
|
33
|
+
|
|
34
|
+
expect(resolve).toHaveBeenCalledWith(dps.result);
|
|
35
|
+
expect(listener['pending'].has(messageId)).toBe(false);
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it('should call resolve if result is ["ok"]', async () => {
|
|
39
|
+
const resolve = jest.fn();
|
|
40
|
+
const reject = jest.fn();
|
|
41
|
+
const messageId = 456;
|
|
42
|
+
listener.waitFor(messageId, { method: 'test' } as RequestMessage, resolve, reject);
|
|
43
|
+
|
|
44
|
+
const dps = { id: messageId, result: ['ok'] };
|
|
45
|
+
const message = {
|
|
46
|
+
contain: (proto: Protocol) => proto === Protocol.rpc_response,
|
|
47
|
+
get: () => dps,
|
|
48
|
+
} as any;
|
|
49
|
+
|
|
50
|
+
await listener.onMessage(message);
|
|
51
|
+
|
|
52
|
+
expect(resolve).toHaveBeenCalled();
|
|
53
|
+
expect(listener['pending'].has(messageId)).toBe(false);
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
it('should remove pending on map_response', async () => {
|
|
57
|
+
const resolve = jest.fn();
|
|
58
|
+
const reject = jest.fn();
|
|
59
|
+
const messageId = 789;
|
|
60
|
+
listener.waitFor(messageId, { method: 'test' } as RequestMessage, resolve, reject);
|
|
61
|
+
|
|
62
|
+
const dps = { id: messageId };
|
|
63
|
+
const message = {
|
|
64
|
+
contain: (proto: Protocol) => proto === Protocol.map_response,
|
|
65
|
+
get: () => dps,
|
|
66
|
+
} as any;
|
|
67
|
+
|
|
68
|
+
await listener.onMessage(message);
|
|
69
|
+
|
|
70
|
+
expect(listener['pending'].has(messageId)).toBe(false);
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
it('should call reject after timeout if not resolved', () => {
|
|
74
|
+
const resolve = jest.fn();
|
|
75
|
+
const reject = jest.fn();
|
|
76
|
+
const messageId = 321;
|
|
77
|
+
listener.waitFor(messageId, { method: 'test' } as RequestMessage, resolve, reject);
|
|
78
|
+
|
|
79
|
+
expect(listener['pending'].has(messageId)).toBe(true);
|
|
80
|
+
|
|
81
|
+
jest.advanceTimersByTime(10000);
|
|
82
|
+
|
|
83
|
+
expect(reject).toHaveBeenCalled();
|
|
84
|
+
expect(listener['pending'].has(messageId)).toBe(false);
|
|
85
|
+
});
|
|
86
|
+
});
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import { MessageProcessor } from '../../../roborockCommunication/broadcast/messageProcessor';
|
|
2
|
+
import { DeviceStatus } from '../../../roborockCommunication/Zmodel/deviceStatus';
|
|
3
|
+
|
|
4
|
+
describe('MessageProcessor', () => {
|
|
5
|
+
let mockClient: any;
|
|
6
|
+
let processor: MessageProcessor;
|
|
7
|
+
let mockLogger: any;
|
|
8
|
+
|
|
9
|
+
beforeEach(() => {
|
|
10
|
+
mockClient = {
|
|
11
|
+
registerMessageListener: jest.fn().mockImplementation(() => {
|
|
12
|
+
void 0;
|
|
13
|
+
}),
|
|
14
|
+
get: jest.fn(),
|
|
15
|
+
send: jest.fn(),
|
|
16
|
+
};
|
|
17
|
+
processor = new MessageProcessor(mockClient);
|
|
18
|
+
mockLogger = { debug: jest.fn(), notice: jest.fn() };
|
|
19
|
+
processor.injectLogger(mockLogger);
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
afterEach(() => {
|
|
23
|
+
jest.restoreAllMocks();
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
it('should inject logger', () => {
|
|
27
|
+
processor.injectLogger(mockLogger);
|
|
28
|
+
expect(processor.logger).toBe(mockLogger);
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
it('getNetworkInfo should call client.get with correct params', async () => {
|
|
32
|
+
mockClient.get.mockResolvedValue('networkInfo');
|
|
33
|
+
const result = await processor.getNetworkInfo('duid');
|
|
34
|
+
expect(mockClient.get).toHaveBeenCalledWith('duid', expect.any(Object));
|
|
35
|
+
expect(result).toBe('networkInfo');
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it('getDeviceStatus should return DeviceStatus if response exists', async () => {
|
|
39
|
+
const mockDeviceStatus = { status: 'ok' };
|
|
40
|
+
mockClient.get.mockResolvedValue([mockDeviceStatus]);
|
|
41
|
+
const result = await processor.getDeviceStatus('duid');
|
|
42
|
+
expect(mockLogger.debug).toHaveBeenCalled();
|
|
43
|
+
expect(result).toBeInstanceOf(DeviceStatus);
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
it('getDeviceStatus should return undefined if response is falsy', async () => {
|
|
47
|
+
mockClient.get.mockResolvedValue(undefined);
|
|
48
|
+
const result = await processor.getDeviceStatus('duid');
|
|
49
|
+
expect(result).toBeUndefined();
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
it('getRooms should return RoomInfo', async () => {
|
|
53
|
+
mockClient.get.mockResolvedValue([[1, 2]]);
|
|
54
|
+
const result = await processor.getRooms('duid');
|
|
55
|
+
expect(result).not.toBeUndefined();
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
it('gotoDock should call client.send', async () => {
|
|
59
|
+
await processor.gotoDock('duid');
|
|
60
|
+
expect(mockClient.send).toHaveBeenCalledWith('duid', expect.any(Object));
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
it('startClean should call client.send', async () => {
|
|
64
|
+
await processor.startClean('duid');
|
|
65
|
+
expect(mockClient.send).toHaveBeenCalledWith('duid', expect.any(Object));
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
it('startRoomClean should call client.send with correct params', async () => {
|
|
69
|
+
await processor.startRoomClean('duid', [1, 2], 3);
|
|
70
|
+
expect(mockClient.send).toHaveBeenCalledWith('duid', expect.any(Object));
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
it('pauseClean should call client.send', async () => {
|
|
74
|
+
await processor.pauseClean('duid');
|
|
75
|
+
expect(mockClient.send).toHaveBeenCalledWith('duid', expect.any(Object));
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
it('resumeClean should call client.send', async () => {
|
|
79
|
+
await processor.resumeClean('duid');
|
|
80
|
+
expect(mockClient.send).toHaveBeenCalledWith('duid', expect.any(Object));
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
it('stopClean should call client.send', async () => {
|
|
84
|
+
await processor.stopClean('duid');
|
|
85
|
+
expect(mockClient.send).toHaveBeenCalledWith('duid', expect.any(Object));
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
it('sendCustomMessage should call client.send', async () => {
|
|
89
|
+
const def = { method: 'custom' };
|
|
90
|
+
await processor.sendCustomMessage('duid', def as any);
|
|
91
|
+
expect(mockClient.send).toHaveBeenCalledWith('duid', expect.any(Object));
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
it('getCustomMessage should call client.get', async () => {
|
|
95
|
+
const def = { method: 'custom' };
|
|
96
|
+
await processor.getCustomMessage('duid', def as any);
|
|
97
|
+
expect(mockClient.get).toHaveBeenCalledWith('duid', def);
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
it('findMyRobot should call client.send', async () => {
|
|
101
|
+
await processor.findMyRobot('duid');
|
|
102
|
+
expect(mockClient.get).toHaveBeenCalledWith('duid', expect.any(Object));
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
it('getCleanModeData should parse and return correct values', async () => {
|
|
106
|
+
mockClient.get
|
|
107
|
+
.mockResolvedValueOnce([306]) // get_mop_mode
|
|
108
|
+
.mockResolvedValueOnce([101]) // get_custom_mode
|
|
109
|
+
.mockResolvedValueOnce({ water_box_mode: 207, distance_off: 5 }); // get_water_box_custom_mode
|
|
110
|
+
|
|
111
|
+
const result = await processor.getCleanModeData('duid');
|
|
112
|
+
expect(result).toEqual({
|
|
113
|
+
suctionPower: 101,
|
|
114
|
+
waterFlow: 207,
|
|
115
|
+
distance_off: 5,
|
|
116
|
+
mopRoute: 306,
|
|
117
|
+
});
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
it('changeCleanMode should call logger.notice and client.send as needed', async () => {
|
|
121
|
+
mockLogger.notice = jest.fn();
|
|
122
|
+
mockClient.get.mockResolvedValueOnce(110); // currentMopMode
|
|
123
|
+
await processor.changeCleanMode('duid', 101, 207, 306, 5);
|
|
124
|
+
expect(mockLogger.notice).toHaveBeenCalled();
|
|
125
|
+
});
|
|
126
|
+
});
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { AnsiLogger } from 'matterbridge/logger';
|
|
2
|
+
import RoborockService from '../roborockService';
|
|
3
|
+
import { MessageProcessor } from '../roborockCommunication/broadcast/messageProcessor';
|
|
4
|
+
import { RoomIndexMap } from '../model/roomIndexMap';
|
|
5
|
+
|
|
6
|
+
describe('RoborockService - startClean', () => {
|
|
7
|
+
let roborockService: RoborockService;
|
|
8
|
+
let mockLogger: AnsiLogger;
|
|
9
|
+
let mockMessageProcessor: jest.Mocked<MessageProcessor>;
|
|
10
|
+
let mockLoginApi: any;
|
|
11
|
+
let mockIotApi: any;
|
|
12
|
+
|
|
13
|
+
beforeEach(() => {
|
|
14
|
+
mockLogger = {
|
|
15
|
+
debug: jest.fn(),
|
|
16
|
+
notice: jest.fn(),
|
|
17
|
+
error: jest.fn(),
|
|
18
|
+
warn: jest.fn(),
|
|
19
|
+
} as any;
|
|
20
|
+
|
|
21
|
+
mockMessageProcessor = {
|
|
22
|
+
startClean: jest.fn(),
|
|
23
|
+
startRoomClean: jest.fn(),
|
|
24
|
+
} as any;
|
|
25
|
+
|
|
26
|
+
mockLoginApi = {
|
|
27
|
+
loginWithPassword: jest.fn(),
|
|
28
|
+
loginWithUserData: jest.fn(),
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
roborockService = new RoborockService(() => mockLoginApi, jest.fn(), 10, {} as any, mockLogger);
|
|
32
|
+
roborockService['auth'] = jest.fn((ud) => ud);
|
|
33
|
+
roborockService['messageProcessorMap'] = new Map<string, MessageProcessor>([['test-duid', mockMessageProcessor]]);
|
|
34
|
+
|
|
35
|
+
mockIotApi = { getCustom: jest.fn() };
|
|
36
|
+
roborockService['iotApi'] = mockIotApi;
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
it('setSelectedAreas should set selected areas', () => {
|
|
40
|
+
roborockService.setSupportedAreaIndexMap(
|
|
41
|
+
'duid',
|
|
42
|
+
new RoomIndexMap(
|
|
43
|
+
new Map([
|
|
44
|
+
[100, { roomId: 1, mapId: 0 }],
|
|
45
|
+
[101, { roomId: 2, mapId: 0 }],
|
|
46
|
+
[102, { roomId: 3, mapId: 0 }],
|
|
47
|
+
[103, { roomId: 4, mapId: 0 }],
|
|
48
|
+
[104, { roomId: 1, mapId: 1 }],
|
|
49
|
+
[105, { roomId: 2, mapId: 1 }],
|
|
50
|
+
[106, { roomId: 3, mapId: 1 }],
|
|
51
|
+
[107, { roomId: 4, mapId: 1 }],
|
|
52
|
+
[108, { roomId: 5, mapId: 1 }],
|
|
53
|
+
]),
|
|
54
|
+
),
|
|
55
|
+
);
|
|
56
|
+
roborockService.setSelectedAreas('duid', [106, 108]);
|
|
57
|
+
|
|
58
|
+
expect(roborockService['selectedAreas'].get('duid')).toEqual([3, 5]);
|
|
59
|
+
expect(mockLogger.debug).toHaveBeenCalledWith('RoborockService - setSelectedAreas - roomIds', [3, 5]);
|
|
60
|
+
});
|
|
61
|
+
});
|