Skip to content

Changing the data type by name helpers to use data type name and cluster#1669

Merged
brdandu merged 1 commit intoproject-chip:masterfrom
brdandu:feature/updateHelpersToUseDataTypeByNameAndCluster/ZAP#1592
Nov 13, 2025
Merged

Changing the data type by name helpers to use data type name and cluster#1669
brdandu merged 1 commit intoproject-chip:masterfrom
brdandu:feature/updateHelpersToUseDataTypeByNameAndCluster/ZAP#1592

Conversation

@brdandu
Copy link
Collaborator

@brdandu brdandu commented Nov 10, 2025

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @brdandu, 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 the accuracy of ZCL data type resolution within the system by introducing cluster-awareness. The primary goal is to prevent ambiguities and errors that arise when data types with identical names exist in different ZCL clusters. This is achieved by implementing a new function that prioritizes cluster-specific type definitions, leading to more robust and precise data handling throughout the application. Additionally, older, less accurate helpers have been deprecated, and documentation has been updated to reflect these changes.

Highlights

  • Cluster-Aware Data Type Resolution: Introduced a new utility function, getSignAndSizeOfZclTypeAndClusterId, which accurately determines ZCL data type properties (sign and size) by first checking for cluster-specific definitions before falling back to global ones. This ensures correct handling of data types that might have the same name but different definitions across clusters.
  • Updated Helper Functions and Validation: Various helper functions and validation logic across the codebase have been updated to utilize the new cluster-aware data type resolution. This includes changes in helper-endpointconfig.js, helper-zcl.js, and validation.js to pass cluster context when resolving type information.
  • Deprecated Helpers: The as_bytes and data_type_for_enum helpers in helper-c.js have been explicitly deprecated. This is due to their inability to correctly handle cluster-specific data types, and deprecation messages have been added to guide developers.
  • Enhanced Documentation: Documentation for ZCL helpers (as_type_min_value, as_type_max_value, as_zcl_type_size) in docs/helpers.md has been updated to reflect the new clusterId option, improving clarity for template developers.
  • Exact Type Size Calculation: A noCeiling option has been added to type size calculation functions, allowing for the retrieval of exact type sizes without rounding up to the nearest power of 2.
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 by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

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 pull request 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 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

  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
Contributor

@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 a necessary change to handle cluster-specific data types by adding a clusterId to the type resolution logic. The new function getSignAndSizeOfZclTypeAndClusterId and its integration into various helpers are well-implemented. The documentation has also been updated accordingly.

My review includes a few suggestions to improve maintainability by reducing code duplication in helper-zcl.js and types.js. I also found a minor bug in helper-c.js where a helper is exported twice, and a typo in a log message in types.js. Overall, this is a good improvement.

@brdandu brdandu force-pushed the feature/updateHelpersToUseDataTypeByNameAndCluster/ZAP#1592 branch from cb3f402 to 6cb445e Compare November 11, 2025 12:34
Copy link
Collaborator

@tecimovic tecimovic left a comment

Choose a reason for hiding this comment

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

Generally looks good, but I have no way of being able to go into details of this...

@brdandu brdandu force-pushed the feature/updateHelpersToUseDataTypeByNameAndCluster/ZAP#1592 branch from 193d651 to 807c101 Compare November 13, 2025 11:10
- Updating types.getSignAndSizeOfZclType to types.getSignAndSizeOfZclTypeAndClusterId for better accuracy and avoiding duplicate data types across clusters.
- updating the code associated with the above as required in the code.
- deprecating as_bytes and data_types_for_enum as they are no longer used.

- Handling clusterId for all the helpers. Now the helpers can mention clusterId=ID-NUMBER along with the helpers in .zapt templates to account for the helpers. The helpers in helpers.js files now extract this from the this object automatically

- Updating the feature level of zap

- Adding unit tests for the as_underlying_zcl_type helper with cluster Id reference
- Github: ZAP project-chip#1592
@brdandu brdandu force-pushed the feature/updateHelpersToUseDataTypeByNameAndCluster/ZAP#1592 branch from 807c101 to 2708354 Compare November 13, 2025 11:11
@brdandu brdandu merged commit aa68383 into project-chip:master Nov 13, 2025
14 checks passed
- language: determines the output of the helper based on language
for eg: (as_type_min_value language='c++') will give the output specific to
the c++ language.
- clusterId: The ID of the cluster the type belongs to
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this the "id" in the sense of database ID, or the "id" in the sense of the actual spec-defined cluster identifier? It's not obvious just looking at this documentation.

- language: determines the output of the helper based on language
for eg: (as_type_max_value language='c++') will give the output specific to
the c++ language.
- clusterId: The ID of the cluster the type belongs to
Copy link
Contributor

Choose a reason for hiding this comment

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

As above.

| Param | Type | Description |
| --- | --- | --- |
| type | <code>\*</code> | |
| options | <code>\*</code> | Available Options: - clusterId: The ID of the cluster the type belongs to |
Copy link
Contributor

Choose a reason for hiding this comment

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

As above.

* [~nullStringDefaultValue(type)](#module_JS API_ type related utilities..nullStringDefaultValue) ⇒ <code>string</code>
* [~processZclTypeSignAndSize(db, dataType, type, packageIds, options, clusterId, clusterName)](#module_JS API_ type related utilities..processZclTypeSignAndSize) ⇒
* [~getSignAndSizeOfZclType(type, context, options)](#module_JS API_ type related utilities..getSignAndSizeOfZclType) ⇒
* [~getSignAndSizeOfZclTypeAndClusterId(db, type, clusterId, packageIds, options)](#module_JS API_ type related utilities..getSignAndSizeOfZclTypeAndClusterId) ⇒ <code>size:&#x27;bits&#x27;</code>
Copy link
Contributor

Choose a reason for hiding this comment

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

See above about id.

| type | <code>\*</code> | | The type name (for error logging) |
| packageIds | <code>\*</code> | | Package IDs |
| options | <code>\*</code> | | Processing options |
| clusterId | <code>\*</code> | <code></code> | Optional cluster ID for cluster-specific queries |
Copy link
Contributor

Choose a reason for hiding this comment

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

See above.

| --- | --- |
| db | <code>\*</code> |
| type | <code>\*</code> |
| clusterId | <code>\*</code> |
Copy link
Contributor

Choose a reason for hiding this comment

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

As above.

| --- | --- |
| db | <code>\*</code> |
| enum_name | <code>\*</code> |
| clusterId | <code>\*</code> |
Copy link
Contributor

Choose a reason for hiding this comment

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

I'll stop commenting on this, but it's a general problem in all these APIs.

}

/**
* Given a zcl device type returns its sign, size and zcl data type info stored
Copy link
Contributor

Choose a reason for hiding this comment

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

This has nothing to do with "device type"....

}

/**
* Given a zcl device type and cluster name returns its sign, size and zcl data type info stored
Copy link
Contributor

Choose a reason for hiding this comment

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

Again, not "device type".

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.

selectEnumByName and selectBitmapByName need to switch to selectEnumByNameAndClusterName and selectBitmapByNameAndClusterName

4 participants