Skip to content
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

Add ZAP helper for detecting fabric-scoped structs. #15281

Merged
Merged
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
20 changes: 20 additions & 0 deletions src/app/zap-templates/templates/app/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -834,6 +834,25 @@ async function zcl_commands_that_need_timed_invoke(options)
return templateUtil.collectBlocks(commands, options, this);
}

// Allows conditioning generation on whether the given type is a fabric-scoped
// struct.
async function if_is_fabric_scoped_struct(type, options)
{
let packageId = await templateUtil.ensureZclPackageId(this);
let st = await zclQuery.selectStructByName(this.global.db, type, packageId);

if (st) {
// TODO: Should know whether a struct is fabric-scoped without sniffing its
// members.
let fields = await zclQuery.selectAllStructItemsById(this.global.db, st.id);
if (fields.find((i) => i.type.toLowerCase() == "fabric_idx")) {
return options.fn(this);
}
}

return options.inverse(this);
}

//
// Module exports
//
Expand All @@ -857,3 +876,4 @@ exports.getPythonFieldDefault = getPythonFieldDefault;
exports.incrementDepth = incrementDepth;
exports.zcl_events_fields_by_event_name = zcl_events_fields_by_event_name;
exports.zcl_commands_that_need_timed_invoke = zcl_commands_that_need_timed_invoke;
exports.if_is_fabric_scoped_struct = if_is_fabric_scoped_struct