matterbridge-roborock-vacuum-plugin 1.1.0-rc04 → 1.1.0-rc05

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/platform.js CHANGED
@@ -82,7 +82,7 @@ export class RoborockMatterbridgePlatform extends MatterbridgeDynamicPlatform {
82
82
  this.log.error('Initializing: No device found');
83
83
  return;
84
84
  }
85
- if (!this.enableExperimentalFeature || !this.enableExperimentalFeature.advancedFeature.enableServerMode) {
85
+ if (!this.enableExperimentalFeature?.enableExperimentalFeature || !this.enableExperimentalFeature?.advancedFeature?.enableServerMode) {
86
86
  vacuums = [vacuums[0]];
87
87
  }
88
88
  for (const vacuum of vacuums) {
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "matterbridge-roborock-vacuum-plugin",
3
3
  "type": "DynamicPlatform",
4
- "version": "1.1.0-rc04",
4
+ "version": "1.1.0-rc05",
5
5
  "whiteList": [],
6
6
  "blackList": [],
7
7
  "useInterval": true,
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "title": "Matterbridge Roborock Vacuum Plugin",
3
- "description": "matterbridge-roborock-vacuum-plugin v. 1.1.0-rc04 by https://github.com/RinDevJunior",
3
+ "description": "matterbridge-roborock-vacuum-plugin v. 1.1.0-rc05 by https://github.com/RinDevJunior",
4
4
  "type": "object",
5
5
  "required": [
6
6
  "username",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "matterbridge-roborock-vacuum-plugin",
3
- "version": "1.1.0-rc04",
3
+ "version": "1.1.0-rc05",
4
4
  "description": "Matterbridge Roborock Vacuum Plugin",
5
5
  "author": "https://github.com/RinDevJunior",
6
6
  "license": "MIT",
package/src/platform.ts CHANGED
@@ -111,7 +111,7 @@ export class RoborockMatterbridgePlatform extends MatterbridgeDynamicPlatform {
111
111
  return;
112
112
  }
113
113
 
114
- if (!this.enableExperimentalFeature || !this.enableExperimentalFeature.advancedFeature.enableServerMode) {
114
+ if (!this.enableExperimentalFeature?.enableExperimentalFeature || !this.enableExperimentalFeature?.advancedFeature?.enableServerMode) {
115
115
  vacuums = [vacuums[0]]; // If server mode is not enabled, only use the first vacuum
116
116
  }
117
117
  // else {
@@ -2,6 +2,7 @@ import { AnsiLogger } from 'matterbridge/logger';
2
2
  import { ServiceArea } from 'matterbridge/matter/clusters';
3
3
  import RoborockService from '../roborockService';
4
4
  import { MessageProcessor } from '../roborockCommunication/broadcast/messageProcessor';
5
+ import { Device } from '../roborockCommunication';
5
6
 
6
7
  describe('RoborockService - startClean', () => {
7
8
  let roborockService: RoborockService;
@@ -152,7 +153,15 @@ describe('RoborockService - startClean', () => {
152
153
  expect(mockLogger.debug).toHaveBeenCalledWith('RoborockService - startRoomClean', expect.anything());
153
154
  expect(mockMessageProcessor.startRoomClean).toHaveBeenCalledWith(duid, [1, 3], 1);
154
155
  });
156
+
157
+ it('should initialize and store MessageProcessor for the given duid', () => {
158
+ const duid = 'test-duid';
159
+ roborockService.initializeMessageClientForLocal({ duid } as Device);
160
+ const storedProcessor = roborockService['messageProcessorMap'].get(duid);
161
+ expect(storedProcessor).not.toBeUndefined();
162
+ });
155
163
  });
164
+
156
165
  describe('RoborockService - basic setters/getters', () => {
157
166
  let roborockService: RoborockService;
158
167
  let mockLogger: AnsiLogger;
@@ -0,0 +1,69 @@
1
+ import { AnsiLogger } from 'matterbridge/logger';
2
+ import RoborockService from '../roborockService';
3
+ import { MessageProcessor } from '../roborockCommunication/broadcast/messageProcessor';
4
+ import { Device, DeviceStatus } from '../roborockCommunication';
5
+
6
+ jest.useFakeTimers();
7
+
8
+ describe('RoborockService - activateDeviceNotify', () => {
9
+ let roborockService: RoborockService;
10
+ let mockLogger: AnsiLogger;
11
+ let mockMessageProcessor: jest.Mocked<MessageProcessor>;
12
+ let mockDeviceNotify: jest.Mock;
13
+
14
+ beforeEach(() => {
15
+ mockLogger = {
16
+ debug: jest.fn(),
17
+ notice: jest.fn(),
18
+ error: jest.fn(),
19
+ warn: jest.fn(),
20
+ } as any;
21
+
22
+ mockMessageProcessor = {
23
+ getDeviceStatus: jest.fn(),
24
+ } as any;
25
+
26
+ mockDeviceNotify = jest.fn(() => {
27
+ jest.fn();
28
+ });
29
+
30
+ roborockService = new RoborockService(jest.fn(), jest.fn(), 1, {} as any, mockLogger); // refreshInterval = 1
31
+ roborockService['deviceNotify'] = mockDeviceNotify;
32
+ roborockService['getMessageProcessor'] = jest.fn().mockReturnValue(mockMessageProcessor);
33
+ roborockService['refreshInterval'] = 1;
34
+ });
35
+
36
+ it('should call getDeviceStatus periodically and notify with status message', async () => {
37
+ const duid = 'test-duid';
38
+ const device: Device = { duid } as Device;
39
+
40
+ const fakeStatus: DeviceStatus = {
41
+ errorStatus: { errorCode: 0 },
42
+ message: { battery: 80 },
43
+ } as any;
44
+
45
+ (roborockService['getMessageProcessor'] as jest.Mock).mockReturnValue(mockMessageProcessor);
46
+ mockMessageProcessor.getDeviceStatus.mockResolvedValue(fakeStatus);
47
+
48
+ await roborockService.activateDeviceNotify(device);
49
+
50
+ jest.advanceTimersByTime(2000); // 1s = 1 cycle
51
+
52
+ expect(mockLogger.debug).toHaveBeenCalledWith('Requesting device info for device', duid);
53
+ expect(mockMessageProcessor.getDeviceStatus).toHaveBeenCalledWith(duid);
54
+ });
55
+
56
+ it('should log error if message processor is not found', async () => {
57
+ const duid = 'not-found-duid';
58
+ const device: Device = { duid } as Device;
59
+
60
+ (roborockService['getMessageProcessor'] as jest.Mock).mockReturnValue(undefined);
61
+
62
+ await roborockService.activateDeviceNotify(device);
63
+
64
+ jest.advanceTimersByTime(1000); // trigger the interval
65
+
66
+ expect(mockLogger.error).toHaveBeenCalledWith('Local client not initialized');
67
+ expect(mockDeviceNotify).not.toHaveBeenCalled();
68
+ });
69
+ });