Skip to content

Commit

Permalink
Adding to all_user_cluster_attributes_irrespective_of_manufacturing_s…
Browse files Browse the repository at this point in the history
…pecification 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.
- all_user_cluster_attributes_irrespective_of_manufacturing_specification is solving this issue correctly and actually only showing attributes which are truly enabled.
- Github: ZAP#898
  • Loading branch information
brdandu committed Jan 19, 2023
1 parent 7bcd9ee commit e6e8677
Show file tree
Hide file tree
Showing 3 changed files with 116 additions and 21 deletions.
112 changes: 96 additions & 16 deletions src-electron/db/query-attribute.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
*/
const dbApi = require('./db-api.js')
const dbMapping = require('./db-mapping.js')
const bin = require('../util/bin')

function attributeExportMapping(x) {
return {
Expand All @@ -32,9 +33,35 @@ function attributeExportMapping(x) {
type: x.TYPE,
define: x.DEFINE,
mfgCode: x.MANUFACTURER_CODE,
manufacturerCode: x.MANUFACTURER_CODE,
hexCode: '0x' + bin.int16ToHex(x['CODE']),
clusterSide: x.SIDE,
clusterName: x.CLUSTER_NAME,
isClusterEnabled: x.ENABLED,
isArray: x.IS_ARRAY,
isWritable: dbApi.fromDbBool(x.IS_WRITABLE),
isWritableAttribute: dbApi.fromDbBool(x.IS_WRITABLE),
isReportableAttribute: dbApi.fromDbBool(x.INCLUDED_REPORTABLE),
includedReportable: dbApi.fromDbBool(x.INCLUDED_REPORTABLE),
isNullable: dbApi.fromDbBool(x.IS_NULLABLE),
maxLength: x.MAX_LENGTH,
minLength: x.MIN_LENGTH,
arrayType: x.ARRAY_TYPE,
entryType: x.ARRAY_TYPE,
min: x.MIN,
max: x.MAX,
mustUseTimedWrite: dbApi.fromDbBool(x.MUST_USE_TIMED_WRITE),
isSceneRequired: dbApi.fromDbBool(x.IS_SCENE_REQUIRED),
isOptionalAttribute: dbApi.fromDbBool(x.IS_OPTIONAL),
storage: x.STORAGE_OPTION,
isSingleton: dbApi.fromDbBool(x.SINGLETON),
isBound: dbApi.fromDbBool(x.BOUNDED),
isIncluded: dbApi.fromDbBool(x.INCLUDED),
defaultValue: x.DEFAULT_VALUE,
minInterval: x.MIN_INTERVAL,
maxInterval: x.MAX_INTERVAL,
reportableChange: x.REPORTABLE_CHANGE,
isGlobalAttribute: x.IS_GLOBAL_ATTRIBUTE,
}
}

Expand All @@ -47,11 +74,11 @@ function attributeExportMapping(x) {
* @param {*} endpointTypeClusterRef
* @returns Records of selected Endpoint Type Attributes.
*/
async function selectEndpointTypeAttributesByEndpointTypeRefAndClusterRef(
async function selectEndpointTypeAttributesByEndpointTypeRefAndClusterRef(
db,
endpointTypeRef,
endpointTypeClusterRef
){
) {
let rows = await dbApi.dbAll(
db,
`
Expand All @@ -73,7 +100,7 @@ function attributeExportMapping(x) {
ENDPOINT_TYPE_ATTRIBUTE
where
ENDPOINT_TYPE_REF = ? and ENDPOINT_TYPE_CLUSTER_REF = ?`,
[endpointTypeRef,endpointTypeClusterRef]
[endpointTypeRef, endpointTypeClusterRef]
)
return rows.map(dbMapping.map.endpointTypeAttribute)
}
Expand All @@ -93,7 +120,7 @@ async function duplicateEndpointTypeAttribute(
newEndpointTypeRef,
newEndpointTypeClusterRef,
attribute
){
) {
return await dbApi.dbInsert(
db,
`INSERT INTO ENDPOINT_TYPE_ATTRIBUTE (
Expand Down Expand Up @@ -123,7 +150,8 @@ async function duplicateEndpointTypeAttribute(
?,
?
)`,
[ newEndpointTypeRef,
[
newEndpointTypeRef,
newEndpointTypeClusterRef,
attribute.attributeRef,
attribute.included,
Expand All @@ -134,24 +162,30 @@ async function duplicateEndpointTypeAttribute(
attribute.includedReportable,
attribute.minInterval,
attribute.maxInterval,
attribute.reportableChange ]
attribute.reportableChange,
]
)
}


/**
* Returns a promise of data for attributes inside an endpoint type.
*
* @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()
Expand All @@ -164,23 +198,68 @@ 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))
Expand Down Expand Up @@ -902,4 +981,5 @@ exports.selectReportableAttributeDetailsFromEnabledClustersAndEndpoints =
exports.selectGlobalAttributeDefaults = selectGlobalAttributeDefaults
exports.selectAttributeByCode = selectAttributeByCode
exports.duplicateEndpointTypeAttribute = duplicateEndpointTypeAttribute
exports.selectEndpointTypeAttributesByEndpointTypeRefAndClusterRef = selectEndpointTypeAttributesByEndpointTypeRefAndClusterRef
exports.selectEndpointTypeAttributesByEndpointTypeRefAndClusterRef =
selectEndpointTypeAttributesByEndpointTypeRefAndClusterRef
19 changes: 15 additions & 4 deletions src-electron/generator/helper-session.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down Expand Up @@ -612,9 +613,12 @@ 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 and non-manufaturing specific 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.
*
* @param name
* @param side
* @param options
* @returns Promise of the resolved blocks iterating over manufacturing specific
* and non-manufacturing specific cluster attributes.
Expand Down Expand Up @@ -1525,8 +1529,15 @@ exports.all_user_cluster_manufacturer_specific_attributes =
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 =
exports.all_user_cluster_attributes_irrespective_of_manufacturing_specification =
all_user_cluster_attributes_irrespective_of_manufatucuring_specification
exports.all_user_cluster_attributes_irrespective_of_manufatucuring_specification =
dep(
all_user_cluster_attributes_irrespective_of_manufatucuring_specification,
{
to: 'all_user_cluster_attributes_irrespective_of_manufacturing_specification',
}
)
exports.all_user_cluster_attributes_for_generated_defaults =
all_user_cluster_attributes_for_generated_defaults
exports.all_user_cluster_generated_attributes =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -745,6 +745,8 @@ async function chip_access_elements(options) {
return templateUtil.templatePromise(this.global, p);
}

const dep = templateUtil.deprecatedHelper;

//
// Module exports
//
Expand All @@ -762,7 +764,9 @@ 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, {
to: 'all_user_cluster_attributes_irrespective_of_manufacturing_specification',
});
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 =
Expand Down

0 comments on commit e6e8677

Please sign in to comment.