Skip to content

Commit

Permalink
Changing user_endpoints back to non async since that is breaking the …
Browse files Browse the repository at this point in the history
…backwards compatibility with after and iteratorAccumulator (#1321)

- After helper waits for the promises to finish. However turning the user_endpoints to async led to accumulator not populate before the iteratorAccumulator tried to access it.
- Turned user-endpoints helper back to no asnyc
- Added test so that this is covered when we actually fix this issue with accumulators
- JIRA: ZAPP-1376
  • Loading branch information
brdandu committed May 8, 2024
1 parent 22785f1 commit 0cc6562
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 58 deletions.
118 changes: 61 additions & 57 deletions src-electron/generator/helper-session.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,71 +39,75 @@ const queryDeviceType = require('../db/query-device-type.js')
*
* @param {*} options
*/
async function user_endpoints(options) {
let packageInfo = await templateUtil
function user_endpoints(options) {
let promise = templateUtil
.ensureTemplatePackageId(this)
.then((packageId) =>
queryPackage.getPackageByPackageId(this.global.db, packageId)
)
let packageInfoCategory = packageInfo.category
let promise = Promise.all([
queryEndpointType.selectAllEndpointTypes(
this.global.db,
this.global.sessionId
),
templateUtil
.ensureEndpointTypeIds(this)
.then((endpointTypes) =>
queryImpexp.exportEndpoints(
.then((packageInfo) => packageInfo.category)
.then((packageInfoCategory) =>
Promise.all([
queryEndpointType.selectAllEndpointTypes(
this.global.db,
this.global.sessionId,
endpointTypes
)
),
])
.then(
(EptEp) =>
new Promise((resolve, reject) => {
let endpointTypeMap = {}
let endpointTypes = EptEp[0]
let endpoints = EptEp[1]
endpointTypes.forEach(
(ept) =>
(endpointTypeMap[ept.endpointTypeId] = {
deviceVersions: ept.deviceVersion,
deviceIdentifiers: ept.deviceIdentifier,
deviceCategories: ept.deviceCategory,
this.global.sessionId
),
templateUtil
.ensureEndpointTypeIds(this)
.then((endpointTypes) =>
queryImpexp.exportEndpoints(
this.global.db,
this.global.sessionId,
endpointTypes
)
),
])
.then(
(EptEp) =>
new Promise((resolve, reject) => {
let endpointTypeMap = {}
let endpointTypes = EptEp[0]
let endpoints = EptEp[1]
endpointTypes.forEach(
(ept) =>
(endpointTypeMap[ept.endpointTypeId] = {
deviceVersions: ept.deviceVersion,
deviceIdentifiers: ept.deviceIdentifier,
deviceCategories: ept.deviceCategory,
})
)
// Adding device Identifiers and versions to endpoints from endpoint types
endpoints.forEach((ep) => {
ep.deviceIdentifier =
endpointTypeMap[ep.endpointTypeRef].deviceIdentifiers
ep.endpointVersion =
endpointTypeMap[ep.endpointTypeRef].deviceVersions
ep.endpointCategories =
endpointTypeMap[ep.endpointTypeRef].deviceCategories
})
)
// Adding device Identifiers and versions to endpoints from endpoint types
endpoints.forEach((ep) => {
ep.deviceIdentifier =
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
return x
})
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
return x
})
)
.then((endpoints) =>
templateUtil.collectBlocks(endpoints, options, this)
)
)
.then((endpoints) => templateUtil.collectBlocks(endpoints, options, this))

return templateUtil.templatePromise(this.global, promise)
}
Expand Down
11 changes: 11 additions & 0 deletions test/gen-template/zigbee/zap-event.h.zapt
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,14 @@
{{/user_clusters}}
{{/user_endpoints}}

{{#user_endpoints}}
{{~addToAccumulator "event_size" 1~}}
{{/user_endpoints}}


{{#after}}
{{#iterateAccumulator accumulator="event_size"}}
#define SL_ZIGBEE_AF_GENERATED_UC_EVENT_CONTEXT_COUNT {{sum}}
{{/iterateAccumulator}}
{{/after}}

8 changes: 7 additions & 1 deletion test/multi-protocol.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ test(
importRes.templateIds[0],
{},
{
generateOnly: 'zap-config-version-3.h',
generateOnly: ['zap-config-version-3.h', 'zap-event.h'],
disableDeprecationWarnings: true,
}
)
Expand Down Expand Up @@ -199,6 +199,12 @@ test(
// Just one notification regarding multiple top level zcl propertoes and 4
// notifications regarding feature map attribute not set correctly
expect(sessionNotifications.length).toEqual(5)

// Test Accumulators in templates
let zigbeeEndpointEvents = genResultZigbee.content['zap-event.h']
expect(zigbeeEndpointEvents).toContain(
'#define SL_ZIGBEE_AF_GENERATED_UC_EVENT_CONTEXT_COUNT 1'
)
},
testUtil.timeout.long()
)

0 comments on commit 0cc6562

Please sign in to comment.