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,134 @@
|
|
|
1
|
+
import { BehaviorDeviceGeneric } from '../../../../behaviors/BehaviorDeviceGeneric.js';
|
|
2
|
+
import { AnsiLogger } from 'matterbridge/logger';
|
|
3
|
+
import RoborockService from '../../../../roborockService.js';
|
|
4
|
+
import { CleanModeSettings } from '../../../../model/ExperimentalFeatureSetting.js';
|
|
5
|
+
import { MopRoute, MopWaterFlow, setDefaultCommandHandler, VacuumSuctionPower } from '../../../../behaviors/roborock.vacuum/default/default.js';
|
|
6
|
+
|
|
7
|
+
describe('setDefaultCommandHandler', () => {
|
|
8
|
+
let handler: BehaviorDeviceGeneric<any>;
|
|
9
|
+
let logger: AnsiLogger;
|
|
10
|
+
let roborockService: jest.Mocked<RoborockService>;
|
|
11
|
+
let cleanModeSettings: CleanModeSettings;
|
|
12
|
+
const duid = 'test-duid';
|
|
13
|
+
|
|
14
|
+
beforeEach(() => {
|
|
15
|
+
handler = {
|
|
16
|
+
setCommandHandler: jest.fn(),
|
|
17
|
+
} as any;
|
|
18
|
+
|
|
19
|
+
logger = {
|
|
20
|
+
notice: jest.fn(),
|
|
21
|
+
warn: jest.fn(),
|
|
22
|
+
} as any;
|
|
23
|
+
|
|
24
|
+
roborockService = {
|
|
25
|
+
startClean: jest.fn(),
|
|
26
|
+
changeCleanMode: jest.fn(),
|
|
27
|
+
setSelectedAreas: jest.fn(),
|
|
28
|
+
pauseClean: jest.fn(),
|
|
29
|
+
resumeClean: jest.fn(),
|
|
30
|
+
stopAndGoHome: jest.fn(),
|
|
31
|
+
playSoundToLocate: jest.fn(),
|
|
32
|
+
} as any;
|
|
33
|
+
|
|
34
|
+
cleanModeSettings = {
|
|
35
|
+
vacuuming: { fanMode: 'Max', mopRouteMode: 'DeepPlus' },
|
|
36
|
+
mopping: { waterFlowMode: 'High', mopRouteMode: 'Fast', distanceOff: 85 },
|
|
37
|
+
vacmop: {
|
|
38
|
+
fanMode: 'Turbo',
|
|
39
|
+
waterFlowMode: 'Low',
|
|
40
|
+
mopRouteMode: 'Deep',
|
|
41
|
+
distanceOff: 85,
|
|
42
|
+
},
|
|
43
|
+
enableCleanModeMapping: true,
|
|
44
|
+
};
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
it('should set all command handlers', () => {
|
|
48
|
+
setDefaultCommandHandler(duid, handler, logger, roborockService, cleanModeSettings);
|
|
49
|
+
expect(handler.setCommandHandler).toHaveBeenCalledWith('changeToMode', expect.any(Function));
|
|
50
|
+
expect(handler.setCommandHandler).toHaveBeenCalledWith('selectAreas', expect.any(Function));
|
|
51
|
+
expect(handler.setCommandHandler).toHaveBeenCalledWith('pause', expect.any(Function));
|
|
52
|
+
expect(handler.setCommandHandler).toHaveBeenCalledWith('resume', expect.any(Function));
|
|
53
|
+
expect(handler.setCommandHandler).toHaveBeenCalledWith('goHome', expect.any(Function));
|
|
54
|
+
expect(handler.setCommandHandler).toHaveBeenCalledWith('playSoundToLocate', expect.any(Function));
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
it('should call startClean for Cleaning mode', async () => {
|
|
58
|
+
setDefaultCommandHandler(duid, handler, logger, roborockService, cleanModeSettings);
|
|
59
|
+
const [[, changeToModeHandler]] = (handler.setCommandHandler as jest.Mock).mock.calls.filter(([cmd]) => cmd === 'changeToMode');
|
|
60
|
+
await (changeToModeHandler as (mode: number) => Promise<void>)(2); // 2 = Cleaning
|
|
61
|
+
expect(roborockService.startClean).toHaveBeenCalledWith(duid);
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
it('should call changeCleanMode for Mop with correct values', async () => {
|
|
65
|
+
setDefaultCommandHandler(duid, handler, logger, roborockService, cleanModeSettings);
|
|
66
|
+
const [[, changeToModeHandler]] = (handler.setCommandHandler as jest.Mock).mock.calls.filter(([cmd]) => cmd === 'changeToMode');
|
|
67
|
+
await (changeToModeHandler as (mode: number) => Promise<void>)(31); // 31 = Mop Default
|
|
68
|
+
expect(roborockService.changeCleanMode).toHaveBeenCalledWith(duid, {
|
|
69
|
+
suctionPower: VacuumSuctionPower.Off,
|
|
70
|
+
waterFlow: MopWaterFlow.High,
|
|
71
|
+
mopRoute: MopRoute.Fast,
|
|
72
|
+
distance_off: 0,
|
|
73
|
+
});
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
it('should call changeCleanMode for Vacuum with correct values', async () => {
|
|
77
|
+
setDefaultCommandHandler(duid, handler, logger, roborockService, cleanModeSettings);
|
|
78
|
+
const [[, changeToModeHandler]] = (handler.setCommandHandler as jest.Mock).mock.calls.filter(([cmd]) => cmd === 'changeToMode');
|
|
79
|
+
await (changeToModeHandler as (mode: number) => Promise<void>)(66); // 66 = Vacuum Default
|
|
80
|
+
expect(roborockService.changeCleanMode).toHaveBeenCalledWith(duid, {
|
|
81
|
+
suctionPower: VacuumSuctionPower.Max,
|
|
82
|
+
waterFlow: MopWaterFlow.Off,
|
|
83
|
+
mopRoute: MopRoute.DeepPlus,
|
|
84
|
+
distance_off: 0,
|
|
85
|
+
});
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
it('should call changeCleanMode for Vac & Mop with correct values', async () => {
|
|
89
|
+
setDefaultCommandHandler(duid, handler, logger, roborockService, cleanModeSettings);
|
|
90
|
+
const [[, changeToModeHandler]] = (handler.setCommandHandler as jest.Mock).mock.calls.filter(([cmd]) => cmd === 'changeToMode');
|
|
91
|
+
await (changeToModeHandler as (mode: number) => Promise<void>)(5); // 5 = Vac & Mop Default
|
|
92
|
+
expect(roborockService.changeCleanMode).toHaveBeenCalledWith(duid, {
|
|
93
|
+
suctionPower: VacuumSuctionPower.Turbo,
|
|
94
|
+
waterFlow: MopWaterFlow.Low,
|
|
95
|
+
mopRoute: MopRoute.Deep,
|
|
96
|
+
distance_off: 0,
|
|
97
|
+
});
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
it('should call setSelectedAreas', async () => {
|
|
101
|
+
setDefaultCommandHandler(duid, handler, logger, roborockService, cleanModeSettings);
|
|
102
|
+
const [[, selectAreasHandler]] = (handler.setCommandHandler as jest.Mock).mock.calls.filter(([cmd]) => cmd === 'selectAreas');
|
|
103
|
+
await (selectAreasHandler as (areas: number[]) => Promise<void>)([1, 2, 3]);
|
|
104
|
+
expect(roborockService.setSelectedAreas).toHaveBeenCalledWith(duid, [1, 2, 3]);
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
it('should call pauseClean', async () => {
|
|
108
|
+
setDefaultCommandHandler(duid, handler, logger, roborockService, cleanModeSettings);
|
|
109
|
+
const [[, pauseHandler]] = (handler.setCommandHandler as jest.Mock).mock.calls.filter(([cmd]) => cmd === 'pause');
|
|
110
|
+
await (pauseHandler as () => Promise<void>)();
|
|
111
|
+
expect(roborockService.pauseClean).toHaveBeenCalledWith(duid);
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
it('should call resumeClean', async () => {
|
|
115
|
+
setDefaultCommandHandler(duid, handler, logger, roborockService, cleanModeSettings);
|
|
116
|
+
const [[, resumeHandler]] = (handler.setCommandHandler as jest.Mock).mock.calls.filter(([cmd]) => cmd === 'resume');
|
|
117
|
+
await (resumeHandler as () => Promise<void>)();
|
|
118
|
+
expect(roborockService.resumeClean).toHaveBeenCalledWith(duid);
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
it('should call stopAndGoHome', async () => {
|
|
122
|
+
setDefaultCommandHandler(duid, handler, logger, roborockService, cleanModeSettings);
|
|
123
|
+
const [[, goHomeHandler]] = (handler.setCommandHandler as jest.Mock).mock.calls.filter(([cmd]) => cmd === 'goHome');
|
|
124
|
+
await (goHomeHandler as () => Promise<void>)();
|
|
125
|
+
expect(roborockService.stopAndGoHome).toHaveBeenCalledWith(duid);
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
it('should call playSoundToLocate', async () => {
|
|
129
|
+
setDefaultCommandHandler(duid, handler, logger, roborockService, cleanModeSettings);
|
|
130
|
+
const [[, playSoundHandler]] = (handler.setCommandHandler as jest.Mock).mock.calls.filter(([cmd]) => cmd === 'playSoundToLocate');
|
|
131
|
+
await (playSoundHandler as (arg: number) => Promise<void>)(1);
|
|
132
|
+
expect(roborockService.playSoundToLocate).toHaveBeenCalledWith(duid);
|
|
133
|
+
});
|
|
134
|
+
});
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { getCurrentCleanModeSmart } from '../../../../behaviors/roborock.vacuum/smart/runtimes';
|
|
2
|
+
import { MopWaterFlowSmart, VacuumSuctionPowerSmart } from '../../../../behaviors/roborock.vacuum/smart/smart';
|
|
3
|
+
|
|
4
|
+
describe('getCurrentCleanModeSmart', () => {
|
|
5
|
+
it('returns undefined if input is undefined', () => {
|
|
6
|
+
expect(getCurrentCleanModeSmart(undefined as any)).toBeUndefined();
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
it('returns the correct key if an exact CleanSetting match exists', () => {
|
|
10
|
+
// Exact match for 'Vac & Mop Default' (key 5)
|
|
11
|
+
expect(
|
|
12
|
+
getCurrentCleanModeSmart({
|
|
13
|
+
suctionPower: VacuumSuctionPowerSmart.Balanced,
|
|
14
|
+
waterFlow: MopWaterFlowSmart.Medium,
|
|
15
|
+
distance_off: 0,
|
|
16
|
+
mopRoute: 300,
|
|
17
|
+
}),
|
|
18
|
+
).toBe(5);
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
it('returns 12 for MopMax', () => {
|
|
22
|
+
expect(
|
|
23
|
+
getCurrentCleanModeSmart({
|
|
24
|
+
suctionPower: VacuumSuctionPowerSmart.Off,
|
|
25
|
+
waterFlow: MopWaterFlowSmart.High,
|
|
26
|
+
distance_off: 0,
|
|
27
|
+
mopRoute: 300,
|
|
28
|
+
}),
|
|
29
|
+
).toBe(32);
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
it('returns 16 for Vacuum Default if waterFlow is Off', () => {
|
|
33
|
+
expect(
|
|
34
|
+
getCurrentCleanModeSmart({
|
|
35
|
+
suctionPower: VacuumSuctionPowerSmart.Balanced,
|
|
36
|
+
waterFlow: MopWaterFlowSmart.Off,
|
|
37
|
+
distance_off: 0,
|
|
38
|
+
mopRoute: 300,
|
|
39
|
+
}),
|
|
40
|
+
).toBe(66);
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it('returns 5 for Vac & Mop Default if neither suctionPower nor waterFlow is Off', () => {
|
|
44
|
+
expect(
|
|
45
|
+
getCurrentCleanModeSmart({
|
|
46
|
+
suctionPower: VacuumSuctionPowerSmart.Balanced,
|
|
47
|
+
waterFlow: MopWaterFlowSmart.Medium,
|
|
48
|
+
distance_off: 1,
|
|
49
|
+
mopRoute: 300,
|
|
50
|
+
}),
|
|
51
|
+
).toBe(5);
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
it('returns undefined if no match and no fallback applies', () => {
|
|
55
|
+
expect(
|
|
56
|
+
getCurrentCleanModeSmart({
|
|
57
|
+
suctionPower: 999,
|
|
58
|
+
waterFlow: 999,
|
|
59
|
+
distance_off: 999,
|
|
60
|
+
mopRoute: 999,
|
|
61
|
+
}),
|
|
62
|
+
).toBe(5);
|
|
63
|
+
});
|
|
64
|
+
});
|
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
import { setCommandHandlerSmart, VacuumSuctionPowerSmart, MopWaterFlowSmart, MopRouteSmart } from '../../../../behaviors/roborock.vacuum/smart/smart';
|
|
2
|
+
import { BehaviorDeviceGeneric } from '../../../../behaviors/BehaviorDeviceGeneric';
|
|
3
|
+
import { AnsiLogger } from 'matterbridge/logger';
|
|
4
|
+
import RoborockService from '../../../../roborockService';
|
|
5
|
+
import { CleanModeSettings } from '../../../../model/ExperimentalFeatureSetting';
|
|
6
|
+
|
|
7
|
+
describe('setCommandHandlerSmart', () => {
|
|
8
|
+
let handler: BehaviorDeviceGeneric<any>;
|
|
9
|
+
let logger: AnsiLogger;
|
|
10
|
+
let roborockService: jest.Mocked<RoborockService>;
|
|
11
|
+
let cleanModeSettings: CleanModeSettings;
|
|
12
|
+
const duid = 'test-duid';
|
|
13
|
+
|
|
14
|
+
beforeEach(() => {
|
|
15
|
+
handler = {
|
|
16
|
+
setCommandHandler: jest.fn(),
|
|
17
|
+
} as any;
|
|
18
|
+
|
|
19
|
+
logger = {
|
|
20
|
+
notice: jest.fn(),
|
|
21
|
+
warn: jest.fn(),
|
|
22
|
+
} as any;
|
|
23
|
+
|
|
24
|
+
roborockService = {
|
|
25
|
+
startClean: jest.fn(),
|
|
26
|
+
changeCleanMode: jest.fn(),
|
|
27
|
+
setSelectedAreas: jest.fn(),
|
|
28
|
+
pauseClean: jest.fn(),
|
|
29
|
+
resumeClean: jest.fn(),
|
|
30
|
+
stopAndGoHome: jest.fn(),
|
|
31
|
+
playSoundToLocate: jest.fn(),
|
|
32
|
+
} as any;
|
|
33
|
+
|
|
34
|
+
cleanModeSettings = {
|
|
35
|
+
vacuuming: { fanMode: 'Max', mopRouteMode: 'DeepPlus' },
|
|
36
|
+
mopping: { waterFlowMode: 'High', mopRouteMode: 'Fast', distanceOff: 25 },
|
|
37
|
+
vacmop: {
|
|
38
|
+
fanMode: 'Turbo',
|
|
39
|
+
waterFlowMode: 'Low',
|
|
40
|
+
mopRouteMode: 'Deep',
|
|
41
|
+
distanceOff: 25,
|
|
42
|
+
},
|
|
43
|
+
enableCleanModeMapping: true,
|
|
44
|
+
};
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
it('should set all command handlers', () => {
|
|
48
|
+
setCommandHandlerSmart(duid, handler, logger, roborockService, cleanModeSettings);
|
|
49
|
+
expect(handler.setCommandHandler).toHaveBeenCalledWith('changeToMode', expect.any(Function));
|
|
50
|
+
expect(handler.setCommandHandler).toHaveBeenCalledWith('selectAreas', expect.any(Function));
|
|
51
|
+
expect(handler.setCommandHandler).toHaveBeenCalledWith('pause', expect.any(Function));
|
|
52
|
+
expect(handler.setCommandHandler).toHaveBeenCalledWith('resume', expect.any(Function));
|
|
53
|
+
expect(handler.setCommandHandler).toHaveBeenCalledWith('goHome', expect.any(Function));
|
|
54
|
+
expect(handler.setCommandHandler).toHaveBeenCalledWith('playSoundToLocate', expect.any(Function));
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
it('should call startClean for Cleaning mode', async () => {
|
|
58
|
+
setCommandHandlerSmart(duid, handler, logger, roborockService, cleanModeSettings);
|
|
59
|
+
const [[, changeToModeHandler]] = (handler.setCommandHandler as jest.Mock).mock.calls.filter(([cmd]) => cmd === 'changeToMode');
|
|
60
|
+
await (changeToModeHandler as (mode: number) => Promise<void>)(2); // 2 = Cleaning
|
|
61
|
+
expect(roborockService.startClean).toHaveBeenCalledWith(duid);
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
it('should call changeCleanMode for Smart Plan', async () => {
|
|
65
|
+
setCommandHandlerSmart(duid, handler, logger, roborockService, cleanModeSettings);
|
|
66
|
+
const [[, changeToModeHandler]] = (handler.setCommandHandler as jest.Mock).mock.calls.filter(([cmd]) => cmd === 'changeToMode');
|
|
67
|
+
await (changeToModeHandler as (mode: number) => Promise<void>)(4); // 4 = Smart Plan
|
|
68
|
+
expect(roborockService.changeCleanMode).toHaveBeenCalledWith(duid, {
|
|
69
|
+
suctionPower: 0,
|
|
70
|
+
waterFlow: 0,
|
|
71
|
+
distance_off: 0,
|
|
72
|
+
mopRoute: MopRouteSmart.Smart,
|
|
73
|
+
});
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
it('should call changeCleanMode for Mop with correct values', async () => {
|
|
77
|
+
setCommandHandlerSmart(duid, handler, logger, roborockService, undefined);
|
|
78
|
+
const [[, changeToModeHandler]] = (handler.setCommandHandler as jest.Mock).mock.calls.filter(([cmd]) => cmd === 'changeToMode');
|
|
79
|
+
await (changeToModeHandler as (mode: number) => Promise<void>)(31); // 31 = Mop Default
|
|
80
|
+
// mopping: { waterFlowMode: 'High', mopRouteMode: 'Fast', distanceOff: 85 },
|
|
81
|
+
expect(roborockService.changeCleanMode).toHaveBeenCalledWith(duid, {
|
|
82
|
+
suctionPower: VacuumSuctionPowerSmart.Off,
|
|
83
|
+
waterFlow: MopWaterFlowSmart.Medium,
|
|
84
|
+
mopRoute: MopRouteSmart.Standard,
|
|
85
|
+
distance_off: 0,
|
|
86
|
+
});
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
it('should call changeCleanMode for Mop with custom values', async () => {
|
|
90
|
+
setCommandHandlerSmart(duid, handler, logger, roborockService, {
|
|
91
|
+
vacuuming: { fanMode: 'Max', mopRouteMode: 'DeepPlus' },
|
|
92
|
+
mopping: { waterFlowMode: 'CustomizeWithDistanceOff', mopRouteMode: 'Fast', distanceOff: 25 },
|
|
93
|
+
vacmop: {
|
|
94
|
+
fanMode: 'Turbo',
|
|
95
|
+
waterFlowMode: 'Low',
|
|
96
|
+
mopRouteMode: 'Deep',
|
|
97
|
+
distanceOff: 25,
|
|
98
|
+
},
|
|
99
|
+
enableCleanModeMapping: true,
|
|
100
|
+
});
|
|
101
|
+
const [[, changeToModeHandler]] = (handler.setCommandHandler as jest.Mock).mock.calls.filter(([cmd]) => cmd === 'changeToMode');
|
|
102
|
+
await (changeToModeHandler as (mode: number) => Promise<void>)(31); // 31 = Mop Default
|
|
103
|
+
// vacuuming: { fanMode: 'Max', mopRouteMode: 'DeepPlus' },
|
|
104
|
+
expect(roborockService.changeCleanMode).toHaveBeenCalledWith(duid, {
|
|
105
|
+
suctionPower: VacuumSuctionPowerSmart.Off,
|
|
106
|
+
waterFlow: MopWaterFlowSmart.CustomizeWithDistanceOff,
|
|
107
|
+
mopRoute: MopRouteSmart.Fast,
|
|
108
|
+
distance_off: 85,
|
|
109
|
+
});
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
it('should call changeCleanMode for Vacuum with correct values', async () => {
|
|
113
|
+
setCommandHandlerSmart(duid, handler, logger, roborockService, undefined);
|
|
114
|
+
const [[, changeToModeHandler]] = (handler.setCommandHandler as jest.Mock).mock.calls.filter(([cmd]) => cmd === 'changeToMode');
|
|
115
|
+
await (changeToModeHandler as (mode: number) => Promise<void>)(66); // 66 = Vacuum Default
|
|
116
|
+
// vacuuming: { fanMode: 'Max', mopRouteMode: 'DeepPlus' },
|
|
117
|
+
expect(roborockService.changeCleanMode).toHaveBeenCalledWith(duid, {
|
|
118
|
+
suctionPower: VacuumSuctionPowerSmart.Balanced,
|
|
119
|
+
waterFlow: MopWaterFlowSmart.Off,
|
|
120
|
+
mopRoute: MopRouteSmart.Standard,
|
|
121
|
+
distance_off: 0,
|
|
122
|
+
});
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
it('should call changeCleanMode for Vacuum with custom values', async () => {
|
|
126
|
+
setCommandHandlerSmart(duid, handler, logger, roborockService, cleanModeSettings);
|
|
127
|
+
const [[, changeToModeHandler]] = (handler.setCommandHandler as jest.Mock).mock.calls.filter(([cmd]) => cmd === 'changeToMode');
|
|
128
|
+
await (changeToModeHandler as (mode: number) => Promise<void>)(66); // 66 = Vacuum Default
|
|
129
|
+
// vacuuming: { fanMode: 'Max', mopRouteMode: 'DeepPlus' },
|
|
130
|
+
expect(roborockService.changeCleanMode).toHaveBeenCalledWith(duid, {
|
|
131
|
+
suctionPower: VacuumSuctionPowerSmart.Max,
|
|
132
|
+
waterFlow: MopWaterFlowSmart.Off,
|
|
133
|
+
mopRoute: MopRouteSmart.DeepPlus,
|
|
134
|
+
distance_off: 0,
|
|
135
|
+
});
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
it('should call changeCleanMode for Vac & Mop with correct values', async () => {
|
|
139
|
+
setCommandHandlerSmart(duid, handler, logger, roborockService, undefined);
|
|
140
|
+
const [[, changeToModeHandler]] = (handler.setCommandHandler as jest.Mock).mock.calls.filter(([cmd]) => cmd === 'changeToMode');
|
|
141
|
+
await (changeToModeHandler as (mode: number) => Promise<void>)(5); // 5 = Vac & Mop Default
|
|
142
|
+
/*
|
|
143
|
+
vacmop: {
|
|
144
|
+
fanMode: 'Turbo',
|
|
145
|
+
waterFlowMode: 'Low',
|
|
146
|
+
mopRouteMode: 'Deep',
|
|
147
|
+
distanceOff: 85,
|
|
148
|
+
},
|
|
149
|
+
*/
|
|
150
|
+
|
|
151
|
+
expect(roborockService.changeCleanMode).toHaveBeenCalledWith(duid, {
|
|
152
|
+
suctionPower: VacuumSuctionPowerSmart.Balanced,
|
|
153
|
+
waterFlow: MopWaterFlowSmart.Medium,
|
|
154
|
+
mopRoute: MopRouteSmart.Standard,
|
|
155
|
+
distance_off: 0,
|
|
156
|
+
});
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
it('should call changeCleanMode for Vac & Mop with custom values', async () => {
|
|
160
|
+
setCommandHandlerSmart(duid, handler, logger, roborockService, {
|
|
161
|
+
vacuuming: { fanMode: 'Max', mopRouteMode: 'DeepPlus' },
|
|
162
|
+
mopping: { waterFlowMode: 'CustomizeWithDistanceOff', mopRouteMode: 'Fast', distanceOff: 25 },
|
|
163
|
+
vacmop: {
|
|
164
|
+
fanMode: 'Turbo',
|
|
165
|
+
waterFlowMode: 'CustomizeWithDistanceOff',
|
|
166
|
+
mopRouteMode: 'Deep',
|
|
167
|
+
distanceOff: 25,
|
|
168
|
+
},
|
|
169
|
+
enableCleanModeMapping: true,
|
|
170
|
+
});
|
|
171
|
+
const [[, changeToModeHandler]] = (handler.setCommandHandler as jest.Mock).mock.calls.filter(([cmd]) => cmd === 'changeToMode');
|
|
172
|
+
await (changeToModeHandler as (mode: number) => Promise<void>)(5); // 5 = Vac & Mop Default
|
|
173
|
+
expect(roborockService.changeCleanMode).toHaveBeenCalledWith(duid, {
|
|
174
|
+
suctionPower: VacuumSuctionPowerSmart.Turbo,
|
|
175
|
+
waterFlow: MopWaterFlowSmart.CustomizeWithDistanceOff,
|
|
176
|
+
mopRoute: MopRouteSmart.Deep,
|
|
177
|
+
distance_off: 85,
|
|
178
|
+
});
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
it('should call setSelectedAreas', async () => {
|
|
182
|
+
setCommandHandlerSmart(duid, handler, logger, roborockService, cleanModeSettings);
|
|
183
|
+
const [[, selectAreasHandler]] = (handler.setCommandHandler as jest.Mock).mock.calls.filter(([cmd]) => cmd === 'selectAreas');
|
|
184
|
+
await (selectAreasHandler as (areas: number[]) => Promise<void>)([1, 2, 3]);
|
|
185
|
+
expect(roborockService.setSelectedAreas).toHaveBeenCalledWith(duid, [1, 2, 3]);
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
it('should call pauseClean', async () => {
|
|
189
|
+
setCommandHandlerSmart(duid, handler, logger, roborockService, cleanModeSettings);
|
|
190
|
+
const [[, pauseHandler]] = (handler.setCommandHandler as jest.Mock).mock.calls.filter(([cmd]) => cmd === 'pause');
|
|
191
|
+
await (pauseHandler as () => Promise<void>)();
|
|
192
|
+
expect(roborockService.pauseClean).toHaveBeenCalledWith(duid);
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
it('should call resumeClean', async () => {
|
|
196
|
+
setCommandHandlerSmart(duid, handler, logger, roborockService, cleanModeSettings);
|
|
197
|
+
const [[, resumeHandler]] = (handler.setCommandHandler as jest.Mock).mock.calls.filter(([cmd]) => cmd === 'resume');
|
|
198
|
+
await (resumeHandler as () => Promise<void>)();
|
|
199
|
+
expect(roborockService.resumeClean).toHaveBeenCalledWith(duid);
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
it('should call stopAndGoHome', async () => {
|
|
203
|
+
setCommandHandlerSmart(duid, handler, logger, roborockService, cleanModeSettings);
|
|
204
|
+
const [[, goHomeHandler]] = (handler.setCommandHandler as jest.Mock).mock.calls.filter(([cmd]) => cmd === 'goHome');
|
|
205
|
+
await (goHomeHandler as () => Promise<void>)();
|
|
206
|
+
expect(roborockService.stopAndGoHome).toHaveBeenCalledWith(duid);
|
|
207
|
+
});
|
|
208
|
+
|
|
209
|
+
it('should call playSoundToLocate', async () => {
|
|
210
|
+
setCommandHandlerSmart(duid, handler, logger, roborockService, cleanModeSettings);
|
|
211
|
+
const [[, playSoundHandler]] = (handler.setCommandHandler as jest.Mock).mock.calls.filter(([cmd]) => cmd === 'playSoundToLocate');
|
|
212
|
+
await (playSoundHandler as (arg: number) => Promise<void>)(1);
|
|
213
|
+
expect(roborockService.playSoundToLocate).toHaveBeenCalledWith(duid);
|
|
214
|
+
});
|
|
215
|
+
});
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
import { getRoomMapFromDevice } from '../helper';
|
|
2
|
+
import { RoomMap } from '../model/RoomMap';
|
|
3
|
+
|
|
4
|
+
const mockLog = {
|
|
5
|
+
notice: jest.fn(),
|
|
6
|
+
error: jest.fn(),
|
|
7
|
+
debug: jest.fn(),
|
|
8
|
+
info: jest.fn(),
|
|
9
|
+
warn: jest.fn(),
|
|
10
|
+
verbose: jest.fn(),
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
const mockRoborockService = {
|
|
14
|
+
getRoomMappings: jest.fn(),
|
|
15
|
+
getMapInformation: jest.fn(),
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
const mockPlatform = {
|
|
19
|
+
log: mockLog,
|
|
20
|
+
roborockService: mockRoborockService,
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
describe('getRoomMapFromDevice', () => {
|
|
24
|
+
beforeEach(() => {
|
|
25
|
+
jest.clearAllMocks();
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
it('returns RoomMap from getRoomMappings if available', async () => {
|
|
29
|
+
const device = {
|
|
30
|
+
duid: '123',
|
|
31
|
+
rooms: [
|
|
32
|
+
{
|
|
33
|
+
'id': 12461114,
|
|
34
|
+
'name': 'Guest bedroom',
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
'id': 12461111,
|
|
38
|
+
'name': 'Balcony',
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
'id': 12461109,
|
|
42
|
+
'name': 'Master bedroom',
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
'id': 11100849,
|
|
46
|
+
'name': 'Study',
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
'id': 11100847,
|
|
50
|
+
'name': 'Bedroom',
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
'id': 11100845,
|
|
54
|
+
'name': 'Kitchen',
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
'id': 11100842,
|
|
58
|
+
'name': 'Living room',
|
|
59
|
+
},
|
|
60
|
+
],
|
|
61
|
+
};
|
|
62
|
+
mockRoborockService.getRoomMappings.mockResolvedValue([
|
|
63
|
+
[1, '11100842', 6],
|
|
64
|
+
[2, '12461114', 3],
|
|
65
|
+
[3, '12461109', 2],
|
|
66
|
+
[4, '12461111', 7],
|
|
67
|
+
]);
|
|
68
|
+
mockRoborockService.getMapInformation.mockResolvedValue(undefined);
|
|
69
|
+
|
|
70
|
+
const result = await getRoomMapFromDevice(device as any, mockPlatform as any);
|
|
71
|
+
|
|
72
|
+
// console.log('Result:', result);
|
|
73
|
+
expect(result).toBeInstanceOf(RoomMap);
|
|
74
|
+
expect(mockRoborockService.getRoomMappings).toHaveBeenCalledWith('123');
|
|
75
|
+
expect(result.rooms.length).toBeGreaterThan(0);
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
it('returns RoomMap from getRoomMappings if available', async () => {
|
|
79
|
+
const device = {
|
|
80
|
+
duid: '123',
|
|
81
|
+
rooms: [
|
|
82
|
+
{ id: 1, name: 'Kitchen' },
|
|
83
|
+
{ id: 2, name: 'Study' },
|
|
84
|
+
{ id: 3, name: 'Living room' },
|
|
85
|
+
{ id: 4, name: 'Bedroom' },
|
|
86
|
+
],
|
|
87
|
+
};
|
|
88
|
+
mockRoborockService.getRoomMappings.mockResolvedValue([
|
|
89
|
+
[1, '11100845', 14],
|
|
90
|
+
[2, '11100849', 9],
|
|
91
|
+
[3, '11100842', 6],
|
|
92
|
+
[4, '11100847', 1],
|
|
93
|
+
]);
|
|
94
|
+
mockRoborockService.getMapInformation.mockResolvedValue(undefined);
|
|
95
|
+
|
|
96
|
+
const result = await getRoomMapFromDevice(device as any, mockPlatform as any);
|
|
97
|
+
|
|
98
|
+
// console.log('Result:', result);
|
|
99
|
+
expect(result).toBeInstanceOf(RoomMap);
|
|
100
|
+
expect(mockRoborockService.getRoomMappings).toHaveBeenCalledWith('123');
|
|
101
|
+
expect(result.rooms.length).toBeGreaterThan(0);
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
it('returns RoomMap from getMapInformation if available', async () => {
|
|
105
|
+
const device = {
|
|
106
|
+
duid: '123',
|
|
107
|
+
rooms: [
|
|
108
|
+
{ id: 11100845, name: 'Kitchen' },
|
|
109
|
+
{ id: 11100849, name: 'Study' },
|
|
110
|
+
{ id: 11100842, name: 'Living room' },
|
|
111
|
+
{ id: 11100847, name: 'Bedroom' },
|
|
112
|
+
{ id: 12469150, name: 'Dining room' },
|
|
113
|
+
{ id: 12461114, name: 'Guest bedroom' },
|
|
114
|
+
{ id: 12461109, name: 'Master bedroom' },
|
|
115
|
+
{ id: 12461111, name: 'Balcony' },
|
|
116
|
+
{ id: 11100842, name: 'Living room' },
|
|
117
|
+
],
|
|
118
|
+
};
|
|
119
|
+
mockRoborockService.getRoomMappings.mockResolvedValue(undefined);
|
|
120
|
+
mockRoborockService.getMapInformation.mockResolvedValue({
|
|
121
|
+
maps: [
|
|
122
|
+
{
|
|
123
|
+
id: 0,
|
|
124
|
+
name: 'First Map',
|
|
125
|
+
rooms: [
|
|
126
|
+
{ id: 1, globalId: 11100845, iot_name_id: '11100845', tag: 14, displayName: 'Kitchen', mapId: 0 },
|
|
127
|
+
{ id: 2, globalId: 11100849, iot_name_id: '11100849', tag: 9, displayName: 'Study', mapId: 0 },
|
|
128
|
+
{ id: 3, globalId: 11100842, iot_name_id: '11100842', tag: 6, displayName: 'Living room', mapId: 0 },
|
|
129
|
+
{ id: 4, globalId: 11100847, iot_name_id: '11100847', tag: 1, displayName: 'Bedroom', mapId: 0 },
|
|
130
|
+
],
|
|
131
|
+
},
|
|
132
|
+
{
|
|
133
|
+
id: 1,
|
|
134
|
+
name: 'Second Map',
|
|
135
|
+
rooms: [
|
|
136
|
+
{ id: 1, globalId: 12469150, iot_name_id: '12469150', tag: 13, displayName: 'Dining room', mapId: 1 },
|
|
137
|
+
{ id: 2, globalId: 12461114, iot_name_id: '12461114', tag: 3, displayName: 'Guest bedroom', mapId: 1 },
|
|
138
|
+
{ id: 3, globalId: 12461109, iot_name_id: '12461109', tag: 2, displayName: 'Master bedroom', mapId: 1 },
|
|
139
|
+
{ id: 4, globalId: 12461111, iot_name_id: '12461111', tag: 7, displayName: 'Balcony', mapId: 1 },
|
|
140
|
+
{ id: 5, globalId: 11100842, iot_name_id: '11100842', tag: 6, displayName: 'Living room', mapId: 1 },
|
|
141
|
+
],
|
|
142
|
+
},
|
|
143
|
+
],
|
|
144
|
+
allRooms: [
|
|
145
|
+
{ id: 1, globalId: 11100845, iot_name_id: '11100845', tag: 14, displayName: 'Kitchen', mapId: 0 },
|
|
146
|
+
{ id: 2, globalId: 11100849, iot_name_id: '11100849', tag: 9, displayName: 'Study', mapId: 0 },
|
|
147
|
+
{ id: 3, globalId: 11100842, iot_name_id: '11100842', tag: 6, displayName: 'Living room', mapId: 0 },
|
|
148
|
+
{ id: 4, globalId: 11100847, iot_name_id: '11100847', tag: 1, displayName: 'Bedroom', mapId: 0 },
|
|
149
|
+
{ id: 1, globalId: 12469150, iot_name_id: '12469150', tag: 13, displayName: 'Dining room', mapId: 1 },
|
|
150
|
+
{ id: 2, globalId: 12461114, iot_name_id: '12461114', tag: 3, displayName: 'Guest bedroom', mapId: 1 },
|
|
151
|
+
{ id: 3, globalId: 12461109, iot_name_id: '12461109', tag: 2, displayName: 'Master bedroom', mapId: 1 },
|
|
152
|
+
{ id: 4, globalId: 12461111, iot_name_id: '12461111', tag: 7, displayName: 'Balcony', mapId: 1 },
|
|
153
|
+
{ id: 5, globalId: 11100842, iot_name_id: '11100842', tag: 6, displayName: 'Living room', mapId: 1 },
|
|
154
|
+
],
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
const result = await getRoomMapFromDevice(device as any, mockPlatform as any);
|
|
158
|
+
expect(result).toBeInstanceOf(RoomMap);
|
|
159
|
+
expect(mockRoborockService.getMapInformation).toHaveBeenCalledWith('123');
|
|
160
|
+
expect(result.rooms.length).toBeGreaterThan(0);
|
|
161
|
+
});
|
|
162
|
+
});
|