@@ -27,6 +27,40 @@ const templateUtil = require('./template-util')
2727const zclUtil = require ( '../util/zcl-util' )
2828const dbEnum = require ( '../../src-shared/db-enum' )
2929
30+ /**
31+ * Counts the number of mandatory attributes (not optional, non-global) for the current cluster context.
32+ * Usage: {{count_mandatory_matter_attributes side="server"}}
33+ * If side is not provided or invalid, counts all attributes.
34+ */
35+ async function count_mandatory_matter_attributes ( options ) {
36+ if ( ! ( 'id' in this ) )
37+ throw new Error (
38+ 'count_mandatory_matter_attributes requires a cluster id inside the context.'
39+ )
40+ const packageIds = await templateUtil . ensureZclPackageIds ( this )
41+ let side = options ?. hash ?. side
42+ if ( typeof side === 'string' ) side = side . toLowerCase ( )
43+ let attributes
44+ if ( side === dbEnum . side . server || side === dbEnum . side . client ) {
45+ attributes =
46+ await queryZcl . selectAttributesByClusterIdAndSideIncludingGlobal (
47+ this . global . db ,
48+ this . id ,
49+ packageIds ,
50+ side
51+ )
52+ } else {
53+ // Get all attributes for this cluster (both sides)
54+ attributes = await queryZcl . selectAttributesByClusterIdIncludingGlobal (
55+ this . global . db ,
56+ this . id ,
57+ packageIds
58+ )
59+ }
60+ // Count mandatory attributes (not optional, non-global)
61+ return attributes . filter ( ( a ) => a . clusterRef && ! a . isOptional ) . length
62+ }
63+
3064/**
3165 * Get feature bits from the given context.
3266 * @param {* } options
@@ -172,3 +206,4 @@ exports.global_attribute_default = attributeDefault
172206exports . feature_bits = featureBits
173207exports . as_underlying_atomic_identifier_for_attribute_id =
174208 as_underlying_atomic_identifier_for_attribute_id
209+ exports . count_mandatory_matter_attributes = count_mandatory_matter_attributes
0 commit comments