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
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
13 changes: 13 additions & 0 deletions docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -8915,6 +8915,7 @@ This module contains the API for templating. For more detailed instructions, rea
* [~access_aggregate(options)](#module_Templating API_ Access helpers..access_aggregate)
* [~access(options)](#module_Templating API_ Access helpers..access)
* [~default_access(options)](#module_Templating API_ Access helpers..default_access) ⇒
* [~chip_get_access_role(options)](#module_Templating API_ Access helpers..chip_get_access_role) ⇒ <code>string</code>

<a name="module_Templating API_ Access helpers..collectDefaultAccessList"></a>

Expand Down Expand Up @@ -8979,6 +8980,18 @@ Get the access list information.
| --- | --- |
| options | <code>\*</code> |

<a name="module_Templating API_ Access helpers..chip_get_access_role"></a>

### Templating API: Access helpers~chip\_get\_access\_role(options) ⇒ <code>string</code>
Determines the access role for a given entity and operation.

**Kind**: inner method of [<code>Templating API: Access helpers</code>](#module_Templating API_ Access helpers)
**Returns**: <code>string</code> - The access role.

| Param | Type |
| --- | --- |
| options | <code>\*</code> |

<a name="module_Templating API_ Attribute helpers"></a>

## Templating API: Attribute helpers
Expand Down
13 changes: 13 additions & 0 deletions docs/helpers.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ This module contains the API for templating. For more detailed instructions, rea
* [~access_aggregate(options)](#module_Templating API_ Access helpers..access_aggregate)
* [~access(options)](#module_Templating API_ Access helpers..access)
* [~default_access(options)](#module_Templating API_ Access helpers..default_access) ⇒
* [~chip_get_access_role(options)](#module_Templating API_ Access helpers..chip_get_access_role) ⇒ <code>string</code>

<a name="module_Templating API_ Access helpers..collectDefaultAccessList"></a>

Expand Down Expand Up @@ -118,6 +119,18 @@ Get the access list information.
| --- | --- |
| options | <code>\*</code> |

<a name="module_Templating API_ Access helpers..chip_get_access_role"></a>

### Templating API: Access helpers~chip\_get\_access\_role(options) ⇒ <code>string</code>
Determines the access role for a given entity and operation.

**Kind**: inner method of [<code>Templating API: Access helpers</code>](#module_Templating API_ Access helpers)
**Returns**: <code>string</code> - The access role.

| Param | Type |
| --- | --- |
| options | <code>\*</code> |

<a name="module_Templating API_ Attribute helpers"></a>

## Templating API: Attribute helpers
Expand Down
27 changes: 27 additions & 0 deletions src-electron/generator/helper-access.js
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,33 @@ async function default_access(options) {
return templateUtil.templatePromise(this.global, p)
}

/**
* Determines the access role for a given entity and operation.
*
* @param {*} options
* @returns {string} The access role.
*/
async function chip_get_access_role(options) {
if (!('op' in options.hash)) {
throw new Error('Access helper requires op from the op="<op>" option.')
}

const op = options.hash.op
const accessList = await collectAccesslist(this, options)
const accessForOp = accessList.find((a) => a.operation === op)

if (accessForOp?.role) {
return accessForOp.role
}

if ('default' in options.hash) {
return options.hash.default
}

return ''
}

exports.access = access
exports.access_aggregate = access_aggregate
exports.default_access = default_access
exports.chip_get_access_role = chip_get_access_role
Original file line number Diff line number Diff line change
Expand Up @@ -594,6 +594,20 @@ function asUpperCamelCase(label, options) {
const preserveAcronyms = options && options.hash.preserveAcronyms;
return asCamelCase(label, false, preserveAcronyms);
}
/**
* Same as asUpperCamelCase, but with a special case for "RFID".
* Special case for cluster specific object files for Matter.
*
* @param {*} label
* @param {*} options
* @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 'Rfid';
}
return asUpperCamelCase(label, options);
}

function chip_friendly_endpoint_type_name(options) {
let name = this.endpointTypeName;
Expand Down Expand Up @@ -1272,6 +1286,7 @@ exports.zcl_commands_that_need_timed_invoke =
zcl_commands_that_need_timed_invoke;
exports.if_is_fabric_scoped_struct = if_is_fabric_scoped_struct;
exports.if_is_non_zero_default = if_is_non_zero_default;
exports.chip_name_for_id_usage = chip_name_for_id_usage;

exports.meta = {
category: dbEnum.helperCategory.matter,
Expand Down
8 changes: 8 additions & 0 deletions test/gen-matter-3-1.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -570,6 +570,14 @@ test(
zclPackageId
)
expect(globalBitmap.id).not.toEqual(clusterBitmap.id)

// Testing chip_get_access_role for attributes
expect(ept).toContain(
'Name - Acl, Read Privilege - Administer, Write Privilege - Administer'
)

// Testing chip_get_access_role for commands
expect(ept).toContain('Name - KeySetWrite, Invoke Privilege - Administer')
},
testUtil.timeout.long()
)
Expand Down
12 changes: 12 additions & 0 deletions test/gen-template/matter3/miscellaneous_helper_tests.zapt
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,15 @@ SemanticTagStruct item {{index}} from Identify cluster: {{name}}
{{#if struct_contains_array}} Struct with array: {{name}}
{{/if}}
{{/zcl_structs}}

// Test chip_get_access_role for attributes
{{#zcl_attributes_server}}
{{#if clusterRef}}
Name - {{asUpperCamelCase label}}, Read Privilege - {{asUpperCamelCase (chip_get_access_role entity="attribute" op="read" default="view")}}, {{#if isWritableAttribute}}Write Privilege - {{asUpperCamelCase (chip_get_access_role entity="attribute" op="write" default="operate")}}{{/if}}
{{/if}}
{{/zcl_attributes_server}}

// Test chip_get_access_role for commands
{{#zcl_commands_source_client}}
Name - {{asUpperCamelCase name}}, Invoke Privilege - {{asUpperCamelCase (chip_get_access_role entity="command" op="invoke" default="operate")}}
{{/zcl_commands_source_client}}
0