8000 Adding helpers for Cluster specific object files by dhchandw · Pull Request #1603 · project-chip/zap · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Adding helpers for Cluster specific object files #1603

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 2 commits into from
Jun 9, 2025

Conversation

dhchandw
Copy link
Collaborator
@dhchandw dhchandw commented Jun 2, 2025

No description provided.

Copy link
@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello @dhchandw, 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!

Summary of Changes

Hello team, gemini-code-assist here to provide a summary of this pull request. This PR, titled "Adding helpers for Cluster specific object files", introduces several new helper functions primarily aimed at improving the templating and code generation process for Matter/CHIP cluster-specific objects. The changes focus on adding helpers for handling access control roles, and extracting quality flags for attributes and commands. It also includes a minor helper for generating names based on IDs, with a specific case for 'RFID'. The documentation is updated to reflect the new helpers.

Highlights

  • New Access Helpers: Two new helpers, chipGetAccessRole and chipAsPrivilege, are added to helper-access.js. chipGetAccessRole determines the access role for a given entity (like attribute or command) and operation (read, write, invoke) based on the access list, falling back to default mappings if needed. chipAsPrivilege maps a role string (view, operate, manage, administer) to its corresponding Matter Access::Privilege constant string.
  • Attribute Quality Flags Helper: A new helper extractAttributeQualityFlags is added to helper-attribute.js. This function extracts relevant quality flags for an attribute based on its properties, specifically checking for mustUseTimedWrite and isArray to return DataModel::AttributeQualityFlags::kTimed and DataModel::AttributeQualityFlags::kListAttribute respectively.
  • Command Quality Flags Helper: A new helper extractCommandQualityFlags is added to helper-command.js. Similar to the attribute helper, this function extracts quality flags for a command, checking for isFabricScoped and mustUseTimedInvoke to return DataModel::CommandQualityFlags::kFabricScoped and DataModel::CommandQualityFlags::kTimed.
  • Naming Helper: A new helper chip_name_for_id_usage is added to helper.js within the Matter app templates. This helper converts a label to UpperCamelCase, with a specific override to handle 'RFID' as 'Rfid'.
  • Documentation Updates: The documentation file docs/helpers.md is updated to include the newly added access, attribute, and command helpers, providing descriptions and usage details.

Changelog

Click here to see the changelog
  • docs/helpers.md
    • Added documentation link for chipGetAccessRole and chipAsPrivilege to the Access helpers list (lines 57-58).
    • Added detailed documentation for chipGetAccessRole including description, parameters, return value, and throws information (lines 123-137).
    • Added detailed documentation for chipAsPrivilege including description, parameters, and return value (lines 139-149).
    • Added documentation link for extractAttributeQualityFlags to the Attribute helpers list (line 158).
    • Added detailed documentation for extractAttributeQualityFlags including description and return value (lines 163-169).
    • Added documentation link for extractCommandQualityFlags to the Command helpers list (line 663).
    • Added detailed documentation for extractCommandQualityFlags including description and return value (lines 866-872).
  • src-electron/generator/helper-access.js
    • Added chipGetAccessRole function to determine access roles based on operation and entity type, with default mappings (lines 240-267).
    • Added chipAsPrivilege function to map role strings to Matter privilege constants (lines 269-283).
    • Exported the new chipGetAccessRole and chipAsPrivilege functions (lines 289-290).
  • src-electron/generator/helper-attribute.js
    • Added extractAttributeQualityFlags function to extract quality flags like Timed and ListAttribute based on attribute properties (lines 30-48).
    • Exported the new extractAttributeQualityFlags function (line 195).
  • src-electron/generator/helper-command.js
    • Added extractCommandQualityFlags function to extract quality flags like FabricScoped and Timed based on command properties (lines 408-427).
    • Exported the new extractCommandQualityFlags function (line 468).
  • src-electron/generator/matter/app/zap-templates/templates/app/helper.js
    • Added chip_name_for_id_usage function to convert labels to UpperCamelCase, handling 'RFID' specifically (lines 598-602).
    • Exported the new chip_name_for_id_usage function (line 1282).
Using Gemini Code Assist

The 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 in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in issue comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist is currently in preview and 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 to provide feedback.

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.


New helpers arrive,
Code generation comes alive,
Docs explain their use.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
@gemini-code-assist gemini-code-assist bot left a 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 several new helper functions for templating, focusing on cluster-specific object file generation, particularly around access control and attribute/command quality flags. The added functionalities seem useful.

Key areas for improvement include ensuring consistency in how these helper functions are documented versus how they are exported and used in templates, and refining some JSDoc parameter descriptions.

While not part of the diff, consider adding unit tests for the new helper functions, especially for chipGetAccessRole which contains conditional logic, to ensure their correctness and maintainability.

Summary of Findings

  • Documentation and Export Naming Inconsistency: Helper functions are documented with camelCase names (e.g., chipGetAccessRole) in docs/helpers.md, but exported and used in templates with snake_case names (e.g., chip_get_access_role). This should be made consistent, preferably by updating the documentation to reflect the exported names. (Severity: High)
  • JSDoc Parameter Specificity: The options parameter for chipGetAccessRole is typed as * in JSDoc and documentation. Using object or a more specific type definition would improve clarity. The description for this parameter is also missing in docs/helpers.md. (Severity: Medium)
  • Maintainability of Special Case Naming: The chip_name_for_id_usage helper includes a hardcoded special case for 'RFID'. While acceptable for a single instance, this approach might become difficult to maintain if more special naming rules are needed. (Severity: Medium)
  • Documentation Typo: In docs/helpers.md, the return descriptions for extractAttributeQualityFlags and extractCommandQualityFlags contain a double hyphen (- -), which appears to be a typo. (Severity: Low, not commented due to settings)

Merge Readiness

The pull request introduces valuable helper functions. However, there are several issues, primarily concerning documentation consistency and JSDoc clarity, that should be addressed before merging. The naming inconsistency between documentation and exported helper names is a high-severity issue that could lead to confusion for template developers. I am unable to approve this pull request myself; please ensure these changes are reviewed and approved by others after the suggested modifications are made.

@dhchandw dhchandw force-pushed the task/csaHelpers branch 2 times, most recently from 5cf6b9d to 7fe3202 Compare June 2, 2025 18:25
@dhchandw dhchandw requested a review from brdandu June 3, 2025 20:52
* @returns {string}
*/
function chip_name_for_id_usage(label, options) {
if (label == 'RFID') {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if we did {{#if (uppercase variable)}} {{as_upper_camel_case (lower_case variable)}}{{/if}} ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could do this but this particular function is used 9 times for cluster specific object files

return accessForOp.role
}

// Default role mappings
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Forgot, Didn't we discuss to get rid of the defaults and move it to templates?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I kept the default values for chip_get_access_role() based of the chip_access_elements() helper in src-electron/generator/matter/app/zap-templates/templates/chip/helper.js

@dhchandw dhchandw merged commit e76a9f0 into project-chip:master Jun 9, 2025
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants
0