Skip to content

Commit ed628b8

Browse files
authored
Fix generation issues with respect to template category (#1318)
- 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
1 parent 3e6d5d7 commit ed628b8

File tree

3 files changed

+41
-7
lines changed

3 files changed

+41
-7
lines changed

src-electron/db/query-endpoint-type.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,15 @@ WHERE SESSION_PARTITION.SESSION_REF = ? ORDER BY NAME`,
7676
DEVICE_TYPE.CODE,
7777
DEVICE_TYPE.NAME,
7878
DEVICE_TYPE.PROFILE_ID,
79-
ENDPOINT_TYPE_DEVICE.DEVICE_VERSION
79+
ENDPOINT_TYPE_DEVICE.DEVICE_VERSION,
80+
PACKAGE.CATEGORY,
81+
PACKAGE.PACKAGE_ID
8082
FROM
83+
PACKAGE
84+
INNER JOIN
8185
DEVICE_TYPE
86+
ON
87+
DEVICE_TYPE.PACKAGE_REF = PACKAGE.PACKAGE_ID
8288
LEFT JOIN
8389
ENDPOINT_TYPE_DEVICE
8490
ON
@@ -104,6 +110,10 @@ WHERE SESSION_PARTITION.SESSION_REF = ? ORDER BY NAME`,
104110
et.deviceTypeRef = rows.map((x) => x.DEVICE_TYPE_ID)
105111
et.deviceVersion = rows.map((x) => x.DEVICE_VERSION)
106112
et.deviceIdentifier = rows.map((x) => x.CODE)
113+
et.deviceCategory = rows.map((x) => x.CATEGORY)
114+
et.devicePackageRef = rows.map((x) => x.PACKAGE_ID)
115+
et.deviceTypeName = rows && rows.length > 0 ? rows[0].NAME : undefined // Getting the first one for backwards compatibility
116+
et.deviceTypeCode = rows && rows.length > 0 ? rows[0].CODE : undefined // Getting the first one for backwards compatibility
107117
}
108118
return endpointTypes
109119
}

src-electron/generator/helper-session.js

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,18 @@ const queryDeviceType = require('../db/query-device-type.js')
3939
*
4040
* @param {*} options
4141
*/
42-
function user_endpoints(options) {
42+
async function user_endpoints(options) {
43+
let packageInfo = await templateUtil
44+
.ensureTemplatePackageId(this)
45+
.then((packageId) =>
46+
queryPackage.getPackageByPackageId(this.global.db, packageId)
47+
)
48+
let packageInfoCategory = packageInfo.category
4349
let promise = Promise.all([
44-
queryImpexp.exportEndpointTypes(this.global.db, this.global.sessionId),
50+
queryEndpointType.selectAllEndpointTypes(
51+
this.global.db,
52+
this.global.sessionId
53+
),
4554
templateUtil
4655
.ensureEndpointTypeIds(this)
4756
.then((endpointTypes) =>
@@ -61,8 +70,9 @@ function user_endpoints(options) {
6170
endpointTypes.forEach(
6271
(ept) =>
6372
(endpointTypeMap[ept.endpointTypeId] = {
64-
deviceVersions: ept.deviceVersions,
65-
deviceIdentifiers: ept.deviceIdentifiers,
73+
deviceVersions: ept.deviceVersion,
74+
deviceIdentifiers: ept.deviceIdentifier,
75+
deviceCategories: ept.deviceCategory,
6676
})
6777
)
6878
// Adding device Identifiers and versions to endpoints from endpoint types
@@ -71,10 +81,22 @@ function user_endpoints(options) {
7181
endpointTypeMap[ep.endpointTypeRef].deviceIdentifiers
7282
ep.endpointVersion =
7383
endpointTypeMap[ep.endpointTypeRef].deviceVersions
84+
ep.endpointCategories =
85+
endpointTypeMap[ep.endpointTypeRef].deviceCategories
7486
})
7587
resolve(endpoints)
7688
})
7789
)
90+
.then((endpoints) =>
91+
packageInfoCategory
92+
? endpoints.filter(
93+
(ep) =>
94+
ep.endpointCategories.includes(packageInfoCategory) ||
95+
ep.endpointCategories.includes(undefined) ||
96+
ep.endpointCategories.includes(null)
97+
)
98+
: endpoints
99+
)
78100
.then((endpoints) =>
79101
endpoints.map((x) => {
80102
x.endpointTypeId = x.endpointTypeRef
@@ -108,8 +130,8 @@ async function user_device_types(options) {
108130
* @param {*} options
109131
*/
110132
function user_endpoint_types(options) {
111-
let promise = queryImpexp
112-
.exportEndpointTypes(this.global.db, this.global.sessionId)
133+
let promise = queryEndpointType
134+
.selectAllEndpointTypes(this.global.db, this.global.sessionId)
113135
.then((endpointTypes) =>
114136
templateUtil.collectBlocks(endpointTypes, options, this)
115137
)

src-electron/generator/template-util.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,8 @@ async function ensureZclPackageIds(context) {
206206
async function ensureTemplatePackageId(context) {
207207
if ('templatePackageId' in context.global) {
208208
return context.global.templatePackageId
209+
} else if ('genTemplatePackageId' in context.global) {
210+
return context.global.genTemplatePackageId
209211
} else {
210212
let pkgs = await queryPackage.getSessionPackagesByType(
211213
context.global.db,

0 commit comments

Comments
 (0)