8000 Adding attribute-mapping capability in ZAP where 2 attributes can be linked to each other by brdandu · Pull Request #1314 · project-chip/zap · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Adding attribute-mapping capability in ZAP where 2 attributes can be linked to each other #1314

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apack.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "Graphical configuration tool for application and libraries based on Zigbee Cluster Library.",
"path": [".", "node_modules/.bin/", "ZAP.app/Contents/MacOS"],
"requiredFeatureLevel": "apack.core:9",
"featureLevel": 102,
"featureLevel": 103,
"uc.triggerExtension": "zap",
"executable": {
"zap:win32.x86_64": {
Expand Down
4,336 changes: 2,241 additions & 2,095 deletions docs/zap-schema.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
21 changes: 21 additions & 0 deletions src-electron/db/db-mapping.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,27 @@ exports.map = {
}
},

attributeMapping: (x) => {
if (x == null) return undefined
return {
attributeMappingId: x.ATTRIBUTE_MAPPING_ID,
attributeRef1: x.ATTRIBUTE_LEFT_REF,
attributeRef2: x.ATTRIBUTE_RIGHT_REF,
attributeCode1: x.A1_CODE,
attributeMfgCode1: x.A1_MANUFACTURER_CODE,
attributeCode2: x.A2_CODE,
attributeMfgCode2: x.A2_MANUFACTURER_CODE,
attributeName1: x.A1_NAME,
attributeName2: x.A2_NAME,
clusterCode1: x.C1_CODE,
clusterMfgCode1: x.C1_MANUFACTURER_CODE,
clusterCode2: x.C2_CODE,
clusterMfgCode2: x.C2_MANUFACTURER_CODE,
clusterName1: x.C1_NAME,
clusterName2: x.C2_NAME,
}
},

eventField: (x) => {
if (x == null) return undefined
return {
Expand Down
56 changes: 56 additions & 0 deletions src-electron/db/query-attribute.js
Original file line number Diff line number Diff line change
Expand Up @@ -1161,6 +1161,60 @@ AND
return rows.map(dbMapping.map.endpointTypeAttributeExtended)
}

/**
* Get all attributes which are related to each other and belong to certain set of packageIds
* @param {*} db
* @param {*} packageIds
* @returns all attributes which are related to each other and belong to certain set of packageIds
*/
async function selectAttributeMappingsByPackageIds(db, packageIds) {
let rows = await dbApi.dbAll(
db,
`
SELECT
ATTRIBUTE_MAPPING.ATTRIBUTE_MAPPING_ID,
ATTRIBUTE_MAPPING.ATTRIBUTE_LEFT_REF,
ATTRIBUTE_MAPPING.ATTRIBUTE_RIGHT_REF,
A1.CODE AS A1_CODE,
COALESCE(A1.MANUFACTURER_CODE, 0) AS A1_MANUFACTURER_CODE,
A2.CODE AS A2_CODE,
COALESCE(A2.MANUFACTURER_CODE, 0) AS A2_MANUFACTURER_CODE,
A1.NAME AS A1_NAME,
A2.NAME AS A2_NAME,
C1.CODE AS C1_CODE,
COALESCE(C1.MANUFACTURER_CODE, 0) AS C1_MANUFACTURER_CODE,
C1.NAME AS C1_NAME,
C2.CODE AS C2_CODE,
COALESCE(C2.MANUFACTURER_CODE, 0) AS C2_MANUFACTURER_CODE,
C2.NAME AS C2_NAME
FROM
ATTRIBUTE_MAPPING
INNER JOIN
ATTRIBUTE A1
ON
ATTRIBUTE_MAPPING.ATTRIBUTE_LEFT_REF = A1.ATTRIBUTE_ID
INNER JOIN
ATTRIBUTE A2
ON
ATTRIBUTE_MAPPING.ATTRIBUTE_RIGHT_REF = A2.ATTRIBUTE_ID
INNER JOIN
CLUSTER C1
ON
C1.CLUSTER_ID = A1.CLUSTER_REF
INNER JOIN
CLUSTER C2
ON
C2.CLUSTER_ID = A2.CLUSTER_REF
WHERE
A1.PACKAGE_REF IN (${dbApi.toInClause(packageIds)})
OR
A2.PACKAGE_REF IN (${dbApi.toInClause(packageIds)})

`
)
return rows.map(dbMapping.map.attributeMapping)
}

exports.selectAllAttributeDetailsFromEnabledClusters = dbCache.cacheQuery(
selectAllAttributeDetailsFromEnabledClusters
)
Expand All @@ -1185,3 +1239,5 @@ exports.selectEndpointTypeAttributesByEndpointTypeRefAndClusterRef =
selectEndpointTypeAttributesByEndpointTypeRefAndClusterRef
exports.selectTokenAttributesForEndpoint = selectTokenAttributesForEndpoint
exports.selectAllUserTokenAttributes = selectAllUserTokenAttributes
exports.selectAttributeMappingsByPackageIds =
selectAttributeMappingsByPackageIds
44 changes: 44 additions & 0 deletions src-electron/db/query-loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,49 @@ async function insertAttributes(db, packageId, attributes) {
}
}

/**
* Load the attribute mapping table with associated attributes
* @param {*} db
* @param {*} data
* @returns attribute mapping ids of the associated attributes
*/
async function insertAttributeMappings(db, data) {
let selectAttributeIdQuery = `
(SELECT
ATTRIBUTE_ID
FROM
ATTRIBUTE
INNER JOIN
CLUSTER
ON
ATTRIBUTE.CLUSTER_REF = CLUSTER.CLUSTER_ID
WHERE
ATTRIBUTE.CODE = ?
AND
(ATTRIBUTE.MANUFACTURER_CODE = ? OR ATTRIBUTE.MANUFACTURER_CODE IS NULL)
AND
CLUSTER.CODE = ?
AND
(CLUSTER.MANUFACTURER_CODE = ? OR CLUSTER.MANUFACTURER_CODE IS NULL)
AND
ATTRIBUTE.PACKAGE_REF = ?
AND
CLUSTER.PACKAGE_REF = ?)
`

// Using insert or replace to cover the use case for updated attribute mappings in a file
return dbApi.dbMultiInsert(
db,
`
INSERT OR REPLACE INTO
ATTRIBUTE_MAPPING (ATTRIBUTE_LEFT_REF, ATTRIBUTE_RIGHT_REF)
VALUES
(${selectAttributeIdQuery}, ${selectAttributeIdQuery})
`,
data
)
}

async function insertEvents(db, packageId, events) {
let data = events.data
let fieldData = events.fields
Expand Down Expand Up @@ -1932,3 +1975,4 @@ exports.insertBitmapFields = insertBitmapFields
exports.insertStruct = insertStruct
exports.insertStructItems = insertStructItems
exports.updateDataTypeClusterReferences = updateDataTypeClusterReferences
exports.insertAttributeMappings = insertAttributeMappings
1 change: 1 addition & 0 deletions src-electron/db/query-package.js
Original file line number Diff line number Diff line change
Expand Up @@ -1116,3 +1116,4 @@ exports.insertSessionKeyValuesFromPackageDefaults =
insertSessionKeyValuesFromPackageDefaults
exports.getPackagesByCategoryAndType = getPackagesByCategoryAndType
exports.getPackagesByPackageIds = getPackagesByPackageIds
exports.getPackageByPathAndType = getPackageByPathAndType
Loading
0