Skip to content

Commit

Permalink
- Cleaning up the custom xml UI update as well as the custom xml pack…
Browse files Browse the repository at this point in the history
…age uploading such that there are no duplicates

- Fixing the custom xml UI for attributes, commands and events when cluster extensions are added through custom xml. Needed the custom xml package ids to be included
- JIRA: ZAPP-1351
  • Loading branch information
brdandu committed Apr 3, 2024
1 parent 5cc7614 commit e41829c
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 13 deletions.
26 changes: 23 additions & 3 deletions src-electron/db/query-package.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,19 +174,38 @@ async function getPackagesByParentAndType(db, parentId, type) {
}

/**
* Checks if the package with a given path exists and executes appropriate action.
* Returns the promise that resolves the the package or null if nothing was found.
* Checks if the package with a given package id exists and executes appropriate action.
* Returns the promise that resolves the package or null if nothing was found.
*
* @export
* @param {*} db
* @param {*} path Path of a file to check.
* @param {*} packageId
*/
async function getPackageByPackageId(db, packageId) {
return dbApi
.dbGet(db, `${querySelectFromPackage} WHERE PACKAGE_ID = ?`, [packageId])
.then(dbMapping.map.package)
}

/**
* Checks if packages with given package ids exist and executes appropriate action.
* Returns the promise that resolves the packages or null if nothing was found.
*
* @export
* @param {*} db
* @param {*} packageIds
*/
async function getPackagesByPackageIds(db, packageIds) {
return dbApi
.dbAll(
db,
`${querySelectFromPackage} WHERE PACKAGE_ID IN (${dbApi.toInClause(
packageIds
)})`
)
.then((rows) => rows.map(dbMapping.map.package))
}

/**
* Returns a package ref from the attribute ID
*
Expand Down Expand Up @@ -1096,3 +1115,4 @@ exports.selectAllUiOptions = selectAllUiOptions
exports.insertSessionKeyValuesFromPackageDefaults =
insertSessionKeyValuesFromPackageDefaults
exports.getPackagesByCategoryAndType = getPackagesByCategoryAndType
exports.getPackagesByPackageIds = getPackagesByPackageIds
31 changes: 22 additions & 9 deletions src-electron/importexport/import-json.js
Original file line number Diff line number Diff line change
Expand Up @@ -1561,17 +1561,30 @@ async function jsonDataLoader(

// packageData: { sessionId, packageId, otherIds, optionalIds}
let optionalPackagePromises = []
if (standAlonePackageData.optionalIds.length > 0) {
standAlonePackageData.optionalIds.forEach((optionalId) => {
optionalPackagePromises.push(
queryPackage.insertSessionPackage(
if (
standAlonePackageData.optionalIds &&
standAlonePackageData.optionalIds.length > 0
) {
let optionalIds = standAlonePackageData.optionalIds
for (let i = 0; i < optionalIds.length; i++) {
let sessionPartitionInfoForNewPackage =
await querySession.selectSessionPartitionInfoFromPackageId(
db,
sessionPartitionInfo[sessionPartitionIndex].sessionPartitionId,
optionalId
sessionId,
optionalIds[i]
)
)
sessionPartitionIndex++
})
// Loading only those packages which have not been loaded
if (sessionPartitionInfoForNewPackage.length == 0) {
optionalPackagePromises.push(
queryPackage.insertSessionPackage(
db,
sessionPartitionInfo[sessionPartitionIndex].sessionPartitionId,
optionalIds[i]
)
)
sessionPartitionIndex++
}
}
}
await Promise.all(optionalPackagePromises)

Expand Down
12 changes: 11 additions & 1 deletion src-electron/rest/static-zcl.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,16 @@ function reduceAndConcatenateZclEntity(
}

async function parseForZclData(db, entity, id, packageIdArray) {
// Retrieve all the standalone custom xml packages
let packageData = await queryPackage.getPackagesByPackageIds(
db,
packageIdArray
)
let standalonePackages = packageData.filter(
(pd) => pd.type === dbEnum.packageType.zclXmlStandalone
)
let standAlonePackageIds = standalonePackages.map((sp) => sp.id)

switch (entity) {
case 'atomics':
return reduceAndConcatenateZclEntity(
Expand Down Expand Up @@ -140,7 +150,7 @@ async function parseForZclData(db, entity, id, packageIdArray) {
: reduceAndConcatenateZclEntity(
db,
id,
[clusterInfo.packageRef],
[...standAlonePackageIds, clusterInfo.packageRef], // Taking cluster package and custom xml into account
returnZclEntitiesForClusterId,
mergeZclClusterAttributeCommandEventData,
{
Expand Down
13 changes: 13 additions & 0 deletions src/store/zap/mutations.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,19 @@ export function updateClusters(state, responseData) {
let selectedDeviceTypeRefs =
state.endpointTypeView.deviceTypeRef[selectedEndpointTypeTemp]
let packageRefs = []
// Add custom xml packages to the list of packageRefs
let sessionPackages = state.packages
if (sessionPackages && sessionPackages.length > 0) {
for (let i = 0; i < sessionPackages.length; i++) {
if (
sessionPackages[i].pkg &&
sessionPackages[i].pkg.type == 'zcl-xml-standalone'
) {
packageRefs.push(sessionPackages[i].pkg.id)
}
}
}

if (selectedDeviceTypeRefs) {
for (let i = 0; i < selectedDeviceTypeRefs.length; i++) {
for (let j = 0; j < responseData.deviceTypes.data.length; j++) {
Expand Down

0 comments on commit e41829c

Please sign in to comment.