From cd31f49b5958dac09f30ad754eeec6bb5bb61fc9 Mon Sep 17 00:00:00 2001 From: Bharat Dandu <brdandu@silabs.com> Date: Wed, 18 May 2022 17:03:21 -0400 Subject: [PATCH] Adding DISABLE_DEFAULT_RESPONSE to the backend during loading and also adding to the helpers queries such that it can be used for generation - Adding DISABLE_DEFAULT_RESPONSE to db-mapping - Adding the above to query-command, query-loader and zcl-loader-silabs for loading into the backend and for querying it from the backend - Adding changes to the schema to include this in the command table - Adding is_command_default_response_disabled helper to check if the command default reponse is diabled or not - JIRA: ZAPP-797 --- src-electron/db/db-mapping.js | 1 + src-electron/db/query-command.js | 9 +++++--- src-electron/db/query-loader.js | 7 +++++-- src-electron/db/zap-schema.sql | 1 + src-electron/generator/helper-session.js | 26 ++++++++++++++++++++++++ src-electron/zcl/zcl-loader-silabs.js | 2 ++ 6 files changed, 41 insertions(+), 5 deletions(-) diff --git a/src-electron/db/db-mapping.js b/src-electron/db/db-mapping.js index 11cb738e..9e17d05f 100644 --- a/src-electron/db/db-mapping.js +++ b/src-electron/db/db-mapping.js @@ -171,6 +171,7 @@ exports.map = { responseName: x.RESPONSE_NAME, isIncoming: x.INCOMING, isOutgoing: x.OUTGOING, + disableDefaultResponse: x.DISABLE_DEFAULT_RESPONSE, } }, diff --git a/src-electron/db/query-command.js b/src-electron/db/query-command.js index 9580c671..41861c06 100644 --- a/src-electron/db/query-command.js +++ b/src-electron/db/query-command.js @@ -862,7 +862,8 @@ SELECT IS_OPTIONAL, MUST_USE_TIMED_INVOKE, RESPONSE_REF, - RESPONSE_NAME + RESPONSE_NAME, + DISABLE_DEFAULT_RESPONSE FROM COMMAND WHERE CLUSTER_REF = ? ORDER BY CODE`, [clusterId] @@ -1051,7 +1052,8 @@ SELECT IS_OPTIONAL, MUST_USE_TIMED_INVOKE, RESPONSE_REF, - RESPONSE_NAME + RESPONSE_NAME, + DISABLE_DEFAULT_RESPONSE FROM COMMAND WHERE PACKAGE_REF IN (${packageIds}) ORDER BY CODE` @@ -1141,7 +1143,8 @@ SELECT IS_OPTIONAL, MUST_USE_TIMED_INVOKE, RESPONSE_REF, - RESPONSE_NAME + RESPONSE_NAME, + DISABLE_DEFAULT_RESPONSE FROM COMMAND WHERE CLUSTER_REF IS NULL AND PACKAGE_REF IN (${packageIds}) ORDER BY CODE`, diff --git a/src-electron/db/query-loader.js b/src-electron/db/query-loader.js index 0fcef57c..2c33c4ce 100644 --- a/src-electron/db/query-loader.js +++ b/src-electron/db/query-loader.js @@ -94,11 +94,13 @@ INSERT INTO COMMAND ( RESPONSE_NAME, MANUFACTURER_CODE, INTRODUCED_IN_REF, - REMOVED_IN_REF + REMOVED_IN_REF, + DISABLE_DEFAULT_RESPONSE ) VALUES ( ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, (SELECT SPEC_ID FROM SPEC WHERE CODE = ? AND PACKAGE_REF = ?), - (SELECT SPEC_ID FROM SPEC WHERE CODE = ? AND PACKAGE_REF = ?) + (SELECT SPEC_ID FROM SPEC WHERE CODE = ? AND PACKAGE_REF = ?), + ? )` const INSERT_COMMAND_ARG_QUERY = ` @@ -223,6 +225,7 @@ function commandMap(clusterId, packageId, commands) { packageId, command.removedIn, packageId, + dbApi.toDbBool(command.disableDefaultResponse), ]) } diff --git a/src-electron/db/zap-schema.sql b/src-electron/db/zap-schema.sql index 9b3ac5f6..feaa8087 100644 --- a/src-electron/db/zap-schema.sql +++ b/src-electron/db/zap-schema.sql @@ -170,6 +170,7 @@ CREATE TABLE IF NOT EXISTS "COMMAND" ( "REMOVED_IN_REF" integer, "RESPONSE_NAME" integer, "RESPONSE_REF" integer, + "DISABLE_DEFAULT_RESPONSE" integer, foreign key (INTRODUCED_IN_REF) references SPEC(SPEC_ID), foreign key (REMOVED_IN_REF) references SPEC(SPEC_ID), foreign key (CLUSTER_REF) references CLUSTER(CLUSTER_ID), diff --git a/src-electron/generator/helper-session.js b/src-electron/generator/helper-session.js index e1097641..863b418f 100644 --- a/src-electron/generator/helper-session.js +++ b/src-electron/generator/helper-session.js @@ -652,6 +652,30 @@ async function user_default_response_policy(options) { else return value } +/** + * An if helper to check if default response for a command is disabled or not. + * @param {*} command + * @param {*} options + * @returns true if the the default response policy is either never or + * when the policy is not always and the command has the disable default + * response policy set to true + */ +async function is_command_default_response_disabled(command, options) { + let defaultRespPolicy = await querySession.getSessionKeyValue( + this.global.db, + this.global.sessionId, + dbEnum.sessionOption.defaultResponsePolicy + ) + if ( + defaultRespPolicy.toUpperCase() == 'NEVER' || + (defaultRespPolicy.toUpperCase('ALWAYS') && command.disableDefaultResponse) + ) { + return options.fn(this) + } else { + return options.inverse(this) + } +} + /* * @param {*} endpointTypeId * Returns the endpoint type identifier for an endpoint type @@ -1441,3 +1465,5 @@ exports.manufacturing_clusters_with_incoming_commands = exports.all_user_clusters_with_outgoing_commands = all_user_clusters_with_outgoing_commands exports.all_outgoing_commands_for_cluster = all_outgoing_commands_for_cluster +exports.is_command_default_response_disabled = + is_command_default_response_disabled diff --git a/src-electron/zcl/zcl-loader-silabs.js b/src-electron/zcl/zcl-loader-silabs.js index ae283e56..f4da3c33 100644 --- a/src-electron/zcl/zcl-loader-silabs.js +++ b/src-electron/zcl/zcl-loader-silabs.js @@ -408,6 +408,8 @@ function prepareCluster(cluster, context, isExtension = false) { introducedIn: command.$.introducedIn, removedIn: command.$.removedIn, responseName: command.$.response == null ? null : command.$.response, + disableDefaultResponse: + command.$.disableDefaultResponse == 'true' ? true : false, } cmd.access = extractAccessIntoArray(command) if (cmd.manufacturerCode == null) { -- GitLab