Skip to content

Commit

Permalink
disabling GUI buttons of forced External Storage (project-chip#1181)
Browse files Browse the repository at this point in the history
* disabling buttons if forced external (MatterSDK)
  • Loading branch information
paulr34 authored Nov 14, 2023
1 parent 1428d6e commit f78db78
Show file tree
Hide file tree
Showing 8 changed files with 103 additions and 13 deletions.
8 changes: 7 additions & 1 deletion src-electron/db/query-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const dbMapping = require('./db-mapping.js')
const queryPackage = require('./query-package.js')
const dbEnum = require('../../src-shared/db-enum.js')
const queryZcl = require('./query-zcl.js')
const queryUpgrade = require('../upgrade/upgrade.js')
const queryUpgrade = require('../matter/matter.js')
const queryDeviceType = require('./query-device-type')
const queryCommand = require('./query-command.js')
const restApi = require('../../src-shared/rest-api.js')
Expand Down Expand Up @@ -223,6 +223,12 @@ async function insertOrUpdateAttributeState(
forcedExternal,
staticAttribute.name
)
if (
staticAttribute.storagePolicy ==
dbEnum.storagePolicy.attributeAccessInterface
) {
staticAttribute.defaultValue = null
}
if (staticAttribute == null) {
throw new Error(`COULD NOT LOCATE ATTRIBUTE: ${attributeId} `)
}
Expand Down
3 changes: 2 additions & 1 deletion src-electron/db/query-impexp.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
const dbApi = require('./db-api')
const dbEnums = require('../../src-shared/db-enum')
const dbMapping = require('./db-mapping.js')
const queryUpgrade = require('../upgrade/upgrade.js')
const queryUpgrade = require('../matter/matter.js')
/**
* Imports a single endpoint
* @param {} db
Expand Down Expand Up @@ -709,6 +709,7 @@ WHERE
}
if (storagePolicy == dbEnums.storagePolicy.attributeAccessInterface) {
attribute.storageOption = dbEnums.storageOption.external
attribute.defaultValue = null
}

let arg = [
Expand Down
2 changes: 1 addition & 1 deletion src-electron/generator/helper-zcl.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const helperC = require('./helper-c')
const env = require('../util/env')
const types = require('../util/types')
const zclUtil = require('../util/zcl-util')
const upgrade = require('../upgrade/upgrade.js')
const upgrade = require('../matter/matter.js')
const _ = require('lodash')

const characterStringTypes = ['CHAR_STRING', 'LONG_CHAR_STRING']
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
const dbApi = require('../db/db-api.js')
const queryPackage = require('../db/query-package.js')
const queryCluster = require('../db/query-cluster.js')
const queryAttribute = require('../db/query-attribute.js')
const dbEnum = require('../../src-shared/db-enum.js')
const fs = require('fs')
const fsp = fs.promises
Expand All @@ -29,11 +30,19 @@ function parseJson(json) {
return undefined
}
}

/**
* This file implements upgrade rules which are used to upgrade .zap files and xml files
* to be in sync with the spec
*/

async function getForcedExternalStorageList(db, zcl) {
let obj = await fsp.readFile(zcl, 'utf-8')
let data = parseJson(obj)
let byName = data?.attributeAccessInterfaceAttributes
let lists = data?.listsUseAttributeAccessInterface
let forcedExternal = { byName, lists }
return forcedExternal
}
/**
* Returns an array of objects containing global attributes that should be forced external.
*
Expand Down Expand Up @@ -92,6 +101,9 @@ async function computeStoragePolicyForGlobalAttributes(
})
)
}
async function getDisabledStorage(db, zcl) {
return await getForcedExternalStorageList(db, zcl)
}

/**
* Returns a flag stating which type of storage option the attribute is categorized to be.
Expand Down Expand Up @@ -162,6 +174,7 @@ async function computeStorageImport(
}

exports.getForcedExternalStorage = getForcedExternalStorage
exports.getDisabledStorage = getDisabledStorage
exports.computeStorageImport = computeStorageImport
exports.computeStorageNewConfig = computeStorageNewConfig
exports.computeStoragePolicyForGlobalAttributes =
Expand Down
18 changes: 16 additions & 2 deletions src-electron/rest/user-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const queryZcl = require('../db/query-zcl.js')
const queryAttribute = require('../db/query-attribute.js')
const queryCommand = require('../db/query-command.js')
const queryConfig = require('../db/query-config.js')
const upgrade = require('../matter/matter.js')
const querySessionNotification = require('../db/query-session-notification.js')
const queryPackageNotification = require('../db/query-package-notification')
const queryEndpointType = require('../db/query-endpoint-type.js')
Expand Down Expand Up @@ -108,7 +109,8 @@ function httpGetPackageNotifications(db) {
function httpGetPackageNotificationsByPackageId(db) {
return async (request, response) => {
let packageId = request.params.packageId
let notifications = await queryPackageNotification.getNotificationByPackageId(db, packageId)
let notifications =
await queryPackageNotification.getNotificationByPackageId(db, packageId)
response.status(StatusCodes.OK).json(notifications)
}
}
Expand Down Expand Up @@ -136,7 +138,8 @@ function httpDeletePackageNotification(db) {
function httpGetUnseenNotificationCount(db) {
return async (request, response) => {
let sessionId = request.zapSessionId
let notificationCount = await querySessionNotification.getUnseenNotificationCount(db, sessionId)
let notificationCount =
await querySessionNotification.getUnseenNotificationCount(db, sessionId)
response.status(StatusCodes.OK).json(notificationCount)
}
}
Expand Down Expand Up @@ -236,6 +239,13 @@ function httpPostCluster(db) {
}
}
}
function httpPostForcedExternal(db) {
return async (request, response) => {
let zcl = request.body[0].pkg.path
let forcedExternal = await upgrade.getDisabledStorage(db, zcl)
return response.send({ forcedExternal })
}
}
/**
* HTTP POST attribute update
*
Expand Down Expand Up @@ -911,6 +921,10 @@ async function duplicateEndpointTypeClusters(
}

exports.post = [
{
uri: restApi.uri.forcedExternal,
callback: httpPostForcedExternal,
},
{
uri: restApi.uri.cluster,
callback: httpPostCluster,
Expand Down
1 change: 1 addition & 0 deletions src-shared/rest-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ const uri = {
sessionCreate: '/zcl/sessionCreate',
reloadSession: '/zcl/reloadSession',
init: '/init',
forcedExternal: '/zcl/forcedExternal',
}

const uiMode = {
Expand Down
68 changes: 61 additions & 7 deletions src/components/ZclAttributeManager.vue
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,14 @@ limitations under the License.
hashAttributeIdClusterId(props.row.id, selectedCluster.id)
]
"
:disable="isDisabled(props.row.id, selectedCluster.id)"
:disable="
isDisabled(
props.row.id,
props.row.label,
selectedCluster.id,
selectedCluster.label
)
"
class="col"
:options="storageOptions"
dense
Expand All @@ -123,7 +130,14 @@ limitations under the License.
:model-value="selectionSingleton"
:val="hashAttributeIdClusterId(props.row.id, selectedCluster.id)"
indeterminate-value="false"
:disable="isDisabled(props.row.id, selectedCluster.id)"
:disable="
isDisabled(
props.row.id,
props.row.label,
selectedCluster.id,
selectedCluster.label
)
"
@update:model-value="
handleLocalSelection(
$event,
Expand All @@ -140,7 +154,14 @@ limitations under the License.
:model-value="selectionBounded"
:val="hashAttributeIdClusterId(props.row.id, selectedCluster.id)"
indeterminate-value="false"
:disable="isDisabled(props.row.id, selectedCluster.id)"
:disable="
isDisabled(
props.row.id,
props.row.label,
selectedCluster.id,
selectedCluster.label
)
"
@update:model-value="
handleLocalSelection(
$event,
Expand All @@ -167,7 +188,14 @@ limitations under the License.
? 'grey'
: ''
"
:disable="isDisabled(props.row.id, selectedCluster.id)"
:disable="
isDisabled(
props.row.id,
props.row.label,
selectedCluster.id,
selectedCluster.label
)
"
:model-value="
selectionDefault[
hashAttributeIdClusterId(props.row.id, selectedCluster.id)
Expand Down Expand Up @@ -223,6 +251,7 @@ limitations under the License.

<script>
import * as DbEnum from '../../src-shared/db-enum'
import restApi from '../../src-shared/rest-api.js'
//This mixin derives from common-mixin.
import EditableAttributeMixin from '../util/editable-attributes-mixin'
Expand All @@ -231,9 +260,27 @@ export default {
name: 'ZclAttributeManager',
mixins: [EditableAttributeMixin],
methods: {
isDisabled(id, selectedClusterId) {
return !this.selection.includes(
this.hashAttributeIdClusterId(id, selectedClusterId)
loadForcedExternal(packages) {
if (packages) {
this.$serverPost(restApi.uri.forcedExternal, packages).then((resp) => {
this.forcedExternal = resp.data.forcedExternal
})
}
},
checkForcedExternal(name) {
if (
this.forcedExternal.byName?.[this.selectedCluster.label]?.includes(name)
) {
return true
} else {
return false
}
},
isDisabled(id, name, selectedClusterId, selectedCluster) {
return (
!this.selection.includes(
this.hashAttributeIdClusterId(id, selectedClusterId)
) || this.checkForcedExternal(name)
)
},
setToNull(row, selectedClusterId) {
Expand Down Expand Up @@ -447,6 +494,13 @@ export default {
headerStyle: 'min-width: 180px',
},
],
forcedExternal: [],
}
},
created() {
if (this.$serverGet != null) {
this.forcedExternal = []
this.loadForcedExternal(this.packages)
}
},
}
Expand Down
1 change: 1 addition & 0 deletions src/store/zap/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,7 @@ export async function updateSelectedEndpointType(
setRequiredCommands(context, res.data)
})
)

context.commit(
'updateSelectedEndpointType',
endpointTypeDeviceTypeRefPair.endpointType
Expand Down

0 comments on commit f78db78

Please sign in to comment.