matterbridge-roborock-vacuum-plugin 1.1.0-rc12 → 1.1.0-rc13

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.
Files changed (37) hide show
  1. package/dist/initialData/getSupportedAreas.js +7 -6
  2. package/dist/model/RoomMap.js +1 -0
  3. package/dist/platform.js +2 -2
  4. package/dist/platformRunner.js +51 -23
  5. package/dist/roborockCommunication/Zmodel/mapInfo.js +3 -1
  6. package/dist/roborockCommunication/broadcast/abstractClient.js +1 -1
  7. package/dist/roborockCommunication/broadcast/client/LocalNetworkClient.js +25 -25
  8. package/dist/roborockCommunication/broadcast/client/LocalNetworkUDPClient.js +129 -0
  9. package/dist/roborockCommunication/broadcast/client/MQTTClient.js +53 -25
  10. package/dist/roborockCommunication/broadcast/clientRouter.js +2 -2
  11. package/dist/roborockCommunication/broadcast/listener/implementation/chainedConnectionListener.js +7 -2
  12. package/dist/roborockCommunication/broadcast/listener/implementation/connectionStateListener.js +9 -8
  13. package/dist/roborockCommunication/helper/messageDeserializer.js +1 -1
  14. package/dist/roborockService.js +5 -5
  15. package/matterbridge-roborock-vacuum-plugin.config.json +2 -2
  16. package/matterbridge-roborock-vacuum-plugin.schema.json +10 -37
  17. package/package.json +2 -1
  18. package/src/initialData/getSupportedAreas.ts +8 -6
  19. package/src/model/RoomMap.ts +2 -0
  20. package/src/platform.ts +3 -2
  21. package/src/platformRunner.ts +68 -25
  22. package/src/roborockCommunication/Zmodel/map.ts +1 -0
  23. package/src/roborockCommunication/Zmodel/mapInfo.ts +5 -4
  24. package/src/roborockCommunication/broadcast/abstractClient.ts +1 -2
  25. package/src/roborockCommunication/broadcast/client/LocalNetworkClient.ts +34 -28
  26. package/src/roborockCommunication/broadcast/client/LocalNetworkUDPClient.ts +157 -0
  27. package/src/roborockCommunication/broadcast/client/MQTTClient.ts +69 -36
  28. package/src/roborockCommunication/broadcast/clientRouter.ts +2 -2
  29. package/src/roborockCommunication/broadcast/listener/abstractConnectionListener.ts +2 -1
  30. package/src/roborockCommunication/broadcast/listener/implementation/chainedConnectionListener.ts +8 -2
  31. package/src/roborockCommunication/broadcast/listener/implementation/connectionStateListener.ts +11 -8
  32. package/src/roborockCommunication/helper/messageDeserializer.ts +2 -3
  33. package/src/roborockService.ts +6 -6
  34. package/src/tests/initialData/getSupportedAreas.test.ts +27 -0
  35. package/src/tests/platformRunner2.test.ts +91 -0
  36. package/src/tests/roborockCommunication/broadcast/client/LocalNetworkClient.test.ts +1 -7
  37. package/src/tests/roborockCommunication/broadcast/client/MQTTClient.test.ts +13 -106
@@ -52,7 +52,7 @@ describe('MQTTClient', () => {
52
52
  let messageListeners: any;
53
53
 
54
54
  beforeEach(() => {
55
- logger = { error: jest.fn(), debug: jest.fn(), notice: jest.fn() };
55
+ logger = { error: jest.fn(), debug: jest.fn(), notice: jest.fn(), info: jest.fn() };
56
56
  context = {};
57
57
  userdata = {
58
58
  rriot: {
@@ -68,6 +68,7 @@ describe('MQTTClient', () => {
68
68
  onConnected: jest.fn().mockResolvedValue(undefined),
69
69
  onDisconnected: jest.fn().mockResolvedValue(undefined),
70
70
  onError: jest.fn().mockResolvedValue(undefined),
71
+ onReconnect: jest.fn().mockResolvedValue(undefined),
71
72
  };
72
73
  messageListeners = { onMessage: jest.fn().mockResolvedValue(undefined) };
73
74
 
@@ -107,14 +108,14 @@ describe('MQTTClient', () => {
107
108
 
108
109
  it('should not connect if already connected', () => {
109
110
  const mqttClient = createMQTTClient();
110
- mqttClient['client'] = client;
111
+ mqttClient['mqttClient'] = client;
111
112
  mqttClient.connect();
112
113
  expect(mockConnect).not.toHaveBeenCalled();
113
114
  });
114
115
 
115
116
  it('should disconnect if connected', async () => {
116
117
  const mqttClient = createMQTTClient();
117
- mqttClient['client'] = client;
118
+ mqttClient['mqttClient'] = client;
118
119
  mqttClient['connected'] = true;
119
120
  await mqttClient.disconnect();
120
121
  expect(client.end).toHaveBeenCalled();
@@ -122,7 +123,7 @@ describe('MQTTClient', () => {
122
123
 
123
124
  it('should not disconnect if not connected', async () => {
124
125
  const mqttClient = createMQTTClient();
125
- mqttClient['client'] = undefined;
126
+ mqttClient['mqttClient'] = undefined;
126
127
  mqttClient['connected'] = false;
127
128
  await mqttClient.disconnect();
128
129
  expect(client.end).not.toHaveBeenCalled();
@@ -130,105 +131,10 @@ describe('MQTTClient', () => {
130
131
 
131
132
  it('should log error if disconnect throws', async () => {
132
133
  const mqttClient = createMQTTClient();
133
- mqttClient['client'] = {
134
+ mqttClient['mqttClient'] = {
134
135
  end: jest.fn(() => {
135
136
  throw new Error('fail');
136
137
  }),
137
- on: jest.fn(),
138
- publish: jest.fn(),
139
- subscribe: jest.fn(),
140
- connected: true,
141
- disconnecting: false,
142
- disconnected: false,
143
- reconnecting: false,
144
- options: {},
145
- removeListener: jest.fn(),
146
- removeAllListeners: jest.fn(),
147
- addListener: jest.fn(),
148
- emit: jest.fn(),
149
- eventNames: jest.fn(),
150
- getMaxListeners: jest.fn(),
151
- listenerCount: jest.fn(),
152
- listeners: jest.fn(),
153
- off: jest.fn(),
154
- once: jest.fn(),
155
- prependListener: jest.fn(),
156
- prependOnceListener: jest.fn(),
157
- rawListeners: jest.fn(),
158
- setMaxListeners: jest.fn(),
159
- handleMessage: jest.fn(),
160
- subscribeAsync: jest.fn(),
161
- unsubscribe: jest.fn(),
162
- unsubscribeAsync: jest.fn(),
163
- publishAsync: jest.fn(),
164
- reconnect: jest.fn(),
165
- destroy: jest.fn(),
166
- removeOutgoingMessage: jest.fn(),
167
- connectedTime: 0,
168
- disconnect: jest.fn(),
169
- stream: {} as any,
170
- messageIdToTopic: {},
171
- outgoingStore: {} as any,
172
- incomingStore: {} as any,
173
- queueQoSZero: jest.fn(),
174
- _resubscribeTopics: {},
175
- _resubscribeTopicsList: [],
176
- _resubscribeTopicsMap: {},
177
- _resubscribeTopicsTimer: null,
178
- _resubscribeTopicsTimeout: 0,
179
- _resubscribeTopicsInProgress: false,
180
- _resubscribeTopicsCallback: jest.fn(),
181
- _resubscribeTopicsError: null,
182
- _resubscribeTopicsErrorCallback: jest.fn(),
183
- _resubscribeTopicsErrorTimer: null,
184
- _resubscribeTopicsErrorTimeout: 0,
185
- _resubscribeTopicsErrorInProgress: false,
186
- _resubscribeTopicsErrorCallback2: jest.fn(),
187
- _resubscribeTopicsError2: null,
188
- _resubscribeTopicsErrorTimer2: null,
189
- _resubscribeTopicsErrorTimeout2: 0,
190
- _resubscribeTopicsErrorInProgress2: false,
191
- _resubscribeTopicsErrorCallback3: jest.fn(),
192
- _resubscribeTopicsError3: null,
193
- _resubscribeTopicsErrorTimer3: null,
194
- _resubscribeTopicsErrorTimeout3: 0,
195
- _resubscribeTopicsErrorInProgress3: false,
196
- _resubscribeTopicsErrorCallback4: jest.fn(),
197
- _resubscribeTopicsError4: null,
198
- _resubscribeTopicsErrorTimer4: null,
199
- _resubscribeTopicsErrorTimeout4: 0,
200
- _resubscribeTopicsErrorInProgress4: false,
201
- _resubscribeTopicsErrorCallback5: jest.fn(),
202
- _resubscribeTopicsError5: null,
203
- _resubscribeTopicsErrorTimer5: null,
204
- _resubscribeTopicsErrorTimeout5: 0,
205
- _resubscribeTopicsErrorInProgress5: false,
206
- _resubscribeTopicsErrorCallback6: jest.fn(),
207
- _resubscribeTopicsError6: null,
208
- _resubscribeTopicsErrorTimer6: null,
209
- _resubscribeTopicsErrorTimeout6: 0,
210
- _resubscribeTopicsErrorInProgress6: false,
211
- _resubscribeTopicsErrorCallback7: jest.fn(),
212
- _resubscribeTopicsError7: null,
213
- _resubscribeTopicsErrorTimer7: null,
214
- _resubscribeTopicsErrorTimeout7: 0,
215
- _resubscribeTopicsErrorInProgress7: false,
216
- _resubscribeTopicsErrorCallback8: jest.fn(),
217
- _resubscribeTopicsError8: null,
218
- _resubscribeTopicsErrorTimer8: null,
219
- _resubscribeTopicsErrorTimeout8: 0,
220
- _resubscribeTopicsErrorInProgress8: false,
221
- _resubscribeTopicsErrorCallback9: jest.fn(),
222
- _resubscribeTopicsError9: null,
223
- _resubscribeTopicsErrorTimer9: null,
224
- _resubscribeTopicsErrorTimeout9: 0,
225
- _resubscribeTopicsErrorInProgress9: false,
226
- _resubscribeTopicsErrorCallback10: jest.fn(),
227
- _resubscribeTopicsError10: null,
228
- _resubscribeTopicsErrorTimer10: null,
229
- _resubscribeTopicsErrorTimeout10: 0,
230
- _resubscribeTopicsErrorInProgress10: false,
231
- // Add more properties as needed for your codebase or use a proper mock library
232
138
  } as any;
233
139
  mqttClient['connected'] = true;
234
140
  await mqttClient.disconnect();
@@ -237,7 +143,7 @@ describe('MQTTClient', () => {
237
143
 
238
144
  it('should publish message if connected', async () => {
239
145
  const mqttClient = createMQTTClient();
240
- mqttClient['client'] = client;
146
+ mqttClient['mqttClient'] = client;
241
147
  mqttClient['connected'] = true;
242
148
  const request = { toMqttRequest: jest.fn(() => 'req') };
243
149
  await mqttClient.send('duid1', request as any);
@@ -247,7 +153,7 @@ describe('MQTTClient', () => {
247
153
 
248
154
  it('should log error if send called when not connected', async () => {
249
155
  const mqttClient = createMQTTClient();
250
- mqttClient['client'] = undefined;
156
+ mqttClient['mqttClient'] = undefined;
251
157
  mqttClient['connected'] = false;
252
158
  const request = { toMqttRequest: jest.fn() };
253
159
  await mqttClient.send('duid1', request as any);
@@ -257,7 +163,7 @@ describe('MQTTClient', () => {
257
163
 
258
164
  it('onConnect should set connected, call onConnected, and subscribeToQueue', async () => {
259
165
  const mqttClient = createMQTTClient();
260
- mqttClient['client'] = client;
166
+ mqttClient['mqttClient'] = client;
261
167
  mqttClient['subscribeToQueue'] = jest.fn();
262
168
  await mqttClient['onConnect']({} as any);
263
169
  expect(mqttClient['connected']).toBe(true);
@@ -267,14 +173,15 @@ describe('MQTTClient', () => {
267
173
 
268
174
  it('subscribeToQueue should call client.subscribe with correct topic', () => {
269
175
  const mqttClient = createMQTTClient();
270
- mqttClient['client'] = client;
176
+ mqttClient['mqttClient'] = client;
177
+ mqttClient['connected'] = true;
271
178
  mqttClient['subscribeToQueue']();
272
179
  expect(client.subscribe).toHaveBeenCalledWith('rr/m/o/user/c6d6afb9/#', expect.any(Function));
273
180
  });
274
181
 
275
182
  it('onSubscribe should log error and call onDisconnected if error', async () => {
276
183
  const mqttClient = createMQTTClient();
277
- await mqttClient['onSubscribe'](new Error('fail'));
184
+ await mqttClient['onSubscribe'](new Error('fail'), undefined);
278
185
  expect(logger.error).toHaveBeenCalledWith(expect.stringContaining('failed to subscribe'));
279
186
  expect(mqttClient['connected']).toBe(false);
280
187
  expect(connectionListeners.onDisconnected).toHaveBeenCalled();
@@ -282,7 +189,7 @@ describe('MQTTClient', () => {
282
189
 
283
190
  it('onSubscribe should do nothing if no error', async () => {
284
191
  const mqttClient = createMQTTClient();
285
- await mqttClient['onSubscribe'](null);
192
+ await mqttClient['onSubscribe'](null, undefined);
286
193
  expect(logger.error).not.toHaveBeenCalled();
287
194
  expect(connectionListeners.onDisconnected).not.toHaveBeenCalled();
288
195
  });