matterbridge-roborock-vacuum-plugin 1.0.7-rc01 → 1.0.7-rc02

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.
@@ -19,13 +19,13 @@ export function getSupportedAreas(rooms, roomMap, log) {
19
19
  },
20
20
  ];
21
21
  }
22
- const supportedAreas = rooms.map((room, index) => {
22
+ const supportedAreas = roomMap.rooms.map((room, index) => {
23
23
  return {
24
- areaId: roomMap.getRoomId(room.id) ?? index + 1,
24
+ areaId: room.id,
25
25
  mapId: null,
26
26
  areaInfo: {
27
27
  locationInfo: {
28
- locationName: room.name,
28
+ locationName: room.displayName ?? rooms.find((r) => r.id == room.globalId)?.name ?? 'Unknown Room',
29
29
  floorNumber: null,
30
30
  areaType: null,
31
31
  },
@@ -37,7 +37,7 @@ export function getSupportedAreas(rooms, roomMap, log) {
37
37
  return duplicated
38
38
  ? [
39
39
  {
40
- areaId: 1,
40
+ areaId: 2,
41
41
  mapId: null,
42
42
  areaInfo: {
43
43
  locationInfo: {
@@ -9,10 +9,4 @@ export default class RoomMap {
9
9
  };
10
10
  });
11
11
  }
12
- getGlobalId(id) {
13
- return this.rooms.find((r) => Number(r.id) == Number(id))?.globalId;
14
- }
15
- getRoomId(globalId) {
16
- return this.rooms.find((r) => Number(r.globalId) == Number(globalId))?.id;
17
- }
18
12
  }
package/dist/platform.js CHANGED
@@ -19,6 +19,7 @@ export class RoborockMatterbridgePlatform extends MatterbridgeDynamicPlatform {
19
19
  platformRunner;
20
20
  devices;
21
21
  serialNumber;
22
+ whiteList;
22
23
  constructor(matterbridge, log, config) {
23
24
  super(matterbridge, log, config);
24
25
  if (this.verifyMatterbridgeVersion === undefined || typeof this.verifyMatterbridgeVersion !== 'function' || !this.verifyMatterbridgeVersion('3.0.4')) {
@@ -31,6 +32,8 @@ export class RoborockMatterbridgePlatform extends MatterbridgeDynamicPlatform {
31
32
  config.blackList = [];
32
33
  if (config.enableExperimentalFeature === undefined)
33
34
  config.enableExperimentalFeature = false;
35
+ this.whiteList = config.whiteList;
36
+ config.whiteList = [];
34
37
  this.clientManager = new ClientManager(this.log);
35
38
  this.devices = new Map();
36
39
  }
@@ -71,8 +74,8 @@ export class RoborockMatterbridgePlatform extends MatterbridgeDynamicPlatform {
71
74
  const devices = await this.roborockService.listDevices(username);
72
75
  this.log.notice('Initializing - devices: ', debugStringify(devices));
73
76
  let vacuum = undefined;
74
- if (this.config.whiteList.length > 0) {
75
- const firstDUID = this.config.whiteList[0];
77
+ if (this.whiteList.length > 0) {
78
+ const firstDUID = this.whiteList[0];
76
79
  vacuum = devices.find((d) => d.duid == firstDUID);
77
80
  }
78
81
  else {
package/jest.config.js ADDED
@@ -0,0 +1,19 @@
1
+ export default {
2
+ testEnvironment: 'node',
3
+ extensionsToTreatAsEsm: ['.ts'],
4
+ moduleNameMapper: {
5
+ '^(\\.{1,2}/.*)\\.js$': '$1',
6
+ },
7
+ transform: {
8
+ '^.+\\.ts$': [
9
+ 'ts-jest',
10
+ {
11
+ useESM: true,
12
+ tsconfig: 'tsconfig.jest.json',
13
+ },
14
+ ],
15
+ },
16
+ transformIgnorePatterns: ['/node_modules/'],
17
+ testPathIgnorePatterns: ['/node_modules/', '/dist/', '/frontend/'],
18
+ coveragePathIgnorePatterns: ['/node_modules/', '/dist/', '/frontend/', '/src/mock/'],
19
+ };
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "matterbridge-roborock-vacuum-plugin",
3
3
  "type": "DynamicPlatform",
4
- "version": "1.0.7-rc01",
4
+ "version": "1.0.7-rc02",
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.0.7-rc01 by https://github.com/RinDevJunior",
3
+ "description": "matterbridge-roborock-vacuum-plugin v. 1.0.7-rc02 by https://github.com/RinDevJunior",
4
4
  "type": "object",
5
5
  "required": [],
6
6
  "properties": {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "matterbridge-roborock-vacuum-plugin",
3
- "version": "1.0.7-rc01",
3
+ "version": "1.0.7-rc02",
4
4
  "description": "Matterbridge Roborock Vacuum Plugin",
5
5
  "author": "https://github.com/RinDevJunior",
6
6
  "license": "MIT",
@@ -0,0 +1,55 @@
1
+ import { getSupportedAreas } from '../initialData/getSupportedAreas';
2
+ import RoomMap from '../model/RoomMap';
3
+ import { jest } from '@jest/globals';
4
+
5
+ const mockLogger = {
6
+ debug: jest.fn(),
7
+ error: jest.fn(),
8
+ };
9
+
10
+ describe('getSupportedAreas', () => {
11
+ beforeEach(() => {
12
+ jest.clearAllMocks();
13
+ });
14
+
15
+ it('returns default area when rooms and roomMap are empty', () => {
16
+ const result = getSupportedAreas(
17
+ [
18
+ { id: 2775739, name: 'Garage' },
19
+ { id: 1474466, name: 'Outside' },
20
+ { id: 1459590, name: 'AAA room' },
21
+ { id: 1459587, name: 'BBB’s Room' },
22
+ { id: 1459580, name: 'CCC’s room' },
23
+ { id: 1458155, name: 'Dining room' },
24
+ { id: 1457889, name: 'Bathroom' },
25
+ { id: 1457888, name: 'Living room' },
26
+ { id: 991195, name: 'Downstairs Bathroom' },
27
+ { id: 991190, name: 'Garage Entryway' },
28
+ { id: 991187, name: 'TV Room' },
29
+ { id: 991185, name: 'Bedroom' },
30
+ { id: 612205, name: 'DDD’s Room' },
31
+ { id: 612204, name: 'Upstairs Bathroom' },
32
+ { id: 612202, name: 'Hallway' },
33
+ { id: 612200, name: 'EEE Room' },
34
+ { id: 609148, name: 'Dining Room' },
35
+ { id: 609146, name: 'Kitchen' },
36
+ { id: 609145, name: 'Living Room' },
37
+ ],
38
+ {
39
+ rooms: [
40
+ { id: 16, globalId: 609146, displayName: 'Kitchen' },
41
+ { id: 17, globalId: 1457889, displayName: 'Bathroom' },
42
+ { id: 18, globalId: 612202, displayName: 'Hallway' },
43
+ { id: 19, globalId: 1458155, displayName: 'Dining room' },
44
+ { id: 20, globalId: 1457888, displayName: 'Living room' },
45
+ { id: 21, globalId: 1459580, displayName: 'BBB’s room' },
46
+ { id: 22, globalId: 612205, displayName: 'CCC’s Room' },
47
+ { id: 23, globalId: 1474466, displayName: 'Outside' },
48
+ ],
49
+ } as RoomMap,
50
+ mockLogger as any,
51
+ );
52
+
53
+ expect(result.length).toEqual(8);
54
+ });
55
+ });
@@ -3,23 +3,6 @@ import { ServiceArea } from 'matterbridge/matter/clusters';
3
3
  import RoomMap from '../model/RoomMap.js';
4
4
  import { Room } from '../roborockCommunication/Zmodel/room.js';
5
5
 
6
- /*
7
- rooms = [
8
- { id: 123456, name: 'Study' },
9
- { id: 123457, name: 'Bedroom' },
10
- { id: 123458, name: 'Kitchen' },
11
- { id: 123459, name: 'Living room' }
12
- ]
13
- roomMap = {
14
- rooms: [
15
- { id: 1, globalId: "123456", displayName: undefined },
16
- { id: 2, globalId: "123457", displayName: undefined },
17
- { id: 3, globalId: "123458", displayName: undefined },
18
- { id: 4, globalId: "123459", displayName: undefined },
19
- ],
20
- };
21
- */
22
-
23
6
  export function getSupportedAreas(rooms: Room[], roomMap: RoomMap | undefined, log?: AnsiLogger): ServiceArea.Area[] {
24
7
  log?.debug('getSupportedAreas', debugStringify(rooms));
25
8
  log?.debug('getSupportedAreas', roomMap ? debugStringify(roomMap) : 'undefined');
@@ -42,13 +25,13 @@ export function getSupportedAreas(rooms: Room[], roomMap: RoomMap | undefined, l
42
25
  ];
43
26
  }
44
27
 
45
- const supportedAreas: ServiceArea.Area[] = rooms.map((room, index) => {
28
+ const supportedAreas: ServiceArea.Area[] = roomMap.rooms.map((room, index) => {
46
29
  return {
47
- areaId: roomMap.getRoomId(room.id) ?? index + 1,
30
+ areaId: room.id,
48
31
  mapId: null,
49
32
  areaInfo: {
50
33
  locationInfo: {
51
- locationName: room.name,
34
+ locationName: room.displayName ?? rooms.find((r) => r.id == room.globalId)?.name ?? 'Unknown Room',
52
35
  floorNumber: null,
53
36
  areaType: null,
54
37
  },
@@ -62,7 +45,7 @@ export function getSupportedAreas(rooms: Room[], roomMap: RoomMap | undefined, l
62
45
  return duplicated
63
46
  ? [
64
47
  {
65
- areaId: 1,
48
+ areaId: 2,
66
49
  mapId: null,
67
50
  areaInfo: {
68
51
  locationInfo: {
@@ -34,11 +34,11 @@ export default class RoomMap {
34
34
  });
35
35
  }
36
36
 
37
- getGlobalId(id: number): number | undefined {
38
- return this.rooms.find((r) => Number(r.id) == Number(id))?.globalId;
39
- }
37
+ // getGlobalId(id: number): number | undefined {
38
+ // return this.rooms.find((r) => Number(r.id) == Number(id))?.globalId;
39
+ // }
40
40
 
41
- getRoomId(globalId: number): number | undefined {
42
- return this.rooms.find((r) => Number(r.globalId) == Number(globalId))?.id;
43
- }
41
+ // getRoomId(globalId: number): number | undefined {
42
+ // return this.rooms.find((r) => Number(r.globalId) == Number(globalId))?.id;
43
+ // }
44
44
  }
package/src/platform.ts CHANGED
@@ -21,6 +21,7 @@ export class RoborockMatterbridgePlatform extends MatterbridgeDynamicPlatform {
21
21
  platformRunner: PlatformRunner | undefined;
22
22
  devices: Map<string, Device>;
23
23
  serialNumber: string | undefined;
24
+ whiteList: string[];
24
25
 
25
26
  constructor(matterbridge: Matterbridge, log: AnsiLogger, config: PlatformConfig) {
26
27
  super(matterbridge, log, config);
@@ -35,6 +36,10 @@ export class RoborockMatterbridgePlatform extends MatterbridgeDynamicPlatform {
35
36
  if (config.whiteList === undefined) config.whiteList = [];
36
37
  if (config.blackList === undefined) config.blackList = [];
37
38
  if (config.enableExperimentalFeature === undefined) config.enableExperimentalFeature = false;
39
+ this.whiteList = config.whiteList as string[];
40
+
41
+ //reset default whitelist
42
+ config.whiteList = [];
38
43
 
39
44
  this.clientManager = new ClientManager(this.log);
40
45
  this.devices = new Map<string, Device>();
@@ -95,8 +100,8 @@ export class RoborockMatterbridgePlatform extends MatterbridgeDynamicPlatform {
95
100
  this.log.notice('Initializing - devices: ', debugStringify(devices));
96
101
 
97
102
  let vacuum: Device | undefined = undefined;
98
- if ((this.config.whiteList as string[]).length > 0) {
99
- const firstDUID = (this.config.whiteList as string[])[0];
103
+ if (this.whiteList.length > 0) {
104
+ const firstDUID = this.whiteList[0];
100
105
  vacuum = devices.find((d) => d.duid == firstDUID);
101
106
  } else {
102
107
  vacuum = devices.find((d) => isSupportedDevice(d.data.model));
@@ -0,0 +1,12 @@
1
+ {
2
+ "extends": "./tsconfig.json",
3
+ "compilerOptions": {
4
+ // enable isolatedModules just for ts-jest
5
+ "isolatedModules": true
6
+ },
7
+ "include": [
8
+ "**/*.spec.ts",
9
+ "**/*.test.ts",
10
+ "**/__test__/*"
11
+ ]
12
+ }