Skip to content
代码片段 群组 项目
提交 090f4196 编辑于 作者: Timotej Ecimovic's avatar Timotej Ecimovic
浏览文件

Add the proper APIs for the package retrieval.

上级 e62019f7
No related branches found
No related tags found
无相关合并请求
......@@ -357,7 +357,7 @@ async function getSessionGenTemplates(db, sessionId) {
}
/**
* Resolves into an array of IDs that are the packageIds that all the ZCL queries should resolve into.
* Resolves into an array of package objects that all the ZCL queries should resolve into.
* @param {*} db
* @param {*} sessionId
*/
......@@ -385,6 +385,17 @@ WHERE
.then((rows) => rows.map(dbMapping.map.sessionPackage))
}
/**
* Resolves into an array of IDs that are the packageIds that all the ZCL queries should resolve into.
* @param {*} db
* @param {*} sessionId
*/
async function getSessionZclPackageIds(db, sessionId) {
return getSessionZclPackages(db, sessionId).then((rows) =>
rows.map((r) => r.packageRef)
)
}
/**
* Returns the session package IDs.
* @param {*} db
......@@ -721,8 +732,10 @@ exports.getPackageByPathAndParent = getPackageByPathAndParent
exports.getPackageByPackageId = getPackageByPackageId
exports.getPackagesByType = getPackagesByType
exports.getPackageByParent = getPackageByParent
exports.getPackageIdByPathAndTypeAndVersion = getPackageIdByPathAndTypeAndVersion
exports.getPackageSessionPackagePairBySessionId = getPackageSessionPackagePairBySessionId
exports.getPackageIdByPathAndTypeAndVersion =
getPackageIdByPathAndTypeAndVersion
exports.getPackageSessionPackagePairBySessionId =
getPackageSessionPackagePairBySessionId
exports.getPathCrc = getPathCrc
exports.insertPathCrc = insertPathCrc
......@@ -741,6 +754,7 @@ exports.selectAllDefaultOptions = selectAllDefaultOptions
exports.selectOptionValueByOptionDefaultId = selectOptionValueByOptionDefaultId
exports.getPackagesByParentAndType = getPackagesByParentAndType
exports.getSessionZclPackages = getSessionZclPackages
exports.getSessionZclPackageIds = getSessionZclPackageIds
exports.insertPackageExtension = insertPackageExtension
exports.selectPackageExtension = selectPackageExtension
exports.deleteSessionPackage = deleteSessionPackage
......@@ -178,15 +178,8 @@ function httpGetZclEntity(db) {
let sessionId = request.zapSessionId
queryPackage
.getSessionZclPackages(db, sessionId)
.then((packageArray) =>
parseForZclData(
db,
entity,
id,
packageArray.map((pkg) => pkg.packageRef)
)
)
.getSessionZclPackageIds(db, sessionId)
.then((packageIdArray) => parseForZclData(db, entity, id, packageIdArray))
.then((resultData) => response.json(resultData))
}
}
......
......@@ -22,6 +22,9 @@
* @module JS API: post-import.
*/
const queryEndpoint = require('../db/query-endpoint.js')
const queryConfig = require('../db/query-config.js')
const dbEnum = require('../../src-shared/db-enum.js')
const queryPackage = require('../db/query-package.js')
/**
* Prints a text to console.
......@@ -112,13 +115,46 @@ function sessionId(context) {
return context.sessionId
}
function disableClientCluster(context, code) {}
// Finds the cluster database primary key from code and context.
async function findClusterId(context, code) {
let sessionId = sessionId(context)
querySession.get
return 0
}
// Non-public, common function to modify cluster.
async function modifyCluster(context, endpoint, code, side, enabled) {
let clusterId = await findClusterId(context, code)
return queryConfig.insertOrReplaceClusterState(
context.db,
endpoint.endpointTypeRef,
clusterId,
side,
enabled
)
}
/**
* Disables the client cluster on an endpoint.
* @param {*} context
* @param {*} endpoint
* @param {*} code
*/
async function disableClientCluster(context, endpoint, code) {
return modifyCluster(context, endpoint, code, dbEnum.side.client, false)
}
function disableServerCluster(context, code) {}
async function disableServerCluster(context, endpoint, code) {
return modifyCluster(context, endpoint, code, dbEnum.side.server, false)
}
function enableClientCluster(context, code) {}
async function enableClientCluster(context, endpoint, code) {
return modifyCluster(context, endpoint, code, dbEnum.side.client, true)
}
function enableServerCluster(context, code) {}
async function enableServerCluster(context, endpoint, code) {
return modifyCluster(context, endpoint, code, dbEnum.side.server, true)
}
exports.print = print
exports.functions = functions
......
// Example file for the post load functionality.
async function postLoad(api, context) {}
async function postLoad(api, context) {
let endpoints = api.endpoints(context)
let ep = endpoints[0]
// Here we disable cluster with code 2
api.disableClientCluster(context, ep, 0x0002)
}
exports.postLoad = postLoad
......@@ -12,14 +12,14 @@ async function postLoad(api, context) {
api.print(` - endpoint: ${ep.endpointIdentifier}`)
let clusters = await api.clusters(context, ep)
for (cl of clusters) {
api.print(` - cluster: ${cl.name} [${cl.side}]`)
api.print(` - cluster ${cl.code}: ${cl.name} [${cl.side}]`)
let attributes = await api.attributes(context, ep, cl)
for (at of attributes) {
api.print(` - attribute: ${at.name}`)
api.print(` - attribute ${at.code}: ${at.name}`)
}
let commands = await api.commands(context, ep, cl)
for (co of commands) {
api.print(` - command: ${co.name}`)
api.print(` - command ${co.code}: ${co.name}`)
}
}
}
......
......@@ -26,7 +26,7 @@ const zclLoader = require('../src-electron/zcl/zcl-loader.js')
const querySession = require('../src-electron/db/query-session.js')
const testUtil = require('./test-util.js')
const queryEndpoint = require('../src-electron/db/query-endpoint.js')
const dbEnum = require('../src-shared/db-enum.js')
let testFile = path.join(__dirname, 'resource/three-endpoint-device.zap')
let testScript3 = path.join(__dirname, 'resource/test-script-3.js')
......@@ -72,6 +72,16 @@ test(
})
let endpoints = await queryEndpoint.selectAllEndpoints(db, sid)
expect(endpoints.length).toBe(3)
// get clusters on first endpoint
let clusters = await queryEndpoint.selectEndpointClusters(
db,
endpoints[0].endpointTypeRef
)
// code 2 = device temperature, get client
let deviceTemps = clusters.filter(
(cl) => cl.code == 2 && cl.side == dbEnum.side.client
)
expect(deviceTemps.length).toBe(1)
},
testUtil.timeout.medium()
)
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册