Skip to content

Commit b3a5eae

Browse files
authored
Cluster Feature Page - Enable feature toggling and sync with device type feature page (#1604)
* cluster feature page phase 2 * add and fix unit tests
1 parent 693a608 commit b3a5eae

28 files changed

+1760
-805
lines changed

docs/api.md

Lines changed: 247 additions & 53 deletions
Large diffs are not rendered by default.

src-electron/db/db-mapping.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -282,14 +282,14 @@ exports.map = {
282282
clusterFeature: (x) => {
283283
if (x == null) return undefined
284284
return {
285-
id: x.FEATURE_ID,
285+
featureId: x.FEATURE_ID,
286286
name: x.NAME,
287287
code: x.CODE,
288288
bit: x.BIT,
289289
description: x.DESCRIPTION,
290290
conformance: x.CONFORMANCE,
291291
packageRef: x.PACKAGE_REF,
292-
clusterId: x.CLUSTER_REF
292+
clusterRef: x.CLUSTER_REF
293293
}
294294
},
295295

@@ -659,7 +659,8 @@ exports.map = {
659659
minInterval: x.MIN_INTERVAL,
660660
maxInterval: x.MAX_INTERVAL,
661661
reportableChange: x.REPORTABLE_CHANGE,
662-
apiMaturity: x.API_MATURITY
662+
apiMaturity: x.API_MATURITY,
663+
id: x.ENDPOINT_TYPE_ATTRIBUTE_ID
663664
}
664665
},
665666

src-electron/db/query-attribute.js

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1276,17 +1276,13 @@ async function selectAttributeMappingsByPackageIds(db, packageIds) {
12761276

12771277
/**
12781278
* Get all attributes in an endpoint type cluster
1279-
* Disabled attributes are not loaded into ENDPOINT_TYPE_ATTRIBUTE table
1280-
* when opening a ZAP file, so we need to join DEVICE_TYPE_CLUSTER table
12811279
* @param {*} db
12821280
* @param {*} endpointTyeClusterId
1283-
* @param {*} deviceTypeClusterId
12841281
* @returns all attributes in an endpoint type cluster
12851282
*/
1286-
async function selectAttributesByEndpointTypeClusterIdAndDeviceTypeClusterId(
1283+
async function selectAttributesByEndpointTypeClusterId(
12871284
db,
1288-
endpointTypeClusterId,
1289-
deviceTypeClusterId
1285+
endpointTypeClusterId
12901286
) {
12911287
let rows = await dbApi.dbAll(
12921288
db,
@@ -1304,19 +1300,19 @@ async function selectAttributesByEndpointTypeClusterIdAndDeviceTypeClusterId(
13041300
FROM
13051301
ATTRIBUTE
13061302
JOIN
1307-
DEVICE_TYPE_CLUSTER
1303+
ENDPOINT_TYPE_CLUSTER
13081304
ON
1309-
ATTRIBUTE.CLUSTER_REF = DEVICE_TYPE_CLUSTER.CLUSTER_REF
1305+
ATTRIBUTE.CLUSTER_REF = ENDPOINT_TYPE_CLUSTER.CLUSTER_REF
1306+
AND
1307+
ENDPOINT_TYPE_CLUSTER.ENDPOINT_TYPE_CLUSTER_ID = ?
13101308
LEFT JOIN
13111309
ENDPOINT_TYPE_ATTRIBUTE
13121310
ON
13131311
ATTRIBUTE.ATTRIBUTE_ID = ENDPOINT_TYPE_ATTRIBUTE.ATTRIBUTE_REF
13141312
AND
1315-
ENDPOINT_TYPE_ATTRIBUTE.ENDPOINT_TYPE_CLUSTER_REF = ?
1316-
WHERE
1317-
DEVICE_TYPE_CLUSTER.DEVICE_TYPE_CLUSTER_ID = ?
1313+
ENDPOINT_TYPE_ATTRIBUTE.ENDPOINT_TYPE_CLUSTER_REF = ENDPOINT_TYPE_CLUSTER.ENDPOINT_TYPE_CLUSTER_ID
13181314
`,
1319-
[endpointTypeClusterId, deviceTypeClusterId]
1315+
[endpointTypeClusterId]
13201316
)
13211317
return rows.map(dbMapping.map.endpointTypeAttributeExtended)
13221318
}
@@ -1347,5 +1343,5 @@ exports.selectTokenAttributesForEndpoint = selectTokenAttributesForEndpoint
13471343
exports.selectAllUserTokenAttributes = selectAllUserTokenAttributes
13481344
exports.selectAttributeMappingsByPackageIds =
13491345
selectAttributeMappingsByPackageIds
1350-
exports.selectAttributesByEndpointTypeClusterIdAndDeviceTypeClusterId =
1351-
selectAttributesByEndpointTypeClusterIdAndDeviceTypeClusterId
1346+
exports.selectAttributesByEndpointTypeClusterId =
1347+
selectAttributesByEndpointTypeClusterId

src-electron/db/query-command.js

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2057,17 +2057,13 @@ async function selectNonManufacturerSpecificCommandDetailsFromAllEndpointTypesAn
20572057

20582058
/**
20592059
* Get all commands in an endpoint type cluster
2060-
* Non-required commands are not loaded into ENDPOINT_TYPE_COMMAND table,
2061-
* so we need to load all commands by joining DEVICE_TYPE_CLUSTER table
20622060
* @param {*} db
20632061
* @param {*} endpointTypeClusterId
2064-
* @param {*} deviceTypeClusterId
20652062
* @returns all commands in an endpoint type cluster
20662063
*/
2067-
async function selectCommandsByEndpointTypeClusterIdAndDeviceTypeClusterId(
2064+
async function selectCommandsByEndpointTypeClusterId(
20682065
db,
2069-
endpointTypeClusterId,
2070-
deviceTypeClusterId
2066+
endpointTypeClusterId
20712067
) {
20722068
let rows = await dbApi.dbAll(
20732069
db,
@@ -2082,19 +2078,19 @@ async function selectCommandsByEndpointTypeClusterIdAndDeviceTypeClusterId(
20822078
FROM
20832079
COMMAND
20842080
JOIN
2085-
DEVICE_TYPE_CLUSTER
2081+
ENDPOINT_TYPE_CLUSTER
20862082
ON
2087-
COMMAND.CLUSTER_REF = DEVICE_TYPE_CLUSTER.CLUSTER_REF
2083+
COMMAND.CLUSTER_REF = ENDPOINT_TYPE_CLUSTER.CLUSTER_REF
2084+
AND
2085+
ENDPOINT_TYPE_CLUSTER.ENDPOINT_TYPE_CLUSTER_ID = ?
20882086
LEFT JOIN
20892087
ENDPOINT_TYPE_COMMAND
20902088
ON
20912089
COMMAND.COMMAND_ID = ENDPOINT_TYPE_COMMAND.COMMAND_REF
20922090
AND
2093-
ENDPOINT_TYPE_COMMAND.ENDPOINT_TYPE_CLUSTER_REF = ?
2094-
WHERE
2095-
DEVICE_TYPE_CLUSTER.DEVICE_TYPE_CLUSTER_ID = ?
2091+
ENDPOINT_TYPE_COMMAND.ENDPOINT_TYPE_CLUSTER_REF = ENDPOINT_TYPE_CLUSTER.ENDPOINT_TYPE_CLUSTER_ID
20962092
`,
2097-
[endpointTypeClusterId, deviceTypeClusterId]
2093+
[endpointTypeClusterId]
20982094
)
20992095
return rows.map(dbMapping.map.endpointTypeCommandExtended)
21002096
}
@@ -2151,5 +2147,5 @@ exports.selectAllOutgoingCommandsForCluster =
21512147
exports.selectEndpointTypeCommandsByEndpointTypeRefAndClusterRef =
21522148
selectEndpointTypeCommandsByEndpointTypeRefAndClusterRef
21532149
exports.duplicateEndpointTypeCommand = duplicateEndpointTypeCommand
2154-
exports.selectCommandsByEndpointTypeClusterIdAndDeviceTypeClusterId =
2155-
selectCommandsByEndpointTypeClusterIdAndDeviceTypeClusterId
2150+
exports.selectCommandsByEndpointTypeClusterId =
2151+
selectCommandsByEndpointTypeClusterId

src-electron/db/query-endpoint-type.js

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -776,31 +776,20 @@ async function selectEndpointTypeClusterFromEndpointIdentifierAndAttributeRef(
776776
* Get all attributes, commands and events in an endpoint type cluster.
777777
* @param {*} db
778778
* @param {*} endpointTypeClusterId
779-
* @param {*} deviceTypeClusterId
780779
* @returns elements object containing all attributes, commands and events
781780
* in an endpoint type cluster
782781
*/
783-
async function getEndpointTypeElements(
784-
db,
785-
endpointTypeClusterId,
786-
deviceTypeClusterId
787-
) {
782+
async function getEndpointTypeElements(db, endpointTypeClusterId) {
788783
let [attributes, commands, events] = await Promise.all([
789-
queryAttribute.selectAttributesByEndpointTypeClusterIdAndDeviceTypeClusterId(
784+
queryAttribute.selectAttributesByEndpointTypeClusterId(
790785
db,
791-
endpointTypeClusterId,
792-
deviceTypeClusterId
786+
endpointTypeClusterId
793787
),
794-
queryCommand.selectCommandsByEndpointTypeClusterIdAndDeviceTypeClusterId(
788+
queryCommand.selectCommandsByEndpointTypeClusterId(
795789
db,
796-
endpointTypeClusterId,
797-
deviceTypeClusterId
790+
endpointTypeClusterId
798791
),
799-
queryEvent.selectEventsByEndpointTypeClusterIdAndDeviceTypeClusterId(
800-
db,
801-
endpointTypeClusterId,
802-
deviceTypeClusterId
803-
)
792+
queryEvent.selectEventsByEndpointTypeClusterId(db, endpointTypeClusterId)
804793
])
805794
return { attributes, commands, events }
806795
}

src-electron/db/query-event.js

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -236,19 +236,12 @@ ORDER BY
236236

237237
/**
238238
* Get all events in an endpoint type cluster
239-
* Disabled events are not loaded into ENDPOINT_TYPE_EVENT table,
240-
* so we need to load all events by joining DEVICE_TYPE_CLUSTER table
241239
*
242240
* @param {*} db
243241
* @param {*} endpointTypeClusterId
244-
* @param {*} deviceTypeClusterId
245242
* @returns all events in an endpoint type cluster
246243
*/
247-
async function selectEventsByEndpointTypeClusterIdAndDeviceTypeClusterId(
248-
db,
249-
endpointTypeClusterId,
250-
deviceTypeClusterId
251-
) {
244+
async function selectEventsByEndpointTypeClusterId(db, endpointTypeClusterId) {
252245
let rows = await dbApi.dbAll(
253246
db,
254247
`
@@ -262,28 +255,28 @@ async function selectEventsByEndpointTypeClusterIdAndDeviceTypeClusterId(
262255
FROM
263256
EVENT
264257
JOIN
265-
DEVICE_TYPE_CLUSTER
258+
ENDPOINT_TYPE_CLUSTER
266259
ON
267-
EVENT.CLUSTER_REF = DEVICE_TYPE_CLUSTER.CLUSTER_REF
260+
EVENT.CLUSTER_REF = ENDPOINT_TYPE_CLUSTER.CLUSTER_REF
261+
AND
262+
ENDPOINT_TYPE_CLUSTER.ENDPOINT_TYPE_CLUSTER_ID = ?
268263
LEFT JOIN
269264
ENDPOINT_TYPE_EVENT
270265
ON
271266
EVENT.EVENT_ID = ENDPOINT_TYPE_EVENT.EVENT_REF
272267
AND
273-
ENDPOINT_TYPE_EVENT.ENDPOINT_TYPE_CLUSTER_REF = ?
274-
WHERE
275-
DEVICE_TYPE_CLUSTER.DEVICE_TYPE_CLUSTER_ID = ?
268+
ENDPOINT_TYPE_EVENT.ENDPOINT_TYPE_CLUSTER_REF = ENDPOINT_TYPE_CLUSTER.ENDPOINT_TYPE_CLUSTER_ID
276269
`,
277-
[endpointTypeClusterId, deviceTypeClusterId]
270+
[endpointTypeClusterId]
278271
)
279272
return rows.map(dbMapping.map.endpointTypeEventExtended)
280273
}
281274

282275
exports.selectEventsByClusterId = selectEventsByClusterId
283276
exports.selectAllEvents = selectAllEvents
284277
exports.selectAllEventFields = selectAllEventFields
285-
exports.selectEventsByEndpointTypeClusterIdAndDeviceTypeClusterId =
286-
selectEventsByEndpointTypeClusterIdAndDeviceTypeClusterId
278+
exports.selectEventsByEndpointTypeClusterId =
279+
selectEventsByEndpointTypeClusterId
287280
exports.selectEventFieldsByEventId = selectEventFieldsByEventId
288281
exports.selectEndpointTypeEventsByEndpointTypeRefAndClusterRef =
289282
selectEndpointTypeEventsByEndpointTypeRefAndClusterRef

src-electron/db/query-session-notification.js

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -197,25 +197,31 @@ async function setWarningIfMessageNotExists(db, sessionId, message) {
197197
}
198198

199199
/**
200-
* Set or delete warning notification after updating a device type feature.
200+
* Set new warnings and delete outdated warnings after updating a feature.
201201
*
202202
* @export
203203
* @param {*} db
204204
* @param {*} sessionId
205205
* @param {*} result
206206
*/
207207
async function setNotificationOnFeatureChange(db, sessionId, result) {
208-
let { warningMessage, disableChange, displayWarning } = result
208+
let {
209+
warningMessage,
210+
disableChange,
211+
displayWarning,
212+
outdatedWarningPatterns
213+
} = result
209214
if (disableChange) {
210215
for (let message of warningMessage) {
211216
await setWarningIfMessageNotExists(db, sessionId, message)
212217
}
213-
return
214-
}
215-
if (displayWarning) {
216-
await setNotification(db, 'WARNING', warningMessage, sessionId, 2, 0)
217218
} else {
218-
await searchNotificationByMessageAndDelete(db, sessionId, warningMessage)
219+
await deleteNotificationWithPatterns(db, sessionId, outdatedWarningPatterns)
220+
if (displayWarning) {
221+
await setNotification(db, 'WARNING', warningMessage, sessionId, 2, 0)
222+
} else {
223+
await searchNotificationByMessageAndDelete(db, sessionId, warningMessage)
224+
}
219225
}
220226
}
221227

src-electron/db/query-zcl.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1124,6 +1124,43 @@ ORDER BY
11241124
return rows.map(dbMapping.map.endpointTypeCluster)
11251125
}
11261126

1127+
/**
1128+
* Get the server-side endpoint type cluster ID from the given endpoint type ID and cluster reference.
1129+
*
1130+
* @param {*} db
1131+
* @param {*} endpointTypeId
1132+
* @param {*} clusterRef
1133+
* @param {*} clusterSide
1134+
* @returns Promise of endpoint type cluster ID, or null if not found.
1135+
*/
1136+
async function selectEndpointTypeClusterIdByEndpointTypeIdAndClusterRefAndSide(
1137+
db,
1138+
endpointTypeId,
1139+
clusterRef,
1140+
clusterSide
1141+
) {
1142+
let rows = await dbApi.dbAll(
1143+
db,
1144+
`
1145+
SELECT
1146+
ENDPOINT_TYPE_CLUSTER_ID,
1147+
ENDPOINT_TYPE_REF,
1148+
CLUSTER_REF,
1149+
SIDE,
1150+
ENABLED
1151+
FROM
1152+
ENDPOINT_TYPE_CLUSTER
1153+
WHERE
1154+
ENDPOINT_TYPE_REF = ?
1155+
AND CLUSTER_REF = ?
1156+
AND SIDE = ?
1157+
`,
1158+
[endpointTypeId, clusterRef, clusterSide]
1159+
)
1160+
let mapped = rows.map(dbMapping.map.endpointTypeCluster)
1161+
return mapped.length > 0 ? mapped[0].endpointTypeClusterId : null
1162+
}
1163+
11271164
/**
11281165
* Get the endpoint type attribute details from the given endpoint type ID.
11291166
*
@@ -1182,6 +1219,7 @@ SELECT
11821219
ETC.ENDPOINT_TYPE_REF,
11831220
ETC.CLUSTER_REF,
11841221
ETA.ATTRIBUTE_REF,
1222+
ETA.ENDPOINT_TYPE_ATTRIBUTE_ID,
11851223
ETA.INCLUDED,
11861224
ETA.STORAGE_OPTION,
11871225
ETA.SINGLETON,
@@ -1313,6 +1351,8 @@ exports.selectAllAttributesBySide = selectAllAttributesBySide
13131351

13141352
exports.selectEndpointTypeClustersByEndpointTypeId =
13151353
selectEndpointTypeClustersByEndpointTypeId
1354+
exports.selectEndpointTypeClusterIdByEndpointTypeIdAndClusterRefAndSide =
1355+
selectEndpointTypeClusterIdByEndpointTypeIdAndClusterRefAndSide
13161356
exports.selectEndpointTypeAttributesByEndpointId =
13171357
selectEndpointTypeAttributesByEndpointId
13181358
exports.selectEndpointTypeAttribute = selectEndpointTypeAttribute

0 commit comments

Comments
 (0)