Skip to content

Commit

Permalink
load attribute when open zap file
Browse files Browse the repository at this point in the history
  • Loading branch information
ethanzhouyc committed Dec 6, 2024
1 parent 4bc1bdb commit 1b71a78
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 14 deletions.
24 changes: 17 additions & 7 deletions src-electron/db/query-attribute.js
Original file line number Diff line number Diff line change
Expand Up @@ -1250,13 +1250,17 @@ async function selectAttributeMappingsByPackageIds(db, packageIds) {

/**
* Get all attributes in an endpoint type cluster
* Disabled attributes are not loaded into ENDPOINT_TYPE_ATTRIBUTE table
* when opening a ZAP file, so we need to join DEVICE_TYPE_ATTRIBUTE table
* @param {*} db
* @param {*} endpointTyeClusterId
* @param {*} deviceTypeClusterId
* @returns all attributes in an endpoint type cluster
*/
async function selectAttributesByEndpointTypeClusterId(
async function selectAttributesByEndpointTypeClusterIdAndDeviceTypeClusterId(
db,
endpointTyeClusterId
endpointTypeClusterId,
deviceTypeClusterId
) {
let rows = await dbApi.dbAll(
db,
Expand All @@ -1274,13 +1278,19 @@ async function selectAttributesByEndpointTypeClusterId(
FROM
ATTRIBUTE
JOIN
DEVICE_TYPE_CLUSTER
ON
ATTRIBUTE.CLUSTER_REF = DEVICE_TYPE_CLUSTER.CLUSTER_REF
LEFT JOIN
ENDPOINT_TYPE_ATTRIBUTE
ON
ATTRIBUTE.ATTRIBUTE_ID = ENDPOINT_TYPE_ATTRIBUTE.ATTRIBUTE_REF
ATTRIBUTE.ATTRIBUTE_ID = ENDPOINT_TYPE_ATTRIBUTE.ATTRIBUTE_REF
AND
ENDPOINT_TYPE_ATTRIBUTE.ENDPOINT_TYPE_CLUSTER_REF = ?
WHERE
ENDPOINT_TYPE_ATTRIBUTE.ENDPOINT_TYPE_CLUSTER_REF = ?
DEVICE_TYPE_CLUSTER.DEVICE_TYPE_CLUSTER_ID = ?
`,
[endpointTyeClusterId]
[endpointTypeClusterId, deviceTypeClusterId]
)
return rows.map(dbMapping.map.endpointTypeAttributeExtended)
}
Expand Down Expand Up @@ -1311,5 +1321,5 @@ exports.selectTokenAttributesForEndpoint = selectTokenAttributesForEndpoint
exports.selectAllUserTokenAttributes = selectAllUserTokenAttributes
exports.selectAttributeMappingsByPackageIds =
selectAttributeMappingsByPackageIds
exports.selectAttributesByEndpointTypeClusterId =
selectAttributesByEndpointTypeClusterId
exports.selectAttributesByEndpointTypeClusterIdAndDeviceTypeClusterId =
selectAttributesByEndpointTypeClusterIdAndDeviceTypeClusterId
5 changes: 3 additions & 2 deletions src-electron/rest/user-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,10 @@ async function getEndpointTypeElements(
deviceTypeClusterId
) {
let [attributes, commands, events] = await Promise.all([
queryAttribute.selectAttributesByEndpointTypeClusterId(
queryAttribute.selectAttributesByEndpointTypeClusterIdAndDeviceTypeClusterId(
db,
endpointTypeClusterId
endpointTypeClusterId,
deviceTypeClusterId
),
queryCommand.selectCommandsByEndpointTypeClusterIdAndDeviceTypeClusterId(
db,
Expand Down
11 changes: 6 additions & 5 deletions test/query.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -623,10 +623,10 @@ describe('Endpoint Type Config Queries', () => {
let expectedNumbers = {
Identify: {
server: { attributes: 2, commands: 6 },
client: { attributes: 1, commands: 6 }
client: { attributes: 2, commands: 6 }
},
Basic: { server: { attributes: 3, commands: 1 } },
'On/off': { client: { attributes: 1, commands: 11 } }
Basic: { server: { attributes: 18, commands: 1 } },
'On/off': { client: { attributes: 9, commands: 11 } }
}
let deviceTypeClusters =
await queryDeviceType.selectDeviceTypeClustersByDeviceTypeRef(
Expand All @@ -646,9 +646,10 @@ describe('Endpoint Type Config Queries', () => {
if (deviceTypeCluster) {
let deviceTypeClusterId = deviceTypeCluster.id
queryAttribute
.selectAttributesByEndpointTypeClusterId(
.selectAttributesByEndpointTypeClusterIdAndDeviceTypeClusterId(
db,
endpointTypeClusterId
endpointTypeClusterId,
deviceTypeClusterId
)
.then((attributes) => {
expect(attributes.length).toBe(
Expand Down

0 comments on commit 1b71a78

Please sign in to comment.