Skip to content

Commit 1b876c1

Browse files
authored
Deprecating stateful helpers with stateless helpers (#982)
- Deprecating chip_client_clusters, chip_cluster_commands, chip_cluster_responses and chip_cluster_command_arguments with all_user_clusters, zcl_commands, zcl_command_responses and zcl_command_arguments respectively - Adding more attributes to the command in db-mapping along with the extension to the zcl_command query - Updating selectAllClustersDetailsFromEndpointTypes such that all_user_clusters can be filtered based on side of cluster - Adding zcl_command_responses to retrieve all commands which are also command responses.a - Extending asJavaType to handle asJavaBoxedType properly under all block helpers and not just chipType block helpers - Updating the local map for command query - Minor cleanup - Github: ZAP#971
1 parent 15f96c4 commit 1b876c1

File tree

9 files changed

+114
-18
lines changed

9 files changed

+114
-18
lines changed

apack.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"description": "Graphical configuration tool for application and libraries based on Zigbee Cluster Library.",
55
"path": [".", "node_modules/.bin/", "ZAP.app/Contents/MacOS"],
66
"requiredFeatureLevel": "apack.core:9",
7-
"featureLevel": 94,
7+
"featureLevel": 95,
88
"uc.triggerExtension": "zap",
99
"executable": {
1010
"zap:win32.x86_64": {

src-electron/db/db-mapping.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,9 +179,13 @@ exports.map = {
179179
argPresentIf: x.ARG_PRESENT_IF,
180180
argCountArg: x.ARG_COUNT_ARG,
181181
commandArgCount: x.COMMAND_ARGUMENT_COUNT,
182+
requiredCommandArgCount: x.REQUIRED_COMMAND_ARGUMENT_COUNT,
183+
hasArguments: x.COMMAND_ARGUMENT_COUNT > 0,
184+
commandHasRequiredField: x.REQUIRED_COMMAND_ARGUMENT_COUNT > 0,
182185
argIsNullable: x.ARG_IS_NULLABLE,
183186
responseRef: x.RESPONSE_REF,
184187
responseName: x.RESPONSE_NAME,
188+
hasSpecificResponse: dbApi.toDbBool(x.RESPONSE_REF),
185189
isIncoming: x.INCOMING,
186190
isOutgoing: x.OUTGOING,
187191
isDefaultResponseEnabled: x.IS_DEFAULT_RESPONSE_ENABLED,

src-electron/db/query-command.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,8 @@ async function selectAllAvailableClusterCommandDetailsFromEndpointTypes(
121121
let endpointTypeIds = endpointTypes.map((ep) => ep.endpointTypeId).toString()
122122
let mapFunction = (x) => {
123123
return {
124-
id: x.CLUSTER_ID,
124+
clusterId: x.CLUSTER_ID,
125+
id: x.COMMAND_ID,
125126
clusterName: x.CLUSTER_NAME,
126127
clusterCode: x.CLUSTER_CODE,
127128
commandMfgCode: x.COMMAND_MANUFACTURER_CODE,
@@ -132,6 +133,9 @@ async function selectAllAvailableClusterCommandDetailsFromEndpointTypes(
132133
commandName: x.COMMAND_NAME,
133134
commandSource: x.COMMAND_SOURCE,
134135
commandCode: x.COMMAND_CODE,
136+
code: x.COMMAND_CODE,
137+
name: x.COMMAND_NAME,
138+
source: x.COMMAND_SOURCE,
135139
incoming: x.INCOMING,
136140
outgoing: x.OUTGOING,
137141
mfgCommandCount: x.MANUFACTURING_SPECIFIC_COMMAND_COUNT,
@@ -153,6 +157,7 @@ SELECT
153157
ENDPOINT_TYPE_CLUSTER.ENABLED AS CLUSTER_ENABLED,
154158
COUNT(*) OVER (PARTITION BY CLUSTER.MANUFACTURER_CODE, CLUSTER.NAME, COMMAND.MANUFACTURER_CODE, COMMAND.NAME) AS NO_OF_CLUSTER_SIDES_ENABLED,
155159
COMMAND.NAME AS COMMAND_NAME,
160+
COMMAND.COMMAND_ID,
156161
COMMAND.SOURCE AS COMMAND_SOURCE,
157162
COMMAND.CODE AS COMMAND_CODE,
158163
ENDPOINT_TYPE_COMMAND.INCOMING AS INCOMING,
@@ -921,7 +926,8 @@ SELECT
921926
COMMAND.RESPONSE_REF,
922927
COMMAND.RESPONSE_NAME,
923928
COMMAND.IS_DEFAULT_RESPONSE_ENABLED,
924-
COUNT(COMMAND_ARG.COMMAND_REF) AS COMMAND_ARGUMENT_COUNT
929+
COUNT(COMMAND_ARG.COMMAND_REF) AS COMMAND_ARGUMENT_COUNT,
930+
COUNT(COMMAND_ARG.COMMAND_REF) FILTER (WHERE COMMAND_ARG.IS_OPTIONAL = 0) AS REQUIRED_COMMAND_ARGUMENT_COUNT
925931
FROM COMMAND
926932
LEFT JOIN
927933
COMMAND_ARG

src-electron/db/query-endpoint-type.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,17 @@ async function selectEndpointType(db, id) {
162162
* @param {*} endpointTypes
163163
* @returns Promise that resolves with the data that should go into the external form.
164164
*/
165-
async function selectAllClustersDetailsFromEndpointTypes(db, endpointTypes) {
165+
async function selectAllClustersDetailsFromEndpointTypes(
166+
db,
167+
endpointTypes,
168+
options = null
169+
) {
170+
let side = null
171+
let endpointClusterSideFilter = 'ENDPOINT_TYPE_CLUSTER.SIDE IS NOT ""'
172+
if (options && options.hash.side) {
173+
side = options.hash.side.toLowerCase()
174+
endpointClusterSideFilter = "ENDPOINT_TYPE_CLUSTER.SIDE = '" + side + "'"
175+
}
166176
let endpointTypeIds = endpointTypes.map((ep) => ep.endpointTypeId).toString()
167177
let mapFunction = (x) => {
168178
return {
@@ -205,7 +215,7 @@ ON
205215
WHERE
206216
ENDPOINT_TYPE_CLUSTER.ENDPOINT_TYPE_REF IN (${endpointTypeIds})
207217
AND
208-
ENDPOINT_TYPE_CLUSTER.SIDE IS NOT "" AND ENDPOINT_TYPE_CLUSTER.ENABLED = 1
218+
${endpointClusterSideFilter} AND ENDPOINT_TYPE_CLUSTER.ENABLED = 1
209219
GROUP BY
210220
NAME, SIDE
211221
${

src-electron/generator/helper-session.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,8 @@ async function all_user_clusters(options) {
451451
let clusters =
452452
await queryEndpointType.selectAllClustersDetailsFromEndpointTypes(
453453
this.global.db,
454-
endpointTypes
454+
endpointTypes,
455+
options
455456
)
456457

457458
return templateUtil.collectBlocks(clusters, options, this)

src-electron/generator/helper-zcl.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,38 @@ function zcl_commands(options) {
405405
return templateUtil.templatePromise(this.global, promise)
406406
}
407407

408+
/**
409+
* Returns all commands which are command responses.
410+
* For eg, If the xml has the following:
411+
* <command source="client" code="0x00" name="newCmd" response="newCmdResponse">
412+
* then newCmdResponse will be included in the list of commands returned here.
413+
*
414+
* There are two modes of this helper:
415+
* - when used in a global context, it iterates over ALL command responses in
416+
* the database.
417+
* - when used inside a `zcl_cluster` block helper, it iterates only over the
418+
* commands responses for that cluster.
419+
* @param {*} options
420+
* @returns all command responses
421+
*/
422+
async function zcl_command_responses(options) {
423+
let packageIds = await templateUtil.ensureZclPackageIds(this)
424+
let cmds = null
425+
if ('id' in this) {
426+
cmds = await queryCommand.selectCommandsByClusterId(
427+
this.global.db,
428+
this.id,
429+
packageIds
430+
)
431+
} else {
432+
cmds = await queryCommand.selectAllCommands(this.global.db, packageIds)
433+
}
434+
let commandResponses = cmds.map((cmd) => cmd.responseName)
435+
let res = cmds.filter((cmd) => commandResponses.includes(cmd.name))
436+
let promise = templateUtil.collectBlocks(res, options, this)
437+
return templateUtil.templatePromise(this.global, promise)
438+
}
439+
408440
/**
409441
* Block helper iterating over all commands with cluster information.
410442
* Note: Similar to zcl_commands but has cluster information as well.
@@ -2954,3 +2986,4 @@ exports.as_zcl_type_size = as_zcl_type_size
29542986
exports.if_compare = if_compare
29552987
exports.if_is_data_type_signed = if_is_data_type_signed
29562988
exports.as_zcl_data_type_size = as_zcl_data_type_size
2989+
exports.zcl_command_responses = zcl_command_responses

src-electron/generator/matter/app/zap-templates/templates/chip/helper.js

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -752,16 +752,27 @@ const dep = templateUtil.deprecatedHelper;
752752
//
753753
exports.chip_clusters = chip_clusters;
754754
exports.chip_has_clusters = chip_has_clusters;
755-
exports.chip_client_clusters = chip_client_clusters;
755+
exports.chip_client_clusters = dep(
756+
chip_client_clusters,
757+
'chip_client_clusters has been deprecated. Use all_user_clusters with the \
758+
side option as client'
759+
);
756760
exports.chip_has_client_clusters = chip_has_client_clusters;
757761
exports.chip_server_clusters = chip_server_clusters;
758762
exports.chip_has_server_clusters = chip_has_server_clusters;
759-
exports.chip_cluster_commands = chip_cluster_commands;
760-
exports.chip_cluster_command_arguments = chip_cluster_command_arguments;
763+
exports.chip_cluster_commands = dep(
764+
chip_cluster_commands,
765+
'chip_cluster_commands has been deprecated. Use zcl_commands with source attribute as client'
766+
);
767+
exports.chip_cluster_command_arguments = dep(chip_cluster_command_arguments, {
768+
to: 'zcl_command_arguments',
769+
});
761770
exports.chip_cluster_command_arguments_with_structs_expanded =
762771
chip_cluster_command_arguments_with_structs_expanded;
763772
exports.chip_server_global_responses = chip_server_global_responses;
764-
exports.chip_cluster_responses = chip_cluster_responses;
773+
exports.chip_cluster_responses = dep(chip_cluster_responses, {
774+
to: 'zcl_command_responses',
775+
});
765776
exports.chip_cluster_response_arguments = chip_cluster_response_arguments;
766777
exports.chip_attribute_list_entryTypes = chip_attribute_list_entryTypes;
767778
exports.chip_server_cluster_attributes = dep(

src-electron/generator/matter/controller/java/templates/helper.js

Lines changed: 38 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -193,8 +193,7 @@ function convertAttributeCallbackTypeToJavaName(cType) {
193193
}
194194

195195
/**
196-
* Note: This helper needs to be used under a block helper which has a
197-
* reference to clusterId.
196+
* Note: This is a util function
198197
* Available options:
199198
* - isBoxedJavaType: 0/1 to return string types in different ways
200199
* - All other options passed to this helper are considered as overrides for
@@ -206,7 +205,12 @@ function convertAttributeCallbackTypeToJavaName(cType) {
206205
* @param {*} options
207206
* @returns The corresponding java data type for a zcl data type.
208207
*/
209-
async function as_underlying_java_zcl_type(type, clusterId, options) {
208+
async function as_underlying_java_zcl_type_util(
209+
type,
210+
clusterId,
211+
options,
212+
context
213+
) {
210214
let hash = options.hash;
211215
// Overwrite any type with the one coming from the template options
212216
// Eg: {{as_underlying_java_zcl_type type [clusterId] boolean='Boolean'}}
@@ -216,9 +220,9 @@ async function as_underlying_java_zcl_type(type, clusterId, options) {
216220
}
217221

218222
// Get ZCL Data Type from the db
219-
const packageIds = await templateUtil.ensureZclPackageIds(this);
223+
const packageIds = await templateUtil.ensureZclPackageIds(context);
220224
let dataType = await queryZcl.selectDataTypeByNameAndClusterId(
221-
this.global.db,
225+
context.global.db,
222226
type,
223227
clusterId,
224228
packageIds
@@ -247,7 +251,7 @@ async function as_underlying_java_zcl_type(type, clusterId, options) {
247251
dataType,
248252
clusterId,
249253
packageIds,
250-
this
254+
context
251255
);
252256
if (sizeAndSign.size >= 3) {
253257
return 'Long';
@@ -268,6 +272,24 @@ async function as_underlying_java_zcl_type(type, clusterId, options) {
268272
}
269273
}
270274

275+
/**
276+
* Note: This helper needs to be used under a block helper which has a
277+
* reference to clusterId.
278+
* Available options:
279+
* - isBoxedJavaType: 0/1 to return string types in different ways
280+
* - All other options passed to this helper are considered as overrides for
281+
* zcl types
282+
* for eg: (as_underlying_java_zcl_type type clusterId boolean='Boolean')
283+
* will return "Boolean" for "boolean" type
284+
* @param {*} type
285+
* @param {*} clusterId
286+
* @param {*} options
287+
* @returns The corresponding java data type for a zcl data type.
288+
*/
289+
async function as_underlying_java_zcl_type(type, clusterId, options) {
290+
return as_underlying_java_zcl_type_util(type, clusterId, options, this);
291+
}
292+
271293
async function asUnderlyingBasicType(type) {
272294
const options = { hash: {} };
273295
let zclType = await zclHelper.asUnderlyingZclType.call(this, type, options);
@@ -295,7 +317,16 @@ async function asJavaType(type, zclType, cluster, options) {
295317
cluster
296318
)}Cluster${appHelper.asUpperCamelCase(type)}`;
297319
} else {
298-
classType += asJavaBoxedType(type, zclType);
320+
let javaBoxedType = asJavaBoxedType(type, zclType);
321+
if (javaBoxedType == 'Object' && options.hash.clusterId) {
322+
javaBoxedType = await as_underlying_java_zcl_type_util(
323+
type,
324+
options.hash.clusterId,
325+
options,
326+
this
327+
);
328+
}
329+
classType += javaBoxedType;
299330
}
300331

301332
if (!options.hash.underlyingType) {

src-electron/generator/matter/controller/python/templates/helper.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ async function as_underlying_python_zcl_type(type, clusterId, options) {
7979
clusterId,
8080
packageIds
8181
);
82-
if (type == 'boolean') {
82+
if (type && type.toLowerCase() == 'boolean') {
8383
return 'bool';
8484
} else if (
8585
dataType.discriminatorName.toLowerCase() == dbEnum.zclType.bitmap ||

0 commit comments

Comments
 (0)