Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix fails in gen-zigbee unit tests #1368

Merged
merged 1 commit into from
Jul 25, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
241 changes: 117 additions & 124 deletions src-electron/util/util.js
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be good to break this long function into smaller pieces but that can be done on a later date so do not worry about it now.

Original file line number Diff line number Diff line change
Expand Up @@ -213,143 +213,136 @@ async function ensurePackagesAndPopulateSessionOptions(
sessionPartitionIndex++
}
} else {
let genTemplateJsonPromise = queryPackage
.getPackagesByType(db, dbEnum.packageType.genTemplatesJson)
.then((rows) => {
let packageId
if (
selectedGenTemplatePackages &&
selectedGenTemplatePackages.length > 0
) {
selectedGenTemplatePackages.forEach((gen) => {
if (gen) {
packageId = gen
} else if (rows.length == 1) {
packageId = rows[0].id
env.logDebug(
`Single generation template metafile found, using it for the session: ${packageId}`
)
} else if (rows.length == 0) {
env.logInfo(
`No generation template metafile found for session.`
)
packageId = null
} else {
rows.forEach((p) => {
if (
selectedGenTemplatePackages != null &&
path.resolve(selectedGenTemplatePackages) === p.path
) {
packageId = p.id
}
})
if (packageId != null) {
env.logWarning(
`Multiple toplevel generation template metafiles found. Using the one from args: ${packageId}`
)
queryNotification.setNotification(
db,
'WARNING',
`Multiple toplevel generation template metafiles found. Using the one from args: ${packageId}`,
sessionId,
2,
0
)
} else {
packageId = rows[0].id
env.logWarning(
`Multiple toplevel generation template metafiles found. Using the first one.`
)
queryNotification.setNotification(
db,
'WARNING',
`Multiple toplevel generation template metafiles found. Using the first one.`,
sessionId,
2,
0
)
}
}
if (packageId != null) {
if (sessionPartitionInfo.length == 0) {
sessionPartitionIndex++
return querySession
.insertSessionPartition(
db,
sessionId,
sessionPartitionIndex
)
.then((sessionPartitionId) =>
queryPackage.insertSessionPackage(
db,
sessionPartitionId,
packageId,
true
)
)
} else {
sessionPartitionIndex++
return querySession
.getAllSessionPartitionInfoForSession(db, sessionId)
.then((sessionPartitionInfo) =>
queryPackage.insertSessionPackage(
db,
sessionPartitionInfo[sessionPartitionIndex - 1]
.sessionPartitionId,
packageId,
true
)
)
}
let rows = await queryPackage.getPackagesByType(
db,
dbEnum.packageType.genTemplatesJson
)
let packageId
if (
selectedGenTemplatePackages &&
selectedGenTemplatePackages.length > 0
) {
for (const gen of selectedGenTemplatePackages) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor stuff const genPkgId gives more readability but not a big deal.

if (gen) {
packageId = gen
} else if (rows.length == 1) {
packageId = rows[0].id
env.logDebug(
`Single generation template metafile found, using it for the session: ${packageId}`
)
} else if (rows.length == 0) {
env.logDebug(`No generation template metafile found for session.`)
packageId = null
} else {
rows.forEach((p) => {
if (
selectedGenTemplatePackages != null &&
path.resolve(selectedGenTemplatePackages) === p.path
) {
packageId = p.id
}
})
}
if (packageId == null && rows.length > 0) {
// If package id is not resolved and there are gen-template packages available,
// find one with matching category. if nothing is found, blindly pick the first one available

let packageId
if (
selectedZclPropertyPackage &&
selectedZclPropertyPackage.length > 0
) {
const matchBySelectedCategory = rows.find(
(r) => r?.category === selectedZclPropertyPackage[0].category
if (packageId != null) {
env.logWarning(
`Multiple toplevel generation template metafiles found. Using the one from args: ${packageId}`
)
queryNotification.setNotification(
db,
'WARNING',
`Multiple toplevel generation template metafiles found. Using the one from args: ${packageId}`,
sessionId,
2,
0
)
packageId = matchBySelectedCategory?.id || rows[0].id
} else {
packageId = rows[0].id
env.logWarning(
`Multiple toplevel generation template metafiles found. Using the first one.`
)
queryNotification.setNotification(
db,
'WARNING',
`Multiple toplevel generation template metafiles found. Using the first one.`,
sessionId,
2,
0
)
}

if (sessionPartitionInfo.length == 0) {
}
if (packageId != null) {
if (sessionPartitionInfo.length === 0) {
sessionPartitionIndex++
return querySession
.insertSessionPartition(db, sessionId, sessionPartitionIndex)
.then((sessionPartitionId) =>
queryPackage.insertSessionPackage(
db,
sessionPartitionId,
packageId,
true
)
const sessionPartitionId =
await querySession.insertSessionPartition(
db,
sessionId,
sessionPartitionIndex
)
await queryPackage.insertSessionPackage(
db,
sessionPartitionId,
packageId,
true
)
} else {
sessionPartitionIndex++
return querySession
.getAllSessionPartitionInfoForSession(db, sessionId)
.then((sessionPartitionInfo) =>
queryPackage.insertSessionPackage(
db,
sessionPartitionInfo[sessionPartitionIndex - 1]
.sessionPartitionId,
packageId,
true
)
const sessionPartitionInfo =
await querySession.getAllSessionPartitionInfoForSession(
db,
sessionId
)
await queryPackage.insertSessionPackage(
db,
sessionPartitionInfo[sessionPartitionIndex - 1]
.sessionPartitionId,
packageId,
true
)
}
}
})
promises.push(genTemplateJsonPromise)
}
}
if (packageId == null && rows.length > 0) {
// If package id is not resolved and there are gen-template packages available,
// find one with matching category. if nothing is found, blindly pick the first one available

let packageId
if (
selectedZclPropertyPackage &&
selectedZclPropertyPackage.length > 0
) {
const matchBySelectedCategory = rows.find(
(r) => r?.category === selectedZclPropertyPackage[0].category
)
packageId = matchBySelectedCategory?.id || rows[0].id
} else {
packageId = rows[0].id
}

if (sessionPartitionInfo.length == 0) {
sessionPartitionIndex++
const sessionPartitionId = await querySession.insertSessionPartition(
db,
sessionId,
sessionPartitionIndex
)
await queryPackage.insertSessionPackage(
db,
sessionPartitionId,
packageId,
true
)
} else {
sessionPartitionIndex++
await querySession.getAllSessionPartitionInfoForSession(db, sessionId)
await queryPackage.insertSessionPackage(
db,
sessionPartitionInfo[sessionPartitionIndex - 1].sessionPartitionId,
packageId,
true
)
}
}
}
}

Expand Down
Loading