diff --git a/src-electron/db/query-loader.js b/src-electron/db/query-loader.js index 5edac56328..a00507931e 100644 --- a/src-electron/db/query-loader.js +++ b/src-electron/db/query-loader.js @@ -905,6 +905,30 @@ async function insertDeviceTypeCommands(db, dtClusterRefDataPairs) { ) } +/** + * This handles the loading of device type event requirements into the database. + * There is a need to post-process to attach the actual event ref after the fact + * @param {*} db + * @param {*} dtClusterRefDataPairs + */ +async function insertDeviceTypeEvents(db, dtClusterRefDataPairs) { + let events = [] + dtClusterRefDataPairs.map((dtClusterRefDataPair) => { + let dtClusterRef = dtClusterRefDataPair.dtClusterRef + let clusterData = dtClusterRefDataPair.clusterData + if ('requiredEvents' in clusterData) { + clusterData.requiredEvents.forEach((eventName) => { + events.push([dtClusterRef, eventName]) + }) + } + }) + return dbApi.dbMultiInsert( + db, + 'INSERT INTO DEVICE_TYPE_EVENT (DEVICE_TYPE_CLUSTER_REF, EVENT_NAME) VALUES (?, ?)', + events + ) +} + async function insertAccessOperations(db, packageId, operations) { let data = operations.map((o) => [packageId, o.name, o.description]) return dbApi.dbMultiInsert( diff --git a/src-electron/zcl/zcl-loader-dotdot.js b/src-electron/zcl/zcl-loader-dotdot.js index d02ce10a86..442658c671 100644 --- a/src-electron/zcl/zcl-loader-dotdot.js +++ b/src-electron/zcl/zcl-loader-dotdot.js @@ -612,12 +612,16 @@ function prepareDeviceType(deviceType) { cluster.include.forEach((include) => { let attributes = [] let commands = [] + let events = [] if ('requireAttribute' in include) { attributes = include.requireAttribute } if ('requireCommand' in include) { commands = include.requireCommand } + if ('requireEvent' in include) { + events = include.requireEvent + } ret.clusters.push({ client: 'true' == include.$.client, server: 'true' == include.$.server, @@ -627,6 +631,7 @@ function prepareDeviceType(deviceType) { include.$.cluster != undefined ? include.$.cluster : include._, requiredAttributes: attributes, requiredCommands: commands, + requiredEvents: events, }) }) } diff --git a/src-electron/zcl/zcl-loader-silabs.js b/src-electron/zcl/zcl-loader-silabs.js index 7d2c1ea3c5..f8bacbe7b0 100644 --- a/src-electron/zcl/zcl-loader-silabs.js +++ b/src-electron/zcl/zcl-loader-silabs.js @@ -1492,12 +1492,16 @@ function prepareDeviceType(deviceType) { cluster.include.forEach((include) => { let attributes = [] let commands = [] + let events = [] if ('requireAttribute' in include) { attributes = include.requireAttribute } if ('requireCommand' in include) { commands = include.requireCommand } + if ('requireEvent' in include) { + events = include.requireEvent + } ret.clusters.push({ client: 'true' == include.$.client, server: 'true' == include.$.server, @@ -1507,6 +1511,7 @@ function prepareDeviceType(deviceType) { include.$.cluster != undefined ? include.$.cluster : include._, requiredAttributes: attributes, requiredCommands: commands, + requiredEvents: events, }) }) } diff --git a/src/store/zap/actions.js b/src/store/zap/actions.js index e6bfa950a3..114678448e 100644 --- a/src/store/zap/actions.js +++ b/src/store/zap/actions.js @@ -261,6 +261,13 @@ export function setDeviceTypeReference(context, endpointIdDeviceTypeRefPair) { .then((res) => { setRequiredCommands(context, res.data) }) + Vue.prototype + .$serverGet( + `${restApi.uri.deviceTypeEvents}${endpointIdDeviceTypeRefPair.deviceTypeRef}` + ) + .then((res) => { + setRequiredEvents(context, res.data) + }) Vue.prototype .$serverGet( @@ -448,6 +455,13 @@ export function updateSelectedEndpointType( .then((res) => { setRequiredCommands(context, res.data) }) + Vue.prototype + .$serverGet( + `${restApi.uri.deviceTypeEvents}${endpointTypeDeviceTypeRefPair.deviceTypeRef}` + ) + .then((res) => { + setRequiredEvents(context, res.data) + }) context.commit( 'updateSelectedEndpointType', endpointTypeDeviceTypeRefPair.endpointType @@ -595,6 +609,16 @@ export function setRequiredCommands(context, data) { }) } +export function setRequiredEvents(context, data) { + let requiredEvents = [] + data.forEach((record) => { + if (record.eventRef) requiredEvents.push(record.eventRef) + }) + context.commit(`setRequiredEventsList`, { + requiredEvents: requiredEvents, + }) +} + export function setLeftDrawerState(context, data) { context.commit('setLeftDrawerState', data) } @@ -799,7 +823,7 @@ export function generateAllEndpointsData(context, endpointData) { enabledClients.push(record.clusterRef) } else { enabledServers.push(record.clusterRef) - + } } }) diff --git a/src/store/zap/mutations.js b/src/store/zap/mutations.js index abbd9bc868..581b574cf0 100644 --- a/src/store/zap/mutations.js +++ b/src/store/zap/mutations.js @@ -371,6 +371,10 @@ export function setRequiredCommandsList(state, data) { Vue.set(state.commandView, 'requiredCommands', data.requiredCommands) } +export function setRequiredEventsList(state, data) { + Vue.set(state.eventView, 'requiredEvents', data.requiredEvents) +} + export function setLeftDrawerState(state, data) { state.leftDrawerOpenState = data } diff --git a/src/store/zap/state.js b/src/store/zap/state.js index 330111a48f..b0a9e75339 100644 --- a/src/store/zap/state.js +++ b/src/store/zap/state.js @@ -136,6 +136,8 @@ export default function () { }, eventView: { selectedEvents: [], + // These are based off of the selected ZCL Endpoint Device Type + requiredEvents: [], }, calledArgs: { defaultUiMode: restApi.uiMode.ZIGBEE,