8000 Fix Groups implementation by Apollon77 · Pull Request #2197 · project-chip/matter.js · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Fix Groups implementation #2197

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 26, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,16 @@ export class GroupKeyManagementServer extends GroupKeyManagementBehavior {
}
this.state.groupTable[existingGroupIndex].groupName = groupName;
} else {
if (
this.state.groupTable.filter(({ fabricIndex: entryFabricIndex }) => entryFabricIndex === fabricIndex)
.length >= this.state.maxGroupsPerFabric
) {
throw new StatusResponseError(
`Too many groups for fabric ${fabricIndex}, maximum is ${this.state.maxGroupsPerFabric}`,
StatusCode.ResourceExhausted,
);
}

// Create a new group entry
this.state.groupTable.push({
groupId,
Expand All @@ -454,7 +464,8 @@ export class GroupKeyManagementServer extends GroupKeyManagementBehavior {
const fabricIndex = fabric.fabricIndex;

// Remove the endpoint from all groups
for (const entry of groupTable) {
for (let i = groupTable.length - 1; i >= 0; i--) {
const entry = groupTable[i];
if (entry.fabricIndex !== fabricIndex || (groupId !== undefined && entry.groupId !== groupId)) {
continue;
}
Expand All @@ -463,8 +474,7 @@ export class GroupKeyManagementServer extends GroupKeyManagementBehavior {
if (entry.endpoints.length === 1 && entry.endpoints[0] === endpointId) {
const groupId = entry.groupId;
// If no endpoints left, remove the group entry
const index = groupTable.indexOf(entry);
groupTable.splice(index, 1);
groupTable.splice(i, 1);
fabric.groups.endpoints.delete(groupId);
} else {
entry.endpoints = entry.endpoints.filter(id => id !== endpointId);
Expand Down
9 changes: 4 additions & 5 deletions packages/node/src/behaviors/groups/GroupsServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { IdentifyBehavior } from "#behaviors/identify";
import { Groups } from "#clusters/groups";
import { Endpoint } from "#endpoint/Endpoint.js";
import { RootEndpoint } from "#endpoints/root";
import { Logger } from "#general";
import { InternalError, Logger } from "#general";
import { AccessLevel } from "#model";
import {
Command,
Expand All @@ -21,14 +21,10 @@ import {
TlvObject,
TlvString,
} from "#types";
import { InternalError } from "@matter/general";
import { GroupsBehavior } from "./GroupsBehavior.js";

const logger = Logger.get("GroupsServer");

// We enable group names by default
const GroupsBase = GroupsBehavior.with(Groups.Feature.GroupNames);

/**
* Monkey patching Tlv Structure of addGroup* commands to prevent data validation of the groupName field to be
* handled as ConstraintError because we need to return a special error.
Expand Down Expand Up @@ -58,6 +54,9 @@ Groups.Cluster.commands = {
),
};

// We enable group names by default
const GroupsBase = GroupsBehavior.with(Groups.Feature.GroupNames);

/**
* This is the default server implementation of {@link GroupsBehavior}.
*/
Expand Down
Loading
0