Skip to content

Commit

Permalink
Fix generation issues with respect to template category (#1318)
Browse files Browse the repository at this point in the history
- Add more device type information in selectAllEndpointTypes query such as category and package id
- Update user_endpoints query to consider categories such that templates are only generated for their corresponding queries
- Update helpers to use selectAllEndpointTypes instead of exportEndpointTypes to only include endpoints based on the correct category. If category is not specified then generate for everything.
- Fix ensureTemplatePackageId to also check for this.global.genTemplatePackageId
  • Loading branch information
brdandu committed May 6, 2024
1 parent 3e6d5d7 commit ed628b8
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 7 deletions.
12 changes: 11 additions & 1 deletion src-electron/db/query-endpoint-type.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,15 @@ WHERE SESSION_PARTITION.SESSION_REF = ? ORDER BY NAME`,
DEVICE_TYPE.CODE,
DEVICE_TYPE.NAME,
DEVICE_TYPE.PROFILE_ID,
ENDPOINT_TYPE_DEVICE.DEVICE_VERSION
ENDPOINT_TYPE_DEVICE.DEVICE_VERSION,
PACKAGE.CATEGORY,
PACKAGE.PACKAGE_ID
FROM
PACKAGE
INNER JOIN
DEVICE_TYPE
ON
DEVICE_TYPE.PACKAGE_REF = PACKAGE.PACKAGE_ID
LEFT JOIN
ENDPOINT_TYPE_DEVICE
ON
Expand All @@ -104,6 +110,10 @@ WHERE SESSION_PARTITION.SESSION_REF = ? ORDER BY NAME`,
et.deviceTypeRef = rows.map((x) => x.DEVICE_TYPE_ID)
et.deviceVersion = rows.map((x) => x.DEVICE_VERSION)
et.deviceIdentifier = rows.map((x) => x.CODE)
et.deviceCategory = rows.map((x) => x.CATEGORY)
et.devicePackageRef = rows.map((x) => x.PACKAGE_ID)
et.deviceTypeName = rows && rows.length > 0 ? rows[0].NAME : undefined // Getting the first one for backwards compatibility
et.deviceTypeCode = rows && rows.length > 0 ? rows[0].CODE : undefined // Getting the first one for backwards compatibility
}
return endpointTypes
}
Expand Down
34 changes: 28 additions & 6 deletions src-electron/generator/helper-session.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,18 @@ const queryDeviceType = require('../db/query-device-type.js')
*
* @param {*} options
*/
function user_endpoints(options) {
async function user_endpoints(options) {
let packageInfo = await templateUtil
.ensureTemplatePackageId(this)
.then((packageId) =>
queryPackage.getPackageByPackageId(this.global.db, packageId)
)
let packageInfoCategory = packageInfo.category
let promise = Promise.all([
queryImpexp.exportEndpointTypes(this.global.db, this.global.sessionId),
queryEndpointType.selectAllEndpointTypes(
this.global.db,
this.global.sessionId
),
templateUtil
.ensureEndpointTypeIds(this)
.then((endpointTypes) =>
Expand All @@ -61,8 +70,9 @@ function user_endpoints(options) {
endpointTypes.forEach(
(ept) =>
(endpointTypeMap[ept.endpointTypeId] = {
deviceVersions: ept.deviceVersions,
deviceIdentifiers: ept.deviceIdentifiers,
deviceVersions: ept.deviceVersion,
deviceIdentifiers: ept.deviceIdentifier,
deviceCategories: ept.deviceCategory,
})
)
// Adding device Identifiers and versions to endpoints from endpoint types
Expand All @@ -71,10 +81,22 @@ function user_endpoints(options) {
endpointTypeMap[ep.endpointTypeRef].deviceIdentifiers
ep.endpointVersion =
endpointTypeMap[ep.endpointTypeRef].deviceVersions
ep.endpointCategories =
endpointTypeMap[ep.endpointTypeRef].deviceCategories
})
resolve(endpoints)
})
)
.then((endpoints) =>
packageInfoCategory
? endpoints.filter(
(ep) =>
ep.endpointCategories.includes(packageInfoCategory) ||
ep.endpointCategories.includes(undefined) ||
ep.endpointCategories.includes(null)
)
: endpoints
)
.then((endpoints) =>
endpoints.map((x) => {
x.endpointTypeId = x.endpointTypeRef
Expand Down Expand Up @@ -108,8 +130,8 @@ async function user_device_types(options) {
* @param {*} options
*/
function user_endpoint_types(options) {
let promise = queryImpexp
.exportEndpointTypes(this.global.db, this.global.sessionId)
let promise = queryEndpointType
.selectAllEndpointTypes(this.global.db, this.global.sessionId)
.then((endpointTypes) =>
templateUtil.collectBlocks(endpointTypes, options, this)
)
Expand Down
2 changes: 2 additions & 0 deletions src-electron/generator/template-util.js
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,8 @@ async function ensureZclPackageIds(context) {
async function ensureTemplatePackageId(context) {
if ('templatePackageId' in context.global) {
return context.global.templatePackageId
} else if ('genTemplatePackageId' in context.global) {
return context.global.genTemplatePackageId
} else {
let pkgs = await queryPackage.getSessionPackagesByType(
context.global.db,
Expand Down

0 comments on commit ed628b8

Please sign in to comment.