Skip to content

Commit 0cc6562

Browse files
authored
Changing user_endpoints back to non async since that is breaking the 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
1 parent 22785f1 commit 0cc6562

File tree

3 files changed

+79
-58
lines changed

3 files changed

+79
-58
lines changed

src-electron/generator/helper-session.js

Lines changed: 61 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -39,71 +39,75 @@ const queryDeviceType = require('../db/query-device-type.js')
3939
*
4040
* @param {*} options
4141
*/
42-
async function user_endpoints(options) {
43-
let packageInfo = await templateUtil
42+
function user_endpoints(options) {
43+
let promise = templateUtil
4444
.ensureTemplatePackageId(this)
4545
.then((packageId) =>
4646
queryPackage.getPackageByPackageId(this.global.db, packageId)
4747
)
48-
let packageInfoCategory = packageInfo.category
49-
let promise = Promise.all([
50-
queryEndpointType.selectAllEndpointTypes(
51-
this.global.db,
52-
this.global.sessionId
53-
),
54-
templateUtil
55-
.ensureEndpointTypeIds(this)
56-
.then((endpointTypes) =>
57-
queryImpexp.exportEndpoints(
48+
.then((packageInfo) => packageInfo.category)
49+
.then((packageInfoCategory) =>
50+
Promise.all([
51+
queryEndpointType.selectAllEndpointTypes(
5852
this.global.db,
59-
this.global.sessionId,
60-
endpointTypes
61-
)
62-
),
63-
])
64-
.then(
65-
(EptEp) =>
66-
new Promise((resolve, reject) => {
67-
let endpointTypeMap = {}
68-
let endpointTypes = EptEp[0]
69-
let endpoints = EptEp[1]
70-
endpointTypes.forEach(
71-
(ept) =>
72-
(endpointTypeMap[ept.endpointTypeId] = {
73-
deviceVersions: ept.deviceVersion,
74-
deviceIdentifiers: ept.deviceIdentifier,
75-
deviceCategories: ept.deviceCategory,
53+
this.global.sessionId
54+
),
55+
templateUtil
56+
.ensureEndpointTypeIds(this)
57+
.then((endpointTypes) =>
58+
queryImpexp.exportEndpoints(
59+
this.global.db,
60+
this.global.sessionId,
61+
endpointTypes
62+
)
63+
),
64+
])
65+
.then(
66+
(EptEp) =>
67+
new Promise((resolve, reject) => {
68+
let endpointTypeMap = {}
69+
let endpointTypes = EptEp[0]
70+
let endpoints = EptEp[1]
71+
endpointTypes.forEach(
72+
(ept) =>
73+
(endpointTypeMap[ept.endpointTypeId] = {
74+
deviceVersions: ept.deviceVersion,
75+
deviceIdentifiers: ept.deviceIdentifier,
76+
deviceCategories: ept.deviceCategory,
77+
})
78+
)
79+
// Adding device Identifiers and versions to endpoints from endpoint types
80+
endpoints.forEach((ep) => {
81+
ep.deviceIdentifier =
82+
endpointTypeMap[ep.endpointTypeRef].deviceIdentifiers
83+
ep.endpointVersion =
84+
endpointTypeMap[ep.endpointTypeRef].deviceVersions
85+
ep.endpointCategories =
86+
endpointTypeMap[ep.endpointTypeRef].deviceCategories
7687
})
77-
)
78-
// Adding device Identifiers and versions to endpoints from endpoint types
79-
endpoints.forEach((ep) => {
80-
ep.deviceIdentifier =
81-
endpointTypeMap[ep.endpointTypeRef].deviceIdentifiers
82-
ep.endpointVersion =
83-
endpointTypeMap[ep.endpointTypeRef].deviceVersions
84-
ep.endpointCategories =
85-
endpointTypeMap[ep.endpointTypeRef].deviceCategories
88+
resolve(endpoints)
89+
})
90+
)
91+
.then((endpoints) =>
92+
packageInfoCategory
93+
? endpoints.filter(
94+
(ep) =>
95+
ep.endpointCategories.includes(packageInfoCategory) ||
96+
ep.endpointCategories.includes(undefined) ||
97+
ep.endpointCategories.includes(null)
98+
)
99+
: endpoints
100+
)
101+
.then((endpoints) =>
102+
endpoints.map((x) => {
103+
x.endpointTypeId = x.endpointTypeRef
104+
return x
86105
})
87-
resolve(endpoints)
88-
})
89-
)
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-
)
100-
.then((endpoints) =>
101-
endpoints.map((x) => {
102-
x.endpointTypeId = x.endpointTypeRef
103-
return x
104-
})
106+
)
107+
.then((endpoints) =>
108+
templateUtil.collectBlocks(endpoints, options, this)
109+
)
105110
)
106-
.then((endpoints) => templateUtil.collectBlocks(endpoints, options, this))
107111

108112
return templateUtil.templatePromise(this.global, promise)
109113
}

test/gen-template/zigbee/zap-event.h.zapt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,3 +74,14 @@
7474
{{/user_clusters}}
7575
{{/user_endpoints}}
7676

77+
{{#user_endpoints}}
78+
{{~addToAccumulator "event_size" 1~}}
79+
{{/user_endpoints}}
80+
81+
82+
{{#after}}
83+
{{#iterateAccumulator accumulator="event_size"}}
84+
#define SL_ZIGBEE_AF_GENERATED_UC_EVENT_CONTEXT_COUNT {{sum}}
85+
{{/iterateAccumulator}}
86+
{{/after}}
87+

test/multi-protocol.test.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ test(
9797
importRes.templateIds[0],
9898
{},
9999
{
100-
generateOnly: 'zap-config-version-3.h',
100+
generateOnly: ['zap-config-version-3.h', 'zap-event.h'],
101101
disableDeprecationWarnings: true,
102102
}
103103
)
@@ -199,6 +199,12 @@ test(
199199
// Just one notification regarding multiple top level zcl propertoes and 4
200200
// notifications regarding feature map attribute not set correctly
201201
expect(sessionNotifications.length).toEqual(5)
202+
203+
// Test Accumulators in templates
204+
let zigbeeEndpointEvents = genResultZigbee.content['zap-event.h']
205+
expect(zigbeeEndpointEvents).toContain(
206+
'#define SL_ZIGBEE_AF_GENERATED_UC_EVENT_CONTEXT_COUNT 1'
207+
)
202208
},
203209
testUtil.timeout.long()
204210
)

0 commit comments

Comments
 (0)