Skip to content

Commit

Permalink
allowing for an array of packageIds to be passed
Browse files Browse the repository at this point in the history
  • Loading branch information
paulr34 committed Aug 13, 2024
1 parent 47d8c1d commit 155d7b9
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 15 deletions.
5 changes: 1 addition & 4 deletions src-electron/db/query-impexp.js
Original file line number Diff line number Diff line change
Expand Up @@ -737,10 +737,7 @@ WHERE
attribute.reportable = false
}
if (attributeId) {
forcedExternal = await queryUpgrade.getForcedExternalStorage(
db,
packageIds[0]
)
forcedExternal = await queryUpgrade.getForcedExternalStorage(db, packageIds)
storagePolicy = await queryUpgrade.computeStorageImport(
db,
cluster.name,
Expand Down
22 changes: 18 additions & 4 deletions src-electron/db/query-package.js
Original file line number Diff line number Diff line change
Expand Up @@ -703,8 +703,21 @@ async function getAllPackages(db) {
* @param {number} packageId - The ID of the package to which the options are related.
* @returns {Promise<Array>} A promise that resolves to an array of option objects, each containing the option category, code, and label.
*/
async function getAttributeAccessInterface(db, code, packageId) {
async function getAttributeAccessInterface(db, code, packageIds) {
try {
let packageRefCondition = `po.PACKAGE_REF = ?`
let attributePackageRefCondition = `a.PACKAGE_REF = ?`
let queryParams = [code, packageIds, code, packageIds]

// Check if packageIds is an array and adjust the query and parameters accordingly
if (Array.isArray(packageIds)) {
const placeholders = packageIds.map(() => '?').join(', ')
packageRefCondition = `po.PACKAGE_REF IN (${placeholders})`
attributePackageRefCondition = `a.PACKAGE_REF IN (${placeholders})`
// Adjust queryParams for the IN clause
queryParams = [code, ...packageIds, code, ...packageIds]
}

const extendedQuery = `
SELECT
po.OPTION_CATEGORY,
Expand All @@ -714,7 +727,7 @@ async function getAttributeAccessInterface(db, code, packageId) {
PACKAGE_OPTION po
WHERE
po.OPTION_CODE = ?
AND po.PACKAGE_REF = ?
AND ${packageRefCondition}
UNION
Expand All @@ -727,10 +740,11 @@ async function getAttributeAccessInterface(db, code, packageId) {
LEFT JOIN CLUSTER c ON a.CLUSTER_REF = c.CLUSTER_ID
WHERE
a.STORAGE_POLICY = ?
AND a.PACKAGE_REF = ?
AND ${attributePackageRefCondition}
`

return dbApi
.dbAll(db, extendedQuery, [code, packageId, code, packageId]) // Note the [code, packageId, code, packageId] to match both placeholders
.dbAll(db, extendedQuery, queryParams)
.then((rows) => rows.map(dbMapping.map.options))
} catch (error) {
console.error('Error fetching attribute access interface:', error)
Expand Down
6 changes: 3 additions & 3 deletions src-electron/generator/helper-zcl.js
Original file line number Diff line number Diff line change
Expand Up @@ -772,7 +772,7 @@ async function zcl_attributes(options) {
this.global.db,
this.id,
attributes,
packageIds[0]
packageIds
)
} else {
attributes = await queryZcl.selectAllAttributes(this.global.db, packageIds)
Expand Down Expand Up @@ -807,7 +807,7 @@ async function zcl_attributes_client(options) {
this.global.db,
this.id,
clientAttributes,
packageIds[0]
packageIds
)
} else {
clientAttributes = await queryZcl.selectAllAttributesBySide(
Expand Down Expand Up @@ -849,7 +849,7 @@ async function zcl_attributes_server(options) {
this.global.db,
this.id,
serverAttributes,
packageIds[0]
packageIds
)
} else {
serverAttributes = await queryZcl.selectAllAttributesBySide(
Expand Down
8 changes: 4 additions & 4 deletions src-electron/sdk/matter.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ const dbEnum = require('../../src-shared/db-enum.js')
* @returns {Promise<Array>} A promise that resolves to an array of forced external storage settings.
*/

async function getForcedExternalStorage(db, packageId) {
async function getForcedExternalStorage(db, packageIds) {
try {
let forcedExternal = await queryPackage.getAttributeAccessInterface(
db,
dbEnum.storagePolicy.attributeAccessInterface,
packageId
packageIds
)
return forcedExternal
} catch (error) {
Expand Down Expand Up @@ -65,15 +65,15 @@ async function computeStoragePolicyForGlobalAttributes(
db,
clusterId,
attributes,
packageId
packageIds
) {
try {
let forcedExternal
let clusterName = await queryCluster.selectClusterName(db, clusterId)
return Promise.all(
attributes.map(async (attribute) => {
if (attribute.clusterId == null) {
forcedExternal = await getForcedExternalStorage(db, packageId)
forcedExternal = await getForcedExternalStorage(db, packageIds)
forcedExternal.some((option) => {
if (
option.optionCategory == clusterName &&
Expand Down

0 comments on commit 155d7b9

Please sign in to comment.