Skip to content

Commit 1d2fe6c

Browse files
authored
load attribute when open zap file (#1492)
1 parent 460bbd0 commit 1d2fe6c

File tree

5 files changed

+28
-16
lines changed

5 files changed

+28
-16
lines changed

src-electron/db/query-attribute.js

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1250,13 +1250,17 @@ async function selectAttributeMappingsByPackageIds(db, packageIds) {
12501250

12511251
/**
12521252
* Get all attributes in an endpoint type cluster
1253+
* Disabled attributes are not loaded into ENDPOINT_TYPE_ATTRIBUTE table
1254+
* when opening a ZAP file, so we need to join DEVICE_TYPE_CLUSTER table
12531255
* @param {*} db
12541256
* @param {*} endpointTyeClusterId
1257+
* @param {*} deviceTypeClusterId
12551258
* @returns all attributes in an endpoint type cluster
12561259
*/
1257-
async function selectAttributesByEndpointTypeClusterId(
1260+
async function selectAttributesByEndpointTypeClusterIdAndDeviceTypeClusterId(
12581261
db,
1259-
endpointTyeClusterId
1262+
endpointTypeClusterId,
1263+
deviceTypeClusterId
12601264
) {
12611265
let rows = await dbApi.dbAll(
12621266
db,
@@ -1274,13 +1278,19 @@ async function selectAttributesByEndpointTypeClusterId(
12741278
FROM
12751279
ATTRIBUTE
12761280
JOIN
1281+
DEVICE_TYPE_CLUSTER
1282+
ON
1283+
ATTRIBUTE.CLUSTER_REF = DEVICE_TYPE_CLUSTER.CLUSTER_REF
1284+
LEFT JOIN
12771285
ENDPOINT_TYPE_ATTRIBUTE
12781286
ON
1279-
ATTRIBUTE.ATTRIBUTE_ID = ENDPOINT_TYPE_ATTRIBUTE.ATTRIBUTE_REF
1287+
ATTRIBUTE.ATTRIBUTE_ID = ENDPOINT_TYPE_ATTRIBUTE.ATTRIBUTE_REF
1288+
AND
1289+
ENDPOINT_TYPE_ATTRIBUTE.ENDPOINT_TYPE_CLUSTER_REF = ?
12801290
WHERE
1281-
ENDPOINT_TYPE_ATTRIBUTE.ENDPOINT_TYPE_CLUSTER_REF = ?
1291+
DEVICE_TYPE_CLUSTER.DEVICE_TYPE_CLUSTER_ID = ?
12821292
`,
1283-
[endpointTyeClusterId]
1293+
[endpointTypeClusterId, deviceTypeClusterId]
12841294
)
12851295
return rows.map(dbMapping.map.endpointTypeAttributeExtended)
12861296
}
@@ -1311,5 +1321,5 @@ exports.selectTokenAttributesForEndpoint = selectTokenAttributesForEndpoint
13111321
exports.selectAllUserTokenAttributes = selectAllUserTokenAttributes
13121322
exports.selectAttributeMappingsByPackageIds =
13131323
selectAttributeMappingsByPackageIds
1314-
exports.selectAttributesByEndpointTypeClusterId =
1315-
selectAttributesByEndpointTypeClusterId
1324+
exports.selectAttributesByEndpointTypeClusterIdAndDeviceTypeClusterId =
1325+
selectAttributesByEndpointTypeClusterIdAndDeviceTypeClusterId

src-electron/db/query-command.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2051,7 +2051,7 @@ async function selectNonManufacturerSpecificCommandDetailsFromAllEndpointTypesAn
20512051
/**
20522052
* Get all commands in an endpoint type cluster
20532053
* Non-required commands are not loaded into ENDPOINT_TYPE_COMMAND table,
2054-
* so we need to load all commands by joining DEVICE_TYPE_COMMAND table
2054+
* so we need to load all commands by joining DEVICE_TYPE_CLUSTER table
20552055
* @param {*} db
20562056
* @param {*} endpointTypeClusterId
20572057
* @param {*} deviceTypeClusterId

src-electron/db/query-event.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ ORDER BY
236236
/**
237237
* Get all events in an endpoint type cluster
238238
* Disabled events are not loaded into ENDPOINT_TYPE_EVENT table,
239-
* so we need to load all events by joining DEVICE_TYPE_EVENT table
239+
* so we need to load all events by joining DEVICE_TYPE_CLUSTER table
240240
*
241241
* @param {*} db
242242
* @param {*} endpointTypeClusterId

src-electron/rest/user-data.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,10 @@ async function getEndpointTypeElements(
112112
deviceTypeClusterId
113113
) {
114114
let [attributes, commands, events] = await Promise.all([
115-
queryAttribute.selectAttributesByEndpointTypeClusterId(
115+
queryAttribute.selectAttributesByEndpointTypeClusterIdAndDeviceTypeClusterId(
116116
db,
117-
endpointTypeClusterId
117+
endpointTypeClusterId,
118+
deviceTypeClusterId
118119
),
119120
queryCommand.selectCommandsByEndpointTypeClusterIdAndDeviceTypeClusterId(
120121
db,

test/query.test.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -623,10 +623,10 @@ describe('Endpoint Type Config Queries', () => {
623623
let expectedNumbers = {
624624
Identify: {
625625
server: { attributes: 2, commands: 6 },
626-
client: { attributes: 1, commands: 6 }
626+
client: { attributes: 2, commands: 6 }
627627
},
628-
Basic: { server: { attributes: 3, commands: 1 } },
629-
'On/off': { client: { attributes: 1, commands: 11 } }
628+
Basic: { server: { attributes: 18, commands: 1 } },
629+
'On/off': { client: { attributes: 9, commands: 11 } }
630630
}
631631
let deviceTypeClusters =
632632
await queryDeviceType.selectDeviceTypeClustersByDeviceTypeRef(
@@ -646,9 +646,10 @@ describe('Endpoint Type Config Queries', () => {
646646
if (deviceTypeCluster) {
647647
let deviceTypeClusterId = deviceTypeCluster.id
648648
queryAttribute
649-
.selectAttributesByEndpointTypeClusterId(
649+
.selectAttributesByEndpointTypeClusterIdAndDeviceTypeClusterId(
650650
db,
651-
endpointTypeClusterId
651+
endpointTypeClusterId,
652+
deviceTypeClusterId
652653
)
653654
.then((attributes) => {
654655
expect(attributes.length).toBe(

0 commit comments

Comments
 (0)