Skip to content

Commit

Permalink
Show standard clusters when custom device types are added from custom…
Browse files Browse the repository at this point in the history
… xml (#1359)

- Adding standalone packages without considering package category
- Making sure that invalid session Packages are handled properly
- Making sure that sessionPartitionIndex is updated when pacakges are not loaded in the db. Also making sure they are not look into for invalidSessionPkgs since they are already verified for existence
- Adding tests to make sure custom device types are being loaded from custom xml
- JIRA: ZAPP-1450
  • Loading branch information
brdandu authored Jul 22, 2024
1 parent 2b0e752 commit 8af71bf
Show file tree
Hide file tree
Showing 6 changed files with 99 additions and 10 deletions.
13 changes: 11 additions & 2 deletions src-electron/generator/template-util.js
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,12 @@ async function ensureEndpointTypeIds(context) {
deviceType.packageRef
)
// Check for package category match based on gen template category and add it to relevant endpoint types
if (packageInfo.category == packageCategory || !packageCategory) {
if (
packageInfo.category == packageCategory ||
!packageCategory ||
(!packageInfo.category &&
packageInfo.type === dbEnum.packageType.zclXmlStandalone)
) {
resEptIds.push(eptIds[i])
break
}
Expand Down Expand Up @@ -327,7 +332,11 @@ async function ensureEndpointTypeIds(context) {
context.global.db,
deviceType.packageRef
)
if (packageInfo.category == packageCategory) {
if (
packageInfo.category == packageCategory ||
(!packageInfo.category &&
packageInfo.type === dbEnum.packageType.zclXmlStandalone)
) {
resEptIds.push(eptIds[i])
break
}
Expand Down
20 changes: 13 additions & 7 deletions src-electron/importexport/import-json.js
Original file line number Diff line number Diff line change
Expand Up @@ -1718,6 +1718,8 @@ async function jsonDataLoader(
.filter((p) => p.succeeded)
.map((p) => p.packageId)

sessionPartitionIndex += newlyLoadedCustomPackageIds.length

let standAlonePackageData = await importPackages(
db,
zclXmlStandAlonePackages,
Expand Down Expand Up @@ -1795,7 +1797,9 @@ async function jsonDataLoader(
pkg.type
)
let invalidSessionPkgs = sessionPkgs.filter(
(x) => x.path !== pkgFilePath
(x) =>
x.path !== pkgFilePath &&
!newlyLoadedCustomPackageIds.includes(x.id) // newly added packages are already verified.
)
let validSessionPkgId =
await queryPackage.getPackageIdByPathAndTypeAndVersion(
Expand All @@ -1816,12 +1820,14 @@ async function jsonDataLoader(
env.logDebug(
`Disabling/removing invalid session package. sessionId(${sessionId}), packageId(${invalidSessionPkgs[i].id}), path(${invalidSessionPkgs[i].path})`
)
await queryPackage.deleteSessionPackage(
db,
sessionPartitionInfoCurrent[0].sessionPartitionId,
invalidSessionPkgs[i].id
)
sessionPartitionIndex--
if (sessionPartitionInfoCurrent.length > 0) {
await queryPackage.deleteSessionPackage(
db,
sessionPartitionInfoCurrent[0].sessionPartitionId,
invalidSessionPkgs[i].id
)
sessionPartitionIndex--
}
}

env.logDebug(
Expand Down
17 changes: 16 additions & 1 deletion src/store/zap/mutations.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export function updateClusters(state, responseData) {
let packageRefs = []
// Add custom xml packages to the list of packageRefs
let sessionPackages = state.packages
let customXmlPackagesCount = 0
if (sessionPackages && sessionPackages.length > 0) {
for (let i = 0; i < sessionPackages.length; i++) {
if (
Expand All @@ -57,15 +58,29 @@ export function updateClusters(state, responseData) {
}
}
}
customXmlPackagesCount = packageRefs.length

if (selectedDeviceTypeRefs) {
for (let i = 0; i < selectedDeviceTypeRefs.length; i++) {
for (let j = 0; j < responseData.deviceTypes.data.length; j++) {
if (selectedDeviceTypeRefs[i] == responseData.deviceTypes.data[j].id) {
if (
selectedDeviceTypeRefs[i] == responseData.deviceTypes.data[j].id &&
!packageRefs.includes(responseData.deviceTypes.data[j].packageRef)
) {
packageRefs.push(responseData.deviceTypes.data[j].packageRef)
}
}
}
// Check if all package refs are standalone(Handles the custom device type use case from xml)
if (customXmlPackagesCount === packageRefs.length) {
// if all packages are custom then add the first standard zcl package to the list of package refs.
for (let i = 0; i < sessionPackages.length; i++) {
if (sessionPackages[i].pkg.type == 'zcl-properties') {
packageRefs.push(sessionPackages[i].pkg.id)
break
}
}
}
} else {
// When endpoint types do not have an associated device type(undefined)
if (responseData.clusterData) {
Expand Down
30 changes: 30 additions & 0 deletions test/gen-zigbee-7.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const genEngine = require('../src-electron/generator/generation-engine')
const env = require('../src-electron/util/env')
const dbApi = require('../src-electron/db/db-api')
const queryPackage = require('../src-electron/db/query-package')
const queryDeviceType = require('../src-electron/db/query-device-type')
const zclLoader = require('../src-electron/zcl/zcl-loader')
const importJs = require('../src-electron/importexport/import')
const testUtil = require('./test-util')
Expand Down Expand Up @@ -119,6 +120,35 @@ test(
expect(pv4).toContain(
'result = emberAfMfglibClusterClusterServerCommandParse(cmd);'
)

// Load a custom xml with device types
result = await zclLoader.loadIndividualFile(
db,
testUtil.testCustomXmlDeviceType,
sessionId
)
if (!result.succeeded) {
console.log(result)
}
expect(result.succeeded).toBeTruthy()

// Check if device type is loaded into the database
let customDeviceType = await queryDeviceType.selectDeviceTypeByCodeAndName(
db,
result.packageId,
0x0002,
'DUT-Server'
)
expect(customDeviceType).not.toBeNull()
expect(customDeviceType.name).toBe('DUT-Server')

// Check device type clusters for device type
let deviceTypeClusters =
await queryDeviceType.selectDeviceTypeClustersByDeviceTypeRef(
db,
customDeviceType.id
)
expect(deviceTypeClusters.length).toBe(2) // 2 device type clusters associated with this device type.
},
testUtil.timeout.long()
)
27 changes: 27 additions & 0 deletions test/resource/custom-cluster/custom-device-type.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0"?>
<configurator>
<deviceType>
<name>DUT-Client</name>
<domain>CUSTOM_DUT</domain>
<typeName>D.U.T. Client</typeName>
<zigbeeType>Coordinator</zigbeeType>
<profileId editable="false">0xC001</profileId>
<deviceId editable="false">0x0001</deviceId>
<clusters lockOthers="true">
<include client="true" server="false" clientLocked="true" serverLocked="true" >Test Cluster</include>
<include cluster="Basic" client="true" server="false" clientLocked="true" serverLocked="true"></include>
</clusters>
</deviceType>
<deviceType>
<name>DUT-Server</name>
<domain>CUSTOM_DUT</domain>
<typeName>D.U.T. Server</typeName>
<zigbeeType>End Device</zigbeeType>
<profileId editable="false">0xC001</profileId>
<deviceId editable="false">0x0002</deviceId>
<clusters lockOthers="true">
<include client="false" server="true" clientLocked="true" serverLocked="true" >Test Cluster</include>
<include cluster="Basic" client="false" server="true" clientLocked="true" serverLocked="true"></include>
</clusters>
</deviceType>
</configurator>
2 changes: 2 additions & 0 deletions test/test-util.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,8 @@ exports.testServer = testServer

exports.testCustomXml = './test/resource/custom-cluster/test-custom.xml'
exports.testCustomXml2 = './test/resource/custom-cluster/custom-dut.xml'
exports.testCustomXmlDeviceType =
'./test/resource/custom-cluster/custom-device-type.xml'
exports.customClusterXml =
'./test/resource/custom-cluster/custom-bead-cluster.xml'
exports.badTestCustomXml = './test/resource/custom-cluster/bad-test-custom.xml'
Expand Down

0 comments on commit 8af71bf

Please sign in to comment.