Skip to content

Commit

Permalink
Stop requiring a fabric index to be provided when writing fabric-scop…
Browse files Browse the repository at this point in the history
…ed structs with chip-tool. (#17145)

It's ignored on the server anyway, so no need to require people to send it.
  • Loading branch information
bzbarsky-apple authored and pull[bot] committed Jun 3, 2022
1 parent d603053 commit f208906
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 40 deletions.
9 changes: 9 additions & 0 deletions examples/chip-tool/templates/ComplexArgumentParser-src.zapt
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,29 @@ CHIP_ERROR ComplexArgumentParser::Setup(const char * label, {{zapTypeToEncodable

{{#zcl_struct_items}}
{{#unless isOptional}}
{{~! Fabric index fields are not sent on writes, so don't force people to
provide them. ~}}
{{#unless (isStrEqual label ../struct_fabric_idx_field)}}
ReturnErrorOnFailure(ComplexArgumentParser::EnsureMemberExist("{{parent.name}}.{{asLowerCamelCase label}}", "{{asLowerCamelCase label}}", value.isMember("{{asLowerCamelCase label}}")));
{{/unless}}
{{/unless}}
{{/zcl_struct_items}}

char labelWithMember[kMaxLabelLength];
{{#zcl_struct_items}}
{{#if isOptional}}
if (value.isMember("{{asLowerCamelCase label}}"))
{
{{else if (isStrEqual label ../struct_fabric_idx_field)}}
if (value.isMember("{{asLowerCamelCase label}}"))
{
{{/if}}
snprintf(labelWithMember, sizeof(labelWithMember), "%s.%s", label, "{{asLowerCamelCase label}}");
ReturnErrorOnFailure(ComplexArgumentParser::Setup(labelWithMember, request.{{asLowerCamelCase label}}, value["{{asLowerCamelCase label}}"]));
{{#if isOptional}}
}
{{else if (isStrEqual label ../struct_fabric_idx_field)}}
}
{{/if}}

{{/zcl_struct_items}}
Expand Down
14 changes: 11 additions & 3 deletions examples/chip-tool/templates/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,13 +116,21 @@ async function structs_with_cluster_name(options)
continue;
}

if (s.struct_cluster_count == 1) {
s.items.forEach(i => {
if (i.type.toLowerCase() == "fabric_idx") {
s.struct_fabric_idx_field = i.label;
}
})

if (s.struct_cluster_count == 1)
{
const clusters = await zclQuery.selectStructClusters(this.global.db, s.id);
blocks.push({ id : s.id, name : s.name, clusterName : clusters[0].name });
blocks.push(
{ id : s.id, name : s.name, struct_fabric_idx_field : s.struct_fabric_idx_field, clusterName : clusters[0].name });
}

if (s.struct_cluster_count > 1) {
blocks.push({ id : s.id, name : s.name, clusterName : "detail" });
blocks.push({ id : s.id, name : s.name, struct_fabric_idx_field : s.struct_fabric_idx_field, clusterName : "detail" });
}
}

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit f208906

Please sign in to comment.