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,101 @@
|
|
|
1
|
+
import { RequestMessage } from '../broadcast/model/requestMessage.js';
|
|
2
|
+
import * as CryptoUtils from './cryptoHelper.js';
|
|
3
|
+
import crypto from 'node:crypto';
|
|
4
|
+
import CRC32 from 'crc-32';
|
|
5
|
+
import { DpsPayload, Payload } from '../broadcast/model/dps.js';
|
|
6
|
+
import { MessageContext } from '../broadcast/model/messageContext.js';
|
|
7
|
+
import { AnsiLogger } from 'matterbridge/logger';
|
|
8
|
+
import { Protocol } from '../broadcast/model/protocol.js';
|
|
9
|
+
|
|
10
|
+
interface SerializeResult {
|
|
11
|
+
messageId: number;
|
|
12
|
+
buffer: Buffer<ArrayBufferLike>;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export class MessageSerializer {
|
|
16
|
+
private readonly context: MessageContext;
|
|
17
|
+
private readonly logger: AnsiLogger;
|
|
18
|
+
private sequence = 1;
|
|
19
|
+
private readonly supportedVersions: string[] = ['1.0', 'A01', 'B01'];
|
|
20
|
+
|
|
21
|
+
constructor(context: MessageContext, logger: AnsiLogger) {
|
|
22
|
+
this.context = context;
|
|
23
|
+
this.logger = logger;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
public serialize(duid: string, request: RequestMessage): SerializeResult {
|
|
27
|
+
const messageId = request.messageId;
|
|
28
|
+
const buffer = this.buildBuffer(duid, messageId, request);
|
|
29
|
+
return { messageId: messageId, buffer: buffer };
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
private buildPayload(messageId: number, request: RequestMessage): Payload {
|
|
33
|
+
const data: DpsPayload = {
|
|
34
|
+
id: messageId,
|
|
35
|
+
method: request.method ?? '',
|
|
36
|
+
params: request.params,
|
|
37
|
+
security: undefined,
|
|
38
|
+
result: undefined,
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
if (request.secure) {
|
|
42
|
+
data.security = {
|
|
43
|
+
endpoint: this.context.getEndpoint(),
|
|
44
|
+
nonce: this.context.getSerializeNonceAsHex(),
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
return {
|
|
48
|
+
dps: {
|
|
49
|
+
[request.protocol]: JSON.stringify(data),
|
|
50
|
+
},
|
|
51
|
+
t: request.timestamp,
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
private buildBuffer(duid: string, messageId: number, request: RequestMessage): Buffer<ArrayBufferLike> {
|
|
56
|
+
const version = this.context.getProtocolVersion(duid);
|
|
57
|
+
if (!version || !this.supportedVersions.includes(version)) {
|
|
58
|
+
throw new Error('unknown protocol version ' + version);
|
|
59
|
+
}
|
|
60
|
+
let encrypted;
|
|
61
|
+
if (request.protocol === Protocol.hello_response || request.protocol === Protocol.ping_response) {
|
|
62
|
+
encrypted = Buffer.alloc(0);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const localKey = this.context.getLocalKey(duid);
|
|
66
|
+
const payloadData = this.buildPayload(messageId, request);
|
|
67
|
+
const payload = JSON.stringify(payloadData);
|
|
68
|
+
|
|
69
|
+
if (version == '1.0') {
|
|
70
|
+
const aesKey = CryptoUtils.md5bin(CryptoUtils.encodeTimestamp(payloadData.t) + localKey + CryptoUtils.SALT);
|
|
71
|
+
const cipher = crypto.createCipheriv('aes-128-ecb', aesKey, null);
|
|
72
|
+
encrypted = Buffer.concat([cipher.update(payload), cipher.final()]);
|
|
73
|
+
} else if (version == 'A01') {
|
|
74
|
+
// 726f626f726f636b2d67a6d6da is in version 4.0 of the roborock app
|
|
75
|
+
const encoder = new TextEncoder();
|
|
76
|
+
const iv = CryptoUtils.md5hex(request.nonce.toString(16).padStart(8, '0') + '726f626f726f636b2d67a6d6da').substring(8, 24);
|
|
77
|
+
const cipher = crypto.createCipheriv('aes-128-cbc', encoder.encode(localKey), iv);
|
|
78
|
+
encrypted = Buffer.concat([cipher.update(payload), cipher.final()]);
|
|
79
|
+
} else if (version == 'B01') {
|
|
80
|
+
const encoder = new TextEncoder();
|
|
81
|
+
const iv = CryptoUtils.md5hex(request.nonce.toString(16).padStart(8, '0') + '5wwh9ikChRjASpMU8cxg7o1d2E').substring(9, 25);
|
|
82
|
+
const cipher = crypto.createCipheriv('aes-128-cbc', encoder.encode(localKey), iv);
|
|
83
|
+
// pad ??
|
|
84
|
+
encrypted = Buffer.concat([cipher.update(payload), cipher.final()]);
|
|
85
|
+
} else {
|
|
86
|
+
throw new Error('unable to build the message: unsupported protocol version: ' + version);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
const msg = Buffer.alloc(23 + encrypted.length);
|
|
90
|
+
msg.write(version);
|
|
91
|
+
msg.writeUint32BE(this.sequence++ & 0xffffffff, 3);
|
|
92
|
+
msg.writeUint32BE(request.nonce & 0xffffffff, 7);
|
|
93
|
+
msg.writeUint32BE(request.timestamp, 11);
|
|
94
|
+
msg.writeUint16BE(request.protocol, 15);
|
|
95
|
+
msg.writeUint16BE(encrypted.length, 17);
|
|
96
|
+
encrypted.copy(msg, 19);
|
|
97
|
+
const crc32 = CRC32.buf(msg.subarray(0, msg.length - 4)) >>> 0;
|
|
98
|
+
msg.writeUint32BE(crc32, msg.length - 4);
|
|
99
|
+
return msg;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
const token = '%[a-f0-9]{2}';
|
|
2
|
+
const singleMatcher = new RegExp('(' + token + ')|([^%]+?)', 'gi');
|
|
3
|
+
const multiMatcher = new RegExp('(' + token + ')+', 'gi');
|
|
4
|
+
|
|
5
|
+
function decodeComponents(components: RegExpMatchArray | string[] | [], split: number | undefined = undefined): string[] {
|
|
6
|
+
try {
|
|
7
|
+
return [decodeURIComponent(components.join(''))];
|
|
8
|
+
} catch {
|
|
9
|
+
// Do nothing
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
if (components.length === 1) {
|
|
13
|
+
return components;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
split = split || 1;
|
|
17
|
+
const left = components.slice(0, split);
|
|
18
|
+
const right = components.slice(split);
|
|
19
|
+
return Array.prototype.concat.call([], decodeComponents(left), decodeComponents(right));
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function decode(input: string) {
|
|
23
|
+
try {
|
|
24
|
+
return decodeURIComponent(input);
|
|
25
|
+
} catch {
|
|
26
|
+
let tokens = input.match(singleMatcher) || [];
|
|
27
|
+
|
|
28
|
+
for (let i = 1; i < tokens.length; i++) {
|
|
29
|
+
input = decodeComponents(tokens, i).join('');
|
|
30
|
+
|
|
31
|
+
tokens = input.match(singleMatcher) || [];
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
return input;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function customDecodeURIComponent(input: string): string {
|
|
39
|
+
const replaceMap: Record<string, string> = {
|
|
40
|
+
'%FE%FF': '\uFFFD\uFFFD',
|
|
41
|
+
'%FF%FE': '\uFFFD\uFFFD',
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
let match = multiMatcher.exec(input);
|
|
45
|
+
while (match) {
|
|
46
|
+
try {
|
|
47
|
+
replaceMap[match[0]] = decodeURIComponent(match[0]);
|
|
48
|
+
} catch {
|
|
49
|
+
const result = decode(match[0]);
|
|
50
|
+
|
|
51
|
+
if (result !== match[0]) {
|
|
52
|
+
replaceMap[match[0]] = result;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
match = multiMatcher.exec(input);
|
|
57
|
+
}
|
|
58
|
+
replaceMap['%C2'] = '\uFFFD';
|
|
59
|
+
|
|
60
|
+
const entries = Object.keys(replaceMap);
|
|
61
|
+
|
|
62
|
+
for (const key of entries) {
|
|
63
|
+
input = input.replace(new RegExp(key, 'g'), replaceMap[key]);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
return input;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export default function decodeComponent(encodedURI: string | undefined) {
|
|
70
|
+
if (encodedURI === undefined) {
|
|
71
|
+
return undefined;
|
|
72
|
+
}
|
|
73
|
+
try {
|
|
74
|
+
return decodeURIComponent(encodedURI);
|
|
75
|
+
} catch {
|
|
76
|
+
return customDecodeURIComponent(encodedURI);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export class Sequence {
|
|
2
|
+
private readonly min: number;
|
|
3
|
+
private readonly max: number;
|
|
4
|
+
private current: number;
|
|
5
|
+
|
|
6
|
+
constructor(min: number, max: number) {
|
|
7
|
+
this.min = min;
|
|
8
|
+
this.max = max;
|
|
9
|
+
this.current = min;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
next(): number {
|
|
13
|
+
if (this.current > this.max) {
|
|
14
|
+
this.current = this.min;
|
|
15
|
+
}
|
|
16
|
+
return this.current++;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export { RoborockAuthenticateApi } from './RESTAPI/roborockAuthenticateApi.js';
|
|
2
|
+
export { RoborockIoTApi } from './RESTAPI/roborockIoTApi.js';
|
|
3
|
+
export { MessageProcessor } from './broadcast/messageProcessor.js';
|
|
4
|
+
export { VacuumErrorCode } from './Zenum/vacuumAndDockErrorCode.js';
|
|
5
|
+
export { RequestMessage } from './broadcast/model/requestMessage.js';
|
|
6
|
+
export { Protocol } from './broadcast/model/protocol.js';
|
|
7
|
+
export { ClientRouter } from './broadcast/clientRouter.js';
|
|
8
|
+
export { DeviceStatus } from './Zmodel/deviceStatus.js';
|
|
9
|
+
export { ResponseMessage } from './broadcast/model/responseMessage.js';
|
|
10
|
+
export { MapInfo } from './Zmodel/mapInfo.js';
|
|
11
|
+
export { AdditionalPropCode } from './Zenum/additionalPropCode.js';
|
|
12
|
+
export { AuthenticateResponseCode } from './Zenum/authenticateResponseCode.js';
|
|
13
|
+
|
|
14
|
+
export { Scene } from './Zmodel/scene.js';
|
|
15
|
+
|
|
16
|
+
export type { AbstractMessageHandler } from './broadcast/listener/abstractMessageHandler.js';
|
|
17
|
+
export type { AbstractConnectionListener, AbstractMessageListener } from './broadcast/listener/index.js';
|
|
18
|
+
export type { UserData } from './Zmodel/userData.js';
|
|
19
|
+
export type { Device } from './Zmodel/device.js';
|
|
20
|
+
export type { Home } from './Zmodel/home.js';
|
|
21
|
+
export type { Client } from './broadcast/client.js';
|
|
22
|
+
export type { SceneParam } from './Zmodel/scene.js';
|
|
23
|
+
export type { BatteryMessage, DeviceErrorMessage, DeviceStatusNotify } from './Zmodel/batteryMessage.js';
|
|
24
|
+
export type { MultipleMap } from './Zmodel/multipleMap.js';
|
|
25
|
+
export type { AuthenticateFlowState } from './Zmodel/authenticateFlowState.js';
|