@matterbridge/jest-utils 3.8.0 → 3.8.1-dev-20260606-d6bb335

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.
@@ -1,6 +1,8 @@
1
1
  import '@matter/nodejs';
2
2
  import { Environment } from '@matter/general';
3
3
  import { Endpoint, ServerNode } from '@matter/node';
4
+ import { BridgedDeviceBasicInformationServer } from '@matter/node/behaviors/bridged-device-basic-information';
5
+ import { OnOffServer } from '@matter/node/behaviors/on-off';
4
6
  import { AggregatorEndpoint } from '@matter/node/endpoints';
5
7
  import { DeviceTypeId } from '@matter/types/datatype';
6
8
  import { type PlatformMatterbridge } from '@matterbridge/types';
@@ -10,6 +12,60 @@ export declare let aggregator: Endpoint<AggregatorEndpoint>;
10
12
  export declare function createTestEnvironment(): Promise<Environment>;
11
13
  export declare function destroyTestEnvironment(): Promise<void>;
12
14
  export declare function getMatterbridge(): Promise<PlatformMatterbridge>;
15
+ export declare const addBridgedEndpointMatterbridgeSpy: import("jest-mock").Mock<(pluginName: string, device: Endpoint) => Promise<boolean>>;
16
+ export declare const removeBridgedEndpointMatterbridgeSpy: import("jest-mock").Mock<(pluginName: string, device: Endpoint) => Promise<boolean>>;
17
+ export declare const removeAllBridgedEndpointsMatterbridgeSpy: import("jest-mock").Mock<(pluginName: string, _delay?: number) => Promise<boolean>>;
18
+ export declare const addVirtualEndpointMatterbridgeSpy: import("jest-mock").Mock<(pluginName: string, name: string, type: "light" | "outlet" | "switch" | "mounted_switch", callback: () => Promise<void>) => Promise<Endpoint<import("@matter/node").MutableEndpoint.With<import("@matter/node").EndpointType.For<{
19
+ readonly name: "MountedOnOffControl";
20
+ readonly deviceType: 271;
21
+ readonly deviceRevision: 2;
22
+ readonly requirements: typeof import("@matter/node/devices/mounted-on-off-control").MountedOnOffControlRequirements;
23
+ readonly behaviors: {
24
+ readonly identify: import("@matter/node").ClusterBehavior.Type<typeof import("@matter/node/behaviors").IdentifyServer, import("@matter/types").ClusterType.WithEnabledAttributes<import("@matter/types").ClusterType.WithEnabledEvents<import("@matter/types/clusters/identify").Identify, never>, never>, import("@matter/types").ClusterType.Concrete, typeof import("@matter/node/behaviors").IdentifyServer.Internal, "identify">;
25
+ } & {
26
+ readonly groups: typeof import("@matter/node/behaviors").GroupsServer;
27
+ } & {
28
+ readonly onOff: import("@matter/node").ClusterBehavior.Type<typeof OnOffServer, import("@matter/types").ClusterType.WithSupportedFeatures<import("@matter/types").ClusterType.WithSupportedFeatures<import("@matter/types").ClusterType.WithSupportedFeatures<import("@matter/types/clusters/on-off").OnOff, {
29
+ deadFrontBehavior: false;
30
+ lighting: true;
31
+ offOnly: false;
32
+ }>, {
33
+ deadFrontBehavior: false;
34
+ lighting: false;
35
+ offOnly: false;
36
+ }>, {
37
+ deadFrontBehavior: false;
38
+ lighting: true;
39
+ offOnly: false;
40
+ }>, import("@matter/types").ClusterType.Concrete, typeof import("@matter/node/behaviors/on-off").OnOffBaseServer.Internal, "onOff">;
41
+ } & {
42
+ readonly scenesManagement: import("@matter/node").ClusterBehavior.Type<typeof import("@matter/node/behaviors").ScenesManagementServer, import("@matter/types").ClusterType.WithEnabledAttributes<import("@matter/types").ClusterType.WithEnabledEvents<import("@matter/types").ClusterType.WithSupportedFeatures<import("@matter/types/clusters/scenes-management").ScenesManagement, {
43
+ sceneNames: true;
44
+ }>, never>, never>, import("@matter/types").ClusterType.Concrete, typeof import("@matter/node/behaviors").ScenesManagementServer.Internal, "scenesManagement">;
45
+ };
46
+ }>, import("@matter/node").SupportedBehaviors.With<{
47
+ readonly identify: import("@matter/node").ClusterBehavior.Type<typeof import("@matter/node/behaviors").IdentifyServer, import("@matter/types").ClusterType.WithEnabledAttributes<import("@matter/types").ClusterType.WithEnabledEvents<import("@matter/types/clusters/identify").Identify, never>, never>, import("@matter/types").ClusterType.Concrete, typeof import("@matter/node/behaviors").IdentifyServer.Internal, "identify">;
48
+ } & {
49
+ readonly groups: typeof import("@matter/node/behaviors").GroupsServer;
50
+ } & {
51
+ readonly onOff: import("@matter/node").ClusterBehavior.Type<typeof OnOffServer, import("@matter/types").ClusterType.WithSupportedFeatures<import("@matter/types").ClusterType.WithSupportedFeatures<import("@matter/types").ClusterType.WithSupportedFeatures<import("@matter/types/clusters/on-off").OnOff, {
52
+ deadFrontBehavior: false;
53
+ lighting: true;
54
+ offOnly: false;
55
+ }>, {
56
+ deadFrontBehavior: false;
57
+ lighting: false;
58
+ offOnly: false;
59
+ }>, {
60
+ deadFrontBehavior: false;
61
+ lighting: true;
62
+ offOnly: false;
63
+ }>, import("@matter/types").ClusterType.Concrete, typeof import("@matter/node/behaviors/on-off").OnOffBaseServer.Internal, "onOff">;
64
+ } & {
65
+ readonly scenesManagement: import("@matter/node").ClusterBehavior.Type<typeof import("@matter/node/behaviors").ScenesManagementServer, import("@matter/types").ClusterType.WithEnabledAttributes<import("@matter/types").ClusterType.WithEnabledEvents<import("@matter/types").ClusterType.WithSupportedFeatures<import("@matter/types/clusters/scenes-management").ScenesManagement, {
66
+ sceneNames: true;
67
+ }>, never>, never>, import("@matter/types").ClusterType.Concrete, typeof import("@matter/node/behaviors").ScenesManagementServer.Internal, "scenesManagement">;
68
+ }, readonly [typeof BridgedDeviceBasicInformationServer]>, {}>>>>;
13
69
  export declare function addMatterbridge(platform: object): void;
14
70
  export declare function flushAllEndpointNumberPersistence(targetServer: ServerNode, rounds?: number, ticks?: number, microTurns?: number, pause?: number): Promise<void>;
15
71
  export declare function assertAllEndpointNumbersPersisted(targetServer: ServerNode): Promise<number>;
@@ -1,8 +1,13 @@
1
1
  import '@matter/nodejs';
2
2
  import path from 'node:path';
3
3
  import { inspect } from 'node:util';
4
+ import { jest } from '@jest/globals';
4
5
  import { Environment, Lifecycle, LogFormat as MatterLogFormat, LogLevel as MatterLogLevel } from '@matter/general';
5
6
  import { Endpoint, ServerNode, ServerNodeStore } from '@matter/node';
7
+ import { BridgedDeviceBasicInformationServer } from '@matter/node/behaviors/bridged-device-basic-information';
8
+ import { DescriptorServer } from '@matter/node/behaviors/descriptor';
9
+ import { OnOffServer } from '@matter/node/behaviors/on-off';
10
+ import { MountedOnOffControlDevice } from '@matter/node/devices/mounted-on-off-control';
6
11
  import { AggregatorEndpoint } from '@matter/node/endpoints';
7
12
  import { DeviceTypeId, VendorId } from '@matter/types/datatype';
8
13
  import { MATTER_STORAGE_DIR } from '@matterbridge/types';
@@ -27,7 +32,6 @@ export async function createTestEnvironment() {
27
32
  export async function destroyTestEnvironment() {
28
33
  }
29
34
  export async function getMatterbridge() {
30
- const { jest } = await import('@jest/globals');
31
35
  const matterbridge = {
32
36
  systemInformation: {
33
37
  interfaceName: 'eth0',
@@ -58,10 +62,10 @@ export async function getMatterbridge() {
58
62
  matterbridgePluginDirectory: path.join(HOMEDIR, 'Matterbridge'),
59
63
  matterbridgeCertDirectory: path.join(HOMEDIR, '.mattercert'),
60
64
  globalModulesDirectory: path.join(HOMEDIR, 'node_modules'),
61
- matterbridgeVersion: '3.8.0',
62
- matterbridgeLatestVersion: '3.8.0',
63
- matterbridgeDevVersion: '3.8.0',
64
- frontendVersion: '3.8.0',
65
+ matterbridgeVersion: '3.8.1',
66
+ matterbridgeLatestVersion: '3.8.1',
67
+ matterbridgeDevVersion: '3.8.1',
68
+ frontendVersion: '3.8.1',
65
69
  bridgeMode: '',
66
70
  restartMode: '',
67
71
  virtualMode: 'mounted_switch',
@@ -70,25 +74,58 @@ export async function getMatterbridge() {
70
74
  aggregatorProductId: 0x8000,
71
75
  aggregatorProductName: 'Matterbridge Jest',
72
76
  };
73
- const injectedFunctions = {
74
- addBridgedEndpoint: jest.fn(async () => {
75
- return Promise.resolve(true);
76
- }),
77
- removeBridgedEndpoint: jest.fn(async () => {
78
- return Promise.resolve(true);
79
- }),
80
- removeAllBridgedEndpoints: jest.fn(async () => {
81
- return Promise.resolve(true);
82
- }),
83
- addVirtualEndpoint: jest.fn(async () => {
84
- return Promise.resolve(true);
85
- }),
86
- };
87
- return { ...matterbridge, ...injectedFunctions };
77
+ return matterbridge;
88
78
  }
79
+ const addBridgedEndpoint = jest.fn(async (pluginName, device) => {
80
+ await aggregator.add(device);
81
+ return Promise.resolve(true);
82
+ });
83
+ const removeBridgedEndpoint = jest.fn(async (pluginName, device) => {
84
+ await device.delete();
85
+ return Promise.resolve(true);
86
+ });
87
+ const removeAllBridgedEndpoints = jest.fn(async (pluginName, _delay = 0) => {
88
+ for (const device of aggregator.parts) {
89
+ await device.delete();
90
+ }
91
+ return Promise.resolve(true);
92
+ });
93
+ const addVirtualEndpoint = jest.fn(async (pluginName, name, type, callback) => {
94
+ const device = new Endpoint(MountedOnOffControlDevice.with(BridgedDeviceBasicInformationServer), {
95
+ id: name.replaceAll(' ', '') + ':' + type,
96
+ bridgedDeviceBasicInformation: {
97
+ vendorId: VendorId(0xfff1),
98
+ vendorName: 'Matterbridge',
99
+ productName: 'Matterbridge Virtual Device',
100
+ nodeLabel: name.slice(0, 32),
101
+ softwareVersion: 20000,
102
+ softwareVersionString: '2.0.0',
103
+ },
104
+ onOff: { onOff: false },
105
+ });
106
+ device.events.onOff.onOff$Changed.on((value) => {
107
+ if (value) {
108
+ void callback().catch(() => { });
109
+ void device.setStateOf(OnOffServer, { onOff: false }).catch(() => { });
110
+ }
111
+ });
112
+ await aggregator.add(device);
113
+ if (type === 'mounted_switch') {
114
+ await device.act(async (agent) => {
115
+ const descriptor = await agent.load(DescriptorServer);
116
+ descriptor.addDeviceTypes('OnOffPlugInUnit');
117
+ });
118
+ }
119
+ await device.setStateOf(OnOffServer, { onOff: false });
120
+ return device;
121
+ });
122
+ export const addBridgedEndpointMatterbridgeSpy = addBridgedEndpoint;
123
+ export const removeBridgedEndpointMatterbridgeSpy = removeBridgedEndpoint;
124
+ export const removeAllBridgedEndpointsMatterbridgeSpy = removeAllBridgedEndpoints;
125
+ export const addVirtualEndpointMatterbridgeSpy = addVirtualEndpoint;
89
126
  export function addMatterbridge(platform) {
90
127
  expect(platform).toBeDefined();
91
- platform.setMatterNode(platform.matterbridge.addBridgedEndpoint, platform.matterbridge.removeBridgedEndpoint, platform.matterbridge.removeAllBridgedEndpoints, platform.matterbridge.addVirtualEndpoint);
128
+ platform.setMatterNode(addBridgedEndpoint, removeBridgedEndpoint, removeAllBridgedEndpoints, addVirtualEndpoint);
92
129
  }
93
130
  export async function flushAllEndpointNumberPersistence(targetServer, rounds = 3, ticks = 1, microTurns = 1, pause = 10) {
94
131
  const nodeStore = targetServer.env.get(ServerNodeStore);
@@ -154,7 +191,8 @@ export async function createServerNode(port, deviceType = DeviceTypeId(0x000e),
154
191
  vendorName: 'Matterbridge',
155
192
  productId: 0x8000,
156
193
  productName: ('Matterbridge ' + NAME).slice(0, 32),
157
- nodeLabel: NAME + 'ServerNode',
194
+ productLabel: ('Label ' + NAME).slice(0, 64),
195
+ nodeLabel: (NAME + 'ServerNode').slice(0, 32),
158
196
  hardwareVersion: 1,
159
197
  softwareVersion: 1,
160
198
  reachable: true,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@matterbridge/jest-utils",
3
- "version": "3.8.0",
3
+ "version": "3.8.1-dev-20260606-d6bb335",
4
4
  "description": "Matterbridge jest utility library",
5
5
  "author": "https://github.com/Luligu",
6
6
  "homepage": "https://matterbridge.io/",
@@ -65,7 +65,7 @@
65
65
  "CHANGELOG.md"
66
66
  ],
67
67
  "dependencies": {
68
- "@matterbridge/types": "3.8.0",
68
+ "@matterbridge/types": "3.8.1-dev-20260606-d6bb335",
69
69
  "node-ansi-logger": "3.3.0-dev-20260524-cac9dd5"
70
70
  }
71
71
  }