Skip to content

Commit

Permalink
Add ZAP helper for detecting fabric-scoped structs. (#15281)
Browse files Browse the repository at this point in the history
We want to condition some codegen on whether a type is a fabric-scoped
struct.
  • Loading branch information
bzbarsky-apple authored and pull[bot] committed Jun 27, 2023
1 parent d28408a commit 1089278
Showing 1 changed file with 20 additions and 0 deletions.
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

0 comments on commit 1089278

Please sign in to comment.