From 0e414d7fd743a4ef261d3316d1232db04d2fe95c Mon Sep 17 00:00:00 2001 From: Bharat Dandu Date: Thu, 19 Jan 2023 13:03:51 -0500 Subject: [PATCH] Adding to enabled_attributes_for_cluster_and_side and zcl_attributes_server helper to replace chip_server_cluster_attributes - chip_server_cluster_attributes is returning server attributes which are not actually enabled because the server side cluster is disabled. - The reason chip_server_cluster_attributes is picking the server side attributes which are not enabled is because those are enabled in the .zap file(Which is the case for saving user selections and ease of use). However the helper is not actually checking if the cluster is enabled as well. - enabled_attributes_for_cluster_and_side is solving this issue correctly and actually only showing attributes which are truly enabled. - Extending endpointTypeAttributeExtended such that there is a common place for an attribute map - Updating endpointTypeAttributeExtended with everything that attributeExportMapping had such that it can act as a common place for all other temporary maps that have been created across our code. Also sorting endpointTypeAttributeExtended for easier readability and avoiding duplicate keys - Updating zcl_attributes_server block helper such that it can behave like chip_server_cluster_attributes. - Updating attribute map such that it can be used more widely - Adding additional helpers to remove the stateful helpers - Adding removeKeys option for removing certain columns which are not needed in a block helper such as enabled_attributes_for_cluster_and_side and zcl_attributes_server - Adding if_unsupported_attribute_type and if_attribute_complex to check for unsupported and complex zcl data types - Deprecating old stateful helpers with new stateless helpers - Adding select data type using type name and cluster id to data_types, enums, bitmap, numbers and structs - Adding if_unsupported_attribute_callback helper and if_basic_attribute if helpers for java code generation - Deprecating java and python zcl type helpers with new zcl type helpers such that they do not need any stateful information coming from parent block helpers. For eg chipType and chipCallback.type - Adding tests for all the newly introduced helpers. - Updating Api documentation - Adding if_is_data_type_signed and as_zcl_data_type_size to determine sign and size of zcl data types - if_is_data_type_signed and as_zcl_data_type_size take type name and cluster id to return size and sign of the zcl data types - Github: ZAP#898 --- docs/api.md | 1637 ++++++++++++++--- src-electron/db/db-mapping.js | 77 +- src-electron/db/query-attribute.js | 86 +- src-electron/db/query-bitmap.js | 59 + src-electron/db/query-data-type.js | 78 + src-electron/db/query-enum.js | 68 + src-electron/db/query-number.js | 58 + src-electron/db/query-struct.js | 66 + src-electron/db/query-zcl.js | 9 + src-electron/generator/helper-attribute.js | 1 + src-electron/generator/helper-session.js | 37 +- src-electron/generator/helper-zcl.js | 129 +- .../zap-templates/templates/chip/helper.js | 104 +- .../controller/java/templates/helper.js | 92 +- .../controller/python/templates/helper.js | 65 +- src-electron/util/zcl-util.js | 52 + test/gen-matter-4.test.js | 92 + .../matter3/miscellaneous_helper_tests.zapt | 22 + test/gen-template/matter3/t.json | 5 + test/test-util.js | 2 +- 20 files changed, 2348 insertions(+), 391 deletions(-) create mode 100644 test/gen-template/matter3/miscellaneous_helper_tests.zapt diff --git a/docs/api.md b/docs/api.md index bc6fd6a394..a8f9a27262 100644 --- a/docs/api.md +++ b/docs/api.md @@ -40,12 +40,12 @@
DB API: device type database access

This module provides queries for device types.

-
DB API: endpoint configuration queries against the database.
-

This module provides queries for endpoint configuration.

-
DB API: endpoint type queries against the database.

This module provides queries for endpoint type.

+
DB API: endpoint configuration queries against the database.
+

This module provides queries for endpoint configuration.

+
DB API: zcl database access

This module provides queries for enums.

@@ -64,14 +64,14 @@
DB API: package-based queries.

This module provides queries related to packages.

-
DB API: session related queries.
-

This module provides session related queries.

-
DB API: zcl database access

This module provides queries for ZCL static entities inside a single session. Things like: all visible clusters, etc.

+
DB API: session related queries.
+

This module provides session related queries.

+
DB API: zcl database access

This module provides queries for enums.

@@ -123,6 +123,9 @@ inside a single session. Things like:
REST API: generation functions

This module provides the REST API to the IDE component handling.

+
REST API: initialization functions
+

This module provides the REST API to the session initialization

+
REST API: static zcl functions

This module provides the REST API to the static zcl queries.

@@ -530,6 +533,10 @@ with its actual type from disciminator table.

Gathers the data type information of an entry based on data type name along with its actual type from disciminator table.

+
selectDataTypeByNameAndClusterId(db, name, clusterId, packageIds)
+

Gathers the data type information based on data type name and +clusterId along with its actual type from disciminator table.

+
selectAllDataTypes(db, packageId)

Gathers All the data types

@@ -541,6 +548,9 @@ if string.

selectNumberByName(db, name, packageIds)

Select an number matched by name.

+
selectNumberByNameAndClusterId(db, name, packageIds)
+

Select a number matched by name and clusterId

+
selectNumberById(db, name)

Select an number matched by id.

@@ -559,6 +569,33 @@ if string.

attributeDefault()

Valid within a cluster context, requires code.

+
if_unsupported_attribute_callback(type, isArray, clusterId, options)
+

If helper that checks if an attribute is not supported based on language +being generated for. +For eg: In java, an attribute callback is not supported when it is a struct. +However it is supported if it is an array of structs. +Available Options:

+ +
+
if_basic_attribute(type, clusterId, options)
+

If helper that checks if an attribute is basic or not based on language +being generated for. +For eg: In java, an attribute is not basic if it is either nullable, optional, +array type or struct. +Note: This helper should be used within an attribute block helper. +Available Options:

+ +

type is basic +{{else}} +type is not basic +{{/if_basic_attribute}}

+
if_command_arguments_exist(commandId, argument_return, no_argument_return)
if_command_args_exist(commandId, options)
@@ -660,6 +697,11 @@ endpoint type array, for the appropriate endpoint.

Generates array of { index , mfgCode } pairs, matching the indexes in attribute table.

+
endpoint_reporting_config_defaults(options)
+

This helper supports an "order" CSV string, such as: + "direction,endpoint,clusterId,attributeId,mask,mfgCode,minmax" +The string above is a default value, and it determines in what order are the fields generated.

+
collectAttributes()

Attribute collection works like this: 1.) Go over all the clusters that exist. @@ -714,6 +756,33 @@ Use it as: {{future name="NAME"}}

span all attributes from all clusters from all endpointTypes. This helper function allows the template to increment the token ID within the tokens context.

+
token_attribute_util(context, options)
+

Util function that extracts all the token attribute information.

+
+
token_attributes(endpointTypeRef, options)
+

Get information about all the token attributes in the configuration or this +helper can be used within an endpoint block helper to fetch the +corresponding token attributes based on endpoint type given. +Available Options: +isSingleton: 0/1, option can be used to filter attributes based on singleton +or non-singleton(Available with endpointTypeRef only)

+
+
token_attribute_clusters(endpointTypeRef, options)
+

This helper can return all token associated clusters across endpoints or +this helper can be used within an endpoint block helper to fetch the +corresponding token associated clusters. +Available Options: +isSingleton: 0/1, option can be used to filter clusters based on singleton +or non-singleton attributes.

+
+
token_attribute_endpoints(options)
+

Get all endpoints which have token attributes in the configuration. +AvailableOptions:

+ +
get_cli_size(size, type, allowZclTypes)
zcl_command_argument_type_to_cli_data_type_util(type, cliPrefix, context, options)
@@ -781,13 +850,6 @@ queries that are needed to load the attribute state

Function that actually loads the data out of a state object. Session at this point is blank, and has no packages.

-
readDataFromFile(filePath)
-

Reads the data from the file and resolves with the state object if all is good.

-
-
importDataFromFile(db, filePath)
-

Writes the data from the file into a new session. -NOTE: This function does NOT initialize session packages.

-
importSessionKeyValues(db, sessionId, keyValuePairs)

Resolves with a promise that imports session key values.

@@ -806,6 +868,13 @@ with the succesfull writing into the database.

readJsonData(filePath, data)

Parses JSON file and creates a state object out of it, which is passed further down the chain.

+
readDataFromFile(filePath)
+

Reads the data from the file and resolves with the state object if all is good.

+
+
importDataFromFile(db, filePath)
+

Writes the data from the file into a new session. +NOTE: This function does NOT initialize session packages.

+
initSessionTimers()

Start session specific validation.

@@ -851,15 +920,6 @@ with the succesfull writing into the database.

startUpMainInstance(quitFunction, argv)

Default startup method.

-
packagesAndSessions(db)
-

This function returns Properties, Templates and Dirty-Sessions

-
-
initializeSession(db, options:)
-

This function creates a new session with its packages according to selected Properties and Templates

-
-
loadPreviousSessions(db)
-

This function reloads previous session by user selected session's id

-
doOpen(menuItem, browserWindow, event)

Perform a file->open operation.

@@ -1005,31 +1065,6 @@ that will be resolved when all the XML files are done, or rejected if at least o

Toplevel function that loads the xml library file and orchestrates the promise chain.

-
recordToplevelPackage(db, metadataFile, crc)
-

Records the toplevel package information and resolves into packageId

-
-
recordVersion(db, ctx)
-

Records the version into the database.

-
-
loadZclMetafiles(db, metadataFile)
-

Toplevel function that loads the zcl file and passes it off to the correct zcl loader.

-
-
loadZcl(db, metadataFile)
-

Loads individual zcl.json metafile.

-
-
loadIndividualFile(db, filePath, sessionId)
-

Load individual custom XML files.

-
-
qualifyZclFile(db, info, parentPackageId)
-

Promises to qualify whether zcl file needs to be reloaded. -If yes, the it will resolve with {filePath, data, packageId} -If not, then it will resolve with {error}

-
-
processZclPostLoading(db)
-

Promises to perform a post loading step.

-
-
getDiscriminatorMap(db, packageIds)
-
collectDataFromJsonFile(ctx)

Promises to read the JSON file and resolve all the data.

@@ -1200,6 +1235,31 @@ e.g. for ClusterExtensions.

Toplevel function that loads the toplevel metafile and orchestrates the promise chain.

+
recordToplevelPackage(db, metadataFile, crc)
+

Records the toplevel package information and resolves into packageId

+
+
recordVersion(db, ctx)
+

Records the version into the database.

+
+
loadZclMetafiles(db, metadataFile)
+

Toplevel function that loads the zcl file and passes it off to the correct zcl loader.

+
+
loadZcl(db, metadataFile)
+

Loads individual zcl.json metafile.

+
+
loadIndividualFile(db, filePath, sessionId)
+

Load individual custom XML files.

+
+
qualifyZclFile(db, info, parentPackageId)
+

Promises to qualify whether zcl file needs to be reloaded. +If yes, the it will resolve with {filePath, data, packageId} +If not, then it will resolve with {error}

+
+
processZclPostLoading(db)
+

Promises to perform a post loading step.

+
+
getDiscriminatorMap(db, packageIds)
+
@@ -1571,22 +1631,29 @@ This module provides cache for commonly used static database queries. - [DB API: zcl database access](#module*DB API* zcl database access) - [~clear()](#module*DB API* zcl database access..clear) - - [~put(key, packageId, data)](#module*DB API* zcl database access..put) + - [~put(key, packageId, data)](#module*DB API* zcl database access..put) ⇒ - [~get(key, packageId)](#module*DB API* zcl database access..get) ⇒ - [~isCached(key, packageId)](#module*DB API* zcl database access..isCached) ⇒ + - [~cacheQuery(key, packageId)](#module*DB API* zcl database access..cacheQuery) ⇒ + - [~cacheStats()](#module*DB API* zcl database access..cacheStats) + - [~enable()](#module*DB API* zcl database access..enable) + - [~disable()](#module*DB API* zcl database access..disable) - [~selectAtomicType(db, packageId, typeName)](#module*DB API* zcl database access..selectAtomicType) - [~selectAtomicById(db, packageId)](#module*DB API* zcl database access..selectAtomicById) - [~selectAllBitmaps(db)](#module*DB API* zcl database access..selectAllBitmaps) ⇒ + - [~selectBitmapByNameAndClusterId(db, name, clusterId, packageIds)](#module*DB API* zcl database access..selectBitmapByNameAndClusterId) ⇒ - [~selectAllEnums(db, packageId)](#module*DB API* zcl database access..selectAllEnums) ⇒ - [~selectClusterEnums(db, packageId, clusterId)](#module*DB API* zcl database access..selectClusterEnums) ⇒ - [~selectAllEnumItemsById(db, id)](#module*DB API* zcl database access..selectAllEnumItemsById) ⇒ - [~selectAllEnumItems(db, packageId)](#module*DB API* zcl database access..selectAllEnumItems) ⇒ - [~selectEnumById(db, id)](#module*DB API* zcl database access..selectEnumById) ⇒ - [~selectEnumByName(db, name, packageIds)](#module*DB API* zcl database access..selectEnumByName) ⇒ + - [~selectEnumByNameAndClusterId(db, name, clusterId, packageIds)](#module*DB API* zcl database access..selectEnumByNameAndClusterId) ⇒ - [~selectSessionClusterByCode(db, sessionId)](#module*DB API* zcl database access..selectSessionClusterByCode) ⇒ - [~selectAllSessionClusters(db, sessionId)](#module*DB API* zcl database access..selectAllSessionClusters) ⇒ - [~selectSessionAttributeByCode(db, sessionId)](#module*DB API* zcl database access..selectSessionAttributeByCode) ⇒ - [~selectSessionCommandByCode(db, sessionId)](#module*DB API* zcl database access..selectSessionCommandByCode) ⇒ + - [~selectStructByNameAndClusterId(db, name, clusterId, packageIds)](#module*DB API* zcl database access..selectStructByNameAndClusterId) ⇒ - [~selectStructsWithClusterAssociation(db, packageIds, groupByStructName)](#module*DB API* zcl database access..selectStructsWithClusterAssociation) ⇒ - [~selectClusterBitmaps(db, packageId, clusterId)](#module*DB API* zcl database access..selectClusterBitmaps) ⇒ - [~selectAllDomains(db)](#module*DB API* zcl database access..selectAllDomains) ⇒ @@ -1614,11 +1681,12 @@ Clears the entire cache. **Kind**: inner method of [DB API: zcl database access](#module*DB API* zcl database access) -### DB API: zcl database access~put(key, packageId, data) +### DB API: zcl database access~put(key, packageId, data) ⇒ Puts a data object into the cache under a given key/packageId -**Kind**: inner method of [DB API: zcl database access](#module*DB API* zcl database access) +**Kind**: inner method of [DB API: zcl database access](#module*DB API* zcl database access) +**Returns**: Returns true on success. | Param | Type | | --------- | --------------- | @@ -1633,7 +1701,7 @@ Puts a data object into the cache under a given key/packageId Returns a data object under a given key/packageId. **Kind**: inner method of [DB API: zcl database access](#module*DB API* zcl database access) -**Returns**: cached object or null if none is present +**Returns**: cached object or undefined if none is present or expired. | Param | Type | | --------- | --------------- | @@ -1654,6 +1722,46 @@ Returns true if a given key/packageId cache exists. | key | \* | | packageId | \* | + + +### DB API: zcl database access~cacheQuery(key, packageId) ⇒ + +Cache input / output of provided queryFunction +The queryFunction is assumed to have the following signature: + +async function queryFunction(db, ...) {...} + +The DB handle is ignored and the remaining arguments are used as the cache key. + +**Kind**: inner method of [DB API: zcl database access](#module*DB API* zcl database access) +**Returns**: true or false, depending on whether the cache is present. + +| Param | Type | +| --------- | --------------- | +| key | \* | +| packageId | \* | + + + +### DB API: zcl database access~cacheStats() + +Returns the cache statistics. + +**Kind**: inner method of [DB API: zcl database access](#module*DB API* zcl database access) + + +### DB API: zcl database access~enable() + +Enable the Database Query cache + +**Kind**: inner method of [DB API: zcl database access](#module*DB API* zcl database access) + + +### DB API: zcl database access~disable() + +Disable the database cache + +**Kind**: inner method of [DB API: zcl database access](#module*DB API* zcl database access) ### DB API: zcl database access~selectAtomicType(db, packageId, typeName) @@ -1694,6 +1802,22 @@ Retrieves all the bitmaps in the database. | ----- | --------------- | | db | \* | + + +### DB API: zcl database access~selectBitmapByNameAndClusterId(db, name, clusterId, packageIds) ⇒ + +Select a bitmap matched by name and clusterId. + +**Kind**: inner method of [DB API: zcl database access](#module*DB API* zcl database access) +**Returns**: bitmap information or undefined + +| Param | Type | +| ---------- | --------------- | +| db | \* | +| name | \* | +| clusterId | \* | +| packageIds | \* | + ### DB API: zcl database access~selectAllEnums(db, packageId) ⇒ @@ -1780,6 +1904,22 @@ Select an enum matched by name. | name | \* | | packageIds | \* | + + +### DB API: zcl database access~selectEnumByNameAndClusterId(db, name, clusterId, packageIds) ⇒ + +Select an enum matched by name and clusterId. + +**Kind**: inner method of [DB API: zcl database access](#module*DB API* zcl database access) +**Returns**: enum information or undefined + +| Param | Type | +| ---------- | --------------- | +| db | \* | +| name | \* | +| clusterId | \* | +| packageIds | \* | + ### DB API: zcl database access~selectSessionClusterByCode(db, sessionId) ⇒ @@ -1836,6 +1976,22 @@ Returns the command available to this session by the code. | db | \* | | sessionId | \* | + + +### DB API: zcl database access~selectStructByNameAndClusterId(db, name, clusterId, packageIds) ⇒ + +Select a struct matched by name and clusterId + +**Kind**: inner method of [DB API: zcl database access](#module*DB API* zcl database access) +**Returns**: struct information or undefined + +| Param | Type | +| ---------- | --------------- | +| db | \* | +| name | \* | +| clusterId | \* | +| packageIds | \* | + ### DB API: zcl database access~selectStructsWithClusterAssociation(db, packageIds, groupByStructName) ⇒ @@ -2107,22 +2263,29 @@ This module provides queries for atomic type queries. - [DB API: zcl database access](#module*DB API* zcl database access) - [~clear()](#module*DB API* zcl database access..clear) - - [~put(key, packageId, data)](#module*DB API* zcl database access..put) + - [~put(key, packageId, data)](#module*DB API* zcl database access..put) ⇒ - [~get(key, packageId)](#module*DB API* zcl database access..get) ⇒ - [~isCached(key, packageId)](#module*DB API* zcl database access..isCached) ⇒ + - [~cacheQuery(key, packageId)](#module*DB API* zcl database access..cacheQuery) ⇒ + - [~cacheStats()](#module*DB API* zcl database access..cacheStats) + - [~enable()](#module*DB API* zcl database access..enable) + - [~disable()](#module*DB API* zcl database access..disable) - [~selectAtomicType(db, packageId, typeName)](#module*DB API* zcl database access..selectAtomicType) - [~selectAtomicById(db, packageId)](#module*DB API* zcl database access..selectAtomicById) - [~selectAllBitmaps(db)](#module*DB API* zcl database access..selectAllBitmaps) ⇒ + - [~selectBitmapByNameAndClusterId(db, name, clusterId, packageIds)](#module*DB API* zcl database access..selectBitmapByNameAndClusterId) ⇒ - [~selectAllEnums(db, packageId)](#module*DB API* zcl database access..selectAllEnums) ⇒ - [~selectClusterEnums(db, packageId, clusterId)](#module*DB API* zcl database access..selectClusterEnums) ⇒ - [~selectAllEnumItemsById(db, id)](#module*DB API* zcl database access..selectAllEnumItemsById) ⇒ - [~selectAllEnumItems(db, packageId)](#module*DB API* zcl database access..selectAllEnumItems) ⇒ - [~selectEnumById(db, id)](#module*DB API* zcl database access..selectEnumById) ⇒ - [~selectEnumByName(db, name, packageIds)](#module*DB API* zcl database access..selectEnumByName) ⇒ + - [~selectEnumByNameAndClusterId(db, name, clusterId, packageIds)](#module*DB API* zcl database access..selectEnumByNameAndClusterId) ⇒ - [~selectSessionClusterByCode(db, sessionId)](#module*DB API* zcl database access..selectSessionClusterByCode) ⇒ - [~selectAllSessionClusters(db, sessionId)](#module*DB API* zcl database access..selectAllSessionClusters) ⇒ - [~selectSessionAttributeByCode(db, sessionId)](#module*DB API* zcl database access..selectSessionAttributeByCode) ⇒ - [~selectSessionCommandByCode(db, sessionId)](#module*DB API* zcl database access..selectSessionCommandByCode) ⇒ + - [~selectStructByNameAndClusterId(db, name, clusterId, packageIds)](#module*DB API* zcl database access..selectStructByNameAndClusterId) ⇒ - [~selectStructsWithClusterAssociation(db, packageIds, groupByStructName)](#module*DB API* zcl database access..selectStructsWithClusterAssociation) ⇒ - [~selectClusterBitmaps(db, packageId, clusterId)](#module*DB API* zcl database access..selectClusterBitmaps) ⇒ - [~selectAllDomains(db)](#module*DB API* zcl database access..selectAllDomains) ⇒ @@ -2150,11 +2313,12 @@ Clears the entire cache. **Kind**: inner method of [DB API: zcl database access](#module*DB API* zcl database access) -### DB API: zcl database access~put(key, packageId, data) +### DB API: zcl database access~put(key, packageId, data) ⇒ Puts a data object into the cache under a given key/packageId -**Kind**: inner method of [DB API: zcl database access](#module*DB API* zcl database access) +**Kind**: inner method of [DB API: zcl database access](#module*DB API* zcl database access) +**Returns**: Returns true on success. | Param | Type | | --------- | --------------- | @@ -2169,7 +2333,7 @@ Puts a data object into the cache under a given key/packageId Returns a data object under a given key/packageId. **Kind**: inner method of [DB API: zcl database access](#module*DB API* zcl database access) -**Returns**: cached object or null if none is present +**Returns**: cached object or undefined if none is present or expired. | Param | Type | | --------- | --------------- | @@ -2190,6 +2354,46 @@ Returns true if a given key/packageId cache exists. | key | \* | | packageId | \* | + + +### DB API: zcl database access~cacheQuery(key, packageId) ⇒ + +Cache input / output of provided queryFunction +The queryFunction is assumed to have the following signature: + +async function queryFunction(db, ...) {...} + +The DB handle is ignored and the remaining arguments are used as the cache key. + +**Kind**: inner method of [DB API: zcl database access](#module*DB API* zcl database access) +**Returns**: true or false, depending on whether the cache is present. + +| Param | Type | +| --------- | --------------- | +| key | \* | +| packageId | \* | + + + +### DB API: zcl database access~cacheStats() + +Returns the cache statistics. + +**Kind**: inner method of [DB API: zcl database access](#module*DB API* zcl database access) + + +### DB API: zcl database access~enable() + +Enable the Database Query cache + +**Kind**: inner method of [DB API: zcl database access](#module*DB API* zcl database access) + + +### DB API: zcl database access~disable() + +Disable the database cache + +**Kind**: inner method of [DB API: zcl database access](#module*DB API* zcl database access) ### DB API: zcl database access~selectAtomicType(db, packageId, typeName) @@ -2230,6 +2434,22 @@ Retrieves all the bitmaps in the database. | ----- | --------------- | | db | \* | + + +### DB API: zcl database access~selectBitmapByNameAndClusterId(db, name, clusterId, packageIds) ⇒ + +Select a bitmap matched by name and clusterId. + +**Kind**: inner method of [DB API: zcl database access](#module*DB API* zcl database access) +**Returns**: bitmap information or undefined + +| Param | Type | +| ---------- | --------------- | +| db | \* | +| name | \* | +| clusterId | \* | +| packageIds | \* | + ### DB API: zcl database access~selectAllEnums(db, packageId) ⇒ @@ -2316,6 +2536,22 @@ Select an enum matched by name. | name | \* | | packageIds | \* | + + +### DB API: zcl database access~selectEnumByNameAndClusterId(db, name, clusterId, packageIds) ⇒ + +Select an enum matched by name and clusterId. + +**Kind**: inner method of [DB API: zcl database access](#module*DB API* zcl database access) +**Returns**: enum information or undefined + +| Param | Type | +| ---------- | --------------- | +| db | \* | +| name | \* | +| clusterId | \* | +| packageIds | \* | + ### DB API: zcl database access~selectSessionClusterByCode(db, sessionId) ⇒ @@ -2372,6 +2608,22 @@ Returns the command available to this session by the code. | db | \* | | sessionId | \* | + + +### DB API: zcl database access~selectStructByNameAndClusterId(db, name, clusterId, packageIds) ⇒ + +Select a struct matched by name and clusterId + +**Kind**: inner method of [DB API: zcl database access](#module*DB API* zcl database access) +**Returns**: struct information or undefined + +| Param | Type | +| ---------- | --------------- | +| db | \* | +| name | \* | +| clusterId | \* | +| packageIds | \* | + ### DB API: zcl database access~selectStructsWithClusterAssociation(db, packageIds, groupByStructName) ⇒ @@ -2637,22 +2889,29 @@ This module provides queries for enums. - [DB API: zcl database access](#module*DB API* zcl database access) - [~clear()](#module*DB API* zcl database access..clear) - - [~put(key, packageId, data)](#module*DB API* zcl database access..put) + - [~put(key, packageId, data)](#module*DB API* zcl database access..put) ⇒ - [~get(key, packageId)](#module*DB API* zcl database access..get) ⇒ - [~isCached(key, packageId)](#module*DB API* zcl database access..isCached) ⇒ + - [~cacheQuery(key, packageId)](#module*DB API* zcl database access..cacheQuery) ⇒ + - [~cacheStats()](#module*DB API* zcl database access..cacheStats) + - [~enable()](#module*DB API* zcl database access..enable) + - [~disable()](#module*DB API* zcl database access..disable) - [~selectAtomicType(db, packageId, typeName)](#module*DB API* zcl database access..selectAtomicType) - [~selectAtomicById(db, packageId)](#module*DB API* zcl database access..selectAtomicById) - [~selectAllBitmaps(db)](#module*DB API* zcl database access..selectAllBitmaps) ⇒ + - [~selectBitmapByNameAndClusterId(db, name, clusterId, packageIds)](#module*DB API* zcl database access..selectBitmapByNameAndClusterId) ⇒ - [~selectAllEnums(db, packageId)](#module*DB API* zcl database access..selectAllEnums) ⇒ - [~selectClusterEnums(db, packageId, clusterId)](#module*DB API* zcl database access..selectClusterEnums) ⇒ - [~selectAllEnumItemsById(db, id)](#module*DB API* zcl database access..selectAllEnumItemsById) ⇒ - [~selectAllEnumItems(db, packageId)](#module*DB API* zcl database access..selectAllEnumItems) ⇒ - [~selectEnumById(db, id)](#module*DB API* zcl database access..selectEnumById) ⇒ - [~selectEnumByName(db, name, packageIds)](#module*DB API* zcl database access..selectEnumByName) ⇒ + - [~selectEnumByNameAndClusterId(db, name, clusterId, packageIds)](#module*DB API* zcl database access..selectEnumByNameAndClusterId) ⇒ - [~selectSessionClusterByCode(db, sessionId)](#module*DB API* zcl database access..selectSessionClusterByCode) ⇒ - [~selectAllSessionClusters(db, sessionId)](#module*DB API* zcl database access..selectAllSessionClusters) ⇒ - [~selectSessionAttributeByCode(db, sessionId)](#module*DB API* zcl database access..selectSessionAttributeByCode) ⇒ - [~selectSessionCommandByCode(db, sessionId)](#module*DB API* zcl database access..selectSessionCommandByCode) ⇒ + - [~selectStructByNameAndClusterId(db, name, clusterId, packageIds)](#module*DB API* zcl database access..selectStructByNameAndClusterId) ⇒ - [~selectStructsWithClusterAssociation(db, packageIds, groupByStructName)](#module*DB API* zcl database access..selectStructsWithClusterAssociation) ⇒ - [~selectClusterBitmaps(db, packageId, clusterId)](#module*DB API* zcl database access..selectClusterBitmaps) ⇒ - [~selectAllDomains(db)](#module*DB API* zcl database access..selectAllDomains) ⇒ @@ -2680,11 +2939,12 @@ Clears the entire cache. **Kind**: inner method of [DB API: zcl database access](#module*DB API* zcl database access) -### DB API: zcl database access~put(key, packageId, data) +### DB API: zcl database access~put(key, packageId, data) ⇒ Puts a data object into the cache under a given key/packageId -**Kind**: inner method of [DB API: zcl database access](#module*DB API* zcl database access) +**Kind**: inner method of [DB API: zcl database access](#module*DB API* zcl database access) +**Returns**: Returns true on success. | Param | Type | | --------- | --------------- | @@ -2699,7 +2959,7 @@ Puts a data object into the cache under a given key/packageId Returns a data object under a given key/packageId. **Kind**: inner method of [DB API: zcl database access](#module*DB API* zcl database access) -**Returns**: cached object or null if none is present +**Returns**: cached object or undefined if none is present or expired. | Param | Type | | --------- | --------------- | @@ -2720,6 +2980,46 @@ Returns true if a given key/packageId cache exists. | key | \* | | packageId | \* | + + +### DB API: zcl database access~cacheQuery(key, packageId) ⇒ + +Cache input / output of provided queryFunction +The queryFunction is assumed to have the following signature: + +async function queryFunction(db, ...) {...} + +The DB handle is ignored and the remaining arguments are used as the cache key. + +**Kind**: inner method of [DB API: zcl database access](#module*DB API* zcl database access) +**Returns**: true or false, depending on whether the cache is present. + +| Param | Type | +| --------- | --------------- | +| key | \* | +| packageId | \* | + + + +### DB API: zcl database access~cacheStats() + +Returns the cache statistics. + +**Kind**: inner method of [DB API: zcl database access](#module*DB API* zcl database access) + + +### DB API: zcl database access~enable() + +Enable the Database Query cache + +**Kind**: inner method of [DB API: zcl database access](#module*DB API* zcl database access) + + +### DB API: zcl database access~disable() + +Disable the database cache + +**Kind**: inner method of [DB API: zcl database access](#module*DB API* zcl database access) ### DB API: zcl database access~selectAtomicType(db, packageId, typeName) @@ -2760,14 +3060,30 @@ Retrieves all the bitmaps in the database. | ----- | --------------- | | db | \* | - + -### DB API: zcl database access~selectAllEnums(db, packageId) ⇒ +### DB API: zcl database access~selectBitmapByNameAndClusterId(db, name, clusterId, packageIds) ⇒ -Retrieves all the enums in the database. +Select a bitmap matched by name and clusterId. **Kind**: inner method of [DB API: zcl database access](#module*DB API* zcl database access) -**Returns**: Promise that resolves with the rows of enums. +**Returns**: bitmap information or undefined + +| Param | Type | +| ---------- | --------------- | +| db | \* | +| name | \* | +| clusterId | \* | +| packageIds | \* | + + + +### DB API: zcl database access~selectAllEnums(db, packageId) ⇒ + +Retrieves all the enums in the database. + +**Kind**: inner method of [DB API: zcl database access](#module*DB API* zcl database access) +**Returns**: Promise that resolves with the rows of enums. | Param | Type | | --------- | --------------- | @@ -2846,6 +3162,22 @@ Select an enum matched by name. | name | \* | | packageIds | \* | + + +### DB API: zcl database access~selectEnumByNameAndClusterId(db, name, clusterId, packageIds) ⇒ + +Select an enum matched by name and clusterId. + +**Kind**: inner method of [DB API: zcl database access](#module*DB API* zcl database access) +**Returns**: enum information or undefined + +| Param | Type | +| ---------- | --------------- | +| db | \* | +| name | \* | +| clusterId | \* | +| packageIds | \* | + ### DB API: zcl database access~selectSessionClusterByCode(db, sessionId) ⇒ @@ -2902,6 +3234,22 @@ Returns the command available to this session by the code. | db | \* | | sessionId | \* | + + +### DB API: zcl database access~selectStructByNameAndClusterId(db, name, clusterId, packageIds) ⇒ + +Select a struct matched by name and clusterId + +**Kind**: inner method of [DB API: zcl database access](#module*DB API* zcl database access) +**Returns**: struct information or undefined + +| Param | Type | +| ---------- | --------------- | +| db | \* | +| name | \* | +| clusterId | \* | +| packageIds | \* | + ### DB API: zcl database access~selectStructsWithClusterAssociation(db, packageIds, groupByStructName) ⇒ @@ -3289,18 +3637,18 @@ we have to link the foreign keys. | ----- | --------------- | | db | \* | - - -## DB API: endpoint configuration queries against the database. - -This module provides queries for endpoint configuration. - ## DB API: endpoint type queries against the database. This module provides queries for endpoint type. + + +## DB API: endpoint configuration queries against the database. + +This module provides queries for endpoint configuration. + ## DB API: zcl database access @@ -3309,22 +3657,29 @@ This module provides queries for enums. - [DB API: zcl database access](#module*DB API* zcl database access) - [~clear()](#module*DB API* zcl database access..clear) - - [~put(key, packageId, data)](#module*DB API* zcl database access..put) + - [~put(key, packageId, data)](#module*DB API* zcl database access..put) ⇒ - [~get(key, packageId)](#module*DB API* zcl database access..get) ⇒ - [~isCached(key, packageId)](#module*DB API* zcl database access..isCached) ⇒ + - [~cacheQuery(key, packageId)](#module*DB API* zcl database access..cacheQuery) ⇒ + - [~cacheStats()](#module*DB API* zcl database access..cacheStats) + - [~enable()](#module*DB API* zcl database access..enable) + - [~disable()](#module*DB API* zcl database access..disable) - [~selectAtomicType(db, packageId, typeName)](#module*DB API* zcl database access..selectAtomicType) - [~selectAtomicById(db, packageId)](#module*DB API* zcl database access..selectAtomicById) - [~selectAllBitmaps(db)](#module*DB API* zcl database access..selectAllBitmaps) ⇒ + - [~selectBitmapByNameAndClusterId(db, name, clusterId, packageIds)](#module*DB API* zcl database access..selectBitmapByNameAndClusterId) ⇒ - [~selectAllEnums(db, packageId)](#module*DB API* zcl database access..selectAllEnums) ⇒ - [~selectClusterEnums(db, packageId, clusterId)](#module*DB API* zcl database access..selectClusterEnums) ⇒ - [~selectAllEnumItemsById(db, id)](#module*DB API* zcl database access..selectAllEnumItemsById) ⇒ - [~selectAllEnumItems(db, packageId)](#module*DB API* zcl database access..selectAllEnumItems) ⇒ - [~selectEnumById(db, id)](#module*DB API* zcl database access..selectEnumById) ⇒ - [~selectEnumByName(db, name, packageIds)](#module*DB API* zcl database access..selectEnumByName) ⇒ + - [~selectEnumByNameAndClusterId(db, name, clusterId, packageIds)](#module*DB API* zcl database access..selectEnumByNameAndClusterId) ⇒ - [~selectSessionClusterByCode(db, sessionId)](#module*DB API* zcl database access..selectSessionClusterByCode) ⇒ - [~selectAllSessionClusters(db, sessionId)](#module*DB API* zcl database access..selectAllSessionClusters) ⇒ - [~selectSessionAttributeByCode(db, sessionId)](#module*DB API* zcl database access..selectSessionAttributeByCode) ⇒ - [~selectSessionCommandByCode(db, sessionId)](#module*DB API* zcl database access..selectSessionCommandByCode) ⇒ + - [~selectStructByNameAndClusterId(db, name, clusterId, packageIds)](#module*DB API* zcl database access..selectStructByNameAndClusterId) ⇒ - [~selectStructsWithClusterAssociation(db, packageIds, groupByStructName)](#module*DB API* zcl database access..selectStructsWithClusterAssociation) ⇒ - [~selectClusterBitmaps(db, packageId, clusterId)](#module*DB API* zcl database access..selectClusterBitmaps) ⇒ - [~selectAllDomains(db)](#module*DB API* zcl database access..selectAllDomains) ⇒ @@ -3352,11 +3707,12 @@ Clears the entire cache. **Kind**: inner method of [DB API: zcl database access](#module*DB API* zcl database access) -### DB API: zcl database access~put(key, packageId, data) +### DB API: zcl database access~put(key, packageId, data) ⇒ Puts a data object into the cache under a given key/packageId -**Kind**: inner method of [DB API: zcl database access](#module*DB API* zcl database access) +**Kind**: inner method of [DB API: zcl database access](#module*DB API* zcl database access) +**Returns**: Returns true on success. | Param | Type | | --------- | --------------- | @@ -3371,7 +3727,7 @@ Puts a data object into the cache under a given key/packageId Returns a data object under a given key/packageId. **Kind**: inner method of [DB API: zcl database access](#module*DB API* zcl database access) -**Returns**: cached object or null if none is present +**Returns**: cached object or undefined if none is present or expired. | Param | Type | | --------- | --------------- | @@ -3392,6 +3748,46 @@ Returns true if a given key/packageId cache exists. | key | \* | | packageId | \* | + + +### DB API: zcl database access~cacheQuery(key, packageId) ⇒ + +Cache input / output of provided queryFunction +The queryFunction is assumed to have the following signature: + +async function queryFunction(db, ...) {...} + +The DB handle is ignored and the remaining arguments are used as the cache key. + +**Kind**: inner method of [DB API: zcl database access](#module*DB API* zcl database access) +**Returns**: true or false, depending on whether the cache is present. + +| Param | Type | +| --------- | --------------- | +| key | \* | +| packageId | \* | + + + +### DB API: zcl database access~cacheStats() + +Returns the cache statistics. + +**Kind**: inner method of [DB API: zcl database access](#module*DB API* zcl database access) + + +### DB API: zcl database access~enable() + +Enable the Database Query cache + +**Kind**: inner method of [DB API: zcl database access](#module*DB API* zcl database access) + + +### DB API: zcl database access~disable() + +Disable the database cache + +**Kind**: inner method of [DB API: zcl database access](#module*DB API* zcl database access) ### DB API: zcl database access~selectAtomicType(db, packageId, typeName) @@ -3432,6 +3828,22 @@ Retrieves all the bitmaps in the database. | ----- | --------------- | | db | \* | + + +### DB API: zcl database access~selectBitmapByNameAndClusterId(db, name, clusterId, packageIds) ⇒ + +Select a bitmap matched by name and clusterId. + +**Kind**: inner method of [DB API: zcl database access](#module*DB API* zcl database access) +**Returns**: bitmap information or undefined + +| Param | Type | +| ---------- | --------------- | +| db | \* | +| name | \* | +| clusterId | \* | +| packageIds | \* | + ### DB API: zcl database access~selectAllEnums(db, packageId) ⇒ @@ -3518,6 +3930,22 @@ Select an enum matched by name. | name | \* | | packageIds | \* | + + +### DB API: zcl database access~selectEnumByNameAndClusterId(db, name, clusterId, packageIds) ⇒ + +Select an enum matched by name and clusterId. + +**Kind**: inner method of [DB API: zcl database access](#module*DB API* zcl database access) +**Returns**: enum information or undefined + +| Param | Type | +| ---------- | --------------- | +| db | \* | +| name | \* | +| clusterId | \* | +| packageIds | \* | + ### DB API: zcl database access~selectSessionClusterByCode(db, sessionId) ⇒ @@ -3574,6 +4002,22 @@ Returns the command available to this session by the code. | db | \* | | sessionId | \* | + + +### DB API: zcl database access~selectStructByNameAndClusterId(db, name, clusterId, packageIds) ⇒ + +Select a struct matched by name and clusterId + +**Kind**: inner method of [DB API: zcl database access](#module*DB API* zcl database access) +**Returns**: struct information or undefined + +| Param | Type | +| ---------- | --------------- | +| db | \* | +| name | \* | +| clusterId | \* | +| packageIds | \* | + ### DB API: zcl database access~selectStructsWithClusterAssociation(db, packageIds, groupByStructName) ⇒ @@ -4278,12 +4722,6 @@ This module provides notification related queries. This module provides queries related to packages. - - -## DB API: session related queries. - -This module provides session related queries. - ## DB API: zcl database access @@ -4294,22 +4732,29 @@ all visible clusters, etc. - [DB API: zcl database access](#module*DB API* zcl database access) - [~clear()](#module*DB API* zcl database access..clear) - - [~put(key, packageId, data)](#module*DB API* zcl database access..put) + - [~put(key, packageId, data)](#module*DB API* zcl database access..put) ⇒ - [~get(key, packageId)](#module*DB API* zcl database access..get) ⇒ - [~isCached(key, packageId)](#module*DB API* zcl database access..isCached) ⇒ + - [~cacheQuery(key, packageId)](#module*DB API* zcl database access..cacheQuery) ⇒ + - [~cacheStats()](#module*DB API* zcl database access..cacheStats) + - [~enable()](#module*DB API* zcl database access..enable) + - [~disable()](#module*DB API* zcl database access..disable) - [~selectAtomicType(db, packageId, typeName)](#module*DB API* zcl database access..selectAtomicType) - [~selectAtomicById(db, packageId)](#module*DB API* zcl database access..selectAtomicById) - [~selectAllBitmaps(db)](#module*DB API* zcl database access..selectAllBitmaps) ⇒ + - [~selectBitmapByNameAndClusterId(db, name, clusterId, packageIds)](#module*DB API* zcl database access..selectBitmapByNameAndClusterId) ⇒ - [~selectAllEnums(db, packageId)](#module*DB API* zcl database access..selectAllEnums) ⇒ - [~selectClusterEnums(db, packageId, clusterId)](#module*DB API* zcl database access..selectClusterEnums) ⇒ - [~selectAllEnumItemsById(db, id)](#module*DB API* zcl database access..selectAllEnumItemsById) ⇒ - [~selectAllEnumItems(db, packageId)](#module*DB API* zcl database access..selectAllEnumItems) ⇒ - [~selectEnumById(db, id)](#module*DB API* zcl database access..selectEnumById) ⇒ - [~selectEnumByName(db, name, packageIds)](#module*DB API* zcl database access..selectEnumByName) ⇒ + - [~selectEnumByNameAndClusterId(db, name, clusterId, packageIds)](#module*DB API* zcl database access..selectEnumByNameAndClusterId) ⇒ - [~selectSessionClusterByCode(db, sessionId)](#module*DB API* zcl database access..selectSessionClusterByCode) ⇒ - [~selectAllSessionClusters(db, sessionId)](#module*DB API* zcl database access..selectAllSessionClusters) ⇒ - [~selectSessionAttributeByCode(db, sessionId)](#module*DB API* zcl database access..selectSessionAttributeByCode) ⇒ - [~selectSessionCommandByCode(db, sessionId)](#module*DB API* zcl database access..selectSessionCommandByCode) ⇒ + - [~selectStructByNameAndClusterId(db, name, clusterId, packageIds)](#module*DB API* zcl database access..selectStructByNameAndClusterId) ⇒ - [~selectStructsWithClusterAssociation(db, packageIds, groupByStructName)](#module*DB API* zcl database access..selectStructsWithClusterAssociation) ⇒ - [~selectClusterBitmaps(db, packageId, clusterId)](#module*DB API* zcl database access..selectClusterBitmaps) ⇒ - [~selectAllDomains(db)](#module*DB API* zcl database access..selectAllDomains) ⇒ @@ -4337,11 +4782,12 @@ Clears the entire cache. **Kind**: inner method of [DB API: zcl database access](#module*DB API* zcl database access) -### DB API: zcl database access~put(key, packageId, data) +### DB API: zcl database access~put(key, packageId, data) ⇒ Puts a data object into the cache under a given key/packageId -**Kind**: inner method of [DB API: zcl database access](#module*DB API* zcl database access) +**Kind**: inner method of [DB API: zcl database access](#module*DB API* zcl database access) +**Returns**: Returns true on success. | Param | Type | | --------- | --------------- | @@ -4356,7 +4802,7 @@ Puts a data object into the cache under a given key/packageId Returns a data object under a given key/packageId. **Kind**: inner method of [DB API: zcl database access](#module*DB API* zcl database access) -**Returns**: cached object or null if none is present +**Returns**: cached object or undefined if none is present or expired. | Param | Type | | --------- | --------------- | @@ -4377,6 +4823,46 @@ Returns true if a given key/packageId cache exists. | key | \* | | packageId | \* | + + +### DB API: zcl database access~cacheQuery(key, packageId) ⇒ + +Cache input / output of provided queryFunction +The queryFunction is assumed to have the following signature: + +async function queryFunction(db, ...) {...} + +The DB handle is ignored and the remaining arguments are used as the cache key. + +**Kind**: inner method of [DB API: zcl database access](#module*DB API* zcl database access) +**Returns**: true or false, depending on whether the cache is present. + +| Param | Type | +| --------- | --------------- | +| key | \* | +| packageId | \* | + + + +### DB API: zcl database access~cacheStats() + +Returns the cache statistics. + +**Kind**: inner method of [DB API: zcl database access](#module*DB API* zcl database access) + + +### DB API: zcl database access~enable() + +Enable the Database Query cache + +**Kind**: inner method of [DB API: zcl database access](#module*DB API* zcl database access) + + +### DB API: zcl database access~disable() + +Disable the database cache + +**Kind**: inner method of [DB API: zcl database access](#module*DB API* zcl database access) ### DB API: zcl database access~selectAtomicType(db, packageId, typeName) @@ -4417,6 +4903,22 @@ Retrieves all the bitmaps in the database. | ----- | --------------- | | db | \* | + + +### DB API: zcl database access~selectBitmapByNameAndClusterId(db, name, clusterId, packageIds) ⇒ + +Select a bitmap matched by name and clusterId. + +**Kind**: inner method of [DB API: zcl database access](#module*DB API* zcl database access) +**Returns**: bitmap information or undefined + +| Param | Type | +| ---------- | --------------- | +| db | \* | +| name | \* | +| clusterId | \* | +| packageIds | \* | + ### DB API: zcl database access~selectAllEnums(db, packageId) ⇒ @@ -4503,6 +5005,22 @@ Select an enum matched by name. | name | \* | | packageIds | \* | + + +### DB API: zcl database access~selectEnumByNameAndClusterId(db, name, clusterId, packageIds) ⇒ + +Select an enum matched by name and clusterId. + +**Kind**: inner method of [DB API: zcl database access](#module*DB API* zcl database access) +**Returns**: enum information or undefined + +| Param | Type | +| ---------- | --------------- | +| db | \* | +| name | \* | +| clusterId | \* | +| packageIds | \* | + ### DB API: zcl database access~selectSessionClusterByCode(db, sessionId) ⇒ @@ -4559,6 +5077,22 @@ Returns the command available to this session by the code. | db | \* | | sessionId | \* | + + +### DB API: zcl database access~selectStructByNameAndClusterId(db, name, clusterId, packageIds) ⇒ + +Select a struct matched by name and clusterId + +**Kind**: inner method of [DB API: zcl database access](#module*DB API* zcl database access) +**Returns**: struct information or undefined + +| Param | Type | +| ---------- | --------------- | +| db | \* | +| name | \* | +| clusterId | \* | +| packageIds | \* | + ### DB API: zcl database access~selectStructsWithClusterAssociation(db, packageIds, groupByStructName) ⇒ @@ -4810,6 +5344,12 @@ Query for attributes by side. | side | \* | | packageId | \* | + + +## DB API: session related queries. + +This module provides session related queries. + ## DB API: zcl database access @@ -4818,22 +5358,29 @@ This module provides queries for enums. - [DB API: zcl database access](#module*DB API* zcl database access) - [~clear()](#module*DB API* zcl database access..clear) - - [~put(key, packageId, data)](#module*DB API* zcl database access..put) + - [~put(key, packageId, data)](#module*DB API* zcl database access..put) ⇒ - [~get(key, packageId)](#module*DB API* zcl database access..get) ⇒ - [~isCached(key, packageId)](#module*DB API* zcl database access..isCached) ⇒ + - [~cacheQuery(key, packageId)](#module*DB API* zcl database access..cacheQuery) ⇒ + - [~cacheStats()](#module*DB API* zcl database access..cacheStats) + - [~enable()](#module*DB API* zcl database access..enable) + - [~disable()](#module*DB API* zcl database access..disable) - [~selectAtomicType(db, packageId, typeName)](#module*DB API* zcl database access..selectAtomicType) - [~selectAtomicById(db, packageId)](#module*DB API* zcl database access..selectAtomicById) - [~selectAllBitmaps(db)](#module*DB API* zcl database access..selectAllBitmaps) ⇒ + - [~selectBitmapByNameAndClusterId(db, name, clusterId, packageIds)](#module*DB API* zcl database access..selectBitmapByNameAndClusterId) ⇒ - [~selectAllEnums(db, packageId)](#module*DB API* zcl database access..selectAllEnums) ⇒ - [~selectClusterEnums(db, packageId, clusterId)](#module*DB API* zcl database access..selectClusterEnums) ⇒ - [~selectAllEnumItemsById(db, id)](#module*DB API* zcl database access..selectAllEnumItemsById) ⇒ - [~selectAllEnumItems(db, packageId)](#module*DB API* zcl database access..selectAllEnumItems) ⇒ - [~selectEnumById(db, id)](#module*DB API* zcl database access..selectEnumById) ⇒ - [~selectEnumByName(db, name, packageIds)](#module*DB API* zcl database access..selectEnumByName) ⇒ + - [~selectEnumByNameAndClusterId(db, name, clusterId, packageIds)](#module*DB API* zcl database access..selectEnumByNameAndClusterId) ⇒ - [~selectSessionClusterByCode(db, sessionId)](#module*DB API* zcl database access..selectSessionClusterByCode) ⇒ - [~selectAllSessionClusters(db, sessionId)](#module*DB API* zcl database access..selectAllSessionClusters) ⇒ - [~selectSessionAttributeByCode(db, sessionId)](#module*DB API* zcl database access..selectSessionAttributeByCode) ⇒ - [~selectSessionCommandByCode(db, sessionId)](#module*DB API* zcl database access..selectSessionCommandByCode) ⇒ + - [~selectStructByNameAndClusterId(db, name, clusterId, packageIds)](#module*DB API* zcl database access..selectStructByNameAndClusterId) ⇒ - [~selectStructsWithClusterAssociation(db, packageIds, groupByStructName)](#module*DB API* zcl database access..selectStructsWithClusterAssociation) ⇒ - [~selectClusterBitmaps(db, packageId, clusterId)](#module*DB API* zcl database access..selectClusterBitmaps) ⇒ - [~selectAllDomains(db)](#module*DB API* zcl database access..selectAllDomains) ⇒ @@ -4861,11 +5408,12 @@ Clears the entire cache. **Kind**: inner method of [DB API: zcl database access](#module*DB API* zcl database access) -### DB API: zcl database access~put(key, packageId, data) +### DB API: zcl database access~put(key, packageId, data) ⇒ Puts a data object into the cache under a given key/packageId -**Kind**: inner method of [DB API: zcl database access](#module*DB API* zcl database access) +**Kind**: inner method of [DB API: zcl database access](#module*DB API* zcl database access) +**Returns**: Returns true on success. | Param | Type | | --------- | --------------- | @@ -4880,7 +5428,7 @@ Puts a data object into the cache under a given key/packageId Returns a data object under a given key/packageId. **Kind**: inner method of [DB API: zcl database access](#module*DB API* zcl database access) -**Returns**: cached object or null if none is present +**Returns**: cached object or undefined if none is present or expired. | Param | Type | | --------- | --------------- | @@ -4901,6 +5449,46 @@ Returns true if a given key/packageId cache exists. | key | \* | | packageId | \* | + + +### DB API: zcl database access~cacheQuery(key, packageId) ⇒ + +Cache input / output of provided queryFunction +The queryFunction is assumed to have the following signature: + +async function queryFunction(db, ...) {...} + +The DB handle is ignored and the remaining arguments are used as the cache key. + +**Kind**: inner method of [DB API: zcl database access](#module*DB API* zcl database access) +**Returns**: true or false, depending on whether the cache is present. + +| Param | Type | +| --------- | --------------- | +| key | \* | +| packageId | \* | + + + +### DB API: zcl database access~cacheStats() + +Returns the cache statistics. + +**Kind**: inner method of [DB API: zcl database access](#module*DB API* zcl database access) + + +### DB API: zcl database access~enable() + +Enable the Database Query cache + +**Kind**: inner method of [DB API: zcl database access](#module*DB API* zcl database access) + + +### DB API: zcl database access~disable() + +Disable the database cache + +**Kind**: inner method of [DB API: zcl database access](#module*DB API* zcl database access) ### DB API: zcl database access~selectAtomicType(db, packageId, typeName) @@ -4941,6 +5529,22 @@ Retrieves all the bitmaps in the database. | ----- | --------------- | | db | \* | + + +### DB API: zcl database access~selectBitmapByNameAndClusterId(db, name, clusterId, packageIds) ⇒ + +Select a bitmap matched by name and clusterId. + +**Kind**: inner method of [DB API: zcl database access](#module*DB API* zcl database access) +**Returns**: bitmap information or undefined + +| Param | Type | +| ---------- | --------------- | +| db | \* | +| name | \* | +| clusterId | \* | +| packageIds | \* | + ### DB API: zcl database access~selectAllEnums(db, packageId) ⇒ @@ -5027,6 +5631,22 @@ Select an enum matched by name. | name | \* | | packageIds | \* | + + +### DB API: zcl database access~selectEnumByNameAndClusterId(db, name, clusterId, packageIds) ⇒ + +Select an enum matched by name and clusterId. + +**Kind**: inner method of [DB API: zcl database access](#module*DB API* zcl database access) +**Returns**: enum information or undefined + +| Param | Type | +| ---------- | --------------- | +| db | \* | +| name | \* | +| clusterId | \* | +| packageIds | \* | + ### DB API: zcl database access~selectSessionClusterByCode(db, sessionId) ⇒ @@ -5083,6 +5703,22 @@ Returns the command available to this session by the code. | db | \* | | sessionId | \* | + + +### DB API: zcl database access~selectStructByNameAndClusterId(db, name, clusterId, packageIds) ⇒ + +Select a struct matched by name and clusterId + +**Kind**: inner method of [DB API: zcl database access](#module*DB API* zcl database access) +**Returns**: struct information or undefined + +| Param | Type | +| ---------- | --------------- | +| db | \* | +| name | \* | +| clusterId | \* | +| packageIds | \* | + ### DB API: zcl database access~selectStructsWithClusterAssociation(db, packageIds, groupByStructName) ⇒ @@ -5342,22 +5978,29 @@ This module provides queries for ZCL static queries. - [DB API: zcl database access](#module*DB API* zcl database access) - [~clear()](#module*DB API* zcl database access..clear) - - [~put(key, packageId, data)](#module*DB API* zcl database access..put) + - [~put(key, packageId, data)](#module*DB API* zcl database access..put) ⇒ - [~get(key, packageId)](#module*DB API* zcl database access..get) ⇒ - [~isCached(key, packageId)](#module*DB API* zcl database access..isCached) ⇒ + - [~cacheQuery(key, packageId)](#module*DB API* zcl database access..cacheQuery) ⇒ + - [~cacheStats()](#module*DB API* zcl database access..cacheStats) + - [~enable()](#module*DB API* zcl database access..enable) + - [~disable()](#module*DB API* zcl database access..disable) - [~selectAtomicType(db, packageId, typeName)](#module*DB API* zcl database access..selectAtomicType) - [~selectAtomicById(db, packageId)](#module*DB API* zcl database access..selectAtomicById) - [~selectAllBitmaps(db)](#module*DB API* zcl database access..selectAllBitmaps) ⇒ + - [~selectBitmapByNameAndClusterId(db, name, clusterId, packageIds)](#module*DB API* zcl database access..selectBitmapByNameAndClusterId) ⇒ - [~selectAllEnums(db, packageId)](#module*DB API* zcl database access..selectAllEnums) ⇒ - [~selectClusterEnums(db, packageId, clusterId)](#module*DB API* zcl database access..selectClusterEnums) ⇒ - [~selectAllEnumItemsById(db, id)](#module*DB API* zcl database access..selectAllEnumItemsById) ⇒ - [~selectAllEnumItems(db, packageId)](#module*DB API* zcl database access..selectAllEnumItems) ⇒ - [~selectEnumById(db, id)](#module*DB API* zcl database access..selectEnumById) ⇒ - [~selectEnumByName(db, name, packageIds)](#module*DB API* zcl database access..selectEnumByName) ⇒ + - [~selectEnumByNameAndClusterId(db, name, clusterId, packageIds)](#module*DB API* zcl database access..selectEnumByNameAndClusterId) ⇒ - [~selectSessionClusterByCode(db, sessionId)](#module*DB API* zcl database access..selectSessionClusterByCode) ⇒ - [~selectAllSessionClusters(db, sessionId)](#module*DB API* zcl database access..selectAllSessionClusters) ⇒ - [~selectSessionAttributeByCode(db, sessionId)](#module*DB API* zcl database access..selectSessionAttributeByCode) ⇒ - [~selectSessionCommandByCode(db, sessionId)](#module*DB API* zcl database access..selectSessionCommandByCode) ⇒ + - [~selectStructByNameAndClusterId(db, name, clusterId, packageIds)](#module*DB API* zcl database access..selectStructByNameAndClusterId) ⇒ - [~selectStructsWithClusterAssociation(db, packageIds, groupByStructName)](#module*DB API* zcl database access..selectStructsWithClusterAssociation) ⇒ - [~selectClusterBitmaps(db, packageId, clusterId)](#module*DB API* zcl database access..selectClusterBitmaps) ⇒ - [~selectAllDomains(db)](#module*DB API* zcl database access..selectAllDomains) ⇒ @@ -5385,11 +6028,12 @@ Clears the entire cache. **Kind**: inner method of [DB API: zcl database access](#module*DB API* zcl database access) -### DB API: zcl database access~put(key, packageId, data) +### DB API: zcl database access~put(key, packageId, data) ⇒ Puts a data object into the cache under a given key/packageId -**Kind**: inner method of [DB API: zcl database access](#module*DB API* zcl database access) +**Kind**: inner method of [DB API: zcl database access](#module*DB API* zcl database access) +**Returns**: Returns true on success. | Param | Type | | --------- | --------------- | @@ -5404,7 +6048,7 @@ Puts a data object into the cache under a given key/packageId Returns a data object under a given key/packageId. **Kind**: inner method of [DB API: zcl database access](#module*DB API* zcl database access) -**Returns**: cached object or null if none is present +**Returns**: cached object or undefined if none is present or expired. | Param | Type | | --------- | --------------- | @@ -5425,7 +6069,47 @@ Returns true if a given key/packageId cache exists. | key | \* | | packageId | \* | - + + +### DB API: zcl database access~cacheQuery(key, packageId) ⇒ + +Cache input / output of provided queryFunction +The queryFunction is assumed to have the following signature: + +async function queryFunction(db, ...) {...} + +The DB handle is ignored and the remaining arguments are used as the cache key. + +**Kind**: inner method of [DB API: zcl database access](#module*DB API* zcl database access) +**Returns**: true or false, depending on whether the cache is present. + +| Param | Type | +| --------- | --------------- | +| key | \* | +| packageId | \* | + + + +### DB API: zcl database access~cacheStats() + +Returns the cache statistics. + +**Kind**: inner method of [DB API: zcl database access](#module*DB API* zcl database access) + + +### DB API: zcl database access~enable() + +Enable the Database Query cache + +**Kind**: inner method of [DB API: zcl database access](#module*DB API* zcl database access) + + +### DB API: zcl database access~disable() + +Disable the database cache + +**Kind**: inner method of [DB API: zcl database access](#module*DB API* zcl database access) + ### DB API: zcl database access~selectAtomicType(db, packageId, typeName) @@ -5465,6 +6149,22 @@ Retrieves all the bitmaps in the database. | ----- | --------------- | | db | \* | + + +### DB API: zcl database access~selectBitmapByNameAndClusterId(db, name, clusterId, packageIds) ⇒ + +Select a bitmap matched by name and clusterId. + +**Kind**: inner method of [DB API: zcl database access](#module*DB API* zcl database access) +**Returns**: bitmap information or undefined + +| Param | Type | +| ---------- | --------------- | +| db | \* | +| name | \* | +| clusterId | \* | +| packageIds | \* | + ### DB API: zcl database access~selectAllEnums(db, packageId) ⇒ @@ -5551,6 +6251,22 @@ Select an enum matched by name. | name | \* | | packageIds | \* | + + +### DB API: zcl database access~selectEnumByNameAndClusterId(db, name, clusterId, packageIds) ⇒ + +Select an enum matched by name and clusterId. + +**Kind**: inner method of [DB API: zcl database access](#module*DB API* zcl database access) +**Returns**: enum information or undefined + +| Param | Type | +| ---------- | --------------- | +| db | \* | +| name | \* | +| clusterId | \* | +| packageIds | \* | + ### DB API: zcl database access~selectSessionClusterByCode(db, sessionId) ⇒ @@ -5607,6 +6323,22 @@ Returns the command available to this session by the code. | db | \* | | sessionId | \* | + + +### DB API: zcl database access~selectStructByNameAndClusterId(db, name, clusterId, packageIds) ⇒ + +Select a struct matched by name and clusterId + +**Kind**: inner method of [DB API: zcl database access](#module*DB API* zcl database access) +**Returns**: struct information or undefined + +| Param | Type | +| ---------- | --------------- | +| db | \* | +| name | \* | +| clusterId | \* | +| packageIds | \* | + ### DB API: zcl database access~selectStructsWithClusterAssociation(db, packageIds, groupByStructName) ⇒ @@ -7285,7 +8017,7 @@ This module contains the API for templating. For more detailed instructions, rea - [~user_cluster_commands_all_endpoints(options)](#module*Templating API* user-data specific helpers..user_cluster_commands_all_endpoints) - [~user_cluster_has_enabled_command(name, side)](#module*Templating API* user-data specific helpers..user_cluster_has_enabled_command) ⇒ - [~all_user_cluster_commands_irrespective_of_manufaturing_specification(options)](#module*Templating API* user-data specific helpers..all_user_cluster_commands_irrespective_of_manufaturing_specification) ⇒ - - [~all_user_cluster_attributes_irrespective_of_manufatucuring_specification(options)](#module*Templating API* user-data specific helpers..all_user_cluster_attributes_irrespective_of_manufatucuring_specification) ⇒ + - [~enabled_attributes_for_cluster_and_side(name, side, options)](#module*Templating API* user-data specific helpers..enabled_attributes_for_cluster_and_side) ⇒ - [~user_session_key(options)](#module*Templating API* user-data specific helpers..user_session_key) ⇒ - [~if_command_discovery_enabled()](#module*Templating API* user-data specific helpers..if_command_discovery_enabled) - [~is_command_default_response_enabled(command, options)](#module*Templating API* user-data specific helpers..is_command_default_response_enabled) ⇒ @@ -7644,20 +8376,29 @@ and non-manufacturing specific cluster commands. | ------- | | options | - + -### Templating API: user-data specific helpers~all_user_cluster_attributes_irrespective_of_manufatucuring_specification(options) ⇒ +### Templating API: user-data specific helpers~enabled_attributes_for_cluster_and_side(name, side, options) ⇒ Creates endpoint type cluster attribute iterator. This fetches all -manufacturing and non-manufaturing specific attributes which have been enabled -on added endpoints +manufacturing-specific and standard attributes which have been enabled on +added endpoints based on the name and side of the cluster. When side +is not mentioned then client and server attributes are returned. +Available Options: + +- removeKeys: Removes one or more keys from the map(for eg keys in db-mapping.js) + for eg:(#enabled_attributes_for_cluster_and_side + [cluster-name], [cluster-side], removeKeys='isOptional, isNullable') + will remove 'isOptional' and 'isNullable' from the results **Kind**: inner method of [Templating API: user-data specific helpers](#module*Templating API* user-data specific helpers) **Returns**: Promise of the resolved blocks iterating over manufacturing specific -and non-manufacturing specific cluster attributes. +and standard cluster attributes. | Param | | ------- | +| name | +| side | | options | @@ -8421,12 +9162,12 @@ This module contains the API for templating. For more detailed instructions, rea - [~command_mask(commmandSource, clusterSide, isIncomingEnabled, isOutgoingEnabled, manufacturingCode, prefixForMask)](#module*Templating API* static zcl helpers..command_mask) ⇒ - [~command_mask_sub_helper(commandMask, str)](#module*Templating API* static zcl helpers..command_mask_sub_helper) ⇒ - [~format_zcl_string_as_characters_for_generated_defaults(stringVal, sizeOfString)](#module*Templating API* static zcl helpers..format_zcl_string_as_characters_for_generated_defaults) ⇒ - - [~get_sign_and_size_of_zcl_type(type, context, options)](#module*Templating API* static zcl helpers..get_sign_and_size_of_zcl_type) ⇒ - [~as_type_min_value(type, options)](#module*Templating API* static zcl helpers..as_type_min_value) ⇒ - [~as_type_max_value(type, options)](#module*Templating API* static zcl helpers..as_type_max_value) ⇒ - [~structs_with_clusters(options)](#module*Templating API* static zcl helpers..structs_with_clusters) - [~as_zcl_type_size(type, options)](#module*Templating API* static zcl helpers..as_zcl_type_size) ⇒ - [~if_compare(leftValue, rightValue, options)](#module*Templating API* static zcl helpers..if_compare) ⇒ Object + - [~as_underlying_zcl_type_chip_callback_name(type, dataType, hash, context)](#module*Templating API* static zcl helpers..as_underlying_zcl_type_chip_callback_name) ⇒ @@ -8757,6 +9498,11 @@ that belong to that cluster. Iterator over the server attributes. If it is used at toplevel, if iterates over all the server attributes in the database. If used within zcl_cluster context, it iterates over all the server attributes that belong to that cluster. +Available Options: + +- removeKeys: Removes one or more keys from the map(for eg keys in db-mapping.js) + for eg: (#zcl_attributes_server removeKeys='isOptional, isNullable') will remove 'isOptional' + from the results **Kind**: inner method of [Templating API: static zcl helpers](#module*Templating API* static zcl helpers) **Returns**: Promise of attribute iteration. @@ -9417,6 +10163,10 @@ will return: 0x00, 0x00, 0x38, 0x40, **Kind**: inner method of [Templating API: static zcl helpers](#module*Templating API* static zcl helpers) **Returns**: Formatted attribute value based on given arguments +Available options: + +- endian: Specify 'big' or 'little' endian format +- isCommaTerminated: '0' or '1' for output to have a ',' at the end | Param | | ------------- | @@ -9430,6 +10180,9 @@ will return: 0x00, 0x00, 0x38, 0x40, Given the attributes of a zcl attribute. Creates an attribute mask based on the given options +Available options: +isClusterCodeMfgSpecific: 0/1, This is to determine if cluster code needs to +be used to determine if a cluster is mfg specific or not. **Kind**: inner method of [Templating API: static zcl helpers](#module*Templating API* static zcl helpers) **Returns**: attribute mask based on given values @@ -9489,6 +10242,12 @@ for example: will return as follows: 3, 'a', 'b', 'c' 0, 0 +Available Options: + +- isOctet: 0/1 can be used to return results correctly for octet strings +- isCommaTerminated: 0/1 can be used to return result with/without ',' at + the end + **Kind**: inner method of [Templating API: static zcl helpers](#module*Templating API* static zcl helpers) **Returns**: Formatted string for generated defaults starting with the lenth of a string then each character and then filler for the size allocated for the @@ -9499,30 +10258,6 @@ string. Long strings prefixed by 2 byte length field. | stringVal | | sizeOfString | - - -### Templating API: static zcl helpers~get_sign_and_size_of_zcl_type(type, context, options) ⇒ - -Given a zcl device type returns its sign, size and zcl data type info stored -in the database table. -Note: Enums and Bitmaps are considered to be unsigned. - -**Kind**: inner method of [Templating API: static zcl helpers](#module*Templating API* static zcl helpers) -**Returns**: returns sign, size and info of zcl device type -Available Options: - -- size: Determine whether to calculate the size of zcl device type in bits - or bytes - for eg: get_sign_and_size_of_zcl_type('int8u' this size='bits') will return - the size in bits which will be 8. If not mentioned then it will return the size - in bytes i.e. 1 in this case. - -| Param | Type | -| ------- | --------------- | -| type | \* | -| context | \* | -| options | \* | - ### Templating API: static zcl helpers~as_type_min_value(type, options) ⇒ @@ -9613,6 +10348,25 @@ Content when comparison returns false | rightValue | \* | | options | \* | + + +### Templating API: static zcl helpers~as_underlying_zcl_type_chip_callback_name(type, dataType, hash, context) ⇒ + +Available Options: + +- asUpperCamelCase: 0/1 to return cpp data type starting with lower/upper + camel case + +**Kind**: inner method of [Templating API: static zcl helpers](#module*Templating API* static zcl helpers) +**Returns**: The corresponding chip callback name for a zcl data type. + +| Param | Type | +| -------- | --------------- | +| type | \* | +| dataType | \* | +| hash | \* | +| context | \* | + ## Templating API: Overridable functions. @@ -11044,6 +11798,7 @@ This module provides the REST API to the admin functions. - [REST API: admin functions](#module*REST API* admin functions) - [~httpPostSql(db, app)](#module*REST API* admin functions..httpPostSql) ⇒ - [~httpGetVersion(db)](#module*REST API* admin functions..httpGetVersion) ⇒ + - [~httpGetCache(db)](#module*REST API* admin functions..httpGetCache) @@ -11098,6 +11853,29 @@ Response JSON: | ----- | --------------- | | db | \* | + + +### REST API: admin functions~httpGetCache(db) + +API: /cache +Response JSON: + +
+	 {
+     keys: 0,    // global key count
+     hits: 0,    // global hit count
+     misses: 0,  // global miss count
+     ksize: 0,   // global key size count in approximately bytes
+     vsize: 0    // global value size count in approximately bytes
+	 }
+
+ +**Kind**: inner method of [REST API: admin functions](#module*REST API* admin functions) + +| Param | Type | +| ----- | --------------- | +| db | \* | + ## REST API: endpoint @@ -11350,6 +12128,71 @@ Enable components by 'componentId' or corresponding components specified, via 'd | ----- | --------------- | | db | \* | + + +## REST API: initialization functions + +This module provides the REST API to the session initialization + +- [REST API: initialization functions](#module*REST API* initialization functions) + - [~packagesAndSessions(db)](#module*REST API* initialization functions..packagesAndSessions) ⇒ + - [~initializeSession(db, options:)](#module*REST API* initialization functions..initializeSession) ⇒ + - [~loadPreviousSessions(db)](#module*REST API* initialization functions..loadPreviousSessions) ⇒ + - [~init(db)](#module*REST API* initialization functions..init) ⇒ + + + +### REST API: initialization functions~packagesAndSessions(db) ⇒ + +This function returns Properties, Templates and Dirty-Sessions + +**Kind**: inner method of [REST API: initialization functions](#module*REST API* initialization functions) +**Returns**: Properties, Templates and Dirty-Sessions. + +| Param | Type | +| ----- | --------------- | +| db | \* | + + + +### REST API: initialization functions~initializeSession(db, options:) ⇒ + +This function creates a new session with its packages according to selected Properties and Templates + +**Kind**: inner method of [REST API: initialization functions](#module*REST API* initialization functions) +**Returns**: A success message. + +| Param | Type | Description | +| -------- | --------------- | -------------------------------------- | +| db | \* | | +| options: | \* | object containing 'zcl' and 'template' | + + + +### REST API: initialization functions~loadPreviousSessions(db) ⇒ + +This function reloads previous session by user selected session's id + +**Kind**: inner method of [REST API: initialization functions](#module*REST API* initialization functions) +**Returns**: A success message. + +| Param | Type | +| ----- | --------------- | +| db | \* | + + + +### REST API: initialization functions~init(db) ⇒ + +Init function from the App.vue + +**Kind**: inner method of [REST API: initialization functions](#module*REST API* initialization functions) +**Returns**: A success message. + +| Param | Type | +| ----- | --------------- | +| db | \* | + ## REST API: static zcl functions @@ -12038,6 +12881,7 @@ logger is used for printouts. - [~isSignedInteger(type)](#module*JS API* type related utilities..isSignedInteger) ⇒ - [~isOneBytePrefixedString(type)](#module*JS API* type related utilities..isOneBytePrefixedString) ⇒ - [~isTwoBytePrefixedString(type)](#module*JS API* type related utilities..isTwoBytePrefixedString) ⇒ + - [~getSignAndSizeOfZclType(type, context, options)](#module*JS API* type related utilities..getSignAndSizeOfZclType) ⇒ @@ -12192,6 +13036,30 @@ Checks if type is a two-byte lengh string. | ----- | --------------- | | type | \* | + + +### JS API: type related utilities~getSignAndSizeOfZclType(type, context, options) ⇒ + +Given a zcl device type returns its sign, size and zcl data type info stored +in the database table. +Note: Enums and Bitmaps are considered to be unsigned. + +**Kind**: inner method of [JS API: type related utilities](#module*JS API* type related utilities) +**Returns**: returns sign, size and info of zcl device type +Available Options: + +- size: Determine whether to calculate the size of zcl device type in bits + or bytes + for eg: getSignAndSizeOfZclType('int8u' this size='bits') will return + the size in bits which will be 8. If not mentioned then it will return the size + in bytes i.e. 1 in this case. + +| Param | Type | +| ------- | --------------- | +| type | \* | +| context | \* | +| options | \* | + ## JS API: random utilities @@ -12491,6 +13359,7 @@ This module provides the API to access various zcl utilities. - [~clusterComparator(a, b)](#module*REST API* various zcl utilities..clusterComparator) ⇒ - [~attributeComparator(a, b)](#module*REST API* various zcl utilities..attributeComparator) ⇒ - [~commandComparator(a, b)](#module*REST API* various zcl utilities..commandComparator) ⇒ + - [~eventComparator(a, b)](#module*REST API* various zcl utilities..eventComparator) ⇒ - [~sortStructsByDependency(structs)](#module*REST API* various zcl utilities..sortStructsByDependency) ⇒ - [~calculateBytes(res, options, db, packageIds, isStructType)](#module*REST API* various zcl utilities..calculateBytes) - [~optionsHashOrDefault(options, optionsKey, defaultValue)](#module*REST API* various zcl utilities..optionsHashOrDefault) @@ -12503,6 +13372,7 @@ This module provides the API to access various zcl utilities. - [~dataTypeHelper(type, options, packageIds, db, resolvedType, overridable)](#module*REST API* various zcl utilities..dataTypeHelper) ⇒ - [~asUnderlyingZclTypeWithPackageId(type, options, packageIds, currentInstance)](#module*REST API* various zcl utilities..asUnderlyingZclTypeWithPackageId) - [~determineType(db, type, packageIds)](#module*REST API* various zcl utilities..determineType) + - [~zcl_data_type_size_and_sign(type, dataType, clusterId, packageIds, context)](#module*REST API* various zcl utilities..zcl_data_type_size_and_sign) ⇒ @@ -12546,6 +13416,20 @@ Comparator for sorting commands. | a | \* | | b | \* | + + +### REST API: various zcl utilities~eventComparator(a, b) ⇒ + +Comparator for sorting events. + +**Kind**: inner method of [REST API: various zcl utilities](#module*REST API* various zcl utilities) +**Returns**: -1, 0 or 1 + +| Param | Type | +| ----- | --------------- | +| a | \* | +| b | \* | + ### REST API: various zcl utilities~sortStructsByDependency(structs) ⇒ @@ -12736,6 +13620,21 @@ Base type for struct is a null. | type | \* | | packageIds | \* | + + +### REST API: various zcl utilities~zcl_data_type_size_and_sign(type, dataType, clusterId, packageIds, context) ⇒ + +**Kind**: inner method of [REST API: various zcl utilities](#module*REST API* various zcl utilities) +**Returns**: The size and sign of a zcl data type + +| Param | Type | +| ---------- | --------------- | +| type | \* | +| dataType | \* | +| clusterId | \* | +| packageIds | \* | +| context | \* | + ## renderer_api @@ -13310,6 +14209,23 @@ with its actual type from disciminator table. | name | | packageIds | + + +## selectDataTypeByNameAndClusterId(db, name, clusterId, packageIds) ⇒ + +Gathers the data type information based on data type name and +clusterId along with its actual type from disciminator table. + +**Kind**: global function +**Returns**: Data type information + +| Param | +| ---------- | +| db | +| name | +| clusterId | +| packageIds | + ## selectAllDataTypes(db, packageId) ⇒ @@ -13356,6 +14272,21 @@ Select an number matched by name. | name | | packageIds | + + +## selectNumberByNameAndClusterId(db, name, packageIds) ⇒ + +Select a number matched by name and clusterId + +**Kind**: global function +**Returns**: number information or undefined + +| Param | +| ---------- | +| db | +| name | +| packageIds | + ## selectNumberById(db, name) ⇒ @@ -13435,6 +14366,56 @@ Valid within a cluster context, requires code. **Kind**: global function **Returns**: Produces attribute defaults. + + +## if_unsupported_attribute_callback(type, isArray, clusterId, options) ⇒ + +If helper that checks if an attribute is not supported based on language +being generated for. +For eg: In java, an attribute callback is not supported when it is a struct. +However it is supported if it is an array of structs. +Available Options: + +- language: attribute callback support based on language + +**Kind**: global function +**Returns**: Promise of content + +| Param | Type | +| --------- | --------------- | +| type | \* | +| isArray | \* | +| clusterId | \* | +| options | \* | + + + +## if_basic_attribute(type, clusterId, options) ⇒ + +If helper that checks if an attribute is basic or not based on language +being generated for. +For eg: In java, an attribute is not basic if it is either nullable, optional, +array type or struct. +Note: This helper should be used within an attribute block helper. +Available Options: + +- language: Determine basic attribute based on language. + example: + {{#if_basic_attribute type}} + type is basic + {{else}} + type is not basic + {{/if_basic_attribute}} + +**Kind**: global function +**Returns**: Promise of content + +| Param | Type | +| --------- | --------------- | +| type | \* | +| clusterId | \* | +| options | \* | + ## if_command_arguments_exist(commandId, argument_return, no_argument_return) @@ -13752,7 +14733,21 @@ the indexes in attribute table. | ------- | --------------- | | options | \* | - + + +## endpoint_reporting_config_defaults(options) + +This helper supports an "order" CSV string, such as: +"direction,endpoint,clusterId,attributeId,mask,mfgCode,minmax" +The string above is a default value, and it determines in what order are the fields generated. + +**Kind**: global function + +| Param | Type | +| ------- | --------------- | +| options | \* | + + ## collectAttributes() @@ -13881,6 +14876,80 @@ span all attributes from all clusters from all endpointTypes. This helper function allows the template to increment the token ID within the tokens context. **Kind**: global function + + +## token_attribute_util(context, options) ⇒ + +Util function that extracts all the token attribute information. + +**Kind**: global function +**Returns**: Information on all token attributes in the configuration. + +| Param | Type | +| ------- | --------------- | +| context | \* | +| options | \* | + + + +## token_attributes(endpointTypeRef, options) ⇒ + +Get information about all the token attributes in the configuration or this +helper can be used within an endpoint block helper to fetch the +corresponding token attributes based on endpoint type given. +Available Options: +isSingleton: 0/1, option can be used to filter attributes based on singleton +or non-singleton(Available with endpointTypeRef only) + +**Kind**: global function +**Returns**: singleton and non-singleton token attributes along with their +endpoint information. Singleton attributes are only returned once whereas +non-singleton attributes are returned per endpoint. However if used within +an endpoint block helper it returns token_attributes for a given endpoint +type. + +| Param | Type | +| --------------- | --------------- | +| endpointTypeRef | \* | +| options | \* | + + + +## token_attribute_clusters(endpointTypeRef, options) ⇒ + +This helper can return all token associated clusters across endpoints or +this helper can be used within an endpoint block helper to fetch the +corresponding token associated clusters. +Available Options: +isSingleton: 0/1, option can be used to filter clusters based on singleton +or non-singleton attributes. + +**Kind**: global function +**Returns**: Token associated clusters for a particular endpoint type or all +token associated clusters across endpoints. + +| Param | Type | +| --------------- | --------------- | +| endpointTypeRef | \* | +| options | \* | + + + +## token_attribute_endpoints(options) ⇒ + +Get all endpoints which have token attributes in the configuration. +AvailableOptions: + +- isSingleton: 0/1, option can be used to filter endpoints based on singleton + or non-singleton. + +**Kind**: global function +**Returns**: all endpoints with token attributes + +| Param | Type | +| ------- | --------------- | +| options | \* | + ## get_cli_size(size, type, allowZclTypes) ⇒ @@ -14175,34 +15244,6 @@ Session at this point is blank, and has no packages. | state | \* | | sessionId | \* | - - -## readDataFromFile(filePath) ⇒ - -Reads the data from the file and resolves with the state object if all is good. - -**Kind**: global function -**Returns**: Promise of file reading. - -| Param | Type | -| -------- | --------------- | -| filePath | \* | - - - -## importDataFromFile(db, filePath) ⇒ - -Writes the data from the file into a new session. -NOTE: This function does NOT initialize session packages. - -**Kind**: global function -**Returns**: a promise that resolves with the import result object that contains: sessionId, errors, warnings. - -| Param | Type | -| -------- | --------------- | -| db | \* | -| filePath | \* | - ## importSessionKeyValues(db, sessionId, keyValuePairs) @@ -14278,6 +15319,34 @@ Parses JSON file and creates a state object out of it, which is passed further d | filePath | \* | | data | \* | + + +## readDataFromFile(filePath) ⇒ + +Reads the data from the file and resolves with the state object if all is good. + +**Kind**: global function +**Returns**: Promise of file reading. + +| Param | Type | +| -------- | --------------- | +| filePath | \* | + + + +## importDataFromFile(db, filePath) ⇒ + +Writes the data from the file into a new session. +NOTE: This function does NOT initialize session packages. + +**Kind**: global function +**Returns**: a promise that resolves with the import result object that contains: sessionId, errors, warnings. + +| Param | Type | +| -------- | --------------- | +| db | \* | +| filePath | \* | + ## initSessionTimers() @@ -14451,46 +15520,6 @@ Default startup method. | quitFunction | \* | | argv | \* | - - -## packagesAndSessions(db) ⇒ - -This function returns Properties, Templates and Dirty-Sessions - -**Kind**: global function -**Returns**: Properties, Templates and Dirty-Sessions. - -| Param | Type | -| ----- | --------------- | -| db | \* | - - - -## initializeSession(db, options:) ⇒ - -This function creates a new session with its packages according to selected Properties and Templates - -**Kind**: global function -**Returns**: A success message. - -| Param | Type | Description | -| -------- | --------------- | -------------------------------------- | -| db | \* | | -| options: | \* | object containing 'zcl' and 'template' | - - - -## loadPreviousSessions(db) ⇒ - -This function reloads previous session by user selected session's id - -**Kind**: global function -**Returns**: A success message. - -| Param | Type | -| ----- | --------------- | -| db | \* | - ## doOpen(menuItem, browserWindow, event) @@ -15131,118 +16160,6 @@ and orchestrates the promise chain. | db | \* | | | ctx | \* | Context of loading. | - - -## recordToplevelPackage(db, metadataFile, crc) ⇒ - -Records the toplevel package information and resolves into packageId - -**Kind**: global function -**Returns**: packageId - -| Param | Type | -| ------------ | --------------- | -| db | \* | -| metadataFile | \* | -| crc | \* | - - - -## recordVersion(db, ctx) - -Records the version into the database. - -**Kind**: global function - -| Param | Type | -| ----- | --------------- | -| db | \* | -| ctx | \* | - - - -## loadZclMetafiles(db, metadataFile) ⇒ - -Toplevel function that loads the zcl file and passes it off to the correct zcl loader. - -**Kind**: global function -**Returns**: Array of loaded packageIds. - -| Param | Type | Description | -| ------------ | --------------- | -------------- | -| db | \* | | -| metadataFile | \* | array of paths | - - - -## loadZcl(db, metadataFile) ⇒ - -Loads individual zcl.json metafile. - -**Kind**: global function -**Returns**: Context object that contains .db and .packageId - -| Param | Type | -| ------------ | --------------- | -| db | \* | -| metadataFile | \* | - - - -## loadIndividualFile(db, filePath, sessionId) - -Load individual custom XML files. - -**Kind**: global function - -| Param | Type | Description | -| --------- | --------------- | ----------------------------------------------------- | -| db | \* | | -| filePath | \* | | -| sessionId | \* | Current session within which we're loading this file. | - - - -## qualifyZclFile(db, info, parentPackageId) ⇒ - -Promises to qualify whether zcl file needs to be reloaded. -If yes, the it will resolve with {filePath, data, packageId} -If not, then it will resolve with {error} - -**Kind**: global function -**Returns**: Promise that resolves int he object of data. - -| Param | Type | -| --------------- | --------------- | -| db | \* | -| info | \* | -| parentPackageId | \* | - - - -## processZclPostLoading(db) ⇒ - -Promises to perform a post loading step. - -**Kind**: global function -**Returns**: Promise to deal with the post-loading cleanup. - -| Param | Type | -| ----- | --------------- | -| db | \* | - - - -## getDiscriminatorMap(db, packageIds) ⇒ - -**Kind**: global function -**Returns**: data type discriminator map - -| Param | Type | -| ---------- | --------------- | -| db | \* | -| packageIds | \* | - ## collectDataFromJsonFile(ctx) ⇒ @@ -16021,3 +16938,115 @@ and orchestrates the promise chain. | ----- | --------------- | ----------------------- | | db | \* | | | ctx | \* | The context of loading. | + + + +## recordToplevelPackage(db, metadataFile, crc) ⇒ + +Records the toplevel package information and resolves into packageId + +**Kind**: global function +**Returns**: packageId + +| Param | Type | +| ------------ | --------------- | +| db | \* | +| metadataFile | \* | +| crc | \* | + + + +## recordVersion(db, ctx) + +Records the version into the database. + +**Kind**: global function + +| Param | Type | +| ----- | --------------- | +| db | \* | +| ctx | \* | + + + +## loadZclMetafiles(db, metadataFile) ⇒ + +Toplevel function that loads the zcl file and passes it off to the correct zcl loader. + +**Kind**: global function +**Returns**: Array of loaded packageIds. + +| Param | Type | Description | +| ------------ | --------------- | -------------- | +| db | \* | | +| metadataFile | \* | array of paths | + + + +## loadZcl(db, metadataFile) ⇒ + +Loads individual zcl.json metafile. + +**Kind**: global function +**Returns**: Context object that contains .db and .packageId + +| Param | Type | +| ------------ | --------------- | +| db | \* | +| metadataFile | \* | + + + +## loadIndividualFile(db, filePath, sessionId) + +Load individual custom XML files. + +**Kind**: global function + +| Param | Type | Description | +| --------- | --------------- | ----------------------------------------------------- | +| db | \* | | +| filePath | \* | | +| sessionId | \* | Current session within which we're loading this file. | + + + +## qualifyZclFile(db, info, parentPackageId) ⇒ + +Promises to qualify whether zcl file needs to be reloaded. +If yes, the it will resolve with {filePath, data, packageId} +If not, then it will resolve with {error} + +**Kind**: global function +**Returns**: Promise that resolves int he object of data. + +| Param | Type | +| --------------- | --------------- | +| db | \* | +| info | \* | +| parentPackageId | \* | + + + +## processZclPostLoading(db) ⇒ + +Promises to perform a post loading step. + +**Kind**: global function +**Returns**: Promise to deal with the post-loading cleanup. + +| Param | Type | +| ----- | --------------- | +| db | \* | + + + +## getDiscriminatorMap(db, packageIds) ⇒ + +**Kind**: global function +**Returns**: data type discriminator map + +| Param | Type | +| ---------- | --------------- | +| db | \* | +| packageIds | \* | diff --git a/src-electron/db/db-mapping.js b/src-electron/db/db-mapping.js index ec75213ba9..a533b77ba1 100644 --- a/src-electron/db/db-mapping.js +++ b/src-electron/db/db-mapping.js @@ -23,6 +23,7 @@ const dbApi = require('./db-api.js') const dbEnums = require('../../src-shared/db-enum.js') +const bin = require('../util/bin') exports.map = { package: (x) => { @@ -93,7 +94,7 @@ exports.map = { manufacturerCode: x.MANUFACTURER_CODE, name: x.NAME, label: x.NAME, - type: x.TYPE, + type: x.TYPE != 'array' ? x.TYPE : x.ARRAY_TYPE, side: x.SIDE, define: x.DEFINE, min: x.MIN, @@ -105,15 +106,20 @@ exports.map = { reportableChange: x.REPORTABLE_CHANGE, reportableChangeLength: x.REPORTABLE_CHANGE_LENGTH, isWritable: dbApi.fromDbBool(x.IS_WRITABLE), + isWritableAttribute: dbApi.fromDbBool(x.IS_WRITABLE), isNullable: dbApi.fromDbBool(x.IS_NULLABLE), defaultValue: x.DEFAULT_VALUE, isOptional: dbApi.fromDbBool(x.IS_OPTIONAL), isReportable: x.REPORTING_POLICY == dbEnums.reportingPolicy.mandatory || x.REPORTING_POLICY == dbEnums.reportingPolicy.suggested, + isReportableAttribute: + x.REPORTING_POLICY == dbEnums.reportingPolicy.mandatory || + x.REPORTING_POLICY == dbEnums.reportingPolicy.suggested, reportingPolicy: x.REPORTING_POLICY, isSceneRequired: dbApi.fromDbBool(x.IS_SCENE_REQUIRED), entryType: x.ARRAY_TYPE, + isArray: x.ARRAY_TYPE ? 1 : 0, mustUseTimedWrite: dbApi.fromDbBool(x.MUST_USE_TIMED_WRITE), } }, @@ -475,36 +481,61 @@ exports.map = { endpointTypeAttributeExtended: (x) => { if (x == null) return undefined return { - endpointTypeRef: x.ENDPOINT_TYPE_REF, - clusterRef: x.CLUSTER_REF, + arrayType: x.ARRAY_TYPE, attributeRef: x.ATTRIBUTE_REF, - included: dbApi.fromDbBool(x.INCLUDED), - storageOption: x.STORAGE_OPTION, - singleton: dbApi.fromDbBool(x.SINGLETON), bounded: dbApi.fromDbBool(x.BOUNDED), - defaultValue: x.DEFAULT_VALUE, - includedReportable: dbApi.fromDbBool(x.INCLUDED_REPORTABLE), - minInterval: x.MIN_INTERVAL, - maxInterval: x.MAX_INTERVAL, - reportableChange: x.REPORTABLE_CHANGE, - name: x.NAME, // Attribute Name - code: x.CODE, // Attribute Code - side: x.SIDE, // Attribute Side - define: x.DEFINE, // Attribute define - type: x.TYPE, // Attribute type - mfgCode: x.MANUFACTURER_CODE - ? x.MANUFACTURER_CODE - : x.CLUSTER_MANUFACTURER_CODE, // Attribute manufacturer code + clusterDefine: x.CLUSTER_DEFINE, clusterMfgCode: x.CLUSTER_MANUFACTURER_CODE, clusterName: x.CLUSTER_NAME, - clusterDefine: x.CLUSTER_DEFINE, - isSingleton: dbApi.fromDbBool(x.SINGLETON), // Endpoint type attribute is singleton or not + clusterRef: x.CLUSTER_REF, + clusterSide: x.SIDE, + code: x.CODE, // Attribute Code + defaultValue: x.DEFAULT_VALUE, + define: x.DEFINE, // Attribute define + endpointId: x.ENDPOINT_IDENTIFIER, // Endpoint type attribute's endpoint Id + endpointTypeRef: x.ENDPOINT_TYPE_REF, + entryType: x.ARRAY_TYPE, + hexCode: '0x' + bin.int16ToHex(x['CODE'] ? x['CODE'] : 0), // Attribute code in hex + id: x.ATTRIBUTE_ID, // Attribute id + included: dbApi.fromDbBool(x.INCLUDED), + includedReportable: dbApi.fromDbBool(x.INCLUDED_REPORTABLE), // Is attribute reportable + isArray: x.IS_ARRAY, // Is attribute of type array + isBound: dbApi.fromDbBool(x.BOUNDED), // Is endpoint type attribute bounded + isClusterEnabled: x.ENABLED, + isGlobalAttribute: x.IS_GLOBAL_ATTRIBUTE, // Is attribute global + isIncluded: dbApi.fromDbBool(x.INCLUDED), // Is endpoint type attribute included isManufacturingSpecific: dbApi.toDbBool( x.MANUFACTURER_CODE | x.CLUSTER_MANUFACTURER_CODE ), // Is Attribute mfg specific or not - endpointId: x.ENDPOINT_IDENTIFIER, // Endpoint type attribute's endpoint Id - tokenId: x.TOKEN_ID, // Endpoint type attribute's token id + isNullable: dbApi.fromDbBool(x.IS_NULLABLE), // Is attribute nullable + isOptionalAttribute: dbApi.fromDbBool(x.IS_OPTIONAL), + isReportableAttribute: dbApi.fromDbBool(x.INCLUDED_REPORTABLE), // Is attribute reportable + isSceneRequired: dbApi.fromDbBool(x.IS_SCENE_REQUIRED), + isSingleton: dbApi.fromDbBool(x.SINGLETON), // Endpoint type attribute is singleton or not + isWritable: dbApi.fromDbBool(x.IS_WRITABLE), // Is attribute writable + isWritableAttribute: dbApi.fromDbBool(x.IS_WRITABLE), // Is attribute writable + manufacturerCode: x.MANUFACTURER_CODE + ? x.MANUFACTURER_CODE + : x.CLUSTER_MANUFACTURER_CODE, // Attribute manufacturer code + max: x.MAX, // Attribute max value + maxInterval: x.MAX_INTERVAL, + maxLength: x.MAX_LENGTH, // Attribute max length + mfgCode: x.MANUFACTURER_CODE + ? x.MANUFACTURER_CODE + : x.CLUSTER_MANUFACTURER_CODE, // Attribute manufacturer code + min: x.MIN, // Attribute min value + minInterval: x.MIN_INTERVAL, + minLength: x.MIN_LENGTH, // Attribute min length + mustUseTimedWrite: dbApi.fromDbBool(x.MUST_USE_TIMED_WRITE), + name: x.NAME, // Attribute Name + reportableChange: x.REPORTABLE_CHANGE, + side: x.SIDE, // Attribute Side + singleton: dbApi.fromDbBool(x.SINGLETON), smallestEndpointIdentifier: x.SMALLEST_ENDPOINT_IDENTIFIER, // Smallest endpoint Id in which the attribute is present + storage: x.STORAGE_OPTION, + storageOption: x.STORAGE_OPTION, + tokenId: x.TOKEN_ID, // Endpoint type attribute's token id + type: x.TYPE != 'array' ? x.TYPE : x.ARRAY_TYPE, // Attribute type } }, diff --git a/src-electron/db/query-attribute.js b/src-electron/db/query-attribute.js index 41079dc0d7..2f5eb10b1d 100644 --- a/src-electron/db/query-attribute.js +++ b/src-electron/db/query-attribute.js @@ -23,21 +23,6 @@ const dbApi = require('./db-api.js') const dbMapping = require('./db-mapping.js') -function attributeExportMapping(x) { - return { - id: x.ATTRIBUTE_ID, - name: x.NAME, - code: x.CODE, - side: x.SIDE, - type: x.TYPE, - define: x.DEFINE, - mfgCode: x.MANUFACTURER_CODE, - clusterSide: x.SIDE, - clusterName: x.CLUSTER_NAME, - isClusterEnabled: x.ENABLED, - } -} - /** * Promises to select all endpoint type attributes filtered by EndpointTypeRef and ClusterRef. * @@ -146,13 +131,19 @@ async function duplicateEndpointTypeAttribute( * @param {*} db * @param {*} endpointTypeId * @param {*} packageIds + * @param {*} side * @returns Promise that resolves with the attribute data. */ async function selectAllAttributeDetailsFromEnabledClusters( db, endpointsAndClusters, - packageIds + packageIds, + side = null ) { + let sideFilter = '' + if (side) { + sideFilter = ` AND ATTRIBUTE.SIDE = '${side}' ` + } let endpointTypeClusterRef = endpointsAndClusters .map((ep) => ep.endpointTypeClusterRef) .toString() @@ -165,26 +156,71 @@ async function selectAllAttributeDetailsFromEnabledClusters( ATTRIBUTE.NAME, ATTRIBUTE.CODE, ATTRIBUTE.SIDE, - ATTRIBUTE.TYPE, + CASE + WHEN + ATTRIBUTE.ARRAY_TYPE IS NULL + THEN + ATTRIBUTE.TYPE + ELSE + ATTRIBUTE.ARRAY_TYPE + END AS TYPE, ATTRIBUTE.DEFINE, ATTRIBUTE.MANUFACTURER_CODE, ENDPOINT_TYPE_CLUSTER.SIDE, CLUSTER.NAME AS CLUSTER_NAME, - ENDPOINT_TYPE_CLUSTER.ENABLED + ENDPOINT_TYPE_CLUSTER.ENABLED, + CASE + WHEN + ATTRIBUTE.ARRAY_TYPE IS NOT NULL + THEN + 1 + ELSE + 0 + END AS IS_ARRAY, + ATTRIBUTE.IS_WRITABLE, + ATTRIBUTE.IS_NULLABLE, + ATTRIBUTE.MAX_LENGTH, + ATTRIBUTE.MIN_LENGTH, + ATTRIBUTE.MIN, + ATTRIBUTE.MAX, + ATTRIBUTE.ARRAY_TYPE, + ATTRIBUTE.MUST_USE_TIMED_WRITE, + ATTRIBUTE.IS_SCENE_REQUIRED, + ATTRIBUTE.IS_OPTIONAL, + CASE + WHEN + ATTRIBUTE.CLUSTER_REF IS NULL + THEN + 1 + ELSE + 0 + END AS IS_GLOBAL_ATTRIBUTE, + ENDPOINT_TYPE_ATTRIBUTE.INCLUDED_REPORTABLE, + ENDPOINT_TYPE_ATTRIBUTE.STORAGE_OPTION, + ENDPOINT_TYPE_ATTRIBUTE.SINGLETON, + ENDPOINT_TYPE_ATTRIBUTE.BOUNDED, + ENDPOINT_TYPE_ATTRIBUTE.INCLUDED, + ENDPOINT_TYPE_ATTRIBUTE.DEFAULT_VALUE, + ENDPOINT_TYPE_ATTRIBUTE.MIN_INTERVAL, + ENDPOINT_TYPE_ATTRIBUTE.MAX_INTERVAL, + ENDPOINT_TYPE_ATTRIBUTE.REPORTABLE_CHANGE FROM ATTRIBUTE INNER JOIN ENDPOINT_TYPE_ATTRIBUTE ON ATTRIBUTE.ATTRIBUTE_ID = ENDPOINT_TYPE_ATTRIBUTE.ATTRIBUTE_REF - INNER JOIN CLUSTER - ON ATTRIBUTE.CLUSTER_REF = CLUSTER.CLUSTER_ID INNER JOIN ENDPOINT_TYPE_CLUSTER - ON CLUSTER.CLUSTER_ID = ENDPOINT_TYPE_CLUSTER.CLUSTER_REF + ON ENDPOINT_TYPE_ATTRIBUTE.ENDPOINT_TYPE_CLUSTER_REF = ENDPOINT_TYPE_CLUSTER.ENDPOINT_TYPE_CLUSTER_ID + INNER JOIN CLUSTER + ON ENDPOINT_TYPE_CLUSTER.CLUSTER_REF = CLUSTER.CLUSTER_ID WHERE ENDPOINT_TYPE_CLUSTER.CLUSTER_REF IN (${endpointTypeClusterRef}) AND ENDPOINT_TYPE_ATTRIBUTE.INCLUDED = 1 - AND ATTRIBUTE.PACKAGE_REF IN (${dbApi.toInClause(packageIds)}) - GROUP BY ATTRIBUTE.NAME + AND ENDPOINT_TYPE_CLUSTER.ENABLED = 1 + AND ATTRIBUTE.PACKAGE_REF IN (${dbApi.toInClause(packageIds)}) + ${sideFilter} + GROUP BY CLUSTER.MANUFACTURER_CODE, CLUSTER.CODE, ATTRIBUTE.MANUFACTURER_CODE, ATTRIBUTE.CODE, ATTRIBUTE.SIDE + ORDER BY ATTRIBUTE.CODE ` ) - .then((rows) => rows.map(attributeExportMapping)) + .then((rows) => rows.map(dbMapping.map.endpointTypeAttributeExtended)) } /** @@ -247,7 +283,7 @@ async function selectAttributeDetailsFromAllEndpointTypesAndClustersUtil( GROUP BY ATTRIBUTE.NAME ` ) - .then((rows) => rows.map(attributeExportMapping)) + .then((rows) => rows.map(dbMapping.map.endpointTypeAttributeExtended)) } /** diff --git a/src-electron/db/query-bitmap.js b/src-electron/db/query-bitmap.js index c9220f4a86..306d151e14 100644 --- a/src-electron/db/query-bitmap.js +++ b/src-electron/db/query-bitmap.js @@ -68,6 +68,62 @@ WHERE (DATA_TYPE.NAME = ? OR DATA_TYPE.NAME = ?) AND DATA_TYPE.PACKAGE_REF IN ($ .then(dbMapping.map.bitmap) } +/** + * Select a bitmap matched by name and clusterId. + * @param {*} db + * @param {*} name + * @param {*} clusterId + * @param {*} packageIds + * @returns bitmap information or undefined + */ +async function selectBitmapByNameAndClusterId(db, name, clusterId, packageIds) { + let res = await dbApi + .dbAll( + db, + ` + SELECT + BITMAP.BITMAP_ID, + DATA_TYPE.NAME AS NAME, + BITMAP.SIZE AS SIZE + FROM BITMAP + INNER JOIN DATA_TYPE ON BITMAP.BITMAP_ID = DATA_TYPE.DATA_TYPE_ID + WHERE (DATA_TYPE.NAME = ? OR DATA_TYPE.NAME = ?) AND DATA_TYPE.PACKAGE_REF IN (${dbApi.toInClause( + packageIds + )})`, + [name, name.toLowerCase()] + ) + .then((rows) => rows.map(dbMapping.map.bitmap)) + + if (res && res.length == 1) { + return res[0] + } else { + return dbApi + .dbGet( + db, + ` +SELECT + BITMAP.BITMAP_ID, + DATA_TYPE.NAME AS NAME, + BITMAP.SIZE AS SIZE +FROM BITMAP +INNER JOIN + DATA_TYPE +ON + BITMAP.BITMAP_ID = DATA_TYPE.DATA_TYPE_ID +INNER JOIN + DATA_TYPE_CLUSTER +ON + DATA_TYPE_CLUSTER.DATA_TYPE_REF = BITMAP.BITMAP_ID +WHERE + (DATA_TYPE.NAME = ? OR DATA_TYPE.NAME = ?) + AND DATA_TYPE_CLUSTER.CLUSTER_REF = ? + AND DATA_TYPE.PACKAGE_REF IN (${dbApi.toInClause(packageIds)})`, + [name, name.toLowerCase(), clusterId] + ) + .then(dbMapping.map.bitmap) + } +} + async function selectBitmapById(db, id) { return dbApi .dbGet( @@ -88,3 +144,6 @@ WHERE BITMAP_ID = ?`, exports.selectBitmapById = selectBitmapById exports.selectAllBitmaps = selectAllBitmaps exports.selectBitmapByName = dbCache.cacheQuery(selectBitmapByName) +exports.selectBitmapByNameAndClusterId = dbCache.cacheQuery( + selectBitmapByNameAndClusterId +) diff --git a/src-electron/db/query-data-type.js b/src-electron/db/query-data-type.js index 926bc2384a..d5d5463874 100644 --- a/src-electron/db/query-data-type.js +++ b/src-electron/db/query-data-type.js @@ -94,6 +94,81 @@ async function selectDataTypeByName(db, name, packageIds) { .then(dbMapping.map.dataType) } +/** + * Gathers the data type information based on data type name and + * clusterId along with its actual type from disciminator table. + * @param db + * @param name + * @param clusterId + * @param packageIds + * @returns Data type information + */ +async function selectDataTypeByNameAndClusterId( + db, + name, + clusterId, + packageIds +) { + let smallCaseName = name.toLowerCase() + let res = await dbApi + .dbAll( + db, + ` + SELECT + DATA_TYPE.DATA_TYPE_ID, + DATA_TYPE.NAME AS NAME, + DATA_TYPE.DESCRIPTION, + DATA_TYPE.DISCRIMINATOR_REF, + DATA_TYPE.PACKAGE_REF, + DISCRIMINATOR.NAME AS DISCRIMINATOR_NAME + FROM + DATA_TYPE + INNER JOIN + DISCRIMINATOR + ON + DATA_TYPE.DISCRIMINATOR_REF = DISCRIMINATOR.DISCRIMINATOR_ID + WHERE + (DATA_TYPE.NAME = ? OR DATA_TYPE.NAME = ?) AND DATA_TYPE.PACKAGE_REF IN (${dbApi.toInClause( + packageIds + )})`, + [name, smallCaseName] + ) + .then((rows) => rows.map(dbMapping.map.dataType)) + + if (res && res.length == 1) { + return res[0] + } else { + return dbApi + .dbGet( + db, + ` + SELECT + DATA_TYPE.DATA_TYPE_ID, + DATA_TYPE.NAME AS NAME, + DATA_TYPE.DESCRIPTION, + DATA_TYPE.DISCRIMINATOR_REF, + DATA_TYPE.PACKAGE_REF, + DISCRIMINATOR.NAME AS DISCRIMINATOR_NAME + FROM + DATA_TYPE + INNER JOIN + DISCRIMINATOR + ON + DATA_TYPE.DISCRIMINATOR_REF = DISCRIMINATOR.DISCRIMINATOR_ID + INNER JOIN + DATA_TYPE_CLUSTER + ON + DATA_TYPE.DATA_TYPE_ID = DATA_TYPE_CLUSTER.DATA_TYPE_REF + WHERE + (DATA_TYPE.NAME = ? OR DATA_TYPE.NAME = ?) + AND DATA_TYPE_CLUSTER.CLUSTER_REF = ? + AND DATA_TYPE.PACKAGE_REF IN (${dbApi.toInClause(packageIds)})`, + [name, smallCaseName, clusterId] + ) + .then(dbMapping.map.dataType) + } +} + /** * Gathers All the data types * @param db @@ -186,3 +261,6 @@ exports.selectDataTypeById = selectDataTypeById exports.selectDataTypeByName = dbCache.cacheQuery(selectDataTypeByName) exports.selectAllDataTypes = selectAllDataTypes exports.selectSizeFromType = selectSizeFromType +exports.selectDataTypeByNameAndClusterId = dbCache.cacheQuery( + selectDataTypeByNameAndClusterId +) diff --git a/src-electron/db/query-enum.js b/src-electron/db/query-enum.js index c1304d34e6..cf9d243a3a 100644 --- a/src-electron/db/query-enum.js +++ b/src-electron/db/query-enum.js @@ -210,9 +210,77 @@ ORDER BY NAME`, .then(dbMapping.map.enum) } +/** + * Select an enum matched by name and clusterId. + * + * @param {*} db + * @param {*} name + * @param {*} clusterId + * @param {*} packageIds + * @returns enum information or undefined + */ +async function selectEnumByNameAndClusterId(db, name, clusterId, packageIds) { + let res = await dbApi + .dbAll( + db, + ` +SELECT + ENUM.ENUM_ID, + DATA_TYPE.NAME AS NAME, + ENUM.SIZE AS SIZE +FROM + ENUM +INNER JOIN + DATA_TYPE +ON + ENUM.ENUM_ID = DATA_TYPE.DATA_TYPE_ID +WHERE + (DATA_TYPE.NAME = ? OR DATA_TYPE.NAME = ?)AND PACKAGE_REF IN (${dbApi.toInClause( + packageIds + )}) +ORDER BY NAME`, + [name, name.toLowerCase()] + ) + .then((rows) => rows.map(dbMapping.map.enum)) + + if (res && res.length == 1) { + return res[0] + } else { + return dbApi + .dbGet( + db, + ` +SELECT + ENUM.ENUM_ID, + DATA_TYPE.NAME AS NAME, + ENUM.SIZE AS SIZE +FROM + ENUM +INNER JOIN + DATA_TYPE +ON + ENUM.ENUM_ID = DATA_TYPE.DATA_TYPE_ID +INNER JOIN + DATA_TYPE_CLUSTER +ON + DATA_TYPE_CLUSTER.DATA_TYPE_REF = ENUM.ENUM_ID +WHERE + (DATA_TYPE.NAME = ? OR DATA_TYPE.NAME = ?) + AND DATA_TYPE_CLUSTER.CLUSTER_REF = ? + AND PACKAGE_REF IN (${dbApi.toInClause(packageIds)}) +ORDER BY NAME`, + [name, name.toLowerCase(), clusterId] + ) + .then(dbMapping.map.enum) + } +} + // exports exports.selectAllEnums = selectAllEnums exports.selectEnumByName = dbCache.cacheQuery(selectEnumByName) +exports.selectEnumByNameAndClusterId = dbCache.cacheQuery( + selectEnumByNameAndClusterId +) exports.selectEnumById = selectEnumById exports.selectClusterEnums = selectClusterEnums exports.selectAllEnumItemsById = selectAllEnumItemsById diff --git a/src-electron/db/query-number.js b/src-electron/db/query-number.js index fa3a1a7898..ce78d4dfb1 100644 --- a/src-electron/db/query-number.js +++ b/src-electron/db/query-number.js @@ -48,6 +48,61 @@ async function selectNumberByName(db, packageIds, name) { .then(dbMapping.map.number) } +/** + * Select a number matched by name and clusterId + * + * @param db + * @param name + * @param packageIds + * @returns number information or undefined + */ +async function selectNumberByNameAndClusterId(db, name, clusterId, packageIds) { + let res = await dbApi + .dbAll( + db, + ` + SELECT + NUMBER.NUMBER_ID, + NUMBER.IS_SIGNED, + DATA_TYPE.NAME AS NAME, + NUMBER.SIZE AS SIZE + FROM NUMBER + INNER JOIN DATA_TYPE ON NUMBER.NUMBER_ID = DATA_TYPE.DATA_TYPE_ID + WHERE NAME = ? AND PACKAGE_REF IN (${dbApi.toInClause(packageIds)})`, + [name] + ) + .then((rows) => rows.map(dbMapping.map.number)) + + if (res && res.length == 1) { + return res[0] + } else { + return dbApi + .dbGet( + db, + ` + SELECT + NUMBER.NUMBER_ID, + NUMBER.IS_SIGNED, + DATA_TYPE.NAME AS NAME, + NUMBER.SIZE AS SIZE + FROM + NUMBER + INNER + JOIN DATA_TYPE ON NUMBER.NUMBER_ID = DATA_TYPE.DATA_TYPE_ID + INNER JOIN + DATA_TYPE_CLUSTER + ON + DATA_TYPE_CLUSTER.DATA_TYPE_REF = NUMBER.NUMBER_ID + WHERE + NAME = ? + AND DATA_TYPE_CLUSTER.CLUSTER_REF = ? + AND PACKAGE_REF IN (${dbApi.toInClause(packageIds)})`, + [name, clusterId] + ) + .then(dbMapping.map.number) + } +} + /** * Select an number matched by id. * @@ -99,5 +154,8 @@ async function selectAllNumbers(db, packageId) { } exports.selectNumberByName = dbCache.cacheQuery(selectNumberByName) +exports.selectNumberByNameAndClusterId = dbCache.cacheQuery( + selectNumberByNameAndClusterId +) exports.selectAllNumbers = selectAllNumbers exports.selectNumberById = selectNumberById diff --git a/src-electron/db/query-struct.js b/src-electron/db/query-struct.js index 6bb12b7c90..84276ba586 100644 --- a/src-electron/db/query-struct.js +++ b/src-electron/db/query-struct.js @@ -94,6 +94,69 @@ ORDER BY .then(dbMapping.map.struct) } +/** + * Select a struct matched by name and clusterId + * @param {*} db + * @param {*} name + * @param {*} clusterId + * @param {*} packageIds + * @returns struct information or undefined + */ +async function selectStructByNameAndClusterId(db, name, clusterId, packageIds) { + let res = await dbApi + .dbAll( + db, + ` +SELECT + STRUCT.STRUCT_ID, + STRUCT.IS_FABRIC_SCOPED, + DATA_TYPE.NAME, + DATA_TYPE.DISCRIMINATOR_REF +FROM + STRUCT +INNER JOIN + DATA_TYPE ON STRUCT.STRUCT_ID = DATA_TYPE.DATA_TYPE_ID +WHERE + NAME = ? + AND PACKAGE_REF IN (${dbApi.toInClause(packageIds)}) +ORDER BY + NAME`, + [name] + ) + .then((rows) => rows.map(dbMapping.map.struct)) + + if (res && res.length == 1) { + return res[0] + } else { + return dbApi + .dbGet( + db, + ` + SELECT + STRUCT.STRUCT_ID, + STRUCT.IS_FABRIC_SCOPED, + DATA_TYPE.NAME, + DATA_TYPE.DISCRIMINATOR_REF + FROM + STRUCT + INNER JOIN + DATA_TYPE ON STRUCT.STRUCT_ID = DATA_TYPE.DATA_TYPE_ID + INNER JOIN + DATA_TYPE_CLUSTER + ON + DATA_TYPE.DATA_TYPE_ID = DATA_TYPE_CLUSTER.DATA_TYPE_REF + WHERE + NAME = ? + AND PACKAGE_REF IN (${dbApi.toInClause(packageIds)}) + AND DATA_TYPE_CLUSTER.CLUSTER_REF = ? + ORDER BY + NAME`, + [name, clusterId] + ) + .then(dbMapping.map.struct) + } +} + /** * Get all structs which have a cluster associated with them. If a struct is * present in more than one cluster then it can be grouped by struct name to @@ -144,5 +207,8 @@ WHERE exports.selectStructById = selectStructById exports.selectAllStructs = selectAllStructs exports.selectStructByName = dbCache.cacheQuery(selectStructByName) +exports.selectStructByNameAndClusterId = dbCache.cacheQuery( + selectStructByNameAndClusterId +) exports.selectStructsWithClusterAssociation = selectStructsWithClusterAssociation diff --git a/src-electron/db/query-zcl.js b/src-electron/db/query-zcl.js index 577f4986b5..2328ebffca 100644 --- a/src-electron/db/query-zcl.js +++ b/src-electron/db/query-zcl.js @@ -1132,18 +1132,27 @@ exports.selectAllEnumItemsById = queryEnum.selectAllEnumItemsById exports.selectAllEnumItems = queryEnum.selectAllEnumItems exports.selectEnumById = queryEnum.selectEnumById exports.selectEnumByName = queryEnum.selectEnumByName +exports.selectEnumByNameAndClusterId = queryEnum.selectEnumByNameAndClusterId exports.selectStructById = queryStruct.selectStructById exports.selectStructByName = queryStruct.selectStructByName +exports.selectStructByNameAndClusterId = + queryStruct.selectStructByNameAndClusterId exports.selectBitmapById = queryBitmap.selectBitmapById exports.selectAllBitmaps = queryBitmap.selectAllBitmaps exports.selectBitmapByName = queryBitmap.selectBitmapByName +exports.selectBitmapByNameAndClusterId = + queryBitmap.selectBitmapByNameAndClusterId exports.selectDataTypeById = queryDataType.selectDataTypeById exports.selectDataTypeByName = queryDataType.selectDataTypeByName +exports.selectDataTypeByNameAndClusterId = + queryDataType.selectDataTypeByNameAndClusterId exports.selectNumberByName = queryNumber.selectNumberByName +exports.selectNumberByNameAndClusterId = + queryNumber.selectNumberByNameAndClusterId exports.selectAllDiscriminators = queryDiscriminator.selectAllDiscriminators exports.selectAllDataTypes = queryDataType.selectAllDataTypes diff --git a/src-electron/generator/helper-attribute.js b/src-electron/generator/helper-attribute.js index 39eac9ca05..f1a93c7ffc 100644 --- a/src-electron/generator/helper-attribute.js +++ b/src-electron/generator/helper-attribute.js @@ -17,6 +17,7 @@ const queryAttribute = require('../db/query-attribute') const templateUtil = require('./template-util') +const queryZcl = require('../db/query-zcl') async function featureBits(options) { if ('featureBits' in this) { diff --git a/src-electron/generator/helper-session.js b/src-electron/generator/helper-session.js index 9cc3a49bd4..559edc357b 100644 --- a/src-electron/generator/helper-session.js +++ b/src-electron/generator/helper-session.js @@ -294,7 +294,8 @@ async function all_user_cluster_attribute_util( await queryAttribute.selectAllAttributeDetailsFromEnabledClusters( currentContext.global.db, endpointsAndClusters, - packageIds + packageIds, + side ) } else if (isManufacturingSpecific) { endpointAttributes = @@ -311,6 +312,10 @@ async function all_user_cluster_attribute_util( packageIds ) } + if ('removeKeys' in options.hash) { + let keys = options.hash.removeKeys.split(',') + keys.forEach((k) => endpointAttributes.map((attr) => delete attr[k.trim()])) + } let availableAttributes = [] for (let i = 0; i < endpointAttributes.length; i++) { @@ -612,18 +617,22 @@ function all_user_cluster_commands_irrespective_of_manufaturing_specification( /** * Creates endpoint type cluster attribute iterator. This fetches all - * manufacturing and non-manufaturing specific attributes which have been enabled - * on added endpoints + * manufacturing-specific and standard attributes which have been enabled on + * added endpoints based on the name and side of the cluster. When side + * is not mentioned then client and server attributes are returned. + * Available Options: + * - removeKeys: Removes one or more keys from the map(for eg keys in db-mapping.js) + * for eg:(#enabled_attributes_for_cluster_and_side + * [cluster-name], [cluster-side], removeKeys='isOptional, isNullable') + * will remove 'isOptional' and 'isNullable' from the results * + * @param name + * @param side * @param options * @returns Promise of the resolved blocks iterating over manufacturing specific - * and non-manufacturing specific cluster attributes. + * and standard cluster attributes. */ -function all_user_cluster_attributes_irrespective_of_manufatucuring_specification( - name, - side, - options -) { +function enabled_attributes_for_cluster_and_side(name, side, options) { return all_user_cluster_attribute_util(name, side, options, this, false, true) } @@ -1526,7 +1535,15 @@ exports.all_user_cluster_manufacturer_specific_attributes = exports.all_user_cluster_non_manufacturer_specific_attributes = all_user_cluster_non_manufacturer_specific_attributes exports.all_user_cluster_attributes_irrespective_of_manufatucuring_specification = - all_user_cluster_attributes_irrespective_of_manufatucuring_specification + enabled_attributes_for_cluster_and_side +exports.all_user_cluster_attributes_irrespective_of_manufatucuring_specification = + dep(enabled_attributes_for_cluster_and_side, { + from: 'all_user_cluster_attributes_irrespective_of_manufatucuring_specification', + to: 'enabled_attributes_for_cluster_and_side', + }) +exports.enabled_attributes_for_cluster_and_side = + enabled_attributes_for_cluster_and_side + exports.all_user_cluster_attributes_for_generated_defaults = all_user_cluster_attributes_for_generated_defaults exports.all_user_cluster_generated_attributes = diff --git a/src-electron/generator/helper-zcl.js b/src-electron/generator/helper-zcl.js index 471a68b4cd..8a88b2522f 100644 --- a/src-electron/generator/helper-zcl.js +++ b/src-electron/generator/helper-zcl.js @@ -730,33 +730,39 @@ function zcl_attributes_client(options) { * Iterator over the server attributes. If it is used at toplevel, if iterates over all the server attributes * in the database. If used within zcl_cluster context, it iterates over all the server attributes * that belong to that cluster. - * + * Available Options: + * - removeKeys: Removes one or more keys from the map(for eg keys in db-mapping.js) + * for eg: (#zcl_attributes_server removeKeys='isOptional, isNullable') will remove 'isOptional' + * from the results * @param {*} options * @returns Promise of attribute iteration. */ -function zcl_attributes_server(options) { +async function zcl_attributes_server(options) { // If used at the toplevel, 'this' is the toplevel context object. // when used at the cluster level, 'this' is a cluster - let promise = templateUtil - .ensureZclPackageIds(this) - .then((packageIds) => { - if ('id' in this) { - // We're functioning inside a nested context with an id, so we will only query for this cluster. - return queryZcl.selectAttributesByClusterIdAndSideIncludingGlobal( - this.global.db, - this.id, - packageIds, - dbEnum.side.server - ) - } else { - return queryZcl.selectAllAttributesBySide( - this.global.db, - dbEnum.side.server, - packageIds - ) - } - }) - .then((atts) => templateUtil.collectBlocks(atts, options, this)) + let packageIds = await templateUtil.ensureZclPackageIds(this) + let serverAttributes = '' + if ('id' in this) { + // We're functioning inside a nested context with an id, so we will only query for this cluster. + serverAttributes = + await queryZcl.selectAttributesByClusterIdAndSideIncludingGlobal( + this.global.db, + this.id, + packageIds, + dbEnum.side.server + ) + } else { + serverAttributes = await queryZcl.selectAllAttributesBySide( + this.global.db, + dbEnum.side.server, + packageIds + ) + } + if ('removeKeys' in options.hash) { + let keys = options.hash.removeKeys.split(',') + keys.forEach((k) => serverAttributes.map((attr) => delete attr[k.trim()])) + } + let promise = templateUtil.collectBlocks(serverAttributes, options, this) return templateUtil.templatePromise(this.global, promise) } @@ -2693,6 +2699,83 @@ function if_compare(leftValue, rightValue, options) { } } +/** + * Check if the given type is signed or not based on the type name and cluster + * id. + * @param {*} type + * @param {*} clusterId + * @param {*} options + * @returns Promise of content + */ +async function if_is_data_type_signed(type, clusterId, options) { + // Get ZCL Data Type from the db + const packageIds = await templateUtil.ensureZclPackageIds(this) + let dataType = await queryZcl.selectDataTypeByNameAndClusterId( + this.global.db, + type, + clusterId, + packageIds + ) + + let sizeAndSign = await zclUtil.zcl_data_type_size_and_sign( + type, + dataType, + clusterId, + packageIds, + this + ) + if (sizeAndSign.isSigned) { + return options.fn(this) + } else { + return options.inverse(this) + } +} + +/** + * Fetches the size of the data type based on type name and cluster id given + * Note: size is zero for structs + * Available Options: + * - roundUpToPowerOfTwo: Rounds the size up to the nearest power of 2 + * - sizeIn: By default size is returned in bytes but it can be returned in bits + * by mentioning sizeIn="bits" + * @param {*} type + * @param {*} clusterId + * @param {*} options + * @returns size of the data type + */ +async function as_zcl_data_type_size(type, clusterId, options) { + let hash = options.hash + let sizeMultiple = 1 + let result = 0 + if (hash && hash.sizeIn == 'bits') { + sizeMultiple = 8 + } + + // Get ZCL Data Type from the db + const packageIds = await templateUtil.ensureZclPackageIds(this) + let dataType = await queryZcl.selectDataTypeByNameAndClusterId( + this.global.db, + type, + clusterId, + packageIds + ) + + let sizeAndSign = await zclUtil.zcl_data_type_size_and_sign( + type, + dataType, + clusterId, + packageIds, + this + ) + result = sizeAndSign.size + result = + hash && hash.roundUpToPowerOfTwo + ? Math.pow(2, Math.ceil(Math.log2(result))) + : result + + return result * sizeMultiple +} + const dep = templateUtil.deprecatedHelper // WARNING! WARNING! WARNING! WARNING! WARNING! WARNING! @@ -2864,3 +2947,5 @@ exports.as_type_max_value = as_type_max_value exports.as_type_min_value = as_type_min_value exports.as_zcl_type_size = as_zcl_type_size exports.if_compare = if_compare +exports.if_is_data_type_signed = if_is_data_type_signed +exports.as_zcl_data_type_size = as_zcl_data_type_size diff --git a/src-electron/generator/matter/app/zap-templates/templates/chip/helper.js b/src-electron/generator/matter/app/zap-templates/templates/chip/helper.js index 493d726b58..cd1c01c010 100644 --- a/src-electron/generator/matter/app/zap-templates/templates/chip/helper.js +++ b/src-electron/generator/matter/app/zap-templates/templates/chip/helper.js @@ -745,6 +745,97 @@ async function chip_access_elements(options) { return templateUtil.templatePromise(this.global, p); } +/** + * If helper that checks if an attribute is basic or not based on language + * being generated for. + * For eg: In java, an attribute is not basic if it is either nullable, optional, + * array type or struct. + * Note: This helper should be used within an attribute block helper. + * Available Options: + * - language: Determine basic attribute based on language. + * example: + * {{#if_basic_attribute type}} + * type is basic + * {{else}} + * type is not basic + * {{/if_basic_attribute}} + * @param {*} type + * @param {*} clusterId + * @param {*} options + * @returns Promise of content + */ +async function if_basic_attribute(type, clusterId, options) { + let hash = options.hash; + let language = hash && hash.language ? hash.language : null; + if (language == 'java') { + let struct = null; + if (this.isNullable || this.isOptional || this.isArray) { + return options.inverse(this); + } else { + let packageIds = await templateUtil.ensureZclPackageIds(this); + struct = await queryZcl.selectStructByNameAndClusterId( + this.global.db, + type, + clusterId, + packageIds + ); + if (struct) { + return options.inverse(this); + } else { + return options.fn(this); + } + } + } else { + return options.fn(this); + } +} + +/** + * If helper that checks if an attribute is not supported based on language + * being generated for. + * For eg: In java, an attribute callback is not supported when it is a struct. + * However it is supported if it is an array of structs. + * Available Options: + * - language: attribute callback support based on language + * @param {*} type + * @param {*} isArray + * @param {*} clusterId + * @param {*} options + * @returns Promise of content + */ +async function if_unsupported_attribute_callback( + type, + isArray, + clusterId, + options +) { + let hash = options.hash; + let language = hash && hash.language ? hash.language : null; + if (language == 'java') { + let struct = null; + if (isArray) { + return options.inverse(this); + } else { + let packageIds = await templateUtil.ensureZclPackageIds(this); + struct = await queryZcl.selectStructByNameAndClusterId( + this.global.db, + type, + clusterId, + packageIds + ); + if (struct) { + return options.fn(this); + } else { + return options.inverse(this); + } + } + } else { + return options.inverse(this); + } +} + +const dep = templateUtil.deprecatedHelper; + // // Module exports // @@ -762,7 +853,12 @@ exports.chip_server_global_responses = chip_server_global_responses; exports.chip_cluster_responses = chip_cluster_responses; exports.chip_cluster_response_arguments = chip_cluster_response_arguments; exports.chip_attribute_list_entryTypes = chip_attribute_list_entryTypes; -exports.chip_server_cluster_attributes = chip_server_cluster_attributes; +exports.chip_server_cluster_attributes = dep( + chip_server_cluster_attributes, + 'chip_server_cluster_attributes has been deprecated. Use \ + enabled_attributes_for_cluster_and_side and \ + zcl_attributes_server to get enabled and all server attributes respectively' +); exports.chip_server_cluster_events = chip_server_cluster_events; exports.chip_server_has_list_attributes = chip_server_has_list_attributes; exports.chip_server_has_reportable_attributes = @@ -772,7 +868,9 @@ exports.chip_endpoints = chip_endpoints; exports.chip_endpoint_clusters = chip_endpoint_clusters; exports.if_chip_enum = if_chip_enum; exports.if_chip_complex = if_chip_complex; -exports.if_basic_global_response = if_basic_global_response; +exports.if_basic_global_response = dep(if_basic_global_response, { + to: 'if_basic_attribute', +}); exports.chip_cluster_specific_structs = chip_cluster_specific_structs; exports.chip_shared_structs = chip_shared_structs; exports.chip_access_elements = chip_access_elements; @@ -783,3 +881,5 @@ exports.meta = { category: dbEnum.helperCategory.matter, alias: ['templates/chip/helper.js', 'matter-chip-helper'], }; +exports.if_basic_attribute = if_basic_attribute; +exports.if_unsupported_attribute_callback = if_unsupported_attribute_callback; diff --git a/src-electron/generator/matter/controller/java/templates/helper.js b/src-electron/generator/matter/controller/java/templates/helper.js index f2db53d41f..5a692ecca1 100644 --- a/src-electron/generator/matter/controller/java/templates/helper.js +++ b/src-electron/generator/matter/controller/java/templates/helper.js @@ -23,6 +23,11 @@ const ChipTypesHelper = require('../../../app/zap-templates/common/ChipTypesHelp const StringHelper = require('../../../app/zap-templates/common/StringHelper.js'); const appHelper = require('../../../app/zap-templates/templates/app/helper.js'); const dbEnum = require('../../../../../../src-shared/db-enum'); +const queryZcl = require(zapPath + 'db/query-zcl'); +const zclUtil = require(zapPath + 'util/zcl-util.js'); + +const characterStringTypes = ['CHAR_STRING', 'LONG_CHAR_STRING']; +const octetStringTypes = ['OCTET_STRING', 'LONG_OCTET_STRING']; function convertBasicCTypeToJavaType(cType) { switch (cType) { @@ -187,6 +192,80 @@ function convertAttributeCallbackTypeToJavaName(cType) { } } +/** + * Available options: + * - isBoxedJavaType: 0/1 to return string types in different ways + * - All other options passed to this helper are considered as overrides for + * zcl types + * for eg: (as_underlying_java_zcl_type type clusterId boolean='Boolean') + * will return "Boolean" for "boolean" type + * @param {*} type + * @param {*} clusterId + * @param {*} options + * @returns The corresponding java data type for a zcl data type. + */ +async function as_underlying_java_zcl_type(type, clusterId, options) { + let hash = options.hash; + // Overwrite any type with the one coming from the template options + // Eg: {{as_underlying_java_zcl_type type [clusterId] boolean='Boolean'}} + // Here all types named 'boolean' will be returned as 'Boolean' + if (type in hash) { + return hash[type]; + } + + // Get ZCL Data Type from the db + const packageIds = await templateUtil.ensureZclPackageIds(this); + let dataType = await queryZcl.selectDataTypeByNameAndClusterId( + this.global.db, + type, + clusterId, + packageIds + ); + + if (!dataType) { + env.logWarning(type + ' not found in the data_type table'); + return 0; + } + let isBoxedJavaType = + hash && hash.isBoxedJavaType ? hash.isBoxedJavaType : false; + if ( + dataType.discriminatorName.toLowerCase() == dbEnum.zclType.bitmap || + dataType.discriminatorName.toLowerCase() == dbEnum.zclType.enum || + dataType.discriminatorName.toLowerCase() == dbEnum.zclType.number + ) { + if (dataType.name.includes('float')) { + return 'Float'; + } else if (dataType.name.includes('double')) { + return 'Double'; + } else if (dataType.name.includes('single')) { + return 'Float'; + } else { + let sizeAndSign = await zclUtil.zcl_data_type_size_and_sign( + type, + dataType, + clusterId, + packageIds, + this + ); + if (sizeAndSign.size >= 3) { + return 'Long'; + } + } + return 'Integer'; + } else if (octetStringTypes.includes(type.toUpperCase())) { + return isBoxedJavaType ? 'byte[]' : 'OctetString'; + } else if (characterStringTypes.includes(type.toUpperCase())) { + return isBoxedJavaType ? 'String' : 'CharString'; + } else { + let error = 'Unhandled type ' + type; + if (isBoxedJavaType) { + return 'Object'; + } else { + throw error; + } + } +} + async function asUnderlyingBasicType(type) { const options = { hash: {} }; let zclType = await zclHelper.asUnderlyingZclType.call(this, type, options); @@ -342,12 +421,16 @@ function incrementDepth(depth) { return depth + 1; } +const dep = templateUtil.deprecatedHelper; + // // Module exports // exports.asUnderlyingBasicType = asUnderlyingBasicType; exports.asJavaType = asJavaType; -exports.asJavaBoxedType = asJavaBoxedType; +exports.asJavaBoxedType = dep(asJavaBoxedType, { + to: 'as_underlying_java_zcl_type', +}); exports.asJniType = asJniType; exports.asJniSignature = asJniSignature; exports.asJniClassName = asJniClassName; @@ -356,11 +439,14 @@ exports.asJniSignatureBasic = asJniSignatureBasic; exports.convertBasicCTypeToJniType = convertBasicCTypeToJniType; exports.convertCTypeToJniSignature = convertCTypeToJniSignature; exports.convertBasicCTypeToJavaBoxedType = convertBasicCTypeToJavaBoxedType; -exports.convertAttributeCallbackTypeToJavaName = - convertAttributeCallbackTypeToJavaName; +exports.convertAttributeCallbackTypeToJavaName = dep( + convertAttributeCallbackTypeToJavaName, + { to: 'as_underlying_java_zcl_type' } +); exports.incrementDepth = incrementDepth; exports.meta = { category: dbEnum.helperCategory.matter, alias: ['controller/java/templates/helper.js', 'matter-java-helper'], }; +exports.as_underlying_java_zcl_type = as_underlying_java_zcl_type; diff --git a/src-electron/generator/matter/controller/python/templates/helper.js b/src-electron/generator/matter/controller/python/templates/helper.js index 5d0ddead17..9b2aadf25f 100644 --- a/src-electron/generator/matter/controller/python/templates/helper.js +++ b/src-electron/generator/matter/controller/python/templates/helper.js @@ -16,8 +16,14 @@ */ // Import helpers from zap core +const zapPath = '../../../../../'; const dbEnum = require('../../../../../../src-shared/db-enum'); const ChipTypesHelper = require('../../../app/zap-templates/common/ChipTypesHelper'); +const templateUtil = require(zapPath + 'generator/template-util.js'); +const queryZcl = require(zapPath + 'db/query-zcl'); + +const characterStringTypes = ['CHAR_STRING', 'LONG_CHAR_STRING']; +const octetStringTypes = ['OCTET_STRING', 'LONG_OCTET_STRING']; function asPythonType(zclType) { const type = ChipTypesHelper.asBasicType(zclType); @@ -43,6 +49,58 @@ function asPythonType(zclType) { } } +/** + * + * Available options: + * - All options passed to this helper are considered as overrides for + * zcl types + * for eg: (as_underlying_python_zcl_type type clusterId boolean='bool') + * will return "bool" for "boolean" type + * @param {*} type + * @param {*} clusterId + * @param {*} options + * @returns The corresponding python data type for a zcl data type. + */ +async function as_underlying_python_zcl_type(type, clusterId, options) { + let hash = options.hash; + // Overwrite any type with the one coming from the template options + // Eg: {{as_underlying_python_zcl_type type [clusterId] boolean='bool'}} + // Here all types named 'boolean' will be returned as 'bool' + if (type in hash) { + return hash[type]; + } + + // Get ZCL Data Type from the db + const packageIds = await templateUtil.ensureZclPackageIds(this); + let dataType = await queryZcl.selectDataTypeByNameAndClusterId( + this.global.db, + type, + clusterId, + packageIds + ); + if ( + dataType.discriminatorName.toLowerCase() == dbEnum.zclType.bitmap || + dataType.discriminatorName.toLowerCase() == dbEnum.zclType.enum || + dataType.discriminatorName.toLowerCase() == dbEnum.zclType.number + ) { + // returning nothing for floats + if ( + dataType.name.includes('float') || + dataType.name.includes('double') || + dataType.name.includes('single') + ) { + return ''; + } + return 'int'; + } else if (octetStringTypes.includes(type.toUpperCase())) { + return 'bytes'; + } else if (characterStringTypes.includes(type.toUpperCase())) { + return 'str'; + } else { + return ''; + } +} + function asPythonCType(zclType) { const type = ChipTypesHelper.asBasicType(zclType); switch (type) { @@ -62,13 +120,18 @@ function asPythonCType(zclType) { } } +const dep = templateUtil.deprecatedHelper; + // // Module exports // -exports.asPythonType = asPythonType; +exports.asPythonType = dep(asPythonType, { + to: 'as_underlying_python_zcl_type', +}); exports.asPythonCType = asPythonCType; exports.meta = { category: dbEnum.helperCategory.matter, alias: ['controller/python/templates/helper.js', 'matter-python-helper'], }; +exports.as_underlying_python_zcl_type = as_underlying_python_zcl_type; diff --git a/src-electron/util/zcl-util.js b/src-electron/util/zcl-util.js index 64b38c70f7..6330643f6a 100644 --- a/src-electron/util/zcl-util.js +++ b/src-electron/util/zcl-util.js @@ -797,6 +797,57 @@ async function createCommandSignature(db, packageId, cmd) { } } +/** + * + * @param {*} type + * @param {*} dataType + * @param {*} clusterId + * @param {*} packageIds + * @param {*} context + * @returns The size and sign of a zcl data type + */ +async function zcl_data_type_size_and_sign( + type, + dataType, + clusterId, + packageIds, + context +) { + let result = 0 + let isSigned = false + if (dataType.discriminatorName.toLowerCase() == dbEnum.zclType.bitmap) { + let bitmap = await queryZcl.selectBitmapByNameAndClusterId( + context.global.db, + dataType.name, + clusterId, + packageIds + ) + result = bitmap.size + } else if (dataType.discriminatorName.toLowerCase() == dbEnum.zclType.enum) { + let en = await queryZcl.selectEnumByNameAndClusterId( + context.global.db, + dataType.name, + clusterId, + packageIds + ) + result = en.size + } else if ( + dataType.discriminatorName.toLowerCase() == dbEnum.zclType.number + ) { + let number = await queryZcl.selectNumberByNameAndClusterId( + context.global.db, + dataType.name, + clusterId, + packageIds + ) + isSigned = number.isSigned + result = number.size + } else { + env.logWarning(type + ' is a complex type and size could not be determined') + } + return { size: result, isSigned: isSigned } +} + exports.clusterComparator = clusterComparator exports.attributeComparator = attributeComparator exports.commandComparator = commandComparator @@ -811,3 +862,4 @@ exports.determineType = determineType exports.dataTypeCharacterFormatter = dataTypeCharacterFormatter exports.calculateBytes = calculateBytes exports.createCommandSignature = createCommandSignature +exports.zcl_data_type_size_and_sign = zcl_data_type_size_and_sign diff --git a/test/gen-matter-4.test.js b/test/gen-matter-4.test.js index 093c46177d..b906c580a5 100644 --- a/test/gen-matter-4.test.js +++ b/test/gen-matter-4.test.js @@ -168,3 +168,95 @@ test( }, testUtil.timeout.long() ) + +test( + `Zap testing miscellaneouos type specific helpers: ${path.relative( + __dirname, + testFile + )}`, + async () => { + let sessionId = await querySession.createBlankSession(db) + + await importJs.importDataFromFile(db, testFile, { + sessionId: sessionId, + }) + + let genResult = await genEngine.generate( + db, + sessionId, + templateContext.packageId, + {}, + { disableDeprecationWarnings: true } + ) + expect(genResult.hasErrors).toEqual(false) + + // Note: A lot of these tests here are for sake of backwards + // compatibility. Latest ZAP must be able to generate content for + // the old SDKs, so if you changed something that generates + // endpoint_config differently, please be very very careful and + // make sure you can answer positively the following question: + // will after my changes, zap still be able to generate content + // that will work with an older SDK. + // + let ept = genResult.content['miscellaneous_helper_tests.out'] + + // Testing if_unsupported_attribute_callback helper + expect(ept).toContain( + 'attribute callback for OnOff of boolean type is supported in java' + ) + expect(ept).toContain( + 'attribute callback for GlobalSceneControl of boolean type is supported in java' + ) + expect(ept).toContain( + 'attribute callback for GeneratedCommandList of command_id type is supported in java' + ) + + // Testing if_basic_attribute helper + expect(ept).toContain( + 'attribute OnTime of int16u type is basic type in java' + ) + expect(ept).toContain( + 'attribute EventList of event_id type is not basic type in java' + ) + expect(ept).toContain( + 'attribute StartUpOnOff of OnOffStartUpOnOff type is not basic type in java' + ) + + // Testing as_underlying_java_zcl_type helper + expect(ept).toContain( + 'Underlying Java type for attribute OnOff of boolean type: Boolean' + ) + expect(ept).toContain( + 'Underlying Java type for attribute OnTime of int16u type: Integer' + ) + expect(ept).toContain( + 'Underlying Java type for attribute GeneratedCommandList of command_id type: Long' + ) + + // Testing as_underlying_python_zcl_type helper + expect(ept).toContain( + 'Underlying Python type for attribute OnOff of boolean type: bool' + ) + expect(ept).toContain( + 'Underlying Python type for attribute OnTime of int16u type: int' + ) + expect(ept).toContain( + 'Underlying Python type for attribute GeneratedCommandList of command_id type: int' + ) + + // Testing if_is_data_type_signed and as_zcl_data_type_size + expect(ept).toContain( + 'attribute OnOff of type boolean is unsigned. The size of this attribute is: 8 bits' + ) + expect(ept).toContain( + 'attribute OnTime of type int16u is unsigned. The size of this attribute is: 16 bits' + ) + expect(ept).toContain( + 'attribute StartUpOnOff of type OnOffStartUpOnOff is unsigned. The size of this attribute is: 8 bits' + ) + expect(ept).toContain( + 'attribute GeneratedCommandList of type command_id is unsigned. The size of this attribute is: 32 bits' + ) + }, + testUtil.timeout.long() +) diff --git a/test/gen-template/matter3/miscellaneous_helper_tests.zapt b/test/gen-template/matter3/miscellaneous_helper_tests.zapt new file mode 100644 index 0000000000..452a050384 --- /dev/null +++ b/test/gen-template/matter3/miscellaneous_helper_tests.zapt @@ -0,0 +1,22 @@ +{{#chip_client_clusters }} + {{#zcl_attributes_server removeKeys='isOptional'}} + {{#if_unsupported_attribute_callback type isArray ../id language='java'}} +attribute callback for {{name}} of {{type}} type is not supported in java + {{else}} +attribute callback for {{name}} of {{type}} type is supported in java + {{#if_basic_attribute type ../id language='java'}} + attribute {{name}} of {{type}} type is basic type in java + {{else}} + attribute {{name}} of {{type}} type is not basic type in java + {{/if_basic_attribute}} + {{/if_unsupported_attribute_callback}} +Underlying Java type for attribute {{name}} of {{type}} type: {{as_underlying_java_zcl_type type ../id boolean="Boolean"}} +Underlying Python type for attribute {{name}} of {{type}} type: {{as_underlying_python_zcl_type type ../id boolean="bool" BOOLEAN="bool"}} + {{#if_is_data_type_signed type ../id}} +attribute {{name}} of type {{type}} is signed. The size of this attribute is: {{as_zcl_data_type_size type ../id sizeIn='bits' roundUpToPowerOfTwo=1}} bits + {{else}} +attribute {{name}} of type {{type}} is unsigned. The size of this attribute is: {{as_zcl_data_type_size type ../id sizeIn='bits' roundUpToPowerOfTwo=1}} bits + {{/if_is_data_type_signed}} + + {{/zcl_attributes_server}} +{{/chip_client_clusters}} \ No newline at end of file diff --git a/test/gen-template/matter3/t.json b/test/gen-template/matter3/t.json index 46d0858bd5..2ceb05887b 100644 --- a/test/gen-template/matter3/t.json +++ b/test/gen-template/matter3/t.json @@ -129,6 +129,11 @@ "path": "endpoint_config.zapt", "name": "Endpoint Config", "output": "endpoint_config.h" + }, + { + "path": "miscellaneous_helper_tests.zapt", + "name": "miscellaneous helper", + "output": "miscellaneous_helper_tests.out" } ] } diff --git a/test/test-util.js b/test/test-util.js index 749e353c77..1f8aa54b6f 100644 --- a/test/test-util.js +++ b/test/test-util.js @@ -86,7 +86,7 @@ exports.testTemplate = { matter2: './test/gen-template/matter2/templates.json', matter2Count: 1, matter3: './test/gen-template/matter3/t.json', - matter3Count: 17, + matter3Count: 18, dotdot: './test/gen-template/dotdot/dotdot-templates.json', dotdotCount: 5, unittest: './test/gen-template/test/gen-test.json',