-
Notifications
You must be signed in to change notification settings - Fork 91
Endpoint composition gui #1672
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
base: master
Are you sure you want to change the base?
Endpoint composition gui #1672
Conversation
…ements functionality. Added new database queries and REST API endpoints to retrieve device type composition requirements. Enhanced loadComposition and addEndpoint functions to automatically create required endpoints based on composition constraints. Updated template to reflect new requirements in endpoint configuration.
- Remove redundant recursion by adding skipCompositionCheck parameter to addEndpoint - Add cycle detection using compositionChain Set to prevent infinite loops - Remove all debug console.log statements - Maintain backward compatibility with default parameter value
Summary of ChangesHello @paulr34, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request significantly enhances ZAP's capability to handle complex Matter device configurations by introducing automatic endpoint creation based on device type composition requirements. This feature ensures that when a primary device type is added, any necessary dependent device types are automatically provisioned as separate endpoints, adhering to specified conformance and constraint rules. The changes span across documentation, template helpers, backend API, database queries, and the frontend Vuex store to provide a complete and integrated solution. Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request introduces a significant feature for automatic endpoint creation based on composition requirements, which is particularly useful for Matter device types. The implementation is comprehensive, covering backend queries, REST APIs, frontend logic, and template helpers, along with documentation and tests. I've identified a few critical and high-severity issues in the endpoint creation logic that could lead to incorrect behavior, such as endpoint ID collisions and incorrect handling of constraints. Additionally, there are some minor suggestions for improving the new documentation. Overall, this is a valuable contribution that will be even stronger with these issues addressed.
| } | ||
|
|
||
| let createdEndpoints = [] | ||
| let nextEndpointId = parentEndpointIdentifier + 1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The current logic for determining nextEndpointId by simply incrementing the parentEndpointIdentifier can lead to endpoint ID collisions if an endpoint with that ID already exists. This could cause existing endpoints to be overwritten silently. To prevent this, the logic should ensure a unique endpoint ID is generated. A robust approach would be to find the maximum existing endpoint ID in the session and start incrementing from there.
let nextEndpointId =
context.rootState.zap.endpoints.reduce(
(maxId, ep) => Math.max(ep.endpointId, maxId),
0
) + 1|
|
||
| // Process each requirement | ||
| // Handle constraints - deviceConstraint might indicate minimum count (e.g., "min 1" = 1) | ||
| for (let requirement of requirementsRes.data) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code automatically creates endpoints for all composition requirements, but it doesn't check if a requirement is mandatory. This can lead to the creation of unwanted optional endpoints. The automatic creation should only apply to mandatory ('M') requirements. Please add a check for requirement.conformance at the beginning of the loop, like so:
if (requirement.conformance !== 'M') {
continue;
}| let minCount = 1 | ||
| if (requirement.deviceConstraint != null) { | ||
| // Try to parse constraint - could be a number or string like "min 1" | ||
| if (typeof requirement.deviceConstraint === 'number') { | ||
| minCount = Math.max(1, requirement.deviceConstraint) | ||
| } else if (typeof requirement.deviceConstraint === 'string') { | ||
| // Try to extract number from string like "min 1" | ||
| let match = requirement.deviceConstraint.match(/min\s*(\d+)/i) | ||
| if (match) { | ||
| minCount = parseInt(match[1], 10) | ||
| } | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The logic for parsing deviceConstraint is incomplete. It handles numbers and strings like "min 1", but it doesn't handle plain number strings like "1" or "2". This will cause it to default to creating only one endpoint, even when more are required by the constraint.
let minCount = 1
if (requirement.deviceConstraint != null) {
if (typeof requirement.deviceConstraint === 'number') {
minCount = requirement.deviceConstraint
} else if (typeof requirement.deviceConstraint === 'string') {
const match = requirement.deviceConstraint.match(/\d+/)
if (match) {
minCount = parseInt(match[0], 10)
}
}
}| {{/user_endpoints}} | ||
| ``` | ||
|
|
||
| **Note**: Automatic cluster merging (where composition-specific clusters override base clusters) is planned for future implementation. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The note about cluster merging functionality not being implemented yet is repeated multiple times in this document (e.g., lines 42, 159, 342, 413, 545, 590). To improve readability and reduce redundancy, consider consolidating this information. For example, you could keep the note in the 'Composition-Specific Clusters' section and the 'Best Practices' section, and remove the other occurrences.
| console.log(` Composition-specific clusters: ${compClusters.length}`) | ||
| compClusters.forEach((cluster) => { | ||
| console.log(` - ${cluster.clusterName}`) | ||
| }) | ||
| } | ||
|
|
||
| // 5. Get base clusters for comparison | ||
| const baseClusters = | ||
| await queryDeviceType.selectDeviceTypeClustersByDeviceTypeRef( | ||
| db, | ||
| req.requiredDeviceTypeRef | ||
| ) | ||
|
|
||
| console.log(` Base clusters: ${baseClusters.length}`) | ||
| console.log(` Composition-specific clusters: ${compClusters.length}`) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the queryCompositionData example, the logging of compClusters.length is a bit inconsistent. It's logged inside an if (compClusters.length > 0) block on line 462, and then again unconditionally on line 476. This means if there are no composition-specific clusters, it will only be logged on line 476. Consider making the logging more consistent, for example by removing the log on line 462 and only keeping the summary logs at the end.
|
|
Automatic Endpoint Creation for Device Type Composition Requirements
Note: This PR depends on the backend queries PR (#XXX). Please merge that PR first.
Overview
This PR adds automatic endpoint creation when device types have composition requirements. When adding an endpoint with a device type that requires additional endpoints (e.g., Refrigerator requires Temperature Controlled Cabinet), the required endpoints are automatically created.