Skip to content

Conversation

brdandu
Copy link
Collaborator

@brdandu brdandu commented Oct 14, 2025

Using slc args json file when opening .zap files and changing the zcl and templates meta data to use what is in the slc agrs json file during the file open operation

JIRA: ZAPP-1656

… and templates meta data to use what is in the slc agrs json file during the file open operation

JIRA: ZAPP-1656
Copy link

Summary of Changes

Hello @brdandu, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request introduces a mechanism to improve Matter generation time within Simplicity Studio by optimizing how ZCL and template metadata are loaded. When opening a .zap file, the system now checks for an accompanying slc_args.json file. If present, this file's contents are used to specify the exact paths for ZCL properties and generation templates, allowing for more efficient and targeted loading of necessary data, thereby streamlining the overall process.

Highlights

  • slc_args.json Integration: The system now reads and utilizes an slc_args.json file located alongside a .zap file to determine ZCL and template metadata paths during file opening.
  • Dynamic Package Loading: A new helper function, ensurePackageLoaded, has been introduced to conditionally load ZCL properties and generation templates into the database, preventing redundant loading.
  • Matter and Zigbee Metadata Configuration: The .zap file opening process is enhanced to specifically load Matter and Zigbee ZCL properties and templates based on paths provided in the slc_args.json file, if available.
  • Standardized slcArgs Keys: A new slcArgs enum has been added to db-enum.js to provide standardized keys for accessing properties within the slc_args.json file.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces an optimization for loading ZCL and template metadata by using a slc_args.json file, which should improve generation time. The overall approach is sound. My review includes several suggestions to enhance performance, maintainability, and consistency with the existing codebase. These include using asynchronous file operations, refactoring duplicated code, using the project's standard logger, and optimizing database queries after package loading.

await zclLoader.loadZcl(db, packagePath)
} else if (packageType === dbEnum.packageType.genTemplatesJson) {
// Load template package using generation engine
const genEngine = require('../generator/generation-engine.js')

Choose a reason for hiding this comment

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

medium

For better performance and code organization, require statements should be at the top of the file. This allows modules to be loaded once when the module is first required, and it makes dependencies clearer.

Comment on lines +55 to +69
if (packageType === dbEnum.packageType.zclProperties) {
// Load ZCL properties package
await zclLoader.loadZcl(db, packagePath)
} else if (packageType === dbEnum.packageType.genTemplatesJson) {
// Load template package using generation engine
const genEngine = require('../generator/generation-engine.js')
await genEngine.loadTemplates(db, [packagePath])
}

// Re-query after loading
existingPackage = await queryPackage.getPackageByPathAndType(
db,
packagePath,
packageType
)

Choose a reason for hiding this comment

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

medium

After loading a package, the code re-queries the database using the package path and type. This is inefficient. The loadZcl and loadTemplates functions return a context object containing the packageId of the newly loaded package. You can use this ID to fetch the package directly with queryPackage.getPackageByPackageId, which is more efficient.

Suggested change
if (packageType === dbEnum.packageType.zclProperties) {
// Load ZCL properties package
await zclLoader.loadZcl(db, packagePath)
} else if (packageType === dbEnum.packageType.genTemplatesJson) {
// Load template package using generation engine
const genEngine = require('../generator/generation-engine.js')
await genEngine.loadTemplates(db, [packagePath])
}
// Re-query after loading
existingPackage = await queryPackage.getPackageByPathAndType(
db,
packagePath,
packageType
)
if (packageType === dbEnum.packageType.zclProperties) {
// Load ZCL properties package
const { packageId } = await zclLoader.loadZcl(db, packagePath)
existingPackage = await queryPackage.getPackageByPackageId(db, packageId)
} else if (packageType === dbEnum.packageType.genTemplatesJson) {
// Load template package using generation engine
const genEngine = require('../generator/generation-engine.js')
const { packageIds } = await genEngine.loadTemplates(db, [packagePath])
if (packageIds && packageIds.length > 0) {
existingPackage = await queryPackage.getPackageByPackageId(
db,
packageIds[0]
)
}
}


return existingPackage
} catch (error) {
console.warn(`Failed to load package ${packagePath}: ${error.message}`)

Choose a reason for hiding this comment

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

medium

The project uses a pino logger accessed via env.log* functions for structured and consistent logging. Instead of console.warn, please use env.logWarning. This also applies to console.log on line 53. You will need to import the env module at the top of the file.

Suggested change
console.warn(`Failed to load package ${packagePath}: ${error.message}`)
env.logWarning(`Failed to load package ${packagePath}`, error)

Comment on lines +95 to +102
try {
if (fs.existsSync(slcArgsFile)) {
const slcArgsData = await fsp.readFile(slcArgsFile, 'utf8')
slcArgs = JSON.parse(slcArgsData)
}
} catch (error) {
console.warn(`Failed to read slc_args.json: ${error.message}`)
}

Choose a reason for hiding this comment

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

medium

The use of fs.existsSync is synchronous and can block the event loop, which should be avoided in an async function. A better approach is to attempt reading the file with fsp.readFile and handle the ENOENT (file not found) error specifically if it occurs. This keeps the operation fully asynchronous.

Suggested change
try {
if (fs.existsSync(slcArgsFile)) {
const slcArgsData = await fsp.readFile(slcArgsFile, 'utf8')
slcArgs = JSON.parse(slcArgsData)
}
} catch (error) {
console.warn(`Failed to read slc_args.json: ${error.message}`)
}
try {
const slcArgsData = await fsp.readFile(slcArgsFile, 'utf8')
slcArgs = JSON.parse(slcArgsData)
} catch (error) {
if (error.code !== 'ENOENT') {
console.warn(`Failed to read or parse slc_args.json: ${error.message}`)
}
}

Comment on lines +119 to +161
if (category.includes(`'${dbEnum.helperCategory.zigbee}'`)) {
// Load Zigbee ZCL properties if specified
let zclPackage = await ensurePackageLoaded(
db,
slcArgs[dbEnum.slcArgs.zigbeeZclJsonFile],
dbEnum.packageType.zclProperties
)
if (zclPackage) {
zclProperties.push(zclPackage)
}

// Load Zigbee templates if specified
let templatePackage = await ensurePackageLoaded(
db,
slcArgs[dbEnum.slcArgs.zigbeeTemplateJsonFile],
dbEnum.packageType.genTemplatesJson
)
if (templatePackage) {
zclGenTemplates.push(templatePackage)
}
}

if (category.includes(`'${dbEnum.helperCategory.matter}'`)) {
// Load Matter ZCL properties if specified
let zclPackage = await ensurePackageLoaded(
db,
slcArgs[dbEnum.slcArgs.matterZclJsonFile],
dbEnum.packageType.zclProperties
)
if (zclPackage) {
zclProperties.push(zclPackage)
}

// Load Matter templates if specified
let templatePackage = await ensurePackageLoaded(
db,
slcArgs[dbEnum.slcArgs.matterTemplateJsonFile],
dbEnum.packageType.genTemplatesJson
)
if (templatePackage) {
zclGenTemplates.push(templatePackage)
}
}

Choose a reason for hiding this comment

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

medium

The logic for loading packages for Zigbee (lines 119-139) and Matter (lines 141-161) is nearly identical. This duplication can be avoided by extracting the logic into a helper function.

For example, you could create a function like loadPackagesForCategory(db, slcArgs, category, zclProperties, zclGenTemplates) that takes the category ('zigbee' or 'matter') and populates the zclProperties and zclGenTemplates arrays.

This would make the code more concise and easier to maintain.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant