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.
- package/dist/initialData/getSupportedAreas.js +4 -4
- package/dist/model/RoomMap.js +0 -6
- package/dist/platform.js +5 -2
- package/jest.config.js +19 -0
- 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/initialData/getSupportedAreas.test.ts +55 -0
- package/src/initialData/getSupportedAreas.ts +4 -21
- package/src/model/RoomMap.ts +6 -6
- package/src/platform.ts +7 -2
- package/tsconfig.jest.json +12 -0
|
@@ -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:
|
|
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:
|
|
40
|
+
areaId: 2,
|
|
41
41
|
mapId: null,
|
|
42
42
|
areaInfo: {
|
|
43
43
|
locationInfo: {
|
package/dist/model/RoomMap.js
CHANGED
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.
|
|
75
|
-
const firstDUID = this.
|
|
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,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"title": "Matterbridge Roborock Vacuum Plugin",
|
|
3
|
-
"description": "matterbridge-roborock-vacuum-plugin v. 1.0.7-
|
|
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
|
@@ -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:
|
|
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:
|
|
48
|
+
areaId: 2,
|
|
66
49
|
mapId: null,
|
|
67
50
|
areaInfo: {
|
|
68
51
|
locationInfo: {
|
package/src/model/RoomMap.ts
CHANGED
|
@@ -34,11 +34,11 @@ export default class RoomMap {
|
|
|
34
34
|
});
|
|
35
35
|
}
|
|
36
36
|
|
|
37
|
-
getGlobalId(id: number): number | undefined {
|
|
38
|
-
|
|
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
|
-
|
|
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 (
|
|
99
|
-
const firstDUID =
|
|
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));
|