matterbridge-roborock-vacuum-plugin 1.1.0-rc08 → 1.1.0-rc09
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/dist/roborockCommunication/broadcast/abstractClient.js +4 -3
- package/dist/roborockCommunication/broadcast/client/LocalNetworkClient.js +3 -0
- package/dist/roborockCommunication/broadcast/client/MQTTClient.js +3 -0
- package/dist/roborockCommunication/broadcast/listener/implementation/connectionStateListener.js +12 -4
- package/matterbridge-roborock-vacuum-plugin.config.json +1 -1
- package/matterbridge-roborock-vacuum-plugin.schema.json +1 -1
- package/package.json +1 -1
- package/src/roborockCommunication/broadcast/abstractClient.ts +8 -5
- package/src/roborockCommunication/broadcast/client/LocalNetworkClient.ts +5 -0
- package/src/roborockCommunication/broadcast/client/MQTTClient.ts +5 -0
- package/src/roborockCommunication/broadcast/listener/implementation/connectionStateListener.ts +14 -4
|
@@ -14,17 +14,18 @@ export class AbstractClient {
|
|
|
14
14
|
logger;
|
|
15
15
|
context;
|
|
16
16
|
syncMessageListener;
|
|
17
|
-
connectionStateListener;
|
|
18
17
|
constructor(logger, context) {
|
|
19
18
|
this.context = context;
|
|
20
19
|
this.serializer = new MessageSerializer(this.context, logger);
|
|
21
20
|
this.deserializer = new MessageDeserializer(this.context, logger);
|
|
22
21
|
this.syncMessageListener = new SyncMessageListener(logger);
|
|
23
22
|
this.messageListeners.register(this.syncMessageListener);
|
|
24
|
-
this.connectionStateListener = new ConnectionStateListener(logger, this);
|
|
25
|
-
this.connectionListeners.register(this.connectionStateListener);
|
|
26
23
|
this.logger = logger;
|
|
27
24
|
}
|
|
25
|
+
initializeConnectionStateListener() {
|
|
26
|
+
const connectionStateListener = new ConnectionStateListener(this.logger, this, this.clientName, this.shouldReconnect);
|
|
27
|
+
this.connectionListeners.register(connectionStateListener);
|
|
28
|
+
}
|
|
28
29
|
async get(duid, request) {
|
|
29
30
|
return new Promise((resolve, reject) => {
|
|
30
31
|
this.syncMessageListener.waitFor(request.messageId, (response) => resolve(response), reject);
|
|
@@ -7,6 +7,8 @@ import { AbstractClient } from '../abstractClient.js';
|
|
|
7
7
|
import { Sequence } from '../../helper/sequence.js';
|
|
8
8
|
import { ChunkBuffer } from '../../helper/chunkBuffer.js';
|
|
9
9
|
export class LocalNetworkClient extends AbstractClient {
|
|
10
|
+
clientName = 'LocalNetworkClient';
|
|
11
|
+
shouldReconnect = true;
|
|
10
12
|
socket = undefined;
|
|
11
13
|
buffer = new ChunkBuffer();
|
|
12
14
|
messageIdSeq;
|
|
@@ -18,6 +20,7 @@ export class LocalNetworkClient extends AbstractClient {
|
|
|
18
20
|
this.duid = duid;
|
|
19
21
|
this.ip = ip;
|
|
20
22
|
this.messageIdSeq = new Sequence(100000, 999999);
|
|
23
|
+
this.initializeConnectionStateListener();
|
|
21
24
|
}
|
|
22
25
|
connect() {
|
|
23
26
|
this.socket = new Socket();
|
|
@@ -3,6 +3,8 @@ import * as CryptoUtils from '../../helper/cryptoHelper.js';
|
|
|
3
3
|
import { AbstractClient } from '../abstractClient.js';
|
|
4
4
|
import { debugStringify } from 'matterbridge/logger';
|
|
5
5
|
export class MQTTClient extends AbstractClient {
|
|
6
|
+
clientName = 'MQTTClient';
|
|
7
|
+
shouldReconnect = false;
|
|
6
8
|
rriot;
|
|
7
9
|
mqttUsername;
|
|
8
10
|
mqttPassword;
|
|
@@ -12,6 +14,7 @@ export class MQTTClient extends AbstractClient {
|
|
|
12
14
|
this.rriot = userdata.rriot;
|
|
13
15
|
this.mqttUsername = CryptoUtils.md5hex(userdata.rriot.u + ':' + userdata.rriot.k).substring(2, 10);
|
|
14
16
|
this.mqttPassword = CryptoUtils.md5hex(userdata.rriot.s + ':' + userdata.rriot.k).substring(16);
|
|
17
|
+
this.initializeConnectionStateListener();
|
|
15
18
|
}
|
|
16
19
|
connect() {
|
|
17
20
|
if (this.client) {
|
package/dist/roborockCommunication/broadcast/listener/implementation/connectionStateListener.js
CHANGED
|
@@ -1,21 +1,29 @@
|
|
|
1
1
|
export class ConnectionStateListener {
|
|
2
2
|
logger;
|
|
3
3
|
client;
|
|
4
|
-
|
|
4
|
+
clientName;
|
|
5
|
+
shouldReconnect;
|
|
6
|
+
constructor(logger, client, clientName, shouldReconnect = false) {
|
|
5
7
|
this.logger = logger;
|
|
6
8
|
this.client = client;
|
|
9
|
+
this.clientName = clientName;
|
|
10
|
+
this.shouldReconnect = shouldReconnect;
|
|
7
11
|
}
|
|
8
12
|
async onConnected(duid) {
|
|
9
|
-
this.logger.notice(`Device ${duid} connected to
|
|
13
|
+
this.logger.notice(`Device ${duid} connected to ${this.clientName}`);
|
|
10
14
|
}
|
|
11
15
|
async onDisconnected(duid) {
|
|
12
|
-
this.
|
|
16
|
+
if (!this.shouldReconnect) {
|
|
17
|
+
this.logger.notice(`Device ${duid} disconnected from ${this.clientName}, but re-registration is disabled.`);
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
this.logger.notice(`Device ${duid} disconnected from ${this.clientName}`);
|
|
13
21
|
const isInDisconnectingStep = this.client.isInDisconnectingStep;
|
|
14
22
|
if (isInDisconnectingStep) {
|
|
15
23
|
this.logger.info(`Device with DUID ${duid} is in disconnecting step, skipping re-registration.`);
|
|
16
24
|
return;
|
|
17
25
|
}
|
|
18
|
-
this.logger.info(`Re-registering device with DUID ${duid} to
|
|
26
|
+
this.logger.info(`Re-registering device with DUID ${duid} to ${this.clientName}`);
|
|
19
27
|
this.client.connect();
|
|
20
28
|
this.client.isInDisconnectingStep = false;
|
|
21
29
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"title": "Matterbridge Roborock Vacuum Plugin",
|
|
3
|
-
"description": "matterbridge-roborock-vacuum-plugin v. 1.1.0-
|
|
3
|
+
"description": "matterbridge-roborock-vacuum-plugin v. 1.1.0-rc09 by https://github.com/RinDevJunior",
|
|
4
4
|
"type": "object",
|
|
5
5
|
"required": ["username", "password"],
|
|
6
6
|
"properties": {
|
package/package.json
CHANGED
|
@@ -22,9 +22,11 @@ export abstract class AbstractClient implements Client {
|
|
|
22
22
|
protected connected = false;
|
|
23
23
|
protected logger: AnsiLogger;
|
|
24
24
|
|
|
25
|
+
protected abstract clientName: string;
|
|
26
|
+
protected abstract shouldReconnect: boolean;
|
|
27
|
+
|
|
25
28
|
private readonly context: MessageContext;
|
|
26
29
|
private readonly syncMessageListener: SyncMessageListener;
|
|
27
|
-
private readonly connectionStateListener: ConnectionStateListener;
|
|
28
30
|
|
|
29
31
|
protected constructor(logger: AnsiLogger, context: MessageContext) {
|
|
30
32
|
this.context = context;
|
|
@@ -33,13 +35,14 @@ export abstract class AbstractClient implements Client {
|
|
|
33
35
|
|
|
34
36
|
this.syncMessageListener = new SyncMessageListener(logger);
|
|
35
37
|
this.messageListeners.register(this.syncMessageListener);
|
|
36
|
-
|
|
37
|
-
this.connectionStateListener = new ConnectionStateListener(logger, this);
|
|
38
|
-
this.connectionListeners.register(this.connectionStateListener);
|
|
39
|
-
|
|
40
38
|
this.logger = logger;
|
|
41
39
|
}
|
|
42
40
|
|
|
41
|
+
protected initializeConnectionStateListener() {
|
|
42
|
+
const connectionStateListener = new ConnectionStateListener(this.logger, this, this.clientName, this.shouldReconnect);
|
|
43
|
+
this.connectionListeners.register(connectionStateListener);
|
|
44
|
+
}
|
|
45
|
+
|
|
43
46
|
abstract connect(): void;
|
|
44
47
|
abstract disconnect(): Promise<void>;
|
|
45
48
|
abstract send(duid: string, request: RequestMessage): Promise<void>;
|
|
@@ -9,6 +9,9 @@ import { Sequence } from '../../helper/sequence.js';
|
|
|
9
9
|
import { ChunkBuffer } from '../../helper/chunkBuffer.js';
|
|
10
10
|
|
|
11
11
|
export class LocalNetworkClient extends AbstractClient {
|
|
12
|
+
protected override clientName = 'LocalNetworkClient';
|
|
13
|
+
protected override shouldReconnect = true;
|
|
14
|
+
|
|
12
15
|
private socket: Socket | undefined = undefined;
|
|
13
16
|
private buffer: ChunkBuffer = new ChunkBuffer();
|
|
14
17
|
private messageIdSeq: Sequence;
|
|
@@ -21,6 +24,8 @@ export class LocalNetworkClient extends AbstractClient {
|
|
|
21
24
|
this.duid = duid;
|
|
22
25
|
this.ip = ip;
|
|
23
26
|
this.messageIdSeq = new Sequence(100000, 999999);
|
|
27
|
+
|
|
28
|
+
this.initializeConnectionStateListener();
|
|
24
29
|
}
|
|
25
30
|
|
|
26
31
|
public connect(): void {
|
|
@@ -7,6 +7,9 @@ import { Rriot, UserData } from '../../Zmodel/userData.js';
|
|
|
7
7
|
import { AnsiLogger, debugStringify } from 'matterbridge/logger';
|
|
8
8
|
|
|
9
9
|
export class MQTTClient extends AbstractClient {
|
|
10
|
+
protected override clientName = 'MQTTClient';
|
|
11
|
+
protected override shouldReconnect = false;
|
|
12
|
+
|
|
10
13
|
private readonly rriot: Rriot;
|
|
11
14
|
private readonly mqttUsername: string;
|
|
12
15
|
private readonly mqttPassword: string;
|
|
@@ -18,6 +21,8 @@ export class MQTTClient extends AbstractClient {
|
|
|
18
21
|
|
|
19
22
|
this.mqttUsername = CryptoUtils.md5hex(userdata.rriot.u + ':' + userdata.rriot.k).substring(2, 10);
|
|
20
23
|
this.mqttPassword = CryptoUtils.md5hex(userdata.rriot.s + ':' + userdata.rriot.k).substring(16);
|
|
24
|
+
|
|
25
|
+
this.initializeConnectionStateListener();
|
|
21
26
|
}
|
|
22
27
|
|
|
23
28
|
public connect(): void {
|
package/src/roborockCommunication/broadcast/listener/implementation/connectionStateListener.ts
CHANGED
|
@@ -5,17 +5,27 @@ import { AbstractClient } from '../../abstractClient.js';
|
|
|
5
5
|
export class ConnectionStateListener implements AbstractConnectionListener {
|
|
6
6
|
protected logger: AnsiLogger;
|
|
7
7
|
protected client: AbstractClient;
|
|
8
|
-
|
|
8
|
+
protected clientName: string;
|
|
9
|
+
protected shouldReconnect: boolean;
|
|
10
|
+
|
|
11
|
+
constructor(logger: AnsiLogger, client: AbstractClient, clientName: string, shouldReconnect = false) {
|
|
9
12
|
this.logger = logger;
|
|
10
13
|
this.client = client;
|
|
14
|
+
this.clientName = clientName;
|
|
15
|
+
this.shouldReconnect = shouldReconnect;
|
|
11
16
|
}
|
|
12
17
|
|
|
13
18
|
public async onConnected(duid: string): Promise<void> {
|
|
14
|
-
this.logger.notice(`Device ${duid} connected to
|
|
19
|
+
this.logger.notice(`Device ${duid} connected to ${this.clientName}`);
|
|
15
20
|
}
|
|
16
21
|
|
|
17
22
|
public async onDisconnected(duid: string): Promise<void> {
|
|
18
|
-
this.
|
|
23
|
+
if (!this.shouldReconnect) {
|
|
24
|
+
this.logger.notice(`Device ${duid} disconnected from ${this.clientName}, but re-registration is disabled.`);
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
this.logger.notice(`Device ${duid} disconnected from ${this.clientName}`);
|
|
19
29
|
|
|
20
30
|
const isInDisconnectingStep = this.client.isInDisconnectingStep;
|
|
21
31
|
if (isInDisconnectingStep) {
|
|
@@ -23,7 +33,7 @@ export class ConnectionStateListener implements AbstractConnectionListener {
|
|
|
23
33
|
return;
|
|
24
34
|
}
|
|
25
35
|
|
|
26
|
-
this.logger.info(`Re-registering device with DUID ${duid} to
|
|
36
|
+
this.logger.info(`Re-registering device with DUID ${duid} to ${this.clientName}`);
|
|
27
37
|
this.client.connect();
|
|
28
38
|
|
|
29
39
|
this.client.isInDisconnectingStep = false;
|